2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* $NetBSD: cd9660_vfsops.c,v 1.18 1995/03/09 12:05:36 mycroft Exp $ */
26 * The Regents of the University of California. All rights reserved.
28 * This code is derived from software contributed to Berkeley
29 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
30 * Support code is derived from software contributed to Berkeley
31 * by Atsushi Murai (amurai@spec.co.jp).
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * @(#)cd9660_vfsops.c 8.9 (Berkeley) 12/5/94
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/vnode.h>
67 #include <sys/mount.h>
68 #include <sys/namei.h>
70 #include <sys/kernel.h>
71 #include <miscfs/specfs/specdev.h>
74 #include <sys/ioctl.h>
76 #include <sys/errno.h>
77 #include <sys/malloc.h>
81 #include <isofs/cd9660/iso.h>
82 #include <isofs/cd9660/iso_rrip.h>
83 #include <isofs/cd9660/cd9660_node.h>
84 #include <isofs/cd9660/cd9660_mount.h>
86 u_char isonullname
[] = "\0";
90 struct vfsops cd9660_vfsops
= {
106 * Called by vfs_mountroot when iso is going to be mounted as root.
108 * Name is updated by mount(8) after booting.
110 #define ROOTNAME "root_device"
112 static int iso_mountfs
__P((struct vnode
*devvp
, struct mount
*mp
,
113 struct proc
*p
, struct iso_args
*argp
));
115 static void DRGetTypeCreatorAndFlags(
116 struct iso_mnt
* theMountPointPtr
,
117 struct iso_directory_record
* theDirRecPtr
,
118 u_int32_t
* theTypePtr
,
119 u_int32_t
* theCreatorPtr
,
120 u_int16_t
* theFlagsPtr
);
122 int cd9660_vget_internal(
127 struct iso_directory_record
*isodir
,
133 register struct mount
*mp
;
134 extern struct vnode
*rootvp
;
135 struct proc
*p
= current_proc(); /* XXX */
139 struct iso_args args
;
142 * Get vnodes for swapdev and rootdev.
144 if ( bdevvp(rootdev
, &rootvp
))
145 panic("cd9660_mountroot: can't setup bdevvp's");
147 MALLOC_ZONE(mp
, struct mount
*,
148 sizeof(struct mount
), M_MOUNT
, M_WAITOK
);
149 bzero((char *)mp
, (u_long
)sizeof(struct mount
));
150 mp
->mnt_op
= &cd9660_vfsops
;
151 mp
->mnt_flag
= MNT_RDONLY
;
152 LIST_INIT(&mp
->mnt_vnodelist
);
153 args
.flags
= ISOFSMNT_ROOT
;
155 if ((error
= iso_mountfs(rootvp
, mp
, p
, &args
))) {
156 FREE_ZONE(mp
, sizeof (struct mount
), M_MOUNT
);
159 simple_lock(&mountlist_slock
);
160 CIRCLEQ_INSERT_TAIL(&mountlist
, mp
, mnt_list
);
161 simple_unlock(&mountlist_slock
);
162 mp
->mnt_vnodecovered
= NULLVP
;
163 imp
= VFSTOISOFS(mp
);
164 (void) copystr("/", mp
->mnt_stat
.f_mntonname
, MNAMELEN
- 1,
166 bzero(mp
->mnt_stat
.f_mntonname
+ size
, MNAMELEN
- size
);
167 (void) copystr(ROOTNAME
, mp
->mnt_stat
.f_mntfromname
, MNAMELEN
- 1,
169 bzero(mp
->mnt_stat
.f_mntfromname
+ size
, MNAMELEN
- size
);
170 (void)cd9660_statfs(mp
, &mp
->mnt_stat
, p
);
180 cd9660_mount(mp
, path
, data
, ndp
, p
)
181 register struct mount
*mp
;
184 struct nameidata
*ndp
;
188 struct iso_args args
;
191 struct iso_mnt
*imp
= NULL
;
193 if ((error
= copyin(data
, (caddr_t
)&args
, sizeof (struct iso_args
))))
196 if ((mp
->mnt_flag
& MNT_RDONLY
) == 0)
200 * If updating, check whether changing from read-only to
201 * read/write; if there is no device name, that's all we do.
203 if (mp
->mnt_flag
& MNT_UPDATE
) {
204 imp
= VFSTOISOFS(mp
);
206 return (vfs_export(mp
, &imp
->im_export
, &args
.export
));
209 * Not an update, or updating the name: look up the name
210 * and verify that it refers to a sensible block device.
212 NDINIT(ndp
, LOOKUP
, FOLLOW
, UIO_USERSPACE
, args
.fspec
, p
);
213 if ((error
= namei(ndp
)))
217 if (devvp
->v_type
!= VBLK
) {
221 if (major(devvp
->v_rdev
) >= nblkdev
) {
225 if ((mp
->mnt_flag
& MNT_UPDATE
) == 0)
226 error
= iso_mountfs(devvp
, mp
, p
, &args
);
228 if (devvp
!= imp
->im_devvp
)
229 error
= EINVAL
; /* needs translation */
238 /* Set the mount flag to indicate that we support volfs */
239 mp
->mnt_flag
|= MNT_DOVOLFS
;
241 (void) copyinstr(path
, mp
->mnt_stat
.f_mntonname
, MNAMELEN
- 1, &size
);
242 bzero(mp
->mnt_stat
.f_mntonname
+ size
, MNAMELEN
- size
);
243 (void) copyinstr(args
.fspec
, mp
->mnt_stat
.f_mntfromname
, MNAMELEN
- 1,
245 bzero(mp
->mnt_stat
.f_mntfromname
+ size
, MNAMELEN
- size
);
250 * Common code for mount and mountroot
253 iso_mountfs(devvp
, mp
, p
, argp
)
254 register struct vnode
*devvp
;
257 struct iso_args
*argp
;
259 register struct iso_mnt
*isomp
= (struct iso_mnt
*)0;
260 struct buf
*bp
= NULL
;
261 struct buf
*pribp
= NULL
, *supbp
= NULL
;
262 dev_t dev
= devvp
->v_rdev
;
266 extern struct vnode
*rootvp
;
270 struct iso_volume_descriptor
*vdp
= NULL
;
271 struct iso_primary_descriptor
*pri
= NULL
;
272 struct iso_primary_descriptor
*sup
= NULL
;
273 struct iso_directory_record
*rootp
;
274 int logical_block_size
;
276 int blkoff
= argp
->ssector
;
278 if (!(mp
->mnt_flag
& MNT_RDONLY
))
282 * Disallow multiple mounts of the same device.
283 * Disallow mounting of a device that is currently in use
284 * (except for root, which might share swap device for miniroot).
285 * Flush out any old buffers remaining from a previous use.
287 if ((error
= vfs_mountedon(devvp
)))
289 if (vcount(devvp
) > 1 && devvp
!= rootvp
)
291 if ((error
= vinvalbuf(devvp
, V_SAVE
, p
->p_ucred
, p
, 0, 0)))
294 if ((error
= VOP_OPEN(devvp
, FREAD
, FSCRED
, p
)))
298 /* This is the "logical sector size". The standard says this
299 * should be 2048 or the physical sector size on the device,
300 * whichever is greater. For now, we'll just use a constant.
302 iso_bsize
= ISO_DEFAULT_BLOCK_SIZE
;
304 /* tell IOKit that we're assuming 2K sectors */
305 if ((error
= VOP_IOCTL(devvp
, DKIOCSETBLOCKSIZE
,
306 (caddr_t
)&iso_bsize
, FWRITE
, p
->p_ucred
, p
)))
308 devvp
->v_specsize
= iso_bsize
;
310 for (iso_blknum
= 16 + blkoff
; iso_blknum
< (100 + blkoff
); iso_blknum
++) {
311 if ((error
= bread(devvp
, iso_blknum
, iso_bsize
, NOCRED
, &bp
))) {
313 bp
->b_flags
|= B_AGE
;
318 printf("iso_mountfs: bread error %d reading block %d\n", error
, iso_blknum
);
322 vdp
= (struct iso_volume_descriptor
*)bp
->b_data
;
323 if (bcmp (vdp
->volume_desc_id
, ISO_STANDARD_ID
, sizeof(vdp
->volume_desc_id
)) != 0) {
325 printf("cd9660_vfsops.c: iso_mountfs: "
326 "Invalid ID in volume desciptor.\n");
332 vdtype
= isonum_711 (vdp
->type
);
333 if (vdtype
== ISO_VD_END
)
336 if (vdtype
== ISO_VD_PRIMARY
) {
340 pri
= (struct iso_primary_descriptor
*)vdp
;
342 } else if(vdtype
== ISO_VD_SUPPLEMENTARY
) {
346 sup
= (struct iso_primary_descriptor
*)vdp
;
348 if ((argp
->flags
& ISOFSMNT_NOJOLIET
) == 0) {
350 * some Joliet CDs are "out-of-spec and don't correctly
351 * set the SVD flags. We ignore the flags and rely soely
354 if (bcmp(sup
->escape_seq
, ISO_UCS2_Level_1
, 3) == 0)
356 else if (bcmp(sup
->escape_seq
, ISO_UCS2_Level_2
, 3) == 0)
358 else if (bcmp(sup
->escape_seq
, ISO_UCS2_Level_3
, 3) == 0)
365 bp
->b_flags
|= B_AGE
;
372 bp
->b_flags
|= B_AGE
;
385 logical_block_size
= isonum_723 (pri
->logical_block_size
);
387 if (logical_block_size
< DEV_BSIZE
|| logical_block_size
> MAXBSIZE
388 || (logical_block_size
& (logical_block_size
- 1)) != 0) {
393 rootp
= (struct iso_directory_record
*)pri
->root_directory_record
;
395 MALLOC(isomp
, struct iso_mnt
*, sizeof *isomp
, M_ISOFSMNT
, M_WAITOK
);
396 bzero((caddr_t
)isomp
, sizeof *isomp
);
397 isomp
->logical_block_size
= logical_block_size
;
398 isomp
->volume_space_size
= isonum_733 (pri
->volume_space_size
);
400 * Since an ISO9660 multi-session CD can also access previous
401 * sessions, we have to include them into the space consider-
402 * ations. This doesn't yield a very accurate number since
403 * parts of the old sessions might be inaccessible now, but we
404 * can't do much better. This is also important for the NFS
405 * filehandle validation.
407 isomp
->volume_space_size
+= blkoff
;
408 bcopy (rootp
, isomp
->root
, sizeof isomp
->root
);
409 isomp
->root_extent
= isonum_733 (rootp
->extent
);
410 isomp
->root_size
= isonum_733 (rootp
->size
);
413 * getattrlist wants the volume name, create date and modify date
416 /* Remove any trailing white space */
417 if ( strlen(pri
->volume_id
) ) {
420 myPtr
= pri
->volume_id
+ strlen( pri
->volume_id
) - 1;
421 while ( *myPtr
== ' ' && myPtr
>= pri
->volume_id
) {
426 /* YYY need to use secondary volume descriptor name for kanji disks */
427 bcopy(pri
->volume_id
, isomp
->volume_id
, sizeof(isomp
->volume_id
));
428 cd9660_tstamp_conv17(pri
->creation_date
, &isomp
->creation_date
);
429 cd9660_tstamp_conv17(pri
->modification_date
, &isomp
->modification_date
);
431 /* See if this is a CD-XA volume */
432 if (bcmp( pri
->CDXASignature
, ISO_XA_ID
,
433 sizeof(pri
->CDXASignature
) ) == 0 )
434 isomp
->im_flags2
|= IMF2_IS_CDXA
;
436 isomp
->im_bmask
= logical_block_size
- 1;
437 isomp
->im_bshift
= 0;
438 while ((1 << isomp
->im_bshift
) < isomp
->logical_block_size
)
441 pribp
->b_flags
|= B_AGE
;
445 mp
->mnt_data
= (qaddr_t
)isomp
;
446 mp
->mnt_stat
.f_fsid
.val
[0] = (long)dev
;
447 mp
->mnt_stat
.f_fsid
.val
[1] = mp
->mnt_vfc
->vfc_typenum
;
448 mp
->mnt_maxsymlinklen
= 0;
449 mp
->mnt_flag
|= MNT_LOCAL
;
451 isomp
->im_mountp
= mp
;
453 isomp
->im_devvp
= devvp
;
455 devvp
->v_specflags
|= SI_MOUNTEDON
;
457 /* Check the Rock Ridge Extention support */
458 if (!(argp
->flags
& ISOFSMNT_NORRIP
)) {
459 if ( (error
= bread(isomp
->im_devvp
,
460 (isomp
->root_extent
+ isonum_711(rootp
->ext_attr_length
)),
461 isomp
->logical_block_size
, NOCRED
, &bp
)) ) {
463 printf("iso_mountfs: bread error %d reading block %d\n",
464 error
, isomp
->root_extent
+ isonum_711(rootp
->ext_attr_length
));
465 argp
->flags
|= ISOFSMNT_NORRIP
;
468 rootp
= (struct iso_directory_record
*)bp
->b_data
;
470 if ((isomp
->rr_skip
= cd9660_rrip_offset(rootp
,isomp
)) < 0) {
471 argp
->flags
|= ISOFSMNT_NORRIP
;
473 argp
->flags
&= ~ISOFSMNT_GENS
;
477 * The contents are valid,
478 * but they will get reread as part of another vnode, so...
480 bp
->b_flags
|= B_AGE
;
486 isomp
->im_flags
= argp
->flags
& (ISOFSMNT_NORRIP
| ISOFSMNT_GENS
|
487 ISOFSMNT_EXTATT
| ISOFSMNT_NOJOLIET
);
489 switch (isomp
->im_flags
&(ISOFSMNT_NORRIP
|ISOFSMNT_GENS
)) {
491 isomp
->iso_ftype
= ISO_FTYPE_DEFAULT
;
493 case ISOFSMNT_GENS
|ISOFSMNT_NORRIP
:
494 isomp
->iso_ftype
= ISO_FTYPE_9660
;
497 isomp
->iso_ftype
= ISO_FTYPE_RRIP
;
501 /* Decide whether to use the Joliet descriptor */
503 if (isomp
->iso_ftype
!= ISO_FTYPE_RRIP
&& joliet_level
!= 0) {
504 rootp
= (struct iso_directory_record
*)
505 sup
->root_directory_record
;
506 bcopy (rootp
, isomp
->root
, sizeof isomp
->root
);
507 isomp
->root_extent
= isonum_733 (rootp
->extent
);
508 isomp
->root_size
= isonum_733 (rootp
->size
);
509 supbp
->b_flags
|= B_AGE
;
510 isomp
->iso_ftype
= ISO_FTYPE_JOLIET
;
527 (void)VOP_CLOSE(devvp
, FREAD
, NOCRED
, p
);
529 FREE((caddr_t
)isomp
, M_ISOFSMNT
);
530 mp
->mnt_data
= (qaddr_t
)0;
533 /* Clear the mounted on bit in the devvp If it */
534 /* not set, this is a nop and there is no way to */
535 /* get here with it set unless we did it. If you*/
536 /* are making code changes which makes the above */
537 /* assumption not true, change this code. */
539 devvp
->v_specflags
&= ~SI_MOUNTEDON
;
545 * Make a filesystem operational.
546 * Nothing to do at the moment.
550 cd9660_start(mp
, flags
, p
)
559 * unmount system call
562 cd9660_unmount(mp
, mntflags
, p
)
567 register struct iso_mnt
*isomp
;
568 int error
, flags
= 0;
570 if ( (mntflags
& MNT_FORCE
) )
573 if ( (error
= vflush(mp
, NULLVP
, flags
)) )
576 isomp
= VFSTOISOFS(mp
);
579 if (isomp
->iso_ftype
== ISO_FTYPE_RRIP
)
580 iso_dunmap(isomp
->im_dev
);
583 isomp
->im_devvp
->v_specflags
&= ~SI_MOUNTEDON
;
584 error
= VOP_CLOSE(isomp
->im_devvp
, FREAD
, NOCRED
, p
);
585 vrele(isomp
->im_devvp
);
586 FREE((caddr_t
)isomp
, M_ISOFSMNT
);
587 mp
->mnt_data
= (qaddr_t
)0;
588 mp
->mnt_flag
&= ~MNT_LOCAL
;
594 * Return root of a filesystem
601 struct iso_mnt
*imp
= VFSTOISOFS(mp
);
602 struct iso_directory_record
*dp
=
603 (struct iso_directory_record
*)imp
->root
;
604 ino_t ino
= isodirino(dp
, imp
);
607 * With RRIP we must use the `.' entry of the root directory.
608 * Simply tell vget, that it's a relocated directory.
610 return (cd9660_vget_internal(mp
, ino
, vpp
,
611 imp
->iso_ftype
== ISO_FTYPE_RRIP
, dp
, current_proc()));
615 * Do operations associated with quotas, not supported
619 cd9660_quotactl(mp
, cmd
, uid
, arg
, p
)
631 * Get file system statistics.
634 cd9660_statfs(mp
, sbp
, p
)
636 register struct statfs
*sbp
;
639 register struct iso_mnt
*isomp
;
641 isomp
= VFSTOISOFS(mp
);
648 sbp
->f_bsize
= isomp
->logical_block_size
;
649 sbp
->f_iosize
= sbp
->f_bsize
; /* XXX */
650 sbp
->f_blocks
= isomp
->volume_space_size
;
651 sbp
->f_bfree
= 0; /* total free blocks */
652 sbp
->f_bavail
= 0; /* blocks free for non superuser */
653 sbp
->f_files
= 0; /* total files */
654 sbp
->f_ffree
= 0; /* free file nodes */
655 if (sbp
!= &mp
->mnt_stat
) {
656 bcopy(mp
->mnt_stat
.f_mntonname
, sbp
->f_mntonname
, MNAMELEN
);
657 bcopy(mp
->mnt_stat
.f_mntfromname
, sbp
->f_mntfromname
, MNAMELEN
);
660 strncpy( sbp
->f_fstypename
, mp
->mnt_vfc
->vfc_name
, (MFSNAMELEN
- 1) );
661 sbp
->f_fstypename
[(MFSNAMELEN
- 1)] = '\0';
663 /* DO NOT use the first spare for flags; it's been reassigned for another use: */
664 /* sbp->f_spare[0] = isomp->im_flags; */
671 cd9660_sync(mp
, waitfor
, cred
, p
)
682 * File handle to vnode
684 * Have to be really careful about stale file handles:
685 * - check that the inode number is in range
686 * - call iget() to get the locked inode
687 * - check for an unallocated inode (i_mode == 0)
688 * - check that the generation number matches
700 cd9660_fhtovp(mp
, fhp
, nam
, vpp
, exflagsp
, credanonp
)
701 register struct mount
*mp
;
706 struct ucred
**credanonp
;
708 struct ifid
*ifhp
= (struct ifid
*)fhp
;
709 register struct iso_node
*ip
;
710 register struct netcred
*np
;
711 register struct iso_mnt
*imp
= VFSTOISOFS(mp
);
716 printf("fhtovp: ino %d, start %ld\n",
717 ifhp
->ifid_ino
, ifhp
->ifid_start
);
721 * Get the export permission structure for this <mp, client> tuple.
723 np
= vfs_export_lookup(mp
, &imp
->im_export
, nam
);
727 if ( (error
= VFS_VGET(mp
, &ifhp
->ifid_ino
, &nvp
)) ) {
732 if (ip
->inode
.iso_mode
== 0) {
738 *exflagsp
= np
->netc_exflags
;
739 *credanonp
= &np
->netc_anon
;
744 cd9660_vget(mp
, ino
, vpp
)
751 * It would be nice if we didn't always set the `relocated' flag
752 * and force the extra read, but I don't want to think about fixing
756 return ( cd9660_vget_internal( mp
, *(ino_t
*)ino
, vpp
, 0,
757 (struct iso_directory_record
*) 0,
762 cd9660_vget_internal(mp
, ino
, vpp
, relocated
, isodir
, p
)
767 struct iso_directory_record
*isodir
;
770 register struct iso_mnt
*imp
;
773 struct vnode
*vp
, *nvp
;
777 imp
= VFSTOISOFS(mp
);
780 /* Check for unmount in progress */
781 if (mp
->mnt_kern_flag
& MNTK_UNMOUNT
) {
786 if ((*vpp
= cd9660_ihashget(dev
, ino
, p
)) != NULLVP
)
789 MALLOC_ZONE(ip
, struct iso_node
*, sizeof(struct iso_node
),
790 M_ISOFSNODE
, M_WAITOK
);
791 /* Allocate a new vnode/iso_node. */
792 if ( (error
= getnewvnode(VT_ISOFS
, mp
, cd9660_vnodeop_p
, &vp
)) ) {
793 FREE_ZONE(ip
,sizeof(struct iso_node
), M_ISOFSNODE
);
797 bzero((caddr_t
)ip
, sizeof(struct iso_node
));
798 lockinit(&ip
->i_lock
, PINOD
,"isonode",0,0);
803 ip
->i_namep
= &isonullname
[0];
806 * Put it onto its hash chain and lock it so that other requests for
807 * this inode will block if they arrive while we are sleeping waiting
808 * for old data structures to be purged or for the contents of the
809 * disk portion of this inode to be read.
816 lbn
= lblkno(imp
, ino
);
817 if (lbn
>= imp
->volume_space_size
) {
819 printf("fhtovp: lbn exceed volume space %d\n", lbn
);
823 off
= blkoff(imp
, ino
);
824 if (off
+ ISO_DIRECTORY_RECORD_SIZE
> imp
->logical_block_size
) {
826 printf("fhtovp: crosses block boundary %d\n",
827 off
+ ISO_DIRECTORY_RECORD_SIZE
);
831 error
= bread(imp
->im_devvp
, lbn
,
832 imp
->logical_block_size
, NOCRED
, &bp
);
836 printf("fhtovp: bread error %d\n",error
);
839 isodir
= (struct iso_directory_record
*)(bp
->b_data
+ off
);
841 if (off
+ isonum_711(isodir
->length
) >
842 imp
->logical_block_size
) {
846 printf("fhtovp: directory crosses block boundary "
847 "%d[off=%d/len=%d]\n",
848 off
+isonum_711(isodir
->length
), off
,
849 isonum_711(isodir
->length
));
854 * for directories we can get parentID from adjacent
855 * parent directory record
857 if ((isonum_711(isodir
->flags
) & directoryBit
)
858 && (isodir
->name
[0] == 0)) {
859 struct iso_directory_record
*pdp
;
861 pdp
= (struct iso_directory_record
*)
862 ((char *)bp
->b_data
+ isonum_711(isodir
->length
));
863 if ((isonum_711(pdp
->flags
) & directoryBit
)
864 && (pdp
->name
[0] == 1))
865 ip
->i_parent
= isodirino(pdp
, imp
);
871 ip
->i_devvp
= imp
->im_devvp
;
876 * On relocated directories we must
877 * read the `.' entry out of a dir.
879 ip
->iso_start
= ino
>> imp
->im_bshift
;
882 if ( (error
= VOP_BLKATOFF(vp
, (off_t
)0, NULL
, &bp
)) ) {
886 isodir
= (struct iso_directory_record
*)bp
->b_data
;
890 * go get apple extensions to ISO directory record or use
891 * defaults when there are no apple extensions.
893 if ( (isonum_711( isodir
->flags
) & directoryBit
) == 0 ) {
894 /* This is an ISO directory record for a file */
895 DRGetTypeCreatorAndFlags( imp
, isodir
, &ip
->i_FileType
,
896 &ip
->i_Creator
, &ip
->i_FinderFlags
);
899 ip
->iso_extent
= isonum_733(isodir
->extent
);
900 ip
->i_size
= isonum_733(isodir
->size
);
901 ip
->iso_start
= isonum_711(isodir
->ext_attr_length
) + ip
->iso_extent
;
904 * if we have a valid name, fill in i_namep with UTF-8 name
906 if (isonum_711(isodir
->name_len
) != 0) {
911 MALLOC(utf8namep
, u_char
*, ISO_RRIP_NAMEMAX
+ 1, M_TEMP
, M_WAITOK
);
912 namelen
= isonum_711(isodir
->name_len
);
914 switch (imp
->iso_ftype
) {
916 cd9660_rrip_getname(isodir
, utf8namep
, &namelen
, &inump
, imp
);
919 case ISO_FTYPE_JOLIET
:
920 ucsfntrans((u_int16_t
*)isodir
->name
, namelen
,
922 isonum_711(isodir
->flags
) & directoryBit
);
926 isofntrans (isodir
->name
, namelen
,
928 imp
->iso_ftype
== ISO_FTYPE_9660
);
931 utf8namep
[namelen
] = '\0';
932 MALLOC(ip
->i_namep
, u_char
*, namelen
+ 1, M_TEMP
, M_WAITOK
);
933 bcopy(utf8namep
, ip
->i_namep
, namelen
+ 1);
934 FREE(utf8namep
, M_TEMP
);
938 * Setup time stamp, attribute
941 switch (imp
->iso_ftype
) {
942 default: /* ISO_FTYPE_9660 */
946 if ((imp
->im_flags
& ISOFSMNT_EXTATT
)
947 && (off
= isonum_711(isodir
->ext_attr_length
)))
948 VOP_BLKATOFF(vp
, (off_t
)-(off
<< imp
->im_bshift
), NULL
, &bp2
);
951 cd9660_defattr(isodir
, ip
, bp2
);
952 cd9660_deftstamp(isodir
, ip
, bp2
);
958 cd9660_rrip_analyze(isodir
, ip
, imp
);
966 * Initialize the associated vnode
969 if (ip
->iso_extent
== imp
->root_extent
) {
971 ip
->i_parent
= 1; /* root's parent is always 1 by convention */
972 /* mode type must be S_IFDIR */
973 ip
->inode
.iso_mode
= (ip
->inode
.iso_mode
& ~S_IFMT
) | S_IFDIR
;
976 switch (vp
->v_type
= IFTOVT(ip
->inode
.iso_mode
)) {
979 vp
->v_op
= cd9660_fifoop_p
;
988 * if device, look at device number table for translation
991 if (dp
= iso_dmap(dev
, ino
, 0))
992 ip
->inode
.iso_rdev
= dp
->d_dev
;
994 vp
->v_op
= cd9660_specop_p
;
995 if ( (nvp
= checkalias(vp
, ip
->inode
.iso_rdev
, mp
)) ) {
997 * Discard unneeded vnode, but save its iso_node.
1000 VOP_UNLOCK(vp
, 0, p
);
1001 nvp
->v_data
= vp
->v_data
;
1003 vp
->v_op
= spec_vnodeop_p
;
1007 * Reinitialize aliased inode.
1011 cd9660_ihashins(ip
);
1022 * XXX need generation number?
1031 /************************************************************************
1033 * Function: DRGetTypeCreatorAndFlags
1035 * Purpose: Set up the fileType, fileCreator and fileFlags
1039 * Side Effects: sets *theTypePtr, *theCreatorPtr, and *theFlagsPtr
1044 * 28 Jul 88 BL¡B Added a new extension type of 6, which allows
1045 * the specification of four of the finder flags.
1046 * We let the creator of the disk just copy over
1047 * the finder flags, but we only look at always
1048 * switch launch, system, bundle, and locked bits.
1049 * 15 Aug 88 BL¡B The Apple extensions to ISO 9660 implemented the
1050 * padding field at the end of a directory record
1052 * 19 Jul 89 BG Rewrote routine to handle the "new" Apple
1053 * Extensions definition, as well as take into
1054 * account the possibility of "other" definitions.
1055 * 02 Nov 89 BG Corrected the 'AA' SystemUseID processing to
1056 * check for SystemUseID == 2 (HFS). Was incorrectly
1057 * checking for SystemUseID == 1 (ProDOS) before.
1058 * 18 Mar 92 CMP Fixed the check for whether len_fi was odd or even.
1059 * Before it would always assume even for an XA record.
1060 * 26 Dec 97 jwc Swiped from MacOS implementation of ISO 9660 CD-ROM
1061 * support and modified to work in MacOSX file system.
1063 *********************************************************************** */
1066 DRGetTypeCreatorAndFlags( struct iso_mnt
* theMountPointPtr
,
1067 struct iso_directory_record
* theDirRecPtr
,
1068 u_int32_t
* theTypePtr
,
1069 u_int32_t
* theCreatorPtr
,
1070 u_int16_t
* theFlagsPtr
)
1074 u_int32_t myCreator
;
1075 AppleExtension
*myAppleExtPtr
;
1076 NewAppleExtension
*myNewAppleExtPtr
;
1077 u_int16_t myFinderFlags
;
1084 *theFlagsPtr
= 0x0000;
1087 * handle the fact that our original apple extensions didn't take
1088 * into account the padding byte on a file name
1091 myPtr
= &theDirRecPtr
->name
[ (isonum_711(theDirRecPtr
->name_len
)) ];
1093 /* if string length is even, bump myPtr for padding byte */
1094 if ( ((isonum_711(theDirRecPtr
->name_len
)) & 0x01) == 0 )
1096 myAppleExtPtr
= (AppleExtension
*) myPtr
;
1099 * checking for whether or not the new 'AA' code is being
1100 * called (and if so, correctly)
1102 if ( (isonum_711(theDirRecPtr
->length
)) <=
1103 ISO_DIRECTORY_RECORD_SIZE
+ (isonum_711(theDirRecPtr
->name_len
)) ) {
1108 foundStuff
= 0; /* now we default to *false* until we find a good one */
1109 myPtr
= (char *) myAppleExtPtr
;
1111 if ( (theMountPointPtr
->im_flags2
& IMF2_IS_CDXA
) != 0 )
1112 myPtr
+= 14;/* add in CD-XA fixed record offset (tnx, Phillips) */
1113 myNewAppleExtPtr
= (NewAppleExtension
*) myPtr
;
1115 /* calculate the "real" end of the directory record information */
1116 myPtr
= ((char *) theDirRecPtr
) + (isonum_711(theDirRecPtr
->length
));
1117 while( (char *) myNewAppleExtPtr
< myPtr
) /* end of directory buffer */
1120 * If we get here, we can assume that ALL further entries in this
1121 * directory record are of the form:
1123 * struct OptionalSystemUse
1125 * byte Signature[2];
1128 * byte fileType[4]; # only if HFS
1129 * byte fileCreator[4]; # only if HFS
1130 * byte finderFlags[2]; # only if HFS
1133 * This means that we can examine the Signature bytes to see
1134 * if they are 'AA' (the NEW Apple extension signature).
1135 * If they are, deal with them. If they aren't,
1136 * the OSULength field will tell us how long this extension
1137 * info is (including the signature and length bytes) and that
1138 * will allow us to walk the OptionalSystemUse records until
1139 * we hit the end of them or run off the end of the
1142 u_char
*myFromPtr
, *myToPtr
;
1145 u_int32_t fourchars
;
1149 if ( (myNewAppleExtPtr
->signature
[0] == 'A') &&
1150 (myNewAppleExtPtr
->signature
[1] == 'A') ) {
1151 if ( isonum_711(myNewAppleExtPtr
->systemUseID
) == 2 ) {
1153 foundStuff
= 1; /* we got one! */
1155 myFromPtr
= &myNewAppleExtPtr
->fileType
[0];
1156 myToPtr
= &myChars
.chars
[0];
1157 *myToPtr
++ = *myFromPtr
++;
1158 *myToPtr
++ = *myFromPtr
++;
1159 *myToPtr
++ = *myFromPtr
++;
1160 *myToPtr
= *myFromPtr
;
1161 myType
= myChars
.fourchars
; /* copy file type to user var */
1163 myFromPtr
= &myNewAppleExtPtr
->fileCreator
[0];
1164 myToPtr
= &myChars
.chars
[0];
1165 *myToPtr
++ = *myFromPtr
++;
1166 *myToPtr
++ = *myFromPtr
++;
1167 *myToPtr
++ = *myFromPtr
++;
1168 *myToPtr
= *myFromPtr
;
1169 myCreator
= myChars
.fourchars
; /* copy creator to user var */
1171 myFromPtr
= &myNewAppleExtPtr
->finderFlags
[0];
1172 myToPtr
= &myChars
.chars
[2]; /* *flags* is a short */
1173 myChars
.fourchars
= 0;
1174 *myToPtr
++ = *myFromPtr
++;
1175 *myToPtr
= *myFromPtr
;
1176 myFinderFlags
= myChars
.fourchars
;
1178 ( fAlwaysBit
| fSystemBit
| fHasBundleBit
| fLockedBit
);
1179 /* return Finder flags to user var */
1180 *theFlagsPtr
= (myFinderFlags
| fInitedBit
);
1182 break; /* exit the loop */
1187 * Check to see if we have a reasonable OSULength value.
1188 * ZERO is not an acceptable value. Nor is any value less than 4.
1191 if ( (isonum_711(myNewAppleExtPtr
->OSULength
)) < 4 )
1192 break; /* not acceptable - get out! */
1194 /* otherwise, step past this SystemUse record */
1195 (char *)myNewAppleExtPtr
+= (isonum_711(myNewAppleExtPtr
->OSULength
));
1197 } /* end of while loop */
1200 if ( foundStuff
!= 0 ) {
1201 *theTypePtr
= myType
;
1202 *theCreatorPtr
= myCreator
;
1210 } /* DRGetTypeCreatorAndFlags */
1214 * Vnode pointer to File handle
1218 cd9660_vptofh(vp
, fhp
)
1222 register struct iso_node
*ip
= VTOI(vp
);
1223 register struct ifid
*ifhp
;
1225 ifhp
= (struct ifid
*)fhp
;
1226 ifhp
->ifid_len
= sizeof(struct ifid
);
1228 ifhp
->ifid_ino
= ip
->i_number
;
1229 ifhp
->ifid_start
= ip
->iso_start
;
1232 printf("vptofh: ino %d, start %ld\n",
1233 ifhp
->ifid_ino
,ifhp
->ifid_start
);
1239 * Fast-FileSystem only?
1242 cd9660_sysctl(name
, namelen
, oldp
, oldlenp
, newp
, newlen
, p
)
1251 return (EOPNOTSUPP
);