2 * Copyright (c) 2000-2001 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>
80 #include <sys/utfconv.h>
81 #include <architecture/byte_order.h>
83 #include <isofs/cd9660/iso.h>
84 #include <isofs/cd9660/iso_rrip.h>
85 #include <isofs/cd9660/cd9660_node.h>
86 #include <isofs/cd9660/cd9660_mount.h>
88 u_char isonullname
[] = "\0";
92 struct vfsops cd9660_vfsops
= {
108 * Called by vfs_mountroot when iso is going to be mounted as root.
110 * Name is updated by mount(8) after booting.
112 #define ROOTNAME "root_device"
114 static int iso_mountfs
__P((struct vnode
*devvp
, struct mount
*mp
,
115 struct proc
*p
, struct iso_args
*argp
));
117 static void DRGetTypeCreatorAndFlags(
118 struct iso_mnt
* theMountPointPtr
,
119 struct iso_directory_record
* theDirRecPtr
,
120 u_int32_t
* theTypePtr
,
121 u_int32_t
* theCreatorPtr
,
122 u_int16_t
* theFlagsPtr
);
124 int cd9660_vget_internal(
129 struct iso_directory_record
*isodir
,
135 register struct mount
*mp
;
136 extern struct vnode
*rootvp
;
137 struct proc
*p
= current_proc(); /* XXX */
141 struct iso_args args
;
144 * Get vnodes for swapdev and rootdev.
146 if ( bdevvp(rootdev
, &rootvp
))
147 panic("cd9660_mountroot: can't setup bdevvp's");
149 MALLOC_ZONE(mp
, struct mount
*,
150 sizeof(struct mount
), M_MOUNT
, M_WAITOK
);
151 bzero((char *)mp
, (u_long
)sizeof(struct mount
));
153 /* Initialize the default IO constraints */
154 mp
->mnt_maxreadcnt
= mp
->mnt_maxwritecnt
= MAXPHYS
;
155 mp
->mnt_segreadcnt
= mp
->mnt_segwritecnt
= 32;
157 mp
->mnt_op
= &cd9660_vfsops
;
158 mp
->mnt_flag
= MNT_RDONLY
;
159 LIST_INIT(&mp
->mnt_vnodelist
);
160 args
.flags
= ISOFSMNT_ROOT
;
162 if ((error
= iso_mountfs(rootvp
, mp
, p
, &args
))) {
163 FREE_ZONE(mp
, sizeof (struct mount
), M_MOUNT
);
166 simple_lock(&mountlist_slock
);
167 CIRCLEQ_INSERT_TAIL(&mountlist
, mp
, mnt_list
);
168 simple_unlock(&mountlist_slock
);
169 mp
->mnt_vnodecovered
= NULLVP
;
170 imp
= VFSTOISOFS(mp
);
171 (void) copystr("/", mp
->mnt_stat
.f_mntonname
, MNAMELEN
- 1,
173 bzero(mp
->mnt_stat
.f_mntonname
+ size
, MNAMELEN
- size
);
174 (void) copystr(ROOTNAME
, mp
->mnt_stat
.f_mntfromname
, MNAMELEN
- 1,
176 bzero(mp
->mnt_stat
.f_mntfromname
+ size
, MNAMELEN
- size
);
177 (void)cd9660_statfs(mp
, &mp
->mnt_stat
, p
);
187 cd9660_mount(mp
, path
, data
, ndp
, p
)
188 register struct mount
*mp
;
191 struct nameidata
*ndp
;
195 struct iso_args args
;
198 struct iso_mnt
*imp
= NULL
;
200 if ((error
= copyin(data
, (caddr_t
)&args
, sizeof (struct iso_args
))))
203 if ((mp
->mnt_flag
& MNT_RDONLY
) == 0)
207 * If updating, check whether changing from read-only to
208 * read/write; if there is no device name, that's all we do.
210 if (mp
->mnt_flag
& MNT_UPDATE
) {
211 imp
= VFSTOISOFS(mp
);
213 return (vfs_export(mp
, &imp
->im_export
, &args
.export
));
216 * Not an update, or updating the name: look up the name
217 * and verify that it refers to a sensible block device.
219 NDINIT(ndp
, LOOKUP
, FOLLOW
, UIO_USERSPACE
, args
.fspec
, p
);
220 if ((error
= namei(ndp
)))
224 if (devvp
->v_type
!= VBLK
) {
228 if (major(devvp
->v_rdev
) >= nblkdev
) {
232 if ((mp
->mnt_flag
& MNT_UPDATE
) == 0)
233 error
= iso_mountfs(devvp
, mp
, p
, &args
);
235 if (devvp
!= imp
->im_devvp
)
236 error
= EINVAL
; /* needs translation */
245 /* Set the mount flag to indicate that we support volfs */
246 mp
->mnt_flag
|= MNT_DOVOLFS
;
248 (void) copyinstr(path
, mp
->mnt_stat
.f_mntonname
, MNAMELEN
- 1, &size
);
249 bzero(mp
->mnt_stat
.f_mntonname
+ size
, MNAMELEN
- size
);
250 (void) copyinstr(args
.fspec
, mp
->mnt_stat
.f_mntfromname
, MNAMELEN
- 1,
252 bzero(mp
->mnt_stat
.f_mntfromname
+ size
, MNAMELEN
- size
);
257 * Common code for mount and mountroot
260 iso_mountfs(devvp
, mp
, p
, argp
)
261 register struct vnode
*devvp
;
264 struct iso_args
*argp
;
266 register struct iso_mnt
*isomp
= (struct iso_mnt
*)0;
267 struct buf
*bp
= NULL
;
268 struct buf
*pribp
= NULL
, *supbp
= NULL
;
269 dev_t dev
= devvp
->v_rdev
;
273 extern struct vnode
*rootvp
;
277 struct iso_volume_descriptor
*vdp
= NULL
;
278 struct iso_primary_descriptor
*pri
= NULL
;
279 struct iso_primary_descriptor
*sup
= NULL
;
280 struct iso_directory_record
*rootp
;
281 int logical_block_size
;
283 int blkoff
= argp
->ssector
;
285 if (!(mp
->mnt_flag
& MNT_RDONLY
))
289 * Disallow multiple mounts of the same device.
290 * Disallow mounting of a device that is currently in use
291 * (except for root, which might share swap device for miniroot).
292 * Flush out any old buffers remaining from a previous use.
294 if ((error
= vfs_mountedon(devvp
)))
296 if (vcount(devvp
) > 1 && devvp
!= rootvp
)
298 if ((error
= vinvalbuf(devvp
, V_SAVE
, p
->p_ucred
, p
, 0, 0)))
301 if ((error
= VOP_OPEN(devvp
, FREAD
, FSCRED
, p
)))
305 /* This is the "logical sector size". The standard says this
306 * should be 2048 or the physical sector size on the device,
307 * whichever is greater. For now, we'll just use a constant.
309 iso_bsize
= ISO_DEFAULT_BLOCK_SIZE
;
311 /* tell IOKit that we're assuming 2K sectors */
312 if ((error
= VOP_IOCTL(devvp
, DKIOCSETBLOCKSIZE
,
313 (caddr_t
)&iso_bsize
, FWRITE
, p
->p_ucred
, p
)))
315 devvp
->v_specsize
= iso_bsize
;
317 for (iso_blknum
= 16 + blkoff
; iso_blknum
< (100 + blkoff
); iso_blknum
++) {
318 if ((error
= bread(devvp
, iso_blknum
, iso_bsize
, NOCRED
, &bp
))) {
320 bp
->b_flags
|= B_AGE
;
325 printf("iso_mountfs: bread error %d reading block %d\n", error
, iso_blknum
);
329 vdp
= (struct iso_volume_descriptor
*)bp
->b_data
;
330 if (bcmp (vdp
->volume_desc_id
, ISO_STANDARD_ID
, sizeof(vdp
->volume_desc_id
)) != 0) {
332 printf("cd9660_vfsops.c: iso_mountfs: "
333 "Invalid ID in volume desciptor.\n");
339 vdtype
= isonum_711 (vdp
->type
);
340 if (vdtype
== ISO_VD_END
)
343 if (vdtype
== ISO_VD_PRIMARY
) {
347 pri
= (struct iso_primary_descriptor
*)vdp
;
349 } else if(vdtype
== ISO_VD_SUPPLEMENTARY
) {
353 sup
= (struct iso_primary_descriptor
*)vdp
;
355 if ((argp
->flags
& ISOFSMNT_NOJOLIET
) == 0) {
357 * some Joliet CDs are "out-of-spec and don't correctly
358 * set the SVD flags. We ignore the flags and rely soely
361 if (bcmp(sup
->escape_seq
, ISO_UCS2_Level_1
, 3) == 0)
363 else if (bcmp(sup
->escape_seq
, ISO_UCS2_Level_2
, 3) == 0)
365 else if (bcmp(sup
->escape_seq
, ISO_UCS2_Level_3
, 3) == 0)
372 bp
->b_flags
|= B_AGE
;
379 bp
->b_flags
|= B_AGE
;
392 logical_block_size
= isonum_723 (pri
->logical_block_size
);
394 if (logical_block_size
< DEV_BSIZE
|| logical_block_size
> MAXBSIZE
395 || (logical_block_size
& (logical_block_size
- 1)) != 0) {
400 rootp
= (struct iso_directory_record
*)pri
->root_directory_record
;
402 MALLOC(isomp
, struct iso_mnt
*, sizeof *isomp
, M_ISOFSMNT
, M_WAITOK
);
403 bzero((caddr_t
)isomp
, sizeof *isomp
);
404 isomp
->logical_block_size
= logical_block_size
;
405 isomp
->volume_space_size
= isonum_733 (pri
->volume_space_size
);
407 * Since an ISO9660 multi-session CD can also access previous
408 * sessions, we have to include them into the space consider-
409 * ations. This doesn't yield a very accurate number since
410 * parts of the old sessions might be inaccessible now, but we
411 * can't do much better. This is also important for the NFS
412 * filehandle validation.
414 isomp
->volume_space_size
+= blkoff
;
415 bcopy (rootp
, isomp
->root
, sizeof isomp
->root
);
416 isomp
->root_extent
= isonum_733 (rootp
->extent
);
417 isomp
->root_size
= isonum_733 (rootp
->size
);
420 * getattrlist wants the volume name, create date and modify date
423 /* Remove any trailing white space */
424 if ( strlen(pri
->volume_id
) ) {
427 myPtr
= pri
->volume_id
+ strlen( pri
->volume_id
) - 1;
428 while ( *myPtr
== ' ' && myPtr
>= pri
->volume_id
) {
434 if (pri
->volume_id
[0] == 0)
435 strcpy(isomp
->volume_id
, ISO_DFLT_VOLUME_ID
);
437 bcopy(pri
->volume_id
, isomp
->volume_id
, sizeof(isomp
->volume_id
));
438 cd9660_tstamp_conv17(pri
->creation_date
, &isomp
->creation_date
);
439 cd9660_tstamp_conv17(pri
->modification_date
, &isomp
->modification_date
);
441 /* See if this is a CD-XA volume */
442 if (bcmp( pri
->CDXASignature
, ISO_XA_ID
,
443 sizeof(pri
->CDXASignature
) ) == 0 )
444 isomp
->im_flags2
|= IMF2_IS_CDXA
;
446 isomp
->im_bmask
= logical_block_size
- 1;
447 isomp
->im_bshift
= 0;
448 while ((1 << isomp
->im_bshift
) < isomp
->logical_block_size
)
451 pribp
->b_flags
|= B_AGE
;
455 mp
->mnt_data
= (qaddr_t
)isomp
;
456 mp
->mnt_stat
.f_fsid
.val
[0] = (long)dev
;
457 mp
->mnt_stat
.f_fsid
.val
[1] = mp
->mnt_vfc
->vfc_typenum
;
458 mp
->mnt_maxsymlinklen
= 0;
459 mp
->mnt_flag
|= MNT_LOCAL
;
461 isomp
->im_mountp
= mp
;
463 isomp
->im_devvp
= devvp
;
465 devvp
->v_specflags
|= SI_MOUNTEDON
;
467 /* Check the Rock Ridge Extention support */
468 if (!(argp
->flags
& ISOFSMNT_NORRIP
)) {
469 if ( (error
= bread(isomp
->im_devvp
,
470 (isomp
->root_extent
+ isonum_711(rootp
->ext_attr_length
)),
471 isomp
->logical_block_size
, NOCRED
, &bp
)) ) {
473 printf("iso_mountfs: bread error %d reading block %d\n",
474 error
, isomp
->root_extent
+ isonum_711(rootp
->ext_attr_length
));
475 argp
->flags
|= ISOFSMNT_NORRIP
;
478 rootp
= (struct iso_directory_record
*)bp
->b_data
;
480 if ((isomp
->rr_skip
= cd9660_rrip_offset(rootp
,isomp
)) < 0) {
481 argp
->flags
|= ISOFSMNT_NORRIP
;
483 argp
->flags
&= ~ISOFSMNT_GENS
;
487 * The contents are valid,
488 * but they will get reread as part of another vnode, so...
490 bp
->b_flags
|= B_AGE
;
496 isomp
->im_flags
= argp
->flags
& (ISOFSMNT_NORRIP
| ISOFSMNT_GENS
|
497 ISOFSMNT_EXTATT
| ISOFSMNT_NOJOLIET
);
499 switch (isomp
->im_flags
&(ISOFSMNT_NORRIP
|ISOFSMNT_GENS
)) {
501 isomp
->iso_ftype
= ISO_FTYPE_DEFAULT
;
503 case ISOFSMNT_GENS
|ISOFSMNT_NORRIP
:
504 isomp
->iso_ftype
= ISO_FTYPE_9660
;
507 isomp
->iso_ftype
= ISO_FTYPE_RRIP
;
511 /* Decide whether to use the Joliet descriptor */
513 if (isomp
->iso_ftype
!= ISO_FTYPE_RRIP
&& joliet_level
!= 0) {
520 * On Joliet CDs use the UCS-2 volume identifier.
522 * This name can have up to 15 UCS-2 chars and is
523 * terminated with 0x0000 or padded with 0x0020.
525 convflags
= UTF_DECOMPOSED
;
526 if (BYTE_ORDER
!= BIG_ENDIAN
)
527 convflags
|= UTF_REVERSE_ENDIAN
;
528 for (i
= 0, uchp
= (u_int16_t
*)sup
->volume_id
; i
< 15 && uchp
[i
]; ++i
);
529 if ((utf8_encodestr((u_int16_t
*)sup
->volume_id
, (i
* 2), vol_id
,
530 &convbytes
, sizeof(vol_id
), 0, convflags
) == 0)
531 && convbytes
&& (vol_id
[0] != ' ')) {
534 /* Remove trailing spaces */
535 strp
= vol_id
+ convbytes
- 1;
536 while (strp
> vol_id
&& *strp
== ' ')
538 bcopy(vol_id
, isomp
->volume_id
, convbytes
);
541 rootp
= (struct iso_directory_record
*)
542 sup
->root_directory_record
;
543 bcopy (rootp
, isomp
->root
, sizeof isomp
->root
);
544 isomp
->root_extent
= isonum_733 (rootp
->extent
);
545 isomp
->root_size
= isonum_733 (rootp
->size
);
546 supbp
->b_flags
|= B_AGE
;
547 isomp
->iso_ftype
= ISO_FTYPE_JOLIET
;
564 (void)VOP_CLOSE(devvp
, FREAD
, NOCRED
, p
);
566 FREE((caddr_t
)isomp
, M_ISOFSMNT
);
567 mp
->mnt_data
= (qaddr_t
)0;
570 /* Clear the mounted on bit in the devvp If it */
571 /* not set, this is a nop and there is no way to */
572 /* get here with it set unless we did it. If you*/
573 /* are making code changes which makes the above */
574 /* assumption not true, change this code. */
576 devvp
->v_specflags
&= ~SI_MOUNTEDON
;
582 * Make a filesystem operational.
583 * Nothing to do at the moment.
587 cd9660_start(mp
, flags
, p
)
596 * unmount system call
599 cd9660_unmount(mp
, mntflags
, p
)
604 register struct iso_mnt
*isomp
;
605 int error
, flags
= 0;
607 if ( (mntflags
& MNT_FORCE
) )
610 if ( (error
= vflush(mp
, NULLVP
, flags
)) )
613 isomp
= VFSTOISOFS(mp
);
616 if (isomp
->iso_ftype
== ISO_FTYPE_RRIP
)
617 iso_dunmap(isomp
->im_dev
);
620 isomp
->im_devvp
->v_specflags
&= ~SI_MOUNTEDON
;
621 error
= VOP_CLOSE(isomp
->im_devvp
, FREAD
, NOCRED
, p
);
622 vrele(isomp
->im_devvp
);
623 FREE((caddr_t
)isomp
, M_ISOFSMNT
);
624 mp
->mnt_data
= (qaddr_t
)0;
625 mp
->mnt_flag
&= ~MNT_LOCAL
;
631 * Return root of a filesystem
638 struct iso_mnt
*imp
= VFSTOISOFS(mp
);
639 struct iso_directory_record
*dp
=
640 (struct iso_directory_record
*)imp
->root
;
641 ino_t ino
= isodirino(dp
, imp
);
644 * With RRIP we must use the `.' entry of the root directory.
645 * Simply tell vget, that it's a relocated directory.
647 return (cd9660_vget_internal(mp
, ino
, vpp
,
648 imp
->iso_ftype
== ISO_FTYPE_RRIP
, dp
, current_proc()));
652 * Do operations associated with quotas, not supported
656 cd9660_quotactl(mp
, cmd
, uid
, arg
, p
)
668 * Get file system statistics.
671 cd9660_statfs(mp
, sbp
, p
)
673 register struct statfs
*sbp
;
676 register struct iso_mnt
*isomp
;
678 isomp
= VFSTOISOFS(mp
);
685 sbp
->f_bsize
= isomp
->logical_block_size
;
686 sbp
->f_iosize
= sbp
->f_bsize
; /* XXX */
687 sbp
->f_blocks
= isomp
->volume_space_size
;
688 sbp
->f_bfree
= 0; /* total free blocks */
689 sbp
->f_bavail
= 0; /* blocks free for non superuser */
690 sbp
->f_files
= 0; /* total files */
691 sbp
->f_ffree
= 0; /* free file nodes */
692 if (sbp
!= &mp
->mnt_stat
) {
693 bcopy(mp
->mnt_stat
.f_mntonname
, sbp
->f_mntonname
, MNAMELEN
);
694 bcopy(mp
->mnt_stat
.f_mntfromname
, sbp
->f_mntfromname
, MNAMELEN
);
697 strncpy( sbp
->f_fstypename
, mp
->mnt_vfc
->vfc_name
, (MFSNAMELEN
- 1) );
698 sbp
->f_fstypename
[(MFSNAMELEN
- 1)] = '\0';
700 /* DO NOT use the first spare for flags; it's been reassigned for another use: */
701 /* sbp->f_spare[0] = isomp->im_flags; */
708 cd9660_sync(mp
, waitfor
, cred
, p
)
719 * File handle to vnode
721 * Have to be really careful about stale file handles:
722 * - check that the inode number is in range
723 * - call iget() to get the locked inode
724 * - check for an unallocated inode (i_mode == 0)
725 * - check that the generation number matches
737 cd9660_fhtovp(mp
, fhp
, nam
, vpp
, exflagsp
, credanonp
)
738 register struct mount
*mp
;
743 struct ucred
**credanonp
;
745 struct ifid
*ifhp
= (struct ifid
*)fhp
;
746 register struct iso_node
*ip
;
747 register struct netcred
*np
;
748 register struct iso_mnt
*imp
= VFSTOISOFS(mp
);
753 printf("fhtovp: ino %d, start %ld\n",
754 ifhp
->ifid_ino
, ifhp
->ifid_start
);
758 * Get the export permission structure for this <mp, client> tuple.
760 np
= vfs_export_lookup(mp
, &imp
->im_export
, nam
);
764 if ( (error
= VFS_VGET(mp
, &ifhp
->ifid_ino
, &nvp
)) ) {
769 if (ip
->inode
.iso_mode
== 0) {
775 *exflagsp
= np
->netc_exflags
;
776 *credanonp
= &np
->netc_anon
;
781 cd9660_vget(mp
, ino
, vpp
)
788 * It would be nice if we didn't always set the `relocated' flag
789 * and force the extra read, but I don't want to think about fixing
793 return ( cd9660_vget_internal( mp
, *(ino_t
*)ino
, vpp
, 0,
794 (struct iso_directory_record
*) 0,
799 cd9660_vget_internal(mp
, ino
, vpp
, relocated
, isodir
, p
)
804 struct iso_directory_record
*isodir
;
807 register struct iso_mnt
*imp
;
810 struct vnode
*vp
, *nvp
;
814 imp
= VFSTOISOFS(mp
);
817 /* Check for unmount in progress */
818 if (mp
->mnt_kern_flag
& MNTK_UNMOUNT
) {
823 if ((*vpp
= cd9660_ihashget(dev
, ino
, p
)) != NULLVP
)
826 MALLOC_ZONE(ip
, struct iso_node
*, sizeof(struct iso_node
),
827 M_ISOFSNODE
, M_WAITOK
);
828 /* Allocate a new vnode/iso_node. */
829 if ( (error
= getnewvnode(VT_ISOFS
, mp
, cd9660_vnodeop_p
, &vp
)) ) {
830 FREE_ZONE(ip
,sizeof(struct iso_node
), M_ISOFSNODE
);
834 bzero((caddr_t
)ip
, sizeof(struct iso_node
));
835 lockinit(&ip
->i_lock
, PINOD
,"isonode",0,0);
840 ip
->i_namep
= &isonullname
[0];
843 * Put it onto its hash chain and lock it so that other requests for
844 * this inode will block if they arrive while we are sleeping waiting
845 * for old data structures to be purged or for the contents of the
846 * disk portion of this inode to be read.
853 lbn
= lblkno(imp
, ino
);
854 if (lbn
>= imp
->volume_space_size
) {
856 printf("fhtovp: lbn exceed volume space %d\n", lbn
);
860 off
= blkoff(imp
, ino
);
861 if (off
+ ISO_DIRECTORY_RECORD_SIZE
> imp
->logical_block_size
) {
863 printf("fhtovp: crosses block boundary %d\n",
864 off
+ ISO_DIRECTORY_RECORD_SIZE
);
868 error
= bread(imp
->im_devvp
, lbn
,
869 imp
->logical_block_size
, NOCRED
, &bp
);
873 printf("fhtovp: bread error %d\n",error
);
876 isodir
= (struct iso_directory_record
*)(bp
->b_data
+ off
);
878 if (off
+ isonum_711(isodir
->length
) >
879 imp
->logical_block_size
) {
883 printf("fhtovp: directory crosses block boundary "
884 "%d[off=%d/len=%d]\n",
885 off
+isonum_711(isodir
->length
), off
,
886 isonum_711(isodir
->length
));
891 * for directories we can get parentID from adjacent
892 * parent directory record
894 if ((isonum_711(isodir
->flags
) & directoryBit
)
895 && (isodir
->name
[0] == 0)) {
896 struct iso_directory_record
*pdp
;
898 pdp
= (struct iso_directory_record
*)
899 ((char *)bp
->b_data
+ isonum_711(isodir
->length
));
900 if ((isonum_711(pdp
->flags
) & directoryBit
)
901 && (pdp
->name
[0] == 1))
902 ip
->i_parent
= isodirino(pdp
, imp
);
908 ip
->i_devvp
= imp
->im_devvp
;
913 * On relocated directories we must
914 * read the `.' entry out of a dir.
916 ip
->iso_start
= ino
>> imp
->im_bshift
;
919 if ( (error
= VOP_BLKATOFF(vp
, (off_t
)0, NULL
, &bp
)) ) {
923 isodir
= (struct iso_directory_record
*)bp
->b_data
;
927 * go get apple extensions to ISO directory record or use
928 * defaults when there are no apple extensions.
930 if ( (isonum_711( isodir
->flags
) & directoryBit
) == 0 ) {
931 /* This is an ISO directory record for a file */
932 DRGetTypeCreatorAndFlags( imp
, isodir
, &ip
->i_FileType
,
933 &ip
->i_Creator
, &ip
->i_FinderFlags
);
936 ip
->iso_extent
= isonum_733(isodir
->extent
);
937 ip
->i_size
= isonum_733(isodir
->size
);
938 ip
->iso_start
= isonum_711(isodir
->ext_attr_length
) + ip
->iso_extent
;
941 * if we have a valid name, fill in i_namep with UTF-8 name
943 if (isonum_711(isodir
->name_len
) != 0) {
948 MALLOC(utf8namep
, u_char
*, ISO_RRIP_NAMEMAX
+ 1, M_TEMP
, M_WAITOK
);
949 namelen
= isonum_711(isodir
->name_len
);
951 switch (imp
->iso_ftype
) {
953 cd9660_rrip_getname(isodir
, utf8namep
, &namelen
, &inump
, imp
);
956 case ISO_FTYPE_JOLIET
:
957 ucsfntrans((u_int16_t
*)isodir
->name
, namelen
,
959 isonum_711(isodir
->flags
) & directoryBit
);
963 isofntrans (isodir
->name
, namelen
,
965 imp
->iso_ftype
== ISO_FTYPE_9660
);
968 utf8namep
[namelen
] = '\0';
969 MALLOC(ip
->i_namep
, u_char
*, namelen
+ 1, M_TEMP
, M_WAITOK
);
970 bcopy(utf8namep
, ip
->i_namep
, namelen
+ 1);
971 FREE(utf8namep
, M_TEMP
);
975 * Setup time stamp, attribute
978 switch (imp
->iso_ftype
) {
979 default: /* ISO_FTYPE_9660 */
983 if ((imp
->im_flags
& ISOFSMNT_EXTATT
)
984 && (off
= isonum_711(isodir
->ext_attr_length
)))
985 VOP_BLKATOFF(vp
, (off_t
)-(off
<< imp
->im_bshift
), NULL
, &bp2
);
988 cd9660_defattr(isodir
, ip
, bp2
);
989 cd9660_deftstamp(isodir
, ip
, bp2
);
995 cd9660_rrip_analyze(isodir
, ip
, imp
);
1003 * Initialize the associated vnode
1006 if (ip
->iso_extent
== imp
->root_extent
) {
1007 vp
->v_flag
|= VROOT
;
1008 ip
->i_parent
= 1; /* root's parent is always 1 by convention */
1009 /* mode type must be S_IFDIR */
1010 ip
->inode
.iso_mode
= (ip
->inode
.iso_mode
& ~S_IFMT
) | S_IFDIR
;
1013 switch (vp
->v_type
= IFTOVT(ip
->inode
.iso_mode
)) {
1016 vp
->v_op
= cd9660_fifoop_p
;
1020 return (EOPNOTSUPP
);
1025 * if device, look at device number table for translation
1028 if (dp
= iso_dmap(dev
, ino
, 0))
1029 ip
->inode
.iso_rdev
= dp
->d_dev
;
1031 vp
->v_op
= cd9660_specop_p
;
1032 if ( (nvp
= checkalias(vp
, ip
->inode
.iso_rdev
, mp
)) ) {
1034 * Discard unneeded vnode, but save its iso_node.
1036 cd9660_ihashrem(ip
);
1037 VOP_UNLOCK(vp
, 0, p
);
1038 nvp
->v_data
= vp
->v_data
;
1040 vp
->v_op
= spec_vnodeop_p
;
1044 * Reinitialize aliased inode.
1048 cd9660_ihashins(ip
);
1059 * XXX need generation number?
1068 /************************************************************************
1070 * Function: DRGetTypeCreatorAndFlags
1072 * Purpose: Set up the fileType, fileCreator and fileFlags
1076 * Side Effects: sets *theTypePtr, *theCreatorPtr, and *theFlagsPtr
1081 * 28 Jul 88 BL¡B Added a new extension type of 6, which allows
1082 * the specification of four of the finder flags.
1083 * We let the creator of the disk just copy over
1084 * the finder flags, but we only look at always
1085 * switch launch, system, bundle, and locked bits.
1086 * 15 Aug 88 BL¡B The Apple extensions to ISO 9660 implemented the
1087 * padding field at the end of a directory record
1089 * 19 Jul 89 BG Rewrote routine to handle the "new" Apple
1090 * Extensions definition, as well as take into
1091 * account the possibility of "other" definitions.
1092 * 02 Nov 89 BG Corrected the 'AA' SystemUseID processing to
1093 * check for SystemUseID == 2 (HFS). Was incorrectly
1094 * checking for SystemUseID == 1 (ProDOS) before.
1095 * 18 Mar 92 CMP Fixed the check for whether len_fi was odd or even.
1096 * Before it would always assume even for an XA record.
1097 * 26 Dec 97 jwc Swiped from MacOS implementation of ISO 9660 CD-ROM
1098 * support and modified to work in MacOSX file system.
1100 *********************************************************************** */
1103 DRGetTypeCreatorAndFlags( struct iso_mnt
* theMountPointPtr
,
1104 struct iso_directory_record
* theDirRecPtr
,
1105 u_int32_t
* theTypePtr
,
1106 u_int32_t
* theCreatorPtr
,
1107 u_int16_t
* theFlagsPtr
)
1111 u_int32_t myCreator
;
1112 AppleExtension
*myAppleExtPtr
;
1113 NewAppleExtension
*myNewAppleExtPtr
;
1114 u_int16_t myFinderFlags
;
1118 myType
= 0x3f3f3f3f;
1119 myCreator
= 0x3f3f3f3f;
1121 *theFlagsPtr
= 0x0000;
1124 * handle the fact that our original apple extensions didn't take
1125 * into account the padding byte on a file name
1128 myPtr
= &theDirRecPtr
->name
[ (isonum_711(theDirRecPtr
->name_len
)) ];
1130 /* if string length is even, bump myPtr for padding byte */
1131 if ( ((isonum_711(theDirRecPtr
->name_len
)) & 0x01) == 0 )
1133 myAppleExtPtr
= (AppleExtension
*) myPtr
;
1136 * checking for whether or not the new 'AA' code is being
1137 * called (and if so, correctly)
1139 if ( (isonum_711(theDirRecPtr
->length
)) <=
1140 ISO_DIRECTORY_RECORD_SIZE
+ (isonum_711(theDirRecPtr
->name_len
)) ) {
1145 foundStuff
= 0; /* now we default to *false* until we find a good one */
1146 myPtr
= (char *) myAppleExtPtr
;
1148 if ( (theMountPointPtr
->im_flags2
& IMF2_IS_CDXA
) != 0 )
1149 myPtr
+= 14;/* add in CD-XA fixed record offset (tnx, Phillips) */
1150 myNewAppleExtPtr
= (NewAppleExtension
*) myPtr
;
1152 /* calculate the "real" end of the directory record information */
1153 myPtr
= ((char *) theDirRecPtr
) + (isonum_711(theDirRecPtr
->length
));
1154 while( (char *) myNewAppleExtPtr
< myPtr
) /* end of directory buffer */
1157 * If we get here, we can assume that ALL further entries in this
1158 * directory record are of the form:
1160 * struct OptionalSystemUse
1162 * byte Signature[2];
1165 * byte fileType[4]; # only if HFS
1166 * byte fileCreator[4]; # only if HFS
1167 * byte finderFlags[2]; # only if HFS
1170 * This means that we can examine the Signature bytes to see
1171 * if they are 'AA' (the NEW Apple extension signature).
1172 * If they are, deal with them. If they aren't,
1173 * the OSULength field will tell us how long this extension
1174 * info is (including the signature and length bytes) and that
1175 * will allow us to walk the OptionalSystemUse records until
1176 * we hit the end of them or run off the end of the
1179 u_char
*myFromPtr
, *myToPtr
;
1182 u_int32_t fourchars
;
1186 if ( (myNewAppleExtPtr
->signature
[0] == 'A') &&
1187 (myNewAppleExtPtr
->signature
[1] == 'A') ) {
1188 if ( isonum_711(myNewAppleExtPtr
->systemUseID
) == 2 ) {
1190 foundStuff
= 1; /* we got one! */
1192 myFromPtr
= &myNewAppleExtPtr
->fileType
[0];
1193 myToPtr
= &myChars
.chars
[0];
1194 *myToPtr
++ = *myFromPtr
++;
1195 *myToPtr
++ = *myFromPtr
++;
1196 *myToPtr
++ = *myFromPtr
++;
1197 *myToPtr
= *myFromPtr
;
1198 myType
= myChars
.fourchars
; /* copy file type to user var */
1200 myFromPtr
= &myNewAppleExtPtr
->fileCreator
[0];
1201 myToPtr
= &myChars
.chars
[0];
1202 *myToPtr
++ = *myFromPtr
++;
1203 *myToPtr
++ = *myFromPtr
++;
1204 *myToPtr
++ = *myFromPtr
++;
1205 *myToPtr
= *myFromPtr
;
1206 myCreator
= myChars
.fourchars
; /* copy creator to user var */
1208 myFromPtr
= &myNewAppleExtPtr
->finderFlags
[0];
1209 myToPtr
= &myChars
.chars
[2]; /* *flags* is a short */
1210 myChars
.fourchars
= 0;
1211 *myToPtr
++ = *myFromPtr
++;
1212 *myToPtr
= *myFromPtr
;
1213 myFinderFlags
= myChars
.fourchars
;
1215 ( fAlwaysBit
| fSystemBit
| fHasBundleBit
| fLockedBit
);
1216 /* return Finder flags to user var */
1217 *theFlagsPtr
= (myFinderFlags
| fInitedBit
);
1219 break; /* exit the loop */
1224 * Check to see if we have a reasonable OSULength value.
1225 * ZERO is not an acceptable value. Nor is any value less than 4.
1228 if ( (isonum_711(myNewAppleExtPtr
->OSULength
)) < 4 )
1229 break; /* not acceptable - get out! */
1231 /* otherwise, step past this SystemUse record */
1232 (char *)myNewAppleExtPtr
+= (isonum_711(myNewAppleExtPtr
->OSULength
));
1234 } /* end of while loop */
1237 if ( foundStuff
!= 0 ) {
1238 *theTypePtr
= myType
;
1239 *theCreatorPtr
= myCreator
;
1247 } /* DRGetTypeCreatorAndFlags */
1251 * Vnode pointer to File handle
1255 cd9660_vptofh(vp
, fhp
)
1259 register struct iso_node
*ip
= VTOI(vp
);
1260 register struct ifid
*ifhp
;
1262 ifhp
= (struct ifid
*)fhp
;
1263 ifhp
->ifid_len
= sizeof(struct ifid
);
1265 ifhp
->ifid_ino
= ip
->i_number
;
1266 ifhp
->ifid_start
= ip
->iso_start
;
1269 printf("vptofh: ino %d, start %ld\n",
1270 ifhp
->ifid_ino
,ifhp
->ifid_start
);
1276 * Fast-FileSystem only?
1279 cd9660_sysctl(name
, namelen
, oldp
, oldlenp
, newp
, newlen
, p
)
1288 return (EOPNOTSUPP
);