]>
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_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* $NetBSD: cd9660_node.c,v 1.13 1994/12/24 15:30:07 cgd Exp $ */
33 * Copyright (c) 1982, 1986, 1989, 1994
34 * The Regents of the University of California. All rights reserved.
36 * This code is derived from software contributed to Berkeley
37 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
38 * Support code is derived from software contributed to Berkeley
39 * by Atsushi Murai (amurai@spec.co.jp).
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * This product includes software developed by the University of
52 * California, Berkeley and its contributors.
53 * 4. Neither the name of the University nor the names of its contributors
54 * may be used to endorse or promote products derived from this software
55 * without specific prior written permission.
57 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * @(#)cd9660_node.c 8.5 (Berkeley) 12/5/94
74 * 22-Jan-98 radar 1669467 - ISO 9660 CD support - jwc
75 * 17-Feb-98 radar 1669467 - changed lock protocols to use the lock manager - chw
79 #include <sys/param.h>
80 #include <sys/systm.h>
81 #include <sys/mount.h>
85 #include <sys/vnode.h>
86 #include <sys/kernel.h>
87 #include <sys/malloc.h>
90 #include <sys/namei.h>
92 #include <isofs/cd9660/iso.h>
93 #include <isofs/cd9660/cd9660_node.h>
94 #include <isofs/cd9660/iso_rrip.h>
95 #include <isofs/cd9660/cd9660_mount.h>
98 * Structures associated with iso_node caching.
100 struct iso_node
**isohashtbl
;
102 #define INOHASH(device, inum) (((device) + ((inum)>>12)) & isohash)
105 struct iso_node
**idvhashtbl
;
107 #define DNOHASH(device, inum) (((device) + ((inum)>>12)) & idvhash)
110 /* defined in bsd/vfs/vfs_subr.c */
111 extern int prtactive
; /* 1 => print out reclaim of active vnodes */
113 extern u_char isonullname
[];
115 * Initialize hash links for inodes and dnodes.
118 cd9660_init(__unused
struct vfsconf
*cp
)
121 isohashtbl
= hashinit(desiredvnodes
, M_ISOFSMNT
, &isohash
);
123 idvhashtbl
= hashinit(desiredvnodes
/ 8, M_ISOFSMNT
, &idvhash
);
130 * Enter a new node into the device hash list
133 iso_dmap(dev_t device
, ino_t inum
, int create
)
135 register struct iso_dnode
**dpp
, *dp
, *dq
;
137 dpp
= &idvhashtbl
[DNOHASH(device
, inum
)];
138 for (dp
= *dpp
;; dp
= dp
->d_next
) {
141 if (inum
== dp
->i_number
&& device
== dp
->i_dev
)
147 MALLOC(dp
, struct iso_dnode
*, sizeof(struct iso_dnode
), M_CACHE
,
153 dq
->d_prev
= dp
->d_next
;
162 iso_dunmap(dev_t device
)
164 struct iso_dnode
**dpp
, *dp
, *dq
;
166 for (dpp
= idvhashtbl
; dpp
<= idvhashtbl
+ idvhash
; dpp
++) {
167 for (dp
= *dpp
; dp
!= NULL
; dp
= dq
)
169 if (device
== dp
->i_dev
) {
171 dq
->d_prev
= dp
->d_prev
;
181 * Use the device/inum pair to find the incore inode, and return a pointer
182 * to it. If it is in core, but locked, wait for it.
185 cd9660_ihashget(dev_t device
, ino_t inum
, struct proc
*p
)
187 register struct iso_node
*ip
;
192 for (ip
= isohashtbl
[INOHASH(device
, inum
)]; ip
; ip
= ip
->i_next
) {
193 if (inum
== ip
->i_number
&& device
== ip
->i_dev
) {
195 if (ISSET(ip
->i_flag
, ISO_INALLOC
)) {
197 * inode is being created... wait for it
198 * to be ready for consumption
200 SET(ip
->i_flag
, ISO_INWALLOC
);
201 tsleep((caddr_t
)ip
, PINOD
, "cd9960_ihashget", 0);
206 * the vid needs to be grabbed before we drop
207 * lock protecting the hash
212 * we currently depend on running under the FS funnel
213 * when we do proper locking and advertise ourselves
214 * as thread safe, we'll need a lock to protect the
215 * hash lookup... this is where we would drop it
217 if (vnode_getwithvid(vp
, vid
)) {
219 * If vnode is being reclaimed, or has
220 * already changed identity, no need to wait
231 * Insert the inode into the hash table, and return it locked.
234 cd9660_ihashins(struct iso_node
*ip
)
236 struct iso_node
**ipp
, *iq
;
238 /* lock the inode, then put it on the appropriate hash list */
240 ipp
= &isohashtbl
[INOHASH(ip
->i_dev
, ip
->i_number
)];
242 iq
->i_prev
= &ip
->i_next
;
249 * Remove the inode from the hash table.
252 cd9660_ihashrem(register struct iso_node
*ip
)
254 register struct iso_node
*iq
;
256 if ((iq
= ip
->i_next
))
257 iq
->i_prev
= ip
->i_prev
;
259 #if 1 /* was ifdef DIAGNOSTIC */
266 * Last reference to an inode... if we're done with
267 * it, go ahead and recycle it for other use
270 cd9660_inactive(struct vnop_inactive_args
*ap
)
272 vnode_t vp
= ap
->a_vp
;
273 struct iso_node
*ip
= VTOI(vp
);
276 * If we are done with the inode, reclaim it
277 * so that it can be reused immediately.
279 if (ip
->inode
.iso_mode
== 0)
286 * Reclaim an inode so that it can be used for other purposes.
289 cd9660_reclaim(struct vnop_reclaim_args
*ap
)
291 vnode_t vp
= ap
->a_vp
;
292 struct iso_node
*ip
= VTOI(vp
);
294 vnode_removefsref(vp
);
296 * Remove the inode from its hash chain.
301 vnode_t devvp
= ip
->i_devvp
;
305 vnode_clearfsnode(vp
);
307 if (ip
->i_namep
!= isonullname
)
308 FREE(ip
->i_namep
, M_TEMP
);
309 if (ip
->i_riff
!= NULL
)
310 FREE(ip
->i_riff
, M_TEMP
);
311 FREE_ZONE(ip
, sizeof(struct iso_node
), M_ISOFSNODE
);
320 cd9660_defattr(struct iso_directory_record
*isodir
, struct iso_node
*inop
,
323 struct buf
*bp2
= NULL
;
325 struct iso_extended_attributes
*ap
= NULL
;
328 if ( isonum_711(isodir
->flags
) & directoryBit
) {
329 inop
->inode
.iso_mode
= S_IFDIR
;
331 * If we return 2, fts() will assume there are no subdirectories
332 * (just links for the path and .), so instead we return 1.
334 inop
->inode
.iso_links
= 1;
336 inop
->inode
.iso_mode
= S_IFREG
;
337 inop
->inode
.iso_links
= 1;
340 && ((imp
= inop
->i_mnt
)->im_flags
& ISOFSMNT_EXTATT
)
341 && (off
= isonum_711(isodir
->ext_attr_length
))) {
342 cd9660_blkatoff(ITOV(inop
), (off_t
)-(off
<< imp
->im_bshift
), NULL
, &bp2
);
346 ap
= (struct iso_extended_attributes
*)buf_dataptr(bp
);
348 if (isonum_711(ap
->version
) == 1) {
349 if (!(ap
->perm
[0]&0x40))
350 inop
->inode
.iso_mode
|= VEXEC
>> 6;
351 if (!(ap
->perm
[0]&0x10))
352 inop
->inode
.iso_mode
|= VREAD
>> 6;
353 if (!(ap
->perm
[0]&4))
354 inop
->inode
.iso_mode
|= VEXEC
>> 3;
355 if (!(ap
->perm
[0]&1))
356 inop
->inode
.iso_mode
|= VREAD
>> 3;
357 if (!(ap
->perm
[1]&0x40))
358 inop
->inode
.iso_mode
|= VEXEC
;
359 if (!(ap
->perm
[1]&0x10))
360 inop
->inode
.iso_mode
|= VREAD
;
361 inop
->inode
.iso_uid
= isonum_723(ap
->owner
); /* what about 0? */
362 inop
->inode
.iso_gid
= isonum_723(ap
->group
); /* what about 0? */
367 inop
->inode
.iso_mode
|= VREAD
|VWRITE
|VEXEC
|(VREAD
|VEXEC
)>>3|(VREAD
|VEXEC
)>>6;
368 inop
->inode
.iso_uid
= ISO_UNKNOWNUID
;
369 inop
->inode
.iso_gid
= ISO_UNKNOWNGID
;
379 cd9660_deftstamp(struct iso_directory_record
*isodir
, struct iso_node
*inop
,
382 struct buf
*bp2
= NULL
;
384 struct iso_extended_attributes
*ap
= NULL
;
388 && ((imp
= inop
->i_mnt
)->im_flags
& ISOFSMNT_EXTATT
)
389 && (off
= isonum_711(isodir
->ext_attr_length
)))
391 cd9660_blkatoff(ITOV(inop
), (off_t
)-(off
<< imp
->im_bshift
), NULL
, &bp2
);
395 ap
= (struct iso_extended_attributes
*)buf_dataptr(bp
);
397 if (isonum_711(ap
->version
) == 1) {
398 if (!cd9660_tstamp_conv17(ap
->ftime
,&inop
->inode
.iso_atime
))
399 cd9660_tstamp_conv17(ap
->ctime
,&inop
->inode
.iso_atime
);
400 if (!cd9660_tstamp_conv17(ap
->ctime
,&inop
->inode
.iso_ctime
))
401 inop
->inode
.iso_ctime
= inop
->inode
.iso_atime
;
402 if (!cd9660_tstamp_conv17(ap
->mtime
,&inop
->inode
.iso_mtime
))
403 inop
->inode
.iso_mtime
= inop
->inode
.iso_ctime
;
408 cd9660_tstamp_conv7(isodir
->date
,&inop
->inode
.iso_ctime
);
409 inop
->inode
.iso_atime
= inop
->inode
.iso_ctime
;
410 inop
->inode
.iso_mtime
= inop
->inode
.iso_ctime
;
417 cd9660_tstamp_conv7(u_char
*pi
, struct timespec
*pu
)
420 int y
, m
, d
, hour
, minute
, second
, mytz
;
436 /* computes day number relative to Sept. 19th,1989 */
437 /* don't even *THINK* about changing formula. It works! */
438 days
= 367*(y
-1980)-7*(y
+(m
+9)/12)/4-3*((y
+(m
-9)/7)/100+1)/4+275*m
/9+d
-100;
441 * Changed :-) to make it relative to Jan. 1st, 1970
442 * and to disambiguate negative division
444 days
= 367*(y
-1960)-7*(y
+(m
+9)/12)/4-3*((y
+(m
+9)/12-1)/100+1)/4+275*m
/9+d
-239;
446 crtime
= ((((days
* 24) + hour
) * 60 + minute
) * 60) + second
;
448 /* timezone offset is unreliable on some disks */
449 if (-48 <= mytz
&& mytz
<= 52)
450 crtime
-= mytz
* 15 * 60;
458 cd9660_chars2ui(u_char
*begin
, int len
)
462 for (rc
= 0; --len
>= 0;) {
464 rc
+= *begin
++ - '0';
470 cd9660_tstamp_conv17(u_char
*pi
, struct timespec
*pu
)
474 /* year:"0001"-"9999" -> -1900 */
475 buf
[0] = cd9660_chars2ui(pi
,4) - 1900;
477 /* month: " 1"-"12" -> 1 - 12 */
478 buf
[1] = cd9660_chars2ui(pi
+ 4,2);
480 /* day: " 1"-"31" -> 1 - 31 */
481 buf
[2] = cd9660_chars2ui(pi
+ 6,2);
483 /* hour: " 0"-"23" -> 0 - 23 */
484 buf
[3] = cd9660_chars2ui(pi
+ 8,2);
486 /* minute:" 0"-"59" -> 0 - 59 */
487 buf
[4] = cd9660_chars2ui(pi
+ 10,2);
489 /* second:" 0"-"59" -> 0 - 59 */
490 buf
[5] = cd9660_chars2ui(pi
+ 12,2);
492 /* difference of GMT */
495 return cd9660_tstamp_conv7(buf
,pu
);
499 isodirino(struct iso_directory_record
*isodir
, struct iso_mnt
*imp
)
503 ino
= (isonum_733(isodir
->extent
) + isonum_711(isodir
->ext_attr_length
))