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