home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / filesy~1 / mfs610s.zoo / minixfs / filesys.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-07  |  15.2 KB  |  495 lines

  1. /*
  2.  * NOTE: This file only works if sizeof(int) == 2!
  3.  * UNLESS: you have an ANSI compiler and use prototypes
  4.  *
  5.  * Copyright 1991,1992 Eric R. Smith. This file may be re-distributed
  6.  * as long as this notice remains intact.
  7.  */
  8.  
  9. #ifndef _filesys_h
  10. #define _filesys_h
  11.  
  12. #ifndef P_
  13. # ifdef __STDC__
  14. #  define P_(x) x
  15. # else
  16. #  define P_(x) ()
  17. # endif
  18. #endif
  19.  
  20. #ifdef _SHORTINT
  21. #define _wORD int
  22. #endif
  23.  
  24. #ifndef _wORD
  25. #ifdef __MSHORT__        /* 16 bit integers? */
  26. #define _wORD int
  27. #else
  28. #define _wORD short
  29. #endif
  30. #endif
  31.  
  32. #define NAME_MAX 32
  33. #define PATH_MAX 128
  34.  
  35. struct filesys;        /* forward declaration */
  36. struct devdrv;        /* ditto */
  37.  
  38. /* structure for timeouts, the `void*'s are really `struct proc *'s */
  39. typedef struct timeout {
  40.     struct timeout    *next;
  41.     void    *proc;
  42.     long    when;
  43.     void    (*func) (void *); /* function to call at timeout */
  44.     short    flags;
  45. } TIMEOUT;
  46.  
  47. typedef struct f_cookie {
  48.     struct filesys *fs;    /* filesystem that knows about this cookie */
  49.     unsigned short    dev;        /* device info (e.g. Rwabs device number) */
  50.     unsigned short    aux;        /* extra data that the file system may want */
  51.     long    index;        /* this+dev uniquely identifies a file */
  52. } fcookie;
  53.  
  54. /* structure for opendir/readdir/closedir */
  55. typedef struct dirstruct {
  56.     fcookie fc;        /* cookie for this directory */
  57.     unsigned short    index;        /* index of the current entry */
  58.     unsigned short    flags;        /* flags (e.g. tos or not) */
  59. #define TOS_SEARCH    0x01
  60.     char    fsstuff[60];    /* anything else the file system wants */
  61.                 /* NOTE: this must be at least 45 bytes */
  62. } DIR;
  63.  
  64. /* structure for getxattr */
  65. typedef struct xattr {
  66.     unsigned short    mode;
  67. /* file types */
  68. #define S_IFMT    0170000        /* mask to select file type */
  69. #define S_IFCHR    0020000        /* BIOS special file */
  70. #define S_IFDIR    0040000        /* directory file */
  71. #define S_IFREG 0100000        /* regular file */
  72. #define S_IFIFO 0120000        /* FIFO */
  73. #define S_IMEM    0140000        /* memory region or process */
  74. #define S_IFLNK    0160000        /* symbolic link */
  75.  
  76. /* special bits: setuid, setgid, sticky bit */
  77. #define S_ISUID    04000
  78. #define S_ISGID 02000
  79. #define S_ISVTX    01000
  80.  
  81. /* file access modes for user, group, and other*/
  82. #define S_IRUSR    0400
  83. #define S_IWUSR 0200
  84. #define S_IXUSR 0100
  85. #define S_IRGRP 0040
  86. #define S_IWGRP    0020
  87. #define S_IXGRP    0010
  88. #define S_IROTH    0004
  89. #define S_IWOTH    0002
  90. #define S_IXOTH    0001
  91. #define DEFAULT_DIRMODE (0777)
  92. #define DEFAULT_MODE    (0666)
  93.     long    index;
  94.     unsigned short    dev;
  95.     unsigned short    rdev;
  96.     unsigned short    nlink;
  97.     unsigned short    uid;
  98.     unsigned short    gid;
  99.     long    size;
  100.     long    blksize, nblocks;
  101.     short    mtime, mdate;
  102.     short    atime, adate;
  103.     short    ctime, cdate;
  104.     short    attr;
  105.     short    reserved2;
  106.     long    reserved3[2];
  107. } XATTR;
  108.  
  109. typedef struct fileptr {
  110.     short    links;        /* number of copies of this descriptor */
  111.     unsigned short    flags;        /* file open mode and other file flags */
  112.     long    pos;        /* position in file */
  113.     long    devinfo;    /* device driver specific info */
  114.     fcookie    fc;        /* file system cookie for this file */
  115.     struct devdrv *dev; /* device driver that knows how to deal with this */
  116.     struct fileptr *next; /* link to next fileptr for this file */
  117. } FILEPTR;
  118.  
  119. /* lock structure */
  120. struct flock {
  121.     short l_type;            /* type of lock */
  122. #define F_RDLCK        O_RDONLY
  123. #define F_WRLCK        O_WRONLY
  124. #define F_UNLCK        3
  125.     short l_whence;            /* SEEK_SET, SEEK_CUR, SEEK_END */
  126.     long l_start;            /* start of locked region */
  127.     long l_len;            /* length of locked region */
  128.     short l_pid;            /* pid of locking process
  129.                         (F_GETLK only) */
  130. };
  131.  
  132. /* LOCK structure used by the kernel internally */
  133.  
  134. typedef struct ilock {
  135.     struct flock l;
  136.     struct ilock *next;
  137.     long  reserved[4];
  138. } LOCK;
  139.  
  140. typedef struct devdrv {
  141.     long (*open)    P_((FILEPTR *f));
  142.     long (*write)    P_((FILEPTR *f, char *buf, long bytes));
  143.     long (*read)    P_((FILEPTR *f, char *buf, long bytes));
  144.     long (*lseek)    P_((FILEPTR *f, long where, _wORD whence));
  145.     long (*ioctl)    P_((FILEPTR *f, _wORD mode, void *buf));
  146.     long (*datime)    P_((FILEPTR *f, _wORD *timeptr, _wORD rwflag));
  147.     long (*close)    P_((FILEPTR *f, _wORD pid));
  148.     long (*select)    P_((FILEPTR *f, long proc, _wORD mode));
  149.     void (*unselect) P_((FILEPTR *f, long proc, _wORD mode));
  150.     long    reserved[3];    /* reserved for future use */
  151. } DEVDRV;
  152.  
  153. typedef struct filesys {
  154.     struct    filesys    *next;    /* link to next file system on chain */
  155.     long    fsflags;
  156. #define FS_KNOPARSE    0x01    /* kernel shouldn't do parsing */
  157. #define FS_CASESENSITIVE    0x02    /* file names are case sensitive */
  158. #define FS_NOXBIT    0x04    /* if a file can be read, it can be executed */
  159. #define    FS_LONGPATH    0x08    /* file system understands "size" argument to
  160.                    "getname" */
  161.  
  162.     long    (*root) P_((_wORD drv, fcookie *fc));
  163.     long    (*lookup) P_((fcookie *dir, char *name, fcookie *fc));
  164.     long    (*creat) P_((fcookie *dir, char *name, unsigned _wORD mode,
  165.                 _wORD attrib, fcookie *fc));
  166.     DEVDRV *(*getdev) P_((fcookie *fc, long *devspecial));
  167.     long    (*getxattr) P_((fcookie *fc, XATTR *xattr));
  168.     long    (*chattr) P_((fcookie *fc, _wORD attr));
  169.     long    (*chown) P_((fcookie *fc, _wORD uid, _wORD gid));
  170.     long    (*chmode) P_((fcookie *fc, unsigned _wORD mode));
  171.     long    (*mkdir) P_((fcookie *dir, char *name, unsigned _wORD mode));
  172.     long    (*rmdir) P_((fcookie *dir, char *name));
  173.     long    (*remove) P_((fcookie *dir, char *name));
  174.     long    (*getname) P_((fcookie *relto, fcookie *dir, char *pathname,
  175.                 _wORD size));
  176.     long    (*rename) P_((fcookie *olddir, char *oldname,
  177.                 fcookie *newdir, char *newname));
  178.     long    (*opendir) P_((DIR *dirh, _wORD tosflag));
  179.     long    (*readdir) P_((DIR *dirh, char *nm, _wORD nmlen, fcookie *fc));
  180.     long    (*rewinddir) P_((DIR *dirh));
  181.     long    (*closedir) P_((DIR *dirh));
  182.     long    (*pathconf) P_((fcookie *dir, _wORD which));
  183.     long    (*dfree) P_((fcookie *dir, long *buf));
  184.     long    (*writelabel) P_((fcookie *dir, char *name));
  185.     long    (*readlabel) P_((fcookie *dir, char *name, _wORD namelen));
  186.     long    (*symlink) P_((fcookie *dir, char *name, char *to));
  187.     long    (*readlink) P_((fcookie *dir, char *buf, _wORD len));
  188.     long    (*hardlink) P_((fcookie *fromdir, char *fromname,
  189.                 fcookie *todir, char *toname));
  190.     long    (*fscntl) P_((fcookie *dir, char *name, _wORD cmd, long arg));
  191.     long    (*dskchng) P_((_wORD drv));
  192.     long    (*release) P_((fcookie *fc));
  193.     long    (*dupcookie) P_((fcookie *dest, fcookie *src));
  194.  
  195. } FILESYS;
  196.  
  197. /*
  198.  * this is the structure passed to loaded file systems to tell them
  199.  * about the kernel
  200.  */
  201.  
  202. typedef long (*_LongFunc)();
  203.  
  204. struct kerinfo {
  205.     short    maj_version;    /* kernel version number */
  206.     short    min_version;    /* minor kernel version number */
  207.     unsigned short default_mode;    /* default file access mode */
  208.     short    reserved1;    /* room for expansion */
  209.  
  210. /* OS functions */
  211.     _LongFunc *bios_tab;     /* pointer to the BIOS entry points */
  212.     _LongFunc *dos_tab;    /* pointer to the GEMDOS entry points */
  213.  
  214. /* media change vector */
  215.     void    (*drvchng) P_((short));
  216.  
  217. /* Debugging stuff */
  218.     void    (*trace) P_((char *, ...));
  219.     void    (*debug) P_((char *, ...));
  220.     void    (*alert) P_((char *, ...));
  221.     void    (*fatal) P_((char *, ...));
  222.  
  223. /* memory allocation functions */
  224.     void *    (*kmalloc) P_((long));
  225.     void    (*kfree) P_((void *));
  226.     void *    (*umalloc) P_((long));
  227.     void    (*ufree) P_((void *));
  228.  
  229. /* utility functions for string manipulation */
  230.     short    (*strnicmp) P_((char *, char *, _wORD));
  231.     short    (*stricmp) P_((char *, char *));
  232.     char *    (*strlwr) P_((char *));
  233.     char *    (*strupr) P_((char *));
  234.     short    (*sprintf) P_((char *, char *, ...));
  235.  
  236. /* utility functions for manipulating time */
  237.     void    (*millis_time) P_((unsigned long, _wORD *));
  238.     long    (*unixtim) P_((unsigned _wORD, unsigned _wORD));
  239.     long    (*dostim) P_((long));
  240.  
  241. /* utility functions for dealing with pauses */
  242.     void    (*nap) P_((unsigned short));
  243.     void    (*sleep) P_((_wORD que, long cond));
  244.     void    (*wake) P_((_wORD que, long cond));
  245.     void    (*wakeselect) P_((long param));
  246.  
  247. /* file system utility functions */
  248.     short    (*denyshare) P_((FILEPTR *, FILEPTR *));
  249.     LOCK *    (*denylock) P_((LOCK *, LOCK *));
  250.  
  251. /* functions for adding/cancelling timeouts */
  252.     TIMEOUT * (*addtimeout) P_((long, void (*)()));
  253.     void    (*canceltimeout) P_((TIMEOUT *));
  254.     TIMEOUT * (*addroottimeout) P_((long, void (*)(), short));
  255.  
  256. /* reserved for future use */
  257.     long    res2[6];
  258. };
  259.  
  260. /* flags for open() modes */
  261. #define O_RWMODE      0x03    /* isolates file read/write mode */
  262. #    define O_RDONLY    0x00
  263. #    define O_WRONLY    0x01
  264. #    define O_RDWR    0x02
  265. #    define O_EXEC    0x03    /* execute file; used by kernel only */
  266.  
  267. #define O_APPEND    0x08    /* all writes go to end of file */
  268.  
  269. #define O_SHMODE    0x70    /* isolates file sharing mode */
  270. #    define O_COMPAT    0x00    /* compatibility mode */
  271. #    define O_DENYRW    0x10    /* deny both read and write access */
  272. #    define O_DENYW    0x20    /* deny write access to others */
  273. #    define O_DENYR    0x30    /* deny read access to others */
  274. #    define O_DENYNONE 0x40    /* don't deny any access to others */
  275.  
  276. #define O_NOINHERIT    0x80    /* children don't get this file descriptor */
  277.  
  278. #define O_NDELAY    0x100    /* don't block for i/o on this file */
  279. #define O_CREAT        0x200    /* create file if it doesn't exist */
  280. #define O_TRUNC        0x400    /* truncate file to 0 bytes if it does exist */
  281. #define O_EXCL        0x800    /* fail open if file exists */
  282.  
  283. #define O_USER        0x0fff    /* isolates user-settable flag bits */
  284.  
  285. #define O_GLOBAL    0x1000    /* for Fopen: opens a global file handle */
  286.  
  287. /* kernel mode bits -- the user can't set these! */
  288. #define O_TTY        0x2000    /* FILEPTR refers to a terminal */
  289. #define O_HEAD        0x4000    /* FILEPTR is the master side of a fifo */
  290. #define O_LOCK        0x8000    /* FILEPTR has had locking Fcntl's performed */
  291.  
  292.  
  293. /* GEMDOS file attributes */
  294.  
  295. /* macros to be applied to FILEPTRS to determine their type */
  296. #define is_terminal(f) (f->flags & O_TTY)
  297.  
  298. /* lseek() origins */
  299. #define    SEEK_SET    0        /* from beginning of file */
  300. #define    SEEK_CUR    1        /* from current location */
  301. #define    SEEK_END    2        /* from end of file */
  302.  
  303. /* The requests for Dpathconf() */
  304. #define DP_IOPEN    0    /* internal limit on # of open files */
  305. #define DP_MAXLINKS    1    /* max number of hard links to a file */
  306. #define DP_PATHMAX    2    /* max path name length */
  307. #define DP_NAMEMAX    3    /* max length of an individual file name */
  308. #define DP_ATOMIC    4    /* # of bytes that can be written atomically */
  309. #define DP_TRUNC    5    /* file name truncation behavior */
  310. #    define    DP_NOTRUNC    0    /* long filenames give an error */
  311. #    define    DP_AUTOTRUNC    1    /* long filenames truncated */
  312. #    define    DP_DOSTRUNC    2    /* DOS truncation rules in effect */
  313. #define DP_CASE        6    /* file name case conversion behavior */
  314. #    define    DP_CASESENS    0    /* case sensitive */
  315. #    define    DP_CASECONV    1    /* case always converted */
  316. #    define    DP_CASEINSENS    2    /* case insensitive, preserved */
  317.  
  318. #define DP_MAXREQ    6    /* highest legal request */
  319.  
  320. /* Dpathconf and Sysconf return this when a value is not limited
  321.    (or is limited only by available memory) */
  322.  
  323. #define UNLIMITED    0x7fffffffL
  324.  
  325. /* various character constants and defines for TTY's */
  326. #define MiNTEOF 0x0000ff1a    /* 1a == ^Z */
  327.  
  328. /* defines for tty_read */
  329. #define RAW    0
  330. #define COOKED    0x1
  331. #define NOECHO    0
  332. #define ECHO    0x2
  333. #define ESCSEQ    0x04        /* cursor keys, etc. get escape sequences */
  334.  
  335. /* constants for various Fcntl commands */
  336. /* constants for Fcntl calls */
  337. #define F_DUPFD        0        /* handled by kernel */
  338. #define F_GETFD        1        /* handled by kernel */
  339. #define F_SETFD        2        /* handled by kernel */
  340. #    define FD_CLOEXEC    1    /* close on exec flag */
  341.  
  342. #define F_GETFL        3        /* handled by kernel */
  343. #define F_SETFL        4        /* handled by kernel */
  344. #define F_GETLK        5
  345. #define F_SETLK        6
  346. #define F_SETLKW    7
  347.  
  348. #define FSTAT        (('F'<< 8) | 0)    /* handled by kernel */
  349. #define FIONREAD    (('F'<< 8) | 1)
  350. #define FIONWRITE    (('F'<< 8) | 2)
  351. #define TIOCGETP    (('T'<< 8) | 0)
  352. #define TIOCSETP    (('T'<< 8) | 1)
  353. #define TIOCSETN    TIOCSETP
  354. #define TIOCGETC    (('T'<< 8) | 2)
  355. #define TIOCSETC    (('T'<< 8) | 3)
  356. #define TIOCGLTC    (('T'<< 8) | 4)
  357. #define TIOCSLTC    (('T'<< 8) | 5)
  358. #define TIOCGPGRP    (('T'<< 8) | 6)
  359. #define TIOCSPGRP    (('T'<< 8) | 7)
  360. #define TIOCFLUSH    (('T'<< 8) | 8)
  361. #define TIOCSTOP    (('T'<< 8) | 9)
  362. #define TIOCSTART    (('T'<< 8) | 10)
  363. #define TIOCGWINSZ    (('T'<< 8) | 11)
  364. #define TIOCSWINSZ    (('T'<< 8) | 12)
  365. #define TIOCGXKEY    (('T'<< 8) | 13)
  366. #define TIOCSXKEY    (('T'<< 8) | 14)
  367. #define TIOCIBAUD    (('T'<< 8) | 18)
  368. #define TIOCOBAUD    (('T'<< 8) | 19)
  369. #define TIOCCBRK    (('T'<< 8) | 20)
  370. #define TIOCSBRK    (('T'<< 8) | 21)
  371. #define TIOCGFLAGS    (('T'<< 8) | 22)
  372. #define TIOCSFLAGS    (('T'<< 8) | 23)
  373.  
  374. #define TCURSOFF    (('c'<< 8) | 0)
  375. #define TCURSON        (('c'<< 8) | 1)
  376. #define TCURSBLINK    (('c'<< 8) | 2)
  377. #define TCURSSTEADY    (('c'<< 8) | 3)
  378. #define TCURSSRATE    (('c'<< 8) | 4)
  379. #define TCURSGRATE    (('c'<< 8) | 5)
  380.  
  381. #define PPROCADDR    (('P'<< 8) | 1)
  382. #define PBASEADDR    (('P'<< 8) | 2)
  383. #define PCTXTSIZE    (('P'<< 8) | 3)
  384. #define PSETFLAGS    (('P'<< 8) | 4)
  385. #define PGETFLAGS    (('P'<< 8) | 5)
  386. #define PTRACESFLAGS    (('P'<< 8) | 6)
  387. #define PTRACEGFLAGS    (('P'<< 8) | 7)
  388. #    define    P_ENABLE    (1 << 0)    /* enable tracing */
  389.  
  390. #define PTRACEGO    (('P'<< 8) | 8)
  391. #define PTRACEFLOW    (('P'<< 8) | 9)
  392. #define PTRACESTEP    (('P'<< 8) | 10)
  393. #define PTRACE11    (('P'<< 8) | 11)    /* unused, reserved */
  394.  
  395. #define SHMGETBLK    (('M'<< 8) | 0)
  396. #define SHMSETBLK    (('M'<< 8) | 1)
  397.  
  398. /* terminal control constants (tty.sg_flags) */
  399. #define T_CRMOD        0x0001
  400. #define T_CBREAK    0x0002
  401. #define T_ECHO        0x0004
  402. #define T_RAW        0x0010
  403. #define T_TOS        0x0080
  404. #define T_TOSTOP    0x0100
  405. #define T_XKEY        0x0200        /* Fread returns escape sequences for
  406.                        cursor keys, etc. */
  407.  
  408. /* the following are terminal status flags (tty.state) */
  409. /* (the low byte of tty.state indicates a part of an escape sequence still
  410.  * hasn't been read by Fread, and is an index into that escape sequence)
  411.  */
  412. #define TS_ESC        0x00ff
  413. #define TS_HOLD        0x1000        /* hold (e.g. ^S/^Q) */
  414. #define TS_COOKED    0x8000        /* interpret control chars */
  415.  
  416. /* structures for terminals */
  417. struct tchars {
  418.     char t_intrc;
  419.     char t_quitc;
  420.     char t_startc;
  421.     char t_stopc;
  422.     char t_eofc;
  423.     char t_brkc;
  424. };
  425.  
  426. struct ltchars {
  427.     char t_suspc;
  428.     char t_dsuspc;
  429.     char t_rprntc;
  430.     char t_flushc;
  431.     char t_werasc;
  432.     char t_lnextc;
  433. };
  434.  
  435. struct sgttyb {
  436.     char sg_ispeed;
  437.     char sg_ospeed;
  438.     char sg_erase;
  439.     char sg_kill;
  440.     unsigned short sg_flags;
  441. };
  442.  
  443. struct winsize {
  444.     short    ws_row;
  445.     short    ws_col;
  446.     short    ws_xpixel;
  447.     short    ws_ypixel;
  448. };
  449.  
  450. struct xkey {
  451.     short    xk_num;
  452.     char    xk_def[8];
  453. };
  454.  
  455. struct tty {
  456.     short        pgrp;        /* process group of terminal */
  457.     short        state;        /* terminal status, e.g. stopped */
  458.     short        use_cnt;    /* number of times terminal is open */
  459.     short        res1;        /* reserved for future expansion */
  460.     struct sgttyb     sg;
  461.     struct tchars     tc;
  462.     struct ltchars     ltc;
  463.     struct winsize    wsiz;
  464.     long        rsel;        /* selecting process for read */
  465.     long        wsel;        /* selecting process for write */
  466.     char        *xkey;        /* extended keyboard table */
  467.     long        rsrvd[3];    /* reserved for future expansion */
  468. };
  469.  
  470. /* defines and declarations for Dcntl operations */
  471.  
  472. #define DEV_INSTALL    0xde02
  473. #define DEV_NEWBIOS    0xde01
  474. #define DEV_NEWTTY    0xde00
  475.  
  476. struct dev_descr {
  477.     DEVDRV    *driver;
  478.     short    dinfo;
  479.     short    flags;
  480.     struct tty *tty;
  481.     long    reserved[4];
  482. };
  483.  
  484. /* defines for TOS attribute bytes */
  485. #ifndef FA_RDONLY
  486. #define           FA_RDONLY           0x01
  487. #define           FA_HIDDEN           0x02
  488. #define           FA_SYSTEM           0x04
  489. #define           FA_LABEL               0x08
  490. #define           FA_DIR               0x10
  491. #define           FA_CHANGED           0x20
  492. #endif
  493.  
  494. #endif /* _filesys_h */
  495.