1 /* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)file.h 8.3 (Berkeley) 1/9/95 34 * $FreeBSD: src/sys/sys/file.h,v 1.22.2.7 2002/11/21 23:39:24 sam Exp $ 35 * $DragonFly: src/sys/sys/file2.h,v 1.3 2005/07/13 01:38:53 dillon Exp $ 36 */ 37 38 #ifndef _SYS_FILE2_H_ 39 #define _SYS_FILE2_H_ 40 41 #ifdef _KERNEL 42 43 static __inline void 44 fhold(struct file *fp) 45 { 46 fp->f_count++; 47 } 48 49 static __inline int 50 fo_read( 51 struct file *fp, 52 struct uio *uio, 53 struct ucred *cred, 54 int flags, 55 struct thread *td 56 ) { 57 int error; 58 59 fhold(fp); 60 error = (*fp->f_ops->fold_read)(fp, uio, cred, flags, td); 61 fdrop(fp, td); 62 return (error); 63 } 64 65 static __inline int 66 fo_write( 67 struct file *fp, 68 struct uio *uio, 69 struct ucred *cred, 70 int flags, 71 struct thread *td 72 ) { 73 int error; 74 75 fhold(fp); 76 error = (*fp->f_ops->fold_write)(fp, uio, cred, flags, td); 77 fdrop(fp, td); 78 return (error); 79 } 80 81 static __inline int 82 fo_ioctl( 83 struct file *fp, 84 u_long com, 85 caddr_t data, 86 struct thread *td 87 ) { 88 int error; 89 90 fhold(fp); 91 error = (*fp->f_ops->fold_ioctl)(fp, com, data, td); 92 fdrop(fp, td); 93 return (error); 94 } 95 96 static __inline int 97 fo_poll( 98 struct file *fp, 99 int events, 100 struct ucred *cred, 101 struct thread *td 102 ) { 103 int error; 104 105 fhold(fp); 106 error = (*fp->f_ops->fold_poll)(fp, events, cred, td); 107 fdrop(fp, td); 108 return (error); 109 } 110 111 static __inline int 112 fo_stat(struct file *fp, struct stat *sb, struct thread *td) 113 { 114 int error; 115 116 fhold(fp); 117 error = (*fp->f_ops->fold_stat)(fp, sb, td); 118 fdrop(fp, td); 119 return (error); 120 } 121 122 static __inline int 123 fo_close(struct file *fp, struct thread *td) 124 { 125 return ((*fp->f_ops->fold_close)(fp, td)); 126 } 127 128 static __inline int 129 fo_shutdown(struct file *fp, int how, struct thread *td) 130 { 131 return ((*fp->f_ops->fold_shutdown)(fp, how, td)); 132 } 133 134 static __inline int 135 fo_kqfilter(struct file *fp, struct knote *kn) 136 { 137 return ((*fp->f_ops->fold_kqfilter)(fp, kn)); 138 } 139 140 #endif /* _KERNEL */ 141 142 #endif /* !SYS_FILE2_H */ 143 144