Repository navigation
Expand file tree
/
Copy pathde.h
More file actions
executable file
·363 lines (277 loc) · 10.7 KB
/
Copy pathde.h
File metadata and controls
executable file
·363 lines (277 loc) · 10.7 KB
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
/****************************************************************/
/* */
/* de.h */
/* */
/* Definitions for the "Disk editor". */
/* */
/****************************************************************/
/* origination 1989-Jan-15 Terrence W. Holm */
/****************************************************************/
/****************************************************************/
/* */
/* de(1) */
/* */
/* This is the MINIX disk editor. It allows the user to */
/* observe and modify a file system. It can also be used */
/* to recover unlink(2)'ed files */
/* */
/* See the de(1) man page. */
/* */
/****************************************************************/
/****************************************************************/
/* */
/* de Copyright Terrence W. Holm 1989 */
/* */
/* This program was written for users of the Minix operating */
/* system, and in the spirit of other public domain software */
/* written for said system, this source code is made available */
/* at no cost to everyone. I assume no responsibility for */
/* damage to file systems caused by this program. */
/* */
/* This program (one .h, five .c's and a "man" page) may be */
/* copied and/or modified subject to (1) no charge must be */
/* made for distribution, other than for the medium, (2) all */
/* modified sources must be clearly marked as such, (3) all */
/* sources must carry this copyright. */
/* */
/****************************************************************/
/****************************************************************/
/* */
/* files */
/* */
/* de.h Definitions */
/* de.c The main loop */
/* de_stdin.c Character input routines */
/* de_stdout.c Output routines */
/* de_diskio.c File system read/write */
/* de_recover.c File restoration routines */
/* */
/* de.1 "Man" page */
/* Makefile For "make" */
/* README Installation help */
/* */
/* */
/* fs/path.c was modified to support the 'x' command. */
/* fs/link.c and fs/open.c were changed for 'X'. */
/* */
/****************************************************************/
#undef printf
#include <stdio.h>
#include <dirent.h>
/* General constants */
#define MAX_STRING 60 /* For all input lines */
#define MAX_PREV 8 /* For 'p' command */
#define SEARCH_BUFFER (4*K) /* For '/' and 'n' */
/* Files */
#define TMP "/tmp" /* For "-r" output */
#define DEV "/dev" /* Where devices are */
/* a.out header constants (see a.out.h, if you have it) */
#if (CHIP == INTEL)
#define A_OUT 0x0301
#define SPLIT 0x0420
#endif
#if (CHIP == M68000)
#define A_OUT 0x0301
#define SPLIT 0x0B20
#endif
#if (CHIP == SPARC)
#define A_OUT 0x0301
#define SPLIT 0x0B20
#endif
/* Each buffer is 1k. In WORD mode 16 words (32 bytes) can be */
/* displayed at once. In BLOCK mode 1K bytes can be displayed. */
/* In MAP mode 2048 bits (256 bytes) are displayed. */
#define K 1024 /* STD_BLK */
#define K_MASK (~(K-1)) /* Round to K boundary */
#define K_SHIFT 10 /* Ie. 1<<10 = K */
#define PAGE_MASK 0x1f /* Word mode: 32 bytes */
#define PAGE_SHIFT 5 /* Ie. 1<<5 = 32 */
#define MAP_BITS_PER_BLOCK (8 * K) /* 1k block, 8192 bits */
#define MAP_MASK 0xff /* 256 bytes/screen */
/* Terminal i/o codes */
#define CTRL_D '\004' /* ASCII ^D */
#define BELL '\007' /* ASCII bell code */
#define BS '\010' /* ASCII back space */
#define CTRL_U '\025' /* ASCII ^U */
#define ESCAPE '\033' /* ASCII escape code */
#define DEL '\177' /* ASCII delete code */
/* Input escape codes generated by the Minix console. */
/* Format: ESC [ X. */
#define ESC_HOME ('H' + 0x80)
#define ESC_UP ('A' + 0x80)
#define ESC_PGUP ('V' + 0x80)
#define ESC_LEFT ('D' + 0x80)
#define ESC_5 ('G' + 0x80)
#define ESC_RIGHT ('C' + 0x80)
#define ESC_END ('Y' + 0x80)
#define ESC_DOWN ('B' + 0x80)
#define ESC_PGDN ('U' + 0x80)
#define ESC_PLUS ('T' + 0x80)
#define ESC_MINUS ('S' + 0x80)
/* Graphic box codes - only applicable for console display */
/* in visual mode "map". */
#if (CHIP == INTEL)
#define BOX_CLR ' ' /* Empty box */
#define BOX_ALL '\333' /* Filled box */
#define BOX_TOP '\337' /* Filled upper half */
#define BOX_BOT '\334' /* Filled lower half */
#endif
#if (CHIP == M68000)
/* Please change these. */
#define BOX_CLR ' ' /* Empty box */
#define BOX_ALL '=' /* Filled box */
#define BOX_TOP '-' /* Filled upper half */
#define BOX_BOT '_' /* Filled lower half */
#endif
#if (CHIP == SPARC)
/* Please change these. */
#define BOX_CLR ' ' /* Empty box */
#define BOX_ALL '=' /* Filled box */
#define BOX_TOP '-' /* Filled upper half */
#define BOX_BOT '_' /* Filled lower half */
#endif
/* Move positions for the output display. */
#define STATUS_COLUMN 2
#define STATUS_LINE 0
#define BLOCK_COLUMN 4
#define BLOCK_LINE 4
#define INFO_COLUMN 30
#define INFO_LINE BLOCK_LINE
#define PROMPT_COLUMN 0
#define PROMPT_LINE 23
#define WARNING_COLUMN 5
#define WARNING_LINE 10
/* Values returned by Process() and Get_Filename() */
#define OK 0 /* No update required */
#define REDRAW 1 /* Redraw whole screen */
#define REDRAW_POINTERS 2 /* Redraw just ptrs */
#define ERROR 3 /* Beep */
/* Visual modes */
#define WORD 1
#define BLOCK 2
#define MAP 3
typedef unsigned short word_t; /* For most user i/o */
#if _WORD_SIZE == 2
typedef unsigned int Word_t; /* What it should always be */
#else
typedef int Word_t; /* Unsigned promotion under ANSI C */
#endif
#ifndef I_MAP_SLOTS
/* Max number of inode and zone map blocks we can handle. */
#define I_MAP_SLOTS 8
#define Z_MAP_SLOTS (sizeof(char *) == 2 ? 16 : 128)
#endif
typedef struct de_state /* State of disk ed. */
{
/* Information from super block */
/* The types here are mostly promoted types for simplicity */
/* and efficiency. */
unsigned inodes; /* Number of i-nodes */
zone_t zones; /* Total # of blocks */
unsigned inode_maps; /* I-node map blocks */
unsigned zone_maps; /* Zone map blocks */
unsigned inode_blocks; /* I-node blocks */
unsigned first_data; /* Total non-data blks */
int magic; /* Magic number */
/* Numbers derived from the magic number */
unsigned char is_fs; /* Nonzero for good fs */
unsigned char v1; /* Nonzero for V1 fs */
unsigned inode_size; /* Size of disk inode */
unsigned nr_indirects; /* # indirect blocks */
unsigned zone_num_size; /* Size of disk z num */
int block_size; /* FS block size */
/* Other derived numbers */
bit_t inodes_in_map; /* Bits in i-node map */
bit_t zones_in_map; /* Bits in zone map */
int ndzones; /* # direct zones in an inode */
/* Information from map blocks */
bitchunk_t inode_map[ I_MAP_SLOTS * K / sizeof (bitchunk_t) ];
bitchunk_t zone_map[ Z_MAP_SLOTS * K / sizeof (bitchunk_t) ];
/* Information for current block */
off_t address; /* Current address */
off_t last_addr; /* For erasing ptrs */
zone_t block; /* Current block (1K) */
unsigned offset; /* Offset within block */
char buffer[ MAX_BLOCK_SIZE ];
/* Display state */
int mode; /* WORD, BLOCK or MAP */
int output_base; /* 2, 8, 10, or 16 */
/* Search information */
char search_string[ MAX_STRING + 1 ]; /* For '/' and 'n' */
off_t prev_addr[ MAX_PREV ]; /* For 'p' command */
int prev_mode[ MAX_PREV ];
/* File information */
char *device_name; /* From command line */
int device_d;
int device_mode; /* O_RDONLY or O_RDWR */
zone_t device_size; /* Number of blocks */
char file_name[ MAX_STRING + 1 ]; /* For 'w' and 'W' */
FILE *file_f;
int file_written; /* Flag if written to */
} de_state;
/* Forward references for external routines */
/* de.c */
_PROTOTYPE(void main , (int argc , char *argv []));
_PROTOTYPE(int Process , (de_state *s , int c ));
#if __STDC__
void Error( const char *text, ... );
#else
void Error();
#endif
_PROTOTYPE(int In_Use , (bit_t bit , bitchunk_t *map ));
_PROTOTYPE(ino_t Find_Inode , (de_state *s , char *filename ));
/* de_stdin.c */
_PROTOTYPE(void Save_Term , (void));
_PROTOTYPE(void Set_Term , (void));
_PROTOTYPE(void Reset_Term , (void));
_PROTOTYPE(int Get_Char , (void));
_PROTOTYPE(char *Get_Line , (void));
_PROTOTYPE(int Arrow_Esc , (int c ));
/* de_stdout.c */
_PROTOTYPE(int Init_Termcap , (void));
_PROTOTYPE(void Draw_Help_Screen , (de_state *s ));
_PROTOTYPE(void Wait_For_Key , (void));
_PROTOTYPE(void Draw_Prompt , (char *string ));
_PROTOTYPE(void Erase_Prompt , (void));
_PROTOTYPE(void Draw_Screen , (de_state *s ));
_PROTOTYPE(void Draw_Strings , (de_state *s ));
_PROTOTYPE(void Draw_Pointers , (de_state *s ));
_PROTOTYPE(void Print_Ascii , (int c ));
_PROTOTYPE(void Goto , (int column , int line ));
_PROTOTYPE(void Block_Type , (de_state *s ));
_PROTOTYPE(void Draw_Words , (de_state *s ));
_PROTOTYPE(void Draw_Info , (de_state *s ));
_PROTOTYPE(void Draw_Block , (char *block ));
_PROTOTYPE(void Draw_Map , (char *block , int max_bits ));
_PROTOTYPE(void Draw_Offset , (de_state *s ));
_PROTOTYPE(void Word_Pointers , (off_t old_addr , off_t new_addr ));
_PROTOTYPE(void Block_Pointers , (off_t old_addr , off_t new_addr ));
_PROTOTYPE(void Map_Pointers , (off_t old_addr , off_t new_addr ));
_PROTOTYPE(void Print_Number , (Word_t number , int output_base ));
_PROTOTYPE(void Draw_Zone_Numbers , (de_state *s , struct inode *inode ,
int zindex , int zrow ));
#if __STDC__
void Warning( const char *text, ... );
#else
void Warning();
#endif
/* de_diskio.c */
_PROTOTYPE(void Read_Disk , (de_state *s , off_t block_addr , char *buffer ));
_PROTOTYPE(void Read_Block , (de_state *s , char *buffer ));
_PROTOTYPE(void Read_Super_Block , (de_state *s ));
_PROTOTYPE(void Read_Bit_Maps , (de_state *s ));
_PROTOTYPE(off_t Search , (de_state *s , char *string ));
_PROTOTYPE(void Write_Word , (de_state *s , Word_t word ));
/* de_recover.c */
_PROTOTYPE(int Path_Dir_File , (char *path_name , char **dir_name ,
char **file_name ));
_PROTOTYPE(char *File_Device , (char *file_name ));
_PROTOTYPE(ino_t Find_Deleted_Entry , (de_state *s , char *path_name ));
_PROTOTYPE(off_t Recover_Blocks , (de_state *s ));
#undef printf /* Because fs/const.h */
/* defines it. */
/* Static functions are all pre-declared FORWARD but none are */
/* declared static yet - this can wait until all functions are */
/* declared with prototypes. */
#undef FORWARD
#define FORWARD /* static */