1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc. 3*0Sstevel@tonic-gate * All rights reserved. 4*0Sstevel@tonic-gate */ 5*0Sstevel@tonic-gate 6*0Sstevel@tonic-gate /* 7*0Sstevel@tonic-gate * Copyright (c) 1982, 1986 Regents of the University of California. 8*0Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 9*0Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 10*0Sstevel@tonic-gate */ 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gate #ifndef __SYS_FILE_H 13*0Sstevel@tonic-gate #define __SYS_FILE_H 14*0Sstevel@tonic-gate 15*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gate #include <sys/types.h> 18*0Sstevel@tonic-gate 19*0Sstevel@tonic-gate #ifdef __cplusplus 20*0Sstevel@tonic-gate extern "C" { 21*0Sstevel@tonic-gate #endif 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gate #ifdef KERNEL 24*0Sstevel@tonic-gate /* 25*0Sstevel@tonic-gate * Descriptor table entry. 26*0Sstevel@tonic-gate * One for each kernel object. 27*0Sstevel@tonic-gate */ 28*0Sstevel@tonic-gate struct file { 29*0Sstevel@tonic-gate int f_flag; /* see below */ 30*0Sstevel@tonic-gate short f_type; /* descriptor type */ 31*0Sstevel@tonic-gate short f_count; /* reference count */ 32*0Sstevel@tonic-gate short f_msgcount; /* references from message queue */ 33*0Sstevel@tonic-gate struct fileops { 34*0Sstevel@tonic-gate int (*fo_rw)(); 35*0Sstevel@tonic-gate int (*fo_ioctl)(); 36*0Sstevel@tonic-gate int (*fo_select)(); 37*0Sstevel@tonic-gate int (*fo_close)(); 38*0Sstevel@tonic-gate } *f_ops; 39*0Sstevel@tonic-gate caddr_t f_data; /* ptr to file specific struct (vnode/socket) */ 40*0Sstevel@tonic-gate off_t f_offset; 41*0Sstevel@tonic-gate struct ucred *f_cred; /* credentials of user who opened file */ 42*0Sstevel@tonic-gate }; 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate struct file *file, *fileNFILE; 45*0Sstevel@tonic-gate int nfile; 46*0Sstevel@tonic-gate struct file *getf(); 47*0Sstevel@tonic-gate struct file *falloc(); 48*0Sstevel@tonic-gate #endif /* KERNEL */ 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate #include <sys/fcntlcom.h> 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate /* 53*0Sstevel@tonic-gate * bits to save after an open. The no delay bits mean "don't wait for 54*0Sstevel@tonic-gate * carrier at open" in all cases. Sys5 & POSIX save the no delay bits, 55*0Sstevel@tonic-gate * using them to also mean "don't block on reads"; BSD has you reset it 56*0Sstevel@tonic-gate * with an fcntl() if you want the "don't block on reads" behavior. 57*0Sstevel@tonic-gate */ 58*0Sstevel@tonic-gate #define FMASK (FREAD|FWRITE|FAPPEND|FSYNC|FNBIO|FNONBIO) 59*0Sstevel@tonic-gate #define FCNTLCANT (FREAD|FWRITE|FMARK|FDEFER|FSHLOCK|FEXLOCK) 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate /* 62*0Sstevel@tonic-gate * User definitions. 63*0Sstevel@tonic-gate */ 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate /* 66*0Sstevel@tonic-gate * Flock call. 67*0Sstevel@tonic-gate */ 68*0Sstevel@tonic-gate #define LOCK_SH 1 /* shared lock */ 69*0Sstevel@tonic-gate #define LOCK_EX 2 /* exclusive lock */ 70*0Sstevel@tonic-gate #define LOCK_NB 4 /* don't block when locking */ 71*0Sstevel@tonic-gate #define LOCK_UN 8 /* unlock */ 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate /* 74*0Sstevel@tonic-gate * Access call. Also maintained in unistd.h 75*0Sstevel@tonic-gate */ 76*0Sstevel@tonic-gate #define F_OK 0 /* does file exist */ 77*0Sstevel@tonic-gate #define X_OK 1 /* is it executable by caller */ 78*0Sstevel@tonic-gate #define W_OK 2 /* writable by caller */ 79*0Sstevel@tonic-gate #define R_OK 4 /* readable by caller */ 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate /* 82*0Sstevel@tonic-gate * Lseek call. Also maintained in 5include/stdio.h and sys/unistd.h as SEEK_* 83*0Sstevel@tonic-gate */ 84*0Sstevel@tonic-gate #define L_SET 0 /* absolute offset */ 85*0Sstevel@tonic-gate #define L_INCR 1 /* relative to current offset */ 86*0Sstevel@tonic-gate #define L_XTND 2 /* relative to end of file */ 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate #ifdef KERNEL 89*0Sstevel@tonic-gate #define GETF(fp, fd) { \ 90*0Sstevel@tonic-gate if ((fd) < 0 || (fd) > u.u_lastfile || \ 91*0Sstevel@tonic-gate ((fp) = u.u_ofile[fd]) == NULL) { \ 92*0Sstevel@tonic-gate u.u_error = EBADF; \ 93*0Sstevel@tonic-gate return; \ 94*0Sstevel@tonic-gate } \ 95*0Sstevel@tonic-gate } 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate #define DTYPE_VNODE 1 /* file */ 98*0Sstevel@tonic-gate #define DTYPE_SOCKET 2 /* communications endpoint */ 99*0Sstevel@tonic-gate #endif /* KERNEL */ 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate #ifdef __cplusplus 102*0Sstevel@tonic-gate } 103*0Sstevel@tonic-gate #endif 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate #endif /* __SYS_FILE_H */ 106