xref: /original-bsd/sys/sys/file.h (revision 4c3b28fe)
1 /*
2  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)file.h	7.4 (Berkeley) 09/06/89
18  */
19 
20 #ifdef KERNEL
21 /*
22  * Descriptor table entry.
23  * One for each kernel object.
24  */
25 struct	file {
26 	int	f_flag;		/* see below */
27 	short	f_type;		/* descriptor type */
28 	short	f_count;	/* reference count */
29 	short	f_msgcount;	/* references from message queue */
30 	struct	ucred *f_cred;	/* credentials associated with descriptor */
31 	struct	fileops {
32 		int	(*fo_read)();
33 		int	(*fo_write)();
34 		int	(*fo_ioctl)();
35 		int	(*fo_select)();
36 		int	(*fo_close)();
37 	} *f_ops;
38 	caddr_t	f_data;		/* inode */
39 	off_t	f_offset;
40 };
41 
42 struct	file *file, *fileNFILE;
43 int	nfile;
44 #endif
45 
46 /*
47  * flags- also for fcntl call.
48  */
49 #define	FOPEN		(-1)
50 #define	FREAD		00001		/* descriptor read/receive'able */
51 #define	FWRITE		00002		/* descriptor write/send'able */
52 #ifndef	F_DUPFD
53 #define	FNDELAY		00004		/* no delay */
54 #define	FAPPEND		00010		/* append on each write */
55 #endif
56 #define	FMARK		00020		/* mark during gc() */
57 #define	FDEFER		00040		/* defer for next gc pass */
58 #ifndef	F_DUPFD
59 #define	FASYNC		00100		/* signal pgrp when data ready */
60 #endif
61 #define	FSHLOCK		00200		/* shared lock present */
62 #define	FEXLOCK		00400		/* exclusive lock present */
63 
64 /* bits to save after open */
65 #define	FMASK		(FASYNC|FAPPEND|FNDELAY|FWRITE|FREAD)
66 #define	FCNTLCANT	(FREAD|FWRITE|FMARK|FDEFER|FSHLOCK|FEXLOCK)
67 
68 /* open only modes */
69 #define	FCREAT		01000		/* create if nonexistant */
70 #define	FTRUNC		02000		/* truncate to zero length */
71 #define	FEXCL		04000		/* error if already created */
72 
73 #ifndef	F_DUPFD
74 /* fcntl(2) requests--from <fcntl.h> */
75 #define	F_DUPFD	0	/* Duplicate fildes */
76 #define	F_GETFD	1	/* Get fildes flags */
77 #define	F_SETFD	2	/* Set fildes flags */
78 #define	F_GETFL	3	/* Get file flags */
79 #define	F_SETFL	4	/* Set file flags */
80 #define	F_GETOWN 5	/* Get owner */
81 #define F_SETOWN 6	/* Set owner */
82 #endif
83 
84 /*
85  * User definitions.
86  */
87 
88 /*
89  * Open call.
90  */
91 #define	O_RDONLY	000		/* open for reading */
92 #define	O_WRONLY	001		/* open for writing */
93 #define	O_RDWR		002		/* open for read & write */
94 #define	O_NDELAY	FNDELAY		/* non-blocking open on file */
95 #define O_NONBLOCK	FNDELAY		/* ditto */
96 #define	O_APPEND	FAPPEND		/* append on each write */
97 #define	O_CREAT		FCREAT		/* open with file create */
98 #define	O_TRUNC		FTRUNC		/* open with truncation */
99 #define	O_EXCL		FEXCL		/* error on create if file exists */
100 
101 /*
102  * Flock call.
103  */
104 #define	LOCK_SH		1	/* shared lock */
105 #define	LOCK_EX		2	/* exclusive lock */
106 #define	LOCK_NB		4	/* don't block when locking */
107 #define	LOCK_UN		8	/* unlock */
108 
109 /*
110  * Access call.
111  */
112 #define	F_OK		0	/* does file exist */
113 #define	X_OK		1	/* is it executable by caller */
114 #define	W_OK		2	/* writable by caller */
115 #define	R_OK		4	/* readable by caller */
116 
117 /*
118  * Lseek call.
119  */
120 #define	L_SET		0	/* absolute offset */
121 #define	L_INCR		1	/* relative to current offset */
122 #define	L_XTND		2	/* relative to end of file */
123 
124 #ifdef KERNEL
125 #define	DTYPE_VNODE	1	/* file */
126 #define	DTYPE_SOCKET	2	/* communications endpoint */
127 #endif
128