/* * Copyright (c) 1991 Regents of the University of California. * All rights reserved. * * %sccs.include.redist.c% * * @(#)lfs_subr.c 7.8 (Berkeley) 01/18/92 */ #include #include #include #include #include #include #include #include /* * Return buffer with the contents of block "offset" from the beginning of * directory "ip". If "res" is non-zero, fill it in with a pointer to the * remaining space in the directory. */ int lfs_blkatoff(vp, offset, res, bpp) struct vnode *vp; off_t offset; char **res; struct buf **bpp; { register struct lfs *fs; struct inode *ip; struct buf *bp; daddr_t lbn; int bsize, error; ip = VTOI(vp); fs = ip->i_lfs; lbn = lblkno(fs, offset); bsize = blksize(fs); *bpp = NULL; if (error = bread(vp, lbn, bsize, NOCRED, &bp)) { brelse(bp); return (error); } if (res) *res = bp->b_un.b_addr + blkoff(fs, offset); *bpp = bp; return (0); } /* Search a block for a specific dinode. */ DINODE * lfs_ifind(fs, ino, page) struct lfs *fs; ino_t ino; void *page; { register DINODE *dip; register int cnt; #ifdef VERBOSE printf("lfs_ifind: inode %d\n", ino); #endif dip = page; for (cnt = INOPB(fs); cnt--; ++dip) if (dip->di_inum == ino) return (dip); panic("lfs_ifind: dinode %u not found", ino); /* NOTREACHED */ }