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 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)cd9660_bmap.c 8.3 (Berkeley) 1/23/94 35 * $FreeBSD: src/sys/isofs/cd9660/cd9660_bmap.c,v 1.8 1999/08/28 00:46:06 peter Exp $ 36 */ 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/vnode.h> 41 #include <sys/mount.h> 42 43 #include "iso.h" 44 #include "cd9660_node.h" 45 46 /* 47 * Bmap converts the logical block number of a file to its physical block 48 * number on the disk. The conversion is done by using the logical block 49 * number to index into the data block (extent) for the file. 50 * 51 * cd9660_bmap(struct vnode *a_vp, off_t a_loffset, 52 * off_t *a_doffsetp, int *a_runp, int *a_runb) 53 */ 54 int 55 cd9660_bmap(struct vop_bmap_args *ap) 56 { 57 struct iso_node *ip = VTOI(ap->a_vp); 58 off_t loffset = ap->a_loffset; 59 int bshift; 60 int bsize; 61 62 /* 63 * Check for underlying vnode requests and ensure that logical 64 * to physical mapping is requested. 65 */ 66 if (ap->a_doffsetp == NULL) 67 return (0); 68 69 /* 70 * Compute the requested block number 71 */ 72 bshift = ip->i_mnt->im_bshift; 73 bsize = 1 << bshift; 74 *ap->a_doffsetp = loffset + ((off_t)ip->iso_start << bshift); 75 76 KKASSERT((loffset & (bsize - 1)) == 0); 77 78 /* 79 * Determine maximum number of readahead bytes following the 80 * requested offset. Align the result to the nearest block 81 * boundary. Do not count any non-full blocks(?) 82 */ 83 if (ap->a_runp) { 84 off_t nbytes; 85 86 nbytes = (off_t)ip->i_size - loffset; 87 if (nbytes < bsize) 88 *ap->a_runp = 0; 89 else if (nbytes > MAXBSIZE) 90 *ap->a_runp = MAXBSIZE; 91 else 92 *ap->a_runp = (int)nbytes & ~(bsize - 1); 93 } 94 95 if (ap->a_runb) { 96 *ap->a_runb = 0; 97 } 98 99 return 0; 100 } 101