summaryrefslogtreecommitdiff
path: root/ext2ed/ext2ed.h
blob: 2ee483e8e2a84016c6631dd3d669c01c8eb3f32c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439

/*

/usr/src/ext2ed/ext2ed.h

A part of the extended file system 2 disk editor.

--------------------------------------
Include file for the ext2 disk editor.
--------------------------------------

This file contains declarations which are needed by all the files in ext2ed.

First written on: April 9 1995

Copyright (C) 1995 Gadi Oxman

*/

#ifndef EXT2ED_EDITOR_H
#define EXT2ED_EDITOR_H

/*

-----------------------
 User definable options
-----------------------

*/

#ifndef ETC_DIR
#define ETC_DIR	"/etc"		/* Where to find the config file */
#endif

#define DEBUG						/* Activate self-sanity checks */

#include <ext2fs/ext2_fs.h>				/* Main kernel ext2 include file */
#include <sys/stat.h>

#include <ncurses.h>

#define MAX_FIELDS 		400

#define MAX_COMMAND_LINE 	81
#define MAX_COMMANDS_NUM	30			/* Maximum number of commands of one type */
#define REMEMBER_COUNT		30			/* Object memory size */

/*
	The user screen consists of four parts:

		1.	Title window (title_win).
		2.	Show (status) window (show_win).
		3.	Main show pad (show_pad).
		4.	Command window (command_win).

*/

/*

   The show pad is mapped to the space left between the other three windows.

   If you wondered why ext2ed grabs so memory, the answer is probably below - I wanted to treat
   the virtual display as infinite. Decrease the following for more realistic memory consumption.

*/

#define SHOW_PAD_LINES 3000
#define SHOW_PAD_COLS (COLS > 140 ? COLS : 140)

#define COMMAND_WIN_LINES 6				/* Change this to your preferences */
#define TITLE_WIN_LINES 3
#define SHOW_WIN_LINES 3

#define HEX 1
#define TEXT 2

#ifndef EXT2_PRE_02B_MAGIC
	#define EXT2_PRE_02B_MAGIC	0xEF51
#endif


typedef void (*PF) (char *);				/* Used to point to the dispatched functions */

struct struct_commands {				/* Holds commands of an object */
	int last_command;
	char *names [MAX_COMMANDS_NUM];
	char *descriptions [MAX_COMMANDS_NUM];
	PF callback [MAX_COMMANDS_NUM];
};

struct struct_descriptor {				/* Describes an object */
	unsigned long length;
	unsigned char name [60];
	unsigned short fields_num;
	unsigned char field_names [MAX_FIELDS][80];
	unsigned char field_types [MAX_FIELDS];
	unsigned short field_lengths [MAX_FIELDS];
	unsigned short field_positions [MAX_FIELDS];
	struct struct_commands type_commands;
	struct struct_descriptor *prev,*next;
};

#define FIELD_TYPE_INT	  1
#define FIELD_TYPE_UINT   2
#define FIELD_TYPE_CHAR   3

struct struct_type_data {				/* The object's data is usually here */
	long offset_in_block;

	union union_type_data {				/* Format it in various ways */
		char buffer [EXT2_MAX_BLOCK_SIZE];
		struct ext2_acl_header t_ext2_acl_header;
		struct ext2_acl_entry t_ext2_acl_entry;
		struct ext2_group_desc t_ext2_group_desc;
		struct ext2_inode t_ext2_inode;
		struct ext2_super_block t_ext2_super_block;
		struct ext2_dir_entry t_ext2_dir_entry;
	} u;
};

struct struct_file_system_info {			/* Important information about the filesystem */
	unsigned long long file_system_size;
	unsigned long super_block_offset;
	unsigned long first_group_desc_offset;
	unsigned long groups_count;
	unsigned long inodes_per_block;
	unsigned long blocks_per_group;			/* The name is misleading; beware */
	unsigned long no_blocks_in_group;
	unsigned short block_size;
	struct ext2_super_block super_block;
};

struct struct_file_info {				/* Used to handle files and directories */

	struct ext2_inode *inode_ptr;

	long inode_offset;
	long global_block_num,global_block_offset;
	long block_num,blocks_count;
	long file_offset,file_length;
	long level;
	unsigned char buffer [EXT2_MAX_BLOCK_SIZE];
	long offset_in_block;

	int display;
	/* The following is used if the file is a directory */

	long dir_entry_num,dir_entries_count;
	long dir_entry_offset;
};

struct struct_super_info {				/* Used to handle the superblock */
	unsigned long copy_num;
};

struct struct_group_info {				/* Used to handle the group descriptors */
	unsigned long copy_num;
	unsigned long group_num;
};

