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