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.48 2003/09/22 13:00:04 christos Exp $       */
    2 
    3 /*
    4  * Copyright (c) 1982, 1986, 1989, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. Neither the name of the University nor the names of its contributors
   16  *    may be used to endorse or promote products derived from this software
   17  *    without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  *      @(#)file.h      8.3 (Berkeley) 1/9/95
   32  */
   33 
   34 #ifndef _SYS_FILE_H_
   35 #define _SYS_FILE_H_
   36 
   37 #include <sys/fcntl.h>
   38 #include <sys/unistd.h>
   39 
   40 #ifdef _KERNEL
   41 #include <sys/mallocvar.h>
   42 #include <sys/queue.h>
   43 #include <sys/lock.h>
   44 
   45 MALLOC_DECLARE(M_FILE);
   46 MALLOC_DECLARE(M_IOCTLOPS);
   47 
   48 struct proc;
   49 struct uio;
   50 struct iovec;
   51 struct stat;
   52 struct knote;
   53 
   54 /*
   55  * Kernel descriptor table.
   56  * One entry for each open kernel vnode and socket.
   57  */
   58 struct file {
   59         LIST_ENTRY(file) f_list;        /* list of active files */
   60         int             f_flag;         /* see fcntl.h */
   61         int             f_iflags;       /* internal flags */
   62 #define DTYPE_VNODE     1               /* file */
   63 #define DTYPE_SOCKET    2               /* communications endpoint */
   64 #define DTYPE_PIPE      3               /* pipe */
   65 #define DTYPE_KQUEUE    4               /* event queue */
   66 #define DTYPE_MISC      5               /* misc file descriptor type */
   67 #define DTYPE_CRYPTO    6               /* crypto */
   68         int             f_type;         /* descriptor type */
   69         u_int           f_count;        /* reference count */
   70         u_int           f_msgcount;     /* references from message queue */
   71         int             f_usecount;     /* number active users */
   72         struct ucred    *f_cred;        /* creds associated with descriptor */
   73         struct fileops {
   74                 int     (*fo_read)      (struct file *, off_t *, struct uio *,
   75                                             struct ucred *, int);
   76                 int     (*fo_write)     (struct file *, off_t *, struct uio *,
   77                                             struct ucred *, int);
   78                 int     (*fo_ioctl)     (struct file *, u_long, void *,
   79                                             struct proc *);
   80                 int     (*fo_fcntl)     (struct file *, u_int, void *,
   81                                             struct proc *);
   82                 int     (*fo_poll)      (struct file *, int, struct proc *);
   83                 int     (*fo_stat)      (struct file *, struct stat *,
   84                                             struct proc *);
   85                 int     (*fo_close)     (struct file *, struct proc *);
   86                 int     (*fo_kqfilter)  (struct file *, struct knote *);
   87         } *f_ops;
   88         off_t           f_offset;
   89         void            *f_data;        /* descriptor data, e.g. vnode/socket */
   90         struct simplelock f_slock;
   91 };
   92 
   93 #define FIF_WANTCLOSE           0x01    /* a close is waiting for usecount */
   94 #define FIF_LARVAL              0x02    /* not fully constructed; don't use */
   95 
   96 #define FILE_IS_USABLE(fp)      (((fp)->f_iflags &                      \
   97                                   (FIF_WANTCLOSE|FIF_LARVAL)) == 0)
   98 
   99 #define FILE_SET_MATURE(fp)                                             \
  100 do {                                                                    \
  101         (fp)->f_iflags &= ~FIF_LARVAL;                                  \
  102 } while (/*CONSTCOND*/0)
  103 
  104 #ifdef DIAGNOSTIC
  105 #define FILE_USE_CHECK(fp, str)                                         \
  106 do {                                                                    \
  107         if ((fp)->f_usecount < 0)                                       \
  108                 panic(str);                                             \
  109 } while (/* CONSTCOND */ 0)
  110 #else
  111 #define FILE_USE_CHECK(fp, str)         /* nothing */
  112 #endif
  113 
  114 /*
  115  * FILE_USE() must be called with the file lock held.
  116  * (Typical usage is: `fp = fd_getfile(..); FILE_USE(fp);'
  117  * and fd_getfile() returns the file locked)
  118  */
  119 #define FILE_USE(fp)                                                    \
  120 do {                                                                    \
  121         (fp)->f_usecount++;                                             \
  122         FILE_USE_CHECK((fp), "f_usecount overflow");                    \
  123         simple_unlock(&(fp)->f_slock);                                  \
  124 } while (/* CONSTCOND */ 0)
  125 
  126 #define FILE_UNUSE(fp, p)                                               \
  127 do {                                                                    \
  128         simple_lock(&(fp)->f_slock);                                    \
  129         if ((fp)->f_iflags & FIF_WANTCLOSE) {                           \
  130                 simple_unlock(&(fp)->f_slock);                          \
  131                 /* Will drop usecount */                                \
  132                 (void) closef((fp), (p));                               \
  133                 break;                                                  \
  134         } else {                                                        \
  135                 (fp)->f_usecount--;                                     \
  136                 FILE_USE_CHECK((fp), "f_usecount underflow");           \
  137         }                                                               \
  138         simple_unlock(&(fp)->f_slock);                                  \
  139 } while (/* CONSTCOND */ 0)
  140 
  141 /*
  142  * Flags for fo_read and fo_write.
  143  */
  144 #define FOF_UPDATE_OFFSET       0x01    /* update the file offset */
  145 
  146 LIST_HEAD(filelist, file);
  147 extern struct filelist  filehead;       /* head of list of open files */
  148 extern int              maxfiles;       /* kernel limit on # of open files */
  149 extern int              nfiles;         /* actual number of open files */
  150 
  151 extern struct fileops   vnops;          /* vnode operations for files */
  152 
  153 int     dofileread(struct proc *, int, struct file *, void *, size_t,
  154             off_t *, int, register_t *);
  155 int     dofilewrite(struct proc *, int, struct file *, const void *,
  156             size_t, off_t *, int, register_t *);
  157 
  158 int     dofilereadv(struct proc *, int, struct file *,
  159             const struct iovec *, int, off_t *, int, register_t *);
  160 int     dofilewritev(struct proc *, int, struct file *,
  161             const struct iovec *, int, off_t *, int, register_t *);
  162 
  163 void    finit(void);
  164 
  165 int     fsetown(struct proc *, pid_t *, int, const void *);
  166 int     fgetown(struct proc *, pid_t, int, void *);
  167 void    fownsignal(pid_t, int, int, int, void *);
  168 
  169 #endif /* _KERNEL */
  170 
  171 #endif /* _SYS_FILE_H_ */

Cache object: 3a6cb2005a4482ed83852862e87cb731


[ 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.