blob: 57953ab6e71d32e72bfbd9453219dfbd018b53c6 [file] [log] [blame]
Theodore Ts'o583a1ce2002-05-11 13:00:22 -04001/*
2
3/usr/src/ext2ed/super_com.c
4
5A part of the extended file system 2 disk editor.
6
7----------------------
8Handles the superblock
9----------------------
10
11First written on: April 9 1995
12
13Copyright (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
24void 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;
Theodore Ts'oefc6f622008-08-27 23:07:54 -040029
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040030 show (command_line);
31
JP Abgralle0ed7402014-03-19 19:08:39 -070032 if (ext2fs_blocks_count(super) != 0) {
33 wmove (show_pad,2,40);wprintw (show_pad,"%2.2f%%",100*(float) ext2fs_r_blocks_count(super)/ (float) ext2fs_blocks_count(super));
34 wmove (show_pad,3,40);wprintw (show_pad,"%2.2f%%",100*(float) ext2fs_free_blocks_count(super)/ (float) ext2fs_blocks_count(super));
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040035 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -040036
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040037 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 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -040063
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040064 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");
Theodore Ts'oefc6f622008-08-27 23:07:54 -040074
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040075 wmove (show_pad,17,40);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040076
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040077 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);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040093
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040094 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
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400104 default:
105 wprintw (show_pad,"Unknown");
106 break;
107 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400108
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400109 refresh_show_pad ();
110
111 wmove (show_win,1,0);wprintw (show_win,"\n");wmove (show_win,2,0);
112 wprintw (show_win,"Superblock copy %ld ",super_info.copy_num);
113 if (super_info.copy_num==0)
114 wprintw (show_win,"(main copy)");
115 wprintw (show_win,"\n");
116 refresh_show_win ();
117}
118
119void type_ext2_super_block___gocopy (char *command_line)
120
121{
122 unsigned long copy_num,offset;
123 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400124
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400125 ptr=parse_word (command_line,buffer);
126 if (*ptr==0) {
127 wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return;
128 }
129 ptr=parse_word (ptr,buffer);
130
131 copy_num=atol (buffer);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400132
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400133 offset=file_system_info.super_block_offset+copy_num*file_system_info.no_blocks_in_group*file_system_info.block_size;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400134
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400135 if (offset > file_system_info.file_system_size) {
136 wprintw (command_win,"Error - Copy number out of bounds\n");refresh_command_win ();return;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400137 }
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400138
139 super_info.copy_num=copy_num;
140 device_offset=offset;
141
142 sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
143 strcpy (buffer,"show");dispatch (buffer);
144}
145
146void type_ext2_super_block___setactivecopy (char *command_line)
147
148{
149 struct ext2_super_block sb;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400150
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400151 sb=type_data.u.t_ext2_super_block;
152 dispatch ("gocopy 0");
153 type_data.u.t_ext2_super_block=sb;
154 dispatch ("show");
155}