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