xref: /titanic_44/usr/src/uts/common/sys/file.h (revision b075ad5b007248d50e4c2e838b460c9c7cfd9fad)
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  */
21794f0adbSRoger A. Faulkner 
22794f0adbSRoger A. Faulkner /*
23794f0adbSRoger A. Faulkner  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24794f0adbSRoger A. Faulkner  */
25794f0adbSRoger A. Faulkner 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
29*b075ad5bSTheo Schlossnagle /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
30*b075ad5bSTheo Schlossnagle 
317c478bd9Sstevel@tonic-gate #ifndef _SYS_FILE_H
327c478bd9Sstevel@tonic-gate #define	_SYS_FILE_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
357c478bd9Sstevel@tonic-gate #ifdef _KERNEL
367c478bd9Sstevel@tonic-gate #include <sys/model.h>
377c478bd9Sstevel@tonic-gate #include <sys/user.h>
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
417c478bd9Sstevel@tonic-gate extern "C" {
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * fio locking:
467c478bd9Sstevel@tonic-gate  *   f_rwlock	protects f_vnode and f_cred
477c478bd9Sstevel@tonic-gate  *   f_tlock	protects the rest
487c478bd9Sstevel@tonic-gate  *
497c478bd9Sstevel@tonic-gate  *   The purpose of locking in this layer is to keep the kernel
507c478bd9Sstevel@tonic-gate  *   from panicing if, for example, a thread calls close() while
517c478bd9Sstevel@tonic-gate  *   another thread is doing a read().  It is up to higher levels
527c478bd9Sstevel@tonic-gate  *   to make sure 2 threads doing I/O to the same file don't
537c478bd9Sstevel@tonic-gate  *   screw each other up.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * One file structure is allocated for each open/creat/pipe call.
577c478bd9Sstevel@tonic-gate  * Main use is to hold the read/write pointer associated with
587c478bd9Sstevel@tonic-gate  * each open file.
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate typedef struct file {
617c478bd9Sstevel@tonic-gate 	kmutex_t	f_tlock;	/* short term lock */
627c478bd9Sstevel@tonic-gate 	ushort_t	f_flag;
63794f0adbSRoger A. Faulkner 	ushort_t	f_flag2;	/* extra flags (FSEARCH, FEXEC) */
647c478bd9Sstevel@tonic-gate 	struct vnode	*f_vnode;	/* pointer to vnode structure */
657c478bd9Sstevel@tonic-gate 	offset_t	f_offset;	/* read/write character pointer */
667c478bd9Sstevel@tonic-gate 	struct cred	*f_cred;	/* credentials of user who opened it */
677c478bd9Sstevel@tonic-gate 	struct f_audit_data	*f_audit_data;	/* file audit data */
687c478bd9Sstevel@tonic-gate 	int		f_count;	/* reference count */
697c478bd9Sstevel@tonic-gate } file_t;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * fpollinfo struct - used by poll caching to track who has polled the fd
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate typedef struct fpollinfo {
757c478bd9Sstevel@tonic-gate 	struct _kthread		*fp_thread;	/* thread caching poll info */
767c478bd9Sstevel@tonic-gate 	struct fpollinfo	*fp_next;
777c478bd9Sstevel@tonic-gate } fpollinfo_t;
787c478bd9Sstevel@tonic-gate 
79794f0adbSRoger A. Faulkner /* f_flag */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	FOPEN		0xffffffff
827c478bd9Sstevel@tonic-gate #define	FREAD		0x01	/* <sys/aiocb.h> LIO_READ must be identical */
837c478bd9Sstevel@tonic-gate #define	FWRITE		0x02	/* <sys/aiocb.h> LIO_WRITE must be identical */
847c478bd9Sstevel@tonic-gate #define	FNDELAY		0x04
857c478bd9Sstevel@tonic-gate #define	FAPPEND		0x08
867c478bd9Sstevel@tonic-gate #define	FSYNC		0x10	/* file (data+inode) integrity while writing */
87d3e55dcdSgww #define	FREVOKED	0x20	/* Object reuse Revoked file */
887c478bd9Sstevel@tonic-gate #define	FDSYNC		0x40	/* file data only integrity while writing */
897c478bd9Sstevel@tonic-gate #define	FNONBLOCK	0x80
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #define	FMASK		0xa0ff	/* all flags that can be changed by F_SETFL */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* open-only modes */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #define	FCREAT		0x0100
967c478bd9Sstevel@tonic-gate #define	FTRUNC		0x0200
977c478bd9Sstevel@tonic-gate #define	FEXCL		0x0400
987c478bd9Sstevel@tonic-gate #define	FASYNC		0x1000	/* asyncio in progress pseudo flag */
99da6c28aaSamw #define	FOFFMAX		0x2000	/* large file */
100da6c28aaSamw #define	FXATTR		0x4000	/* open as extended attribute */
101da6c28aaSamw #define	FNOCTTY		0x0800
102da6c28aaSamw #define	FRSYNC		0x8000	/* sync read operations at same level of */
103da6c28aaSamw 				/* integrity as specified for writes by */
104da6c28aaSamw 				/* FSYNC and FDSYNC flags */
105da6c28aaSamw 
1067c478bd9Sstevel@tonic-gate #define	FNODSYNC	0x10000 /* fsync pseudo flag */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #define	FNOFOLLOW	0x20000	/* don't follow symlinks */
1097c478bd9Sstevel@tonic-gate #define	FNOLINKS	0x40000	/* don't allow multiple hard links */
110da6c28aaSamw #define	FIGNORECASE	0x80000 /* request case-insensitive lookups */
111da6c28aaSamw #define	FXATTRDIROPEN	0x100000  /* only opening hidden attribute directory */
1127c478bd9Sstevel@tonic-gate 
113794f0adbSRoger A. Faulkner /* f_flag2 (open-only) */
114794f0adbSRoger A. Faulkner 
115794f0adbSRoger A. Faulkner #define	FSEARCH		0x200000	/* O_SEARCH = 0x200000 */
116794f0adbSRoger A. Faulkner #define	FEXEC		0x400000	/* O_EXEC = 0x400000 */
117794f0adbSRoger A. Faulkner 
118*b075ad5bSTheo Schlossnagle #define	FCLOEXEC	0x800000	/* O_CLOEXEC = 0x800000 */
119*b075ad5bSTheo Schlossnagle 
1207c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate  * Fake flags for driver ioctl calls to inform them of the originating
1247c478bd9Sstevel@tonic-gate  * process' model.  See <sys/model.h>
1257c478bd9Sstevel@tonic-gate  *
1267c478bd9Sstevel@tonic-gate  * Part of the Solaris 2.6+ DDI/DKI
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate #define	FMODELS	DATAMODEL_MASK	/* Note: 0x0ff00000 */
1297c478bd9Sstevel@tonic-gate #define	FILP32	DATAMODEL_ILP32
1307c478bd9Sstevel@tonic-gate #define	FLP64	DATAMODEL_LP64
1317c478bd9Sstevel@tonic-gate #define	FNATIVE	DATAMODEL_NATIVE
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * Large Files: The macro gets the offset maximum (refer to LFS API doc)
1357c478bd9Sstevel@tonic-gate  * corresponding to a file descriptor. We had the choice of storing
1367c478bd9Sstevel@tonic-gate  * this value in file descriptor. Right now we only have two
1377c478bd9Sstevel@tonic-gate  * offset maximums one if MAXOFF_T and other is MAXOFFSET_T. It is
1387c478bd9Sstevel@tonic-gate  * inefficient to store these two values in a separate member in
1397c478bd9Sstevel@tonic-gate  * file descriptor. To avoid wasting spaces we define this macro.
1407c478bd9Sstevel@tonic-gate  * The day there are more than two offset maximum we may want to
1417c478bd9Sstevel@tonic-gate  * rewrite this macro.
1427c478bd9Sstevel@tonic-gate  */
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #define	OFFSET_MAX(fd)	((fd->f_flag & FOFFMAX) ? MAXOFFSET_T : MAXOFF32_T)
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /*
1477c478bd9Sstevel@tonic-gate  * Fake flag => internal ioctl call for layered drivers.
1487c478bd9Sstevel@tonic-gate  * Note that this flag deliberately *won't* fit into
1497c478bd9Sstevel@tonic-gate  * the f_flag field of a file_t.
1507c478bd9Sstevel@tonic-gate  *
1517c478bd9Sstevel@tonic-gate  * Part of the Solaris 2.x DDI/DKI.
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate #define	FKIOCTL		0x80000000	/* ioctl addresses are from kernel */
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * Fake flag => this time to specify that the open(9E)
1577c478bd9Sstevel@tonic-gate  * comes from another part of the kernel, not userland.
1587c478bd9Sstevel@tonic-gate  *
1597c478bd9Sstevel@tonic-gate  * Part of the Solaris 2.x DDI/DKI.
1607c478bd9Sstevel@tonic-gate  */
1617c478bd9Sstevel@tonic-gate #define	FKLYR		0x40000000	/* layered driver call */
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /* miscellaneous defines */
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate #ifndef L_SET
1687c478bd9Sstevel@tonic-gate #define	L_SET	0	/* for lseek */
1697c478bd9Sstevel@tonic-gate #endif /* L_SET */
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate /*
1747c478bd9Sstevel@tonic-gate  * Routines dealing with user per-open file flags and
1757c478bd9Sstevel@tonic-gate  * user open files.
1767c478bd9Sstevel@tonic-gate  */
1777c478bd9Sstevel@tonic-gate struct proc;	/* forward reference for function prototype */
1787c478bd9Sstevel@tonic-gate struct vnodeops;
179794f0adbSRoger A. Faulkner struct vattr;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate extern file_t *getf(int);
1827c478bd9Sstevel@tonic-gate extern void releasef(int);
1837c478bd9Sstevel@tonic-gate extern void areleasef(int, uf_info_t *);
1847c478bd9Sstevel@tonic-gate #ifndef	_BOOT
1857c478bd9Sstevel@tonic-gate extern void closeall(uf_info_t *);
1867c478bd9Sstevel@tonic-gate #endif
1877c478bd9Sstevel@tonic-gate extern void flist_fork(uf_info_t *, uf_info_t *);
1887c478bd9Sstevel@tonic-gate extern int closef(file_t *);
1897c478bd9Sstevel@tonic-gate extern int closeandsetf(int, file_t *);
1907c478bd9Sstevel@tonic-gate extern int ufalloc_file(int, file_t *);
1917c478bd9Sstevel@tonic-gate extern int ufalloc(int);
1922cb27123Saguzovsk extern int ufcanalloc(struct proc *, uint_t);
1937c478bd9Sstevel@tonic-gate extern int falloc(struct vnode *, int, file_t **, int *);
1947c478bd9Sstevel@tonic-gate extern void finit(void);
1957c478bd9Sstevel@tonic-gate extern void unfalloc(file_t *);
1967c478bd9Sstevel@tonic-gate extern void setf(int, file_t *);
1977c478bd9Sstevel@tonic-gate extern int f_getfd_error(int, int *);
1987c478bd9Sstevel@tonic-gate extern char f_getfd(int);
1997c478bd9Sstevel@tonic-gate extern int f_setfd_error(int, int);
2007c478bd9Sstevel@tonic-gate extern void f_setfd(int, char);
2017c478bd9Sstevel@tonic-gate extern int f_getfl(int, int *);
202a5f69788Scraigm extern int f_badfd(int, int *, int);
2037c478bd9Sstevel@tonic-gate extern int fassign(struct vnode **, int, int *);
2047c478bd9Sstevel@tonic-gate extern void fcnt_add(uf_info_t *, int);
2057c478bd9Sstevel@tonic-gate extern void close_exec(uf_info_t *);
2067c478bd9Sstevel@tonic-gate extern void clear_stale_fd(void);
2077c478bd9Sstevel@tonic-gate extern void clear_active_fd(int);
2087c478bd9Sstevel@tonic-gate extern void free_afd(afd_t *afd);
209794f0adbSRoger A. Faulkner extern int fgetstartvp(int, char *, struct vnode **);
210794f0adbSRoger A. Faulkner extern int fsetattrat(int, char *, int, struct vattr *);
2117c478bd9Sstevel@tonic-gate extern int fisopen(struct vnode *);
2127c478bd9Sstevel@tonic-gate extern void delfpollinfo(int);
2137c478bd9Sstevel@tonic-gate extern void addfpollinfo(int);
2147c478bd9Sstevel@tonic-gate extern int sock_getfasync(struct vnode *);
2157c478bd9Sstevel@tonic-gate extern int files_can_change_zones(void);
2167c478bd9Sstevel@tonic-gate #ifdef DEBUG
2177c478bd9Sstevel@tonic-gate /* The following functions are only used in ASSERT()s */
2187c478bd9Sstevel@tonic-gate extern void checkwfdlist(struct vnode *, fpollinfo_t *);
2197c478bd9Sstevel@tonic-gate extern void checkfpollinfo(void);
2207c478bd9Sstevel@tonic-gate extern int infpollinfo(int);
2217c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate #endif
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate #endif	/* _SYS_FILE_H */
230