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/buf.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 /*
    2  * Copyright (c) 1982, 1986, 1989, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  * (c) UNIX System Laboratories, Inc.
    5  * All or some portions of this file are derived from material licensed
    6  * to the University of California by American Telephone and Telegraph
    7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
    8  * the permission of UNIX System Laboratories, Inc.
    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  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *      This product includes software developed by the University of
   21  *      California, Berkeley and its contributors.
   22  * 4. Neither the name of the University nor the names of its contributors
   23  *    may be used to endorse or promote products derived from this software
   24  *    without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   36  * SUCH DAMAGE.
   37  *
   38  *      @(#)buf.h       8.9 (Berkeley) 3/30/95
   39  * $FreeBSD: src/sys/sys/buf.h,v 1.34.2.4 1999/09/05 08:21:58 peter Exp $
   40  */
   41 
   42 #ifndef _SYS_BUF_H_
   43 #define _SYS_BUF_H_
   44 
   45 #include <sys/queue.h>
   46 
   47 #define NOLIST ((struct buf *)0x87654321)
   48 
   49 struct buf;
   50 
   51 struct iodone_chain {
   52         long    ic_prev_flags;
   53         void    (*ic_prev_iodone) __P((struct buf *));
   54         void    *ic_prev_iodone_chain;
   55         struct {
   56                 long    ia_long;
   57                 void    *ia_ptr;
   58         }       ic_args[5];
   59 };
   60 
   61 /*
   62  * The buffer header describes an I/O operation in the kernel.
   63  */
   64 struct buf {
   65         LIST_ENTRY(buf) b_hash;         /* Hash chain. */
   66         LIST_ENTRY(buf) b_vnbufs;       /* Buffer's associated vnode. */
   67         TAILQ_ENTRY(buf) b_freelist;    /* Free list position if not active. */
   68         TAILQ_ENTRY(buf) b_act;         /* Device driver queue when active. *new* */
   69         struct  proc *b_proc;           /* Associated proc; NULL if kernel. */
   70         long    b_flags;                /* B_* flags. */
   71         unsigned short b_qindex;        /* buffer queue index */
   72         unsigned char b_usecount;       /* buffer use count */
   73         int     b_error;                /* Errno value. */
   74         long    b_bufsize;              /* Allocated buffer size. */
   75         long    b_bcount;               /* Valid bytes in buffer. */
   76         long    b_resid;                /* Remaining I/O. */
   77         dev_t   b_dev;                  /* Device associated with buffer. */
   78         struct {
   79                 caddr_t b_addr;         /* Memory, superblocks, indirect etc. */
   80         } b_un;
   81         caddr_t b_kvabase;              /* base kva for buffer */
   82         int     b_kvasize;              /* size of kva for buffer */
   83         void    *b_saveaddr;            /* Original b_addr for physio. */
   84         daddr_t b_lblkno;               /* Logical block number. */
   85         daddr_t b_blkno;                /* Underlying physical block number. */
   86                                         /* Function to call upon completion. */
   87         void    (*b_iodone) __P((struct buf *));
   88                                         /* For nested b_iodone's. */
   89         struct  iodone_chain *b_iodone_chain;
   90         struct  vnode *b_vp;            /* Device vnode. */
   91         int     b_dirtyoff;             /* Offset in buffer of dirty region. */
   92         int     b_dirtyend;             /* Offset of end of dirty region. */
   93         struct  ucred *b_rcred;         /* Read credentials reference. */
   94         struct  ucred *b_wcred;         /* Write credentials reference. */
   95         int     b_validoff;             /* Offset in buffer of valid region. */
   96         int     b_validend;             /* Offset of end of valid region. */
   97         daddr_t b_pblkno;               /* physical block number */
   98         caddr_t b_savekva;              /* saved kva for transfer while bouncing */
   99         void    *b_driver1;             /* for private use by the driver */
  100         void    *b_driver2;             /* for private use by the driver */
  101         void    *b_spc;
  102         union   cluster_info {
  103                 TAILQ_HEAD(cluster_list_head, buf) cluster_head;
  104                 TAILQ_ENTRY(buf) cluster_entry;
  105         } b_cluster;
  106         struct  vm_page *b_pages[btoc(MAXPHYS)];
  107         int             b_npages;
  108 };
  109 
  110 /* Device driver compatibility definitions. */
  111 #define b_data   b_un.b_addr            /* b_un.b_addr is not changeable. */
  112 
  113 /*
  114  * These flags are kept in b_flags.
  115  */
  116 #define B_AGE           0x00000001      /* Move to age queue when I/O done. */
  117 #define B_NEEDCOMMIT    0x00000002      /* Append-write in progress. */
  118 #define B_ASYNC         0x00000004      /* Start I/O, do not wait. */
  119 #define B_BAD           0x00000008      /* Bad block revectoring in progress. */
  120 #define B_BUSY          0x00000010      /* I/O in progress. */
  121 #define B_CACHE         0x00000020      /* Bread found us in the cache. */
  122 #define B_CALL          0x00000040      /* Call b_iodone from biodone. */
  123 #define B_DELWRI        0x00000080      /* Delay I/O until buffer reused. */
  124 #define B_DIRTY         0x00000100      /* Dirty page to be pushed out async. */
  125 #define B_DONE          0x00000200      /* I/O completed. */
  126 #define B_EINTR         0x00000400      /* I/O was interrupted */
  127 #define B_ERROR         0x00000800      /* I/O error occurred. */
  128 #define B_GATHERED      0x00001000      /* LFS: already in a segment. */
  129 #define B_INVAL         0x00002000      /* Does not contain valid info. */
  130 #define B_LOCKED        0x00004000      /* Locked in core (not reusable). */
  131 #define B_NOCACHE       0x00008000      /* Do not cache block after use. */
  132 #define B_MALLOC        0x00010000      /* malloced b_data */
  133 #define B_CLUSTEROK     0x00020000      /* Pagein op, so swap() can count it. */
  134 #define B_PHYS          0x00040000      /* I/O to user memory. */
  135 #define B_RAW           0x00080000      /* Set by physio for raw transfers. */
  136 #define B_READ          0x00100000      /* Read buffer. */
  137 #define B_TAPE          0x00200000      /* Magnetic tape I/O. */
  138 #define B_RELBUF        0x00400000      /* Release VMIO buffer. */
  139 #define B_WANTED        0x00800000      /* Process wants this buffer. */
  140 #define B_WRITE         0x00000000      /* Write buffer (pseudo flag). */
  141 #define B_WRITEINPROG   0x01000000      /* Write in progress. */
  142 #define B_XXX           0x02000000      /* Debugging flag. */
  143 #define B_PAGING        0x04000000      /* volatile paging I/O -- bypass VMIO */
  144 #define B_ORDERED       0x08000000      /* Must guarantee I/O ordering */
  145 #define B_VMIO          0x20000000      /* VMIO flag */
  146 #define B_CLUSTER       0x40000000      /* pagein op, so swap() can count it */
  147 #define B_BOUNCE        0x80000000      /* bounce buffer flag */
  148 
  149 typedef struct buf_queue_head {
  150         TAILQ_HEAD(buf_queue, buf) queue;
  151         struct  buf *insert_point;
  152         struct  buf *switch_point;
  153 } buf_queue_head, *buf_queue_head_t;
  154 
  155 static __inline void bufq_init __P((buf_queue_head *head));
  156 
  157 static __inline void bufq_insert_tail __P((buf_queue_head *head,
  158                                                 struct buf *bp));
  159 
  160 static __inline void bufq_remove __P((buf_queue_head *head,
  161                                            struct buf *bp));
  162 
  163 static __inline struct buf *bufq_first __P((buf_queue_head *head));
  164 
  165 static __inline void
  166 bufq_init(buf_queue_head *head)
  167 {
  168         TAILQ_INIT(&head->queue);
  169         head->insert_point = NULL;
  170         head->switch_point = NULL;
  171 }
  172 
  173 static __inline void
  174 bufq_insert_tail(buf_queue_head *head, struct buf *bp)
  175 {
  176         if ((bp->b_flags & B_ORDERED) != 0) {
  177                 head->insert_point = bp;
  178                 head->switch_point = NULL;
  179         }
  180         TAILQ_INSERT_TAIL(&head->queue, bp, b_act);
  181 }
  182 
  183 static __inline void
  184 bufq_remove(buf_queue_head *head, struct buf *bp)
  185 {
  186         if (bp == head->insert_point)
  187                 head->insert_point = TAILQ_PREV(bp, buf_queue, b_act);
  188         if (bp == head->switch_point)
  189                 head->switch_point = TAILQ_NEXT(bp, b_act);
  190         TAILQ_REMOVE(&head->queue, bp, b_act);
  191         if (TAILQ_FIRST(&head->queue) == head->switch_point)
  192                 head->switch_point = NULL;
  193 }
  194 
  195 static __inline struct buf *
  196 bufq_first(buf_queue_head *head)
  197 {
  198         return (TAILQ_FIRST(&head->queue));
  199 }
  200 
  201 /*
  202  * number of buffer hash entries
  203  */
  204 #define BUFHSZ 512
  205 
  206 /*
  207  * buffer hash table calculation, originally by David Greenman
  208  */
  209 #define BUFHASH(vnp, bn)        \
  210         (&bufhashtbl[(((unsigned long)(vnp) >> 7)+(int)(bn)) % BUFHSZ])
  211 
  212 /*
  213  * Definitions for the buffer free lists.
  214  */
  215 #define BUFFER_QUEUES   6       /* number of free buffer queues */
  216 
  217 extern LIST_HEAD(bufhashhdr, buf) bufhashtbl[BUFHSZ], invalhash;
  218 extern TAILQ_HEAD(bqueues, buf) bufqueues[BUFFER_QUEUES];
  219 
  220 #define QUEUE_NONE      0       /* on no queue */
  221 #define QUEUE_LOCKED    1       /* locked buffers */
  222 #define QUEUE_LRU       2       /* useful buffers */
  223 #define QUEUE_VMIO      3       /* VMIO buffers */
  224 #define QUEUE_AGE       4       /* not-useful buffers */
  225 #define QUEUE_EMPTY     5       /* empty buffer headers*/
  226 
  227 /*
  228  * Zero out the buffer's data area.
  229  */
  230 #define clrbuf(bp) {                                                    \
  231         bzero((bp)->b_data, (u_int)(bp)->b_bcount);                     \
  232         (bp)->b_resid = 0;                                              \
  233 }
  234 
  235 /* Flags to low-level allocation routines. */
  236 #define B_CLRBUF        0x01    /* Request allocated buffer be cleared. */
  237 #define B_SYNC          0x02    /* Do all allocations synchronously. */
  238 
  239 #ifdef KERNEL
  240 extern int      nbuf;                   /* The number of buffer headers */
  241 extern struct   buf *buf;               /* The buffer headers. */
  242 extern char     *buffers;               /* The buffer contents. */
  243 extern int      bufpages;               /* Number of memory pages in the buffer pool. */
  244 extern struct   buf *swbuf;             /* Swap I/O buffer headers. */
  245 extern int      nswbuf;                 /* Number of swap I/O buffer headers. */
  246 extern TAILQ_HEAD(swqueue, buf) bswlist;
  247 
  248 void    bufinit __P((void));
  249 void    bremfree __P((struct buf *));
  250 int     bread __P((struct vnode *, daddr_t, int,
  251             struct ucred *, struct buf **));
  252 int     breadn __P((struct vnode *, daddr_t, int, daddr_t *, int *, int,
  253             struct ucred *, struct buf **));
  254 int     bwrite __P((struct buf *));
  255 void    bdwrite __P((struct buf *));
  256 void    bawrite __P((struct buf *));
  257 int     bowrite __P((struct buf *));
  258 void    brelse __P((struct buf *));
  259 void    bqrelse __P((struct buf *));
  260 int     vfs_bio_awrite __P((struct buf *));
  261 struct buf *     getpbuf __P((void));
  262 struct buf *incore __P((struct vnode *, daddr_t));
  263 struct buf *gbincore __P((struct vnode *, daddr_t));
  264 int     inmem __P((struct vnode *, daddr_t));
  265 struct buf *getblk __P((struct vnode *, daddr_t, int, int, int));
  266 struct buf *geteblk __P((int));
  267 int     allocbuf __P((struct buf *, int));
  268 int     biowait __P((struct buf *));
  269 void    biodone __P((struct buf *));
  270 
  271 void    cluster_callback __P((struct buf *));
  272 int     cluster_read __P((struct vnode *, u_quad_t, daddr_t, long,
  273             struct ucred *, struct buf **));
  274 int     cluster_wbuild __P((struct vnode *, long, daddr_t, int));
  275 void    cluster_write __P((struct buf *, u_quad_t));
  276 int     physio __P((void (*)(struct buf *), struct buf *, dev_t, 
  277             int, u_int (*)(struct buf *), struct uio *));
  278 u_int   minphys __P((struct buf *));
  279 void    vfs_bio_clrbuf __P((struct buf *));
  280 void    vfs_busy_pages __P((struct buf *, int clear_modify));
  281 void    vfs_unbusy_pages(struct buf *);
  282 void    vwakeup __P((struct buf *));
  283 void    vmapbuf __P((struct buf *));
  284 void    vunmapbuf __P((struct buf *));
  285 void    relpbuf __P((struct buf *));
  286 void    brelvp __P((struct buf *));
  287 void    bgetvp __P((struct vnode *, struct buf *));
  288 void    pbgetvp __P((struct vnode *, struct buf *));
  289 void    pbrelvp __P((struct buf *));
  290 void    reassignbuf __P((struct buf *, struct vnode *));
  291 struct  buf *trypbuf __P((void));
  292 void    vm_bounce_alloc __P((struct buf *));
  293 void    vm_bounce_free __P((struct buf *));
  294 vm_offset_t     vm_bounce_kva_alloc __P((int));
  295 void    vm_bounce_kva_alloc_free __P((vm_offset_t, int));
  296 #endif /* KERNEL */
  297 
  298 #endif /* !_SYS_BUF_H_ */

Cache object: b5433aa04aec23c6383d056ff68f6ac1


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