home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / mint / mint095s / file.h < prev    next >
C/C++ Source or Header  |  1993-08-03  |  15KB  |  488 lines

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