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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)cd9660_bmap.c 8.3 (Berkeley) 1/23/94
39 * $FreeBSD: head/sys/fs/cd9660/cd9660_bmap.c 96009 2002-05-04 02:37:00Z jeff $
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/vnode.h>
45#include <sys/mount.h>
46
47#include <isofs/cd9660/iso.h>
48#include <isofs/cd9660/cd9660_node.h>
49
50/*
51 * Bmap converts a the logical block number of a file to its physical block
52 * number on the disk. The conversion is done by using the logical block
53 * number to index into the data block (extent) for the file.
54 */
55int
56cd9660_bmap(ap)
57 struct vop_bmap_args /* {
58 struct vnode *a_vp;
59 daddr_t a_bn;
60 struct vnode **a_vpp;
61 daddr_t *a_bnp;
62 int *a_runp;
63 int *a_runb;
64 } */ *ap;
65{
66 struct iso_node *ip = VTOI(ap->a_vp);
67 daddr_t lblkno = ap->a_bn;
68 int bshift;
69
70 /*
71 * Check for underlying vnode requests and ensure that logical
72 * to physical mapping is requested.
73 */
74 if (ap->a_vpp != NULL)
75 *ap->a_vpp = ip->i_devvp;
76 if (ap->a_bnp == NULL)
77 return (0);
78
79 /*
80 * Compute the requested block number
81 */
82 bshift = ip->i_mnt->im_bshift;
83 *ap->a_bnp = (ip->iso_start + lblkno) << (bshift - DEV_BSHIFT);
84
85 /*
86 * Determine maximum number of readahead blocks following the
87 * requested block.
88 */
89 if (ap->a_runp) {
90 int nblk;
91
92 nblk = (ip->i_size >> bshift) - (lblkno + 1);
93 if (nblk <= 0)
94 *ap->a_runp = 0;
95 else if (nblk >= (MAXBSIZE >> bshift))
96 *ap->a_runp = (MAXBSIZE >> bshift) - 1;
97 else
98 *ap->a_runp = nblk;
99 }
100
101 if (ap->a_runb) {
102 *ap->a_runb = 0;
103 }
104
105 return 0;
106}
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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)cd9660_bmap.c 8.3 (Berkeley) 1/23/94
39 * $FreeBSD: head/sys/fs/cd9660/cd9660_bmap.c 96009 2002-05-04 02:37:00Z jeff $
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/vnode.h>
45#include <sys/mount.h>
46
47#include <isofs/cd9660/iso.h>
48#include <isofs/cd9660/cd9660_node.h>
49
50/*
51 * Bmap converts a the logical block number of a file to its physical block
52 * number on the disk. The conversion is done by using the logical block
53 * number to index into the data block (extent) for the file.
54 */
55int
56cd9660_bmap(ap)
57 struct vop_bmap_args /* {
58 struct vnode *a_vp;
59 daddr_t a_bn;
60 struct vnode **a_vpp;
61 daddr_t *a_bnp;
62 int *a_runp;
63 int *a_runb;
64 } */ *ap;
65{
66 struct iso_node *ip = VTOI(ap->a_vp);
67 daddr_t lblkno = ap->a_bn;
68 int bshift;
69
70 /*
71 * Check for underlying vnode requests and ensure that logical
72 * to physical mapping is requested.
73 */
74 if (ap->a_vpp != NULL)
75 *ap->a_vpp = ip->i_devvp;
76 if (ap->a_bnp == NULL)
77 return (0);
78
79 /*
80 * Compute the requested block number
81 */
82 bshift = ip->i_mnt->im_bshift;
83 *ap->a_bnp = (ip->iso_start + lblkno) << (bshift - DEV_BSHIFT);
84
85 /*
86 * Determine maximum number of readahead blocks following the
87 * requested block.
88 */
89 if (ap->a_runp) {
90 int nblk;
91
92 nblk = (ip->i_size >> bshift) - (lblkno + 1);
93 if (nblk <= 0)
94 *ap->a_runp = 0;
95 else if (nblk >= (MAXBSIZE >> bshift))
96 *ap->a_runp = (MAXBSIZE >> bshift) - 1;
97 else
98 *ap->a_runp = nblk;
99 }
100
101 if (ap->a_runb) {
102 *ap->a_runb = 0;
103 }
104
105 return 0;
106}