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