home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / alt_os / mint / mfs6011 / source / minixfs / filesys.h < prev    next >
C/C++ Source or Header  |  1994-12-30  |  16KB  |  496 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. #define FS_DO_SYNC  0x20  /* file system has sync function */
  162.  
  163.     long    (*root) P_((_wORD drv, fcookie *fc));
  164.     long    (*lookup) P_((fcookie *dir, char *name, fcookie *fc));
  165.     long    (*creat) P_((fcookie *dir, char *name, unsigned _wORD mode,
  166.                 _wORD attrib, fcookie *fc));
  167.     DEVDRV *(*getdev) P_((fcookie *fc, long *devspecial));
  168.     long    (*getxattr) P_((fcookie *fc, XATTR *xattr));
  169.     long    (*chattr) P_((fcookie *fc, _wORD attr));
  170.     long    (*chown) P_((fcookie *fc, _wORD uid, _wORD gid));
  171.     long    (*chmode) P_((fcookie *fc, unsigned _wORD mode));
  172.     long    (*mkdir) P_((fcookie *dir, char *name, unsigned _wORD mode));
  173.     long    (*rmdir) P_((fcookie *dir, char *name));
  174.     long    (*remove) P_((fcookie *dir, char *name));
  175.     long    (*getname) P_((fcookie *relto, fcookie *dir, char *pathname,
  176.                 _wORD size));
  177.     long    (*rename) P_((fcookie *olddir, char *oldname,
  178.                 fcookie *newdir, char *newname));
  179.     long    (*opendir) P_((DIR *dirh, _wORD tosflag));
  180.     long    (*readdir) P_((DIR *dirh, char *nm, _wORD nmlen, fcookie *fc));
  181.     long    (*rewinddir) P_((DIR *dirh));
  182.     long    (*closedir) P_((DIR *dirh));
  183.     long    (*pathconf) P_((fcookie *dir, _wORD which));
  184.     long    (*dfree) P_((fcookie *dir, long *buf));
  185.     long    (*writelabel) P_((fcookie *dir, char *name));
  186.     long    (*readlabel) P_((fcookie *dir, char *name, _wORD namelen));
  187.     long    (*symlink) P_((fcookie *dir, char *name, char *to));
  188.     long    (*readlink) P_((fcookie *dir, char *buf, _wORD len));
  189.     long    (*hardlink) P_((fcookie *fromdir, char *fromname,
  190.                 fcookie *todir, char *toname));
  191.     long    (*fscntl) P_((fcookie *dir, char *name, _wORD cmd, long arg));
  192.     long    (*dskchng) P_((_wORD drv));
  193.     long    (*release) P_((fcookie *fc));
  194.     long    (*dupcookie) P_((fcookie *dest, fcookie *src));
  195.     void    (*sync) P_((void));
  196. } FILESYS;
  197.  
  198. /*
  199.  * this is the structure passed to loaded file systems to tell them
  200.  * about the kernel
  201.  */
  202.  
  203. typedef long (*_LongFunc)();
  204.  
  205. struct kerinfo {
  206.     short    maj_version;    /* kernel version number */
  207.     short    min_version;    /* minor kernel version number */
  208.     unsigned short default_mode;    /* default file access mode */
  209.     short    reserved1;    /* room for expansion */
  210.  
  211. /* OS functions */
  212.     _LongFunc *bios_tab;     /* pointer to the BIOS entry points */
  213.     _LongFunc *dos_tab;    /* pointer to the GEMDOS entry points */
  214.  
  215. /* media change vector */
  216.     void    (*drvchng) P_((short));
  217.  
  218. /* Debugging stuff */
  219.     void    (*trace) P_((char *, ...));
  220.     void    (*debug) P_((char *, ...));
  221.     void    (*alert) P_((char *, ...));
  222.     void    (*fatal) P_((char *, ...));
  223.  
  224. /* memory allocation functions */
  225.     void *    (*kmalloc) P_((long));
  226.     void    (*kfree) P_((void *));
  227.     void *    (*umalloc) P_((long));
  228.     void    (*ufree) P_((void *));
  229.  
  230. /* utility functions for string manipulation */
  231.     short    (*strnicmp) P_((char *, char *, _wORD));
  232.     short    (*stricmp) P_((char *, char *));
  233.     char *    (*strlwr) P_((char *));
  234.     char *    (*strupr) P_((char *));
  235.     short    (*sprintf) P_((char *, char *, ...));
  236.  
  237. /* utility functions for manipulating time */
  238.     void    (*millis_time) P_((unsigned long, _wORD *));
  239.     long    (*unixtim) P_((unsigned _wORD, unsigned _wORD));
  240.     long    (*dostim) P_((long));
  241.  
  242. /* utility functions for dealing with pauses */
  243.     void    (*nap) P_((unsigned short));
  244.     void    (*sleep) P_((_wORD que, long cond));
  245.     void    (*wake) P_((_wORD que, long cond));
  246.     void    (*wakeselect) P_((long param));
  247.  
  248. /* file system utility functions */
  249.     short    (*denyshare) P_((FILEPTR *, FILEPTR *));
  250.     LOCK *    (*denylock) P_((LOCK *, LOCK *));
  251.  
  252. /* functions for adding/cancelling timeouts */
  253.     TIMEOUT * (*addtimeout) P_((long, void (*)()));
  254.     void    (*canceltimeout) P_((TIMEOUT *));
  255.     TIMEOUT * (*addroottimeout) P_((long, void (*)(), short));
  256.  
  257. /* reserved for future use */
  258.     long    res2[6];
  259. };
  260.  
  261. /* flags for open() modes */
  262. #define O_RWMODE      0x03    /* isolates file read/write mode */
  263. #    define O_RDONLY    0x00
  264. #    define O_WRONLY    0x01
  265. #    define O_RDWR    0x02
  266. #    define O_EXEC    0x03    /* execute file; used by kernel only */
  267.  
  268. #define O_APPEND    0x08    /* all writes go to end of file */
  269.  
  270. #define O_SHMODE    0x70    /* isolates file sharing mode */
  271. #    define O_COMPAT    0x00    /* compatibility mode */
  272. #    define O_DENYRW    0x10    /* deny both read and write access */
  273. #    define O_DENYW    0x20    /* deny write access to others */
  274. #    define O_DENYR    0x30    /* deny read access to others */
  275. #    define O_DENYNONE 0x40    /* don't deny any access to others */
  276.  
  277. #define O_NOINHERIT    0x80    /* children don't get this file descriptor */
  278.  
  279. #define O_NDELAY    0x100    /* don't block for i/o on this file */
  280. #define O_CREAT        0x200    /* create file if it doesn't exist */
  281. #define O_TRUNC        0x400    /* truncate file to 0 bytes if it does exist */
  282. #define O_EXCL        0x800    /* fail open if file exists */
  283.  
  284. #define O_USER        0x0fff    /* isolates user-settable flag bits */
  285.  
  286. #define O_GLOBAL    0x1000    /* for Fopen: opens a global file handle */
  287.  
  288. /* kernel mode bits -- the user can't set these! */
  289. #define O_TTY        0x2000    /* FILEPTR refers to a terminal */
  290. #define O_HEAD        0x4000    /* FILEPTR is the master side of a fifo */
  291. #define O_LOCK        0x8000    /* FILEPTR has had locking Fcntl's performed */
  292.  
  293.  
  294. /* GEMDOS file attributes */
  295.  
  296. /* macros to be applied to FILEPTRS to determine their type */
  297. #define is_terminal(f) (f->flags & O_TTY)
  298.  
  299. /* lseek() origins */
  300. #define    SEEK_SET    0        /* from beginning of file */
  301. #define    SEEK_CUR    1        /* from current location */
  302. #define    SEEK_END    2        /* from end of file */
  303.  
  304. /* The requests for Dpathconf() */
  305. #define DP_IOPEN    0    /* internal limit on # of open files */
  306. #define DP_MAXLINKS    1    /* max number of hard links to a file */
  307. #define DP_PATHMAX    2    /* max path name length */
  308. #define DP_NAMEMAX    3    /* max length of an individual file name */
  309. #define DP_ATOMIC    4    /* # of bytes that can be written atomically */
  310. #define DP_TRUNC    5    /* file name truncation behavior */
  311. #    define    DP_NOTRUNC    0    /* long filenames give an error */
  312. #    define    DP_AUTOTRUNC    1    /* long filenames truncated */
  313. #    define    DP_DOSTRUNC    2    /* DOS truncation rules in effect */
  314. #define DP_CASE        6    /* file name case conversion behavior */
  315. #    define    DP_CASESENS    0    /* case sensitive */
  316. #    define    DP_CASECONV    1    /* case always converted */
  317. #    define    DP_CASEINSENS    2    /* case insensitive, preserved */
  318.  
  319. #define DP_MAXREQ    6    /* highest legal request */
  320.  
  321. /* Dpathconf and Sysconf return this when a value is not limited
  322.    (or is limited only by available memory) */
  323.  
  324. #define UNLIMITED    0x7fffffffL
  325.  
  326. /* various character constants and defines for TTY's */
  327. #define MiNTEOF 0x0000ff1a    /* 1a == ^Z */
  328.  
  329. /* defines for tty_read */
  330. #define RAW    0
  331. #define COOKED    0x1
  332. #define NOECHO    0
  333. #define ECHO    0x2
  334. #define ESCSEQ    0x04        /* cursor keys, etc. get escape sequences */
  335.  
  336. /* constants for various Fcntl commands */
  337. /* constants for Fcntl calls */
  338. #define F_DUPFD        0        /* handled by kernel */
  339. #define F_GETFD        1        /* handled by kernel */
  340. #define F_SETFD        2        /* handled by kernel */
  341. #    define FD_CLOEXEC    1    /* close on exec flag */
  342.  
  343. #define F_GETFL        3        /* handled by kernel */
  344. #define F_SETFL        4        /* handled by kernel */
  345. #define F_GETLK        5
  346. #define F_SETLK        6
  347. #define F_SETLKW    7
  348.  
  349. #define FSTAT        (('F'<< 8) | 0)    /* handled by kernel */
  350. #define FIONREAD    (('F'<< 8) | 1)
  351. #define FIONWRITE    (('F'<< 8) | 2)
  352. #define TIOCGETP    (('T'<< 8) | 0)
  353. #define TIOCSETP    (('T'<< 8) | 1)
  354. #define TIOCSETN    TIOCSETP
  355. #define TIOCGETC    (('T'<< 8) | 2)
  356. #define TIOCSETC    (('T'<< 8) | 3)
  357. #define TIOCGLTC    (('T'<< 8) | 4)
  358. #define TIOCSLTC    (('T'<< 8) | 5)
  359. #define TIOCGPGRP    (('T'<< 8) | 6)
  360. #define TIOCSPGRP    (('T'<< 8) | 7)
  361. #define TIOCFLUSH    (('T'<< 8) | 8)
  362. #define TIOCSTOP    (('T'<< 8) | 9)
  363. #define TIOCSTART    (('T'<< 8) | 10)
  364. #define TIOCGWINSZ    (('T'<< 8) | 11)
  365. #define TIOCSWINSZ    (('T'<< 8) | 12)
  366. #define TIOCGXKEY    (('T'<< 8) | 13)
  367. #define TIOCSXKEY    (('T'<< 8) | 14)
  368. #define TIOCIBAUD    (('T'<< 8) | 18)
  369. #define TIOCOBAUD    (('T'<< 8) | 19)
  370. #define TIOCCBRK    (('T'<< 8) | 20)
  371. #define TIOCSBRK    (('T'<< 8) | 21)
  372. #define TIOCGFLAGS    (('T'<< 8) | 22)
  373. #define TIOCSFLAGS    (('T'<< 8) | 23)
  374.  
  375. #define TCURSOFF    (('c'<< 8) | 0)
  376. #define TCURSON        (('c'<< 8) | 1)
  377. #define TCURSBLINK    (('c'<< 8) | 2)
  378. #define TCURSSTEADY    (('c'<< 8) | 3)
  379. #define TCURSSRATE    (('c'<< 8) | 4)
  380. #define TCURSGRATE    (('c'<< 8) | 5)
  381.  
  382. #define PPROCADDR    (('P'<< 8) | 1)
  383. #define PBASEADDR    (('P'<< 8) | 2)
  384. #define PCTXTSIZE    (('P'<< 8) | 3)
  385. #define PSETFLAGS    (('P'<< 8) | 4)
  386. #define PGETFLAGS    (('P'<< 8) | 5)
  387. #define PTRACESFLAGS    (('P'<< 8) | 6)
  388. #define PTRACEGFLAGS    (('P'<< 8) | 7)
  389. #    define    P_ENABLE    (1 << 0)    /* enable tracing */
  390.  
  391. #define PTRACEGO    (('P'<< 8) | 8)
  392. #define PTRACEFLOW    (('P'<< 8) | 9)
  393. #define PTRACESTEP    (('P'<< 8) | 10)
  394. #define PTRACE11    (('P'<< 8) | 11)    /* unused, reserved */
  395.  
  396. #define SHMGETBLK    (('M'<< 8) | 0)
  397. #define SHMSETBLK    (('M'<< 8) | 1)
  398.  
  399. /* terminal control constants (tty.sg_flags) */
  400. #define T_CRMOD        0x0001
  401. #define T_CBREAK    0x0002
  402. #define T_ECHO        0x0004
  403. #define T_RAW        0x0010
  404. #define T_TOS        0x0080
  405. #define T_TOSTOP    0x0100
  406. #define T_XKEY        0x0200        /* Fread returns escape sequences for
  407.                        cursor keys, etc. */
  408.  
  409. /* the following are terminal status flags (tty.state) */
  410. /* (the low byte of tty.state indicates a part of an escape sequence still
  411.  * hasn't been read by Fread, and is an index into that escape sequence)
  412.  */
  413. #define TS_ESC        0x00ff
  414. #define TS_HOLD        0x1000        /* hold (e.g. ^S/^Q) */
  415. #define TS_COOKED    0x8000        /* interpret control chars */
  416.  
  417. /* structures for terminals */
  418. struct tchars {
  419.     char t_intrc;
  420.     char t_quitc;
  421.     char t_startc;
  422.     char t_stopc;
  423.     char t_eofc;
  424.     char t_brkc;
  425. };
  426.  
  427. struct ltchars {
  428.     char t_suspc;
  429.     char t_dsuspc;
  430.     char t_rprntc;
  431.     char t_flushc;
  432.     char t_werasc;
  433.     char t_lnextc;
  434. };
  435.  
  436. struct sgttyb {
  437.     char sg_ispeed;
  438.     char sg_ospeed;
  439.     char sg_erase;
  440.     char sg_kill;
  441.     unsigned short sg_flags;
  442. };
  443.  
  444. struct winsize {
  445.     short    ws_row;
  446.     short    ws_col;
  447.     short    ws_xpixel;
  448.     short    ws_ypixel;
  449. };
  450.  
  451. struct xkey {
  452.     short    xk_num;
  453.     char    xk_def[8];
  454. };
  455.  
  456. struct tty {
  457.     short        pgrp;        /* process group of terminal */
  458.     short        state;        /* terminal status, e.g. stopped */
  459.     short        use_cnt;    /* number of times terminal is open */
  460.     short        res1;        /* reserved for future expansion */
  461.     struct sgttyb     sg;
  462.     struct tchars     tc;
  463.     struct ltchars     ltc;
  464.     struct winsize    wsiz;
  465.     long        rsel;        /* selecting process for read */
  466.     long        wsel;        /* selecting process for write */
  467.     char        *xkey;        /* extended keyboard table */
  468.     long        rsrvd[3];    /* reserved for future expansion */
  469. };
  470.  
  471. /* defines and declarations for Dcntl operations */
  472.  
  473. #define DEV_INSTALL    0xde02
  474. #define DEV_NEWBIOS    0xde01
  475. #define DEV_NEWTTY    0xde00
  476.  
  477. struct dev_descr {
  478.     DEVDRV    *driver;
  479.     short    dinfo;
  480.     short    flags;
  481.     struct tty *tty;
  482.     long    reserved[4];
  483. };
  484.  
  485. /* defines for TOS attribute bytes */
  486. #ifndef FA_RDONLY
  487. #define           FA_RDONLY           0x01
  488. #define           FA_HIDDEN           0x02
  489. #define           FA_SYSTEM           0x04
  490. #define           FA_LABEL               0x08
  491. #define           FA_DIR               0x10
  492. #define           FA_CHANGED           0x20
  493. #endif
  494.  
  495. #endif /* _filesys_h */
  496.