xref: /original-bsd/sys/sys/file.h (revision f0fd5f8a)
1 /*	file.h	4.14	82/11/13	*/
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 	char	f_nbhow;	/* state from dnblock */
12 	char	f_sighow;	/* state from dsignal */
13 	short	f_count;		/* reference count */
14 /* begin XXX */
15 	struct	inode *f_inode;		/* inode */
16 	union {
17 		struct f_in { off_t fi_offset; } f_in;
18 		struct f_so { struct socket *fs_socket; } f_so;
19 	} f_un;
20 #define f_offset	f_un.f_in.fi_offset
21 #define	f_socket	f_un.f_so.fs_socket
22 /* end XXX */
23 };
24 
25 struct	file *file, *fileNFILE;
26 int	nfile;
27 struct	file *getf();
28 struct	file *falloc();
29 
30 /* flags */
31 #define	FREAD		0x001		/* descriptor read/receive'able */
32 #define	FWRITE		0x002		/* descriptor write/send'able */
33 #define	FAPPEND		0x004		/* append on each write */
34 /* the following defines the bits that users can set in f_flag */
35 #define	FMODES	(FREAD|FWRITE|FAPPEND)
36 #endif
37 
38 /*
39  * User visible desriptor attributes.
40  * These are supplied at open or flock time.
41  * FRDONLY, FWRONLY, and FRDWR are
42  * converted to FREAD and FWRITE on open.
43  */
44 #define	FRDONLY		0x000		/* open for reading only */
45 #define	FWRONLY		0x001		/* open for writing only */
46 #define	FRDWR		0x002		/* open for reading and writing */
47 #define	FAPPEND		0x004		/* append on each write */
48 #define	FSHLOCK		0x008		/* apply shared lock */
49 #define	FEXLOCK		0x010		/* apply exclusive lock */
50 #define	FUNLOCK		0x100		/* release all locks */
51 #define	FCREATE		0x200		/* create file if nonexistant */
52 #define	FTRUNCATE	0x400		/* truncate file to size 0 on open */
53 #define	FNBLOCK		0x800		/* don't block on open */
54 
55 /* these are for 3.0 "compatibility" */
56 #define	O_RDONLY	FRDONLY		/* open for read */
57 #define	O_WRONLY	FWRONLY		/* open for writing */
58 #define	O_RDWR		FRDWR		/* open for read & write */
59 #define	O_NDELAY	FNBLOCK 	/* non-blocking I/O */
60 #define	O_APPEND	FAPPEND		/* append */
61 #define	O_CREAT		FCREATE		/* open with file create */
62 #define	O_TRUNC		FTRUNCATE	/* open with truncation */
63 #define	O_EXCL		FEXLOCK		/* exclusive open */
64 
65 /* flags supplied to access call */
66 #define	FACCESS_EXISTS	0x0	/* does file exist */
67 #define	FACCESS_EXECUTE	0x1	/* is it executable by caller */
68 #define	FACCESS_WRITE	0x2	/* writable by caller */
69 #define	FACCESS_READ	0x4	/* readable by caller */
70 
71 /* flags supplies to lseek call */
72 #define	FSEEK_ABSOLUTE	0x0	/* absolute offset */
73 #define	FSEEK_RELATIVE	0x1	/* relative to current offset */
74 #define	FSEEK_EOF	0x2	/* relative to end of file */
75 
76 /* file types which may be specified to mknod */
77 #define	FTYPE_CDEV	0x2000	/* character special device */
78 #define	FTYPE_DIR	0x4000	/* directory */
79 #define	FTYPE_BDEV	0x8000	/* block special device */
80 
81 #define	GETF(fp, fd) { \
82 	if ((unsigned)(fd) >= NOFILE || ((fp) = u.u_ofile[fd]) == NULL) { \
83 		u.u_error = EBADF; \
84 		return; \
85 	} \
86 }
87