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