struct struct_block_bitmap_info {			/* Used in blockbitmap_com.c */
	unsigned long entry_num;
	unsigned long group_num;
};

struct struct_inode_bitmap_info {			/* Used in inodebitmap_com.c */
	unsigned long entry_num;
	unsigned long group_num;
};

struct struct_remember_lifo {				/* Implements the objects circular memory */
	long entries_count;

	long offset [REMEMBER_COUNT];
	struct struct_descriptor *type [REMEMBER_COUNT];
	char name [REMEMBER_COUNT][80];
};

struct struct_pad_info {				/* Used to zoom into the pad window */
	int display_lines,display_cols;
	int line,col;
	int max_line,max_col;
	int disable_output;
};

/* Global variables (defined mostly in main.c) */

/* Configurable variables (Through configuration file) */

extern char AlternateDescriptors [200];
extern char Ext2Descriptors [200];
extern char LogFile [200];
extern int LogChanges;
extern int AllowChanges;
extern int AllowMountedRead;
extern int ForceExt2;
extern int DefaultBlockSize;
extern unsigned long DefaultTotalBlocks;
extern unsigned long DefaultBlocksInGroup;
extern int ForceDefault;

extern char device_name [80];
extern char last_command_line [80];
extern FILE *device_handle;
extern long device_offset;
extern int  mounted;

extern short block_size;
extern struct struct_commands general_commands;
extern struct struct_commands ext2_commands;
extern struct struct_descriptor *first_type;
extern struct struct_descriptor *last_type;
extern struct struct_descriptor *current_type;
extern struct struct_type_data type_data;
extern struct struct_file_system_info file_system_info;
extern struct struct_file_info file_info,first_file_info;
extern struct struct_group_info group_info;
extern struct struct_super_info super_info;
extern struct struct_block_bitmap_info block_bitmap_info;
extern struct struct_inode_bitmap_info inode_bitmap_info;
extern struct struct_remember_lifo remember_lifo;
extern struct struct_pad_info show_pad_info;
extern int write_access;

extern int redraw_request;
extern char lines_s [80];
extern char cols_s [80];


/* init.c */

extern int init (void);
extern void prepare_to_close (void);
extern int set_struct_descriptors (char *file_name);
extern void free_struct_descriptors (void);
extern struct struct_descriptor *add_new_descriptor (char *name);
extern void add_new_variable (struct struct_descriptor *descriptor,char *v_type,char *v_name);
extern void fill_type_commands (struct struct_descriptor *ptr);
extern void add_user_command (struct struct_commands *ptr,char *name,char *description,PF callback);
extern void free_user_commands (struct struct_commands *ptr);
extern int set_file_system_info (void);
extern int process_configuration_file (void);
extern void add_general_commands (void);
extern void add_ext2_general_commands (void);
extern void check_mounted (char *name);

int get_next_option (FILE *fp,char *option,char *value);
void init_readline (void);
void init_signals (void);
void signal_SIGWINCH_handler (int sig_num);
void signal_SIGTERM_handler (int sig_num);
void signal_SIGSEGV_handler (int sig_num);

/* general_com.c */

/* General commands which are aviable always */

extern void help (char *command_line);
extern void set (char *command_line);
extern void set_device (char *command_line);
extern void set_offset (char *command_line);
extern void set_type (char *command_line);
extern void show (char *command_line);
extern void pgup (char *command_line);
extern void pgdn (char *command_line);
extern void redraw (char *command_line);
extern void remember (char *command_line);
extern void recall (char *command_line);
extern void cd (char *command_line);
extern void enable_write (char *command_line);
extern void disable_write (char *command_line);
extern void write_data (char *command_line);
extern void next (char *command_line);
extern void prev (char *command_line);

void hex_set (char *command_line);
void detailed_help (char *text);


/* ext2_com.c */

/* Extended2 filesystem genereal commands - Aviable only when editing an
   ext2 filesystem */

extern void type_ext2___super (char *command_line);
extern void type_ext2___group (char *command_line);
extern void type_ext2___cd (char *command_line);


/* main.c */

extern int version_major,version_minor;
extern char revision_date [80];
extern char email_address [80];

#ifdef DEBUG
extern void internal_error (char *description,char *source_name,char *function_name);
#endif

void parser (void);
extern int dispatch (char *command_line);
char *parse_word (char *source,char *dest);
char *complete_command (char *text,int state);
char *dupstr (char *src);



/* disk.c */

extern int load_type_data (void);
extern int write_type_data (void);
extern int low_read (unsigned char *buffer,unsigned long length,unsigned long offset);
extern int low_write (unsigned char *buffer,unsigned long length,unsigned long offset);
extern int log_changes (unsigned char *buffer,unsigned long length,unsigned long offset);

/* file_com.c */

