4 /usr/src/ext2ed/ext2ed.h
6 A part of the extended file system 2 disk editor.
8 --------------------------------------
9 Include file for the ext2 disk editor.
10 --------------------------------------
12 This file contains declarations which are needed by all the files in ext2ed.
14 First written on: April 9 1995
16 Copyright (C) 1995 Gadi Oxman
20 #ifndef EXT2ED_EDITOR_H
21 #define EXT2ED_EDITOR_H
25 -----------------------
26 User definable options
27 -----------------------
31 #define DEBUG /* Activate self-sanity checks */
33 #include <ext2fs/ext2_fs.h> /* Main kernel ext2 include file */
38 #define MAX_FIELDS 400
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 */
45 The user screen consists of four parts:
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).
56 The show pad is mapped to the space left between the other three windows.
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.
63 #define SHOW_PAD_LINES 3000
64 #define SHOW_PAD_COLS (COLS > 140 ? COLS : 140)
66 #define COMMAND_WIN_LINES 6 /* Change this to your preferences */
67 #define TITLE_WIN_LINES 3
68 #define SHOW_WIN_LINES 3
73 #ifndef EXT2_PRE_02B_MAGIC
74 #define EXT2_PRE_02B_MAGIC 0xEF51
78 typedef void (*PF
) (char *); /* Used to point to the dispatched functions */
80 struct struct_commands
{ /* Holds commands of an object */
82 char *names
[MAX_COMMANDS_NUM
];
83 char *descriptions
[MAX_COMMANDS_NUM
];
84 PF callback
[MAX_COMMANDS_NUM
];
87 struct struct_descriptor
{ /* Describes an object */
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
;
99 #define FIELD_TYPE_INT 1
100 #define FIELD_TYPE_UINT 2
101 #define FIELD_TYPE_CHAR 3
103 struct struct_type_data
{ /* The object's data is usually here */
104 long offset_in_block
;
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
;
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
;
129 struct struct_file_info
{ /* Used to handle files and directories */
131 struct ext2_inode
*inode_ptr
;
134 long global_block_num
,global_block_offset
;
135 long block_num
,blocks_count
;
136 long file_offset
,file_length
;
138 unsigned char buffer
[EXT2_MAX_BLOCK_SIZE
];
139 long offset_in_block
;
142 /* The following is used if the file is a directory */
144 long dir_entry_num
,dir_entries_count
;
145 long dir_entry_offset
;
148 struct struct_super_info
{ /* Used to handle the superblock */
149 unsigned long copy_num
;
152 struct struct_group_info
{ /* Used to handle the group descriptors */
153 unsigned long copy_num
;
154 unsigned long group_num
;
157 struct struct_block_bitmap_info
{ /* Used in blockbitmap_com.c */
158 unsigned long entry_num
;
159 unsigned long group_num
;
162 struct struct_inode_bitmap_info
{ /* Used in inodebitmap_com.c */
163 unsigned long entry_num
;
164 unsigned long group_num
;
167 struct struct_remember_lifo
{ /* Implements the objects circular memory */
170 long offset
[REMEMBER_COUNT
];
171 struct struct_descriptor
*type
[REMEMBER_COUNT
];
172 char name
[REMEMBER_COUNT
][80];
175 struct struct_pad_info
{ /* Used to zoom into the pad window */
176 int display_lines
,display_cols
;
178 int max_line
,max_col
;
182 /* Global variables (defined mostly in main.c) */
184 /* Configurable variables (Through configuration file) */
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
;
198 extern char device_name
[80];
199 extern char last_command_line
[80];
200 extern FILE *device_handle
;
201 extern long device_offset
;
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
;
221 extern int redraw_request
;
222 extern char lines_s
[80];
223 extern char cols_s
[80];
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
);
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
);
252 /* General commands which are available always */
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
);
272 void hex_set (char *command_line
);
273 void detailed_help (char *text
);
278 /* Extended2 filesystem general commands - Available only when editing an
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
);
288 extern int version_major
,version_minor
;
289 extern char revision_date
[80];
290 extern char email_address
[80];
293 extern void internal_error (char *description
,char *source_name
,char *function_name
);
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
);
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
);
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
);
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
);
333 void file_show_hex (void);
334 void file_show_text (void);
335 void show_status (void);
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
);
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
);
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
);
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
);
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
);
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
);
400 /* blockbitmap_com.c */
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
);
411 /* inodebitmap_bom.c */
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
);
424 extern WINDOW
*title_win
,*show_win
,*command_win
,*show_pad
;
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);
435 #endif /* EXT2ED_EDITOR_H */