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