home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / UZI.ARK / UNIX.H < prev    next >
Text File  |  1988-11-30  |  11KB  |  378 lines

  1. /**************************************************
  2. UZI (Unix Z80 Implementation) Kernel:  unix.h
  3. ***************************************************/
  4.  
  5.  
  6. #ifndef vax
  7. #define CPM
  8. #endif
  9.  
  10. #define UFTSIZE 10    /* Number of user files */
  11. #define OFTSIZE 15    /* Open file table size */
  12. #define ITABSIZE 20   /* Inode table size */
  13. #define PTABSIZE 20   /* Process table size */
  14.  
  15. #define NSIGS 16        /* Number of signals <= 16 */
  16.  
  17. #define ROOTINODE 1  /* Inode # of /  for all mounted filesystems. */
  18.  
  19. #define TICKSPERSEC 10  /*Ticks per second */
  20. #define MAXTICKS   10   /* Max ticks before swapping out (time slice) */
  21.  
  22. #define ARGBLK 0        /* Block number on SWAPDEV for arguments */
  23. #define PROGBASE ((char *)(0x100))
  24. #define MAXEXEC 0       /* Max no of blks of executable file */
  25.  
  26. #define EMAGIC 0xc3     /* Header of executable */
  27. #define CMAGIC 24721    /* Random number for cinode c_magic */
  28. #define SMOUNTED 12742  /* Magic number to specify mounted filesystem */
  29. #define NULL 0
  30.  
  31.  
  32. /* These macros are simply to trick the compiler into generating
  33.    more compact code. */
  34.  
  35. #define ifnull(e) if(e){}else
  36. #define ifnot(e) if(e){}else
  37. #define ifzero(e) if(e){}else
  38.  
  39.  
  40.  
  41. #ifdef CPM
  42.     typedef unsigned uint16;
  43.     typedef int int16;
  44. #else
  45.     typedef unsigned short uint16;
  46.     typedef short int16;
  47. #endif
  48.  
  49.  
  50. typedef struct s_queue {
  51.     char *q_base;   /* Pointer to data */
  52.     char *q_head;  /* Pointer to addr of next char to read. */
  53.     char *q_tail;  /* Pointer to where next char to insert goes. */
  54.     int q_size; /* Max size of queue */
  55.     int q_count;        /* How many characters presently in queue */
  56.     int q_wakeup;       /* Threshold for waking up processes waiting on queue */
  57. } queue_t;
  58.  
  59.  
  60.  
  61. typedef struct time_s {
  62.     uint16 t_time;
  63.     uint16 t_date;
  64. } time_t;
  65.  
  66.  
  67. /* User's structure for times() system call */
  68.  
  69. struct tms {
  70.     time_t  tms_utime;
  71.     time_t  tms_stime;
  72.     time_t  tms_cutime;
  73.     time_t  tms_cstime;
  74.     time_t  tms_etime;      /* Elapsed real time */
  75. } ;
  76.  
  77.  
  78. /* Flags for setftime() */
  79. #define A_TIME 1
  80. #define M_TIME 2
  81. #define C_TIME 4
  82.  
  83.  
  84. typedef struct off_t {
  85.     uint16 o_blkno;  /* Block number */
  86.     int16 o_offset;     /* Offset within block 0-511 */
  87. } off_t;
  88.  
  89.  
  90. typedef uint16 blkno_t;  /* Can have 65536 512-byte blocks in filesystem */
  91. #define NULLBLK ((blkno_t)-1)
  92.  
  93.  
  94. typedef struct blkbuf {
  95.     char        bf_data[512];    /* This MUST be first ! */
  96.     char        bf_dev;
  97.     blkno_t     bf_blk;
  98.     char        bf_dirty;
  99.     char        bf_busy;
  100.     uint16      bf_time;        /* LRU time stamp */
  101. /*    struct blkbuf *bf_next;    /* LRU free list pointer */
  102. } blkbuf, *bufptr;
  103.  
  104.  
  105. typedef struct dinode {
  106.     uint16 i_mode;
  107.     uint16 i_nlink;
  108.     uint16 i_uid;
  109.     uint16 i_gid;
  110.     off_t    i_size;
  111.     time_t   i_atime;
  112.     time_t   i_mtime;
  113.     time_t   i_ctime;
  114.     blkno_t  i_addr[20];
  115. } dinode;               /* Exactly 64 bytes long! */
  116.  
  117.  
  118. struct  stat    /* Really only used by users */
  119. {
  120.     int16   st_dev;
  121.     uint16  st_ino;
  122.     uint16  st_mode;
  123.     uint16  st_nlink;
  124.     uint16  st_uid;
  125.     uint16  st_gid;
  126.     uint16  st_rdev;
  127.     off_t   st_size;
  128.     time_t  st_atime;
  129.     time_t  st_mtime;
  130.     time_t  st_ctime;
  131. };
  132.  
  133. /* Bit masks for i_mode and st_mode */
  134.  
  135. #define OTH_EX  0001
  136. #define OTH_WR  0002
  137. #define OTH_RD  0004
  138. #define GRP_EX  0010
  139. #define GRP_WR  0020
  140. #define GRP_RD  0040
  141. #define OWN_EX  0100
  142. #define OWN_WR  0200
  143. #define OWN_RD  0400
  144.  
  145. #define SAV_TXT 01000
  146. #define SET_GID 02000
  147. #define SET_UID 04000
  148.  
  149. #define MODE_MASK 07777
  150.  
  151. #define F_REG  0100000
  152. #define F_DIR   040000
  153. #define F_PIPE  010000
  154. #define F_BDEV  060000
  155. #define F_CDEV  020000
  156.  
  157. #define F_MASK  0170000
  158.  
  159.  
  160.  
  161. typedef struct cinode {
  162.     int    c_magic;             /* Used to check for corruption. */
  163.     int    c_dev;               /* Inode's device */
  164.     unsigned   c_num;           /* Inode # */
  165.     dinode   c_node;
  166.     char     c_refs;            /* In-core reference count */
  167.     char     c_dirty;           /* Modified flag. */
  168. } cinode, *inoptr;
  169.  
  170. #define NULLINODE ((inoptr)NULL)
  171. #define NULLINOPTR ((inoptr*)NULL)
  172.  
  173.  
  174. typedef struct direct {
  175.     uint16 d_ino;
  176.     char     d_name[14];
  177. } direct;
  178.  
  179.  
  180.  
  181. typedef struct filesys {
  182.     int16       s_mounted;
  183.     uint16      s_isize;
  184.     uint16      s_fsize;
  185.     int16       s_nfree;
  186.     blkno_t     s_free[50];
  187.     int16       s_ninode;
  188.     uint16      s_inode[50];
  189.     int16       s_fmod;
  190.     time_t      s_time;
  191.     blkno_t     s_tfree;
  192.     uint16      s_tinode;
  193.     inoptr      s_mntpt; /* Mount point */
  194. } filesys, *fsptr;
  195.  
  196. typedef struct oft {
  197.     off_t       o_ptr;   /* File position point16er */
  198.     inoptr      o_inode; /* Pointer into in-core inode table */
  199.     char        o_access; /* O_RDONLY, O_WRONLY, or O_RDWR */
  200.     char        o_refs;  /* Reference count: depends on # of active children*/
  201. } oft;
  202.  
  203.  
  204. /* Process table p_status values */
  205.  
  206. #define P_EMPTY         0    /* Unused slot */
  207. #define P_RUNNING       1    /* Currently running process */
  208. #define P_READY         2    /* Runnable   */
  209. #define P_SLEEP         3    /* Sleeping; can be awakened by signal */
  210. #define P_XSLEEP        4    /* Sleeping, don't wake up for signal */
  211. #define P_PAUSE         5    /* Sleeping for pause(); can wakeup for signal */
  212. #define P_FORKING       6    /* In process of forking; do not mess with */
  213. #define P_WAIT          7    /* Executed a wait() */
  214. #define P_ZOMBIE        8    /* Exited. */
  215.  
  216.  
  217. #define SIGHUP  1       
  218. #define SIGINT  2      
  219. #define SIGQUIT 3     
  220. #define SIGILL  4    
  221. #define SIGTRAP 5   
  222. #define SIGIOT  6  
  223. #define SIGEMT  7 
  224. #define SIGFPE  8 
  225. #define SIGKILL 9
  226. #define SIGBUS  10
  227. #define SIGSEGV 11
  228. #define SIGSYS  12
  229. #define SIGPIPE 13
  230. #define SIGALRM 14
  231. #define SIGTERM 15
  232.  
  233. #define SIG_DFL         (int (*)())0
  234. #define SIG_IGN         (int (*)())1
  235.  
  236. #define sigmask(sig)    (1<<(sig))
  237.  
  238. /* Process table entry */
  239.  
  240. typedef struct p_tab {
  241.     char        p_status;       /* Process status */
  242.     int p_pid;    /* Process ID */
  243.     int p_uid;
  244.     struct p_tab *p_pptr;    /* Process parent's table entry */
  245.     blkno_t     p_swap;   /* Starting block of swap space */
  246.     unsigned    p_alarm;        /* Seconds until alarm goes off */
  247.     unsigned    p_exitval;      /* Exit value */
  248.     /* Everything below here is overlaid by time info at exit */
  249.     char       *p_wait;         /* Address of thing waited for */
  250.     int p_priority;     /* Process priority */
  251.     uint16      p_pending;      /* Pending signals */
  252.     uint16      p_ignored;      /* Ignored signals */
  253. } p_tab, *ptptr;
  254.  
  255. /* Per-process data (Swapped with process) */
  256.  
  257. #asm 8080
  258. ?OSYS equ 2     ;byte offsets of elements of u_data
  259. ?OCALL equ 3
  260. ?ORET equ 4     ;return location
  261. ?ORVAL equ 6    ;return value
  262. ?OERR equ 8     ;error number
  263. ?OSP equ 10     ;users stack pointer
  264. ?OBC equ 12     ;users frame pointer
  265. #endasm
  266.  
  267. typedef struct u_data {
  268.     struct p_tab *u_ptab;       /* Process table pointer */
  269.     char        u_insys;        /* True if in kernel */
  270.     char        u_callno;       /* sys call being executed. */
  271.     char        *u_retloc;     /* Return location from sys call */
  272.     int         u_retval;       /* Return value from sys call */
  273.     int         u_error;                /* Last error number */
  274.     char        *u_sp;          /* Used when a process is swapped. */
  275.     char        *u_bc;          /* Place to save user's frame pointer */
  276.     int         u_argn;         /* Last arg */
  277.     int         u_argn1;        /* This way because args on stack backwards */
  278.     int         u_argn2;
  279.     int         u_argn3;        /* args n-3, n-2, n-1, and n */
  280.  
  281.     char *      u_base;         /* Source or dest for I/O */
  282.     unsigned    u_count;        /* Amount for I/O */
  283.     off_t       u_offset;       /* Place in file for I/O */
  284.     struct blkbuf *u_buf;
  285.  
  286.     int         u_gid;
  287.     int         u_euid;
  288.     int         u_egid;
  289.     int         u_mask;         /* umask: file creation mode mask */
  290.     time_t      u_time;         /* Start time */
  291.     char        u_files[UFTSIZE];       /* Process file table:
  292.                             contains indexes into open file table. */
  293.     inoptr      u_cwd;          /* Index into inode table of cwd. */
  294.     char        *u_break;        /* Top of data space */
  295.  
  296.     inoptr      u_ino;  /* Used during execve() */
  297.     char        *u_isp;  /* Value of initial sp (argv) */
  298.  
  299.     int         (*u_sigvec[NSIGS])();   /* Array of signal vectors */
  300.     int         u_cursig;       /* Signal currently being caught */
  301.     char        u_name[8];      /* Name invoked with */
  302.     time_t      u_utime;        /* Elapsed ticks in user mode */
  303.     time_t      u_stime;        /* Ticks in system mode */
  304.     time_t      u_cutime;       /* Total childrens ticks */
  305.     time_t      u_cstime;
  306.  
  307. } u_data;
  308.  
  309.  
  310. /* Struct to temporarily hold arguments in execve */
  311. struct s_argblk {
  312.     int a_argc;
  313.     int a_arglen;
  314.     int a_envc;
  315.     char a_buf[512-3*sizeof(int)];
  316. };
  317.  
  318.  
  319. /* The device driver switch table */
  320.  
  321. typedef struct devsw {
  322.     int minor;          /* The minor device number (an argument to below) */
  323.     int (*dev_open)();  /* The routines for reading, etc */
  324.     int (*dev_close)(); /* format: op(minor,blkno,offset,count,buf); */
  325.     int (*dev_read)();  /* offset would be ignored for block devices */
  326.     int (*dev_write)(); /* blkno and offset ignored for tty, etc. */
  327.     int (*dev_ioctl)(); /* count is rounded to 512 for block devices */
  328. } devsw;
  329.  
  330.  
  331.  
  332. /* Open() parameters. */
  333.  
  334. #define O_RDONLY        0
  335. #define O_WRONLY        1
  336. #define O_RDWR          2
  337.  
  338. /*
  339.  * Error codes
  340.  */
  341.  
  342. #define EPERM           1               
  343. #define ENOENT          2               
  344. #define ESRCH           3               
  345. #define EINTR           4               
  346. #define EIO             5               
  347. #define ENXIO           6               
  348. #define E2BIG           7               
  349. #define ENOEXEC         8               
  350. #define EBADF           9               
  351. #define ECHILD          10              
  352. #define EAGAIN          11              
  353. #define ENOMEM          12              
  354. #define EACCES          13              
  355. #define EFAULT          14              
  356. #define ENOTBLK         15              
  357. #define EBUSY           16              
  358. #define EEXIST          17              
  359. #define EXDEV           18              
  360. #define ENODEV          19              
  361. #define ENOTDIR         20              
  362. #define EISDIR          21              
  363. #define EINVAL          22              
  364. #define ENFILE          23              
  365. #define EMFILE          24              
  366. #define ENOTTY          25              
  367. #define ETXTBSY         26              
  368. #define EFBIG           27              
  369. #define ENOSPC          28              
  370. #define ESPIPE          29              
  371. #define EROFS           30              
  372. #define EMLINK          31              
  373. #define EPIPE           32              
  374. #define ENAMETOOLONG    63              
  375.  
  376. #include "config.h"
  377.  
  378.