ext2_subr.c revision 33291
112115Sdyson/* 212115Sdyson * modified for Lites 1.1 312115Sdyson * 412115Sdyson * Aug 1995, Godmar Back (gback@cs.utah.edu) 512115Sdyson * University of Utah, Department of Computer Science 612115Sdyson */ 712115Sdyson/* 812115Sdyson * Copyright (c) 1982, 1986, 1989, 1993 912115Sdyson * The Regents of the University of California. All rights reserved. 1012115Sdyson * 1112115Sdyson * Redistribution and use in source and binary forms, with or without 1212115Sdyson * modification, are permitted provided that the following conditions 1312115Sdyson * are met: 1412115Sdyson * 1. Redistributions of source code must retain the above copyright 1512115Sdyson * notice, this list of conditions and the following disclaimer. 1612115Sdyson * 2. Redistributions in binary form must reproduce the above copyright 1712115Sdyson * notice, this list of conditions and the following disclaimer in the 1812115Sdyson * documentation and/or other materials provided with the distribution. 1912115Sdyson * 3. All advertising materials mentioning features or use of this software 2012115Sdyson * must display the following acknowledgement: 2112115Sdyson * This product includes software developed by the University of 2212115Sdyson * California, Berkeley and its contributors. 2312115Sdyson * 4. Neither the name of the University nor the names of its contributors 2412115Sdyson * may be used to endorse or promote products derived from this software 2512115Sdyson * without specific prior written permission. 2612115Sdyson * 2712115Sdyson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2812115Sdyson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2912115Sdyson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3012115Sdyson * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3112115Sdyson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3212115Sdyson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3312115Sdyson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3412115Sdyson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3512115Sdyson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3612115Sdyson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3712115Sdyson * SUCH DAMAGE. 3812115Sdyson * 3912115Sdyson * @(#)ext2_subr.c 8.2 (Berkeley) 9/21/93 4012115Sdyson */ 4112115Sdyson 4212115Sdyson#include <sys/param.h> 4312115Sdyson#include <gnu/ext2fs/ext2_fs_sb.h> 4412115Sdyson#include <gnu/ext2fs/fs.h> 4512115Sdyson 4631561Sbde#include <sys/lock.h> 4712115Sdyson#include <sys/systm.h> 4812115Sdyson#include <sys/vnode.h> 4912115Sdyson#include <gnu/ext2fs/ext2_extern.h> 5012115Sdyson#include <sys/buf.h> 5112115Sdyson#include <ufs/ufs/quota.h> 5212115Sdyson#include <ufs/ufs/inode.h> 5312115Sdyson 5433291Sbdestatic void ext2_checkoverlap __P((struct buf *, struct inode *)); 5533291Sbde 5612115Sdyson/* 5712115Sdyson * Return buffer with the contents of block "offset" from the beginning of 5812115Sdyson * directory "ip". If "res" is non-zero, fill it in with a pointer to the 5912115Sdyson * remaining space in the directory. 6012115Sdyson */ 6112115Sdysonint 6230474Sphkext2_blkatoff(vp, offset, res, bpp) 6330474Sphk struct vnode *vp; 6430474Sphk off_t offset; 6530474Sphk char **res; 6630474Sphk struct buf **bpp; 6712115Sdyson{ 6812115Sdyson struct inode *ip; 6912115Sdyson register struct ext2_sb_info *fs; 7012115Sdyson struct buf *bp; 7112115Sdyson daddr_t lbn; 7212115Sdyson int bsize, error; 7312115Sdyson 7430474Sphk ip = VTOI(vp); 7512115Sdyson fs = ip->i_e2fs; 7630474Sphk lbn = lblkno(fs, offset); 7712115Sdyson bsize = blksize(fs, ip, lbn); 7812115Sdyson 7930474Sphk *bpp = NULL; 8030474Sphk if (error = bread(vp, lbn, bsize, NOCRED, &bp)) { 8112115Sdyson brelse(bp); 8212115Sdyson return (error); 8312115Sdyson } 8430474Sphk if (res) 8530474Sphk *res = (char *)bp->b_data + blkoff(fs, offset); 8630474Sphk *bpp = bp; 8712115Sdyson return (0); 8812115Sdyson} 8912115Sdyson 9033291Sbde#ifdef DDB 9133291Sbdestatic void 9212115Sdysonext2_checkoverlap(bp, ip) 9312115Sdyson struct buf *bp; 9412115Sdyson struct inode *ip; 9512115Sdyson{ 9612115Sdyson register struct buf *ebp, *ep; 9712115Sdyson register daddr_t start, last; 9812115Sdyson struct vnode *vp; 9912115Sdyson 10012115Sdyson ebp = &buf[nbuf]; 10112115Sdyson start = bp->b_blkno; 10212115Sdyson last = start + btodb(bp->b_bcount) - 1; 10312115Sdyson for (ep = buf; ep < ebp; ep++) { 10412115Sdyson if (ep == bp || (ep->b_flags & B_INVAL) || 10512115Sdyson ep->b_vp == NULLVP) 10612115Sdyson continue; 10712115Sdyson if (VOP_BMAP(ep->b_vp, (daddr_t)0, &vp, (daddr_t)0, NULL, NULL)) 10812115Sdyson continue; 10912115Sdyson if (vp != ip->i_devvp) 11012115Sdyson continue; 11112115Sdyson /* look for overlap */ 11212115Sdyson if (ep->b_bcount == 0 || ep->b_blkno > last || 11312115Sdyson ep->b_blkno + btodb(ep->b_bcount) <= start) 11412115Sdyson continue; 11512115Sdyson vprint("Disk overlap", vp); 11612115Sdyson (void)printf("\tstart %d, end %d overlap start %d, end %d\n", 11712115Sdyson start, last, ep->b_blkno, 11812115Sdyson ep->b_blkno + btodb(ep->b_bcount) - 1); 11912115Sdyson panic("Disk buffer overlap"); 12012115Sdyson } 12112115Sdyson} 12233291Sbde#endif /* DDB */ 123