de.h

Go to the documentation of this file.
00001 /****************************************************************/
00002 /*                                                              */
00003 /*      de.h                                                    */
00004 /*                                                              */
00005 /*              Definitions for the "Disk editor".              */
00006 /*                                                              */
00007 /****************************************************************/
00008 /*  origination         1989-Jan-15        Terrence W. Holm     */
00009 /****************************************************************/
00010 
00011 
00012 /****************************************************************/
00013 /*                                                              */
00014 /*      de(1)                                                   */
00015 /*                                                              */
00016 /*  This is the MINIX disk editor. It allows the user to        */
00017 /*  observe and modify a file system. It can also be used       */
00018 /*  to recover unlink(2)'ed files                               */
00019 /*                                                              */
00020 /*  See the de(1) man page.                                     */
00021 /*                                                              */
00022 /****************************************************************/
00023 
00024 
00025 /****************************************************************/
00026 /*                                                              */
00027 /*      de                 Copyright  Terrence W. Holm  1989    */
00028 /*                                                              */
00029 /* This program was written for users of the Minix operating    */
00030 /* system, and in the spirit of other public domain software    */
00031 /* written for said system, this source code is made available  */
00032 /* at no cost to everyone. I assume no responsibility for       */
00033 /* damage to file systems caused by this program.               */
00034 /*                                                              */
00035 /* This program (one .h, five .c's and a "man" page) may be     */
00036 /* copied and/or modified subject to (1) no charge must be      */
00037 /* made for distribution, other than for the medium, (2) all    */
00038 /* modified sources must be clearly marked as such, (3) all     */
00039 /* sources must carry this copyright.                           */
00040 /*                                                              */
00041 /****************************************************************/
00042 
00043 
00044 /****************************************************************/
00045 /*                                                              */
00046 /*      files                                                   */
00047 /*                                                              */
00048 /*          de.h                Definitions                     */
00049 /*          de.c                The main loop                   */
00050 /*          de_stdin.c          Character input routines        */
00051 /*          de_stdout.c         Output routines                 */
00052 /*          de_diskio.c         File system read/write          */
00053 /*          de_recover.c        File restoration routines       */
00054 /*                                                              */
00055 /*          de.1                "Man" page                      */
00056 /*          Makefile            For "make"                      */
00057 /*          README              Installation help               */
00058 /*                                                              */
00059 /*                                                              */
00060 /*      fs/path.c was modified to support the 'x' command.      */
00061 /*      fs/link.c and fs/open.c were changed for 'X'.           */
00062 /*                                                              */
00063 /****************************************************************/
00064 #undef printf
00065 #include <stdio.h>
00066 #include <dirent.h>
00067 
00068 /*  General constants  */
00069 
00070 #define   MAX_STRING    60              /*  For all input lines */
00071 #define   MAX_PREV      8               /*  For 'p' command     */
00072 #define   SEARCH_BUFFER (4*K)           /*  For '/' and 'n'     */
00073 
00074 
00075 /*  Files  */
00076 
00077 #define   TMP      "/tmp"               /*  For "-r" output     */
00078 #define   DEV      "/dev"               /*  Where devices are   */
00079 
00080 
00081 /*  a.out header constants  (see a.out.h, if you have it)  */
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 /*  Each buffer is 1k.  In WORD mode 16 words (32 bytes) can be */
00099 /*  displayed at once. In BLOCK mode 1K bytes can be displayed. */
00100 /*  In MAP mode 2048 bits (256 bytes) are displayed.            */
00101 
00102 #define   K             1024            /*  STD_BLK             */
00103 #define   K_MASK        (~(K-1))        /*  Round to K boundary */
00104 #define   K_SHIFT       10              /*  Ie. 1<<10 = K       */
00105 #define   PAGE_MASK     0x1f            /*  Word mode: 32 bytes */
00106 #define   PAGE_SHIFT    5               /*  Ie. 1<<5 = 32       */
00107 #define   MAP_BITS_PER_BLOCK (8 * K)    /*  1k block, 8192 bits */
00108 #define   MAP_MASK      0xff            /*  256 bytes/screen    */
00109 
00110 
00111 
00112 /*  Terminal i/o codes  */
00113 
00114 #define   CTRL_D        '\004'          /*  ASCII ^D            */
00115 #define   BELL          '\007'          /*  ASCII bell code     */
00116 #define   BS            '\010'          /*  ASCII back space    */
00117 #define   CTRL_U        '\025'          /*  ASCII ^U            */
00118 #define   ESCAPE        '\033'          /*  ASCII escape code   */
00119 #define   DEL           '\177'          /*  ASCII delete code   */
00120 
00121 
00122 /*  Input escape codes generated by the Minix console.  */
00123 /*  Format: ESC [ X.                                    */
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 /*  Graphic box codes - only applicable for console display  */
00139 /*  in visual mode "map".                                    */
00140 
00141 #if (CHIP == INTEL)
00142 #define   BOX_CLR       ' '             /*  Empty box           */
00143 #define   BOX_ALL       '\333'          /*  Filled box          */
00144 #define   BOX_TOP       '\337'          /*  Filled upper half   */
00145 #define   BOX_BOT       '\334'          /*  Filled lower half   */
00146 #endif
00147 
00148 #if (CHIP == M68000)
00149 /*  Please change these.  */
00150 #define   BOX_CLR       ' '             /*  Empty box           */
00151 #define   BOX_ALL       '='             /*  Filled box          */
00152 #define   BOX_TOP       '-'             /*  Filled upper half   */
00153 #define   BOX_BOT       '_'             /*  Filled lower half   */
00154 #endif
00155 
00156 #if (CHIP == SPARC)
00157 /*  Please change these.  */
00158 #define   BOX_CLR       ' '             /*  Empty box           */
00159 #define   BOX_ALL       '='             /*  Filled box          */
00160 #define   BOX_TOP       '-'             /*  Filled upper half   */
00161 #define   BOX_BOT       '_'             /*  Filled lower half   */
00162 #endif
00163 
00164 /*  Move positions for the output display.  */
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 /*  Values returned by Process() and Get_Filename()  */
00180 
00181 #define   OK              0             /*  No update required  */
00182 #define   REDRAW          1             /*  Redraw whole screen */
00183 #define   REDRAW_POINTERS 2             /*  Redraw just ptrs    */
00184 #define   ERROR           3             /*  Beep                */
00185 
00186 
00187 /*  Visual modes  */
00188 
00189 #define   WORD     1
00190 #define   BLOCK    2
00191 #define   MAP      3
00192 
00193 typedef  unsigned short word_t;         /*  For most user i/o   */
00194 #if _WORD_SIZE == 2
00195 typedef  unsigned int Word_t;           /*  What it should always be */
00196 #else
00197 typedef  int Word_t;                    /*  Unsigned promotion under ANSI C */
00198 #endif
00199 
00200 #ifndef I_MAP_SLOTS
00201 /* Max number of inode and zone map blocks we can handle. */
00202 #define I_MAP_SLOTS     8
00203 #define Z_MAP_SLOTS     (sizeof(char *) == 2 ? 16 : 128)
00204 #endif
00205 
00206 typedef  struct  de_state               /*  State of disk ed.   */
00207   {
00208   /*  Information from super block  */
00209   /*  The types here are mostly promoted types for simplicity   */
00210   /*  and efficiency.                                           */
00211 
00212   unsigned inodes;                      /*  Number of i-nodes   */
00213   zone_t zones;                         /*  Total # of blocks   */
00214   unsigned inode_maps;                  /*  I-node map blocks   */
00215   unsigned zone_maps;                   /*  Zone map blocks     */
00216   unsigned inode_blocks;                /*  I-node blocks       */
00217   unsigned first_data;                  /*  Total non-data blks */
00218   int magic;                            /*  Magic number        */
00219 
00220   /* Numbers derived from the magic number */  
00221   
00222   unsigned char is_fs;                  /*  Nonzero for good fs */
00223   unsigned char v1;                     /*  Nonzero for V1 fs   */
00224   unsigned inode_size;                  /*  Size of disk inode  */
00225   unsigned nr_indirects;                /*  # indirect blocks   */
00226   unsigned zone_num_size;               /*  Size of disk z num  */
00227   int block_size;                       /*  FS block size       */
00228 
00229   /* Other derived numbers */  
00230   
00231   bit_t inodes_in_map;                  /*  Bits in i-node map  */
00232   bit_t zones_in_map;                   /*  Bits in zone map    */
00233   int ndzones;                          /*  # direct zones in an inode */
00234 
00235   /*  Information from map blocks  */
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   /*  Information for current block  */
00241 
00242   off_t address;                        /*  Current address     */
00243   off_t last_addr;                      /*  For erasing ptrs    */
00244   zone_t block;                         /*  Current block (1K)  */
00245   unsigned offset;                      /*  Offset within block */
00246 
00247   char buffer[ _MAX_BLOCK_SIZE ];
00248 
00249   /*  Display state  */
00250 
00251   int  mode;                            /*  WORD, BLOCK or MAP  */
00252   int  output_base;                     /*  2, 8, 10, or 16     */
00253 
00254   /*  Search information  */
00255 
00256   char search_string[ MAX_STRING + 1 ]; /*  For '/' and 'n'     */
00257   off_t prev_addr[ MAX_PREV ];          /*  For 'p' command     */
00258   int   prev_mode[ MAX_PREV ];
00259 
00260   /*  File information  */
00261 
00262   char *device_name;                    /*  From command line   */
00263   int   device_d;
00264   int   device_mode;                    /*  O_RDONLY or O_RDWR  */
00265   zone_t device_size;                   /*  Number of blocks    */
00266 
00267   char  file_name[ MAX_STRING + 1 ];    /*  For 'w' and 'W'     */
00268   FILE *file_f;
00269   int   file_written;                   /*  Flag if written to  */
00270 
00271   }  de_state;
00272 
00273 
00274 
00275 /*  Forward references for external routines  */
00276 
00277 /*  de.c  */
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 /*  de_stdin.c  */
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 /*  de_stdout.c  */
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 /*  de_diskio.c  */
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 /*  de_recover.c  */
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                        /*  Because fs/const.h  */
00355                                         /*  defines it.         */
00356 
00357 
00358 /*  Static functions are all pre-declared FORWARD but none are  */
00359 /*  declared static yet - this can wait until all functions are */
00360 /*  declared with prototypes.                                   */
00361 
00362 #undef FORWARD
00363 #define FORWARD /* static */

Generated on Fri Apr 14 22:56:47 2006 for minix by  doxygen 1.4.6