The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/file.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: file.h,v 1.65.6.2 2009/04/04 23:36:28 snj Exp $        */
    2 
    3 /*-
    4  * Copyright (c) 2009 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Andrew Doran.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   29  * POSSIBILITY OF SUCH DAMAGE.
   30  */
   31 
   32 /*
   33  * Copyright (c) 1982, 1986, 1989, 1993
   34  *      The Regents of the University of California.  All rights reserved.
   35  *
   36  * Redistribution and use in source and binary forms, with or without
   37  * modification, are permitted provided that the following conditions
   38  * are met:
   39  * 1. Redistributions of source code must retain the above copyright
   40  *    notice, this list of conditions and the following disclaimer.
   41  * 2. Redistributions in binary form must reproduce the above copyright
   42  *    notice, this list of conditions and the following disclaimer in the
   43  *    documentation and/or other materials provided with the distribution.
   44  * 3. Neither the name of the University nor the names of its contributors
   45  *    may be used to endorse or promote products derived from this software
   46  *    without specific prior written permission.
   47  *
   48  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   51  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   58  * SUCH DAMAGE.
   59  *
   60  *      @(#)file.h      8.3 (Berkeley) 1/9/95
   61  */
   62 
   63 #ifndef _SYS_FILE_H_
   64 #define _SYS_FILE_H_
   65 
   66 #include <sys/fcntl.h>
   67 #include <sys/unistd.h>
   68 
   69 #ifdef _KERNEL
   70 #include <sys/mallocvar.h>
   71 #include <sys/queue.h>
   72 #include <sys/mutex.h>
   73 #include <sys/condvar.h>
   74 
   75 struct proc;
   76 struct lwp;
   77 struct uio;
   78 struct iovec;
   79 struct stat;
   80 struct knote;
   81 
   82 /*
   83  * Kernel file descriptor.  One entry for each open kernel vnode and
   84  * socket.
   85  *
   86  * This structure is exported via the KERN_FILE and KERN_FILE2 sysctl
   87  * calls.  Only add members to the end, do not delete them.
   88  */
   89 struct file {
   90         off_t           f_offset;       /* first, is 64-bit */
   91         kauth_cred_t    f_cred;         /* creds associated with descriptor */
   92         const struct fileops {
   93                 int     (*fo_read)      (struct file *, off_t *, struct uio *,
   94                                             kauth_cred_t, int);
   95                 int     (*fo_write)     (struct file *, off_t *, struct uio *,
   96                                             kauth_cred_t, int);
   97                 int     (*fo_ioctl)     (struct file *, u_long, void *);
   98                 int     (*fo_fcntl)     (struct file *, u_int, void *);
   99                 int     (*fo_poll)      (struct file *, int);
  100                 int     (*fo_stat)      (struct file *, struct stat *);
  101                 int     (*fo_close)     (struct file *);
  102                 int     (*fo_kqfilter)  (struct file *, struct knote *);
  103                 void    (*fo_drain)     (struct file *);
  104                 void    (*fo_spare1)    (void);
  105                 void    (*fo_spare2)    (void);
  106         } *f_ops;
  107         void            *f_data;        /* descriptor data, e.g. vnode/socket */
  108         LIST_ENTRY(file) f_list;        /* list of active files */
  109         kmutex_t        f_lock;         /* lock on structure */
  110         int             f_flag;         /* see fcntl.h */
  111         u_int           f_unused1;      /* unused; was internal flags; FIF_* */
  112 #define DTYPE_VNODE     1               /* file */
  113 #define DTYPE_SOCKET    2               /* communications endpoint */
  114 #define DTYPE_PIPE      3               /* pipe */
  115 #define DTYPE_KQUEUE    4               /* event queue */
  116 #define DTYPE_MISC      5               /* misc file descriptor type */
  117 #define DTYPE_CRYPTO    6               /* crypto */
  118 #define DTYPE_MQUEUE    7               /* message queue */
  119 #define DTYPE_NAMES \
  120     "", "file", "socket", "pipe", "kqueue", "misc", "crypto", "mqueue"
  121         u_int           f_type;         /* descriptor type */
  122         u_int           f_advice;       /* access pattern hint; UVM_ADV_* */
  123         u_int           f_count;        /* reference count */
  124         u_int           f_msgcount;     /* references from message queue */
  125         u_int           f_unpcount;     /* deferred close: see uipc_usrreq.c */
  126         SLIST_ENTRY(file) f_unplist;    /* deferred close: see uipc_usrreq.c */
  127 };
  128 
  129 #define FILE_LOCK(fp)   mutex_enter(&(fp)->f_lock)
  130 #define FILE_UNLOCK(fp) mutex_exit(&(fp)->f_lock)
  131 
  132 /*
  133  * Flags for fo_read and fo_write and do_fileread/write/v
  134  */
  135 #define FOF_UPDATE_OFFSET       0x0001  /* update the file offset */
  136 #define FOF_IOV_SYSSPACE        0x0100  /* iov structure in kernel memory */
  137 
  138 LIST_HEAD(filelist, file);
  139 extern struct filelist  filehead;       /* head of list of open files */
  140 extern u_int            maxfiles;       /* kernel limit on # of open files */
  141 extern u_int            nfiles;         /* actual number of open files */
  142 
  143 extern const struct fileops vnops;      /* vnode operations for files */
  144 
  145 int     dofileread(int, struct file *, void *, size_t,
  146             off_t *, int, register_t *);
  147 int     dofilewrite(int, struct file *, const void *,
  148             size_t, off_t *, int, register_t *);
  149 
  150 int     do_filereadv(int, const struct iovec *, int, off_t *,
  151             int, register_t *);
  152 int     do_filewritev(int, const struct iovec *, int, off_t *,
  153             int, register_t *);
  154 
  155 int     fsetown(pid_t *, u_long, const void *);
  156 int     fgetown(pid_t, u_long, void *);
  157 void    fownsignal(pid_t, int, int, int, void *);
  158 
  159 /* Commonly used fileops */
  160 int     fnullop_fcntl(struct file *, u_int, void *);
  161 int     fnullop_poll(struct file *, int);
  162 int     fnullop_kqfilter(struct file *, struct knote *);
  163 int     fbadop_read(struct file *, off_t *, struct uio *, kauth_cred_t, int);
  164 int     fbadop_write(struct file *, off_t *, struct uio *, kauth_cred_t, int);
  165 int     fbadop_ioctl(struct file *, u_long, void *);
  166 int     fbadop_close(struct file *);
  167 int     fbadop_stat(struct file *, struct stat *);
  168 void    fnullop_drain(struct file *);
  169 
  170 #endif /* _KERNEL */
  171 
  172 #endif /* _SYS_FILE_H_ */

Cache object: da2f96b2b74bb9d3bf3c06252ca1e037


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.