|
|
1.1 root 1: /*
2:
3: * NOTE: This file only works if sizeof(int) == 2!
4:
5: * UNLESS: you have an ANSI compiler and use prototypes
6:
7: *
8:
9: * Copyright 1991,1992 Eric R. Smith. This file may be re-distributed
10:
11: * as long as this notice remains intact.
12:
13: */
14:
15:
16:
17: #ifndef _filesys_h
18:
19: #define _filesys_h
20:
21:
22:
23: #ifndef P_
24:
25: # ifdef __STDC__
26:
27: # define P_(x) x
28:
29: # else
30:
31: # define P_(x) ()
32:
33: # endif
34:
35: #endif
36:
37:
38:
39: #ifdef _SHORTINT
40:
41: #define _wORD int
42:
43: #endif
44:
45:
46:
47: #ifndef _wORD
48:
49: #ifdef __MSHORT__ /* 16 bit integers? */
50:
51: #define _wORD int
52:
53: #else
54:
55: #define _wORD short
56:
57: #endif
58:
59: #endif
60:
61:
62:
63: #define NAME_MAX 32
64:
65: #define PATH_MAX 128
66:
67:
68:
69: struct filesys; /* forward declaration */
70:
71: struct devdrv; /* ditto */
72:
73:
74:
75: typedef struct f_cookie {
76:
77: struct filesys *fs; /* filesystem that knows about this cookie */
78:
79: unsigned short dev; /* device info (e.g. Rwabs device number) */
80:
81: unsigned short aux; /* extra data that the file system may want */
82:
83: long index; /* this+dev uniquely identifies a file */
84:
85: } fcookie;
86:
87:
88:
89: /* structure for opendir/readdir/closedir */
90:
91: typedef struct dirstruct {
92:
93: fcookie fc; /* cookie for this directory */
94:
95: unsigned short index; /* index of the current entry */
96:
97: unsigned short flags; /* flags (e.g. tos or not) */
98:
99: #define TOS_SEARCH 0x01
100:
101: char fsstuff[60]; /* anything else the file system wants */
102:
103: /* NOTE: this must be at least 45 bytes */
104:
105: } DIR;
106:
107:
108:
109: /* structure for getxattr */
110:
111: typedef struct xattr {
112:
113: unsigned short mode;
114:
115: /* file types */
116:
117: #define S_IFMT 0170000 /* mask to select file type */
118:
119: #define S_IFCHR 0020000 /* BIOS special file */
120:
121: #define S_IFDIR 0040000 /* directory file */
122:
123: #define S_IFREG 0100000 /* regular file */
124:
125: #define S_IFIFO 0120000 /* FIFO */
126:
127: #define S_IMEM 0140000 /* memory region or process */
128:
129: #define S_IFLNK 0160000 /* symbolic link */
130:
131:
132:
133: /* special bits: setuid, setgid, sticky bit */
134:
135: #define S_ISUID 04000
136:
137: #define S_ISGID 02000
138:
139: #define S_ISVTX 01000
140:
141:
142:
143: /* file access modes for user, group, and other*/
144:
145: #define S_IRUSR 0400
146:
147: #define S_IWUSR 0200
148:
149: #define S_IXUSR 0100
150:
151: #define S_IRGRP 0040
152:
153: #define S_IWGRP 0020
154:
155: #define S_IXGRP 0010
156:
157: #define S_IROTH 0004
158:
159: #define S_IWOTH 0002
160:
161: #define S_IXOTH 0001
162:
163: #define DEFAULT_DIRMODE (0777)
164:
165: #define DEFAULT_MODE (0666)
166:
167: long index;
168:
169: unsigned short dev;
170:
171: unsigned short reserved1;
172:
173: unsigned short nlink;
174:
175: unsigned short uid;
176:
177: unsigned short gid;
178:
179: long size;
180:
181: long blksize, nblocks;
182:
183: short mtime, mdate;
184:
185: short atime, adate;
186:
187: short ctime, cdate;
188:
189: short attr;
190:
191: short reserved2;
192:
193: long reserved3[2];
194:
195: } XATTR;
196:
197:
198:
199: typedef struct fileptr {
200:
201: short links; /* number of copies of this descriptor */
202:
203: unsigned short flags; /* file open mode and other file flags */
204:
205: long pos; /* position in file */
206:
207: long devinfo; /* device driver specific info */
208:
209: fcookie fc; /* file system cookie for this file */
210:
211: struct devdrv *dev; /* device driver that knows how to deal with this */
212:
213: struct fileptr *next; /* link to next fileptr for this file */
214:
215: } FILEPTR;
216:
217:
218:
219: /* lock structure */
220:
221: struct flock {
222:
223: short l_type; /* type of lock */
224:
225: #define F_RDLCK O_RDONLY
226:
227: #define F_WRLCK O_WRONLY
228:
229: #define F_UNLCK 3
230:
231: short l_whence; /* SEEK_SET, SEEK_CUR, SEEK_END */
232:
233: long l_start; /* start of locked region */
234:
235: long l_len; /* length of locked region */
236:
237: short l_pid; /* pid of locking process
238:
239: (F_GETLK only) */
240:
241: };
242:
243:
244:
245: /* LOCK structure used by the kernel internally */
246:
247:
248:
249: typedef struct ilock {
250:
251: struct flock l;
252:
253: struct ilock *next;
254:
255: long reserved[4];
256:
257: } LOCK;
258:
259:
260:
261: typedef struct devdrv {
262:
263: long (*open) P_((FILEPTR *f));
264:
265: long (*write) P_((FILEPTR *f, char *buf, long bytes));
266:
267: long (*read) P_((FILEPTR *f, char *buf, long bytes));
268:
269: long (*lseek) P_((FILEPTR *f, long where, _wORD whence));
270:
271: long (*ioctl) P_((FILEPTR *f, _wORD mode, void *buf));
272:
273: long (*datime) P_((FILEPTR *f, _wORD *timeptr, _wORD rwflag));
274:
275: long (*close) P_((FILEPTR *f, _wORD pid));
276:
277: long (*select) P_((FILEPTR *f, long proc, _wORD mode));
278:
279: void (*unselect) P_((FILEPTR *f, long proc, _wORD mode));
280:
281: long reserved[3]; /* reserved for future use */
282:
283: } DEVDRV;
284:
285:
286:
287: typedef struct filesys {
288:
289: struct filesys *next; /* link to next file system on chain */
290:
291: long fsflags;
292:
293: #define FS_KNOPARSE 0x01 /* kernel shouldn't do parsing */
294:
295: #define FS_CASESENSITIVE 0x02 /* file names are case sensitive */
296:
297: #define FS_NOXBIT 0x04 /* if a file can be read, it can be executed */
298:
299:
300:
301: long (*root) P_((_wORD drv, fcookie *fc));
302:
303: long (*lookup) P_((fcookie *dir, char *name, fcookie *fc));
304:
305: long (*creat) P_((fcookie *dir, char *name, unsigned _wORD mode,
306:
307: _wORD attrib, fcookie *fc));
308:
309: DEVDRV *(*getdev) P_((fcookie *fc, long *devspecial));
310:
311: long (*getxattr) P_((fcookie *fc, XATTR *xattr));
312:
313: long (*chattr) P_((fcookie *fc, _wORD attr));
314:
315: long (*chown) P_((fcookie *fc, _wORD uid, _wORD gid));
316:
317: long (*chmode) P_((fcookie *fc, unsigned _wORD mode));
318:
319: long (*mkdir) P_((fcookie *dir, char *name, unsigned _wORD mode));
320:
321: long (*rmdir) P_((fcookie *dir, char *name));
322:
323: long (*remove) P_((fcookie *dir, char *name));
324:
325: long (*getname) P_((fcookie *relto, fcookie *dir, char *pathname));
326:
327: long (*rename) P_((fcookie *olddir, char *oldname,
328:
329: fcookie *newdir, char *newname));
330:
331: long (*opendir) P_((DIR *dirh, _wORD tosflag));
332:
333: long (*readdir) P_((DIR *dirh, char *nm, _wORD nmlen, fcookie *fc));
334:
335: long (*rewinddir) P_((DIR *dirh));
336:
337: long (*closedir) P_((DIR *dirh));
338:
339: long (*pathconf) P_((fcookie *dir, _wORD which));
340:
341: long (*dfree) P_((fcookie *dir, long *buf));
342:
343: long (*writelabel) P_((fcookie *dir, char *name));
344:
345: long (*readlabel) P_((fcookie *dir, char *name, _wORD namelen));
346:
347: long (*symlink) P_((fcookie *dir, char *name, char *to));
348:
349: long (*readlink) P_((fcookie *dir, char *buf, _wORD len));
350:
351: long (*hardlink) P_((fcookie *fromdir, char *fromname,
352:
353: fcookie *todir, char *toname));
354:
355: long (*fscntl) P_((fcookie *dir, char *name, _wORD cmd, long arg));
356:
357: long (*dskchng) P_((_wORD drv));
358:
359: long zero;
360:
361: } FILESYS;
362:
363:
364:
365: /*
366:
367: * this is the structure passed to loaded file systems to tell them
368:
369: * about the kernel
370:
371: */
372:
373:
374:
375: typedef long (*_LongFunc)();
376:
377:
378:
379: struct kerinfo {
380:
381: short maj_version; /* kernel version number */
382:
383: short min_version; /* minor kernel version number */
384:
385: unsigned short default_mode; /* default file access mode */
386:
387: short reserved1; /* room for expansion */
388:
389:
390:
391: /* OS functions */
392:
393: _LongFunc *bios_tab; /* pointer to the BIOS entry points */
394:
395: _LongFunc *dos_tab; /* pointer to the GEMDOS entry points */
396:
397:
398:
399: /* media change vector */
400:
401: void (*drvchng) P_((short));
402:
403:
404:
405: /* Debugging stuff */
406:
407: void (*trace) P_((char *, ...));
408:
409: void (*debug) P_((char *, ...));
410:
411: void (*alert) P_((char *, ...));
412:
413: void (*fatal) P_((char *, ...));
414:
415:
416:
417: /* memory allocation functions */
418:
419: void * (*kmalloc) P_((long));
420:
421: void (*kfree) P_((void *));
422:
423: void * (*umalloc) P_((long));
424:
425: void (*ufree) P_((void *));
426:
427:
428:
429: /* utility functions for string manipulation */
430:
431: short (*strnicmp) P_((char *, char *, _wORD));
432:
433: short (*stricmp) P_((char *, char *));
434:
435: char * (*strlwr) P_((char *));
436:
437: char * (*strupr) P_((char *));
438:
439: short (*sprintf) P_((char *, char *, ...));
440:
441:
442:
443: /* utility functions for manipulating time */
444:
445: void (*millis_time) P_((unsigned long, _wORD *));
446:
447: long (*unixtim) P_((unsigned _wORD, unsigned _wORD));
448:
449: long (*dostim) P_((long));
450:
451:
452:
453: /* utility functions for dealing with pauses */
454:
455: void (*nap) P_((unsigned short));
456:
457: void (*sleep) P_((_wORD que, long cond));
458:
459: void (*wake) P_((_wORD que, long cond));
460:
461: void (*wakeselect) P_((long param));
462:
463:
464:
465: /* file system utility functions */
466:
467: short (*denyshare) P_((FILEPTR *, FILEPTR *));
468:
469: LOCK * (*denylock) P_((LOCK *, LOCK *));
470:
471:
472:
473: /* reserved for future use */
474:
475: long res2[9];
476:
477: };
478:
479:
480:
481: /* flags for open() modes */
482:
483: #define O_RWMODE 0x03 /* isolates file read/write mode */
484:
485: # define O_RDONLY 0x00
486:
487: # define O_WRONLY 0x01
488:
489: # define O_RDWR 0x02
490:
491: # define O_EXEC 0x03 /* execute file; used by kernel only */
492:
493:
494:
495: #define O_APPEND 0x08 /* all writes go to end of file */
496:
497:
498:
499: #define O_SHMODE 0x70 /* isolates file sharing mode */
500:
501: # define O_COMPAT 0x00 /* compatibility mode */
502:
503: # define O_DENYRW 0x10 /* deny both read and write access */
504:
505: # define O_DENYW 0x20 /* deny write access to others */
506:
507: # define O_DENYR 0x30 /* deny read access to others */
508:
509: # define O_DENYNONE 0x40 /* don't deny any access to others */
510:
511:
512:
513: #define O_NOINHERIT 0x80 /* children don't get this file descriptor */
514:
515:
516:
517: #define O_NDELAY 0x100 /* don't block for i/o on this file */
518:
519: #define O_CREAT 0x200 /* create file if it doesn't exist */
520:
521: #define O_TRUNC 0x400 /* truncate file to 0 bytes if it does exist */
522:
523: #define O_EXCL 0x800 /* fail open if file exists */
524:
525:
526:
527: #define O_USER 0x0fff /* isolates user-settable flag bits */
528:
529:
530:
531: #define O_GLOBAL 0x1000 /* for Fopen: opens a global file handle */
532:
533:
534:
535: /* kernel mode bits -- the user can't set these! */
536:
537: #define O_TTY 0x2000 /* FILEPTR refers to a terminal */
538:
539: #define O_HEAD 0x4000 /* FILEPTR is the master side of a fifo */
540:
541: #define O_LOCK 0x8000 /* FILEPTR has had locking Fcntl's performed */
542:
543:
544:
545:
546:
547: /* GEMDOS file attributes */
548:
549:
550:
551: /* macros to be applied to FILEPTRS to determine their type */
552:
553: #define is_terminal(f) (f->flags & O_TTY)
554:
555:
556:
557: /* lseek() origins */
558:
559: #define SEEK_SET 0 /* from beginning of file */
560:
561: #define SEEK_CUR 1 /* from current location */
562:
563: #define SEEK_END 2 /* from end of file */
564:
565:
566:
567: /* The requests for Dpathconf() */
568:
569: #define DP_IOPEN 0 /* internal limit on # of open files */
570:
571: #define DP_MAXLINKS 1 /* max number of hard links to a file */
572:
573: #define DP_PATHMAX 2 /* max path name length */
574:
575: #define DP_NAMEMAX 3 /* max length of an individual file name */
576:
577: #define DP_ATOMIC 4 /* # of bytes that can be written atomically */
578:
579: #define DP_TRUNC 5 /* file name truncation behavior */
580:
581: # define DP_NOTRUNC 0 /* long filenames give an error */
582:
583: # define DP_AUTOTRUNC 1 /* long filenames truncated */
584:
585: # define DP_DOSTRUNC 2 /* DOS truncation rules in effect */
586:
587: #define DP_CASE 6 /* file name case conversion behavior */
588:
589: # define DP_CASESENS 0 /* case sensitive */
590:
591: # define DP_CASECONV 1 /* case always converted */
592:
593: # define DP_CASEINSENS 2 /* case insensitive, preserved */
594:
595:
596:
597: #define DP_MAXREQ 6 /* highest legal request */
598:
599:
600:
601: /* Dpathconf and Sysconf return this when a value is not limited
602:
603: (or is limited only by available memory) */
604:
605:
606:
607: #define UNLIMITED 0x7fffffffL
608:
609:
610:
611: /* various character constants and defines for TTY's */
612:
613: #define MiNTEOF 0x0000ff1a /* 1a == ^Z */
614:
615:
616:
617: /* defines for tty_read */
618:
619: #define RAW 0
620:
621: #define COOKED 0x1
622:
623: #define NOECHO 0
624:
625: #define ECHO 0x2
626:
627: #define ESCSEQ 0x04 /* cursor keys, etc. get escape sequences */
628:
629:
630:
631: /* constants for various Fcntl commands */
632:
633: /* constants for Fcntl calls */
634:
635: #define F_DUPFD 0 /* handled by kernel */
636:
637: #define F_GETFD 1 /* handled by kernel */
638:
639: #define F_SETFD 2 /* handled by kernel */
640:
641: # define FD_CLOEXEC 1 /* close on exec flag */
642:
643:
644:
645: #define F_GETFL 3 /* handled by kernel */
646:
647: #define F_SETFL 4 /* handled by kernel */
648:
649: #define F_GETLK 5
650:
651: #define F_SETLK 6
652:
653: #define F_SETLKW 7
654:
655:
656:
657: #define FSTAT (('F'<< 8) | 0) /* handled by kernel */
658:
659: #define FIONREAD (('F'<< 8) | 1)
660:
661: #define FIONWRITE (('F'<< 8) | 2)
662:
663: #define TIOCGETP (('T'<< 8) | 0)
664:
665: #define TIOCSETP (('T'<< 8) | 1)
666:
667: #define TIOCSETN TIOCSETP
668:
669: #define TIOCGETC (('T'<< 8) | 2)
670:
671: #define TIOCSETC (('T'<< 8) | 3)
672:
673: #define TIOCGLTC (('T'<< 8) | 4)
674:
675: #define TIOCSLTC (('T'<< 8) | 5)
676:
677: #define TIOCGPGRP (('T'<< 8) | 6)
678:
679: #define TIOCSPGRP (('T'<< 8) | 7)
680:
681: #define TIOCFLUSH (('T'<< 8) | 8)
682:
683: #define TIOCSTOP (('T'<< 8) | 9)
684:
685: #define TIOCSTART (('T'<< 8) | 10)
686:
687: #define TIOCGWINSZ (('T'<< 8) | 11)
688:
689: #define TIOCSWINSZ (('T'<< 8) | 12)
690:
691: #define TIOCGXKEY (('T'<< 8) | 13)
692:
693: #define TIOCSXKEY (('T'<< 8) | 14)
694:
695: #define TIOCIBAUD (('T'<< 8) | 18)
696:
697: #define TIOCOBAUD (('T'<< 8) | 19)
698:
699: #define TIOCCBRK (('T'<< 8) | 20)
700:
701: #define TIOCSBRK (('T'<< 8) | 21)
702:
703: #define TIOCGFLAGS (('T'<< 8) | 22)
704:
705: #define TIOCSFLAGS (('T'<< 8) | 23)
706:
707:
708:
709: #define TCURSOFF (('c'<< 8) | 0)
710:
711: #define TCURSON (('c'<< 8) | 1)
712:
713: #define TCURSBLINK (('c'<< 8) | 2)
714:
715: #define TCURSSTEADY (('c'<< 8) | 3)
716:
717: #define TCURSSRATE (('c'<< 8) | 4)
718:
719: #define TCURSGRATE (('c'<< 8) | 5)
720:
721:
722:
723: #define PPROCADDR (('P'<< 8) | 1)
724:
725: #define PBASEADDR (('P'<< 8) | 2)
726:
727: #define PCTXTSIZE (('P'<< 8) | 3)
728:
729: #define PSETFLAGS (('P'<< 8) | 4)
730:
731: #define PGETFLAGS (('P'<< 8) | 5)
732:
733: #define PTRACESFLAGS (('P'<< 8) | 6)
734:
735: #define PTRACEGFLAGS (('P'<< 8) | 7)
736:
737: # define P_ENABLE (1 << 0) /* enable tracing */
738:
739:
740:
741: #define PTRACEGO (('P'<< 8) | 8)
742:
743: #define PTRACEFLOW (('P'<< 8) | 9)
744:
745: #define PTRACESTEP (('P'<< 8) | 10)
746:
747: #define PTRACE11 (('P'<< 8) | 11) /* unused, reserved */
748:
749:
750:
751: #define SHMGETBLK (('M'<< 8) | 0)
752:
753: #define SHMSETBLK (('M'<< 8) | 1)
754:
755:
756:
757: /* terminal control constants (tty.sg_flags) */
758:
759: #define T_CRMOD 0x0001
760:
761: #define T_CBREAK 0x0002
762:
763: #define T_ECHO 0x0004
764:
765: #define T_RAW 0x0010
766:
767: #define T_TOS 0x0080
768:
769: #define T_TOSTOP 0x0100
770:
771: #define T_XKEY 0x0200 /* Fread returns escape sequences for
772:
773: cursor keys, etc. */
774:
775:
776:
777: /* the following are terminal status flags (tty.state) */
778:
779: /* (the low byte of tty.state indicates a part of an escape sequence still
780:
781: * hasn't been read by Fread, and is an index into that escape sequence)
782:
783: */
784:
785: #define TS_ESC 0x00ff
786:
787: #define TS_HOLD 0x1000 /* hold (e.g. ^S/^Q) */
788:
789: #define TS_COOKED 0x8000 /* interpret control chars */
790:
791:
792:
793: /* structures for terminals */
794:
795: struct tchars {
796:
797: char t_intrc;
798:
799: char t_quitc;
800:
801: char t_startc;
802:
803: char t_stopc;
804:
805: char t_eofc;
806:
807: char t_brkc;
808:
809: };
810:
811:
812:
813: struct ltchars {
814:
815: char t_suspc;
816:
817: char t_dsuspc;
818:
819: char t_rprntc;
820:
821: char t_flushc;
822:
823: char t_werasc;
824:
825: char t_lnextc;
826:
827: };
828:
829:
830:
831: struct sgttyb {
832:
833: char sg_ispeed;
834:
835: char sg_ospeed;
836:
837: char sg_erase;
838:
839: char sg_kill;
840:
841: unsigned short sg_flags;
842:
843: };
844:
845:
846:
847: struct winsize {
848:
849: short ws_row;
850:
851: short ws_col;
852:
853: short ws_xpixel;
854:
855: short ws_ypixel;
856:
857: };
858:
859:
860:
861: struct xkey {
862:
863: short xk_num;
864:
865: char xk_def[8];
866:
867: };
868:
869:
870:
871: struct tty {
872:
873: short pgrp; /* process group of terminal */
874:
875: short state; /* terminal status, e.g. stopped */
876:
877: short use_cnt; /* number of times terminal is open */
878:
879: short res1; /* reserved for future expansion */
880:
881: struct sgttyb sg;
882:
883: struct tchars tc;
884:
885: struct ltchars ltc;
886:
887: struct winsize wsiz;
888:
889: long rsel; /* selecting process for read */
890:
891: long wsel; /* selecting process for write */
892:
893: char *xkey; /* extended keyboard table */
894:
895: long rsrvd[3]; /* reserved for future expansion */
896:
897: };
898:
899:
900:
901: /* defines and declarations for Dcntl operations */
902:
903:
904:
905: #define DEV_INSTALL 0xde02
906:
907: #define DEV_NEWBIOS 0xde01
908:
909: #define DEV_NEWTTY 0xde00
910:
911:
912:
913: struct dev_descr {
914:
915: DEVDRV *driver;
916:
917: short dinfo;
918:
919: short flags;
920:
921: struct tty *tty;
922:
923: long reserved[4];
924:
925: };
926:
927:
928:
929: /* defines for TOS attribute bytes */
930:
931: #ifndef FA_RDONLY
932:
933: #define FA_RDONLY 0x01
934:
935: #define FA_HIDDEN 0x02
936:
937: #define FA_SYSTEM 0x04
938:
939: #define FA_LABEL 0x08
940:
941: #define FA_DIR 0x10
942:
943: #define FA_CHANGED 0x20
944:
945: #endif
946:
947:
948:
949: #endif /* _filesys_h */
950:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.