blob: a998970ec8be20ab16b5b488d09609a07cc889ee [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
Theodore Ts'od1154eb2011-09-18 17:34:37 -040017#include "config.h"
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040018#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <time.h>
22
23#include "ext2ed.h"
24
25void 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;
Theodore Ts'oefc6f622008-08-27 23:07:54 -040030
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040031 show (command_line);
32
Valerie Aurora Henson4efbac62009-09-07 20:46:34 -040033 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));
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040036 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -040037
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040038 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 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -040064
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040065 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");
Theodore Ts'oefc6f622008-08-27 23:07:54 -040075
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040076 wmove (show_pad,17,40);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040077
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040078 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);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040094
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040095 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
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400105 default:
106 wprintw (show_pad,"Unknown");
107 break;
108 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400109
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400110 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
120void type_ext2_super_block___gocopy (char *command_line)
121
122{
123 unsigned long copy_num,offset;
124 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400125
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400126 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);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400133
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400134 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 -0400135
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400136 if (offset > file_system_info.file_system_size) {
137 wprintw (command_win,"Error - Copy number out of bounds\n");refresh_command_win ();return;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400138 }
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400139
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
147void type_ext2_super_block___setactivecopy (char *command_line)
148
149{
150 struct ext2_super_block sb;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400151
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400152 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}