1 /* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)buf.h 8.1 (Berkeley) 06/02/93 8 */ 9 10 #ifndef _BUF_H_ 11 #define _BUF_H_ 12 #include <sys/queue.h> 13 14 /* 15 * The header for buffers in the buffer pool and otherwise used 16 * to describe a block i/o request is given here. 17 * 18 * Each buffer in the pool is usually doubly linked into 2 lists: 19 * hashed into a chain by <dev,blkno> so it can be located in the cache, 20 * and (usually) on (one of several) queues. These lists are circular and 21 * doubly linked for easy removal. 22 * 23 * There are currently three queues for buffers: 24 * one for buffers which must be kept permanently (super blocks) 25 * one for buffers containing ``useful'' information (the cache) 26 * one for buffers containing ``non-useful'' information 27 * (and empty buffers, pushed onto the front) 28 * The latter two queues contain the buffers which are available for 29 * reallocation, are kept in lru order. When not on one of these queues, 30 * the buffers are ``checked out'' to drivers which use the available list 31 * pointers to keep track of them in their i/o active queues. 32 */ 33 34 struct buf { 35 volatile long b_flags; /* too much goes here to describe */ 36 struct queue_entry b_hash; /* hash chain */ 37 struct queue_entry b_vnbufs; /* associated vnode */ 38 struct queue_entry b_freelist; /* position on free list if not BUSY */ 39 struct buf *b_actf, **b_actb; /* device driver I/O queue when BUSY */ 40 long b_bcount; /* transfer count */ 41 long b_bufsize; /* size of allocated buffer */ 42 short b_error; /* returned after I/O */ 43 dev_t b_dev; /* major+minor device name */ 44 union { 45 caddr_t b_addr; /* low order core address */ 46 int *b_words; /* words for clearing */ 47 struct fs *b_fs; /* UFS superblocks */ 48 struct lfs *b_lfs; /* LFS superblocks */ 49 struct csum *b_cs; /* superblock summary information */ 50 struct cg *b_cg; /* cylinder group block */ 51 struct dinode *b_dino; /* ilist */ 52 daddr_t *b_daddr; /* indirect block */ 53 } b_un; 54 daddr_t b_lblkno; /* logical block number */ 55 daddr_t b_blkno; /* block # on device */ 56 long b_resid; /* words not transferred after error */ 57 struct proc *b_proc; /* proc doing physical or swap I/O */ 58 void (*b_iodone)(); /* function called by iodone */ 59 struct vnode *b_vp; /* vnode for dev */ 60 int b_pfcent; /* center page when swapping cluster */ 61 struct ucred *b_rcred; /* ref to read credentials */ 62 struct ucred *b_wcred; /* ref to write credendtials */ 63 int b_dirtyoff; /* offset in buffer of dirty region */ 64 int b_dirtyend; /* offset of end of dirty region */ 65 caddr_t b_saveaddr; /* original b_addr for PHYSIO */ 66 int b_validoff; /* offset in buffer of valid region */ 67 int b_validend; /* offset of end of valid region */ 68 }; 69 70 /* 71 * Defines for device drivers. 72 */ 73 #define b_active b_bcount /* driver queue head: drive active */ 74 #define b_errcnt b_resid /* while i/o in progress: # retries */ 75 76 /* 77 * This structure describes a clustered I/O. It is 78 * stored in the b_saveaddr field of the buffer on 79 * which I/O is performed. At I/O completion, cluster 80 * callback uses the structure to parcel I/Os to 81 * individual buffers, and then frees this structure. 82 */ 83 struct cluster_save { 84 long bs_bcount; 85 long bs_bufsize; 86 caddr_t bs_saveaddr; 87 int bs_nchildren; 88 struct buf **bs_children; 89 }; 90 91 #ifdef KERNEL 92 struct buf *buf; /* the buffer pool itself */ 93 char *buffers; 94 int nbuf; /* number of buffer headers */ 95 int bufpages; /* number of memory pages in the buffer pool */ 96 struct buf *swbuf; /* swap I/O headers */ 97 int nswbuf; 98 struct buf bswlist; /* head of free swap header list */ 99 struct buf *bclnlist; /* head of cleaned page list */ 100 101 __BEGIN_DECLS 102 int allocbuf __P((struct buf *, int)); 103 int bawrite __P((struct buf *)); 104 int bdwrite __P((struct buf *)); 105 void biodone __P((struct buf *)); 106 int biowait __P((struct buf *)); 107 int bread __P((struct vnode *, daddr_t, int, 108 struct ucred *, struct buf **)); 109 int breadn __P((struct vnode *, daddr_t, int, daddr_t *, int *, int, 110 struct ucred *, struct buf **)); 111 int brelse __P((struct buf *)); 112 void bufinit __P((void)); 113 int bwrite __P((struct buf *)); 114 void cluster_callback __P((struct buf *)); 115 int cluster_read __P((struct vnode *, u_quad_t, daddr_t, long, 116 struct ucred *, struct buf **)); 117 void cluster_write __P((struct buf *, u_quad_t)); 118 struct buf *getblk __P((struct vnode *, daddr_t, int, int, int)); 119 struct buf *geteblk __P((int)); 120 struct buf *getnewbuf __P((int slpflag, int slptimeo)); 121 struct buf *incore __P((struct vnode *, daddr_t)); 122 u_int minphys __P((struct buf *bp)); 123 __END_DECLS 124 #endif 125 126 /* 127 * These flags are kept in b_flags. 128 */ 129 #define B_WRITE 0x00000000 /* non-read pseudo-flag */ 130 #define B_READ 0x00000001 /* read when I/O occurs */ 131 #define B_DONE 0x00000002 /* transaction finished */ 132 #define B_ERROR 0x00000004 /* transaction aborted */ 133 #define B_BUSY 0x00000008 /* not on av_forw/back list */ 134 #define B_PHYS 0x00000010 /* physical IO */ 135 #define B_XXX 0x00000020 /* was B_MAP, alloc UNIBUS on pdp-11 */ 136 #define B_WANTED 0x00000040 /* issue wakeup when BUSY goes off */ 137 #define B_AGE 0x00000080 /* delayed write for correct aging */ 138 #define B_ASYNC 0x00000100 /* don't wait for I/O completion */ 139 #define B_DELWRI 0x00000200 /* write at exit of avail list */ 140 #define B_TAPE 0x00000400 /* this is a magtape (no bdwrite) */ 141 #define B_UAREA 0x00000800 /* add u-area to a swap operation */ 142 #define B_PAGET 0x00001000 /* page in/out of page table space */ 143 #define B_DIRTY 0x00002000 /* dirty page to be pushed out async */ 144 #define B_PGIN 0x00004000 /* pagein op, so swap() can count it */ 145 #define B_CACHE 0x00008000 /* did bread find us in the cache ? */ 146 #define B_INVAL 0x00010000 /* does not contain valid info */ 147 #define B_LOCKED 0x00020000 /* locked in core (not reusable) */ 148 #define B_HEAD 0x00040000 /* a buffer header, not a buffer */ 149 #define B_GATHERED 0x00080000 /* LFS: already in a segment */ 150 #define B_BAD 0x00100000 /* bad block revectoring in progress */ 151 #define B_CALL 0x00200000 /* call b_iodone from iodone */ 152 #define B_RAW 0x00400000 /* set by physio for raw transfers */ 153 #define B_NOCACHE 0x00800000 /* do not cache block after use */ 154 #define B_WRITEINPROG 0x01000000 /* write in progress on buffer */ 155 #define B_APPENDWRITE 0x02000000 /* append-write in progress on buffer */ 156 #define B_EINTR 0x04000000 /* I/O was interrupted */ 157 158 #define iodone biodone 159 #define iowait biowait 160 161 /* 162 * Zero out a buffer's data portion. 163 */ 164 #define clrbuf(bp) { \ 165 blkclr((bp)->b_un.b_addr, (unsigned)(bp)->b_bcount); \ 166 (bp)->b_resid = 0; \ 167 } 168 #define B_CLRBUF 0x1 /* request allocated buffer be cleared */ 169 #define B_SYNC 0x2 /* do all allocations synchronously */ 170 #endif /* !_BUF_H_ */ 171