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 29b075ad5bSTheo Schlossnagle /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */ 307a5aac98SJerry Jelinek /* Copyright 2015 Joyent, Inc. */ 31b075ad5bSTheo Schlossnagle 327c478bd9Sstevel@tonic-gate #ifndef _SYS_FILE_H 337c478bd9Sstevel@tonic-gate #define _SYS_FILE_H 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. 587a5aac98SJerry Jelinek * Main use is to hold the read/write pointer (and OFD locks) 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; 64794f0adbSRoger A. Faulkner ushort_t f_flag2; /* extra flags (FSEARCH, FEXEC) */ 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 */ 707a5aac98SJerry Jelinek struct filock *f_filock; /* ptr to single lock_descriptor_t */ 717c478bd9Sstevel@tonic-gate } file_t; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * fpollinfo struct - used by poll caching to track who has polled the fd 757c478bd9Sstevel@tonic-gate */ 767c478bd9Sstevel@tonic-gate typedef struct fpollinfo { 777c478bd9Sstevel@tonic-gate struct _kthread *fp_thread; /* thread caching poll info */ 787c478bd9Sstevel@tonic-gate struct fpollinfo *fp_next; 797c478bd9Sstevel@tonic-gate } fpollinfo_t; 807c478bd9Sstevel@tonic-gate 81794f0adbSRoger A. Faulkner /* f_flag */ 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate #define FOPEN 0xffffffff 847c478bd9Sstevel@tonic-gate #define FREAD 0x01 /* <sys/aiocb.h> LIO_READ must be identical */ 857c478bd9Sstevel@tonic-gate #define FWRITE 0x02 /* <sys/aiocb.h> LIO_WRITE must be identical */ 867c478bd9Sstevel@tonic-gate #define FNDELAY 0x04 877c478bd9Sstevel@tonic-gate #define FAPPEND 0x08 887c478bd9Sstevel@tonic-gate #define FSYNC 0x10 /* file (data+inode) integrity while writing */ 89d3e55dcdSgww #define FREVOKED 0x20 /* Object reuse Revoked file */ 907c478bd9Sstevel@tonic-gate #define FDSYNC 0x40 /* file data only integrity while writing */ 917c478bd9Sstevel@tonic-gate #define FNONBLOCK 0x80 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate #define FMASK 0xa0ff /* all flags that can be changed by F_SETFL */ 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* open-only modes */ 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate #define FCREAT 0x0100 987c478bd9Sstevel@tonic-gate #define FTRUNC 0x0200 997c478bd9Sstevel@tonic-gate #define FEXCL 0x0400 1007c478bd9Sstevel@tonic-gate #define FASYNC 0x1000 /* asyncio in progress pseudo flag */ 101da6c28aaSamw #define FOFFMAX 0x2000 /* large file */ 102da6c28aaSamw #define FXATTR 0x4000 /* open as extended attribute */ 103da6c28aaSamw #define FNOCTTY 0x0800 104da6c28aaSamw #define FRSYNC 0x8000 /* sync read operations at same level of */ 105da6c28aaSamw /* integrity as specified for writes by */ 106da6c28aaSamw /* FSYNC and FDSYNC flags */ 107da6c28aaSamw 1087c478bd9Sstevel@tonic-gate #define FNODSYNC 0x10000 /* fsync pseudo flag */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #define FNOFOLLOW 0x20000 /* don't follow symlinks */ 1117c478bd9Sstevel@tonic-gate #define FNOLINKS 0x40000 /* don't allow multiple hard links */ 112da6c28aaSamw #define FIGNORECASE 0x80000 /* request case-insensitive lookups */ 113da6c28aaSamw #define FXATTRDIROPEN 0x100000 /* only opening hidden attribute directory */ 1147c478bd9Sstevel@tonic-gate 115794f0adbSRoger A. Faulkner /* f_flag2 (open-only) */ 116794f0adbSRoger A. Faulkner 117794f0adbSRoger A. Faulkner #define FSEARCH 0x200000 /* O_SEARCH = 0x200000 */ 118794f0adbSRoger A. Faulkner #define FEXEC 0x400000 /* O_EXEC = 0x400000 */ 119794f0adbSRoger A. Faulkner 120b075ad5bSTheo Schlossnagle #define FCLOEXEC 0x800000 /* O_CLOEXEC = 0x800000 */ 121*36626562SRobert Mustacchi #define FDIRECTORY 0x1000000 /* O_DIRECTORY = 0x1000000 */ 122b075ad5bSTheo Schlossnagle 1237c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate /* 126a5eb7107SBryan Cantrill * This is a flag that is set on f_flag2, but is never user-visible 127a5eb7107SBryan Cantrill */ 128a5eb7107SBryan Cantrill #define FEPOLLED 0x8000 129a5eb7107SBryan Cantrill 130a5eb7107SBryan Cantrill /* 1317c478bd9Sstevel@tonic-gate * Fake flags for driver ioctl calls to inform them of the originating 1327c478bd9Sstevel@tonic-gate * process' model. See <sys/model.h> 1337c478bd9Sstevel@tonic-gate * 1347c478bd9Sstevel@tonic-gate * Part of the Solaris 2.6+ DDI/DKI 1357c478bd9Sstevel@tonic-gate */ 1367c478bd9Sstevel@tonic-gate #define FMODELS DATAMODEL_MASK /* Note: 0x0ff00000 */ 1377c478bd9Sstevel@tonic-gate #define FILP32 DATAMODEL_ILP32 1387c478bd9Sstevel@tonic-gate #define FLP64 DATAMODEL_LP64 1397c478bd9Sstevel@tonic-gate #define FNATIVE DATAMODEL_NATIVE 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate /* 1427c478bd9Sstevel@tonic-gate * Large Files: The macro gets the offset maximum (refer to LFS API doc) 1437c478bd9Sstevel@tonic-gate * corresponding to a file descriptor. We had the choice of storing 1447c478bd9Sstevel@tonic-gate * this value in file descriptor. Right now we only have two 1457c478bd9Sstevel@tonic-gate * offset maximums one if MAXOFF_T and other is MAXOFFSET_T. It is 1467c478bd9Sstevel@tonic-gate * inefficient to store these two values in a separate member in 1477c478bd9Sstevel@tonic-gate * file descriptor. To avoid wasting spaces we define this macro. 1487c478bd9Sstevel@tonic-gate * The day there are more than two offset maximum we may want to 1497c478bd9Sstevel@tonic-gate * rewrite this macro. 1507c478bd9Sstevel@tonic-gate */ 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate #define OFFSET_MAX(fd) ((fd->f_flag & FOFFMAX) ? MAXOFFSET_T : MAXOFF32_T) 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate /* 1557c478bd9Sstevel@tonic-gate * Fake flag => internal ioctl call for layered drivers. 1567c478bd9Sstevel@tonic-gate * Note that this flag deliberately *won't* fit into 1577c478bd9Sstevel@tonic-gate * the f_flag field of a file_t. 1587c478bd9Sstevel@tonic-gate * 1597c478bd9Sstevel@tonic-gate * Part of the Solaris 2.x DDI/DKI. 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate #define FKIOCTL 0x80000000 /* ioctl addresses are from kernel */ 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * Fake flag => this time to specify that the open(9E) 1657c478bd9Sstevel@tonic-gate * comes from another part of the kernel, not userland. 1667c478bd9Sstevel@tonic-gate * 1677c478bd9Sstevel@tonic-gate * Part of the Solaris 2.x DDI/DKI. 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate #define FKLYR 0x40000000 /* layered driver call */ 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate /* miscellaneous defines */ 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate #ifndef L_SET 1767c478bd9Sstevel@tonic-gate #define L_SET 0 /* for lseek */ 1777c478bd9Sstevel@tonic-gate #endif /* L_SET */ 1787c478bd9Sstevel@tonic-gate 1797a5aac98SJerry Jelinek /* 1807a5aac98SJerry Jelinek * For flock(3C). These really don't belong here but for historical reasons 1817a5aac98SJerry Jelinek * the interface defines them to be here. 1827a5aac98SJerry Jelinek */ 1837a5aac98SJerry Jelinek #define LOCK_SH 1 1847a5aac98SJerry Jelinek #define LOCK_EX 2 1857a5aac98SJerry Jelinek #define LOCK_NB 4 1867a5aac98SJerry Jelinek #define LOCK_UN 8 1877a5aac98SJerry Jelinek 1887a5aac98SJerry Jelinek #if !defined(_STRICT_SYMBOLS) 1897a5aac98SJerry Jelinek extern int flock(int, int); 1907a5aac98SJerry Jelinek #endif 1917a5aac98SJerry Jelinek 1927c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate /* 1957c478bd9Sstevel@tonic-gate * Routines dealing with user per-open file flags and 1967c478bd9Sstevel@tonic-gate * user open files. 1977c478bd9Sstevel@tonic-gate */ 1987c478bd9Sstevel@tonic-gate struct proc; /* forward reference for function prototype */ 1997c478bd9Sstevel@tonic-gate struct vnodeops; 200794f0adbSRoger A. Faulkner struct vattr; 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate extern file_t *getf(int); 2037c478bd9Sstevel@tonic-gate extern void releasef(int); 2047c478bd9Sstevel@tonic-gate extern void areleasef(int, uf_info_t *); 2057c478bd9Sstevel@tonic-gate #ifndef _BOOT 2067c478bd9Sstevel@tonic-gate extern void closeall(uf_info_t *); 2077c478bd9Sstevel@tonic-gate #endif 2087c478bd9Sstevel@tonic-gate extern void flist_fork(uf_info_t *, uf_info_t *); 2097c478bd9Sstevel@tonic-gate extern int closef(file_t *); 2107c478bd9Sstevel@tonic-gate extern int closeandsetf(int, file_t *); 2117c478bd9Sstevel@tonic-gate extern int ufalloc_file(int, file_t *); 2127c478bd9Sstevel@tonic-gate extern int ufalloc(int); 2132cb27123Saguzovsk extern int ufcanalloc(struct proc *, uint_t); 2147c478bd9Sstevel@tonic-gate extern int falloc(struct vnode *, int, file_t **, int *); 2157c478bd9Sstevel@tonic-gate extern void finit(void); 2167c478bd9Sstevel@tonic-gate extern void unfalloc(file_t *); 2177c478bd9Sstevel@tonic-gate extern void setf(int, file_t *); 2187c478bd9Sstevel@tonic-gate extern int f_getfd_error(int, int *); 2197c478bd9Sstevel@tonic-gate extern char f_getfd(int); 2207c478bd9Sstevel@tonic-gate extern int f_setfd_error(int, int); 2217c478bd9Sstevel@tonic-gate extern void f_setfd(int, char); 2227c478bd9Sstevel@tonic-gate extern int f_getfl(int, int *); 223a5f69788Scraigm extern int f_badfd(int, int *, int); 2247c478bd9Sstevel@tonic-gate extern int fassign(struct vnode **, int, int *); 2257c478bd9Sstevel@tonic-gate extern void fcnt_add(uf_info_t *, int); 2267c478bd9Sstevel@tonic-gate extern void close_exec(uf_info_t *); 2277c478bd9Sstevel@tonic-gate extern void clear_stale_fd(void); 2287c478bd9Sstevel@tonic-gate extern void clear_active_fd(int); 2297c478bd9Sstevel@tonic-gate extern void free_afd(afd_t *afd); 230794f0adbSRoger A. Faulkner extern int fgetstartvp(int, char *, struct vnode **); 231794f0adbSRoger A. Faulkner extern int fsetattrat(int, char *, int, struct vattr *); 2327c478bd9Sstevel@tonic-gate extern int fisopen(struct vnode *); 2337c478bd9Sstevel@tonic-gate extern void delfpollinfo(int); 2347c478bd9Sstevel@tonic-gate extern void addfpollinfo(int); 2357c478bd9Sstevel@tonic-gate extern int sock_getfasync(struct vnode *); 2367c478bd9Sstevel@tonic-gate extern int files_can_change_zones(void); 2377c478bd9Sstevel@tonic-gate #ifdef DEBUG 2387c478bd9Sstevel@tonic-gate /* The following functions are only used in ASSERT()s */ 2397c478bd9Sstevel@tonic-gate extern void checkwfdlist(struct vnode *, fpollinfo_t *); 2407c478bd9Sstevel@tonic-gate extern void checkfpollinfo(void); 2417c478bd9Sstevel@tonic-gate extern int infpollinfo(int); 2427c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) */ 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate #endif 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate #endif /* _SYS_FILE_H */ 251