]>
git.saurik.com Git - apple/xnu.git/blob - bsd/isofs/cd9660/cd9660_bmap.c
b0d7d46017cc7775e28b910532bfda5b02f5fffe
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* $NetBSD: cd9660_bmap.c,v 1.5 1994/12/13 22:33:12 mycroft Exp $ */
29 * The Regents of the University of California. All rights reserved.
31 * This code is derived from software contributed to Berkeley
32 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
33 * Support code is derived from software contributed to Berkeley
34 * by Atsushi Murai (amurai@spec.co.jp).
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * @(#)cd9660_bmap.c 8.4 (Berkeley) 12/5/94
67 #include <sys/param.h>
68 #include <sys/vnode.h>
69 #include <sys/mount.h>
70 #include <sys/namei.h>
74 #include <isofs/cd9660/iso.h>
75 #include <isofs/cd9660/cd9660_node.h>
78 * Bmap converts the logical block number of a file to its physical block
79 * number on the disk. The conversion is done by using the logical block
80 * number to index into the data block (extent) for the file.
84 struct vop_bmap_args
/* {
92 struct iso_node
*ip
= VTOI(ap
->a_vp
);
93 daddr_t lblkno
= ap
->a_bn
;
97 * Check for underlying vnode requests and ensure that logical
98 * to physical mapping is requested.
100 if (ap
->a_vpp
!= NULL
)
101 *ap
->a_vpp
= ip
->i_devvp
;
102 if (ap
->a_bnp
== NULL
)
106 * Compute the requested block number
108 bshift
= ip
->i_mnt
->im_bshift
;
109 *ap
->a_bnp
= (ip
->iso_start
+ lblkno
);
112 * Determine maximum number of readahead blocks following the
118 nblk
= (ip
->i_size
>> bshift
) - (lblkno
+ 1);
121 else if (nblk
>= (MAXBSIZE
>> bshift
))
122 *ap
->a_runp
= (MAXBSIZE
>> bshift
) - 1;
130 /* blktooff converts a logical block number to a file offset */
133 struct vop_blktooff_args
/* {
139 register struct iso_node
*ip
;
140 register struct iso_mnt
*imp
;
142 if (ap
->a_vp
== NULL
)
148 *ap
->a_offset
= (off_t
)lblktosize(imp
, ap
->a_lblkno
);
152 /* offtoblk converts a file offset to a logical block number */
155 struct vop_offtoblk_args
/* {
161 register struct iso_node
*ip
;
162 register struct iso_mnt
*imp
;
164 if (ap
->a_vp
== NULL
)
170 *ap
->a_lblkno
= (daddr_t
)lblkno(imp
, ap
->a_offset
);
176 struct vop_cmap_args
/* {
185 struct iso_node
*ip
= VTOI(ap
->a_vp
);
187 int devBlockSize
= 0;
190 * Check for underlying vnode requests and ensure that logical
191 * to physical mapping is requested.
193 if (ap
->a_bpn
== NULL
)
196 VOP_DEVBLOCKSIZE(ip
->i_devvp
, &devBlockSize
);
198 *ap
->a_bpn
= (daddr_t
)(ip
->iso_start
+ lblkno(ip
->i_mnt
, ap
->a_foffset
));
201 * Determine maximum number of contiguous bytes following the
205 if (ip
->i_size
> ap
->a_foffset
)
206 cbytes
= ip
->i_size
- ap
->a_foffset
;
210 cbytes
= (cbytes
+ (devBlockSize
- 1)) & ~(devBlockSize
- 1);
212 *ap
->a_run
= MIN(cbytes
, ap
->a_size
);
216 *(int *)ap
->a_poff
= (long)ap
->a_foffset
& (devBlockSize
- 1);