extern int init_file_info (void);
extern void type_file___show (char *command_line);
extern void type_file___inode (char *command_line);
extern void type_file___display (char *command_line);
extern void type_file___prev (char *command_line);
extern void type_file___next (char *command_line);
extern void type_file___offset (char *command_line);
extern void type_file___prevblock (char *command_line);
extern void type_file___nextblock (char *command_line);
extern void type_file___block (char *command_line);
extern void type_file___remember (char *command_line);
extern void type_file___set (char *command_line);
extern void type_file___writedata (char *command_line);

extern long file_block_to_global_block (long file_block,struct struct_file_info *file_info_ptr);
extern long return_indirect (long table_block,long block_num);
extern long return_dindirect (long table_block,long block_num);
extern long return_tindirect (long table_block,long block_num);

void file_show_hex (void);
void file_show_text (void);
void show_status (void);

/* inode_com.c */

extern void type_ext2_inode___next (char *command_line);
extern void type_ext2_inode___prev (char *command_line);
extern void type_ext2_inode___show (char *command_line);
extern void type_ext2_inode___group (char *command_line);
extern void type_ext2_inode___entry (char *command_line);
extern void type_ext2_inode___file (char *command_line);
extern void type_ext2_inode___dir (char *command_line);

extern long inode_offset_to_group_num (long inode_offset);
extern long int inode_offset_to_inode_num (long inode_offset);
extern long int inode_num_to_inode_offset (long inode_num);

/* dir_com.c */

extern int init_dir_info (struct struct_file_info *info);
extern void type_dir___show (char *command_line);
extern void type_dir___inode (char *command_line);
extern void type_dir___pgdn (char *command_line);
extern void type_dir___pgup (char *command_line);
extern void type_dir___prev (char *command_line);
extern void type_dir___next (char *command_line);
extern void type_dir___followinode (char *command_line);
extern void type_dir___remember (char *command_line);
extern void type_dir___cd (char *command_line);
extern void type_dir___entry (char *command_line);
extern void type_dir___writedata (char *command_line);
extern void type_dir___set (char *command_line);

#define HEX 1
#define TEXT 2

#define ABORT		0
#define CONTINUE	1
#define FOUND		2

struct struct_file_info search_dir_entries (int (*action) (struct struct_file_info *info),int *status);
int action_count (struct struct_file_info *info);
void show_dir_status (void);
long count_dir_entries (void);
int action_name (struct struct_file_info *info);
int action_entry_num (struct struct_file_info *info);
int action_show (struct struct_file_info *info);

/* super_com.c */

extern void type_ext2_super_block___show (char *command_line);
extern void type_ext2_super_block___gocopy (char *command_line);
extern void type_ext2_super_block___setactivecopy (char *command_line);

/* group_com.c */

extern void type_ext2_group_desc___next (char *command_line);
extern void type_ext2_group_desc___prev (char *command_line);
extern void type_ext2_group_desc___entry (char *command_line);
extern void type_ext2_group_desc___show (char *command_line);
extern void type_ext2_group_desc___inode (char *command_line);
extern void type_ext2_group_desc___gocopy (char *command_line);
extern void type_ext2_group_desc___blockbitmap (char *command_line);
extern void type_ext2_group_desc___inodebitmap (char *command_line);
extern void type_ext2_group_desc___setactivecopy (char *command_line);

/* blockbitmap_com.c */

extern void type_ext2_block_bitmap___show (char *command_line);
extern void type_ext2_block_bitmap___entry (char *command_line);
extern void type_ext2_block_bitmap___next (char *command_line);
extern void type_ext2_block_bitmap___prev (char *command_line);
extern void type_ext2_block_bitmap___allocate (char *command_line);
extern void type_ext2_block_bitmap___deallocate (char *command_line);
void allocate_block (long entry_num);
void deallocate_block (long entry_num);

/* inodebitmap_bom.c */

extern void type_ext2_inode_bitmap___show (char *command_line);
extern void type_ext2_inode_bitmap___entry (char *command_line);
extern void type_ext2_inode_bitmap___next (char *command_line);
extern void type_ext2_inode_bitmap___prev (char *command_line);
extern void type_ext2_inode_bitmap___allocate (char *command_line);
extern void type_ext2_inode_bitmap___deallocate (char *command_line);
void allocate_inode (long entry_num);
void deallocate_inode (long entry_num);

/* win.c */

extern WINDOW *title_win,*show_win,*command_win,*show_pad;

extern void init_windows (void);
extern void refresh_title_win (void);
extern void refresh_show_win (void);
extern void refresh_show_pad (void);
extern void refresh_command_win (void);
extern void show_info (void);
extern void redraw_all (void);
extern void close_windows (void);

#endif /* EXT2ED_EDITOR_H */