xref: /csrg-svn/sys/isofs/cd9660/cd9660_bmap.c (revision 68043)
165789Smckusick /*-
265789Smckusick  * Copyright (c) 1994
365789Smckusick  *	The Regents of the University of California.  All rights reserved.
465789Smckusick  *
565789Smckusick  * This code is derived from software contributed to Berkeley
665789Smckusick  * by Pace Willisson (pace@blitz.com).  The Rock Ridge Extension
765789Smckusick  * Support code is derived from software contributed to Berkeley
865789Smckusick  * by Atsushi Murai (amurai@spec.co.jp).
965789Smckusick  *
1065789Smckusick  * %sccs.include.redist.c%
1165789Smckusick  *
12*68043Smckusick  *	@(#)cd9660_bmap.c	8.4 (Berkeley) 12/05/94
1365789Smckusick  */
1465789Smckusick 
1565789Smckusick #include <sys/param.h>
1665789Smckusick #include <sys/namei.h>
1765789Smckusick #include <sys/buf.h>
1865789Smckusick #include <sys/file.h>
1965789Smckusick #include <sys/vnode.h>
2065789Smckusick #include <sys/mount.h>
2165789Smckusick 
2265789Smckusick #include <isofs/cd9660/iso.h>
2365855Smckusick #include <isofs/cd9660/cd9660_node.h>
2465789Smckusick 
2565789Smckusick /*
2665789Smckusick  * Bmap converts a the logical block number of a file to its physical block
2765789Smckusick  * number on the disk. The conversion is done by using the logical block
2865789Smckusick  * number to index into the data block (extent) for the file.
2965789Smckusick  */
3065789Smckusick int
cd9660_bmap(ap)3165855Smckusick cd9660_bmap(ap)
3265789Smckusick 	struct vop_bmap_args /* {
3365789Smckusick 		struct vnode *a_vp;
3465789Smckusick 		daddr_t  a_bn;
3565789Smckusick 		struct vnode **a_vpp;
3665789Smckusick 		daddr_t *a_bnp;
3765789Smckusick 		int *a_runp;
3865789Smckusick 	} */ *ap;
3965789Smckusick {
4065789Smckusick 	struct iso_node *ip = VTOI(ap->a_vp);
4165789Smckusick 	daddr_t lblkno = ap->a_bn;
42*68043Smckusick 	int bshift;
4365789Smckusick 
4465789Smckusick 	/*
4565789Smckusick 	 * Check for underlying vnode requests and ensure that logical
4665789Smckusick 	 * to physical mapping is requested.
4765789Smckusick 	 */
4865789Smckusick 	if (ap->a_vpp != NULL)
4965789Smckusick 		*ap->a_vpp = ip->i_devvp;
5065789Smckusick 	if (ap->a_bnp == NULL)
5165789Smckusick 		return (0);
5265789Smckusick 
5365789Smckusick 	/*
5465789Smckusick 	 * Compute the requested block number
5565789Smckusick 	 */
56*68043Smckusick 	bshift = ip->i_mnt->im_bshift;
57*68043Smckusick 	*ap->a_bnp = (ip->iso_start + lblkno) << (bshift - DEV_BSHIFT);
5865789Smckusick 
5965789Smckusick 	/*
6065789Smckusick 	 * Determine maximum number of readahead blocks following the
6165789Smckusick 	 * requested block.
6265789Smckusick 	 */
6365789Smckusick 	if (ap->a_runp) {
6465789Smckusick 		int nblk;
6565789Smckusick 
66*68043Smckusick 		nblk = (ip->i_size >> bshift) - (lblkno + 1);
6765789Smckusick 		if (nblk <= 0)
6865789Smckusick 			*ap->a_runp = 0;
69*68043Smckusick 		else if (nblk >= (MAXBSIZE >> bshift))
70*68043Smckusick 			*ap->a_runp = (MAXBSIZE >> bshift) - 1;
7165789Smckusick 		else
7265789Smckusick 			*ap->a_runp = nblk;
7365789Smckusick 	}
7465789Smckusick 
75*68043Smckusick 	return (0);
7665789Smckusick }
77