xref: /titanic_41/usr/src/lib/libbc/inc/include/sys/file.h (revision 99ebb4ca412cb0a19d77a3899a87c055b9c30fa8)
1 /*
2  * Copyright (c) 2001 by Sun Microsystems, Inc.
3  * All rights reserved.
4  */
5 
6 /*
7  * Copyright (c) 1982, 1986 Regents of the University of California.
8  * All rights reserved.  The Berkeley software License Agreement
9  * specifies the terms and conditions for redistribution.
10  */
11 
12 #ifndef	__SYS_FILE_H
13 #define	__SYS_FILE_H
14 
15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 #include <sys/types.h>
18 
19 #ifdef	__cplusplus
20 extern "C" {
21 #endif
22 
23 #ifdef	KERNEL
24 /*
25  * Descriptor table entry.
26  * One for each kernel object.
27  */
28 struct	file {
29 	int	f_flag;		/* see below */
30 	short	f_type;		/* descriptor type */
31 	short	f_count;	/* reference count */
32 	short	f_msgcount;	/* references from message queue */
33 	struct	fileops {
34 		int	(*fo_rw)();
35 		int	(*fo_ioctl)();
36 		int	(*fo_select)();
37 		int	(*fo_close)();
38 	} *f_ops;
39 	caddr_t	f_data;		/* ptr to file specific struct (vnode/socket) */
40 	off_t	f_offset;
41 	struct	ucred *f_cred;	/* credentials of user who opened file */
42 };
43 
44 struct	file *file, *fileNFILE;
45 int	nfile;
46 struct	file *getf();
47 struct	file *falloc();
48 #endif	/* KERNEL */
49 
50 #include <sys/fcntlcom.h>
51 
52 /*
53  * bits to save after an open.  The no delay bits mean "don't wait for
54  * carrier at open" in all cases.  Sys5 & POSIX save the no delay bits,
55  * using them to also mean "don't block on reads"; BSD has you reset it
56  * with an fcntl() if you want the "don't block on reads" behavior.
57  */
58 #define	FMASK		(FREAD|FWRITE|FAPPEND|FSYNC|FNBIO|FNONBIO)
59 #define	FCNTLCANT	(FREAD|FWRITE|FMARK|FDEFER|FSHLOCK|FEXLOCK)
60 
61 /*
62  * User definitions.
63  */
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.  Also maintained in unistd.h
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.  Also maintained in 5include/stdio.h and sys/unistd.h as SEEK_*
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 ((fd) < 0 || (fd) > u.u_lastfile || \
91 	    ((fp) = u.u_ofile[fd]) == NULL) { \
92 		u.u_error = EBADF; \
93 		return; \
94 	} \
95 }
96 
97 #define	DTYPE_VNODE	1	/* file */
98 #define	DTYPE_SOCKET	2	/* communications endpoint */
99 #endif	/* KERNEL */
100 
101 #ifdef	__cplusplus
102 }
103 #endif
104 
105 #endif	/* __SYS_FILE_H */
106