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>
94 #include <architecture/byte_order.h>
96 #include <isofs/cd9660/iso.h>
97 #include <isofs/cd9660/cd9660_node.h>
98 #include <isofs/cd9660/iso_rrip.h>
101 * translate and compare a filename
102 * Note: Version number plus ';' may be omitted.
105 isofncmp(u_char
*fn
, int fnlen
, u_char
*isofn
, int isolen
)
110 while (--fnlen
>= 0) {
113 if ((c
= *isofn
++) == ';') {
122 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
123 if (*fn
< '0' || *fn
> '9') {
127 for (j
= 0; --isolen
>= 0; j
= j
* 10 + *isofn
++ - '0');
130 /* if raw comparison fails, check if char was mapped */
132 if (c
>= 'A' && c
<= 'Z') {
133 if (c
+ ('a' - 'A') != *fn
) {
134 if (*fn
>= 'a' && *fn
<= 'z')
135 return *fn
- ('a' - 'A') - c
;
139 } else if (c
== '/') {
142 } else if (c
> 0 || *fn
!= '_')
163 * translate and compare a UCS-2 filename
164 * Note: Version number plus ';' may be omitted.
168 ucsfncmp(u_int16_t
*fn
, int fnlen
, u_int16_t
*ucsfn
, int ucslen
)
173 /* convert byte count to char count */
177 while (--fnlen
>= 0) {
180 if ((c
= *ucsfn
++) == UCS_SEPARATOR2
) {
189 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
190 if (*fn
< '0' || *fn
> '9') {
194 for (j
= 0; --ucslen
>= 0; j
= j
* 10 + *ucsfn
++ - '0');
206 if (ucsfn
[1] != UCS_SEPARATOR2
)
217 * translate a filename
220 isofntrans(u_char
*infn
, int infnlen
, u_char
*outfn
, u_short
*outfnlen
,
221 int original
, int assoc
)
226 * Add a "._" prefix for associated files
229 *outfn
++ = ASSOCCHAR1
;
230 *outfn
++ = ASSOCCHAR2
;
234 for (; fnidx
< infnlen
; fnidx
++) {
238 * Some ISO 9600 CD names contain 8-bit chars.
239 * These chars are mapped to '_' because there
240 * is no context for mapping them to UTF-8.
241 * In addition '/' is mapped to ':'.
243 * isofncmp accounts for these mappings.
250 else if (c
== '.' && *infn
== ';')
263 * translate a UCS-2 filename to UTF-8
266 ucsfntrans(u_int16_t
*infn
, int infnlen
, u_char
*outfn
, u_short
*outfnlen
,
272 if (*(u_char
*)infn
== 0)
274 else if (*(u_char
*)infn
== 1)
285 * Add a "._" prefix for associated files
288 *outfn
++ = ASSOCCHAR1
;
289 *outfn
++ = ASSOCCHAR2
;
292 /* strip file version number */
293 for (fnidx
--; fnidx
> 0; fnidx
--) {
294 /* stop when ';' is found */
295 if (infn
[fnidx
] == UCS_SEPARATOR2
) {
296 /* drop dangling dot */
297 if (fnidx
> 0 && infn
[fnidx
-1] == UCS_SEPARATOR1
)
306 flags
= UTF_NO_NULL_TERM
| UTF_DECOMPOSED
;
307 if (BYTE_ORDER
!= BIG_ENDIAN
)
308 flags
|= UTF_REVERSE_ENDIAN
;
310 (void) utf8_encodestr(infn
, fnidx
* 2, outfn
, &outbytes
, ISO_JOLIET_NAMEMAX
, 0, flags
);
311 *outfnlen
= assoc
? outbytes
+ 2 : outbytes
;
317 * count the number of children by enumerating the directory
320 isochildcount(struct vnode
*vdp
, int *dircnt
, int *filcnt
)
323 struct buf
*bp
= NULL
;
325 struct iso_directory_record
*ep
;
336 bmask
= imp
->im_sector_size
- 1;
337 logblksize
= imp
->im_sector_size
;
338 blkoffset
= diroffset
= 0;
341 while (diroffset
< dp
->i_size
) {
343 * If offset is on a block boundary, read the next
344 * directory block. Release previous if it exists.
346 if ((diroffset
& bmask
) == 0) {
349 if ( (error
= cd9660_blkatoff(vdp
, SECTOFF(imp
, diroffset
), NULL
, &bp
)) )
354 ep
= (struct iso_directory_record
*)
355 (buf_dataptr(bp
) + blkoffset
);
357 reclen
= isonum_711(ep
->length
);
359 /* skip to next block, if any */
361 (diroffset
& ~bmask
) + logblksize
;
365 if ((reclen
< ISO_DIRECTORY_RECORD_SIZE
) ||
366 (blkoffset
+ reclen
> logblksize
) ||
367 (reclen
< ISO_DIRECTORY_RECORD_SIZE
+ isonum_711(ep
->name_len
))){
368 /* illegal, so give up */
373 * Some poorly mastered discs have an incorrect directory
374 * file size. If the '.' entry has a better size (bigger)
375 * then use that instead.
377 if ((diroffset
== 0) && (isonum_733(ep
->size
) > dp
->i_size
)) {
378 dp
->i_size
= isonum_733(ep
->size
);
381 if ( isonum_711(ep
->flags
) & directoryBit
)
383 else if ((isonum_711(ep
->flags
) & associatedBit
) == 0)
401 DerivePermissionSummary(uid_t owner
, gid_t group
, mode_t obj_mode
, __unused
struct iso_mnt
*imp
)
403 kauth_cred_t cred
= kauth_cred_get();
404 uint32_t permissions
;
407 /* User id 0 (root) always gets access. */
408 if (!suser(cred
, NULL
)) {
409 permissions
= R_OK
| X_OK
;
413 /* Otherwise, check the owner. */
414 if (owner
== kauth_cred_getuid(cred
)) {
415 permissions
= ((uint32_t)obj_mode
& S_IRWXU
) >> 6;
419 /* Otherwise, check the groups. */
420 if (kauth_cred_ismember_gid(cred
, group
, &is_member
) == 0 && is_member
) {
421 permissions
= ((uint32_t)obj_mode
& S_IRWXG
) >> 3;
425 /* Otherwise, settle for 'others' access. */
426 permissions
= (uint32_t)obj_mode
& S_IRWXO
;
429 return permissions
& ~W_OK
; /* Write access is always impossible */
434 attrcalcsize(struct attrlist
*attrlist
)
438 boolean_t is_64_bit
= proc_is64bit(current_proc());
440 #if ((ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_FSID | ATTR_CMN_OBJTYPE | \
441 ATTR_CMN_OBJTAG | ATTR_CMN_OBJID | ATTR_CMN_OBJPERMANENTID | ATTR_CMN_PAROBJID | \
442 ATTR_CMN_SCRIPT | ATTR_CMN_CRTIME | ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME | \
443 ATTR_CMN_ACCTIME | ATTR_CMN_BKUPTIME | ATTR_CMN_FNDRINFO | ATTR_CMN_OWNERID | \
444 ATTR_CMN_GRPID | ATTR_CMN_ACCESSMASK | ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST| \
445 ATTR_CMN_FLAGS | ATTR_CMN_USERACCESS) != ATTR_CMN_VALIDMASK)
446 #error AttributeBlockSize: Missing bits in common mask computation!
448 assert((attrlist
->commonattr
& ~ATTR_CMN_VALIDMASK
) == 0);
450 #if ((ATTR_VOL_FSTYPE | ATTR_VOL_SIGNATURE | ATTR_VOL_SIZE | ATTR_VOL_SPACEFREE | \
451 ATTR_VOL_SPACEAVAIL | ATTR_VOL_MINALLOCATION | ATTR_VOL_ALLOCATIONCLUMP | ATTR_VOL_IOBLOCKSIZE | \
452 ATTR_VOL_OBJCOUNT | ATTR_VOL_FILECOUNT | ATTR_VOL_DIRCOUNT | ATTR_VOL_MAXOBJCOUNT | \
453 ATTR_VOL_MOUNTPOINT | ATTR_VOL_NAME | ATTR_VOL_MOUNTFLAGS | ATTR_VOL_INFO | \
454 ATTR_VOL_MOUNTEDDEVICE| ATTR_VOL_ENCODINGSUSED | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES) != ATTR_VOL_VALIDMASK)
455 #error AttributeBlockSize: Missing bits in volume mask computation!
457 assert((attrlist
->volattr
& ~ATTR_VOL_VALIDMASK
) == 0);
459 #if ((ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT | ATTR_DIR_MOUNTSTATUS) != ATTR_DIR_VALIDMASK)
460 #error AttributeBlockSize: Missing bits in directory mask computation!
462 assert((attrlist
->dirattr
& ~ATTR_DIR_VALIDMASK
) == 0);
463 #if ((ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE | ATTR_FILE_ALLOCSIZE | ATTR_FILE_IOBLOCKSIZE | \
464 ATTR_FILE_CLUMPSIZE | ATTR_FILE_DEVTYPE | ATTR_FILE_FILETYPE | ATTR_FILE_FORKCOUNT | \
465 ATTR_FILE_FORKLIST | ATTR_FILE_DATALENGTH | ATTR_FILE_DATAALLOCSIZE | ATTR_FILE_DATAEXTENTS | \
466 ATTR_FILE_RSRCLENGTH | ATTR_FILE_RSRCALLOCSIZE | ATTR_FILE_RSRCEXTENTS) != ATTR_FILE_VALIDMASK)
467 #error AttributeBlockSize: Missing bits in file mask computation!
469 assert((attrlist
->fileattr
& ~ATTR_FILE_VALIDMASK
) == 0);
471 #if ((ATTR_FORK_TOTALSIZE | ATTR_FORK_ALLOCSIZE) != ATTR_FORK_VALIDMASK)
472 #error AttributeBlockSize: Missing bits in fork mask computation!
474 assert((attrlist
->forkattr
& ~ATTR_FORK_VALIDMASK
) == 0);
478 if ((a
= attrlist
->commonattr
) != 0) {
479 if (a
& ATTR_CMN_NAME
) size
+= sizeof(struct attrreference
);
480 if (a
& ATTR_CMN_DEVID
) size
+= sizeof(dev_t
);
481 if (a
& ATTR_CMN_FSID
) size
+= sizeof(fsid_t
);
482 if (a
& ATTR_CMN_OBJTYPE
) size
+= sizeof(fsobj_type_t
);
483 if (a
& ATTR_CMN_OBJTAG
) size
+= sizeof(fsobj_tag_t
);
484 if (a
& ATTR_CMN_OBJID
) size
+= sizeof(fsobj_id_t
);
485 if (a
& ATTR_CMN_OBJPERMANENTID
) size
+= sizeof(fsobj_id_t
);
486 if (a
& ATTR_CMN_PAROBJID
) size
+= sizeof(fsobj_id_t
);
487 if (a
& ATTR_CMN_SCRIPT
) size
+= sizeof(text_encoding_t
);
488 if (a
& ATTR_CMN_CRTIME
) {
490 size
+= sizeof(struct user_timespec
);
492 size
+= sizeof(struct timespec
);
494 if (a
& ATTR_CMN_MODTIME
) {
496 size
+= sizeof(struct user_timespec
);
498 size
+= sizeof(struct timespec
);
500 if (a
& ATTR_CMN_CHGTIME
) {
502 size
+= sizeof(struct user_timespec
);
504 size
+= sizeof(struct timespec
);
506 if (a
& ATTR_CMN_ACCTIME
) {
508 size
+= sizeof(struct user_timespec
);
510 size
+= sizeof(struct timespec
);
512 if (a
& ATTR_CMN_BKUPTIME
) {
514 size
+= sizeof(struct user_timespec
);
516 size
+= sizeof(struct timespec
);
518 if (a
& ATTR_CMN_FNDRINFO
) size
+= 32 * sizeof(u_int8_t
);
519 if (a
& ATTR_CMN_OWNERID
) size
+= sizeof(uid_t
);
520 if (a
& ATTR_CMN_GRPID
) size
+= sizeof(gid_t
);
521 if (a
& ATTR_CMN_ACCESSMASK
) size
+= sizeof(uint32_t);
522 if (a
& ATTR_CMN_NAMEDATTRCOUNT
) size
+= sizeof(uint32_t);
523 if (a
& ATTR_CMN_NAMEDATTRLIST
) size
+= sizeof(struct attrreference
);
524 if (a
& ATTR_CMN_FLAGS
) size
+= sizeof(uint32_t);
525 if (a
& ATTR_CMN_USERACCESS
) size
+= sizeof(uint32_t);
527 if ((a
= attrlist
->volattr
) != 0) {
528 if (a
& ATTR_VOL_FSTYPE
) size
+= sizeof(uint32_t);
529 if (a
& ATTR_VOL_SIGNATURE
) size
+= sizeof(uint32_t);
530 if (a
& ATTR_VOL_SIZE
) size
+= sizeof(off_t
);
531 if (a
& ATTR_VOL_SPACEFREE
) size
+= sizeof(off_t
);
532 if (a
& ATTR_VOL_SPACEAVAIL
) size
+= sizeof(off_t
);
533 if (a
& ATTR_VOL_MINALLOCATION
) size
+= sizeof(off_t
);
534 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) size
+= sizeof(off_t
);
535 if (a
& ATTR_VOL_IOBLOCKSIZE
) size
+= sizeof(uint32_t);
536 if (a
& ATTR_VOL_OBJCOUNT
) size
+= sizeof(uint32_t);
537 if (a
& ATTR_VOL_FILECOUNT
) size
+= sizeof(uint32_t);
538 if (a
& ATTR_VOL_DIRCOUNT
) size
+= sizeof(uint32_t);
539 if (a
& ATTR_VOL_MAXOBJCOUNT
) size
+= sizeof(uint32_t);
540 if (a
& ATTR_VOL_MOUNTPOINT
) size
+= sizeof(struct attrreference
);
541 if (a
& ATTR_VOL_NAME
) size
+= sizeof(struct attrreference
);
542 if (a
& ATTR_VOL_MOUNTFLAGS
) size
+= sizeof(uint32_t);
543 if (a
& ATTR_VOL_MOUNTEDDEVICE
) size
+= sizeof(struct attrreference
);
544 if (a
& ATTR_VOL_ENCODINGSUSED
) size
+= sizeof(unsigned long long);
545 if (a
& ATTR_VOL_CAPABILITIES
) size
+= sizeof(vol_capabilities_attr_t
);
546 if (a
& ATTR_VOL_ATTRIBUTES
) size
+= sizeof(vol_attributes_attr_t
);
548 if ((a
= attrlist
->dirattr
) != 0) {
549 if (a
& ATTR_DIR_LINKCOUNT
) size
+= sizeof(uint32_t);
550 if (a
& ATTR_DIR_ENTRYCOUNT
) size
+= sizeof(uint32_t);
551 if (a
& ATTR_DIR_MOUNTSTATUS
) size
+= sizeof(uint32_t);
553 if ((a
= attrlist
->fileattr
) != 0) {
554 if (a
& ATTR_FILE_LINKCOUNT
) size
+= sizeof(uint32_t);
555 if (a
& ATTR_FILE_TOTALSIZE
) size
+= sizeof(off_t
);
556 if (a
& ATTR_FILE_ALLOCSIZE
) size
+= sizeof(off_t
);
557 if (a
& ATTR_FILE_IOBLOCKSIZE
) size
+= sizeof(uint32_t);
558 if (a
& ATTR_FILE_CLUMPSIZE
) size
+= sizeof(uint32_t);
559 if (a
& ATTR_FILE_DEVTYPE
) size
+= sizeof(uint32_t);
560 if (a
& ATTR_FILE_FILETYPE
) size
+= sizeof(uint32_t);
561 if (a
& ATTR_FILE_FORKCOUNT
) size
+= sizeof(uint32_t);
562 if (a
& ATTR_FILE_FORKLIST
) size
+= sizeof(struct attrreference
);
563 if (a
& ATTR_FILE_DATALENGTH
) size
+= sizeof(off_t
);
564 if (a
& ATTR_FILE_DATAALLOCSIZE
) size
+= sizeof(off_t
);
565 if (a
& ATTR_FILE_DATAEXTENTS
) size
+= sizeof(extentrecord
);
566 if (a
& ATTR_FILE_RSRCLENGTH
) size
+= sizeof(off_t
);
567 if (a
& ATTR_FILE_RSRCALLOCSIZE
) size
+= sizeof(off_t
);
568 if (a
& ATTR_FILE_RSRCEXTENTS
) size
+= sizeof(extentrecord
);
570 if ((a
= attrlist
->forkattr
) != 0) {
571 if (a
& ATTR_FORK_TOTALSIZE
) size
+= sizeof(off_t
);
572 if (a
& ATTR_FORK_ALLOCSIZE
) size
+= sizeof(off_t
);
581 packvolattr (struct attrlist
*alist
,
582 struct iso_node
*ip
, /* ip for root directory */
583 void **attrbufptrptr
,
592 boolean_t is_64_bit
= proc_is64bit(current_proc());
594 attrbufptr
= *attrbufptrptr
;
595 varbufptr
= *varbufptrptr
;
599 if ((a
= alist
->commonattr
) != 0) {
600 if (a
& ATTR_CMN_NAME
) {
601 attrlength
= strlen( imp
->volume_id
) + 1;
602 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
603 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
604 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
606 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
607 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
608 ++((struct attrreference
*)attrbufptr
);
610 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = vnode_specrdev(imp
->im_devvp
);
611 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = vfs_statfs(vnode_mount(ITOV(ip
)))->f_fsid
;
612 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = 0;
613 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = VT_ISOFS
;
614 if (a
& ATTR_CMN_OBJID
) {
615 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
616 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
617 ++((fsobj_id_t
*)attrbufptr
);
619 if (a
& ATTR_CMN_OBJPERMANENTID
) {
620 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
621 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
622 ++((fsobj_id_t
*)attrbufptr
);
624 if (a
& ATTR_CMN_PAROBJID
) {
625 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
626 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
627 ++((fsobj_id_t
*)attrbufptr
);
629 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
630 if (a
& ATTR_CMN_CRTIME
) {
632 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
633 tmpp
->tv_sec
= (user_time_t
) imp
->creation_date
.tv_sec
;
634 tmpp
->tv_nsec
= imp
->creation_date
.tv_nsec
;
637 *((struct timespec
*)attrbufptr
)++ = imp
->creation_date
;
640 if (a
& ATTR_CMN_MODTIME
) {
642 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
643 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
644 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
647 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
650 if (a
& ATTR_CMN_CHGTIME
) {
652 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
653 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
654 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
657 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
660 if (a
& ATTR_CMN_ACCTIME
) {
662 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
663 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
664 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
667 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
670 if (a
& ATTR_CMN_BKUPTIME
) {
671 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
672 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
673 ++((struct timespec
*)attrbufptr
);
675 if (a
& ATTR_CMN_FNDRINFO
) {
676 bzero (attrbufptr
, 32 * sizeof(u_int8_t
));
677 (u_int8_t
*)attrbufptr
+= 32 * sizeof(u_int8_t
);
679 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
680 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
681 if (a
& ATTR_CMN_ACCESSMASK
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_mode
;
682 if (a
& ATTR_CMN_FLAGS
) *((uint32_t *)attrbufptr
)++ = 0;
683 if (a
& ATTR_CMN_USERACCESS
) {
684 *((uint32_t *)attrbufptr
)++ =
685 DerivePermissionSummary(ip
->inode
.iso_uid
,
692 if ((a
= alist
->volattr
) != 0) {
693 off_t blocksize
= (off_t
)imp
->logical_block_size
;
695 if (a
& ATTR_VOL_FSTYPE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)vfs_typenum(mp
);
696 if (a
& ATTR_VOL_SIGNATURE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ISO9660SIGNATURE
;
697 if (a
& ATTR_VOL_SIZE
) *((off_t
*)attrbufptr
)++ = (off_t
)imp
->volume_space_size
* blocksize
;
698 if (a
& ATTR_VOL_SPACEFREE
) *((off_t
*)attrbufptr
)++ = 0;
699 if (a
& ATTR_VOL_SPACEAVAIL
) *((off_t
*)attrbufptr
)++ = 0;
700 if (a
& ATTR_VOL_MINALLOCATION
) *((off_t
*)attrbufptr
)++ = blocksize
;
701 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) *((off_t
*)attrbufptr
)++ = blocksize
;
702 if (a
& ATTR_VOL_IOBLOCKSIZE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)blocksize
;
703 if (a
& ATTR_VOL_OBJCOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
704 if (a
& ATTR_VOL_FILECOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
705 if (a
& ATTR_VOL_DIRCOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
706 if (a
& ATTR_VOL_MAXOBJCOUNT
) *((uint32_t *)attrbufptr
)++ = 0xFFFFFFFF;
707 if (a
& ATTR_VOL_NAME
) {
708 attrlength
= strlen( imp
->volume_id
) + 1;
709 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
710 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
711 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
713 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
714 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
715 ++((struct attrreference
*)attrbufptr
);
717 if (a
& ATTR_VOL_MOUNTFLAGS
) {
718 *((uint32_t *)attrbufptr
)++ = (uint32_t)vfs_flags(mp
);
720 if (a
& ATTR_VOL_MOUNTEDDEVICE
) {
721 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
722 ((struct attrreference
*)attrbufptr
)->attr_length
= strlen(vfs_statfs(mp
)->f_mntfromname
) + 1;
723 attrlength
= ((struct attrreference
*)attrbufptr
)->attr_length
;
724 attrlength
= attrlength
+ ((4 - (attrlength
& 3)) & 3); /* round up to the next 4-byte boundary: */
725 (void) bcopy(vfs_statfs(mp
)->f_mntfromname
, varbufptr
, attrlength
);
727 /* Advance beyond the space just allocated: */
728 (u_int8_t
*)varbufptr
+= attrlength
;
729 ++((struct attrreference
*)attrbufptr
);
731 if (a
& ATTR_VOL_ENCODINGSUSED
) *((unsigned long long *)attrbufptr
)++ = (unsigned long long)0;
732 if (a
& ATTR_VOL_CAPABILITIES
) {
733 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_FORMAT
] =
734 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_SYMBOLICLINKS
: 0) |
735 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_HARDLINKS
: 0) |
736 (imp
->iso_ftype
== ISO_FTYPE_RRIP
|| imp
->iso_ftype
== ISO_FTYPE_JOLIET
737 ? VOL_CAP_FMT_CASE_SENSITIVE
: 0) |
738 VOL_CAP_FMT_CASE_PRESERVING
|
739 VOL_CAP_FMT_FAST_STATFS
;
740 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_INTERFACES
] =
741 VOL_CAP_INT_ATTRLIST
|
742 VOL_CAP_INT_NFSEXPORT
;
743 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED1
] = 0;
744 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED2
] = 0;
746 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_FORMAT
] =
747 VOL_CAP_FMT_PERSISTENTOBJECTIDS
|
748 VOL_CAP_FMT_SYMBOLICLINKS
|
749 VOL_CAP_FMT_HARDLINKS
|
750 VOL_CAP_FMT_JOURNAL
|
751 VOL_CAP_FMT_JOURNAL_ACTIVE
|
752 VOL_CAP_FMT_NO_ROOT_TIMES
|
753 VOL_CAP_FMT_SPARSE_FILES
|
754 VOL_CAP_FMT_ZERO_RUNS
|
755 VOL_CAP_FMT_CASE_SENSITIVE
|
756 VOL_CAP_FMT_CASE_PRESERVING
|
757 VOL_CAP_FMT_FAST_STATFS
|
758 VOL_CAP_FMT_2TB_FILESIZE
;
759 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_INTERFACES
] =
760 VOL_CAP_INT_SEARCHFS
|
761 VOL_CAP_INT_ATTRLIST
|
762 VOL_CAP_INT_NFSEXPORT
|
763 VOL_CAP_INT_READDIRATTR
|
764 VOL_CAP_INT_EXCHANGEDATA
|
765 VOL_CAP_INT_COPYFILE
|
766 VOL_CAP_INT_ALLOCATE
|
767 VOL_CAP_INT_VOL_RENAME
|
768 VOL_CAP_INT_ADVLOCK
|
770 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
771 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
773 ++((vol_capabilities_attr_t
*)attrbufptr
);
775 if (a
& ATTR_VOL_ATTRIBUTES
) {
776 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.commonattr
= ATTR_CMN_VALIDMASK
;
777 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.volattr
= ATTR_VOL_VALIDMASK
;
778 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.dirattr
= ATTR_DIR_VALIDMASK
;
779 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.fileattr
= ATTR_FILE_VALIDMASK
;
780 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.forkattr
= ATTR_FORK_VALIDMASK
;
782 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.commonattr
= ATTR_CMN_VALIDMASK
;
783 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.volattr
= ATTR_VOL_VALIDMASK
;
784 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.dirattr
= ATTR_DIR_VALIDMASK
;
785 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.fileattr
= ATTR_FILE_VALIDMASK
;
786 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.forkattr
= ATTR_FORK_VALIDMASK
;
788 ++((vol_attributes_attr_t
*)attrbufptr
);
792 *attrbufptrptr
= attrbufptr
;
793 *varbufptrptr
= varbufptr
;
798 packcommonattr (struct attrlist
*alist
,
800 void **attrbufptrptr
,
807 boolean_t is_64_bit
= proc_is64bit(current_proc());
809 attrbufptr
= *attrbufptrptr
;
810 varbufptr
= *varbufptrptr
;
812 if ((a
= alist
->commonattr
) != 0) {
813 struct iso_mnt
*imp
= ip
->i_mnt
;
815 if (a
& ATTR_CMN_NAME
) {
816 /* special case root since we know how to get it's name */
817 if (vnode_isvroot(ITOV(ip
))) {
818 attrlength
= strlen( imp
->volume_id
) + 1;
819 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
821 attrlength
= strlen(ip
->i_namep
) + 1;
822 (void) strncpy((unsigned char *)varbufptr
, ip
->i_namep
, attrlength
);
825 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
826 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
827 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
828 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
829 ++((struct attrreference
*)attrbufptr
);
831 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = ip
->i_dev
;
832 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = vfs_statfs(vnode_mount(ITOV(ip
)))->f_fsid
;
833 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = vnode_vtype(ITOV(ip
));
834 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = vnode_tag(ITOV(ip
));
835 if (a
& ATTR_CMN_OBJID
) {
836 if (vnode_isvroot(ITOV(ip
)))
837 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
839 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
840 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
841 ++((fsobj_id_t
*)attrbufptr
);
843 if (a
& ATTR_CMN_OBJPERMANENTID
) {
844 if (vnode_isvroot(ITOV(ip
)))
845 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
847 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
848 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
849 ++((fsobj_id_t
*)attrbufptr
);
851 if (a
& ATTR_CMN_PAROBJID
) {
852 struct iso_directory_record
*dp
= (struct iso_directory_record
*)imp
->root
;
853 ino_t rootino
= isodirino(dp
, imp
);
855 if (ip
->i_number
== rootino
)
856 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 1; /* force root parent to be 1 */
857 else if (ip
->i_parent
== rootino
)
858 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
860 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_parent
;
861 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
862 ++((fsobj_id_t
*)attrbufptr
);
864 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
865 if (a
& ATTR_CMN_CRTIME
) {
867 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
868 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_mtime
.tv_sec
;
869 tmpp
->tv_nsec
= ip
->inode
.iso_mtime
.tv_nsec
;
872 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
875 if (a
& ATTR_CMN_MODTIME
) {
877 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
878 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_mtime
.tv_sec
;
879 tmpp
->tv_nsec
= ip
->inode
.iso_mtime
.tv_nsec
;
882 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
885 if (a
& ATTR_CMN_CHGTIME
) {
887 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
888 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_ctime
.tv_sec
;
889 tmpp
->tv_nsec
= ip
->inode
.iso_ctime
.tv_nsec
;
892 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_ctime
;
895 if (a
& ATTR_CMN_ACCTIME
) {
897 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
898 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_atime
.tv_sec
;
899 tmpp
->tv_nsec
= ip
->inode
.iso_atime
.tv_nsec
;
902 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
905 if (a
& ATTR_CMN_BKUPTIME
) {
907 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
908 tmpp
->tv_sec
= (user_time_t
) 0;
912 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
913 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
914 ++((struct timespec
*)attrbufptr
);
915 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
918 if (a
& ATTR_CMN_FNDRINFO
) {
919 struct finder_info finfo
;
921 bzero(&finfo
, sizeof(finfo
));
922 finfo
.fdFlags
= ip
->i_FinderFlags
;
923 finfo
.fdLocation
.v
= -1;
924 finfo
.fdLocation
.h
= -1;
925 if (vnode_isreg(ITOV(ip
))) {
926 finfo
.fdType
= ip
->i_FileType
;
927 finfo
.fdCreator
= ip
->i_Creator
;
929 bcopy (&finfo
, attrbufptr
, sizeof(finfo
));
930 (u_int8_t
*)attrbufptr
+= sizeof(finfo
);
931 bzero (attrbufptr
, EXTFNDRINFOSIZE
);
932 (u_int8_t
*)attrbufptr
+= EXTFNDRINFOSIZE
;
934 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
935 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
936 if (a
& ATTR_CMN_ACCESSMASK
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_mode
;
937 if (a
& ATTR_CMN_FLAGS
) *((uint32_t *)attrbufptr
)++ = 0; /* could also use ip->i_flag */
938 if (a
& ATTR_CMN_USERACCESS
) {
939 *((uint32_t *)attrbufptr
)++ =
940 DerivePermissionSummary(ip
->inode
.iso_uid
,
947 *attrbufptrptr
= attrbufptr
;
948 *varbufptrptr
= varbufptr
;
953 packdirattr(struct attrlist
*alist
,
955 void **attrbufptrptr
,
956 __unused
void **varbufptrptr
)
962 attrbufptr
= *attrbufptrptr
;
966 if (vnode_isdir(ITOV(ip
)) && (a
!= 0)) {
968 * if we haven't counted our children yet, do it now...
970 if ((ip
->i_entries
== 0) &&
971 (a
& (ATTR_DIR_LINKCOUNT
| ATTR_DIR_ENTRYCOUNT
))) {
972 (void) isochildcount(ITOV(ip
), &dircnt
, &filcnt
);
974 if ((ip
->inode
.iso_links
== 1) && (dircnt
!= 0))
975 ip
->inode
.iso_links
= dircnt
;
976 if ((filcnt
+ dircnt
) > 0)
977 ip
->i_entries
= dircnt
+ filcnt
;
980 if (a
& ATTR_DIR_LINKCOUNT
) {
981 *((uint32_t *)attrbufptr
)++ = ip
->inode
.iso_links
;
983 if (a
& ATTR_DIR_ENTRYCOUNT
) {
984 /* exclude '.' and '..' from total caount */
985 *((uint32_t *)attrbufptr
)++ = ((ip
->i_entries
<= 2) ? 0 : (ip
->i_entries
- 2));
987 if (a
& ATTR_DIR_MOUNTSTATUS
) {
988 if (vnode_mountedhere(ITOV(ip
))) {
989 *((uint32_t *)attrbufptr
)++ = DIR_MNTSTATUS_MNTPOINT
;
991 *((uint32_t *)attrbufptr
)++ = 0;
996 *attrbufptrptr
= attrbufptr
;
1001 packfileattr(struct attrlist
*alist
,
1002 struct iso_node
*ip
,
1003 void **attrbufptrptr
,
1004 void **varbufptrptr
)
1006 void *attrbufptr
= *attrbufptrptr
;
1007 void *varbufptr
= *varbufptrptr
;
1008 attrgroup_t a
= alist
->fileattr
;
1010 if (vnode_isreg(ITOV(ip
)) && (a
!= 0)) {
1011 if (a
& ATTR_FILE_LINKCOUNT
)
1012 *((uint32_t *)attrbufptr
)++ = ip
->inode
.iso_links
;
1013 if (a
& ATTR_FILE_TOTALSIZE
)
1014 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1015 if (a
& ATTR_FILE_ALLOCSIZE
)
1016 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1017 if (a
& ATTR_FILE_IOBLOCKSIZE
)
1018 *((uint32_t *)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
1019 if (a
& ATTR_FILE_CLUMPSIZE
)
1020 *((uint32_t *)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
1021 if (a
& ATTR_FILE_DEVTYPE
)
1022 *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_rdev
;
1023 if (a
& ATTR_FILE_DATALENGTH
)
1024 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1025 if (a
& ATTR_FILE_DATAALLOCSIZE
)
1026 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1027 if (a
& ATTR_FILE_RSRCLENGTH
)
1028 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
1029 if (a
& ATTR_FILE_RSRCALLOCSIZE
)
1030 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
1033 *attrbufptrptr
= attrbufptr
;
1034 *varbufptrptr
= varbufptr
;
1039 packattrblk(struct attrlist
*alist
,
1041 void **attrbufptrptr
,
1042 void **varbufptrptr
)
1044 struct iso_node
*ip
= VTOI(vp
);
1046 if (alist
->volattr
!= 0) {
1047 packvolattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1049 packcommonattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1051 switch (vnode_vtype(ITOV(ip
))) {
1053 packdirattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1057 packfileattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1060 /* Without this the compiler complains about VNON,VBLK,VCHR,VLNK,VSOCK,VFIFO,VBAD and VSTR
1061 not being handled...