]>
git.saurik.com Git - apple/xnu.git/blob - bsd/isofs/cd9660/cd9660_node.c
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 /* $NetBSD: cd9660_node.c,v 1.13 1994/12/24 15:30:07 cgd Exp $ */
26 * Copyright (c) 1982, 1986, 1989, 1994
27 * The Regents of the University of California. All rights reserved.
29 * This code is derived from software contributed to Berkeley
30 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
31 * Support code is derived from software contributed to Berkeley
32 * by Atsushi Murai (amurai@spec.co.jp).
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * @(#)cd9660_node.c 8.5 (Berkeley) 12/5/94
67 * 22-Jan-98 radar 1669467 - ISO 9660 CD support - jwc
68 * 17-Feb-98 radar 1669467 - changed lock protocols to use the lock manager - chw
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/mount.h>
78 #include <sys/vnode.h>
79 #include <sys/kernel.h>
80 #include <sys/malloc.h>
83 #include <sys/namei.h>
85 #include <isofs/cd9660/iso.h>
86 #include <isofs/cd9660/cd9660_node.h>
87 #include <isofs/cd9660/iso_rrip.h>
88 #include <isofs/cd9660/cd9660_mount.h>
91 * Structures associated with iso_node caching.
93 struct iso_node
**isohashtbl
;
95 #define INOHASH(device, inum) (((device) + ((inum)>>12)) & isohash)
98 struct iso_node
**idvhashtbl
;
100 #define DNOHASH(device, inum) (((device) + ((inum)>>12)) & idvhash)
103 /* defined in bsd/vfs/vfs_subr.c */
104 extern int prtactive
; /* 1 => print out reclaim of active vnodes */
106 extern u_char isonullname
[];
108 * Initialize hash links for inodes and dnodes.
111 cd9660_init(__unused
struct vfsconf
*cp
)
114 isohashtbl
= hashinit(desiredvnodes
, M_ISOFSMNT
, &isohash
);
116 idvhashtbl
= hashinit(desiredvnodes
/ 8, M_ISOFSMNT
, &idvhash
);
123 * Enter a new node into the device hash list
126 iso_dmap(dev_t device
, ino_t inum
, int create
)
128 register struct iso_dnode
**dpp
, *dp
, *dq
;
130 dpp
= &idvhashtbl
[DNOHASH(device
, inum
)];
131 for (dp
= *dpp
;; dp
= dp
->d_next
) {
134 if (inum
== dp
->i_number
&& device
== dp
->i_dev
)
140 MALLOC(dp
, struct iso_dnode
*, sizeof(struct iso_dnode
), M_CACHE
,
146 dq
->d_prev
= dp
->d_next
;
155 iso_dunmap(dev_t device
)
157 struct iso_dnode
**dpp
, *dp
, *dq
;
159 for (dpp
= idvhashtbl
; dpp
<= idvhashtbl
+ idvhash
; dpp
++) {
160 for (dp
= *dpp
; dp
!= NULL
; dp
= dq
)
162 if (device
== dp
->i_dev
) {
164 dq
->d_prev
= dp
->d_prev
;
174 * Use the device/inum pair to find the incore inode, and return a pointer
175 * to it. If it is in core, but locked, wait for it.
178 cd9660_ihashget(dev_t device
, ino_t inum
, struct proc
*p
)
180 register struct iso_node
*ip
;
185 for (ip
= isohashtbl
[INOHASH(device
, inum
)]; ip
; ip
= ip
->i_next
) {
186 if (inum
== ip
->i_number
&& device
== ip
->i_dev
) {
188 if (ISSET(ip
->i_flag
, ISO_INALLOC
)) {
190 * inode is being created... wait for it
191 * to be ready for consumption
193 SET(ip
->i_flag
, ISO_INWALLOC
);
194 tsleep((caddr_t
)ip
, PINOD
, "cd9960_ihashget", 0);
199 * the vid needs to be grabbed before we drop
200 * lock protecting the hash
205 * we currently depend on running under the FS funnel
206 * when we do proper locking and advertise ourselves
207 * as thread safe, we'll need a lock to protect the
208 * hash lookup... this is where we would drop it
210 if (vnode_getwithvid(vp
, vid
)) {
212 * If vnode is being reclaimed, or has
213 * already changed identity, no need to wait
224 * Insert the inode into the hash table, and return it locked.
227 cd9660_ihashins(struct iso_node
*ip
)
229 struct iso_node
**ipp
, *iq
;
231 /* lock the inode, then put it on the appropriate hash list */
233 ipp
= &isohashtbl
[INOHASH(ip
->i_dev
, ip
->i_number
)];
235 iq
->i_prev
= &ip
->i_next
;
242 * Remove the inode from the hash table.
245 cd9660_ihashrem(register struct iso_node
*ip
)
247 register struct iso_node
*iq
;
249 if ((iq
= ip
->i_next
))
250 iq
->i_prev
= ip
->i_prev
;
252 #if 1 /* was ifdef DIAGNOSTIC */
259 * Last reference to an inode... if we're done with
260 * it, go ahead and recycle it for other use
263 cd9660_inactive(struct vnop_inactive_args
*ap
)
265 vnode_t vp
= ap
->a_vp
;
266 struct iso_node
*ip
= VTOI(vp
);
269 * If we are done with the inode, reclaim it
270 * so that it can be reused immediately.
272 if (ip
->inode
.iso_mode
== 0)
279 * Reclaim an inode so that it can be used for other purposes.
282 cd9660_reclaim(struct vnop_reclaim_args
*ap
)
284 vnode_t vp
= ap
->a_vp
;
285 struct iso_node
*ip
= VTOI(vp
);
287 vnode_removefsref(vp
);
289 * Remove the inode from its hash chain.
294 vnode_t devvp
= ip
->i_devvp
;
298 vnode_clearfsnode(vp
);
300 if (ip
->i_namep
!= isonullname
)
301 FREE(ip
->i_namep
, M_TEMP
);
302 if (ip
->i_riff
!= NULL
)
303 FREE(ip
->i_riff
, M_TEMP
);
304 FREE_ZONE(ip
, sizeof(struct iso_node
), M_ISOFSNODE
);
313 cd9660_defattr(struct iso_directory_record
*isodir
, struct iso_node
*inop
,
316 struct buf
*bp2
= NULL
;
318 struct iso_extended_attributes
*ap
= NULL
;
321 if ( isonum_711(isodir
->flags
) & directoryBit
) {
322 inop
->inode
.iso_mode
= S_IFDIR
;
324 * If we return 2, fts() will assume there are no subdirectories
325 * (just links for the path and .), so instead we return 1.
327 inop
->inode
.iso_links
= 1;
329 inop
->inode
.iso_mode
= S_IFREG
;
330 inop
->inode
.iso_links
= 1;
333 && ((imp
= inop
->i_mnt
)->im_flags
& ISOFSMNT_EXTATT
)
334 && (off
= isonum_711(isodir
->ext_attr_length
))) {
335 cd9660_blkatoff(ITOV(inop
), (off_t
)-(off
<< imp
->im_bshift
), NULL
, &bp2
);
339 ap
= (struct iso_extended_attributes
*)buf_dataptr(bp
);
341 if (isonum_711(ap
->version
) == 1) {
342 if (!(ap
->perm
[0]&0x40))
343 inop
->inode
.iso_mode
|= VEXEC
>> 6;
344 if (!(ap
->perm
[0]&0x10))
345 inop
->inode
.iso_mode
|= VREAD
>> 6;
346 if (!(ap
->perm
[0]&4))
347 inop
->inode
.iso_mode
|= VEXEC
>> 3;
348 if (!(ap
->perm
[0]&1))
349 inop
->inode
.iso_mode
|= VREAD
>> 3;
350 if (!(ap
->perm
[1]&0x40))
351 inop
->inode
.iso_mode
|= VEXEC
;
352 if (!(ap
->perm
[1]&0x10))
353 inop
->inode
.iso_mode
|= VREAD
;
354 inop
->inode
.iso_uid
= isonum_723(ap
->owner
); /* what about 0? */
355 inop
->inode
.iso_gid
= isonum_723(ap
->group
); /* what about 0? */
360 inop
->inode
.iso_mode
|= VREAD
|VWRITE
|VEXEC
|(VREAD
|VEXEC
)>>3|(VREAD
|VEXEC
)>>6;
361 inop
->inode
.iso_uid
= ISO_UNKNOWNUID
;
362 inop
->inode
.iso_gid
= ISO_UNKNOWNGID
;
372 cd9660_deftstamp(struct iso_directory_record
*isodir
, struct iso_node
*inop
,
375 struct buf
*bp2
= NULL
;
377 struct iso_extended_attributes
*ap
= NULL
;
381 && ((imp
= inop
->i_mnt
)->im_flags
& ISOFSMNT_EXTATT
)
382 && (off
= isonum_711(isodir
->ext_attr_length
)))
384 cd9660_blkatoff(ITOV(inop
), (off_t
)-(off
<< imp
->im_bshift
), NULL
, &bp2
);
388 ap
= (struct iso_extended_attributes
*)buf_dataptr(bp
);
390 if (isonum_711(ap
->version
) == 1) {
391 if (!cd9660_tstamp_conv17(ap
->ftime
,&inop
->inode
.iso_atime
))
392 cd9660_tstamp_conv17(ap
->ctime
,&inop
->inode
.iso_atime
);
393 if (!cd9660_tstamp_conv17(ap
->ctime
,&inop
->inode
.iso_ctime
))
394 inop
->inode
.iso_ctime
= inop
->inode
.iso_atime
;
395 if (!cd9660_tstamp_conv17(ap
->mtime
,&inop
->inode
.iso_mtime
))
396 inop
->inode
.iso_mtime
= inop
->inode
.iso_ctime
;
401 cd9660_tstamp_conv7(isodir
->date
,&inop
->inode
.iso_ctime
);
402 inop
->inode
.iso_atime
= inop
->inode
.iso_ctime
;
403 inop
->inode
.iso_mtime
= inop
->inode
.iso_ctime
;
410 cd9660_tstamp_conv7(u_char
*pi
, struct timespec
*pu
)
413 int y
, m
, d
, hour
, minute
, second
, mytz
;
429 /* computes day number relative to Sept. 19th,1989 */
430 /* don't even *THINK* about changing formula. It works! */
431 days
= 367*(y
-1980)-7*(y
+(m
+9)/12)/4-3*((y
+(m
-9)/7)/100+1)/4+275*m
/9+d
-100;
434 * Changed :-) to make it relative to Jan. 1st, 1970
435 * and to disambiguate negative division
437 days
= 367*(y
-1960)-7*(y
+(m
+9)/12)/4-3*((y
+(m
+9)/12-1)/100+1)/4+275*m
/9+d
-239;
439 crtime
= ((((days
* 24) + hour
) * 60 + minute
) * 60) + second
;
441 /* timezone offset is unreliable on some disks */
442 if (-48 <= mytz
&& mytz
<= 52)
443 crtime
-= mytz
* 15 * 60;
451 cd9660_chars2ui(u_char
*begin
, int len
)
455 for (rc
= 0; --len
>= 0;) {
457 rc
+= *begin
++ - '0';
463 cd9660_tstamp_conv17(u_char
*pi
, struct timespec
*pu
)
467 /* year:"0001"-"9999" -> -1900 */
468 buf
[0] = cd9660_chars2ui(pi
,4) - 1900;
470 /* month: " 1"-"12" -> 1 - 12 */
471 buf
[1] = cd9660_chars2ui(pi
+ 4,2);
473 /* day: " 1"-"31" -> 1 - 31 */
474 buf
[2] = cd9660_chars2ui(pi
+ 6,2);
476 /* hour: " 0"-"23" -> 0 - 23 */
477 buf
[3] = cd9660_chars2ui(pi
+ 8,2);
479 /* minute:" 0"-"59" -> 0 - 59 */
480 buf
[4] = cd9660_chars2ui(pi
+ 10,2);
482 /* second:" 0"-"59" -> 0 - 59 */
483 buf
[5] = cd9660_chars2ui(pi
+ 12,2);
485 /* difference of GMT */
488 return cd9660_tstamp_conv7(buf
,pu
);
492 isodirino(struct iso_directory_record
*isodir
, struct iso_mnt
*imp
)
496 ino
= (isonum_733(isodir
->extent
) + isonum_711(isodir
->ext_attr_length
))