1 2/* 3 4/usr/src/ext2ed/ext2ed.h 5 6A part of the extended file system 2 disk editor. 7 8-------------------------------------- 9Include file for the ext2 disk editor. 10-------------------------------------- 11 12This file contains declarations which are needed by all the files in ext2ed. 13 14First written on: April 9 1995 15 16Copyright (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 82typedef void (*PF) (char *); /* Used to point to the dispatched functions */ 83 84struct 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 91struct 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 107struct 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 121struct 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 133struct 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 152struct struct_super_info { /* Used to handle the superblock */ 153 unsigned long copy_num; 154}; 155 156struct struct_group_info { /* Used to handle the group descriptors */ 157 unsigned long copy_num; 158 unsigned long group_num; 159}; 160 161struct struct_block_bitmap_info { /* Used in blockbitmap_com.c */ 162 unsigned long entry_num; 163 unsigned long group_num; 164}; 165 166struct struct_inode_bitmap_info { /* Used in inodebitmap_com.c */ 167 unsigned long entry_num; 168 unsigned long group_num; 169}; 170 171struct 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 179struct 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 190extern char AlternateDescriptors [200]; 191extern char Ext2Descriptors [200]; 192extern char LogFile [200]; 193extern int LogChanges; 194extern int AllowChanges; 195extern int AllowMountedRead; 196extern int ForceExt2; 197extern int DefaultBlockSize; 198extern unsigned long DefaultTotalBlocks; 199extern unsigned long DefaultBlocksInGroup; 200extern int ForceDefault; 201 202extern char device_name [80]; 203extern char last_command_line [80]; 204extern FILE *device_handle; 205extern long device_offset; 206extern int mounted; 207 208extern short block_size; 209extern struct struct_commands general_commands; 210extern struct struct_commands ext2_commands; 211extern struct struct_descriptor *first_type; 212extern struct struct_descriptor *last_type; 213extern struct struct_descriptor *current_type; 214extern struct struct_type_data type_data; 215extern struct struct_file_system_info file_system_info; 216extern struct struct_file_info file_info,first_file_info; 217extern struct struct_group_info group_info; 218extern struct struct_super_info super_info; 219extern struct struct_block_bitmap_info block_bitmap_info; 220extern struct struct_inode_bitmap_info inode_bitmap_info; 221extern struct struct_remember_lifo remember_lifo; 222extern struct struct_pad_info show_pad_info; 223extern int write_access; 224 225extern int redraw_request; 226extern char lines_s [80]; 227extern char cols_s [80]; 228 229 230/* init.c */ 231 232extern int init (void); 233extern void prepare_to_close (void); 234extern int set_struct_descriptors (char *file_name); 235extern void free_struct_descriptors (void); 236extern struct struct_descriptor *add_new_descriptor (char *name); 237extern void add_new_variable (struct struct_descriptor *descriptor,char *v_type,char *v_name); 238extern void fill_type_commands (struct struct_descriptor *ptr); 239extern void add_user_command (struct struct_commands *ptr,char *name,char *description,PF callback); 240extern void free_user_commands (struct struct_commands *ptr); 241extern int set_file_system_info (void); 242extern int process_configuration_file (void); 243extern void add_general_commands (void); 244extern void add_ext2_general_commands (void); 245extern void check_mounted (char *name); 246 247int get_next_option (FILE *fp,char *option,char *value); 248void init_readline (void); 249void init_signals (void); 250void signal_SIGWINCH_handler (int sig_num); 251void signal_SIGTERM_handler (int sig_num); 252void signal_SIGSEGV_handler (int sig_num); 253 254/* general_com.c */ 255 256/* General commands which are aviable always */ 257 258extern void help (char *command_line); 259extern void set (char *command_line); 260extern void set_device (char *command_line); 261extern void set_offset (char *command_line); 262extern void set_type (char *command_line); 263extern void show (char *command_line); 264extern void pgup (char *command_line); 265extern void pgdn (char *command_line); 266extern void redraw (char *command_line); 267extern void remember (char *command_line); 268extern void recall (char *command_line); 269extern void cd (char *command_line); 270extern void enable_write (char *command_line); 271extern void disable_write (char *command_line); 272extern void write_data (char *command_line); 273extern void next (char *command_line); 274extern void prev (char *command_line); 275 276void hex_set (char *command_line); 277void 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 285extern void type_ext2___super (char *command_line); 286extern void type_ext2___group (char *command_line); 287extern void type_ext2___cd (char *command_line); 288 289 290/* main.c */ 291 292extern int version_major,version_minor; 293extern char revision_date [80]; 294extern char email_address [80]; 295 296#ifdef DEBUG 297extern void internal_error (char *description,char *source_name,char *function_name); 298#endif 299 300void parser (void); 301extern int dispatch (char *command_line); 302char *parse_word (char *source,char *dest); 303char *complete_command (char *text,int state); 304char *dupstr (char *src); 305 306 307 308/* disk.c */ 309 310extern int load_type_data (void); 311extern int write_type_data (void); 312extern int low_read (unsigned char *buffer,unsigned long length,unsigned long offset); 313extern int low_write (unsigned char *buffer,unsigned long length,unsigned long offset); 314extern int log_changes (unsigned char *buffer,unsigned long length,unsigned long offset); 315 316/* file_com.c */ 317 318extern int init_file_info (void); 319extern void type_file___show (char *command_line); 320extern void type_file___inode (char *command_line); 321extern void type_file___display (char *command_line); 322extern void type_file___prev (char *command_line); 323extern void type_file___next (char *command_line); 324extern void type_file___offset (char *command_line); 325extern void type_file___prevblock (char *command_line); 326extern void type_file___nextblock (char *command_line); 327extern void type_file___block (char *command_line); 328extern void type_file___remember (char *command_line); 329extern void type_file___set (char *command_line); 330extern void type_file___writedata (char *command_line); 331 332extern long file_block_to_global_block (long file_block,struct struct_file_info *file_info_ptr); 333extern long return_indirect (long table_block,long block_num); 334extern long return_dindirect (long table_block,long block_num); 335extern long return_tindirect (long table_block,long block_num); 336 337void file_show_hex (void); 338void file_show_text (void); 339void show_status (void); 340 341/* inode_com.c */ 342 343extern void type_ext2_inode___next (char *command_line); 344extern void type_ext2_inode___prev (char *command_line); 345extern void type_ext2_inode___show (char *command_line); 346extern void type_ext2_inode___group (char *command_line); 347extern void type_ext2_inode___entry (char *command_line); 348extern void type_ext2_inode___file (char *command_line); 349extern void type_ext2_inode___dir (char *command_line); 350 351extern long inode_offset_to_group_num (long inode_offset); 352extern long int inode_offset_to_inode_num (long inode_offset); 353extern long int inode_num_to_inode_offset (long inode_num); 354 355/* dir_com.c */ 356 357extern int init_dir_info (struct struct_file_info *info); 358extern void type_dir___show (char *command_line); 359extern void type_dir___inode (char *command_line); 360extern void type_dir___pgdn (char *command_line); 361extern void type_dir___pgup (char *command_line); 362extern void type_dir___prev (char *command_line); 363extern void type_dir___next (char *command_line); 364extern void type_dir___followinode (char *command_line); 365extern void type_dir___remember (char *command_line); 366extern void type_dir___cd (char *command_line); 367extern void type_dir___entry (char *command_line); 368extern void type_dir___writedata (char *command_line); 369extern 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 378struct struct_file_info search_dir_entries (int (*action) (struct struct_file_info *info),int *status); 379int action_count (struct struct_file_info *info); 380void show_dir_status (void); 381long count_dir_entries (void); 382int action_name (struct struct_file_info *info); 383int action_entry_num (struct struct_file_info *info); 384int action_show (struct struct_file_info *info); 385 386/* super_com.c */ 387 388extern void type_ext2_super_block___show (char *command_line); 389extern void type_ext2_super_block___gocopy (char *command_line); 390extern void type_ext2_super_block___setactivecopy (char *command_line); 391 392/* group_com.c */ 393 394extern void type_ext2_group_desc___next (char *command_line); 395extern void type_ext2_group_desc___prev (char *command_line); 396extern void type_ext2_group_desc___entry (char *command_line); 397extern void type_ext2_group_desc___show (char *command_line); 398extern void type_ext2_group_desc___inode (char *command_line); 399extern void type_ext2_group_desc___gocopy (char *command_line); 400extern void type_ext2_group_desc___blockbitmap (char *command_line); 401extern void type_ext2_group_desc___inodebitmap (char *command_line); 402extern void type_ext2_group_desc___setactivecopy (char *command_line); 403 404/* blockbitmap_com.c */ 405 406extern void type_ext2_block_bitmap___show (char *command_line); 407extern void type_ext2_block_bitmap___entry (char *command_line); 408extern void type_ext2_block_bitmap___next (char *command_line); 409extern void type_ext2_block_bitmap___prev (char *command_line); 410extern void type_ext2_block_bitmap___allocate (char *command_line); 411extern void type_ext2_block_bitmap___deallocate (char *command_line); 412void allocate_block (long entry_num); 413void deallocate_block (long entry_num); 414 415/* inodebitmap_bom.c */ 416 417extern void type_ext2_inode_bitmap___show (char *command_line); 418extern void type_ext2_inode_bitmap___entry (char *command_line); 419extern void type_ext2_inode_bitmap___next (char *command_line); 420extern void type_ext2_inode_bitmap___prev (char *command_line); 421extern void type_ext2_inode_bitmap___allocate (char *command_line); 422extern void type_ext2_inode_bitmap___deallocate (char *command_line); 423void allocate_inode (long entry_num); 424void deallocate_inode (long entry_num); 425 426/* win.c */ 427 428extern WINDOW *title_win,*show_win,*command_win,*show_pad; 429 430extern void init_windows (void); 431extern void refresh_title_win (void); 432extern void refresh_show_win (void); 433extern void refresh_show_pad (void); 434extern void refresh_command_win (void); 435extern void show_info (void); 436extern void redraw_all (void); 437extern void close_windows (void); 438 439#endif /* EXT2ED_EDITOR_H */ 440