1 /* $NetBSD: ext2fs_subr.c,v 1.4 2000/03/30 12:41:11 augustss 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 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 #ifdef DIAGNOSTIC 86 void 87 ext2fs_checkoverlap(bp, ip) 88 struct buf *bp; 89 struct inode *ip; 90 { 91 struct buf *ebp, *ep; 92 ufs_daddr_t start, last; 93 struct vnode *vp; 94 95 ebp = &buf[nbuf]; 96 start = bp->b_blkno; 97 last = start + btodb(bp->b_bcount) - 1; 98 for (ep = buf; ep < ebp; ep++) { 99 if (ep == bp || (ep->b_flags & B_INVAL) || 100 ep->b_vp == NULLVP) 101 continue; 102 if (VOP_BMAP(ep->b_vp, (ufs_daddr_t)0, &vp, (ufs_daddr_t)0, NULL)) 103 continue; 104 if (vp != ip->i_devvp) 105 continue; 106 /* look for overlap */ 107 if (ep->b_bcount == 0 || ep->b_blkno > last || 108 ep->b_blkno + btodb(ep->b_bcount) <= start) 109 continue; 110 vprint("Disk overlap", vp); 111 printf("\tstart %d, end %d overlap start %d, end %ld\n", 112 start, last, ep->b_blkno, 113 ep->b_blkno + btodb(ep->b_bcount) - 1); 114 panic("Disk buffer overlap"); 115 } 116 } 117 #endif 118