xref: /titanic_51/usr/src/uts/common/sys/file.h (revision 794f0adb050e571bbfde4d2a19b9f88b852079dd)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5a5f69788Scraigm  * Common Development and Distribution License (the "License").
6a5f69788Scraigm  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*794f0adbSRoger A. Faulkner 
22*794f0adbSRoger A. Faulkner /*
23*794f0adbSRoger A. Faulkner  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24*794f0adbSRoger A. Faulkner  */
25*794f0adbSRoger A. Faulkner 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef _SYS_FILE_H
307c478bd9Sstevel@tonic-gate #define	_SYS_FILE_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
337c478bd9Sstevel@tonic-gate #ifdef _KERNEL
347c478bd9Sstevel@tonic-gate #include <sys/model.h>
357c478bd9Sstevel@tonic-gate #include <sys/user.h>
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * fio locking:
447c478bd9Sstevel@tonic-gate  *   f_rwlock	protects f_vnode and f_cred
457c478bd9Sstevel@tonic-gate  *   f_tlock	protects the rest
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  *   The purpose of locking in this layer is to keep the kernel
487c478bd9Sstevel@tonic-gate  *   from panicing if, for example, a thread calls close() while
497c478bd9Sstevel@tonic-gate  *   another thread is doing a read().  It is up to higher levels
507c478bd9Sstevel@tonic-gate  *   to make sure 2 threads doing I/O to the same file don't
517c478bd9Sstevel@tonic-gate  *   screw each other up.
527c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * One file structure is allocated for each open/creat/pipe call.
557c478bd9Sstevel@tonic-gate  * Main use is to hold the read/write pointer associated with
567c478bd9Sstevel@tonic-gate  * each open file.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate typedef struct file {
597c478bd9Sstevel@tonic-gate 	kmutex_t	f_tlock;	/* short term lock */
607c478bd9Sstevel@tonic-gate 	ushort_t	f_flag;
61*794f0adbSRoger A. Faulkner 	ushort_t	f_flag2;	/* extra flags (FSEARCH, FEXEC) */
627c478bd9Sstevel@tonic-gate 	struct vnode	*f_vnode;	/* pointer to vnode structure */
637c478bd9Sstevel@tonic-gate 	offset_t	f_offset;	/* read/write character pointer */
647c478bd9Sstevel@tonic-gate 	struct cred	*f_cred;	/* credentials of user who opened it */
657c478bd9Sstevel@tonic-gate 	struct f_audit_data	*f_audit_data;	/* file audit data */
667c478bd9Sstevel@tonic-gate 	int		f_count;	/* reference count */
677c478bd9Sstevel@tonic-gate } file_t;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * fpollinfo struct - used by poll caching to track who has polled the fd
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate typedef struct fpollinfo {
737c478bd9Sstevel@tonic-gate 	struct _kthread		*fp_thread;	/* thread caching poll info */
747c478bd9Sstevel@tonic-gate 	struct fpollinfo	*fp_next;
757c478bd9Sstevel@tonic-gate } fpollinfo_t;
767c478bd9Sstevel@tonic-gate 
77*794f0adbSRoger A. Faulkner /* f_flag */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	FOPEN		0xffffffff
807c478bd9Sstevel@tonic-gate #define	FREAD		0x01	/* <sys/aiocb.h> LIO_READ must be identical */
817c478bd9Sstevel@tonic-gate #define	FWRITE		0x02	/* <sys/aiocb.h> LIO_WRITE must be identical */
827c478bd9Sstevel@tonic-gate #define	FNDELAY		0x04
837c478bd9Sstevel@tonic-gate #define	FAPPEND		0x08
847c478bd9Sstevel@tonic-gate #define	FSYNC		0x10	/* file (data+inode) integrity while writing */
85d3e55dcdSgww #define	FREVOKED	0x20	/* Object reuse Revoked file */
867c478bd9Sstevel@tonic-gate #define	FDSYNC		0x40	/* file data only integrity while writing */
877c478bd9Sstevel@tonic-gate #define	FNONBLOCK	0x80
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #define	FMASK		0xa0ff	/* all flags that can be changed by F_SETFL */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /* open-only modes */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #define	FCREAT		0x0100
947c478bd9Sstevel@tonic-gate #define	FTRUNC		0x0200
957c478bd9Sstevel@tonic-gate #define	FEXCL		0x0400
967c478bd9Sstevel@tonic-gate #define	FASYNC		0x1000	/* asyncio in progress pseudo flag */
97da6c28aaSamw #define	FOFFMAX		0x2000	/* large file */
98da6c28aaSamw #define	FXATTR		0x4000	/* open as extended attribute */
99da6c28aaSamw #define	FNOCTTY		0x0800
100da6c28aaSamw #define	FRSYNC		0x8000	/* sync read operations at same level of */
101da6c28aaSamw 				/* integrity as specified for writes by */
102da6c28aaSamw 				/* FSYNC and FDSYNC flags */
103da6c28aaSamw 
1047c478bd9Sstevel@tonic-gate #define	FNODSYNC	0x10000 /* fsync pseudo flag */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #define	FNOFOLLOW	0x20000	/* don't follow symlinks */
1077c478bd9Sstevel@tonic-gate #define	FNOLINKS	0x40000	/* don't allow multiple hard links */
108da6c28aaSamw #define	FIGNORECASE	0x80000 /* request case-insensitive lookups */
109da6c28aaSamw #define	FXATTRDIROPEN	0x100000  /* only opening hidden attribute directory */
1107c478bd9Sstevel@tonic-gate 
111*794f0adbSRoger A. Faulkner /* f_flag2 (open-only) */
112*794f0adbSRoger A. Faulkner 
113*794f0adbSRoger A. Faulkner #define	FSEARCH		0x200000	/* O_SEARCH = 0x200000 */
114*794f0adbSRoger A. Faulkner #define	FEXEC		0x400000	/* O_EXEC = 0x400000 */
115*794f0adbSRoger A. Faulkner 
1167c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /*
1197c478bd9Sstevel@tonic-gate  * Fake flags for driver ioctl calls to inform them of the originating
1207c478bd9Sstevel@tonic-gate  * process' model.  See <sys/model.h>
1217c478bd9Sstevel@tonic-gate  *
1227c478bd9Sstevel@tonic-gate  * Part of the Solaris 2.6+ DDI/DKI
1237c478bd9Sstevel@tonic-gate  */
1247c478bd9Sstevel@tonic-gate #define	FMODELS	DATAMODEL_MASK	/* Note: 0x0ff00000 */
1257c478bd9Sstevel@tonic-gate #define	FILP32	DATAMODEL_ILP32
1267c478bd9Sstevel@tonic-gate #define	FLP64	DATAMODEL_LP64
1277c478bd9Sstevel@tonic-gate #define	FNATIVE	DATAMODEL_NATIVE
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * Large Files: The macro gets the offset maximum (refer to LFS API doc)
1317c478bd9Sstevel@tonic-gate  * corresponding to a file descriptor. We had the choice of storing
1327c478bd9Sstevel@tonic-gate  * this value in file descriptor. Right now we only have two
1337c478bd9Sstevel@tonic-gate  * offset maximums one if MAXOFF_T and other is MAXOFFSET_T. It is
1347c478bd9Sstevel@tonic-gate  * inefficient to store these two values in a separate member in
1357c478bd9Sstevel@tonic-gate  * file descriptor. To avoid wasting spaces we define this macro.
1367c478bd9Sstevel@tonic-gate  * The day there are more than two offset maximum we may want to
1377c478bd9Sstevel@tonic-gate  * rewrite this macro.
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #define	OFFSET_MAX(fd)	((fd->f_flag & FOFFMAX) ? MAXOFFSET_T : MAXOFF32_T)
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * Fake flag => internal ioctl call for layered drivers.
1447c478bd9Sstevel@tonic-gate  * Note that this flag deliberately *won't* fit into
1457c478bd9Sstevel@tonic-gate  * the f_flag field of a file_t.
1467c478bd9Sstevel@tonic-gate  *
1477c478bd9Sstevel@tonic-gate  * Part of the Solaris 2.x DDI/DKI.
1487c478bd9Sstevel@tonic-gate  */
1497c478bd9Sstevel@tonic-gate #define	FKIOCTL		0x80000000	/* ioctl addresses are from kernel */
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate  * Fake flag => this time to specify that the open(9E)
1537c478bd9Sstevel@tonic-gate  * comes from another part of the kernel, not userland.
1547c478bd9Sstevel@tonic-gate  *
1557c478bd9Sstevel@tonic-gate  * Part of the Solaris 2.x DDI/DKI.
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate #define	FKLYR		0x40000000	/* layered driver call */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /* miscellaneous defines */
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #ifndef L_SET
1647c478bd9Sstevel@tonic-gate #define	L_SET	0	/* for lseek */
1657c478bd9Sstevel@tonic-gate #endif /* L_SET */
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * Routines dealing with user per-open file flags and
1717c478bd9Sstevel@tonic-gate  * user open files.
1727c478bd9Sstevel@tonic-gate  */
1737c478bd9Sstevel@tonic-gate struct proc;	/* forward reference for function prototype */
1747c478bd9Sstevel@tonic-gate struct vnodeops;
175*794f0adbSRoger A. Faulkner struct vattr;
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate extern file_t *getf(int);
1787c478bd9Sstevel@tonic-gate extern void releasef(int);
1797c478bd9Sstevel@tonic-gate extern void areleasef(int, uf_info_t *);
1807c478bd9Sstevel@tonic-gate #ifndef	_BOOT
1817c478bd9Sstevel@tonic-gate extern void closeall(uf_info_t *);
1827c478bd9Sstevel@tonic-gate #endif
1837c478bd9Sstevel@tonic-gate extern void flist_fork(uf_info_t *, uf_info_t *);
1847c478bd9Sstevel@tonic-gate extern int closef(file_t *);
1857c478bd9Sstevel@tonic-gate extern int closeandsetf(int, file_t *);
1867c478bd9Sstevel@tonic-gate extern int ufalloc_file(int, file_t *);
1877c478bd9Sstevel@tonic-gate extern int ufalloc(int);
1882cb27123Saguzovsk extern int ufcanalloc(struct proc *, uint_t);
1897c478bd9Sstevel@tonic-gate extern int falloc(struct vnode *, int, file_t **, int *);
1907c478bd9Sstevel@tonic-gate extern void finit(void);
1917c478bd9Sstevel@tonic-gate extern void unfalloc(file_t *);
1927c478bd9Sstevel@tonic-gate extern void setf(int, file_t *);
1937c478bd9Sstevel@tonic-gate extern int f_getfd_error(int, int *);
1947c478bd9Sstevel@tonic-gate extern char f_getfd(int);
1957c478bd9Sstevel@tonic-gate extern int f_setfd_error(int, int);
1967c478bd9Sstevel@tonic-gate extern void f_setfd(int, char);
1977c478bd9Sstevel@tonic-gate extern int f_getfl(int, int *);
198a5f69788Scraigm extern int f_badfd(int, int *, int);
1997c478bd9Sstevel@tonic-gate extern int fassign(struct vnode **, int, int *);
2007c478bd9Sstevel@tonic-gate extern void fcnt_add(uf_info_t *, int);
2017c478bd9Sstevel@tonic-gate extern void close_exec(uf_info_t *);
2027c478bd9Sstevel@tonic-gate extern void clear_stale_fd(void);
2037c478bd9Sstevel@tonic-gate extern void clear_active_fd(int);
2047c478bd9Sstevel@tonic-gate extern void free_afd(afd_t *afd);
205*794f0adbSRoger A. Faulkner extern int fgetstartvp(int, char *, struct vnode **);
206*794f0adbSRoger A. Faulkner extern int fsetattrat(int, char *, int, struct vattr *);
2077c478bd9Sstevel@tonic-gate extern int fisopen(struct vnode *);
2087c478bd9Sstevel@tonic-gate extern void delfpollinfo(int);
2097c478bd9Sstevel@tonic-gate extern void addfpollinfo(int);
2107c478bd9Sstevel@tonic-gate extern int sock_getfasync(struct vnode *);
2117c478bd9Sstevel@tonic-gate extern int files_can_change_zones(void);
2127c478bd9Sstevel@tonic-gate #ifdef DEBUG
2137c478bd9Sstevel@tonic-gate /* The following functions are only used in ASSERT()s */
2147c478bd9Sstevel@tonic-gate extern void checkwfdlist(struct vnode *, fpollinfo_t *);
2157c478bd9Sstevel@tonic-gate extern void checkfpollinfo(void);
2167c478bd9Sstevel@tonic-gate extern int infpollinfo(int);
2177c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate #endif
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #endif	/* _SYS_FILE_H */
226