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