2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* $NetBSD: cd9660_util.c,v 1.8 1994/12/13 22:33:25 mycroft Exp $ */
32 * The Regents of the University of California. All rights reserved.
34 * This code is derived from software contributed to Berkeley
35 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
36 * Support code is derived from software contributed to Berkeley
37 * by Atsushi Murai (amurai@spec.co.jp).
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed by the University of
50 * California, Berkeley and its contributors.
51 * 4. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 * @(#)cd9660_util.c 8.3 (Berkeley) 12/5/94
70 * 7-Dec-98 Add ATTR_VOL_MOUNTFLAGS attribute support - djb
71 * 18-Nov-98 Add support for volfs - djb
74 #include <sys/param.h>
75 #include <sys/systm.h>
76 #include <sys/vnode.h>
77 #include <sys/mount.h>
78 #include <sys/namei.h>
79 #include <sys/resourcevar.h>
80 #include <sys/kernel.h>
85 #include <sys/kauth.h>
87 #include <sys/utfconv.h>
88 #include <miscfs/specfs/specdev.h> /* XXX */
89 #include <miscfs/fifofs/fifo.h> /* XXX */
90 #include <sys/malloc.h>
93 #include <kern/assert.h>
95 #include <isofs/cd9660/iso.h>
96 #include <isofs/cd9660/cd9660_node.h>
97 #include <isofs/cd9660/iso_rrip.h>
100 * translate and compare a filename
101 * Note: Version number plus ';' may be omitted.
104 isofncmp(u_char
*fn
, int fnlen
, u_char
*isofn
, int isolen
)
109 while (--fnlen
>= 0) {
112 if ((c
= *isofn
++) == ';') {
121 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
122 if (*fn
< '0' || *fn
> '9') {
126 for (j
= 0; --isolen
>= 0; j
= j
* 10 + *isofn
++ - '0');
129 /* if raw comparison fails, check if char was mapped */
131 if (c
>= 'A' && c
<= 'Z') {
132 if (c
+ ('a' - 'A') != *fn
) {
133 if (*fn
>= 'a' && *fn
<= 'z')
134 return *fn
- ('a' - 'A') - c
;
138 } else if (c
== '/') {
141 } else if (c
> 0 || *fn
!= '_')
162 * translate and compare a UCS-2 filename
163 * Note: Version number plus ';' may be omitted.
165 * The name pointed to by "fn" is the search name, whose characters are
166 * in native endian order. The name "ucsfn" is the on-disk name, whose
167 * characters are in big endian order.
171 ucsfncmp(u_int16_t
*fn
, int fnlen
, u_int16_t
*ucsfn
, int ucslen
)
176 /* convert byte count to char count */
180 while (--fnlen
>= 0) {
183 if ((c
= OSSwapBigToHostInt16(*ucsfn
++)) == UCS_SEPARATOR2
) {
192 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
193 if (*fn
< '0' || *fn
> '9') {
197 for (j
= 0; --ucslen
>= 0; j
= j
* 10 + OSSwapBigToHostInt16(*ucsfn
++) - '0');
208 case OSSwapHostToBigConstInt16(UCS_SEPARATOR1
):
209 if (ucsfn
[1] != OSSwapHostToBigConstInt16(UCS_SEPARATOR2
))
211 case OSSwapHostToBigConstInt16(UCS_SEPARATOR2
):
220 * translate a filename
223 isofntrans(u_char
*infn
, int infnlen
, u_char
*outfn
, u_short
*outfnlen
,
224 int original
, int assoc
)
229 * Add a "._" prefix for associated files
232 *outfn
++ = ASSOCCHAR1
;
233 *outfn
++ = ASSOCCHAR2
;
237 for (; fnidx
< infnlen
; fnidx
++) {
241 * Some ISO 9600 CD names contain 8-bit chars.
242 * These chars are mapped to '_' because there
243 * is no context for mapping them to UTF-8.
244 * In addition '/' is mapped to ':'.
246 * isofncmp accounts for these mappings.
253 else if (c
== '.' && *infn
== ';')
266 * translate a UCS-2 filename to UTF-8
269 ucsfntrans(u_int16_t
*infn
, int infnlen
, u_char
*outfn
, u_short
*outfnlen
,
275 if (*(u_char
*)infn
== 0)
277 else if (*(u_char
*)infn
== 1)
288 * Add a "._" prefix for associated files
291 *outfn
++ = ASSOCCHAR1
;
292 *outfn
++ = ASSOCCHAR2
;
295 /* strip file version number */
296 for (fnidx
--; fnidx
> 0; fnidx
--) {
297 /* stop when ';' is found */
298 if (infn
[fnidx
] == OSSwapHostToBigConstInt16(UCS_SEPARATOR2
)) {
299 /* drop dangling dot */
300 if (fnidx
> 0 && infn
[fnidx
-1] == OSSwapHostToBigConstInt16(UCS_SEPARATOR1
))
309 flags
= UTF_NO_NULL_TERM
| UTF_DECOMPOSED
;
310 if (BYTE_ORDER
!= BIG_ENDIAN
)
311 flags
|= UTF_REVERSE_ENDIAN
;
313 (void) utf8_encodestr(infn
, fnidx
* 2, outfn
, &outbytes
, ISO_JOLIET_NAMEMAX
, 0, flags
);
314 *outfnlen
= assoc
? outbytes
+ 2 : outbytes
;
320 * count the number of children by enumerating the directory
323 isochildcount(struct vnode
*vdp
, int *dircnt
, int *filcnt
)
326 struct buf
*bp
= NULL
;
328 struct iso_directory_record
*ep
;
339 bmask
= imp
->im_sector_size
- 1;
340 logblksize
= imp
->im_sector_size
;
341 blkoffset
= diroffset
= 0;
344 while (diroffset
< dp
->i_size
) {
346 * If offset is on a block boundary, read the next
347 * directory block. Release previous if it exists.
349 if ((diroffset
& bmask
) == 0) {
352 if ( (error
= cd9660_blkatoff(vdp
, SECTOFF(imp
, diroffset
), NULL
, &bp
)) )
357 ep
= (struct iso_directory_record
*)
358 (buf_dataptr(bp
) + blkoffset
);
360 reclen
= isonum_711(ep
->length
);
362 /* skip to next block, if any */
364 (diroffset
& ~bmask
) + logblksize
;
368 if ((reclen
< ISO_DIRECTORY_RECORD_SIZE
) ||
369 (blkoffset
+ reclen
> logblksize
) ||
370 (reclen
< ISO_DIRECTORY_RECORD_SIZE
+ isonum_711(ep
->name_len
))){
371 /* illegal, so give up */
376 * Some poorly mastered discs have an incorrect directory
377 * file size. If the '.' entry has a better size (bigger)
378 * then use that instead.
380 if ((diroffset
== 0) && (isonum_733(ep
->size
) > dp
->i_size
)) {
381 dp
->i_size
= isonum_733(ep
->size
);
384 if ( isonum_711(ep
->flags
) & directoryBit
)
386 else if ((isonum_711(ep
->flags
) & associatedBit
) == 0)
404 DerivePermissionSummary(uid_t owner
, gid_t group
, mode_t obj_mode
, __unused
struct iso_mnt
*imp
)
406 kauth_cred_t cred
= kauth_cred_get();
407 uint32_t permissions
;
410 /* User id 0 (root) always gets access. */
411 if (!suser(cred
, NULL
)) {
412 permissions
= R_OK
| X_OK
;
416 /* Otherwise, check the owner. */
417 if (owner
== kauth_cred_getuid(cred
)) {
418 permissions
= ((uint32_t)obj_mode
& S_IRWXU
) >> 6;
422 /* Otherwise, check the groups. */
423 if (kauth_cred_ismember_gid(cred
, group
, &is_member
) == 0 && is_member
) {
424 permissions
= ((uint32_t)obj_mode
& S_IRWXG
) >> 3;
428 /* Otherwise, settle for 'others' access. */
429 permissions
= (uint32_t)obj_mode
& S_IRWXO
;
432 return permissions
& ~W_OK
; /* Write access is always impossible */
437 attrcalcsize(struct attrlist
*attrlist
)
441 boolean_t is_64_bit
= proc_is64bit(current_proc());
443 #if ((ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_FSID | ATTR_CMN_OBJTYPE | \
444 ATTR_CMN_OBJTAG | ATTR_CMN_OBJID | ATTR_CMN_OBJPERMANENTID | ATTR_CMN_PAROBJID | \
445 ATTR_CMN_SCRIPT | ATTR_CMN_CRTIME | ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME | \
446 ATTR_CMN_ACCTIME | ATTR_CMN_BKUPTIME | ATTR_CMN_FNDRINFO | ATTR_CMN_OWNERID | \
447 ATTR_CMN_GRPID | ATTR_CMN_ACCESSMASK | ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST| \
448 ATTR_CMN_FLAGS | ATTR_CMN_USERACCESS) != ATTR_CMN_VALIDMASK)
449 #error AttributeBlockSize: Missing bits in common mask computation!
451 assert((attrlist
->commonattr
& ~ATTR_CMN_VALIDMASK
) == 0);
453 #if ((ATTR_VOL_FSTYPE | ATTR_VOL_SIGNATURE | ATTR_VOL_SIZE | ATTR_VOL_SPACEFREE | \
454 ATTR_VOL_SPACEAVAIL | ATTR_VOL_MINALLOCATION | ATTR_VOL_ALLOCATIONCLUMP | ATTR_VOL_IOBLOCKSIZE | \
455 ATTR_VOL_OBJCOUNT | ATTR_VOL_FILECOUNT | ATTR_VOL_DIRCOUNT | ATTR_VOL_MAXOBJCOUNT | \
456 ATTR_VOL_MOUNTPOINT | ATTR_VOL_NAME | ATTR_VOL_MOUNTFLAGS | ATTR_VOL_INFO | \
457 ATTR_VOL_MOUNTEDDEVICE| ATTR_VOL_ENCODINGSUSED | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES) != ATTR_VOL_VALIDMASK)
458 #error AttributeBlockSize: Missing bits in volume mask computation!
460 assert((attrlist
->volattr
& ~ATTR_VOL_VALIDMASK
) == 0);
462 #if ((ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT | ATTR_DIR_MOUNTSTATUS) != ATTR_DIR_VALIDMASK)
463 #error AttributeBlockSize: Missing bits in directory mask computation!
465 assert((attrlist
->dirattr
& ~ATTR_DIR_VALIDMASK
) == 0);
466 #if ((ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE | ATTR_FILE_ALLOCSIZE | ATTR_FILE_IOBLOCKSIZE | \
467 ATTR_FILE_CLUMPSIZE | ATTR_FILE_DEVTYPE | ATTR_FILE_FILETYPE | ATTR_FILE_FORKCOUNT | \
468 ATTR_FILE_FORKLIST | ATTR_FILE_DATALENGTH | ATTR_FILE_DATAALLOCSIZE | ATTR_FILE_DATAEXTENTS | \
469 ATTR_FILE_RSRCLENGTH | ATTR_FILE_RSRCALLOCSIZE | ATTR_FILE_RSRCEXTENTS) != ATTR_FILE_VALIDMASK)
470 #error AttributeBlockSize: Missing bits in file mask computation!
472 assert((attrlist
->fileattr
& ~ATTR_FILE_VALIDMASK
) == 0);
474 #if ((ATTR_FORK_TOTALSIZE | ATTR_FORK_ALLOCSIZE) != ATTR_FORK_VALIDMASK)
475 #error AttributeBlockSize: Missing bits in fork mask computation!
477 assert((attrlist
->forkattr
& ~ATTR_FORK_VALIDMASK
) == 0);
481 if ((a
= attrlist
->commonattr
) != 0) {
482 if (a
& ATTR_CMN_NAME
) size
+= sizeof(struct attrreference
);
483 if (a
& ATTR_CMN_DEVID
) size
+= sizeof(dev_t
);
484 if (a
& ATTR_CMN_FSID
) size
+= sizeof(fsid_t
);
485 if (a
& ATTR_CMN_OBJTYPE
) size
+= sizeof(fsobj_type_t
);
486 if (a
& ATTR_CMN_OBJTAG
) size
+= sizeof(fsobj_tag_t
);
487 if (a
& ATTR_CMN_OBJID
) size
+= sizeof(fsobj_id_t
);
488 if (a
& ATTR_CMN_OBJPERMANENTID
) size
+= sizeof(fsobj_id_t
);
489 if (a
& ATTR_CMN_PAROBJID
) size
+= sizeof(fsobj_id_t
);
490 if (a
& ATTR_CMN_SCRIPT
) size
+= sizeof(text_encoding_t
);
491 if (a
& ATTR_CMN_CRTIME
) {
493 size
+= sizeof(struct user_timespec
);
495 size
+= sizeof(struct timespec
);
497 if (a
& ATTR_CMN_MODTIME
) {
499 size
+= sizeof(struct user_timespec
);
501 size
+= sizeof(struct timespec
);
503 if (a
& ATTR_CMN_CHGTIME
) {
505 size
+= sizeof(struct user_timespec
);
507 size
+= sizeof(struct timespec
);
509 if (a
& ATTR_CMN_ACCTIME
) {
511 size
+= sizeof(struct user_timespec
);
513 size
+= sizeof(struct timespec
);
515 if (a
& ATTR_CMN_BKUPTIME
) {
517 size
+= sizeof(struct user_timespec
);
519 size
+= sizeof(struct timespec
);
521 if (a
& ATTR_CMN_FNDRINFO
) size
+= 32 * sizeof(u_int8_t
);
522 if (a
& ATTR_CMN_OWNERID
) size
+= sizeof(uid_t
);
523 if (a
& ATTR_CMN_GRPID
) size
+= sizeof(gid_t
);
524 if (a
& ATTR_CMN_ACCESSMASK
) size
+= sizeof(uint32_t);
525 if (a
& ATTR_CMN_NAMEDATTRCOUNT
) size
+= sizeof(uint32_t);
526 if (a
& ATTR_CMN_NAMEDATTRLIST
) size
+= sizeof(struct attrreference
);
527 if (a
& ATTR_CMN_FLAGS
) size
+= sizeof(uint32_t);
528 if (a
& ATTR_CMN_USERACCESS
) size
+= sizeof(uint32_t);
530 if ((a
= attrlist
->volattr
) != 0) {
531 if (a
& ATTR_VOL_FSTYPE
) size
+= sizeof(uint32_t);
532 if (a
& ATTR_VOL_SIGNATURE
) size
+= sizeof(uint32_t);
533 if (a
& ATTR_VOL_SIZE
) size
+= sizeof(off_t
);
534 if (a
& ATTR_VOL_SPACEFREE
) size
+= sizeof(off_t
);
535 if (a
& ATTR_VOL_SPACEAVAIL
) size
+= sizeof(off_t
);
536 if (a
& ATTR_VOL_MINALLOCATION
) size
+= sizeof(off_t
);
537 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) size
+= sizeof(off_t
);
538 if (a
& ATTR_VOL_IOBLOCKSIZE
) size
+= sizeof(uint32_t);
539 if (a
& ATTR_VOL_OBJCOUNT
) size
+= sizeof(uint32_t);
540 if (a
& ATTR_VOL_FILECOUNT
) size
+= sizeof(uint32_t);
541 if (a
& ATTR_VOL_DIRCOUNT
) size
+= sizeof(uint32_t);
542 if (a
& ATTR_VOL_MAXOBJCOUNT
) size
+= sizeof(uint32_t);
543 if (a
& ATTR_VOL_MOUNTPOINT
) size
+= sizeof(struct attrreference
);
544 if (a
& ATTR_VOL_NAME
) size
+= sizeof(struct attrreference
);
545 if (a
& ATTR_VOL_MOUNTFLAGS
) size
+= sizeof(uint32_t);
546 if (a
& ATTR_VOL_MOUNTEDDEVICE
) size
+= sizeof(struct attrreference
);
547 if (a
& ATTR_VOL_ENCODINGSUSED
) size
+= sizeof(unsigned long long);
548 if (a
& ATTR_VOL_CAPABILITIES
) size
+= sizeof(vol_capabilities_attr_t
);
549 if (a
& ATTR_VOL_ATTRIBUTES
) size
+= sizeof(vol_attributes_attr_t
);
551 if ((a
= attrlist
->dirattr
) != 0) {
552 if (a
& ATTR_DIR_LINKCOUNT
) size
+= sizeof(uint32_t);
553 if (a
& ATTR_DIR_ENTRYCOUNT
) size
+= sizeof(uint32_t);
554 if (a
& ATTR_DIR_MOUNTSTATUS
) size
+= sizeof(uint32_t);
556 if ((a
= attrlist
->fileattr
) != 0) {
557 if (a
& ATTR_FILE_LINKCOUNT
) size
+= sizeof(uint32_t);
558 if (a
& ATTR_FILE_TOTALSIZE
) size
+= sizeof(off_t
);
559 if (a
& ATTR_FILE_ALLOCSIZE
) size
+= sizeof(off_t
);
560 if (a
& ATTR_FILE_IOBLOCKSIZE
) size
+= sizeof(uint32_t);
561 if (a
& ATTR_FILE_CLUMPSIZE
) size
+= sizeof(uint32_t);
562 if (a
& ATTR_FILE_DEVTYPE
) size
+= sizeof(uint32_t);
563 if (a
& ATTR_FILE_FILETYPE
) size
+= sizeof(uint32_t);
564 if (a
& ATTR_FILE_FORKCOUNT
) size
+= sizeof(uint32_t);
565 if (a
& ATTR_FILE_FORKLIST
) size
+= sizeof(struct attrreference
);
566 if (a
& ATTR_FILE_DATALENGTH
) size
+= sizeof(off_t
);
567 if (a
& ATTR_FILE_DATAALLOCSIZE
) size
+= sizeof(off_t
);
568 if (a
& ATTR_FILE_DATAEXTENTS
) size
+= sizeof(extentrecord
);
569 if (a
& ATTR_FILE_RSRCLENGTH
) size
+= sizeof(off_t
);
570 if (a
& ATTR_FILE_RSRCALLOCSIZE
) size
+= sizeof(off_t
);
571 if (a
& ATTR_FILE_RSRCEXTENTS
) size
+= sizeof(extentrecord
);
573 if ((a
= attrlist
->forkattr
) != 0) {
574 if (a
& ATTR_FORK_TOTALSIZE
) size
+= sizeof(off_t
);
575 if (a
& ATTR_FORK_ALLOCSIZE
) size
+= sizeof(off_t
);
584 packvolattr (struct attrlist
*alist
,
585 struct iso_node
*ip
, /* ip for root directory */
586 void **attrbufptrptr
,
595 boolean_t is_64_bit
= proc_is64bit(current_proc());
597 attrbufptr
= *attrbufptrptr
;
598 varbufptr
= *varbufptrptr
;
602 if ((a
= alist
->commonattr
) != 0) {
603 if (a
& ATTR_CMN_NAME
) {
604 attrlength
= strlen( imp
->volume_id
) + 1;
605 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
606 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
607 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
609 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
610 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
611 ++((struct attrreference
*)attrbufptr
);
613 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = vnode_specrdev(imp
->im_devvp
);
614 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = vfs_statfs(vnode_mount(ITOV(ip
)))->f_fsid
;
615 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = 0;
616 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = VT_ISOFS
;
617 if (a
& ATTR_CMN_OBJID
) {
618 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
619 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
620 ++((fsobj_id_t
*)attrbufptr
);
622 if (a
& ATTR_CMN_OBJPERMANENTID
) {
623 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
624 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
625 ++((fsobj_id_t
*)attrbufptr
);
627 if (a
& ATTR_CMN_PAROBJID
) {
628 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
629 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
630 ++((fsobj_id_t
*)attrbufptr
);
632 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
633 if (a
& ATTR_CMN_CRTIME
) {
635 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
636 tmpp
->tv_sec
= (user_time_t
) imp
->creation_date
.tv_sec
;
637 tmpp
->tv_nsec
= imp
->creation_date
.tv_nsec
;
640 *((struct timespec
*)attrbufptr
)++ = imp
->creation_date
;
643 if (a
& ATTR_CMN_MODTIME
) {
645 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
646 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
647 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
650 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
653 if (a
& ATTR_CMN_CHGTIME
) {
655 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
656 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
657 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
660 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
663 if (a
& ATTR_CMN_ACCTIME
) {
665 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
666 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
667 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
670 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
673 if (a
& ATTR_CMN_BKUPTIME
) {
674 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
675 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
676 ++((struct timespec
*)attrbufptr
);
678 if (a
& ATTR_CMN_FNDRINFO
) {
679 bzero (attrbufptr
, 32 * sizeof(u_int8_t
));
680 (u_int8_t
*)attrbufptr
+= 32 * sizeof(u_int8_t
);
682 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
683 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
684 if (a
& ATTR_CMN_ACCESSMASK
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_mode
;
685 if (a
& ATTR_CMN_FLAGS
) *((uint32_t *)attrbufptr
)++ = 0;
686 if (a
& ATTR_CMN_USERACCESS
) {
687 *((uint32_t *)attrbufptr
)++ =
688 DerivePermissionSummary(ip
->inode
.iso_uid
,
695 if ((a
= alist
->volattr
) != 0) {
696 off_t blocksize
= (off_t
)imp
->logical_block_size
;
698 if (a
& ATTR_VOL_FSTYPE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)vfs_typenum(mp
);
699 if (a
& ATTR_VOL_SIGNATURE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ISO9660SIGNATURE
;
700 if (a
& ATTR_VOL_SIZE
) *((off_t
*)attrbufptr
)++ = (off_t
)imp
->volume_space_size
* blocksize
;
701 if (a
& ATTR_VOL_SPACEFREE
) *((off_t
*)attrbufptr
)++ = 0;
702 if (a
& ATTR_VOL_SPACEAVAIL
) *((off_t
*)attrbufptr
)++ = 0;
703 if (a
& ATTR_VOL_MINALLOCATION
) *((off_t
*)attrbufptr
)++ = blocksize
;
704 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) *((off_t
*)attrbufptr
)++ = blocksize
;
705 if (a
& ATTR_VOL_IOBLOCKSIZE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)blocksize
;
706 if (a
& ATTR_VOL_OBJCOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
707 if (a
& ATTR_VOL_FILECOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
708 if (a
& ATTR_VOL_DIRCOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
709 if (a
& ATTR_VOL_MAXOBJCOUNT
) *((uint32_t *)attrbufptr
)++ = 0xFFFFFFFF;
710 if (a
& ATTR_VOL_NAME
) {
711 attrlength
= strlen( imp
->volume_id
) + 1;
712 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
713 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
714 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
716 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
717 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
718 ++((struct attrreference
*)attrbufptr
);
720 if (a
& ATTR_VOL_MOUNTFLAGS
) {
721 *((uint32_t *)attrbufptr
)++ = (uint32_t)vfs_flags(mp
);
723 if (a
& ATTR_VOL_MOUNTEDDEVICE
) {
724 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
725 ((struct attrreference
*)attrbufptr
)->attr_length
= strlen(vfs_statfs(mp
)->f_mntfromname
) + 1;
726 attrlength
= ((struct attrreference
*)attrbufptr
)->attr_length
;
727 attrlength
= attrlength
+ ((4 - (attrlength
& 3)) & 3); /* round up to the next 4-byte boundary: */
728 (void) bcopy(vfs_statfs(mp
)->f_mntfromname
, varbufptr
, attrlength
);
730 /* Advance beyond the space just allocated: */
731 (u_int8_t
*)varbufptr
+= attrlength
;
732 ++((struct attrreference
*)attrbufptr
);
734 if (a
& ATTR_VOL_ENCODINGSUSED
) *((unsigned long long *)attrbufptr
)++ = (unsigned long long)0;
735 if (a
& ATTR_VOL_CAPABILITIES
) {
736 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_FORMAT
] =
737 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_SYMBOLICLINKS
: 0) |
738 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_HARDLINKS
: 0) |
739 (imp
->iso_ftype
== ISO_FTYPE_RRIP
|| imp
->iso_ftype
== ISO_FTYPE_JOLIET
740 ? VOL_CAP_FMT_CASE_SENSITIVE
: 0) |
741 VOL_CAP_FMT_CASE_PRESERVING
|
742 VOL_CAP_FMT_FAST_STATFS
;
743 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_INTERFACES
] =
744 VOL_CAP_INT_ATTRLIST
|
745 VOL_CAP_INT_NFSEXPORT
;
746 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED1
] = 0;
747 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED2
] = 0;
749 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_FORMAT
] =
750 VOL_CAP_FMT_PERSISTENTOBJECTIDS
|
751 VOL_CAP_FMT_SYMBOLICLINKS
|
752 VOL_CAP_FMT_HARDLINKS
|
753 VOL_CAP_FMT_JOURNAL
|
754 VOL_CAP_FMT_JOURNAL_ACTIVE
|
755 VOL_CAP_FMT_NO_ROOT_TIMES
|
756 VOL_CAP_FMT_SPARSE_FILES
|
757 VOL_CAP_FMT_ZERO_RUNS
|
758 VOL_CAP_FMT_CASE_SENSITIVE
|
759 VOL_CAP_FMT_CASE_PRESERVING
|
760 VOL_CAP_FMT_FAST_STATFS
|
761 VOL_CAP_FMT_2TB_FILESIZE
;
762 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_INTERFACES
] =
763 VOL_CAP_INT_SEARCHFS
|
764 VOL_CAP_INT_ATTRLIST
|
765 VOL_CAP_INT_NFSEXPORT
|
766 VOL_CAP_INT_READDIRATTR
|
767 VOL_CAP_INT_EXCHANGEDATA
|
768 VOL_CAP_INT_COPYFILE
|
769 VOL_CAP_INT_ALLOCATE
|
770 VOL_CAP_INT_VOL_RENAME
|
771 VOL_CAP_INT_ADVLOCK
|
773 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
774 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
776 ++((vol_capabilities_attr_t
*)attrbufptr
);
778 if (a
& ATTR_VOL_ATTRIBUTES
) {
779 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.commonattr
= ATTR_CMN_VALIDMASK
;
780 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.volattr
= ATTR_VOL_VALIDMASK
;
781 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.dirattr
= ATTR_DIR_VALIDMASK
;
782 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.fileattr
= ATTR_FILE_VALIDMASK
;
783 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.forkattr
= ATTR_FORK_VALIDMASK
;
785 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.commonattr
= ATTR_CMN_VALIDMASK
;
786 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.volattr
= ATTR_VOL_VALIDMASK
;
787 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.dirattr
= ATTR_DIR_VALIDMASK
;
788 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.fileattr
= ATTR_FILE_VALIDMASK
;
789 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.forkattr
= ATTR_FORK_VALIDMASK
;
791 ++((vol_attributes_attr_t
*)attrbufptr
);
795 *attrbufptrptr
= attrbufptr
;
796 *varbufptrptr
= varbufptr
;
801 packcommonattr (struct attrlist
*alist
,
803 void **attrbufptrptr
,
810 boolean_t is_64_bit
= proc_is64bit(current_proc());
812 attrbufptr
= *attrbufptrptr
;
813 varbufptr
= *varbufptrptr
;
815 if ((a
= alist
->commonattr
) != 0) {
816 struct iso_mnt
*imp
= ip
->i_mnt
;
818 if (a
& ATTR_CMN_NAME
) {
819 /* special case root since we know how to get it's name */
820 if (vnode_isvroot(ITOV(ip
))) {
821 attrlength
= strlen( imp
->volume_id
) + 1;
822 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
824 attrlength
= strlen(ip
->i_namep
) + 1;
825 (void) strncpy((unsigned char *)varbufptr
, ip
->i_namep
, attrlength
);
828 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
829 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
830 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
831 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
832 ++((struct attrreference
*)attrbufptr
);
834 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = ip
->i_dev
;
835 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = vfs_statfs(vnode_mount(ITOV(ip
)))->f_fsid
;
836 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = vnode_vtype(ITOV(ip
));
837 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = vnode_tag(ITOV(ip
));
838 if (a
& ATTR_CMN_OBJID
) {
839 if (vnode_isvroot(ITOV(ip
)))
840 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
842 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
843 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
844 ++((fsobj_id_t
*)attrbufptr
);
846 if (a
& ATTR_CMN_OBJPERMANENTID
) {
847 if (vnode_isvroot(ITOV(ip
)))
848 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
850 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
851 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
852 ++((fsobj_id_t
*)attrbufptr
);
854 if (a
& ATTR_CMN_PAROBJID
) {
855 struct iso_directory_record
*dp
= (struct iso_directory_record
*)imp
->root
;
856 ino_t rootino
= isodirino(dp
, imp
);
858 if (ip
->i_number
== rootino
)
859 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 1; /* force root parent to be 1 */
860 else if (ip
->i_parent
== rootino
)
861 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
863 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_parent
;
864 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
865 ++((fsobj_id_t
*)attrbufptr
);
867 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
868 if (a
& ATTR_CMN_CRTIME
) {
870 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
871 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_mtime
.tv_sec
;
872 tmpp
->tv_nsec
= ip
->inode
.iso_mtime
.tv_nsec
;
875 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
878 if (a
& ATTR_CMN_MODTIME
) {
880 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
881 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_mtime
.tv_sec
;
882 tmpp
->tv_nsec
= ip
->inode
.iso_mtime
.tv_nsec
;
885 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
888 if (a
& ATTR_CMN_CHGTIME
) {
890 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
891 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_ctime
.tv_sec
;
892 tmpp
->tv_nsec
= ip
->inode
.iso_ctime
.tv_nsec
;
895 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_ctime
;
898 if (a
& ATTR_CMN_ACCTIME
) {
900 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
901 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_atime
.tv_sec
;
902 tmpp
->tv_nsec
= ip
->inode
.iso_atime
.tv_nsec
;
905 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
908 if (a
& ATTR_CMN_BKUPTIME
) {
910 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
911 tmpp
->tv_sec
= (user_time_t
) 0;
915 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
916 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
917 ++((struct timespec
*)attrbufptr
);
918 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
921 if (a
& ATTR_CMN_FNDRINFO
) {
922 struct finder_info finfo
;
924 bzero(&finfo
, sizeof(finfo
));
925 finfo
.fdFlags
= ip
->i_FinderFlags
;
926 finfo
.fdLocation
.v
= -1;
927 finfo
.fdLocation
.h
= -1;
928 if (vnode_isreg(ITOV(ip
))) {
929 finfo
.fdType
= ip
->i_FileType
;
930 finfo
.fdCreator
= ip
->i_Creator
;
932 bcopy (&finfo
, attrbufptr
, sizeof(finfo
));
933 (u_int8_t
*)attrbufptr
+= sizeof(finfo
);
934 bzero (attrbufptr
, EXTFNDRINFOSIZE
);
935 (u_int8_t
*)attrbufptr
+= EXTFNDRINFOSIZE
;
937 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
938 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
939 if (a
& ATTR_CMN_ACCESSMASK
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_mode
;
940 if (a
& ATTR_CMN_FLAGS
) *((uint32_t *)attrbufptr
)++ = 0; /* could also use ip->i_flag */
941 if (a
& ATTR_CMN_USERACCESS
) {
942 *((uint32_t *)attrbufptr
)++ =
943 DerivePermissionSummary(ip
->inode
.iso_uid
,
950 *attrbufptrptr
= attrbufptr
;
951 *varbufptrptr
= varbufptr
;
956 packdirattr(struct attrlist
*alist
,
958 void **attrbufptrptr
,
959 __unused
void **varbufptrptr
)
965 attrbufptr
= *attrbufptrptr
;
969 if (vnode_isdir(ITOV(ip
)) && (a
!= 0)) {
971 * if we haven't counted our children yet, do it now...
973 if ((ip
->i_entries
== 0) &&
974 (a
& (ATTR_DIR_LINKCOUNT
| ATTR_DIR_ENTRYCOUNT
))) {
975 (void) isochildcount(ITOV(ip
), &dircnt
, &filcnt
);
977 if ((ip
->inode
.iso_links
== 1) && (dircnt
!= 0))
978 ip
->inode
.iso_links
= dircnt
;
979 if ((filcnt
+ dircnt
) > 0)
980 ip
->i_entries
= dircnt
+ filcnt
;
983 if (a
& ATTR_DIR_LINKCOUNT
) {
984 *((uint32_t *)attrbufptr
)++ = ip
->inode
.iso_links
;
986 if (a
& ATTR_DIR_ENTRYCOUNT
) {
987 /* exclude '.' and '..' from total caount */
988 *((uint32_t *)attrbufptr
)++ = ((ip
->i_entries
<= 2) ? 0 : (ip
->i_entries
- 2));
990 if (a
& ATTR_DIR_MOUNTSTATUS
) {
991 if (vnode_mountedhere(ITOV(ip
))) {
992 *((uint32_t *)attrbufptr
)++ = DIR_MNTSTATUS_MNTPOINT
;
994 *((uint32_t *)attrbufptr
)++ = 0;
999 *attrbufptrptr
= attrbufptr
;
1004 packfileattr(struct attrlist
*alist
,
1005 struct iso_node
*ip
,
1006 void **attrbufptrptr
,
1007 void **varbufptrptr
)
1009 void *attrbufptr
= *attrbufptrptr
;
1010 void *varbufptr
= *varbufptrptr
;
1011 attrgroup_t a
= alist
->fileattr
;
1013 if (vnode_isreg(ITOV(ip
)) && (a
!= 0)) {
1014 if (a
& ATTR_FILE_LINKCOUNT
)
1015 *((uint32_t *)attrbufptr
)++ = ip
->inode
.iso_links
;
1016 if (a
& ATTR_FILE_TOTALSIZE
)
1017 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1018 if (a
& ATTR_FILE_ALLOCSIZE
)
1019 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1020 if (a
& ATTR_FILE_IOBLOCKSIZE
)
1021 *((uint32_t *)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
1022 if (a
& ATTR_FILE_CLUMPSIZE
)
1023 *((uint32_t *)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
1024 if (a
& ATTR_FILE_DEVTYPE
)
1025 *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_rdev
;
1026 if (a
& ATTR_FILE_DATALENGTH
)
1027 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1028 if (a
& ATTR_FILE_DATAALLOCSIZE
)
1029 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1030 if (a
& ATTR_FILE_RSRCLENGTH
)
1031 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
1032 if (a
& ATTR_FILE_RSRCALLOCSIZE
)
1033 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
1036 *attrbufptrptr
= attrbufptr
;
1037 *varbufptrptr
= varbufptr
;
1042 packattrblk(struct attrlist
*alist
,
1044 void **attrbufptrptr
,
1045 void **varbufptrptr
)
1047 struct iso_node
*ip
= VTOI(vp
);
1049 if (alist
->volattr
!= 0) {
1050 packvolattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1052 packcommonattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1054 switch (vnode_vtype(ITOV(ip
))) {
1056 packdirattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1060 packfileattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1063 /* Without this the compiler complains about VNON,VBLK,VCHR,VLNK,VSOCK,VFIFO,VBAD and VSTR
1064 not being handled...