Home | History | Annotate | Line # | Download | only in ext2fs
ext2fs_subr.c revision 1.10
      1 /*	$NetBSD: ext2fs_subr.c,v 1.10 2003/08/07 16:34:27 agc Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1989, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	@(#)ffs_subr.c	8.2 (Berkeley) 9/21/93
     32  * Modified for ext2fs by Manuel Bouyer.
     33  */
     34 
     35 /*
     36  * Copyright (c) 1997 Manuel Bouyer.
     37  *
     38  * Redistribution and use in source and binary forms, with or without
     39  * modification, are permitted provided that the following conditions
     40  * are met:
     41  * 1. Redistributions of source code must retain the above copyright
     42  *    notice, this list of conditions and the following disclaimer.
     43  * 2. Redistributions in binary form must reproduce the above copyright
     44  *    notice, this list of conditions and the following disclaimer in the
     45  *    documentation and/or other materials provided with the distribution.
     46  * 3. All advertising materials mentioning features or use of this software
     47  *    must display the following acknowledgement:
     48  *	This product includes software developed by the University of
     49  *	California, Berkeley and its contributors.
     50  * 4. 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  *	@(#)ffs_subr.c	8.2 (Berkeley) 9/21/93
     67  * Modified for ext2fs by Manuel Bouyer.
     68  */
     69 
     70 #include <sys/cdefs.h>
     71 __KERNEL_RCSID(0, "$NetBSD: ext2fs_subr.c,v 1.10 2003/08/07 16:34:27 agc Exp $");
     72 
     73 #include <sys/param.h>
     74 #include <sys/systm.h>
     75 #include <sys/vnode.h>
     76 #include <sys/buf.h>
     77 #include <sys/inttypes.h>
     78 #include <ufs/ufs/inode.h>
     79 #include <ufs/ext2fs/ext2fs.h>
     80 #include <ufs/ext2fs/ext2fs_extern.h>
     81 
     82 /*
     83  * Return buffer with the contents of block "offset" from the beginning of
     84  * directory "ip".  If "res" is non-zero, fill it in with a pointer to the
     85  * remaining space in the directory.
     86  */
     87 int
     88 ext2fs_blkatoff(v)
     89 	void *v;
     90 {
     91 	struct vop_blkatoff_args /* {
     92 		struct vnode *a_vp;
     93 		off_t a_offset;
     94 		char **a_res;
     95 		struct buf **a_bpp;
     96 	} */ *ap = v;
     97 	struct inode *ip;
     98 	struct m_ext2fs *fs;
     99 	struct buf *bp;
    100 	daddr_t lbn;
    101 	int error;
    102 
    103 	ip = VTOI(ap->a_vp);
    104 	fs = ip->i_e2fs;
    105 	lbn = lblkno(fs, ap->a_offset);
    106 
    107 	*ap->a_bpp = NULL;
    108 	if ((error = bread(ap->a_vp, lbn, fs->e2fs_bsize, NOCRED, &bp)) != 0) {
    109 		brelse(bp);
    110 		return (error);
    111 	}
    112 	if (ap->a_res)
    113 		*ap->a_res = (char *)bp->b_data + blkoff(fs, ap->a_offset);
    114 	*ap->a_bpp = bp;
    115 	return (0);
    116 }
    117 
    118 #ifdef DIAGNOSTIC
    119 void
    120 ext2fs_checkoverlap(bp, ip)
    121 	struct buf *bp;
    122 	struct inode *ip;
    123 {
    124 	struct buf *ebp, *ep;
    125 	daddr_t start, last;
    126 	struct vnode *vp;
    127 
    128 	ebp = &buf[nbuf];
    129 	start = bp->b_blkno;
    130 	last = start + btodb(bp->b_bcount) - 1;
    131 	for (ep = buf; ep < ebp; ep++) {
    132 		if (ep == bp || (ep->b_flags & B_INVAL) ||
    133 			ep->b_vp == NULLVP)
    134 			continue;
    135 		if (VOP_BMAP(ep->b_vp, (daddr_t)0, &vp, (daddr_t)0, NULL))
    136 			continue;
    137 		if (vp != ip->i_devvp)
    138 			continue;
    139 		/* look for overlap */
    140 		if (ep->b_bcount == 0 || ep->b_blkno > last ||
    141 			ep->b_blkno + btodb(ep->b_bcount) <= start)
    142 			continue;
    143 		vprint("Disk overlap", vp);
    144 		printf("\tstart %" PRId64 ", end %" PRId64 " overlap start "
    145 			"%" PRId64 ", end %" PRId64 "\n",
    146 			start, last, ep->b_blkno,
    147 			ep->b_blkno + btodb(ep->b_bcount) - 1);
    148 		panic("Disk buffer overlap");
    149 	}
    150 }
    151 #endif
    152