2 * Copyright (c) 2000-2003 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_util.c,v 1.8 1994/12/13 22:33:25 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_util.c 8.3 (Berkeley) 12/5/94
67 * 7-Dec-98 Add ATTR_VOL_MOUNTFLAGS attribute support - djb
68 * 18-Nov-98 Add support for volfs - djb
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/vnode.h>
74 #include <sys/mount.h>
75 #include <sys/namei.h>
76 #include <sys/resourcevar.h>
77 #include <sys/kernel.h>
83 #include <sys/utfconv.h>
84 #include <miscfs/specfs/specdev.h> /* XXX */
85 #include <miscfs/fifofs/fifo.h> /* XXX */
86 #include <sys/malloc.h>
89 #include <kern/assert.h>
90 #include <architecture/byte_order.h>
92 #include <isofs/cd9660/iso.h>
93 #include <isofs/cd9660/cd9660_node.h>
94 #include <isofs/cd9660/iso_rrip.h>
97 * translate and compare a filename
98 * Note: Version number plus ';' may be omitted.
101 isofncmp(fn
, fnlen
, isofn
, isolen
)
108 while (--fnlen
>= 0) {
111 if ((c
= *isofn
++) == ';') {
120 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
121 if (*fn
< '0' || *fn
> '9') {
125 for (j
= 0; --isolen
>= 0; j
= j
* 10 + *isofn
++ - '0');
128 /* if raw comparison fails, check if char was mapped */
130 if (c
>= 'A' && c
<= 'Z') {
131 if (c
+ ('a' - 'A') != *fn
) {
132 if (*fn
>= 'a' && *fn
<= 'z')
133 return *fn
- ('a' - 'A') - c
;
137 } else if (c
== '/') {
140 } else if (c
> 0 || *fn
!= '_')
161 * translate and compare a UCS-2 filename
162 * Note: Version number plus ';' may be omitted.
166 ucsfncmp(fn
, fnlen
, ucsfn
, ucslen
)
175 /* convert byte count to char count */
179 while (--fnlen
>= 0) {
182 if ((c
= *ucsfn
++) == UCS_SEPARATOR2
) {
191 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
192 if (*fn
< '0' || *fn
> '9') {
196 for (j
= 0; --ucslen
>= 0; j
= j
* 10 + *ucsfn
++ - '0');
208 if (ucsfn
[1] != UCS_SEPARATOR2
)
219 * translate a filename
222 isofntrans(infn
, infnlen
, outfn
, outfnlen
, original
, assoc
)
223 u_char
*infn
, *outfn
;
232 * Add a "._" prefix for associated files
235 *outfn
++ = ASSOCCHAR1
;
236 *outfn
++ = ASSOCCHAR2
;
240 for (; fnidx
< infnlen
; fnidx
++) {
244 * Some ISO 9600 CD names contain 8-bit chars.
245 * These chars are mapped to '_' because there
246 * is no context for mapping them to UTF-8.
247 * In addition '/' is mapped to ':'.
249 * isofncmp accounts for these mappings.
256 else if (c
== '.' && *infn
== ';')
269 * translate a UCS-2 filename to UTF-8
272 ucsfntrans(infn
, infnlen
, outfn
, outfnlen
, dir
, assoc
)
283 if (*(u_char
*)infn
== 0)
285 else if (*(u_char
*)infn
== 1)
296 * Add a "._" prefix for associated files
299 *outfn
++ = ASSOCCHAR1
;
300 *outfn
++ = ASSOCCHAR2
;
303 /* strip file version number */
304 for (fnidx
--; fnidx
> 0; fnidx
--) {
305 /* stop when ';' is found */
306 if (infn
[fnidx
] == UCS_SEPARATOR2
) {
307 /* drop dangling dot */
308 if (fnidx
> 0 && infn
[fnidx
-1] == UCS_SEPARATOR1
)
317 flags
= UTF_NO_NULL_TERM
| UTF_DECOMPOSED
;
318 if (BYTE_ORDER
!= BIG_ENDIAN
)
319 flags
|= UTF_REVERSE_ENDIAN
;
321 (void) utf8_encodestr(infn
, fnidx
* 2, outfn
, &outbytes
, ISO_JOLIET_NAMEMAX
, 0, flags
);
322 *outfnlen
= assoc
? outbytes
+ 2 : outbytes
;
328 * count the number of children by enumerating the directory
331 isochildcount(vdp
, dircnt
, filcnt
)
337 struct buf
*bp
= NULL
;
339 struct iso_directory_record
*ep
;
350 bmask
= imp
->im_sector_size
- 1;
351 logblksize
= imp
->im_sector_size
;
352 blkoffset
= diroffset
= 0;
355 while (diroffset
< dp
->i_size
) {
357 * If offset is on a block boundary, read the next
358 * directory block. Release previous if it exists.
360 if ((diroffset
& bmask
) == 0) {
363 if ( (error
= VOP_BLKATOFF(vdp
, SECTOFF(imp
, diroffset
), NULL
, &bp
)) )
368 ep
= (struct iso_directory_record
*)
369 ((char *)bp
->b_data
+ blkoffset
);
371 reclen
= isonum_711(ep
->length
);
373 /* skip to next block, if any */
375 (diroffset
& ~bmask
) + logblksize
;
379 if ((reclen
< ISO_DIRECTORY_RECORD_SIZE
) ||
380 (blkoffset
+ reclen
> logblksize
) ||
381 (reclen
< ISO_DIRECTORY_RECORD_SIZE
+ isonum_711(ep
->name_len
))){
382 /* illegal, so give up */
387 * Some poorly mastered discs have an incorrect directory
388 * file size. If the '.' entry has a better size (bigger)
389 * then use that instead.
391 if ((diroffset
== 0) && (isonum_733(ep
->size
) > dp
->i_size
)) {
392 dp
->i_size
= isonum_733(ep
->size
);
395 if ( isonum_711(ep
->flags
) & directoryBit
)
397 else if ((isonum_711(ep
->flags
) & associatedBit
) == 0)
415 * There are two ways to qualify for ownership rights on an object:
417 * 1. Your UID matches the UID of the vnode
421 static int cd9660_owner_rights(uid_t owner
, struct iso_mnt
*imp
, struct ucred
*cred
, struct proc
*p
, int invokesuperuserstatus
) {
422 return ((cred
->cr_uid
== owner
) || /* [1] */
423 (invokesuperuserstatus
&& (suser(cred
, &p
->p_acflag
) == 0))) ? 0 : EPERM
; /* [2] */
428 static unsigned long DerivePermissionSummary(uid_t owner
, gid_t group
, mode_t obj_mode
, struct iso_mnt
*imp
, struct ucred
*cred
, struct proc
*p
) {
430 unsigned long permissions
;
433 /* User id 0 (root) always gets access. */
434 if (cred
->cr_uid
== 0) {
435 permissions
= R_OK
| X_OK
;
439 /* Otherwise, check the owner. */
440 if (cd9660_owner_rights(owner
, imp
, cred
, p
, 0) == 0) {
441 permissions
= ((unsigned long)obj_mode
& S_IRWXU
) >> 6;
445 /* Otherwise, check the groups. */
446 for (i
= 0, gp
= cred
->cr_groups
; i
< cred
->cr_ngroups
; i
++, gp
++) {
448 permissions
= ((unsigned long)obj_mode
& S_IRWXG
) >> 3;
453 /* Otherwise, settle for 'others' access. */
454 permissions
= (unsigned long)obj_mode
& S_IRWXO
;
457 return permissions
& ~W_OK
; /* Write access is always impossible */
462 attrcalcsize(struct attrlist
*attrlist
)
467 #if ((ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_FSID | ATTR_CMN_OBJTYPE | \
468 ATTR_CMN_OBJTAG | ATTR_CMN_OBJID | ATTR_CMN_OBJPERMANENTID | ATTR_CMN_PAROBJID | \
469 ATTR_CMN_SCRIPT | ATTR_CMN_CRTIME | ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME | \
470 ATTR_CMN_ACCTIME | ATTR_CMN_BKUPTIME | ATTR_CMN_FNDRINFO | ATTR_CMN_OWNERID | \
471 ATTR_CMN_GRPID | ATTR_CMN_ACCESSMASK | ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST| \
472 ATTR_CMN_FLAGS | ATTR_CMN_USERACCESS) != ATTR_CMN_VALIDMASK)
473 #error AttributeBlockSize: Missing bits in common mask computation!
475 assert((attrlist
->commonattr
& ~ATTR_CMN_VALIDMASK
) == 0);
477 #if ((ATTR_VOL_FSTYPE | ATTR_VOL_SIGNATURE | ATTR_VOL_SIZE | ATTR_VOL_SPACEFREE | \
478 ATTR_VOL_SPACEAVAIL | ATTR_VOL_MINALLOCATION | ATTR_VOL_ALLOCATIONCLUMP | ATTR_VOL_IOBLOCKSIZE | \
479 ATTR_VOL_OBJCOUNT | ATTR_VOL_FILECOUNT | ATTR_VOL_DIRCOUNT | ATTR_VOL_MAXOBJCOUNT | \
480 ATTR_VOL_MOUNTPOINT | ATTR_VOL_NAME | ATTR_VOL_MOUNTFLAGS | ATTR_VOL_INFO | \
481 ATTR_VOL_MOUNTEDDEVICE| ATTR_VOL_ENCODINGSUSED | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES) != ATTR_VOL_VALIDMASK)
482 #error AttributeBlockSize: Missing bits in volume mask computation!
484 assert((attrlist
->volattr
& ~ATTR_VOL_VALIDMASK
) == 0);
486 #if ((ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT | ATTR_DIR_MOUNTSTATUS) != ATTR_DIR_VALIDMASK)
487 #error AttributeBlockSize: Missing bits in directory mask computation!
489 assert((attrlist
->dirattr
& ~ATTR_DIR_VALIDMASK
) == 0);
490 #if ((ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE | ATTR_FILE_ALLOCSIZE | ATTR_FILE_IOBLOCKSIZE | \
491 ATTR_FILE_CLUMPSIZE | ATTR_FILE_DEVTYPE | ATTR_FILE_FILETYPE | ATTR_FILE_FORKCOUNT | \
492 ATTR_FILE_FORKLIST | ATTR_FILE_DATALENGTH | ATTR_FILE_DATAALLOCSIZE | ATTR_FILE_DATAEXTENTS | \
493 ATTR_FILE_RSRCLENGTH | ATTR_FILE_RSRCALLOCSIZE | ATTR_FILE_RSRCEXTENTS) != ATTR_FILE_VALIDMASK)
494 #error AttributeBlockSize: Missing bits in file mask computation!
496 assert((attrlist
->fileattr
& ~ATTR_FILE_VALIDMASK
) == 0);
498 #if ((ATTR_FORK_TOTALSIZE | ATTR_FORK_ALLOCSIZE) != ATTR_FORK_VALIDMASK)
499 #error AttributeBlockSize: Missing bits in fork mask computation!
501 assert((attrlist
->forkattr
& ~ATTR_FORK_VALIDMASK
) == 0);
505 if ((a
= attrlist
->commonattr
) != 0) {
506 if (a
& ATTR_CMN_NAME
) size
+= sizeof(struct attrreference
);
507 if (a
& ATTR_CMN_DEVID
) size
+= sizeof(dev_t
);
508 if (a
& ATTR_CMN_FSID
) size
+= sizeof(fsid_t
);
509 if (a
& ATTR_CMN_OBJTYPE
) size
+= sizeof(fsobj_type_t
);
510 if (a
& ATTR_CMN_OBJTAG
) size
+= sizeof(fsobj_tag_t
);
511 if (a
& ATTR_CMN_OBJID
) size
+= sizeof(fsobj_id_t
);
512 if (a
& ATTR_CMN_OBJPERMANENTID
) size
+= sizeof(fsobj_id_t
);
513 if (a
& ATTR_CMN_PAROBJID
) size
+= sizeof(fsobj_id_t
);
514 if (a
& ATTR_CMN_SCRIPT
) size
+= sizeof(text_encoding_t
);
515 if (a
& ATTR_CMN_CRTIME
) size
+= sizeof(struct timespec
);
516 if (a
& ATTR_CMN_MODTIME
) size
+= sizeof(struct timespec
);
517 if (a
& ATTR_CMN_CHGTIME
) size
+= sizeof(struct timespec
);
518 if (a
& ATTR_CMN_ACCTIME
) size
+= sizeof(struct timespec
);
519 if (a
& ATTR_CMN_BKUPTIME
) size
+= sizeof(struct timespec
);
520 if (a
& ATTR_CMN_FNDRINFO
) size
+= 32 * sizeof(u_int8_t
);
521 if (a
& ATTR_CMN_OWNERID
) size
+= sizeof(uid_t
);
522 if (a
& ATTR_CMN_GRPID
) size
+= sizeof(gid_t
);
523 if (a
& ATTR_CMN_ACCESSMASK
) size
+= sizeof(u_long
);
524 if (a
& ATTR_CMN_NAMEDATTRCOUNT
) size
+= sizeof(u_long
);
525 if (a
& ATTR_CMN_NAMEDATTRLIST
) size
+= sizeof(struct attrreference
);
526 if (a
& ATTR_CMN_FLAGS
) size
+= sizeof(u_long
);
527 if (a
& ATTR_CMN_USERACCESS
) size
+= sizeof(u_long
);
529 if ((a
= attrlist
->volattr
) != 0) {
530 if (a
& ATTR_VOL_FSTYPE
) size
+= sizeof(u_long
);
531 if (a
& ATTR_VOL_SIGNATURE
) size
+= sizeof(u_long
);
532 if (a
& ATTR_VOL_SIZE
) size
+= sizeof(off_t
);
533 if (a
& ATTR_VOL_SPACEFREE
) size
+= sizeof(off_t
);
534 if (a
& ATTR_VOL_SPACEAVAIL
) size
+= sizeof(off_t
);
535 if (a
& ATTR_VOL_MINALLOCATION
) size
+= sizeof(off_t
);
536 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) size
+= sizeof(off_t
);
537 if (a
& ATTR_VOL_IOBLOCKSIZE
) size
+= sizeof(size_t);
538 if (a
& ATTR_VOL_OBJCOUNT
) size
+= sizeof(u_long
);
539 if (a
& ATTR_VOL_FILECOUNT
) size
+= sizeof(u_long
);
540 if (a
& ATTR_VOL_DIRCOUNT
) size
+= sizeof(u_long
);
541 if (a
& ATTR_VOL_MAXOBJCOUNT
) size
+= sizeof(u_long
);
542 if (a
& ATTR_VOL_MOUNTPOINT
) size
+= sizeof(struct attrreference
);
543 if (a
& ATTR_VOL_NAME
) size
+= sizeof(struct attrreference
);
544 if (a
& ATTR_VOL_MOUNTFLAGS
) size
+= sizeof(u_long
);
545 if (a
& ATTR_VOL_MOUNTEDDEVICE
) size
+= sizeof(struct attrreference
);
546 if (a
& ATTR_VOL_ENCODINGSUSED
) size
+= sizeof(unsigned long long);
547 if (a
& ATTR_VOL_CAPABILITIES
) size
+= sizeof(vol_capabilities_attr_t
);
548 if (a
& ATTR_VOL_ATTRIBUTES
) size
+= sizeof(vol_attributes_attr_t
);
550 if ((a
= attrlist
->dirattr
) != 0) {
551 if (a
& ATTR_DIR_LINKCOUNT
) size
+= sizeof(u_long
);
552 if (a
& ATTR_DIR_ENTRYCOUNT
) size
+= sizeof(u_long
);
553 if (a
& ATTR_DIR_MOUNTSTATUS
) size
+= sizeof(u_long
);
555 if ((a
= attrlist
->fileattr
) != 0) {
556 if (a
& ATTR_FILE_LINKCOUNT
) size
+= sizeof(u_long
);
557 if (a
& ATTR_FILE_TOTALSIZE
) size
+= sizeof(off_t
);
558 if (a
& ATTR_FILE_ALLOCSIZE
) size
+= sizeof(off_t
);
559 if (a
& ATTR_FILE_IOBLOCKSIZE
) size
+= sizeof(size_t);
560 if (a
& ATTR_FILE_CLUMPSIZE
) size
+= sizeof(off_t
);
561 if (a
& ATTR_FILE_DEVTYPE
) size
+= sizeof(u_long
);
562 if (a
& ATTR_FILE_FILETYPE
) size
+= sizeof(u_long
);
563 if (a
& ATTR_FILE_FORKCOUNT
) size
+= sizeof(u_long
);
564 if (a
& ATTR_FILE_FORKLIST
) size
+= sizeof(struct attrreference
);
565 if (a
& ATTR_FILE_DATALENGTH
) size
+= sizeof(off_t
);
566 if (a
& ATTR_FILE_DATAALLOCSIZE
) size
+= sizeof(off_t
);
567 if (a
& ATTR_FILE_DATAEXTENTS
) size
+= sizeof(extentrecord
);
568 if (a
& ATTR_FILE_RSRCLENGTH
) size
+= sizeof(off_t
);
569 if (a
& ATTR_FILE_RSRCALLOCSIZE
) size
+= sizeof(off_t
);
570 if (a
& ATTR_FILE_RSRCEXTENTS
) size
+= sizeof(extentrecord
);
572 if ((a
= attrlist
->forkattr
) != 0) {
573 if (a
& ATTR_FORK_TOTALSIZE
) size
+= sizeof(off_t
);
574 if (a
& ATTR_FORK_ALLOCSIZE
) size
+= sizeof(off_t
);
583 packvolattr (struct attrlist
*alist
,
584 struct iso_node
*ip
, /* ip for root directory */
585 void **attrbufptrptr
,
595 attrbufptr
= *attrbufptrptr
;
596 varbufptr
= *varbufptrptr
;
600 if ((a
= alist
->commonattr
) != 0) {
601 if (a
& ATTR_CMN_NAME
) {
602 attrlength
= strlen( imp
->volume_id
) + 1;
603 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
604 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
605 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
607 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
608 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
609 ++((struct attrreference
*)attrbufptr
);
611 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = imp
->im_devvp
->v_rdev
;
612 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = ITOV(ip
)->v_mount
->mnt_stat
.f_fsid
;
613 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = 0;
614 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = VT_ISOFS
;
615 if (a
& ATTR_CMN_OBJID
) {
616 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
617 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
618 ++((fsobj_id_t
*)attrbufptr
);
620 if (a
& ATTR_CMN_OBJPERMANENTID
) {
621 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
622 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
623 ++((fsobj_id_t
*)attrbufptr
);
625 if (a
& ATTR_CMN_PAROBJID
) {
626 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
627 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
628 ++((fsobj_id_t
*)attrbufptr
);
630 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
631 if (a
& ATTR_CMN_CRTIME
) *((struct timespec
*)attrbufptr
)++ = imp
->creation_date
;
632 if (a
& ATTR_CMN_MODTIME
) *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
633 if (a
& ATTR_CMN_CHGTIME
) *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
634 if (a
& ATTR_CMN_ACCTIME
) *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
635 if (a
& ATTR_CMN_BKUPTIME
) {
636 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
637 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
638 ++((struct timespec
*)attrbufptr
);
640 if (a
& ATTR_CMN_FNDRINFO
) {
641 bzero (attrbufptr
, 32 * sizeof(u_int8_t
));
642 (u_int8_t
*)attrbufptr
+= 32 * sizeof(u_int8_t
);
644 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
645 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
646 if (a
& ATTR_CMN_ACCESSMASK
) *((u_long
*)attrbufptr
)++ = (u_long
)ip
->inode
.iso_mode
;
647 if (a
& ATTR_CMN_FLAGS
) *((u_long
*)attrbufptr
)++ = 0;
648 if (a
& ATTR_CMN_USERACCESS
) {
649 *((u_long
*)attrbufptr
)++ =
650 DerivePermissionSummary(ip
->inode
.iso_uid
,
654 current_proc()->p_ucred
,
659 if ((a
= alist
->volattr
) != 0) {
660 off_t blocksize
= (off_t
)imp
->logical_block_size
;
662 if (a
& ATTR_VOL_FSTYPE
) *((u_long
*)attrbufptr
)++ = (u_long
)imp
->im_mountp
->mnt_vfc
->vfc_typenum
;
663 if (a
& ATTR_VOL_SIGNATURE
) *((u_long
*)attrbufptr
)++ = (u_long
)ISO9660SIGNATURE
;
664 if (a
& ATTR_VOL_SIZE
) *((off_t
*)attrbufptr
)++ = (off_t
)imp
->volume_space_size
* blocksize
;
665 if (a
& ATTR_VOL_SPACEFREE
) *((off_t
*)attrbufptr
)++ = 0;
666 if (a
& ATTR_VOL_SPACEAVAIL
) *((off_t
*)attrbufptr
)++ = 0;
667 if (a
& ATTR_VOL_MINALLOCATION
) *((off_t
*)attrbufptr
)++ = blocksize
;
668 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) *((off_t
*)attrbufptr
)++ = blocksize
;
669 if (a
& ATTR_VOL_IOBLOCKSIZE
) *((size_t *)attrbufptr
)++ = blocksize
;
670 if (a
& ATTR_VOL_OBJCOUNT
) *((u_long
*)attrbufptr
)++ = 0;
671 if (a
& ATTR_VOL_FILECOUNT
) *((u_long
*)attrbufptr
)++ = 0;
672 if (a
& ATTR_VOL_DIRCOUNT
) *((u_long
*)attrbufptr
)++ = 0;
673 if (a
& ATTR_VOL_MAXOBJCOUNT
) *((u_long
*)attrbufptr
)++ = 0xFFFFFFFF;
674 if (a
& ATTR_VOL_NAME
) {
675 attrlength
= strlen( imp
->volume_id
) + 1;
676 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
677 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
678 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
680 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
681 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
682 ++((struct attrreference
*)attrbufptr
);
684 if (a
& ATTR_VOL_MOUNTFLAGS
) *((u_long
*)attrbufptr
)++ = (u_long
)imp
->im_mountp
->mnt_flag
;
685 if (a
& ATTR_VOL_MOUNTEDDEVICE
) {
686 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
687 ((struct attrreference
*)attrbufptr
)->attr_length
= strlen(mp
->mnt_stat
.f_mntfromname
) + 1;
688 attrlength
= ((struct attrreference
*)attrbufptr
)->attr_length
;
689 attrlength
= attrlength
+ ((4 - (attrlength
& 3)) & 3); /* round up to the next 4-byte boundary: */
690 (void) bcopy(mp
->mnt_stat
.f_mntfromname
, varbufptr
, attrlength
);
692 /* Advance beyond the space just allocated: */
693 (u_int8_t
*)varbufptr
+= attrlength
;
694 ++((struct attrreference
*)attrbufptr
);
696 if (a
& ATTR_VOL_ENCODINGSUSED
) *((unsigned long long *)attrbufptr
)++ = (unsigned long long)0;
697 if (a
& ATTR_VOL_CAPABILITIES
) {
698 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_FORMAT
] =
699 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_SYMBOLICLINKS
: 0) |
700 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_HARDLINKS
: 0) |
701 (imp
->iso_ftype
== ISO_FTYPE_RRIP
|| imp
->iso_ftype
== ISO_FTYPE_JOLIET
702 ? VOL_CAP_FMT_CASE_SENSITIVE
: 0) |
703 VOL_CAP_FMT_CASE_PRESERVING
|
704 VOL_CAP_FMT_FAST_STATFS
;
705 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_INTERFACES
] =
706 VOL_CAP_INT_ATTRLIST
|
707 VOL_CAP_INT_NFSEXPORT
;
708 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED1
] = 0;
709 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED2
] = 0;
711 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_FORMAT
] =
712 VOL_CAP_FMT_PERSISTENTOBJECTIDS
|
713 VOL_CAP_FMT_SYMBOLICLINKS
|
714 VOL_CAP_FMT_HARDLINKS
|
715 VOL_CAP_FMT_JOURNAL
|
716 VOL_CAP_FMT_JOURNAL_ACTIVE
|
717 VOL_CAP_FMT_NO_ROOT_TIMES
|
718 VOL_CAP_FMT_SPARSE_FILES
|
719 VOL_CAP_FMT_ZERO_RUNS
|
720 VOL_CAP_FMT_CASE_SENSITIVE
|
721 VOL_CAP_FMT_CASE_PRESERVING
|
722 VOL_CAP_FMT_FAST_STATFS
;
723 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_INTERFACES
] =
724 VOL_CAP_INT_SEARCHFS
|
725 VOL_CAP_INT_ATTRLIST
|
726 VOL_CAP_INT_NFSEXPORT
|
727 VOL_CAP_INT_READDIRATTR
|
728 VOL_CAP_INT_EXCHANGEDATA
|
729 VOL_CAP_INT_COPYFILE
|
730 VOL_CAP_INT_ALLOCATE
|
731 VOL_CAP_INT_VOL_RENAME
|
732 VOL_CAP_INT_ADVLOCK
|
734 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
735 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
737 ++((vol_capabilities_attr_t
*)attrbufptr
);
739 if (a
& ATTR_VOL_ATTRIBUTES
) {
740 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.commonattr
= ATTR_CMN_VALIDMASK
;
741 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.volattr
= ATTR_VOL_VALIDMASK
;
742 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.dirattr
= ATTR_DIR_VALIDMASK
;
743 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.fileattr
= ATTR_FILE_VALIDMASK
;
744 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.forkattr
= ATTR_FORK_VALIDMASK
;
746 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.commonattr
= ATTR_CMN_VALIDMASK
;
747 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.volattr
= ATTR_VOL_VALIDMASK
;
748 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.dirattr
= ATTR_DIR_VALIDMASK
;
749 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.fileattr
= ATTR_FILE_VALIDMASK
;
750 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.forkattr
= ATTR_FORK_VALIDMASK
;
752 ++((vol_attributes_attr_t
*)attrbufptr
);
756 *attrbufptrptr
= attrbufptr
;
757 *varbufptrptr
= varbufptr
;
762 packcommonattr (struct attrlist
*alist
,
764 void **attrbufptrptr
,
772 attrbufptr
= *attrbufptrptr
;
773 varbufptr
= *varbufptrptr
;
775 if ((a
= alist
->commonattr
) != 0) {
776 struct iso_mnt
*imp
= ip
->i_mnt
;
778 if (a
& ATTR_CMN_NAME
) {
779 /* special case root since we know how to get it's name */
780 if (ITOV(ip
)->v_flag
& VROOT
) {
781 attrlength
= strlen( imp
->volume_id
) + 1;
782 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
784 attrlength
= strlen(ip
->i_namep
) + 1;
785 (void) strncpy((unsigned char *)varbufptr
, ip
->i_namep
, attrlength
);
788 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
789 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
790 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
791 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
792 ++((struct attrreference
*)attrbufptr
);
794 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = ip
->i_dev
;
795 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = ITOV(ip
)->v_mount
->mnt_stat
.f_fsid
;
796 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = ITOV(ip
)->v_type
;
797 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = ITOV(ip
)->v_tag
;
798 if (a
& ATTR_CMN_OBJID
) {
799 if (ITOV(ip
)->v_flag
& VROOT
)
800 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
802 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
803 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
804 ++((fsobj_id_t
*)attrbufptr
);
806 if (a
& ATTR_CMN_OBJPERMANENTID
) {
807 if (ITOV(ip
)->v_flag
& VROOT
)
808 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
810 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
811 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
812 ++((fsobj_id_t
*)attrbufptr
);
814 if (a
& ATTR_CMN_PAROBJID
) {
815 struct iso_directory_record
*dp
= (struct iso_directory_record
*)imp
->root
;
816 ino_t rootino
= isodirino(dp
, imp
);
818 if (ip
->i_number
== rootino
)
819 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 1; /* force root parent to be 1 */
820 else if (ip
->i_parent
== rootino
)
821 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
823 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_parent
;
824 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
825 ++((fsobj_id_t
*)attrbufptr
);
827 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
828 if (a
& ATTR_CMN_CRTIME
) *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
829 if (a
& ATTR_CMN_MODTIME
) *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
830 if (a
& ATTR_CMN_CHGTIME
) *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_ctime
;
831 if (a
& ATTR_CMN_ACCTIME
) *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
832 if (a
& ATTR_CMN_BKUPTIME
) {
833 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
834 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
835 ++((struct timespec
*)attrbufptr
);
837 if (a
& ATTR_CMN_FNDRINFO
) {
838 struct finder_info finfo
= {0};
840 finfo
.fdFlags
= ip
->i_FinderFlags
;
841 finfo
.fdLocation
.v
= -1;
842 finfo
.fdLocation
.h
= -1;
843 if (ITOV(ip
)->v_type
== VREG
) {
844 finfo
.fdType
= ip
->i_FileType
;
845 finfo
.fdCreator
= ip
->i_Creator
;
847 bcopy (&finfo
, attrbufptr
, sizeof(finfo
));
848 (u_int8_t
*)attrbufptr
+= sizeof(finfo
);
849 bzero (attrbufptr
, EXTFNDRINFOSIZE
);
850 (u_int8_t
*)attrbufptr
+= EXTFNDRINFOSIZE
;
852 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
853 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
854 if (a
& ATTR_CMN_ACCESSMASK
) *((u_long
*)attrbufptr
)++ = (u_long
)ip
->inode
.iso_mode
;
855 if (a
& ATTR_CMN_FLAGS
) *((u_long
*)attrbufptr
)++ = 0; /* could also use ip->i_flag */
856 if (a
& ATTR_CMN_USERACCESS
) {
857 *((u_long
*)attrbufptr
)++ =
858 DerivePermissionSummary(ip
->inode
.iso_uid
,
862 current_proc()->p_ucred
,
867 *attrbufptrptr
= attrbufptr
;
868 *varbufptrptr
= varbufptr
;
873 packdirattr(struct attrlist
*alist
,
875 void **attrbufptrptr
,
882 attrbufptr
= *attrbufptrptr
;
886 if ((ITOV(ip
)->v_type
== VDIR
) && (a
!= 0)) {
888 * if we haven't counted our children yet, do it now...
890 if ((ip
->i_entries
== 0) &&
891 (a
& (ATTR_DIR_LINKCOUNT
| ATTR_DIR_ENTRYCOUNT
))) {
892 (void) isochildcount(ITOV(ip
), &dircnt
, &filcnt
);
894 if ((ip
->inode
.iso_links
== 1) && (dircnt
!= 0))
895 ip
->inode
.iso_links
= dircnt
;
896 if ((filcnt
+ dircnt
) > 0)
897 ip
->i_entries
= dircnt
+ filcnt
;
900 if (a
& ATTR_DIR_LINKCOUNT
) {
901 *((u_long
*)attrbufptr
)++ = ip
->inode
.iso_links
;
903 if (a
& ATTR_DIR_ENTRYCOUNT
) {
904 /* exclude '.' and '..' from total caount */
905 *((u_long
*)attrbufptr
)++ = ((ip
->i_entries
<= 2) ? 0 : (ip
->i_entries
- 2));
907 if (a
& ATTR_DIR_MOUNTSTATUS
) {
908 if (ITOV(ip
)->v_mountedhere
) {
909 *((u_long
*)attrbufptr
)++ = DIR_MNTSTATUS_MNTPOINT
;
911 *((u_long
*)attrbufptr
)++ = 0;
916 *attrbufptrptr
= attrbufptr
;
921 packfileattr(struct attrlist
*alist
,
923 void **attrbufptrptr
,
926 void *attrbufptr
= *attrbufptrptr
;
927 void *varbufptr
= *varbufptrptr
;
928 attrgroup_t a
= alist
->fileattr
;
930 if ((ITOV(ip
)->v_type
== VREG
) && (a
!= 0)) {
931 if (a
& ATTR_FILE_LINKCOUNT
)
932 *((u_long
*)attrbufptr
)++ = ip
->inode
.iso_links
;
933 if (a
& ATTR_FILE_TOTALSIZE
)
934 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
935 if (a
& ATTR_FILE_ALLOCSIZE
)
936 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
937 if (a
& ATTR_FILE_IOBLOCKSIZE
)
938 *((u_long
*)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
939 if (a
& ATTR_FILE_CLUMPSIZE
)
940 *((u_long
*)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
941 if (a
& ATTR_FILE_DEVTYPE
)
942 *((u_long
*)attrbufptr
)++ = (u_long
)ip
->inode
.iso_rdev
;
943 if (a
& ATTR_FILE_DATALENGTH
)
944 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
945 if (a
& ATTR_FILE_DATAALLOCSIZE
)
946 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
947 if (a
& ATTR_FILE_RSRCLENGTH
)
948 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
949 if (a
& ATTR_FILE_RSRCALLOCSIZE
)
950 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
953 *attrbufptrptr
= attrbufptr
;
954 *varbufptrptr
= varbufptr
;
959 packattrblk(struct attrlist
*alist
,
961 void **attrbufptrptr
,
964 struct iso_node
*ip
= VTOI(vp
);
966 if (alist
->volattr
!= 0) {
967 packvolattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
969 packcommonattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
971 switch (ITOV(ip
)->v_type
) {
973 packdirattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
977 packfileattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
980 /* Without this the compiler complains about VNON,VBLK,VCHR,VLNK,VSOCK,VFIFO,VBAD and VSTR