2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* $NetBSD: cd9660_util.c,v 1.8 1994/12/13 22:33:25 mycroft Exp $ */
34 * The Regents of the University of California. All rights reserved.
36 * This code is derived from software contributed to Berkeley
37 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
38 * Support code is derived from software contributed to Berkeley
39 * by Atsushi Murai (amurai@spec.co.jp).
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * This product includes software developed by the University of
52 * California, Berkeley and its contributors.
53 * 4. Neither the name of the University nor the names of its contributors
54 * may be used to endorse or promote products derived from this software
55 * without specific prior written permission.
57 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * @(#)cd9660_util.c 8.3 (Berkeley) 12/5/94
72 * 7-Dec-98 Add ATTR_VOL_MOUNTFLAGS attribute support - djb
73 * 18-Nov-98 Add support for volfs - djb
76 #include <sys/param.h>
77 #include <sys/systm.h>
78 #include <sys/vnode.h>
79 #include <sys/mount.h>
80 #include <sys/namei.h>
81 #include <sys/resourcevar.h>
82 #include <sys/kernel.h>
87 #include <sys/kauth.h>
89 #include <sys/utfconv.h>
90 #include <miscfs/specfs/specdev.h> /* XXX */
91 #include <miscfs/fifofs/fifo.h> /* XXX */
92 #include <sys/malloc.h>
95 #include <kern/assert.h>
96 #include <architecture/byte_order.h>
98 #include <isofs/cd9660/iso.h>
99 #include <isofs/cd9660/cd9660_node.h>
100 #include <isofs/cd9660/iso_rrip.h>
103 * translate and compare a filename
104 * Note: Version number plus ';' may be omitted.
107 isofncmp(u_char
*fn
, int fnlen
, u_char
*isofn
, int isolen
)
112 while (--fnlen
>= 0) {
115 if ((c
= *isofn
++) == ';') {
124 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
125 if (*fn
< '0' || *fn
> '9') {
129 for (j
= 0; --isolen
>= 0; j
= j
* 10 + *isofn
++ - '0');
132 /* if raw comparison fails, check if char was mapped */
134 if (c
>= 'A' && c
<= 'Z') {
135 if (c
+ ('a' - 'A') != *fn
) {
136 if (*fn
>= 'a' && *fn
<= 'z')
137 return *fn
- ('a' - 'A') - c
;
141 } else if (c
== '/') {
144 } else if (c
> 0 || *fn
!= '_')
165 * translate and compare a UCS-2 filename
166 * Note: Version number plus ';' may be omitted.
170 ucsfncmp(u_int16_t
*fn
, int fnlen
, u_int16_t
*ucsfn
, int 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(u_char
*infn
, int infnlen
, u_char
*outfn
, u_short
*outfnlen
,
223 int original
, int assoc
)
228 * Add a "._" prefix for associated files
231 *outfn
++ = ASSOCCHAR1
;
232 *outfn
++ = ASSOCCHAR2
;
236 for (; fnidx
< infnlen
; fnidx
++) {
240 * Some ISO 9600 CD names contain 8-bit chars.
241 * These chars are mapped to '_' because there
242 * is no context for mapping them to UTF-8.
243 * In addition '/' is mapped to ':'.
245 * isofncmp accounts for these mappings.
252 else if (c
== '.' && *infn
== ';')
265 * translate a UCS-2 filename to UTF-8
268 ucsfntrans(u_int16_t
*infn
, int infnlen
, u_char
*outfn
, u_short
*outfnlen
,
274 if (*(u_char
*)infn
== 0)
276 else if (*(u_char
*)infn
== 1)
287 * Add a "._" prefix for associated files
290 *outfn
++ = ASSOCCHAR1
;
291 *outfn
++ = ASSOCCHAR2
;
294 /* strip file version number */
295 for (fnidx
--; fnidx
> 0; fnidx
--) {
296 /* stop when ';' is found */
297 if (infn
[fnidx
] == UCS_SEPARATOR2
) {
298 /* drop dangling dot */
299 if (fnidx
> 0 && infn
[fnidx
-1] == UCS_SEPARATOR1
)
308 flags
= UTF_NO_NULL_TERM
| UTF_DECOMPOSED
;
309 if (BYTE_ORDER
!= BIG_ENDIAN
)
310 flags
|= UTF_REVERSE_ENDIAN
;
312 (void) utf8_encodestr(infn
, fnidx
* 2, outfn
, &outbytes
, ISO_JOLIET_NAMEMAX
, 0, flags
);
313 *outfnlen
= assoc
? outbytes
+ 2 : outbytes
;
319 * count the number of children by enumerating the directory
322 isochildcount(struct vnode
*vdp
, int *dircnt
, int *filcnt
)
325 struct buf
*bp
= NULL
;
327 struct iso_directory_record
*ep
;
338 bmask
= imp
->im_sector_size
- 1;
339 logblksize
= imp
->im_sector_size
;
340 blkoffset
= diroffset
= 0;
343 while (diroffset
< dp
->i_size
) {
345 * If offset is on a block boundary, read the next
346 * directory block. Release previous if it exists.
348 if ((diroffset
& bmask
) == 0) {
351 if ( (error
= cd9660_blkatoff(vdp
, SECTOFF(imp
, diroffset
), NULL
, &bp
)) )
356 ep
= (struct iso_directory_record
*)
357 (buf_dataptr(bp
) + blkoffset
);
359 reclen
= isonum_711(ep
->length
);
361 /* skip to next block, if any */
363 (diroffset
& ~bmask
) + logblksize
;
367 if ((reclen
< ISO_DIRECTORY_RECORD_SIZE
) ||
368 (blkoffset
+ reclen
> logblksize
) ||
369 (reclen
< ISO_DIRECTORY_RECORD_SIZE
+ isonum_711(ep
->name_len
))){
370 /* illegal, so give up */
375 * Some poorly mastered discs have an incorrect directory
376 * file size. If the '.' entry has a better size (bigger)
377 * then use that instead.
379 if ((diroffset
== 0) && (isonum_733(ep
->size
) > dp
->i_size
)) {
380 dp
->i_size
= isonum_733(ep
->size
);
383 if ( isonum_711(ep
->flags
) & directoryBit
)
385 else if ((isonum_711(ep
->flags
) & associatedBit
) == 0)
403 DerivePermissionSummary(uid_t owner
, gid_t group
, mode_t obj_mode
, __unused
struct iso_mnt
*imp
)
405 kauth_cred_t cred
= kauth_cred_get();
406 uint32_t permissions
;
409 /* User id 0 (root) always gets access. */
410 if (!suser(cred
, NULL
)) {
411 permissions
= R_OK
| X_OK
;
415 /* Otherwise, check the owner. */
416 if (owner
== kauth_cred_getuid(cred
)) {
417 permissions
= ((uint32_t)obj_mode
& S_IRWXU
) >> 6;
421 /* Otherwise, check the groups. */
422 if (kauth_cred_ismember_gid(cred
, group
, &is_member
) == 0 && is_member
) {
423 permissions
= ((uint32_t)obj_mode
& S_IRWXG
) >> 3;
427 /* Otherwise, settle for 'others' access. */
428 permissions
= (uint32_t)obj_mode
& S_IRWXO
;
431 return permissions
& ~W_OK
; /* Write access is always impossible */
436 attrcalcsize(struct attrlist
*attrlist
)
440 boolean_t is_64_bit
= proc_is64bit(current_proc());
442 #if ((ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_FSID | ATTR_CMN_OBJTYPE | \
443 ATTR_CMN_OBJTAG | ATTR_CMN_OBJID | ATTR_CMN_OBJPERMANENTID | ATTR_CMN_PAROBJID | \
444 ATTR_CMN_SCRIPT | ATTR_CMN_CRTIME | ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME | \
445 ATTR_CMN_ACCTIME | ATTR_CMN_BKUPTIME | ATTR_CMN_FNDRINFO | ATTR_CMN_OWNERID | \
446 ATTR_CMN_GRPID | ATTR_CMN_ACCESSMASK | ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST| \
447 ATTR_CMN_FLAGS | ATTR_CMN_USERACCESS) != ATTR_CMN_VALIDMASK)
448 #error AttributeBlockSize: Missing bits in common mask computation!
450 assert((attrlist
->commonattr
& ~ATTR_CMN_VALIDMASK
) == 0);
452 #if ((ATTR_VOL_FSTYPE | ATTR_VOL_SIGNATURE | ATTR_VOL_SIZE | ATTR_VOL_SPACEFREE | \
453 ATTR_VOL_SPACEAVAIL | ATTR_VOL_MINALLOCATION | ATTR_VOL_ALLOCATIONCLUMP | ATTR_VOL_IOBLOCKSIZE | \
454 ATTR_VOL_OBJCOUNT | ATTR_VOL_FILECOUNT | ATTR_VOL_DIRCOUNT | ATTR_VOL_MAXOBJCOUNT | \
455 ATTR_VOL_MOUNTPOINT | ATTR_VOL_NAME | ATTR_VOL_MOUNTFLAGS | ATTR_VOL_INFO | \
456 ATTR_VOL_MOUNTEDDEVICE| ATTR_VOL_ENCODINGSUSED | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES) != ATTR_VOL_VALIDMASK)
457 #error AttributeBlockSize: Missing bits in volume mask computation!
459 assert((attrlist
->volattr
& ~ATTR_VOL_VALIDMASK
) == 0);
461 #if ((ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT | ATTR_DIR_MOUNTSTATUS) != ATTR_DIR_VALIDMASK)
462 #error AttributeBlockSize: Missing bits in directory mask computation!
464 assert((attrlist
->dirattr
& ~ATTR_DIR_VALIDMASK
) == 0);
465 #if ((ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE | ATTR_FILE_ALLOCSIZE | ATTR_FILE_IOBLOCKSIZE | \
466 ATTR_FILE_CLUMPSIZE | ATTR_FILE_DEVTYPE | ATTR_FILE_FILETYPE | ATTR_FILE_FORKCOUNT | \
467 ATTR_FILE_FORKLIST | ATTR_FILE_DATALENGTH | ATTR_FILE_DATAALLOCSIZE | ATTR_FILE_DATAEXTENTS | \
468 ATTR_FILE_RSRCLENGTH | ATTR_FILE_RSRCALLOCSIZE | ATTR_FILE_RSRCEXTENTS) != ATTR_FILE_VALIDMASK)
469 #error AttributeBlockSize: Missing bits in file mask computation!
471 assert((attrlist
->fileattr
& ~ATTR_FILE_VALIDMASK
) == 0);
473 #if ((ATTR_FORK_TOTALSIZE | ATTR_FORK_ALLOCSIZE) != ATTR_FORK_VALIDMASK)
474 #error AttributeBlockSize: Missing bits in fork mask computation!
476 assert((attrlist
->forkattr
& ~ATTR_FORK_VALIDMASK
) == 0);
480 if ((a
= attrlist
->commonattr
) != 0) {
481 if (a
& ATTR_CMN_NAME
) size
+= sizeof(struct attrreference
);
482 if (a
& ATTR_CMN_DEVID
) size
+= sizeof(dev_t
);
483 if (a
& ATTR_CMN_FSID
) size
+= sizeof(fsid_t
);
484 if (a
& ATTR_CMN_OBJTYPE
) size
+= sizeof(fsobj_type_t
);
485 if (a
& ATTR_CMN_OBJTAG
) size
+= sizeof(fsobj_tag_t
);
486 if (a
& ATTR_CMN_OBJID
) size
+= sizeof(fsobj_id_t
);
487 if (a
& ATTR_CMN_OBJPERMANENTID
) size
+= sizeof(fsobj_id_t
);
488 if (a
& ATTR_CMN_PAROBJID
) size
+= sizeof(fsobj_id_t
);
489 if (a
& ATTR_CMN_SCRIPT
) size
+= sizeof(text_encoding_t
);
490 if (a
& ATTR_CMN_CRTIME
) {
492 size
+= sizeof(struct user_timespec
);
494 size
+= sizeof(struct timespec
);
496 if (a
& ATTR_CMN_MODTIME
) {
498 size
+= sizeof(struct user_timespec
);
500 size
+= sizeof(struct timespec
);
502 if (a
& ATTR_CMN_CHGTIME
) {
504 size
+= sizeof(struct user_timespec
);
506 size
+= sizeof(struct timespec
);
508 if (a
& ATTR_CMN_ACCTIME
) {
510 size
+= sizeof(struct user_timespec
);
512 size
+= sizeof(struct timespec
);
514 if (a
& ATTR_CMN_BKUPTIME
) {
516 size
+= sizeof(struct user_timespec
);
518 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(uint32_t);
524 if (a
& ATTR_CMN_NAMEDATTRCOUNT
) size
+= sizeof(uint32_t);
525 if (a
& ATTR_CMN_NAMEDATTRLIST
) size
+= sizeof(struct attrreference
);
526 if (a
& ATTR_CMN_FLAGS
) size
+= sizeof(uint32_t);
527 if (a
& ATTR_CMN_USERACCESS
) size
+= sizeof(uint32_t);
529 if ((a
= attrlist
->volattr
) != 0) {
530 if (a
& ATTR_VOL_FSTYPE
) size
+= sizeof(uint32_t);
531 if (a
& ATTR_VOL_SIGNATURE
) size
+= sizeof(uint32_t);
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(uint32_t);
538 if (a
& ATTR_VOL_OBJCOUNT
) size
+= sizeof(uint32_t);
539 if (a
& ATTR_VOL_FILECOUNT
) size
+= sizeof(uint32_t);
540 if (a
& ATTR_VOL_DIRCOUNT
) size
+= sizeof(uint32_t);
541 if (a
& ATTR_VOL_MAXOBJCOUNT
) size
+= sizeof(uint32_t);
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(uint32_t);
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(uint32_t);
552 if (a
& ATTR_DIR_ENTRYCOUNT
) size
+= sizeof(uint32_t);
553 if (a
& ATTR_DIR_MOUNTSTATUS
) size
+= sizeof(uint32_t);
555 if ((a
= attrlist
->fileattr
) != 0) {
556 if (a
& ATTR_FILE_LINKCOUNT
) size
+= sizeof(uint32_t);
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(uint32_t);
560 if (a
& ATTR_FILE_CLUMPSIZE
) size
+= sizeof(uint32_t);
561 if (a
& ATTR_FILE_DEVTYPE
) size
+= sizeof(uint32_t);
562 if (a
& ATTR_FILE_FILETYPE
) size
+= sizeof(uint32_t);
563 if (a
& ATTR_FILE_FORKCOUNT
) size
+= sizeof(uint32_t);
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
,
594 boolean_t is_64_bit
= proc_is64bit(current_proc());
596 attrbufptr
= *attrbufptrptr
;
597 varbufptr
= *varbufptrptr
;
601 if ((a
= alist
->commonattr
) != 0) {
602 if (a
& ATTR_CMN_NAME
) {
603 attrlength
= strlen( imp
->volume_id
) + 1;
604 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
605 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
606 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
608 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
609 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
610 ++((struct attrreference
*)attrbufptr
);
612 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = vnode_specrdev(imp
->im_devvp
);
613 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = vfs_statfs(vnode_mount(ITOV(ip
)))->f_fsid
;
614 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = 0;
615 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = VT_ISOFS
;
616 if (a
& ATTR_CMN_OBJID
) {
617 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
618 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
619 ++((fsobj_id_t
*)attrbufptr
);
621 if (a
& ATTR_CMN_OBJPERMANENTID
) {
622 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
623 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
624 ++((fsobj_id_t
*)attrbufptr
);
626 if (a
& ATTR_CMN_PAROBJID
) {
627 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
628 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
629 ++((fsobj_id_t
*)attrbufptr
);
631 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
632 if (a
& ATTR_CMN_CRTIME
) {
634 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
635 tmpp
->tv_sec
= (user_time_t
) imp
->creation_date
.tv_sec
;
636 tmpp
->tv_nsec
= imp
->creation_date
.tv_nsec
;
639 *((struct timespec
*)attrbufptr
)++ = imp
->creation_date
;
642 if (a
& ATTR_CMN_MODTIME
) {
644 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
645 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
646 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
649 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
652 if (a
& ATTR_CMN_CHGTIME
) {
654 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
655 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
656 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
659 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
662 if (a
& ATTR_CMN_ACCTIME
) {
664 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
665 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
666 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
669 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
672 if (a
& ATTR_CMN_BKUPTIME
) {
673 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
674 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
675 ++((struct timespec
*)attrbufptr
);
677 if (a
& ATTR_CMN_FNDRINFO
) {
678 bzero (attrbufptr
, 32 * sizeof(u_int8_t
));
679 (u_int8_t
*)attrbufptr
+= 32 * sizeof(u_int8_t
);
681 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
682 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
683 if (a
& ATTR_CMN_ACCESSMASK
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_mode
;
684 if (a
& ATTR_CMN_FLAGS
) *((uint32_t *)attrbufptr
)++ = 0;
685 if (a
& ATTR_CMN_USERACCESS
) {
686 *((uint32_t *)attrbufptr
)++ =
687 DerivePermissionSummary(ip
->inode
.iso_uid
,
694 if ((a
= alist
->volattr
) != 0) {
695 off_t blocksize
= (off_t
)imp
->logical_block_size
;
697 if (a
& ATTR_VOL_FSTYPE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)vfs_typenum(mp
);
698 if (a
& ATTR_VOL_SIGNATURE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ISO9660SIGNATURE
;
699 if (a
& ATTR_VOL_SIZE
) *((off_t
*)attrbufptr
)++ = (off_t
)imp
->volume_space_size
* blocksize
;
700 if (a
& ATTR_VOL_SPACEFREE
) *((off_t
*)attrbufptr
)++ = 0;
701 if (a
& ATTR_VOL_SPACEAVAIL
) *((off_t
*)attrbufptr
)++ = 0;
702 if (a
& ATTR_VOL_MINALLOCATION
) *((off_t
*)attrbufptr
)++ = blocksize
;
703 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) *((off_t
*)attrbufptr
)++ = blocksize
;
704 if (a
& ATTR_VOL_IOBLOCKSIZE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)blocksize
;
705 if (a
& ATTR_VOL_OBJCOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
706 if (a
& ATTR_VOL_FILECOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
707 if (a
& ATTR_VOL_DIRCOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
708 if (a
& ATTR_VOL_MAXOBJCOUNT
) *((uint32_t *)attrbufptr
)++ = 0xFFFFFFFF;
709 if (a
& ATTR_VOL_NAME
) {
710 attrlength
= strlen( imp
->volume_id
) + 1;
711 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
712 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
713 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
715 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
716 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
717 ++((struct attrreference
*)attrbufptr
);
719 if (a
& ATTR_VOL_MOUNTFLAGS
) {
720 *((uint32_t *)attrbufptr
)++ = (uint32_t)vfs_flags(mp
);
722 if (a
& ATTR_VOL_MOUNTEDDEVICE
) {
723 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
724 ((struct attrreference
*)attrbufptr
)->attr_length
= strlen(vfs_statfs(mp
)->f_mntfromname
) + 1;
725 attrlength
= ((struct attrreference
*)attrbufptr
)->attr_length
;
726 attrlength
= attrlength
+ ((4 - (attrlength
& 3)) & 3); /* round up to the next 4-byte boundary: */
727 (void) bcopy(vfs_statfs(mp
)->f_mntfromname
, varbufptr
, attrlength
);
729 /* Advance beyond the space just allocated: */
730 (u_int8_t
*)varbufptr
+= attrlength
;
731 ++((struct attrreference
*)attrbufptr
);
733 if (a
& ATTR_VOL_ENCODINGSUSED
) *((unsigned long long *)attrbufptr
)++ = (unsigned long long)0;
734 if (a
& ATTR_VOL_CAPABILITIES
) {
735 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_FORMAT
] =
736 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_SYMBOLICLINKS
: 0) |
737 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_HARDLINKS
: 0) |
738 (imp
->iso_ftype
== ISO_FTYPE_RRIP
|| imp
->iso_ftype
== ISO_FTYPE_JOLIET
739 ? VOL_CAP_FMT_CASE_SENSITIVE
: 0) |
740 VOL_CAP_FMT_CASE_PRESERVING
|
741 VOL_CAP_FMT_FAST_STATFS
;
742 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_INTERFACES
] =
743 VOL_CAP_INT_ATTRLIST
|
744 VOL_CAP_INT_NFSEXPORT
;
745 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED1
] = 0;
746 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED2
] = 0;
748 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_FORMAT
] =
749 VOL_CAP_FMT_PERSISTENTOBJECTIDS
|
750 VOL_CAP_FMT_SYMBOLICLINKS
|
751 VOL_CAP_FMT_HARDLINKS
|
752 VOL_CAP_FMT_JOURNAL
|
753 VOL_CAP_FMT_JOURNAL_ACTIVE
|
754 VOL_CAP_FMT_NO_ROOT_TIMES
|
755 VOL_CAP_FMT_SPARSE_FILES
|
756 VOL_CAP_FMT_ZERO_RUNS
|
757 VOL_CAP_FMT_CASE_SENSITIVE
|
758 VOL_CAP_FMT_CASE_PRESERVING
|
759 VOL_CAP_FMT_FAST_STATFS
|
760 VOL_CAP_FMT_2TB_FILESIZE
;
761 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_INTERFACES
] =
762 VOL_CAP_INT_SEARCHFS
|
763 VOL_CAP_INT_ATTRLIST
|
764 VOL_CAP_INT_NFSEXPORT
|
765 VOL_CAP_INT_READDIRATTR
|
766 VOL_CAP_INT_EXCHANGEDATA
|
767 VOL_CAP_INT_COPYFILE
|
768 VOL_CAP_INT_ALLOCATE
|
769 VOL_CAP_INT_VOL_RENAME
|
770 VOL_CAP_INT_ADVLOCK
|
772 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
773 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
775 ++((vol_capabilities_attr_t
*)attrbufptr
);
777 if (a
& ATTR_VOL_ATTRIBUTES
) {
778 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.commonattr
= ATTR_CMN_VALIDMASK
;
779 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.volattr
= ATTR_VOL_VALIDMASK
;
780 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.dirattr
= ATTR_DIR_VALIDMASK
;
781 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.fileattr
= ATTR_FILE_VALIDMASK
;
782 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.forkattr
= ATTR_FORK_VALIDMASK
;
784 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.commonattr
= ATTR_CMN_VALIDMASK
;
785 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.volattr
= ATTR_VOL_VALIDMASK
;
786 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.dirattr
= ATTR_DIR_VALIDMASK
;
787 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.fileattr
= ATTR_FILE_VALIDMASK
;
788 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.forkattr
= ATTR_FORK_VALIDMASK
;
790 ++((vol_attributes_attr_t
*)attrbufptr
);
794 *attrbufptrptr
= attrbufptr
;
795 *varbufptrptr
= varbufptr
;
800 packcommonattr (struct attrlist
*alist
,
802 void **attrbufptrptr
,
809 boolean_t is_64_bit
= proc_is64bit(current_proc());
811 attrbufptr
= *attrbufptrptr
;
812 varbufptr
= *varbufptrptr
;
814 if ((a
= alist
->commonattr
) != 0) {
815 struct iso_mnt
*imp
= ip
->i_mnt
;
817 if (a
& ATTR_CMN_NAME
) {
818 /* special case root since we know how to get it's name */
819 if (vnode_isvroot(ITOV(ip
))) {
820 attrlength
= strlen( imp
->volume_id
) + 1;
821 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
823 attrlength
= strlen(ip
->i_namep
) + 1;
824 (void) strncpy((unsigned char *)varbufptr
, ip
->i_namep
, attrlength
);
827 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
828 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
829 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
830 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
831 ++((struct attrreference
*)attrbufptr
);
833 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = ip
->i_dev
;
834 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = vfs_statfs(vnode_mount(ITOV(ip
)))->f_fsid
;
835 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = vnode_vtype(ITOV(ip
));
836 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = vnode_tag(ITOV(ip
));
837 if (a
& ATTR_CMN_OBJID
) {
838 if (vnode_isvroot(ITOV(ip
)))
839 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
841 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
842 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
843 ++((fsobj_id_t
*)attrbufptr
);
845 if (a
& ATTR_CMN_OBJPERMANENTID
) {
846 if (vnode_isvroot(ITOV(ip
)))
847 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
849 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
850 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
851 ++((fsobj_id_t
*)attrbufptr
);
853 if (a
& ATTR_CMN_PAROBJID
) {
854 struct iso_directory_record
*dp
= (struct iso_directory_record
*)imp
->root
;
855 ino_t rootino
= isodirino(dp
, imp
);
857 if (ip
->i_number
== rootino
)
858 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 1; /* force root parent to be 1 */
859 else if (ip
->i_parent
== rootino
)
860 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
862 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_parent
;
863 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
864 ++((fsobj_id_t
*)attrbufptr
);
866 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
867 if (a
& ATTR_CMN_CRTIME
) {
869 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
870 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_mtime
.tv_sec
;
871 tmpp
->tv_nsec
= ip
->inode
.iso_mtime
.tv_nsec
;
874 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
877 if (a
& ATTR_CMN_MODTIME
) {
879 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
880 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_mtime
.tv_sec
;
881 tmpp
->tv_nsec
= ip
->inode
.iso_mtime
.tv_nsec
;
884 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
887 if (a
& ATTR_CMN_CHGTIME
) {
889 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
890 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_ctime
.tv_sec
;
891 tmpp
->tv_nsec
= ip
->inode
.iso_ctime
.tv_nsec
;
894 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_ctime
;
897 if (a
& ATTR_CMN_ACCTIME
) {
899 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
900 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_atime
.tv_sec
;
901 tmpp
->tv_nsec
= ip
->inode
.iso_atime
.tv_nsec
;
904 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
907 if (a
& ATTR_CMN_BKUPTIME
) {
909 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
910 tmpp
->tv_sec
= (user_time_t
) 0;
914 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
915 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
916 ++((struct timespec
*)attrbufptr
);
917 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
920 if (a
& ATTR_CMN_FNDRINFO
) {
921 struct finder_info finfo
;
923 bzero(&finfo
, sizeof(finfo
));
924 finfo
.fdFlags
= ip
->i_FinderFlags
;
925 finfo
.fdLocation
.v
= -1;
926 finfo
.fdLocation
.h
= -1;
927 if (vnode_isreg(ITOV(ip
))) {
928 finfo
.fdType
= ip
->i_FileType
;
929 finfo
.fdCreator
= ip
->i_Creator
;
931 bcopy (&finfo
, attrbufptr
, sizeof(finfo
));
932 (u_int8_t
*)attrbufptr
+= sizeof(finfo
);
933 bzero (attrbufptr
, EXTFNDRINFOSIZE
);
934 (u_int8_t
*)attrbufptr
+= EXTFNDRINFOSIZE
;
936 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
937 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
938 if (a
& ATTR_CMN_ACCESSMASK
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_mode
;
939 if (a
& ATTR_CMN_FLAGS
) *((uint32_t *)attrbufptr
)++ = 0; /* could also use ip->i_flag */
940 if (a
& ATTR_CMN_USERACCESS
) {
941 *((uint32_t *)attrbufptr
)++ =
942 DerivePermissionSummary(ip
->inode
.iso_uid
,
949 *attrbufptrptr
= attrbufptr
;
950 *varbufptrptr
= varbufptr
;
955 packdirattr(struct attrlist
*alist
,
957 void **attrbufptrptr
,
958 __unused
void **varbufptrptr
)
964 attrbufptr
= *attrbufptrptr
;
968 if (vnode_isdir(ITOV(ip
)) && (a
!= 0)) {
970 * if we haven't counted our children yet, do it now...
972 if ((ip
->i_entries
== 0) &&
973 (a
& (ATTR_DIR_LINKCOUNT
| ATTR_DIR_ENTRYCOUNT
))) {
974 (void) isochildcount(ITOV(ip
), &dircnt
, &filcnt
);
976 if ((ip
->inode
.iso_links
== 1) && (dircnt
!= 0))
977 ip
->inode
.iso_links
= dircnt
;
978 if ((filcnt
+ dircnt
) > 0)
979 ip
->i_entries
= dircnt
+ filcnt
;
982 if (a
& ATTR_DIR_LINKCOUNT
) {
983 *((uint32_t *)attrbufptr
)++ = ip
->inode
.iso_links
;
985 if (a
& ATTR_DIR_ENTRYCOUNT
) {
986 /* exclude '.' and '..' from total caount */
987 *((uint32_t *)attrbufptr
)++ = ((ip
->i_entries
<= 2) ? 0 : (ip
->i_entries
- 2));
989 if (a
& ATTR_DIR_MOUNTSTATUS
) {
990 if (vnode_mountedhere(ITOV(ip
))) {
991 *((uint32_t *)attrbufptr
)++ = DIR_MNTSTATUS_MNTPOINT
;
993 *((uint32_t *)attrbufptr
)++ = 0;
998 *attrbufptrptr
= attrbufptr
;
1003 packfileattr(struct attrlist
*alist
,
1004 struct iso_node
*ip
,
1005 void **attrbufptrptr
,
1006 void **varbufptrptr
)
1008 void *attrbufptr
= *attrbufptrptr
;
1009 void *varbufptr
= *varbufptrptr
;
1010 attrgroup_t a
= alist
->fileattr
;
1012 if (vnode_isreg(ITOV(ip
)) && (a
!= 0)) {
1013 if (a
& ATTR_FILE_LINKCOUNT
)
1014 *((uint32_t *)attrbufptr
)++ = ip
->inode
.iso_links
;
1015 if (a
& ATTR_FILE_TOTALSIZE
)
1016 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1017 if (a
& ATTR_FILE_ALLOCSIZE
)
1018 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1019 if (a
& ATTR_FILE_IOBLOCKSIZE
)
1020 *((uint32_t *)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
1021 if (a
& ATTR_FILE_CLUMPSIZE
)
1022 *((uint32_t *)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
1023 if (a
& ATTR_FILE_DEVTYPE
)
1024 *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_rdev
;
1025 if (a
& ATTR_FILE_DATALENGTH
)
1026 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1027 if (a
& ATTR_FILE_DATAALLOCSIZE
)
1028 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1029 if (a
& ATTR_FILE_RSRCLENGTH
)
1030 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
1031 if (a
& ATTR_FILE_RSRCALLOCSIZE
)
1032 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
1035 *attrbufptrptr
= attrbufptr
;
1036 *varbufptrptr
= varbufptr
;
1041 packattrblk(struct attrlist
*alist
,
1043 void **attrbufptrptr
,
1044 void **varbufptrptr
)
1046 struct iso_node
*ip
= VTOI(vp
);
1048 if (alist
->volattr
!= 0) {
1049 packvolattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1051 packcommonattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1053 switch (vnode_vtype(ITOV(ip
))) {
1055 packdirattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1059 packfileattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1062 /* Without this the compiler complains about VNON,VBLK,VCHR,VLNK,VSOCK,VFIFO,VBAD and VSTR
1063 not being handled...