xref: /original-bsd/sys/sys/file.h (revision 3e5087d8)
1 /*	file.h	4.17	83/06/09	*/
2 
3 #ifdef KERNEL
4 /*
5  * Descriptor table entry.
6  * One for each kernel object.
7  */
8 struct	file {
9 	short	f_flag;		/* see below */
10 	short	f_type;		/* descriptor type */
11 	short	f_count;	/* reference count */
12 	short	f_msgcount;	/* references from message queue */
13 	struct	fileops {
14 		int	(*fo_rw)();
15 		int	(*fo_ioctl)();
16 		int	(*fo_select)();
17 		int	(*fo_stat)();
18 		int	(*fo_close)();
19 	} *f_ops;
20 	caddr_t	f_data;		/* inode */
21 	off_t	f_offset;
22 };
23 
24 struct	file *file, *fileNFILE;
25 int	nfile;
26 struct	file *getf();
27 struct	file *falloc();
28 
29 /* flags */
30 #define	FOPEN		(-1)
31 #define	FREAD		00001		/* descriptor read/receive'able */
32 #define	FWRITE		00002		/* descriptor write/send'able */
33 #define	FNDELAY		00004		/* no delay */
34 #define	FAPPEND		00010		/* append on each write */
35 #define	FMARK		00020		/* mark during gc() */
36 #define	FDEFER		00040		/* defer for next gc pass */
37 #define	FASYNC		00100		/* signal pgrp when data ready */
38 
39 /* bits to save after open */
40 #define	FMASK		00117
41 #define	FCNTLCANT	(FREAD|FWRITE|FMARK|FDEFER)
42 #endif
43 
44 /* open only modes */
45 #define	FCREAT		01000		/* create if nonexistant */
46 #define	FTRUNC		02000		/* truncate to zero length */
47 #define	FEXCL		04000		/* error if already created */
48 
49 /*
50  * User definitions.
51  */
52 
53 /*
54  * Open call.
55  */
56 #define	O_RDONLY	000		/* open for reading */
57 #define	O_WRONLY	001		/* open for writing */
58 #define	O_RDWR		002		/* open for read & write */
59 #define	O_NDELAY	004 		/* non-blocking open */
60 #define	O_APPEND	010		/* append on each write */
61 #define	O_CREAT		FCREAT		/* open with file create */
62 #define	O_TRUNC		FTRUNC		/* open with truncation */
63 #define	O_EXCL		FEXCL		/* error on create if file exists */
64 
65 /*
66  * Flock call.
67  */
68 #define	LOCK_SH		1	/* shared lock */
69 #define	LOCK_EX		2	/* exclusive lock */
70 #define	LOCK_NB		4	/* don't block when locking */
71 #define	LOCK_UN		8	/* unlock */
72 
73 /*
74  * Access call.
75  */
76 #define	F_OK		0	/* does file exist */
77 #define	X_OK		1	/* is it executable by caller */
78 #define	W_OK		2	/* writable by caller */
79 #define	R_OK		4	/* readable by caller */
80 
81 /*
82  * Lseek call.
83  */
84 #define	L_SET		0	/* absolute offset */
85 #define	L_INCR		1	/* relative to current offset */
86 #define	L_XTND		2	/* relative to end of file */
87 
88 #ifdef KERNEL
89 #define	GETF(fp, fd) { \
90 	if ((unsigned)(fd) >= NOFILE || ((fp) = u.u_ofile[fd]) == NULL) { \
91 		u.u_error = EBADF; \
92 		return; \
93 	} \
94 }
95 #define	DTYPE_INODE	1	/* file */
96 #define	DTYPE_SOCKET	2	/* communications endpoint */
97 #endif
98