xref: /csrg-svn/sys/ufs/lfs/lfs_subr.c (revision 53592)
151500Sbostic /*
251503Sbostic  * Copyright (c) 1991 Regents of the University of California.
351500Sbostic  * All rights reserved.
451500Sbostic  *
551500Sbostic  * %sccs.include.redist.c%
651500Sbostic  *
7*53592Sheideman  *	@(#)lfs_subr.c	7.11 (Berkeley) 05/15/92
851500Sbostic  */
951500Sbostic 
1051500Sbostic #include <sys/param.h>
1151500Sbostic #include <sys/namei.h>
1251500Sbostic #include <sys/vnode.h>
1351500Sbostic #include <sys/buf.h>
1451500Sbostic 
1551500Sbostic #include <ufs/ufs/quota.h>
1651500Sbostic #include <ufs/ufs/inode.h>
1751500Sbostic 
1851500Sbostic #include <ufs/lfs/lfs.h>
1951500Sbostic #include <ufs/lfs/lfs_extern.h>
2051500Sbostic 
2151500Sbostic /*
2251500Sbostic  * Return buffer with the contents of block "offset" from the beginning of
2351500Sbostic  * directory "ip".  If "res" is non-zero, fill it in with a pointer to the
2451500Sbostic  * remaining space in the directory.
2551500Sbostic  */
2651500Sbostic int
2753530Sheideman lfs_blkatoff (ap)
2853530Sheideman 	struct vop_blkatoff_args *ap;
2951500Sbostic {
3051500Sbostic 	register struct lfs *fs;
3151557Smckusick 	struct inode *ip;
3251500Sbostic 	struct buf *bp;
3351500Sbostic 	daddr_t lbn;
3451500Sbostic 	int bsize, error;
3551500Sbostic 
36*53592Sheideman 	ip = VTOI(ap->a_vp);
3751500Sbostic 	fs = ip->i_lfs;
38*53592Sheideman 	lbn = lblkno(fs, ap->a_offset);
3951500Sbostic 	bsize = blksize(fs);
4051500Sbostic 
41*53592Sheideman 	*ap->a_bpp = NULL;
42*53592Sheideman 	if (error = bread(ap->a_vp, lbn, bsize, NOCRED, &bp)) {
4351500Sbostic 		brelse(bp);
4451500Sbostic 		return (error);
4551500Sbostic 	}
46*53592Sheideman 	if (ap->a_res)
47*53592Sheideman 		*ap->a_res = bp->b_un.b_addr + blkoff(fs, ap->a_offset);
48*53592Sheideman 	*ap->a_bpp = bp;
4951500Sbostic 	return (0);
5051500Sbostic }
51