xref: /illumos-gate/usr/src/uts/common/sys/file.h (revision 2cb27123)
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  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
227c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26*2cb27123Saguzovsk  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _SYS_FILE_H
317c478bd9Sstevel@tonic-gate #define	_SYS_FILE_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 11.28 */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
367c478bd9Sstevel@tonic-gate #ifdef _KERNEL
377c478bd9Sstevel@tonic-gate #include <sys/model.h>
387c478bd9Sstevel@tonic-gate #include <sys/user.h>
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * fio locking:
477c478bd9Sstevel@tonic-gate  *   f_rwlock	protects f_vnode and f_cred
487c478bd9Sstevel@tonic-gate  *   f_tlock	protects the rest
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  *   The purpose of locking in this layer is to keep the kernel
517c478bd9Sstevel@tonic-gate  *   from panicing if, for example, a thread calls close() while
527c478bd9Sstevel@tonic-gate  *   another thread is doing a read().  It is up to higher levels
537c478bd9Sstevel@tonic-gate  *   to make sure 2 threads doing I/O to the same file don't
547c478bd9Sstevel@tonic-gate  *   screw each other up.
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * One file structure is allocated for each open/creat/pipe call.
587c478bd9Sstevel@tonic-gate  * Main use is to hold the read/write pointer associated with
597c478bd9Sstevel@tonic-gate  * each open file.
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate typedef struct file {
627c478bd9Sstevel@tonic-gate 	kmutex_t	f_tlock;	/* short term lock */
637c478bd9Sstevel@tonic-gate 	ushort_t	f_flag;
647c478bd9Sstevel@tonic-gate 	ushort_t	f_pad;		/* Explicit pad to 4 byte boundary */
657c478bd9Sstevel@tonic-gate 	struct vnode	*f_vnode;	/* pointer to vnode structure */
667c478bd9Sstevel@tonic-gate 	offset_t	f_offset;	/* read/write character pointer */
677c478bd9Sstevel@tonic-gate 	struct cred	*f_cred;	/* credentials of user who opened it */
687c478bd9Sstevel@tonic-gate 	struct f_audit_data	*f_audit_data;	/* file audit data */
697c478bd9Sstevel@tonic-gate 	int		f_count;	/* reference count */
707c478bd9Sstevel@tonic-gate } file_t;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * fpollinfo struct - used by poll caching to track who has polled the fd
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate typedef struct fpollinfo {
767c478bd9Sstevel@tonic-gate 	struct _kthread		*fp_thread;	/* thread caching poll info */
777c478bd9Sstevel@tonic-gate 	struct fpollinfo	*fp_next;
787c478bd9Sstevel@tonic-gate } fpollinfo_t;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate /* flags */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #define	FOPEN		0xffffffff
837c478bd9Sstevel@tonic-gate #define	FREAD		0x01	/* <sys/aiocb.h> LIO_READ must be identical */
847c478bd9Sstevel@tonic-gate #define	FWRITE		0x02	/* <sys/aiocb.h> LIO_WRITE must be identical */
857c478bd9Sstevel@tonic-gate #define	FNDELAY		0x04
867c478bd9Sstevel@tonic-gate #define	FAPPEND		0x08
877c478bd9Sstevel@tonic-gate #define	FSYNC		0x10	/* file (data+inode) integrity while writing */
887c478bd9Sstevel@tonic-gate #ifdef C2_AUDIT
897c478bd9Sstevel@tonic-gate #define	FREVOKED	0x20	/* C2 Security - Revoke Subsystem */
907c478bd9Sstevel@tonic-gate #endif
917c478bd9Sstevel@tonic-gate #define	FDSYNC		0x40	/* file data only integrity while writing */
927c478bd9Sstevel@tonic-gate #define	FRSYNC		0x8000	/* sync read operations at same level of */
937c478bd9Sstevel@tonic-gate 				/* integrity as specified for writes by */
947c478bd9Sstevel@tonic-gate 				/* FSYNC and FDSYNC flags */
957c478bd9Sstevel@tonic-gate #define	FOFFMAX		0x2000	/* large file */
967c478bd9Sstevel@tonic-gate #define	FNONBLOCK	0x80
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #define	FMASK		0xa0ff	/* all flags that can be changed by F_SETFL */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /* open-only modes */
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate #define	FCREAT		0x0100
1037c478bd9Sstevel@tonic-gate #define	FTRUNC		0x0200
1047c478bd9Sstevel@tonic-gate #define	FEXCL		0x0400
1057c478bd9Sstevel@tonic-gate #define	FNOCTTY		0x0800
1067c478bd9Sstevel@tonic-gate #define	FXATTR		0x4000	/* open as extended attribute */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #define	FASYNC		0x1000	/* asyncio in progress pseudo flag */
1097c478bd9Sstevel@tonic-gate #define	FNODSYNC	0x10000 /* fsync pseudo flag */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #define	FNOFOLLOW	0x20000	/* don't follow symlinks */
1127c478bd9Sstevel@tonic-gate #define	FNOLINKS	0x40000	/* don't allow multiple hard links */
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * Fake flags for driver ioctl calls to inform them of the originating
1187c478bd9Sstevel@tonic-gate  * process' model.  See <sys/model.h>
1197c478bd9Sstevel@tonic-gate  *
1207c478bd9Sstevel@tonic-gate  * Part of the Solaris 2.6+ DDI/DKI
1217c478bd9Sstevel@tonic-gate  */
1227c478bd9Sstevel@tonic-gate #define	FMODELS	DATAMODEL_MASK	/* Note: 0x0ff00000 */
1237c478bd9Sstevel@tonic-gate #define	FILP32	DATAMODEL_ILP32
1247c478bd9Sstevel@tonic-gate #define	FLP64	DATAMODEL_LP64
1257c478bd9Sstevel@tonic-gate #define	FNATIVE	DATAMODEL_NATIVE
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * Large Files: The macro gets the offset maximum (refer to LFS API doc)
1297c478bd9Sstevel@tonic-gate  * corresponding to a file descriptor. We had the choice of storing
1307c478bd9Sstevel@tonic-gate  * this value in file descriptor. Right now we only have two
1317c478bd9Sstevel@tonic-gate  * offset maximums one if MAXOFF_T and other is MAXOFFSET_T. It is
1327c478bd9Sstevel@tonic-gate  * inefficient to store these two values in a separate member in
1337c478bd9Sstevel@tonic-gate  * file descriptor. To avoid wasting spaces we define this macro.
1347c478bd9Sstevel@tonic-gate  * The day there are more than two offset maximum we may want to
1357c478bd9Sstevel@tonic-gate  * rewrite this macro.
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate #define	OFFSET_MAX(fd)	((fd->f_flag & FOFFMAX) ? MAXOFFSET_T : MAXOFF32_T)
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate  * Fake flag => internal ioctl call for layered drivers.
1427c478bd9Sstevel@tonic-gate  * Note that this flag deliberately *won't* fit into
1437c478bd9Sstevel@tonic-gate  * the f_flag field of a file_t.
1447c478bd9Sstevel@tonic-gate  *
1457c478bd9Sstevel@tonic-gate  * Part of the Solaris 2.x DDI/DKI.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate #define	FKIOCTL		0x80000000	/* ioctl addresses are from kernel */
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate  * Fake flag => this time to specify that the open(9E)
1517c478bd9Sstevel@tonic-gate  * comes from another part of the kernel, not userland.
1527c478bd9Sstevel@tonic-gate  *
1537c478bd9Sstevel@tonic-gate  * Part of the Solaris 2.x DDI/DKI.
1547c478bd9Sstevel@tonic-gate  */
1557c478bd9Sstevel@tonic-gate #define	FKLYR		0x40000000	/* layered driver call */
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /* miscellaneous defines */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #ifndef L_SET
1627c478bd9Sstevel@tonic-gate #define	L_SET	0	/* for lseek */
1637c478bd9Sstevel@tonic-gate #endif /* L_SET */
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate  * Routines dealing with user per-open file flags and
1697c478bd9Sstevel@tonic-gate  * user open files.
1707c478bd9Sstevel@tonic-gate  */
1717c478bd9Sstevel@tonic-gate struct proc;	/* forward reference for function prototype */
1727c478bd9Sstevel@tonic-gate struct vnodeops;
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate extern file_t *getf(int);
1757c478bd9Sstevel@tonic-gate extern void releasef(int);
1767c478bd9Sstevel@tonic-gate extern void areleasef(int, uf_info_t *);
1777c478bd9Sstevel@tonic-gate #ifndef	_BOOT
1787c478bd9Sstevel@tonic-gate extern void closeall(uf_info_t *);
1797c478bd9Sstevel@tonic-gate #endif
1807c478bd9Sstevel@tonic-gate extern void flist_fork(uf_info_t *, uf_info_t *);
1817c478bd9Sstevel@tonic-gate extern int closef(file_t *);
1827c478bd9Sstevel@tonic-gate extern int closeandsetf(int, file_t *);
1837c478bd9Sstevel@tonic-gate extern int ufalloc_file(int, file_t *);
1847c478bd9Sstevel@tonic-gate extern int ufalloc(int);
185*2cb27123Saguzovsk extern int ufcanalloc(struct proc *, uint_t);
1867c478bd9Sstevel@tonic-gate extern int falloc(struct vnode *, int, file_t **, int *);
1877c478bd9Sstevel@tonic-gate extern void finit(void);
1887c478bd9Sstevel@tonic-gate extern void unfalloc(file_t *);
1897c478bd9Sstevel@tonic-gate extern void setf(int, file_t *);
1907c478bd9Sstevel@tonic-gate extern int f_getfd_error(int, int *);
1917c478bd9Sstevel@tonic-gate extern char f_getfd(int);
1927c478bd9Sstevel@tonic-gate extern int f_setfd_error(int, int);
1937c478bd9Sstevel@tonic-gate extern void f_setfd(int, char);
1947c478bd9Sstevel@tonic-gate extern int f_getfl(int, int *);
195a5f69788Scraigm extern int f_badfd(int, int *, int);
1967c478bd9Sstevel@tonic-gate extern int fassign(struct vnode **, int, int *);
1977c478bd9Sstevel@tonic-gate extern void fcnt_add(uf_info_t *, int);
1987c478bd9Sstevel@tonic-gate extern void close_exec(uf_info_t *);
1997c478bd9Sstevel@tonic-gate extern void clear_stale_fd(void);
2007c478bd9Sstevel@tonic-gate extern void clear_active_fd(int);
2017c478bd9Sstevel@tonic-gate extern void free_afd(afd_t *afd);
2027c478bd9Sstevel@tonic-gate extern int fisopen(struct vnode *);
2037c478bd9Sstevel@tonic-gate extern void delfpollinfo(int);
2047c478bd9Sstevel@tonic-gate extern void addfpollinfo(int);
2057c478bd9Sstevel@tonic-gate extern int sock_getfasync(struct vnode *);
2067c478bd9Sstevel@tonic-gate extern int files_can_change_zones(void);
2077c478bd9Sstevel@tonic-gate #ifdef DEBUG
2087c478bd9Sstevel@tonic-gate /* The following functions are only used in ASSERT()s */
2097c478bd9Sstevel@tonic-gate extern void checkwfdlist(struct vnode *, fpollinfo_t *);
2107c478bd9Sstevel@tonic-gate extern void checkfpollinfo(void);
2117c478bd9Sstevel@tonic-gate extern int infpollinfo(int);
2127c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate #endif
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate #endif	/* _SYS_FILE_H */
221