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