00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 #undef printf
00065 #include <stdio.h>
00066 #include <dirent.h>
00067
00068
00069
00070 #define MAX_STRING 60
00071 #define MAX_PREV 8
00072 #define SEARCH_BUFFER (4*K)
00073
00074
00075
00076
00077 #define TMP "/tmp"
00078 #define DEV "/dev"
00079
00080
00081
00082
00083 #if (CHIP == INTEL)
00084 #define A_OUT 0x0301
00085 #define SPLIT 0x0420
00086 #endif
00087
00088 #if (CHIP == M68000)
00089 #define A_OUT 0x0301
00090 #define SPLIT 0x0B20
00091 #endif
00092
00093 #if (CHIP == SPARC)
00094 #define A_OUT 0x0301
00095 #define SPLIT 0x0B20
00096 #endif
00097
00098
00099
00100
00101
00102 #define K 1024
00103 #define K_MASK (~(K-1))
00104 #define K_SHIFT 10
00105 #define PAGE_MASK 0x1f
00106 #define PAGE_SHIFT 5
00107 #define MAP_BITS_PER_BLOCK (8 * K)
00108 #define MAP_MASK 0xff
00109
00110
00111
00112
00113
00114 #define CTRL_D '\004'
00115 #define BELL '\007'
00116 #define BS '\010'
00117 #define CTRL_U '\025'
00118 #define ESCAPE '\033'
00119 #define DEL '\177'
00120
00121
00122
00123
00124
00125 #define ESC_HOME ('H' + 0x80)
00126 #define ESC_UP ('A' + 0x80)
00127 #define ESC_PGUP ('V' + 0x80)
00128 #define ESC_LEFT ('D' + 0x80)
00129 #define ESC_5 ('G' + 0x80)
00130 #define ESC_RIGHT ('C' + 0x80)
00131 #define ESC_END ('Y' + 0x80)
00132 #define ESC_DOWN ('B' + 0x80)
00133 #define ESC_PGDN ('U' + 0x80)
00134 #define ESC_PLUS ('T' + 0x80)
00135 #define ESC_MINUS ('S' + 0x80)
00136
00137
00138
00139
00140
00141 #if (CHIP == INTEL)
00142 #define BOX_CLR ' '
00143 #define BOX_ALL '\333'
00144 #define BOX_TOP '\337'
00145 #define BOX_BOT '\334'
00146 #endif
00147
00148 #if (CHIP == M68000)
00149
00150 #define BOX_CLR ' '
00151 #define BOX_ALL '='
00152 #define BOX_TOP '-'
00153 #define BOX_BOT '_'
00154 #endif
00155
00156 #if (CHIP == SPARC)
00157
00158 #define BOX_CLR ' '
00159 #define BOX_ALL '='
00160 #define BOX_TOP '-'
00161 #define BOX_BOT '_'
00162 #endif
00163
00164
00165
00166 #define STATUS_COLUMN 2
00167 #define STATUS_LINE 0
00168 #define BLOCK_COLUMN 4
00169 #define BLOCK_LINE 4
00170 #define INFO_COLUMN 30
00171 #define INFO_LINE BLOCK_LINE
00172 #define PROMPT_COLUMN 0
00173 #define PROMPT_LINE 23
00174 #define WARNING_COLUMN 5
00175 #define WARNING_LINE 10
00176
00177
00178
00179
00180
00181 #define OK 0
00182 #define REDRAW 1
00183 #define REDRAW_POINTERS 2
00184 #define ERROR 3
00185
00186
00187
00188
00189 #define WORD 1
00190 #define BLOCK 2
00191 #define MAP 3
00192
00193 typedef unsigned short word_t;
00194 #if _WORD_SIZE == 2
00195 typedef unsigned int Word_t;
00196 #else
00197 typedef int Word_t;
00198 #endif
00199
00200 #ifndef I_MAP_SLOTS
00201
00202 #define I_MAP_SLOTS 8
00203 #define Z_MAP_SLOTS (sizeof(char *) == 2 ? 16 : 128)
00204 #endif
00205
00206 typedef struct de_state
00207 {
00208
00209
00210
00211
00212 unsigned inodes;
00213 zone_t zones;
00214 unsigned inode_maps;
00215 unsigned zone_maps;
00216 unsigned inode_blocks;
00217 unsigned first_data;
00218 int magic;
00219
00220
00221
00222 unsigned char is_fs;
00223 unsigned char v1;
00224 unsigned inode_size;
00225 unsigned nr_indirects;
00226 unsigned zone_num_size;
00227 int block_size;
00228
00229
00230
00231 bit_t inodes_in_map;
00232 bit_t zones_in_map;
00233 int ndzones;
00234
00235
00236
00237 bitchunk_t inode_map[ I_MAP_SLOTS * K / sizeof (bitchunk_t) ];
00238 bitchunk_t zone_map[ Z_MAP_SLOTS * K / sizeof (bitchunk_t) ];
00239
00240
00241
00242 off_t address;
00243 off_t last_addr;
00244 zone_t block;
00245 unsigned offset;
00246
00247 char buffer[ _MAX_BLOCK_SIZE ];
00248
00249
00250
00251 int mode;
00252 int output_base;
00253
00254
00255
00256 char search_string[ MAX_STRING + 1 ];
00257 off_t prev_addr[ MAX_PREV ];
00258 int prev_mode[ MAX_PREV ];
00259
00260
00261
00262 char *device_name;
00263 int device_d;
00264 int device_mode;
00265 zone_t device_size;
00266
00267 char file_name[ MAX_STRING + 1 ];
00268 FILE *file_f;
00269 int file_written;
00270
00271 } de_state;
00272
00273
00274
00275
00276
00277
00278
00279 _PROTOTYPE(void main , (int argc , char *argv []));
00280 _PROTOTYPE(int Process , (de_state *s , int c ));
00281
00282 #if __STDC__
00283 void Error( const char *text, ... );
00284 #else
00285 void Error();
00286 #endif
00287
00288 _PROTOTYPE(int In_Use , (bit_t bit , bitchunk_t *map ));
00289 _PROTOTYPE(ino_t Find_Inode , (de_state *s , char *filename ));
00290
00291
00292
00293
00294 _PROTOTYPE(void Save_Term , (void));
00295 _PROTOTYPE(void Set_Term , (void));
00296 _PROTOTYPE(void Reset_Term , (void));
00297 _PROTOTYPE(int Get_Char , (void));
00298 _PROTOTYPE(char *Get_Line , (void));
00299 _PROTOTYPE(int Arrow_Esc , (int c ));
00300
00301
00302
00303 _PROTOTYPE(int Init_Termcap , (void));
00304 _PROTOTYPE(void Draw_Help_Screen , (de_state *s ));
00305 _PROTOTYPE(void Wait_For_Key , (void));
00306 _PROTOTYPE(void Draw_Prompt , (char *string ));
00307 _PROTOTYPE(void Erase_Prompt , (void));
00308
00309 _PROTOTYPE(void Draw_Screen , (de_state *s ));
00310 _PROTOTYPE(void Draw_Strings , (de_state *s ));
00311 _PROTOTYPE(void Draw_Pointers , (de_state *s ));
00312 _PROTOTYPE(void Print_Ascii , (int c ));
00313
00314 _PROTOTYPE(void Goto , (int column , int line ));
00315 _PROTOTYPE(void Block_Type , (de_state *s ));
00316 _PROTOTYPE(void Draw_Words , (de_state *s ));
00317 _PROTOTYPE(void Draw_Info , (de_state *s ));
00318 _PROTOTYPE(void Draw_Block , (char *block ));
00319 _PROTOTYPE(void Draw_Map , (char *block , int max_bits ));
00320 _PROTOTYPE(void Draw_Offset , (de_state *s ));
00321 _PROTOTYPE(void Word_Pointers , (off_t old_addr , off_t new_addr ));
00322 _PROTOTYPE(void Block_Pointers , (off_t old_addr , off_t new_addr ));
00323 _PROTOTYPE(void Map_Pointers , (off_t old_addr , off_t new_addr ));
00324 _PROTOTYPE(void Print_Number , (Word_t number , int output_base ));
00325 _PROTOTYPE(void Draw_Zone_Numbers , (de_state *s , struct inode *inode ,
00326 int zindex , int zrow ));
00327
00328 #if __STDC__
00329 void Warning( const char *text, ... );
00330 #else
00331 void Warning();
00332 #endif
00333
00334
00335
00336
00337 _PROTOTYPE(void Read_Disk , (de_state *s , off_t block_addr , char *buffer ));
00338 _PROTOTYPE(void Read_Block , (de_state *s , char *buffer ));
00339 _PROTOTYPE(void Read_Super_Block , (de_state *s ));
00340 _PROTOTYPE(void Read_Bit_Maps , (de_state *s ));
00341 _PROTOTYPE(off_t Search , (de_state *s , char *string ));
00342 _PROTOTYPE(void Write_Word , (de_state *s , Word_t word ));
00343
00344
00345
00346
00347 _PROTOTYPE(int Path_Dir_File , (char *path_name , char **dir_name ,
00348 char **file_name ));
00349 _PROTOTYPE(char *File_Device , (char *file_name ));
00350 _PROTOTYPE(ino_t Find_Deleted_Entry , (de_state *s , char *path_name ));
00351 _PROTOTYPE(off_t Recover_Blocks , (de_state *s ));
00352
00353
00354 #undef printf
00355
00356
00357
00358
00359
00360
00361
00362 #undef FORWARD
00363 #define FORWARD