xref: /netbsd-src/sbin/fsck_lfs/bufcache.h (revision d710132b4b8ce7f7cccaaf660cb16aa16b4077a0)
1 /*	$NetBSD: bufcache.h,v 1.1 2003/03/28 08:09:52 perseant Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the NetBSD
22  *	Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 /*
41  * Copyright (c) 1982, 1986, 1989, 1993
42  *	The Regents of the University of California.  All rights reserved.
43  * (c) UNIX System Laboratories, Inc.
44  * All or some portions of this file are derived from material licensed
45  * to the University of California by American Telephone and Telegraph
46  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
47  * the permission of UNIX System Laboratories, Inc.
48  *
49  * Redistribution and use in source and binary forms, with or without
50  * modification, are permitted provided that the following conditions
51  * are met:
52  * 1. Redistributions of source code must retain the above copyright
53  *    notice, this list of conditions and the following disclaimer.
54  * 2. Redistributions in binary form must reproduce the above copyright
55  *    notice, this list of conditions and the following disclaimer in the
56  *    documentation and/or other materials provided with the distribution.
57  * 3. All advertising materials mentioning features or use of this software
58  *    must display the following acknowledgement:
59  *	This product includes software developed by the University of
60  *	California, Berkeley and its contributors.
61  * 4. Neither the name of the University nor the names of its contributors
62  *    may be used to endorse or promote products derived from this software
63  *    without specific prior written permission.
64  *
65  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
66  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
67  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
68  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
69  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
70  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
71  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
72  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
73  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
74  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
75  * SUCH DAMAGE.
76  *
77  *	@(#)buf.h	8.9 (Berkeley) 3/30/95
78  */
79 
80 #define BUF_CACHE_SIZE 1000
81 
82 /*
83  * The buffer header describes an I/O operation.
84  */
85 struct ubuf {
86 	LIST_ENTRY(ubuf) b_hash;	/* Hash chain. */
87 	LIST_ENTRY(ubuf) b_vnbufs;	/* Buffer's associated vnode. */
88 	TAILQ_ENTRY(ubuf) b_freelist;	/* Free list position if not active. */
89 	volatile long	b_flags;	/* B_* flags. */
90 	long	b_bcount;		/* Valid bytes in buffer. */
91 #undef b_data
92 	char	*b_data;		/* Data in buffer */
93 	daddr_t	b_lblkno;		/* Logical block number. */
94 	daddr_t	b_blkno;		/* Underlying physical block number */
95 	struct	uvnode *b_vp;		/* File vnode. */
96 };
97 
98 #define b_bufsize b_bcount
99 
100 /*
101  * These flags are kept in b_flags.
102  */
103 #define	B_AGE		0x00000001	/* Move to age queue when I/O done. */
104 #define	B_NEEDCOMMIT	0x00000002	/* Needs committing to stable storage */
105 #define	B_BUSY		0x00000010	/* I/O in progress. */
106 #define	B_DELWRI	0x00000080	/* Delay I/O until buffer reused. */
107 #define	B_DONE		0x00000200	/* I/O completed. */
108 #define	B_ERROR		0x00000800	/* I/O error occurred. */
109 #define	B_GATHERED	0x00001000	/* LFS: already in a segment. */
110 #define	B_INVAL		0x00002000	/* Does not contain valid info. */
111 #define	B_LOCKED	0x00004000	/* Locked in core (not reusable). */
112 #define	B_READ		0x00100000	/* Read buffer. */
113 
114 LIST_HEAD(bufhash_struct, ubuf);
115 
116 void bufinit(void);
117 void bufstats(void);
118 void buf_destroy(struct ubuf *);
119 void bremfree(struct ubuf *);
120 struct ubuf *incore(struct uvnode *, int);
121 struct ubuf *getblk(struct uvnode *, daddr_t, int);
122 void bwrite(struct ubuf *);
123 void brelse(struct ubuf *);
124 int bread(struct uvnode *, daddr_t, int, struct ucred *, struct ubuf **);
125 void reassignbuf(struct ubuf *, struct uvnode *);
126