xref: /original-bsd/sys/sys/buf.h (revision be1f24e8)
1 /*
2  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)buf.h	7.19 (Berkeley) 10/02/92
8  */
9 
10 #ifndef _BUF_H_
11 #define	_BUF_H_
12 
13 /*
14  * The header for buffers in the buffer pool and otherwise used
15  * to describe a block i/o request is given here.
16  *
17  * Each buffer in the pool is usually doubly linked into 2 lists:
18  * hashed into a chain by <dev,blkno> so it can be located in the cache,
19  * and (usually) on (one of several) queues.  These lists are circular and
20  * doubly linked for easy removal.
21  *
22  * There are currently three queues for buffers:
23  *	one for buffers which must be kept permanently (super blocks)
24  * 	one for buffers containing ``useful'' information (the cache)
25  *	one for buffers containing ``non-useful'' information
26  *		(and empty buffers, pushed onto the front)
27  * The latter two queues contain the buffers which are available for
28  * reallocation, are kept in lru order.  When not on one of these queues,
29  * the buffers are ``checked out'' to drivers which use the available list
30  * pointers to keep track of them in their i/o active queues.
31  */
32 
33 struct buf {
34 	volatile long	b_flags;	/* too much goes here to describe */
35 	struct	buf *b_forw, **b_back;	/* hash chain (2 way street) */
36 	struct	buf *b_blockf, **b_blockb;/* associated vnode */
37 	struct	buf *b_actf, **b_actb;	/* position on free list if not BUSY */
38 	long	b_bcount;		/* transfer count */
39 	long	b_bufsize;		/* size of allocated buffer */
40 #define	b_active b_bcount		/* driver queue head: drive active */
41 	short	b_error;		/* returned after I/O */
42 	dev_t	b_dev;			/* major+minor device name */
43 	union {
44 	    caddr_t b_addr;		/* low order core address */
45 	    int	*b_words;		/* words for clearing */
46 	    struct fs *b_fs;		/* UFS superblocks */
47 	    struct lfs *b_lfs;		/* LFS superblocks */
48 	    struct csum *b_cs;		/* superblock summary information */
49 	    struct cg *b_cg;		/* cylinder group block */
50 	    struct dinode *b_dino;	/* ilist */
51 	    daddr_t *b_daddr;		/* indirect block */
52 	} b_un;
53 	daddr_t	b_lblkno;		/* logical block number */
54 	daddr_t	b_blkno;		/* block # on device */
55 	long	b_resid;		/* words not transferred after error */
56 #define	b_errcnt b_resid		/* while i/o in progress: # retries */
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 #ifdef KERNEL
71 struct	buf *buf;		/* the buffer pool itself */
72 char	*buffers;
73 int	nbuf;			/* number of buffer headers */
74 int	bufpages;		/* number of memory pages in the buffer pool */
75 struct	buf *swbuf;		/* swap I/O headers */
76 int	nswbuf;
77 struct	buf bswlist;		/* head of free swap header list */
78 struct	buf *bclnlist;		/* head of cleaned page list */
79 
80 __BEGIN_DECLS
81 int	allocbuf __P((struct buf *, int));
82 int	bawrite __P((struct buf *));
83 int	bdwrite __P((struct buf *));
84 void	biodone __P((struct buf *));
85 int	biowait __P((struct buf *));
86 int	bread __P((struct vnode *, daddr_t, int,
87 	    struct ucred *, struct buf **));
88 int	breadn __P((struct vnode *, daddr_t, int, daddr_t *, int *, int,
89 	    struct ucred *, struct buf **));
90 int	brelse __P((struct buf *));
91 void	bufinit __P((void));
92 int	bwrite __P((struct buf *));
93 struct buf *getblk __P((struct vnode *, daddr_t, int));
94 struct buf *geteblk __P((int));
95 struct buf *getnewbuf __P((void));
96 int	incore __P((struct vnode *, daddr_t));
97 u_int	minphys __P((struct buf *bp));
98 __END_DECLS
99 #endif
100 
101 /*
102  * These flags are kept in b_flags.
103  */
104 #define	B_WRITE		0x000000	/* non-read pseudo-flag */
105 #define	B_READ		0x000001	/* read when I/O occurs */
106 #define	B_DONE		0x000002	/* transaction finished */
107 #define	B_ERROR		0x000004	/* transaction aborted */
108 #define	B_BUSY		0x000008	/* not on av_forw/back list */
109 #define	B_PHYS		0x000010	/* physical IO */
110 #define	B_XXX		0x000020	/* was B_MAP, alloc UNIBUS on pdp-11 */
111 #define	B_WANTED	0x000040	/* issue wakeup when BUSY goes off */
112 #define	B_AGE		0x000080	/* delayed write for correct aging */
113 #define	B_ASYNC		0x000100	/* don't wait for I/O completion */
114 #define	B_DELWRI	0x000200	/* write at exit of avail list */
115 #define	B_TAPE		0x000400	/* this is a magtape (no bdwrite) */
116 #define	B_UAREA		0x000800	/* add u-area to a swap operation */
117 #define	B_PAGET		0x001000	/* page in/out of page table space */
118 #define	B_DIRTY		0x002000	/* dirty page to be pushed out async */
119 #define	B_PGIN		0x004000	/* pagein op, so swap() can count it */
120 #define	B_CACHE		0x008000	/* did bread find us in the cache ? */
121 #define	B_INVAL		0x010000	/* does not contain valid info  */
122 #define	B_LOCKED	0x020000	/* locked in core (not reusable) */
123 #define	B_HEAD		0x040000	/* a buffer header, not a buffer */
124 #define	B_GATHERED	0x080000	/* LFS: already in a segment */
125 #define	B_BAD		0x100000	/* bad block revectoring in progress */
126 #define	B_CALL		0x200000	/* call b_iodone from iodone */
127 #define	B_RAW		0x400000	/* set by physio for raw transfers */
128 #define	B_NOCACHE	0x800000	/* do not cache block after use */
129 
130 #define	iodone	biodone
131 #define	iowait	biowait
132 
133 /*
134  * Zero out a buffer's data portion.
135  */
136 #define	clrbuf(bp) { \
137 	blkclr((bp)->b_un.b_addr, (unsigned)(bp)->b_bcount); \
138 	(bp)->b_resid = 0; \
139 }
140 #define B_CLRBUF	0x1	/* request allocated buffer be cleared */
141 #define B_SYNC		0x2	/* do all allocations synchronously */
142 #endif /* !_BUF_H_ */
143