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