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