super_com.c revision 18a1444b4f1e6a0948fd38fa0de382d86cfe04de
1/* 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; 29 30 show (command_line); 31 32 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)); 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 default: 105 wprintw (show_pad,"Unknown"); 106 break; 107 } 108 109 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]; 124 125 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); 132 133 offset=file_system_info.super_block_offset+copy_num*file_system_info.no_blocks_in_group*file_system_info.block_size; 134 135 if (offset > file_system_info.file_system_size) { 136 wprintw (command_win,"Error - Copy number out of bounds\n");refresh_command_win ();return; 137 } 138 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; 150 151 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} 156