-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunix.h
377 lines (297 loc) · 10.6 KB
/
unix.h
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
/**************************************************
UZI (Unix Z80 Implementation) Kernel: unix.h
***************************************************/
#ifndef vax
#define CPM
#endif
#define UFTSIZE 10 /* Number of user files */
#define OFTSIZE 15 /* Open file table size */
#define ITABSIZE 20 /* Inode table size */
#define PTABSIZE 20 /* Process table size */
#define NSIGS 16 /* Number of signals <= 16 */
#define ROOTINODE 1 /* Inode # of / for all mounted filesystems. */
#define TICKSPERSEC 10 /*Ticks per second */
#define MAXTICKS 10 /* Max ticks before swapping out (time slice) */
#define ARGBLK 0 /* Block number on SWAPDEV for arguments */
#define PROGBASE ((char *)(0x100))
#define MAXEXEC 0 /* Max no of blks of executable file */
#define EMAGIC 0xc3 /* Header of executable */
#define CMAGIC 24721 /* Random number for cinode c_magic */
#define SMOUNTED 12742 /* Magic number to specify mounted filesystem */
#define NULL 0
/* These macros are simply to trick the compiler into generating
more compact code. */
#define ifnull(e) if(e){}else
#define ifnot(e) if(e){}else
#define ifzero(e) if(e){}else
#ifdef CPM
typedef unsigned uint16;
typedef int int16;
#else
typedef unsigned short uint16;
typedef short int16;
#endif
typedef struct s_queue {
char *q_base; /* Pointer to data */
char *q_head; /* Pointer to addr of next char to read. */
char *q_tail; /* Pointer to where next char to insert goes. */
int q_size; /* Max size of queue */
int q_count; /* How many characters presently in queue */
int q_wakeup; /* Threshold for waking up processes waiting on queue */
} queue_t;
typedef struct time_s {
uint16 t_time;
uint16 t_date;
} time_t;
/* User's structure for times() system call */
struct tms {
time_t tms_utime;
time_t tms_stime;
time_t tms_cutime;
time_t tms_cstime;
time_t tms_etime; /* Elapsed real time */
} ;
/* Flags for setftime() */
#define A_TIME 1
#define M_TIME 2
#define C_TIME 4
typedef struct off_t {
uint16 o_blkno; /* Block number */
int16 o_offset; /* Offset within block 0-511 */
} off_t;
typedef uint16 blkno_t; /* Can have 65536 512-byte blocks in filesystem */
#define NULLBLK ((blkno_t)-1)
typedef struct blkbuf {
char bf_data[512]; /* This MUST be first ! */
char bf_dev;
blkno_t bf_blk;
char bf_dirty;
char bf_busy;
uint16 bf_time; /* LRU time stamp */
/* struct blkbuf *bf_next; /* LRU free list pointer */
} blkbuf, *bufptr;
typedef struct dinode {
uint16 i_mode;
uint16 i_nlink;
uint16 i_uid;
uint16 i_gid;
off_t i_size;
time_t i_atime;
time_t i_mtime;
time_t i_ctime;
blkno_t i_addr[20];
} dinode; /* Exactly 64 bytes long! */
struct stat /* Really only used by users */
{
int16 st_dev;
uint16 st_ino;
uint16 st_mode;
uint16 st_nlink;
uint16 st_uid;
uint16 st_gid;
uint16 st_rdev;
off_t st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
};
/* Bit masks for i_mode and st_mode */
#define OTH_EX 0001
#define OTH_WR 0002
#define OTH_RD 0004
#define GRP_EX 0010
#define GRP_WR 0020
#define GRP_RD 0040
#define OWN_EX 0100
#define OWN_WR 0200
#define OWN_RD 0400
#define SAV_TXT 01000
#define SET_GID 02000
#define SET_UID 04000
#define MODE_MASK 07777
#define F_REG 0100000
#define F_DIR 040000
#define F_PIPE 010000
#define F_BDEV 060000
#define F_CDEV 020000
#define F_MASK 0170000
typedef struct cinode {
int c_magic; /* Used to check for corruption. */
int c_dev; /* Inode's device */
unsigned c_num; /* Inode # */
dinode c_node;
char c_refs; /* In-core reference count */
char c_dirty; /* Modified flag. */
} cinode, *inoptr;
#define NULLINODE ((inoptr)NULL)
#define NULLINOPTR ((inoptr*)NULL)
typedef struct direct {
uint16 d_ino;
char d_name[14];
} direct;
typedef struct filesys {
int16 s_mounted;
uint16 s_isize;
uint16 s_fsize;
int16 s_nfree;
blkno_t s_free[50];
int16 s_ninode;
uint16 s_inode[50];
int16 s_fmod;
time_t s_time;
blkno_t s_tfree;
uint16 s_tinode;
inoptr s_mntpt; /* Mount point */
} filesys, *fsptr;
typedef struct oft {
off_t o_ptr; /* File position point16er */
inoptr o_inode; /* Pointer into in-core inode table */
char o_access; /* O_RDONLY, O_WRONLY, or O_RDWR */
char o_refs; /* Reference count: depends on # of active children*/
} oft;
/* Process table p_status values */
#define P_EMPTY 0 /* Unused slot */
#define P_RUNNING 1 /* Currently running process */
#define P_READY 2 /* Runnable */
#define P_SLEEP 3 /* Sleeping; can be awakened by signal */
#define P_XSLEEP 4 /* Sleeping, don't wake up for signal */
#define P_PAUSE 5 /* Sleeping for pause(); can wakeup for signal */
#define P_FORKING 6 /* In process of forking; do not mess with */
#define P_WAIT 7 /* Executed a wait() */
#define P_ZOMBIE 8 /* Exited. */
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGIOT 6
#define SIGEMT 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGBUS 10
#define SIGSEGV 11
#define SIGSYS 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIG_DFL (int (*)())0
#define SIG_IGN (int (*)())1
#define sigmask(sig) (1<<(sig))
/* Process table entry */
typedef struct p_tab {
char p_status; /* Process status */
int p_pid; /* Process ID */
int p_uid;
struct p_tab *p_pptr; /* Process parent's table entry */
blkno_t p_swap; /* Starting block of swap space */
unsigned p_alarm; /* Seconds until alarm goes off */
unsigned p_exitval; /* Exit value */
/* Everything below here is overlaid by time info at exit */
char *p_wait; /* Address of thing waited for */
int p_priority; /* Process priority */
uint16 p_pending; /* Pending signals */
uint16 p_ignored; /* Ignored signals */
} p_tab, *ptptr;
/* Per-process data (Swapped with process) */
#asm 8080
?OSYS equ 2 ;byte offsets of elements of u_data
?OCALL equ 3
?ORET equ 4 ;return location
?ORVAL equ 6 ;return value
?OERR equ 8 ;error number
?OSP equ 10 ;users stack pointer
?OBC equ 12 ;users frame pointer
#endasm
typedef struct u_data {
struct p_tab *u_ptab; /* Process table pointer */
char u_insys; /* True if in kernel */
char u_callno; /* sys call being executed. */
char *u_retloc; /* Return location from sys call */
int u_retval; /* Return value from sys call */
int u_error; /* Last error number */
char *u_sp; /* Used when a process is swapped. */
char *u_bc; /* Place to save user's frame pointer */
int u_argn; /* Last arg */
int u_argn1; /* This way because args on stack backwards */
int u_argn2;
int u_argn3; /* args n-3, n-2, n-1, and n */
char * u_base; /* Source or dest for I/O */
unsigned u_count; /* Amount for I/O */
off_t u_offset; /* Place in file for I/O */
struct blkbuf *u_buf;
int u_gid;
int u_euid;
int u_egid;
int u_mask; /* umask: file creation mode mask */
time_t u_time; /* Start time */
char u_files[UFTSIZE]; /* Process file table:
contains indexes into open file table. */
inoptr u_cwd; /* Index into inode table of cwd. */
char *u_break; /* Top of data space */
inoptr u_ino; /* Used during execve() */
char *u_isp; /* Value of initial sp (argv) */
int (*u_sigvec[NSIGS])(); /* Array of signal vectors */
int u_cursig; /* Signal currently being caught */
char u_name[8]; /* Name invoked with */
time_t u_utime; /* Elapsed ticks in user mode */
time_t u_stime; /* Ticks in system mode */
time_t u_cutime; /* Total childrens ticks */
time_t u_cstime;
} u_data;
/* Struct to temporarily hold arguments in execve */
struct s_argblk {
int a_argc;
int a_arglen;
int a_envc;
char a_buf[512-3*sizeof(int)];
};
/* The device driver switch table */
typedef struct devsw {
int minor; /* The minor device number (an argument to below) */
int (*dev_open)(); /* The routines for reading, etc */
int (*dev_close)(); /* format: op(minor,blkno,offset,count,buf); */
int (*dev_read)(); /* offset would be ignored for block devices */
int (*dev_write)(); /* blkno and offset ignored for tty, etc. */
int (*dev_ioctl)(); /* count is rounded to 512 for block devices */
} devsw;
/* Open() parameters. */
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
/*
* Error codes
*/
#define EPERM 1
#define ENOENT 2
#define ESRCH 3
#define EINTR 4
#define EIO 5
#define ENXIO 6
#define E2BIG 7
#define ENOEXEC 8
#define EBADF 9
#define ECHILD 10
#define EAGAIN 11
#define ENOMEM 12
#define EACCES 13
#define EFAULT 14
#define ENOTBLK 15
#define EBUSY 16
#define EEXIST 17
#define EXDEV 18
#define ENODEV 19
#define ENOTDIR 20
#define EISDIR 21
#define EINVAL 22
#define ENFILE 23
#define EMFILE 24
#define ENOTTY 25
#define ETXTBSY 26
#define EFBIG 27
#define ENOSPC 28
#define ESPIPE 29
#define EROFS 30
#define EMLINK 31
#define EPIPE 32
#define ENAMETOOLONG 63
#include "config.h"