1 /* $NetBSD: ext2fs_subr.c,v 1.1 1997/06/11 09:34:03 bouyer 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 <ufs/ext2fs/ext2fs.h> 43 #include <ufs/ext2fs/ext2fs_extern.h> 44 45 #ifdef _KERNEL 46 #include <sys/vnode.h> 47 #include <sys/buf.h> 48 #include <ufs/ufs/quota.h> 49 #include <ufs/ufs/inode.h> 50 51 /* 52 * Return buffer with the contents of block "offset" from the beginning of 53 * directory "ip". If "res" is non-zero, fill it in with a pointer to the 54 * remaining space in the directory. 55 */ 56 int 57 ext2fs_blkatoff(v) 58 void *v; 59 { 60 struct vop_blkatoff_args /* { 61 struct vnode *a_vp; 62 off_t a_offset; 63 char **a_res; 64 struct buf **a_bpp; 65 } */ *ap = v; 66 struct inode *ip; 67 register struct m_ext2fs *fs; 68 struct buf *bp; 69 daddr_t lbn; 70 int error; 71 72 ip = VTOI(ap->a_vp); 73 fs = ip->i_e2fs; 74 lbn = lblkno(fs, ap->a_offset); 75 76 *ap->a_bpp = NULL; 77 if ((error = bread(ap->a_vp, lbn, fs->e2fs_bsize, NOCRED, &bp)) != 0) { 78 brelse(bp); 79 return (error); 80 } 81 if (ap->a_res) 82 *ap->a_res = (char *)bp->b_data + blkoff(fs, ap->a_offset); 83 *ap->a_bpp = bp; 84 return (0); 85 } 86 #endif 87 88 #if defined(_KERNEL) && defined(DIAGNOSTIC) 89 void 90 ext2fs_checkoverlap(bp, ip) 91 struct buf *bp; 92 struct inode *ip; 93 { 94 register struct buf *ebp, *ep; 95 register daddr_t start, last; 96 struct vnode *vp; 97 98 ebp = &buf[nbuf]; 99 start = bp->b_blkno; 100 last = start + btodb(bp->b_bcount) - 1; 101 for (ep = buf; ep < ebp; ep++) { 102 if (ep == bp || (ep->b_flags & B_INVAL) || 103 ep->b_vp == NULLVP) 104 continue; 105 if (VOP_BMAP(ep->b_vp, (daddr_t)0, &vp, (daddr_t)0, NULL)) 106 continue; 107 if (vp != ip->i_devvp) 108 continue; 109 /* look for overlap */ 110 if (ep->b_bcount == 0 || ep->b_blkno > last || 111 ep->b_blkno + btodb(ep->b_bcount) <= start) 112 continue; 113 vprint("Disk overlap", vp); 114 printf("\tstart %d, end %d overlap start %d, end %ld\n", 115 start, last, ep->b_blkno, 116 ep->b_blkno + btodb(ep->b_bcount) - 1); 117 panic("Disk buffer overlap"); 118 } 119 } 120 #endif /* DIAGNOSTIC */ 121