/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 19944* The Regents of the University of California. All rights reserved.5*6* This code is derived from software contributed to Berkeley7* by Pace Willisson ([email protected]). The Rock Ridge Extension8* Support code is derived from software contributed to Berkeley9* by Atsushi Murai ([email protected]).10*11* Redistribution and use in source and binary forms, with or without12* modification, are permitted provided that the following conditions13* are met:14* 1. Redistributions of source code must retain the above copyright15* notice, this list of conditions and the following disclaimer.16* 2. Redistributions in binary form must reproduce the above copyright17* notice, this list of conditions and the following disclaimer in the18* documentation and/or other materials provided with the distribution.19* 3. Neither the name of the University nor the names of its contributors20* may be used to endorse or promote products derived from this software21* without specific prior written permission.22*23* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND24* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE27* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL28* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS29* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)30* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY32* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF33* SUCH DAMAGE.34*/3536#include <sys/param.h>37#include <sys/systm.h>38#include <sys/vnode.h>39#include <sys/mount.h>4041#include <fs/cd9660/iso.h>42#include <fs/cd9660/cd9660_node.h>4344/*45* Bmap converts the logical block number of a file to its physical46* block number on the disk. The conversion is done by using the47* logical block number to index into the data block (extent) for the48* file.49*/50int51cd9660_bmap(struct vop_bmap_args *ap)52{53struct iso_node *ip = VTOI(ap->a_vp);54daddr_t lblkno = ap->a_bn;55int bshift;5657/*58* Check for underlying vnode requests and ensure that logical59* to physical mapping is requested.60*/61if (ap->a_bop != NULL)62*ap->a_bop = &ip->i_mnt->im_devvp->v_bufobj;63if (ap->a_bnp == NULL)64return (0);6566/*67* Compute the requested block number68*/69bshift = ip->i_mnt->im_bshift;70*ap->a_bnp = (ip->iso_start + lblkno) << (bshift - DEV_BSHIFT);7172/*73* Determine maximum number of readahead blocks following the74* requested block.75*/76if (ap->a_runp) {77int nblk;7879nblk = (ip->i_size >> bshift) - (lblkno + 1);80if (nblk <= 0)81*ap->a_runp = 0;82else if (nblk >= (MAXBSIZE >> bshift))83*ap->a_runp = (MAXBSIZE >> bshift) - 1;84else85*ap->a_runp = nblk;86}8788if (ap->a_runb) {89*ap->a_runb = 0;90}9192return 0;93}949596