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