Home | History | Annotate | Line # | Download | only in fsck_lfs
bufcache.h revision 1.2
      1 /*	$NetBSD: bufcache.h,v 1.2 2003/08/07 10:04:22 agc 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. Neither the name of the University nor the names of its contributors
     58  *    may be used to endorse or promote products derived from this software
     59  *    without specific prior written permission.
     60  *
     61  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     62  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     63  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     64  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     65  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     66  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     67  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     68  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     69  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     70  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     71  * SUCH DAMAGE.
     72  *
     73  *	@(#)buf.h	8.9 (Berkeley) 3/30/95
     74  */
     75 
     76 #define BUF_CACHE_SIZE 1000
     77 
     78 /*
     79  * The buffer header describes an I/O operation.
     80  */
     81 struct ubuf {
     82 	LIST_ENTRY(ubuf) b_hash;	/* Hash chain. */
     83 	LIST_ENTRY(ubuf) b_vnbufs;	/* Buffer's associated vnode. */
     84 	TAILQ_ENTRY(ubuf) b_freelist;	/* Free list position if not active. */
     85 	volatile long	b_flags;	/* B_* flags. */
     86 	long	b_bcount;		/* Valid bytes in buffer. */
     87 #undef b_data
     88 	char	*b_data;		/* Data in buffer */
     89 	daddr_t	b_lblkno;		/* Logical block number. */
     90 	daddr_t	b_blkno;		/* Underlying physical block number */
     91 	struct	uvnode *b_vp;		/* File vnode. */
     92 };
     93 
     94 #define b_bufsize b_bcount
     95 
     96 /*
     97  * These flags are kept in b_flags.
     98  */
     99 #define	B_AGE		0x00000001	/* Move to age queue when I/O done. */
    100 #define	B_NEEDCOMMIT	0x00000002	/* Needs committing to stable storage */
    101 #define	B_BUSY		0x00000010	/* I/O in progress. */
    102 #define	B_DELWRI	0x00000080	/* Delay I/O until buffer reused. */
    103 #define	B_DONE		0x00000200	/* I/O completed. */
    104 #define	B_ERROR		0x00000800	/* I/O error occurred. */
    105 #define	B_GATHERED	0x00001000	/* LFS: already in a segment. */
    106 #define	B_INVAL		0x00002000	/* Does not contain valid info. */
    107 #define	B_LOCKED	0x00004000	/* Locked in core (not reusable). */
    108 #define	B_READ		0x00100000	/* Read buffer. */
    109 
    110 LIST_HEAD(bufhash_struct, ubuf);
    111 
    112 void bufinit(void);
    113 void bufstats(void);
    114 void buf_destroy(struct ubuf *);
    115 void bremfree(struct ubuf *);
    116 struct ubuf *incore(struct uvnode *, int);
    117 struct ubuf *getblk(struct uvnode *, daddr_t, int);
    118 void bwrite(struct ubuf *);
    119 void brelse(struct ubuf *);
    120 int bread(struct uvnode *, daddr_t, int, struct ucred *, struct ubuf **);
    121 void reassignbuf(struct ubuf *, struct uvnode *);
    122