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