1 /*- 2 * Copyright (c) 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley 6 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension 7 * Support code is derived from software contributed to Berkeley 8 * by Atsushi Murai (amurai@spec.co.jp). 9 * 10 * %sccs.include.redist.c% 11 * 12 * @(#)cd9660_bmap.c 8.3 (Berkeley) 01/23/94 13 */ 14 15 #include <sys/param.h> 16 #include <sys/namei.h> 17 #include <sys/buf.h> 18 #include <sys/file.h> 19 #include <sys/vnode.h> 20 #include <sys/mount.h> 21 22 #include <isofs/cd9660/iso.h> 23 #include <isofs/cd9660/cd9660_node.h> 24 25 /* 26 * Bmap converts a the logical block number of a file to its physical block 27 * number on the disk. The conversion is done by using the logical block 28 * number to index into the data block (extent) for the file. 29 */ 30 int 31 cd9660_bmap(ap) 32 struct vop_bmap_args /* { 33 struct vnode *a_vp; 34 daddr_t a_bn; 35 struct vnode **a_vpp; 36 daddr_t *a_bnp; 37 int *a_runp; 38 } */ *ap; 39 { 40 struct iso_node *ip = VTOI(ap->a_vp); 41 daddr_t lblkno = ap->a_bn; 42 long bsize; 43 44 /* 45 * Check for underlying vnode requests and ensure that logical 46 * to physical mapping is requested. 47 */ 48 if (ap->a_vpp != NULL) 49 *ap->a_vpp = ip->i_devvp; 50 if (ap->a_bnp == NULL) 51 return (0); 52 53 /* 54 * Compute the requested block number 55 */ 56 bsize = ip->i_mnt->logical_block_size; 57 *ap->a_bnp = (ip->iso_start + lblkno) * btodb(bsize); 58 59 /* 60 * Determine maximum number of readahead blocks following the 61 * requested block. 62 */ 63 if (ap->a_runp) { 64 int nblk; 65 66 nblk = (ip->i_size - (lblkno + 1) * bsize) / bsize; 67 if (nblk <= 0) 68 *ap->a_runp = 0; 69 else if (nblk >= MAXBSIZE/bsize) 70 *ap->a_runp = MAXBSIZE/bsize - 1; 71 else 72 *ap->a_runp = nblk; 73 } 74 75 return 0; 76 } 77