1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 24 */ 25 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 27 /* All Rights Reserved */ 28 29 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */ 30 /* Copyright 2015 Joyent, Inc. */ 31 32 #ifndef _SYS_FILE_H 33 #define _SYS_FILE_H 34 35 #include <sys/t_lock.h> 36 #ifdef _KERNEL 37 #include <sys/model.h> 38 #include <sys/user.h> 39 #endif 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /* 46 * fio locking: 47 * f_rwlock protects f_vnode and f_cred 48 * f_tlock protects the rest 49 * 50 * The purpose of locking in this layer is to keep the kernel 51 * from panicing if, for example, a thread calls close() while 52 * another thread is doing a read(). It is up to higher levels 53 * to make sure 2 threads doing I/O to the same file don't 54 * screw each other up. 55 */ 56 /* 57 * One file structure is allocated for each open/creat/pipe call. 58 * Main use is to hold the read/write pointer (and OFD locks) associated with 59 * each open file. 60 */ 61 typedef struct file { 62 kmutex_t f_tlock; /* short term lock */ 63 ushort_t f_flag; 64 ushort_t f_flag2; /* extra flags (FSEARCH, FEXEC) */ 65 struct vnode *f_vnode; /* pointer to vnode structure */ 66 offset_t f_offset; /* read/write character pointer */ 67 struct cred *f_cred; /* credentials of user who opened it */ 68 struct f_audit_data *f_audit_data; /* file audit data */ 69 int f_count; /* reference count */ 70 struct filock *f_filock; /* ptr to single lock_descriptor_t */ 71 } file_t; 72 73 /* 74 * fpollinfo struct - used by poll caching to track who has polled the fd 75 */ 76 typedef struct fpollinfo { 77 struct _kthread *fp_thread; /* thread caching poll info */ 78 struct fpollinfo *fp_next; 79 } fpollinfo_t; 80 81 /* f_flag */ 82 83 #define FOPEN 0xffffffff 84 #define FREAD 0x01 /* <sys/aiocb.h> LIO_READ must be identical */ 85 #define FWRITE 0x02 /* <sys/aiocb.h> LIO_WRITE must be identical */ 86 #define FNDELAY 0x04 87 #define FAPPEND 0x08 88 #define FSYNC 0x10 /* file (data+inode) integrity while writing */ 89 #define FREVOKED 0x20 /* Object reuse Revoked file */ 90 #define FDSYNC 0x40 /* file data only integrity while writing */ 91 #define FNONBLOCK 0x80 92 93 #define FMASK 0xa0ff /* all flags that can be changed by F_SETFL */ 94 95 /* open-only modes */ 96 97 #define FCREAT 0x0100 98 #define FTRUNC 0x0200 99 #define FEXCL 0x0400 100 #define FASYNC 0x1000 /* asyncio in progress pseudo flag */ 101 #define FOFFMAX 0x2000 /* large file */ 102 #define FXATTR 0x4000 /* open as extended attribute */ 103 #define FNOCTTY 0x0800 104 #define FRSYNC 0x8000 /* sync read operations at same level of */ 105 /* integrity as specified for writes by */ 106 /* FSYNC and FDSYNC flags */ 107 108 #define FNODSYNC 0x10000 /* fsync pseudo flag */ 109 110 #define FNOFOLLOW 0x20000 /* don't follow symlinks */ 111 #define FNOLINKS 0x40000 /* don't allow multiple hard links */ 112 #define FIGNORECASE 0x80000 /* request case-insensitive lookups */ 113 #define FXATTRDIROPEN 0x100000 /* only opening hidden attribute directory */ 114 115 /* f_flag2 (open-only) */ 116 117 #define FSEARCH 0x200000 /* O_SEARCH = 0x200000 */ 118 #define FEXEC 0x400000 /* O_EXEC = 0x400000 */ 119 120 #define FCLOEXEC 0x800000 /* O_CLOEXEC = 0x800000 */ 121 #define FDIRECTORY 0x1000000 /* O_DIRECTORY = 0x1000000 */ 122 123 #if defined(_KERNEL) || defined(_FAKE_KERNEL) 124 125 /* 126 * This is a flag that is set on f_flag2, but is never user-visible 127 */ 128 #define FEPOLLED 0x8000 129 130 /* 131 * Fake flags for driver ioctl calls to inform them of the originating 132 * process' model. See <sys/model.h> 133 * 134 * Part of the Solaris 2.6+ DDI/DKI 135 */ 136 #define FMODELS DATAMODEL_MASK /* Note: 0x0ff00000 */ 137 #define FILP32 DATAMODEL_ILP32 138 #define FLP64 DATAMODEL_LP64 139 #define FNATIVE DATAMODEL_NATIVE 140 141 /* 142 * Large Files: The macro gets the offset maximum (refer to LFS API doc) 143 * corresponding to a file descriptor. We had the choice of storing 144 * this value in file descriptor. Right now we only have two 145 * offset maximums one if MAXOFF_T and other is MAXOFFSET_T. It is 146 * inefficient to store these two values in a separate member in 147 * file descriptor. To avoid wasting spaces we define this macro. 148 * The day there are more than two offset maximum we may want to 149 * rewrite this macro. 150 */ 151 152 #define OFFSET_MAX(fd) ((fd->f_flag & FOFFMAX) ? MAXOFFSET_T : MAXOFF32_T) 153 154 /* 155 * Fake flag => internal ioctl call for layered drivers. 156 * Note that this flag deliberately *won't* fit into 157 * the f_flag field of a file_t. 158 * 159 * Part of the Solaris 2.x DDI/DKI. 160 */ 161 #define FKIOCTL 0x80000000 /* ioctl addresses are from kernel */ 162 163 /* 164 * Fake flag => this time to specify that the open(9E) 165 * comes from another part of the kernel, not userland. 166 * 167 * Part of the Solaris 2.x DDI/DKI. 168 */ 169 #define FKLYR 0x40000000 /* layered driver call */ 170 171 #endif /* _KERNEL */ 172 173 /* miscellaneous defines */ 174 175 #ifndef L_SET 176 #define L_SET 0 /* for lseek */ 177 #endif /* L_SET */ 178 179 /* 180 * For flock(3C). These really don't belong here but for historical reasons 181 * the interface defines them to be here. 182 */ 183 #define LOCK_SH 1 184 #define LOCK_EX 2 185 #define LOCK_NB 4 186 #define LOCK_UN 8 187 188 #if !defined(_STRICT_SYMBOLS) 189 extern int flock(int, int); 190 #endif 191 192 #if defined(_KERNEL) || defined(_FAKE_KERNEL) 193 194 /* 195 * Routines dealing with user per-open file flags and 196 * user open files. 197 */ 198 struct proc; /* forward reference for function prototype */ 199 struct vnodeops; 200 struct vattr; 201 struct uf_info; 202 203 extern file_t *getf(int); 204 extern void releasef(int); 205 extern void areleasef(int, struct uf_info *); 206 #ifndef _BOOT 207 extern void closeall(struct uf_info *); 208 #endif 209 extern void flist_fork(struct uf_info *, struct uf_info *); 210 extern int closef(file_t *); 211 extern int closeandsetf(int, file_t *); 212 extern int ufalloc_file(int, file_t *); 213 extern int ufalloc(int); 214 extern int ufcanalloc(struct proc *, uint_t); 215 extern int falloc(struct vnode *, int, file_t **, int *); 216 extern void finit(void); 217 extern void unfalloc(file_t *); 218 extern void setf(int, file_t *); 219 extern int f_getfd_error(int, int *); 220 extern char f_getfd(int); 221 extern int f_setfd_error(int, int); 222 extern void f_setfd(int, char); 223 extern int f_getfl(int, int *); 224 extern int f_badfd(int, int *, int); 225 extern int fassign(struct vnode **, int, int *); 226 extern void fcnt_add(struct uf_info *, int); 227 extern void close_exec(struct uf_info *); 228 extern void clear_stale_fd(void); 229 extern void clear_active_fd(int); 230 extern void free_afd(afd_t *afd); 231 extern int fgetstartvp(int, char *, struct vnode **); 232 extern int fsetattrat(int, char *, int, struct vattr *); 233 extern int fisopen(struct vnode *); 234 extern void delfpollinfo(int); 235 extern void addfpollinfo(int); 236 extern int sock_getfasync(struct vnode *); 237 extern int files_can_change_zones(void); 238 #ifdef DEBUG 239 /* The following functions are only used in ASSERT()s */ 240 extern void checkwfdlist(struct vnode *, fpollinfo_t *); 241 extern void checkfpollinfo(void); 242 extern int infpollinfo(int); 243 #endif /* DEBUG */ 244 245 #endif /* defined(_KERNEL) */ 246 247 #ifdef __cplusplus 248 } 249 #endif 250 251 #endif /* _SYS_FILE_H */ 252