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