xref: /original-bsd/sys/sys/file.h (revision a5e8528f)
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.5 (Berkeley) 05/25/90
18  */
19 
20 #ifdef KERNEL
21 #include "fcntl.h"
22 #include "unistd.h"
23 
24 /*
25  * Descriptor table entry.
26  * One for each kernel object.
27  */
28 struct file {
29 	int	f_flag;		/* see below */
30 #define	DTYPE_VNODE	1	/* file */
31 #define	DTYPE_SOCKET	2	/* communications endpoint */
32 	short	f_type;		/* descriptor type */
33 	short	f_count;	/* reference count */
34 	short	f_msgcount;	/* references from message queue */
35 	struct	ucred *f_cred;	/* credentials associated with descriptor */
36 	struct	fileops {
37 		int	(*fo_read)();
38 		int	(*fo_write)();
39 		int	(*fo_ioctl)();
40 		int	(*fo_select)();
41 		int	(*fo_close)();
42 	} *f_ops;
43 	caddr_t	f_data;		/* inode */
44 	off_t	f_offset;
45 };
46 
47 struct file *file, *fileNFILE;
48 int nfile;
49 
50 /* convert O_RDONLY/O_WRONLY/O_RDWR to FREAD/FWRITE */
51 #define	FOPEN		(-1)
52 #define	FREAD		1
53 #define	FWRITE		2
54 
55 /* kernel only versions -- deprecated, should be removed */
56 #define	FCREAT		O_CREAT
57 #define	FDEFER		O_DEFER
58 #define	FEXCL		O_EXCL
59 #define	FEXLOCK		O_EXLOCK
60 #define	FMARK		O_MARK
61 #define	FSHLOCK		O_SHLOCK
62 #define	FTRUNC		O_TRUNC
63 
64 /* bits to save after open */
65 #define	FMASK		(FREAD|FWRITE|O_APPEND|O_ASYNC|O_NONBLOCK)
66 /* bits not settable by fcntl(F_SETFL, ...) */
67 #define	FCNTLCANT	(FREAD|FWRITE|O_DEFER|O_EXLOCK|O_MARK|O_SHLOCK)
68 
69 #else
70 
71 #include <sys/fcntl.h>
72 #include <sys/unistd.h>
73 
74 #endif
75 
76 /* operation for lseek(2); renamed by POSIX 1003.1 to unistd.h */
77 #define	L_SET		0	/* set file offset to offset */
78 #define	L_INCR		1	/* set file offset to current plus offset */
79 #define	L_XTND		2	/* set file offset to EOF plus offset */
80