• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 
3 /usr/src/ext2ed/super_com.c
4 
5 A part of the extended file system 2 disk editor.
6 
7 ----------------------
8 Handles the superblock
9 ----------------------
10 
11 First written on: April 9 1995
12 
13 Copyright (C) 1995 Gadi Oxman
14 
15 */
16 
17 #include "config.h"
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <time.h>
22 
23 #include "ext2ed.h"
24 
type_ext2_super_block___show(char * command_line)25 void type_ext2_super_block___show (char *command_line)
26 
27 {
28 	struct ext2_super_block *super;
29 	super=&type_data.u.t_ext2_super_block;
30 
31 	show (command_line);
32 
33 	if (ext2fs_blocks_count(super) != 0) {
34 		wmove (show_pad,2,40);wprintw (show_pad,"%2.2f%%",100*(float) ext2fs_r_blocks_count(super)/ (float) ext2fs_blocks_count(super));
35 		wmove (show_pad,3,40);wprintw (show_pad,"%2.2f%%",100*(float) ext2fs_free_blocks_count(super)/ (float) ext2fs_blocks_count(super));
36 	}
37 
38 	if (super->s_inodes_count != 0) {
39 		wmove (show_pad,4,40);wprintw (show_pad,"%2.2f%%",100*(float) super->s_free_inodes_count/ (float) super->s_inodes_count);
40 	}
41 
42 	wmove (show_pad,6,40);
43 	switch (super->s_log_block_size) {
44 		case 0:	wprintw (show_pad,"1024 bytes");break;
45 		case 1: wprintw (show_pad,"2048 bytes");break;
46 		case 2: wprintw (show_pad,"4096 bytes");break;
47 	}
48 	wmove (show_pad,11,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_super_block.s_mtime));
49 	wmove (show_pad,12,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_super_block.s_wtime));
50 	wmove (show_pad,19,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_super_block.s_lastcheck));
51 	wmove (show_pad,15,40);
52 
53 	switch (type_data.u.t_ext2_super_block.s_magic) {
54 		case EXT2_SUPER_MAGIC:
55 			wprintw (show_pad,"ext2 >= 0.2B");
56 			break;
57 		case EXT2_PRE_02B_MAGIC:
58 			wprintw (show_pad,"ext2 < 0.2B (not supported)");
59 			break;
60 		default:
61 			wprintw (show_pad,"Unknown");
62 			break;
63 	}
64 
65 	wmove (show_pad,16,40);
66 	if (type_data.u.t_ext2_super_block.s_state & 0x1)
67 		wprintw (show_pad,"clean ");
68 	else
69 		wprintw (show_pad,"not clean ");
70 
71 	if (type_data.u.t_ext2_super_block.s_state & 0x2)
72 		wprintw (show_pad,"with errors ");
73 	else
74 		wprintw (show_pad,"with no errors");
75 
76 	wmove (show_pad,17,40);
77 
78 	switch (type_data.u.t_ext2_super_block.s_errors) {
79 		case EXT2_ERRORS_CONTINUE:
80 			wprintw (show_pad,"Continue");
81 			break;
82 		case EXT2_ERRORS_RO:
83 			wprintw (show_pad,"Remount read only");
84 			break;
85 		case EXT2_ERRORS_PANIC:
86 			wprintw (show_pad,"Issue kernel panic");
87 			break;
88 		default:
89 			wprintw (show_pad,"Unknown");
90 			break;
91 	}
92 
93 	wmove (show_pad,21,40);
94 
95 	switch (type_data.u.t_ext2_super_block.s_creator_os) {
96 
97 		case EXT2_OS_LINUX:
98 			wprintw (show_pad,"Linux :-)");
99 			break;
100 
101 		case EXT2_OS_HURD:
102 			wprintw (show_pad,"Hurd");
103 			break;
104 
105 		default:
106 			wprintw (show_pad,"Unknown");
107 			break;
108 	}
109 
110 	refresh_show_pad ();
111 
112 	wmove (show_win,1,0);wprintw (show_win,"\n");wmove (show_win,2,0);
113 	wprintw (show_win,"Superblock copy %ld ",super_info.copy_num);
114 	if (super_info.copy_num==0)
115 		wprintw (show_win,"(main copy)");
116 	wprintw (show_win,"\n");
117 	refresh_show_win ();
118 }
119 
type_ext2_super_block___gocopy(char * command_line)120 void type_ext2_super_block___gocopy (char *command_line)
121 
122 {
123 	unsigned long copy_num,offset;
124 	char *ptr,buffer [80];
125 
126 	ptr=parse_word (command_line,buffer);
127 	if (*ptr==0) {
128 		wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return;
129 	}
130 	ptr=parse_word (ptr,buffer);
131 
132 	copy_num=atol (buffer);
133 
134 	offset=file_system_info.super_block_offset+copy_num*file_system_info.no_blocks_in_group*file_system_info.block_size;
135 
136 	if (offset > file_system_info.file_system_size) {
137 		wprintw (command_win,"Error - Copy number out of bounds\n");refresh_command_win ();return;
138 	}
139 
140 	super_info.copy_num=copy_num;
141 	device_offset=offset;
142 
143 	sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
144 	strcpy (buffer,"show");dispatch (buffer);
145 }
146 
type_ext2_super_block___setactivecopy(char * command_line)147 void type_ext2_super_block___setactivecopy (char *command_line)
148 
149 {
150 	struct ext2_super_block sb;
151 
152 	sb=type_data.u.t_ext2_super_block;
153 	dispatch ("gocopy 0");
154 	type_data.u.t_ext2_super_block=sb;
155 	dispatch ("show");
156 }
157