xref: /onnv-gate/usr/src/uts/common/sys/file.h (revision 12789:82cffaae72d5)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51846Scraigm  * Common Development and Distribution License (the "License").
61846Scraigm  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*12789SRoger.Faulkner@Oracle.COM 
22*12789SRoger.Faulkner@Oracle.COM /*
23*12789SRoger.Faulkner@Oracle.COM  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24*12789SRoger.Faulkner@Oracle.COM  */
25*12789SRoger.Faulkner@Oracle.COM 
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifndef _SYS_FILE_H
300Sstevel@tonic-gate #define	_SYS_FILE_H
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/t_lock.h>
330Sstevel@tonic-gate #ifdef _KERNEL
340Sstevel@tonic-gate #include <sys/model.h>
350Sstevel@tonic-gate #include <sys/user.h>
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef	__cplusplus
390Sstevel@tonic-gate extern "C" {
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * fio locking:
440Sstevel@tonic-gate  *   f_rwlock	protects f_vnode and f_cred
450Sstevel@tonic-gate  *   f_tlock	protects the rest
460Sstevel@tonic-gate  *
470Sstevel@tonic-gate  *   The purpose of locking in this layer is to keep the kernel
480Sstevel@tonic-gate  *   from panicing if, for example, a thread calls close() while
490Sstevel@tonic-gate  *   another thread is doing a read().  It is up to higher levels
500Sstevel@tonic-gate  *   to make sure 2 threads doing I/O to the same file don't
510Sstevel@tonic-gate  *   screw each other up.
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate  * One file structure is allocated for each open/creat/pipe call.
550Sstevel@tonic-gate  * Main use is to hold the read/write pointer associated with
560Sstevel@tonic-gate  * each open file.
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate typedef struct file {
590Sstevel@tonic-gate 	kmutex_t	f_tlock;	/* short term lock */
600Sstevel@tonic-gate 	ushort_t	f_flag;
61*12789SRoger.Faulkner@Oracle.COM 	ushort_t	f_flag2;	/* extra flags (FSEARCH, FEXEC) */
620Sstevel@tonic-gate 	struct vnode	*f_vnode;	/* pointer to vnode structure */
630Sstevel@tonic-gate 	offset_t	f_offset;	/* read/write character pointer */
640Sstevel@tonic-gate 	struct cred	*f_cred;	/* credentials of user who opened it */
650Sstevel@tonic-gate 	struct f_audit_data	*f_audit_data;	/* file audit data */
660Sstevel@tonic-gate 	int		f_count;	/* reference count */
670Sstevel@tonic-gate } file_t;
680Sstevel@tonic-gate 
690Sstevel@tonic-gate /*
700Sstevel@tonic-gate  * fpollinfo struct - used by poll caching to track who has polled the fd
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate typedef struct fpollinfo {
730Sstevel@tonic-gate 	struct _kthread		*fp_thread;	/* thread caching poll info */
740Sstevel@tonic-gate 	struct fpollinfo	*fp_next;
750Sstevel@tonic-gate } fpollinfo_t;
760Sstevel@tonic-gate 
77*12789SRoger.Faulkner@Oracle.COM /* f_flag */
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #define	FOPEN		0xffffffff
800Sstevel@tonic-gate #define	FREAD		0x01	/* <sys/aiocb.h> LIO_READ must be identical */
810Sstevel@tonic-gate #define	FWRITE		0x02	/* <sys/aiocb.h> LIO_WRITE must be identical */
820Sstevel@tonic-gate #define	FNDELAY		0x04
830Sstevel@tonic-gate #define	FAPPEND		0x08
840Sstevel@tonic-gate #define	FSYNC		0x10	/* file (data+inode) integrity while writing */
855753Sgww #define	FREVOKED	0x20	/* Object reuse Revoked file */
860Sstevel@tonic-gate #define	FDSYNC		0x40	/* file data only integrity while writing */
870Sstevel@tonic-gate #define	FNONBLOCK	0x80
880Sstevel@tonic-gate 
890Sstevel@tonic-gate #define	FMASK		0xa0ff	/* all flags that can be changed by F_SETFL */
900Sstevel@tonic-gate 
910Sstevel@tonic-gate /* open-only modes */
920Sstevel@tonic-gate 
930Sstevel@tonic-gate #define	FCREAT		0x0100
940Sstevel@tonic-gate #define	FTRUNC		0x0200
950Sstevel@tonic-gate #define	FEXCL		0x0400
965331Samw #define	FASYNC		0x1000	/* asyncio in progress pseudo flag */
975331Samw #define	FOFFMAX		0x2000	/* large file */
980Sstevel@tonic-gate #define	FXATTR		0x4000	/* open as extended attribute */
995331Samw #define	FNOCTTY		0x0800
1005331Samw #define	FRSYNC		0x8000	/* sync read operations at same level of */
1015331Samw 				/* integrity as specified for writes by */
1025331Samw 				/* FSYNC and FDSYNC flags */
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate #define	FNODSYNC	0x10000 /* fsync pseudo flag */
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate #define	FNOFOLLOW	0x20000	/* don't follow symlinks */
1070Sstevel@tonic-gate #define	FNOLINKS	0x40000	/* don't allow multiple hard links */
1085331Samw #define	FIGNORECASE	0x80000 /* request case-insensitive lookups */
1095331Samw #define	FXATTRDIROPEN	0x100000  /* only opening hidden attribute directory */
1100Sstevel@tonic-gate 
111*12789SRoger.Faulkner@Oracle.COM /* f_flag2 (open-only) */
112*12789SRoger.Faulkner@Oracle.COM 
113*12789SRoger.Faulkner@Oracle.COM #define	FSEARCH		0x200000	/* O_SEARCH = 0x200000 */
114*12789SRoger.Faulkner@Oracle.COM #define	FEXEC		0x400000	/* O_EXEC = 0x400000 */
115*12789SRoger.Faulkner@Oracle.COM 
1160Sstevel@tonic-gate #ifdef _KERNEL
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate /*
1190Sstevel@tonic-gate  * Fake flags for driver ioctl calls to inform them of the originating
1200Sstevel@tonic-gate  * process' model.  See <sys/model.h>
1210Sstevel@tonic-gate  *
1220Sstevel@tonic-gate  * Part of the Solaris 2.6+ DDI/DKI
1230Sstevel@tonic-gate  */
1240Sstevel@tonic-gate #define	FMODELS	DATAMODEL_MASK	/* Note: 0x0ff00000 */
1250Sstevel@tonic-gate #define	FILP32	DATAMODEL_ILP32
1260Sstevel@tonic-gate #define	FLP64	DATAMODEL_LP64
1270Sstevel@tonic-gate #define	FNATIVE	DATAMODEL_NATIVE
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate /*
1300Sstevel@tonic-gate  * Large Files: The macro gets the offset maximum (refer to LFS API doc)
1310Sstevel@tonic-gate  * corresponding to a file descriptor. We had the choice of storing
1320Sstevel@tonic-gate  * this value in file descriptor. Right now we only have two
1330Sstevel@tonic-gate  * offset maximums one if MAXOFF_T and other is MAXOFFSET_T. It is
1340Sstevel@tonic-gate  * inefficient to store these two values in a separate member in
1350Sstevel@tonic-gate  * file descriptor. To avoid wasting spaces we define this macro.
1360Sstevel@tonic-gate  * The day there are more than two offset maximum we may want to
1370Sstevel@tonic-gate  * rewrite this macro.
1380Sstevel@tonic-gate  */
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate #define	OFFSET_MAX(fd)	((fd->f_flag & FOFFMAX) ? MAXOFFSET_T : MAXOFF32_T)
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate /*
1430Sstevel@tonic-gate  * Fake flag => internal ioctl call for layered drivers.
1440Sstevel@tonic-gate  * Note that this flag deliberately *won't* fit into
1450Sstevel@tonic-gate  * the f_flag field of a file_t.
1460Sstevel@tonic-gate  *
1470Sstevel@tonic-gate  * Part of the Solaris 2.x DDI/DKI.
1480Sstevel@tonic-gate  */
1490Sstevel@tonic-gate #define	FKIOCTL		0x80000000	/* ioctl addresses are from kernel */
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate /*
1520Sstevel@tonic-gate  * Fake flag => this time to specify that the open(9E)
1530Sstevel@tonic-gate  * comes from another part of the kernel, not userland.
1540Sstevel@tonic-gate  *
1550Sstevel@tonic-gate  * Part of the Solaris 2.x DDI/DKI.
1560Sstevel@tonic-gate  */
1570Sstevel@tonic-gate #define	FKLYR		0x40000000	/* layered driver call */
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate #endif	/* _KERNEL */
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /* miscellaneous defines */
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate #ifndef L_SET
1640Sstevel@tonic-gate #define	L_SET	0	/* for lseek */
1650Sstevel@tonic-gate #endif /* L_SET */
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate #if defined(_KERNEL)
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate /*
1700Sstevel@tonic-gate  * Routines dealing with user per-open file flags and
1710Sstevel@tonic-gate  * user open files.
1720Sstevel@tonic-gate  */
1730Sstevel@tonic-gate struct proc;	/* forward reference for function prototype */
1740Sstevel@tonic-gate struct vnodeops;
175*12789SRoger.Faulkner@Oracle.COM struct vattr;
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate extern file_t *getf(int);
1780Sstevel@tonic-gate extern void releasef(int);
1790Sstevel@tonic-gate extern void areleasef(int, uf_info_t *);
1800Sstevel@tonic-gate #ifndef	_BOOT
1810Sstevel@tonic-gate extern void closeall(uf_info_t *);
1820Sstevel@tonic-gate #endif
1830Sstevel@tonic-gate extern void flist_fork(uf_info_t *, uf_info_t *);
1840Sstevel@tonic-gate extern int closef(file_t *);
1850Sstevel@tonic-gate extern int closeandsetf(int, file_t *);
1860Sstevel@tonic-gate extern int ufalloc_file(int, file_t *);
1870Sstevel@tonic-gate extern int ufalloc(int);
1884426Saguzovsk extern int ufcanalloc(struct proc *, uint_t);
1890Sstevel@tonic-gate extern int falloc(struct vnode *, int, file_t **, int *);
1900Sstevel@tonic-gate extern void finit(void);
1910Sstevel@tonic-gate extern void unfalloc(file_t *);
1920Sstevel@tonic-gate extern void setf(int, file_t *);
1930Sstevel@tonic-gate extern int f_getfd_error(int, int *);
1940Sstevel@tonic-gate extern char f_getfd(int);
1950Sstevel@tonic-gate extern int f_setfd_error(int, int);
1960Sstevel@tonic-gate extern void f_setfd(int, char);
1970Sstevel@tonic-gate extern int f_getfl(int, int *);
1981846Scraigm extern int f_badfd(int, int *, int);
1990Sstevel@tonic-gate extern int fassign(struct vnode **, int, int *);
2000Sstevel@tonic-gate extern void fcnt_add(uf_info_t *, int);
2010Sstevel@tonic-gate extern void close_exec(uf_info_t *);
2020Sstevel@tonic-gate extern void clear_stale_fd(void);
2030Sstevel@tonic-gate extern void clear_active_fd(int);
2040Sstevel@tonic-gate extern void free_afd(afd_t *afd);
205*12789SRoger.Faulkner@Oracle.COM extern int fgetstartvp(int, char *, struct vnode **);
206*12789SRoger.Faulkner@Oracle.COM extern int fsetattrat(int, char *, int, struct vattr *);
2070Sstevel@tonic-gate extern int fisopen(struct vnode *);
2080Sstevel@tonic-gate extern void delfpollinfo(int);
2090Sstevel@tonic-gate extern void addfpollinfo(int);
2100Sstevel@tonic-gate extern int sock_getfasync(struct vnode *);
2110Sstevel@tonic-gate extern int files_can_change_zones(void);
2120Sstevel@tonic-gate #ifdef DEBUG
2130Sstevel@tonic-gate /* The following functions are only used in ASSERT()s */
2140Sstevel@tonic-gate extern void checkwfdlist(struct vnode *, fpollinfo_t *);
2150Sstevel@tonic-gate extern void checkfpollinfo(void);
2160Sstevel@tonic-gate extern int infpollinfo(int);
2170Sstevel@tonic-gate #endif	/* DEBUG */
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate #ifdef	__cplusplus
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate #endif
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate #endif	/* _SYS_FILE_H */
226