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