Home | History | Annotate | Download | only in ext2ed
      1 
      2 /*
      3 
      4 /usr/src/ext2ed/ext2ed.h
      5 
      6 A part of the extended file system 2 disk editor.
      7 
      8 --------------------------------------
      9 Include file for the ext2 disk editor.
     10 --------------------------------------
     11 
     12 This file contains declarations which are needed by all the files in ext2ed.
     13 
     14 First written on: April 9 1995
     15 
     16 Copyright (C) 1995 Gadi Oxman
     17 
     18 */
     19 
     20 #ifndef EXT2ED_EDITOR_H
     21 #define EXT2ED_EDITOR_H
     22 
     23 /*
     24 
     25 -----------------------
     26  User definable options
     27 -----------------------
     28 
     29 */
     30 
     31 #define DEBUG						/* Activate self-sanity checks */
     32 
     33 #include <ext2fs/ext2_fs.h>				/* Main kernel ext2 include file */
     34 #include <sys/stat.h>
     35 
     36 #include <ncurses.h>
     37 
     38 #define MAX_FIELDS 		400
     39 
     40 #define MAX_COMMAND_LINE 	81
     41 #define MAX_COMMANDS_NUM	30			/* Maximum number of commands of one type */
     42 #define REMEMBER_COUNT		30			/* Object memory size */
     43 
     44 /*
     45 	The user screen consists of four parts:
     46 
     47 		1.	Title window (title_win).
     48 		2.	Show (status) window (show_win).
     49 		3.	Main show pad (show_pad).
     50 		4.	Command window (command_win).
     51 
     52 */
     53 
     54 /*
     55 
     56    The show pad is mapped to the space left between the other three windows.
     57 
     58    If you wondered why ext2ed grabs so memory, the answer is probably below - I wanted to treat
     59    the virtual display as infinite. Decrease the following for more realistic memory consumption.
     60 
     61 */
     62 
     63 #define SHOW_PAD_LINES 3000
     64 #define SHOW_PAD_COLS (COLS > 140 ? COLS : 140)
     65 
     66 #define COMMAND_WIN_LINES 6				/* Change this to your preferences */
     67 #define TITLE_WIN_LINES 3
     68 #define SHOW_WIN_LINES 3
     69 
     70 #define HEX 1
     71 #define TEXT 2
     72 
     73 #ifndef EXT2_PRE_02B_MAGIC
     74 	#define EXT2_PRE_02B_MAGIC	0xEF51
     75 #endif
     76 
     77 
     78 typedef void (*PF) (char *);				/* Used to point to the dispatched functions */
     79 
     80 struct struct_commands {				/* Holds commands of an object */
     81 	int last_command;
     82 	char *names [MAX_COMMANDS_NUM];
     83 	char *descriptions [MAX_COMMANDS_NUM];
     84 	PF callback [MAX_COMMANDS_NUM];
     85 };
     86 
     87 struct struct_descriptor {				/* Describes an object */
     88 	unsigned long length;
     89 	unsigned char name [60];
     90 	unsigned short fields_num;
     91 	unsigned char field_names [MAX_FIELDS][80];
     92 	unsigned char field_types [MAX_FIELDS];
     93 	unsigned short field_lengths [MAX_FIELDS];
     94 	unsigned short field_positions [MAX_FIELDS];
     95 	struct struct_commands type_commands;
     96 	struct struct_descriptor *prev,*next;
     97 };
     98 
     99 #define FIELD_TYPE_INT	  1
    100 #define FIELD_TYPE_UINT   2
    101 #define FIELD_TYPE_CHAR   3
    102 
    103 struct struct_type_data {				/* The object's data is usually here */
    104 	long offset_in_block;
    105 
    106 	union union_type_data {				/* Format it in various ways */
    107 		char buffer [EXT2_MAX_BLOCK_SIZE];
    108 		struct ext2_acl_header t_ext2_acl_header;
    109 		struct ext2_acl_entry t_ext2_acl_entry;
    110 		struct ext2_group_desc t_ext2_group_desc;
    111 		struct ext2_inode t_ext2_inode;
    112 		struct ext2_super_block t_ext2_super_block;
    113 		struct ext2_dir_entry t_ext2_dir_entry;
    114 	} u;
    115 };
    116 
    117 struct struct_file_system_info {			/* Important information about the filesystem */
    118 	unsigned long long file_system_size;
    119 	unsigned long super_block_offset;
    120 	unsigned long first_group_desc_offset;
    121 	unsigned long groups_count;
    122 	unsigned long inodes_per_block;
    123 	unsigned long blocks_per_group;			/* The name is misleading; beware */
    124 	unsigned long no_blocks_in_group;
    125 	unsigned short block_size;
    126 	struct ext2_super_block super_block;
    127 };
    128 
    129 struct struct_file_info {				/* Used to handle files and directories */
    130 
    131 	struct ext2_inode *inode_ptr;
    132 
    133 	long inode_offset;
    134 	long global_block_num,global_block_offset;
    135 	long block_num,blocks_count;
    136 	long file_offset,file_length;
    137 	long level;
    138 	unsigned char buffer [EXT2_MAX_BLOCK_SIZE];
    139 	long offset_in_block;
    140 
    141 	int display;
    142 	/* The following is used if the file is a directory */
    143 
    144 	long dir_entry_num,dir_entries_count;
    145 	long dir_entry_offset;
    146 };
    147 
    148 struct struct_super_info {				/* Used to handle the superblock */
    149 	unsigned long copy_num;
    150 };
    151 
    152 struct struct_group_info {				/* Used to handle the group descriptors */
    153 	unsigned long copy_num;
    154 	unsigned long group_num;
    155 };
    156 
    157 struct struct_block_bitmap_info {			/* Used in blockbitmap_com.c */
    158 	unsigned long entry_num;
    159 	unsigned long group_num;
    160 };
    161 
    162 struct struct_inode_bitmap_info {			/* Used in inodebitmap_com.c */
    163 	unsigned long entry_num;
    164 	unsigned long group_num;
    165 };
    166 
    167 struct struct_remember_lifo {				/* Implements the objects circular memory */
    168 	long entries_count;
    169 
    170 	long offset [REMEMBER_COUNT];
    171 	struct struct_descriptor *type [REMEMBER_COUNT];
    172 	char name [REMEMBER_COUNT][80];
    173 };
    174 
    175 struct struct_pad_info {				/* Used to zoom into the pad window */
    176 	int display_lines,display_cols;
    177 	int line,col;
    178 	int max_line,max_col;
    179 	int disable_output;
    180 };
    181 
    182 /* Global variables (defined mostly in main.c) */
    183 
    184 /* Configurable variables (Through configuration file) */
    185 
    186 extern char AlternateDescriptors [200];
    187 extern char Ext2Descriptors [200];
    188 extern char LogFile [200];
    189 extern int LogChanges;
    190 extern int AllowChanges;
    191 extern int AllowMountedRead;
    192 extern int ForceExt2;
    193 extern int DefaultBlockSize;
    194 extern unsigned long DefaultTotalBlocks;
    195 extern unsigned long DefaultBlocksInGroup;
    196 extern int ForceDefault;
    197 
    198 extern char device_name [80];
    199 extern char last_command_line [80];
    200 extern FILE *device_handle;
    201 extern long device_offset;
    202 extern int  mounted;
    203 
    204 extern short block_size;
    205 extern struct struct_commands general_commands;
    206 extern struct struct_commands ext2_commands;
    207 extern struct struct_descriptor *first_type;
    208 extern struct struct_descriptor *last_type;
    209 extern struct struct_descriptor *current_type;
    210 extern struct struct_type_data type_data;
    211 extern struct struct_file_system_info file_system_info;
    212 extern struct struct_file_info file_info,first_file_info;
    213 extern struct struct_group_info group_info;
    214 extern struct struct_super_info super_info;
    215 extern struct struct_block_bitmap_info block_bitmap_info;
    216 extern struct struct_inode_bitmap_info inode_bitmap_info;
    217 extern struct struct_remember_lifo remember_lifo;
    218 extern struct struct_pad_info show_pad_info;
    219 extern int write_access;
    220 
    221 extern int redraw_request;
    222 extern char lines_s [80];
    223 extern char cols_s [80];
    224 
    225 
    226 /* init.c */
    227 
    228 extern int init (void);
    229 extern void prepare_to_close (void);
    230 extern int set_struct_descriptors (char *file_name);
    231 extern void free_struct_descriptors (void);
    232 extern struct struct_descriptor *add_new_descriptor (char *name);
    233 extern void add_new_variable (struct struct_descriptor *descriptor,char *v_type,char *v_name);
    234 extern void fill_type_commands (struct struct_descriptor *ptr);
    235 extern void add_user_command (struct struct_commands *ptr,char *name,char *description,PF callback);
    236 extern void free_user_commands (struct struct_commands *ptr);
    237 extern int set_file_system_info (void);
    238 extern int process_configuration_file (void);
    239 extern void add_general_commands (void);
    240 extern void add_ext2_general_commands (void);
    241 extern void check_mounted (char *name);
    242 
    243 int get_next_option (FILE *fp,char *option,char *value);
    244 void init_readline (void);
    245 void init_signals (void);
    246 void signal_SIGWINCH_handler (int sig_num);
    247 void signal_SIGTERM_handler (int sig_num);
    248 void signal_SIGSEGV_handler (int sig_num);
    249 
    250 /* general_com.c */
    251 
    252 /* General commands which are available always */
    253 
    254 extern void help (char *command_line);
    255 extern void set (char *command_line);
    256 extern void set_device (char *command_line);
    257 extern void set_offset (char *command_line);
    258 extern void set_type (char *command_line);
    259 extern void show (char *command_line);
    260 extern void pgup (char *command_line);
    261 extern void pgdn (char *command_line);
    262 extern void redraw (char *command_line);
    263 extern void remember (char *command_line);
    264 extern void recall (char *command_line);
    265 extern void cd (char *command_line);
    266 extern void enable_write (char *command_line);
    267 extern void disable_write (char *command_line);
    268 extern void write_data (char *command_line);
    269 extern void next (char *command_line);
    270 extern void prev (char *command_line);
    271 
    272 void hex_set (char *command_line);
    273 void detailed_help (char *text);
    274 
    275 
    276 /* ext2_com.c */
    277 
    278 /* Extended2 filesystem general commands - Available only when editing an
    279    ext2 filesystem */
    280 
    281 extern void type_ext2___super (char *command_line);
    282 extern void type_ext2___group (char *command_line);
    283 extern void type_ext2___cd (char *command_line);
    284 
    285 
    286 /* main.c */
    287 
    288 extern int version_major,version_minor;
    289 extern char revision_date [80];
    290 extern char email_address [80];
    291 
    292 #ifdef DEBUG
    293 extern void internal_error (char *description,char *source_name,char *function_name);
    294 #endif
    295 
    296 void parser (void);
    297 extern int dispatch (char *command_line);
    298 char *parse_word (char *source,char *dest);
    299 char *complete_command (char *text,int state);
    300 char *dupstr (char *src);
    301 
    302 
    303 
    304 /* disk.c */
    305 
    306 extern int load_type_data (void);
    307 extern int write_type_data (void);
    308 extern int low_read (unsigned char *buffer,unsigned long length,unsigned long offset);
    309 extern int low_write (unsigned char *buffer,unsigned long length,unsigned long offset);
    310 extern int log_changes (unsigned char *buffer,unsigned long length,unsigned long offset);
    311 
    312 /* file_com.c */
    313 
    314 extern int init_file_info (void);
    315 extern void type_file___show (char *command_line);
    316 extern void type_file___inode (char *command_line);
    317 extern void type_file___display (char *command_line);
    318 extern void type_file___prev (char *command_line);
    319 extern void type_file___next (char *command_line);
    320 extern void type_file___offset (char *command_line);
    321 extern void type_file___prevblock (char *command_line);
    322 extern void type_file___nextblock (char *command_line);
    323 extern void type_file___block (char *command_line);
    324 extern void type_file___remember (char *command_line);
    325 extern void type_file___set (char *command_line);
    326 extern void type_file___writedata (char *command_line);
    327 
    328 extern long file_block_to_global_block (long file_block,struct struct_file_info *file_info_ptr);
    329 extern long return_indirect (long table_block,long block_num);
    330 extern long return_dindirect (long table_block,long block_num);
    331 extern long return_tindirect (long table_block,long block_num);
    332 
    333 void file_show_hex (void);
    334 void file_show_text (void);
    335 void show_status (void);
    336 
    337 /* inode_com.c */
    338 
    339 extern void type_ext2_inode___next (char *command_line);
    340 extern void type_ext2_inode___prev (char *command_line);
    341 extern void type_ext2_inode___show (char *command_line);
    342 extern void type_ext2_inode___group (char *command_line);
    343 extern void type_ext2_inode___entry (char *command_line);
    344 extern void type_ext2_inode___file (char *command_line);
    345 extern void type_ext2_inode___dir (char *command_line);
    346 
    347 extern long inode_offset_to_group_num (long inode_offset);
    348 extern long int inode_offset_to_inode_num (long inode_offset);
    349 extern long int inode_num_to_inode_offset (long inode_num);
    350 
    351 /* dir_com.c */
    352 
    353 extern int init_dir_info (struct struct_file_info *info);
    354 extern void type_dir___show (char *command_line);
    355 extern void type_dir___inode (char *command_line);
    356 extern void type_dir___pgdn (char *command_line);
    357 extern void type_dir___pgup (char *command_line);
    358 extern void type_dir___prev (char *command_line);
    359 extern void type_dir___next (char *command_line);
    360 extern void type_dir___followinode (char *command_line);
    361 extern void type_dir___remember (char *command_line);
    362 extern void type_dir___cd (char *command_line);
    363 extern void type_dir___entry (char *command_line);
    364 extern void type_dir___writedata (char *command_line);
    365 extern void type_dir___set (char *command_line);
    366 
    367 #define HEX 1
    368 #define TEXT 2
    369 
    370 #define ABORT		0
    371 #define CONTINUE	1
    372 #define FOUND		2
    373 
    374 struct struct_file_info search_dir_entries (int (*action) (struct struct_file_info *info),int *status);
    375 int action_count (struct struct_file_info *info);
    376 void show_dir_status (void);
    377 long count_dir_entries (void);
    378 int action_name (struct struct_file_info *info);
    379 int action_entry_num (struct struct_file_info *info);
    380 int action_show (struct struct_file_info *info);
    381 
    382 /* super_com.c */
    383 
    384 extern void type_ext2_super_block___show (char *command_line);
    385 extern void type_ext2_super_block___gocopy (char *command_line);
    386 extern void type_ext2_super_block___setactivecopy (char *command_line);
    387 
    388 /* group_com.c */
    389 
    390 extern void type_ext2_group_desc___next (char *command_line);
    391 extern void type_ext2_group_desc___prev (char *command_line);
    392 extern void type_ext2_group_desc___entry (char *command_line);
    393 extern void type_ext2_group_desc___show (char *command_line);
    394 extern void type_ext2_group_desc___inode (char *command_line);
    395 extern void type_ext2_group_desc___gocopy (char *command_line);
    396 extern void type_ext2_group_desc___blockbitmap (char *command_line);
    397 extern void type_ext2_group_desc___inodebitmap (char *command_line);
    398 extern void type_ext2_group_desc___setactivecopy (char *command_line);
    399 
    400 /* blockbitmap_com.c */
    401 
    402 extern void type_ext2_block_bitmap___show (char *command_line);
    403 extern void type_ext2_block_bitmap___entry (char *command_line);
    404 extern void type_ext2_block_bitmap___next (char *command_line);
    405 extern void type_ext2_block_bitmap___prev (char *command_line);
    406 extern void type_ext2_block_bitmap___allocate (char *command_line);
    407 extern void type_ext2_block_bitmap___deallocate (char *command_line);
    408 void allocate_block (long entry_num);
    409 void deallocate_block (long entry_num);
    410 
    411 /* inodebitmap_bom.c */
    412 
    413 extern void type_ext2_inode_bitmap___show (char *command_line);
    414 extern void type_ext2_inode_bitmap___entry (char *command_line);
    415 extern void type_ext2_inode_bitmap___next (char *command_line);
    416 extern void type_ext2_inode_bitmap___prev (char *command_line);
    417 extern void type_ext2_inode_bitmap___allocate (char *command_line);
    418 extern void type_ext2_inode_bitmap___deallocate (char *command_line);
    419 void allocate_inode (long entry_num);
    420 void deallocate_inode (long entry_num);
    421 
    422 /* win.c */
    423 
    424 extern WINDOW *title_win,*show_win,*command_win,*show_pad;
    425 
    426 extern void init_windows (void);
    427 extern void refresh_title_win (void);
    428 extern void refresh_show_win (void);
    429 extern void refresh_show_pad (void);
    430 extern void refresh_command_win (void);
    431 extern void show_info (void);
    432 extern void redraw_all (void);
    433 extern void close_windows (void);
    434 
    435 #endif /* EXT2ED_EDITOR_H */
    436