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