xref: /original-bsd/sys/sys/buf.h (revision 9a96b58b)
1 /*	buf.h	4.14	82/04/19	*/
2 
3 /*	buf.h	2.1	3/25/82	*/
4 
5 /*
6  * The header for buffers in the buffer pool and otherwise used
7  * to describe a block i/o request is given here.  The routines
8  * which manipulate these things are given in bio.c.
9  *
10  * Each buffer in the pool is usually doubly linked into 2 lists:
11  * hashed into a chain by <dev,blkno> so it can be located in the cache,
12  * and (usually) on (one of several) queues.  These lists are circular and
13  * doubly linked for easy removal.
14  *
15  * There are currently three queues for buffers:
16  *	one for buffers which must be kept permanently (super blocks)
17  * 	one for buffers containing ``useful'' information (the cache)
18  *	one for buffers containing ``non-useful'' information
19  *		(and empty buffers, pushed onto the front)
20  * The latter two queues contain the buffers which are available for
21  * reallocation, are kept in lru order.  When not on one of these queues,
22  * the buffers are ``checked out'' to drivers which use the available list
23  * pointers to keep track of them in their i/o active queues.
24  */
25 
26 /*
27  * Bufhd structures used at the head of the hashed buffer queues.
28  * We only need three words for these, so this abbreviated
29  * definition saves some space.
30  */
31 struct bufhd
32 {
33 	long	b_flags;		/* see defines below */
34 	struct	buf *b_forw, *b_back;	/* fwd/bkwd pointer in chain */
35 };
36 struct buf
37 {
38 	long	b_flags;		/* too much goes here to describe */
39 	struct	buf *b_forw, *b_back;	/* hash chain (2 way street) */
40 	struct	buf *av_forw, *av_back;	/* position on free list if not BUSY */
41 #define	b_actf	av_forw			/* alternate names for driver queue */
42 #define	b_actl	av_back			/*    head - isn't history wonderful */
43 	long	b_bcount;		/* transfer count */
44 #define	b_active b_bcount		/* driver queue head: drive active */
45 	short	b_error;		/* returned after I/O */
46 	dev_t	b_dev;			/* major+minor device name */
47 	union {
48 	    caddr_t b_addr;		/* low order core address */
49 	    int	*b_words;		/* words for clearing */
50 	    struct fs *b_fs;		/* superblocks */
51 	    struct csum *b_cs;		/* superblock summary information */
52 	    struct cg *b_cg;		/* cylinder group block */
53 	    struct dinode *b_dino;	/* ilist */
54 	    daddr_t *b_daddr;		/* indirect block */
55 	} b_un;
56 	daddr_t	b_blkno;		/* block # on device */
57 	long	b_resid;		/* words not transferred after error */
58 #define	b_errcnt b_resid		/* while i/o in progress: # retries */
59 #define	b_pfcent b_resid		/* garbage: don't ask */
60 	struct  proc *b_proc;		/* proc doing physical or swap I/O */
61 };
62 
63 #define	BQUEUES		3		/* number of free buffer queues */
64 #define	BQ_LOCKED	0		/* super-blocks &c */
65 #define	BQ_LRU		1		/* lru, useful buffers */
66 #define	BQ_AGE		2		/* rubbish */
67 
68 #ifdef	KERNEL
69 struct	buf *buf;		/* the buffer pool itself */
70 char	*buffers;
71 int	nbuf;
72 struct	buf *swbuf;		/* swap I/O headers */
73 int	nswbuf;
74 short	*swsize;
75 int	*swpf;
76 struct	buf bfreelist[BQUEUES];	/* heads of available lists */
77 struct	buf bswlist;		/* head of free swap header list */
78 struct	buf *bclnlist;		/* head of cleaned page list */
79 
80 struct	buf *alloc();
81 struct	buf *realloccg();
82 struct	buf *baddr();
83 struct	buf *getblk();
84 struct	buf *geteblk();
85 struct	buf *bread();
86 struct	buf *breada();
87 
88 unsigned minphys();
89 #endif
90 
91 /*
92  * These flags are kept in b_flags.
93  */
94 #define	B_WRITE		0x000000	/* non-read pseudo-flag */
95 #define	B_READ		0x000001	/* read when I/O occurs */
96 #define	B_DONE		0x000002	/* transaction finished */
97 #define	B_ERROR		0x000004	/* transaction aborted */
98 #define	B_BUSY		0x000008	/* not on av_forw/back list */
99 #define	B_PHYS		0x000010	/* physical IO */
100 #define	B_XXX		0x000020	/* was B_MAP, alloc UNIBUS on pdp-11 */
101 #define	B_WANTED	0x000040	/* issue wakeup when BUSY goes off */
102 #define	B_AGE		0x000080	/* delayed write for correct aging */
103 #define	B_ASYNC		0x000100	/* don't wait for I/O completion */
104 #define	B_DELWRI	0x000200	/* write at exit of avail list */
105 #define	B_TAPE		0x000400	/* this is a magtape (no bdwrite) */
106 #define	B_UAREA		0x000800	/* add u-area to a swap operation */
107 #define	B_PAGET		0x001000	/* page in/out of page table space */
108 #define	B_DIRTY		0x002000	/* dirty page to be pushed out async */
109 #define	B_PGIN		0x004000	/* pagein op, so swap() can count it */
110 #define	B_CACHE		0x008000	/* did bread find us in the cache ? */
111 #define	B_INVAL		0x010000	/* does not contain valid info  */
112 #define	B_LOCKED	0x020000	/* locked in core (not reusable) */
113 #define	B_HEAD		0x040000	/* a buffer header, not a buffer */
114 #define	B_BAD		0x100000	/* bad block revectoring in progress */
115