2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* $NetBSD: cd9660_util.c,v 1.8 1994/12/13 22:33:25 mycroft Exp $ */
26 * The Regents of the University of California. All rights reserved.
28 * This code is derived from software contributed to Berkeley
29 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
30 * Support code is derived from software contributed to Berkeley
31 * by Atsushi Murai (amurai@spec.co.jp).
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * @(#)cd9660_util.c 8.3 (Berkeley) 12/5/94
64 * 7-Dec-98 Add ATTR_VOL_MOUNTFLAGS attribute support - djb
65 * 18-Nov-98 Add support for volfs - djb
68 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/vnode.h>
71 #include <sys/mount.h>
72 #include <sys/namei.h>
73 #include <sys/resourcevar.h>
74 #include <sys/kernel.h>
79 #include <sys/kauth.h>
81 #include <sys/utfconv.h>
82 #include <miscfs/specfs/specdev.h> /* XXX */
83 #include <miscfs/fifofs/fifo.h> /* XXX */
84 #include <sys/malloc.h>
87 #include <kern/assert.h>
89 #include <isofs/cd9660/iso.h>
90 #include <isofs/cd9660/cd9660_node.h>
91 #include <isofs/cd9660/iso_rrip.h>
94 * translate and compare a filename
95 * Note: Version number plus ';' may be omitted.
98 isofncmp(u_char
*fn
, int fnlen
, u_char
*isofn
, int isolen
)
103 while (--fnlen
>= 0) {
106 if ((c
= *isofn
++) == ';') {
115 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
116 if (*fn
< '0' || *fn
> '9') {
120 for (j
= 0; --isolen
>= 0; j
= j
* 10 + *isofn
++ - '0');
123 /* if raw comparison fails, check if char was mapped */
125 if (c
>= 'A' && c
<= 'Z') {
126 if (c
+ ('a' - 'A') != *fn
) {
127 if (*fn
>= 'a' && *fn
<= 'z')
128 return *fn
- ('a' - 'A') - c
;
132 } else if (c
== '/') {
135 } else if (c
> 0 || *fn
!= '_')
156 * translate and compare a UCS-2 filename
157 * Note: Version number plus ';' may be omitted.
159 * The name pointed to by "fn" is the search name, whose characters are
160 * in native endian order. The name "ucsfn" is the on-disk name, whose
161 * characters are in big endian order.
165 ucsfncmp(u_int16_t
*fn
, int fnlen
, u_int16_t
*ucsfn
, int ucslen
)
170 /* convert byte count to char count */
174 while (--fnlen
>= 0) {
177 if ((c
= OSSwapBigToHostInt16(*ucsfn
++)) == UCS_SEPARATOR2
) {
186 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
187 if (*fn
< '0' || *fn
> '9') {
191 for (j
= 0; --ucslen
>= 0; j
= j
* 10 + OSSwapBigToHostInt16(*ucsfn
++) - '0');
202 case OSSwapHostToBigConstInt16(UCS_SEPARATOR1
):
203 if (ucsfn
[1] != OSSwapHostToBigConstInt16(UCS_SEPARATOR2
))
205 case OSSwapHostToBigConstInt16(UCS_SEPARATOR2
):
214 * translate a filename
217 isofntrans(u_char
*infn
, int infnlen
, u_char
*outfn
, u_short
*outfnlen
,
218 int original
, int assoc
)
223 * Add a "._" prefix for associated files
226 *outfn
++ = ASSOCCHAR1
;
227 *outfn
++ = ASSOCCHAR2
;
231 for (; fnidx
< infnlen
; fnidx
++) {
235 * Some ISO 9600 CD names contain 8-bit chars.
236 * These chars are mapped to '_' because there
237 * is no context for mapping them to UTF-8.
238 * In addition '/' is mapped to ':'.
240 * isofncmp accounts for these mappings.
247 else if (c
== '.' && *infn
== ';')
260 * translate a UCS-2 filename to UTF-8
263 ucsfntrans(u_int16_t
*infn
, int infnlen
, u_char
*outfn
, u_short
*outfnlen
,
269 if (*(u_char
*)infn
== 0)
271 else if (*(u_char
*)infn
== 1)
282 * Add a "._" prefix for associated files
285 *outfn
++ = ASSOCCHAR1
;
286 *outfn
++ = ASSOCCHAR2
;
289 /* strip file version number */
290 for (fnidx
--; fnidx
> 0; fnidx
--) {
291 /* stop when ';' is found */
292 if (infn
[fnidx
] == OSSwapHostToBigConstInt16(UCS_SEPARATOR2
)) {
293 /* drop dangling dot */
294 if (fnidx
> 0 && infn
[fnidx
-1] == OSSwapHostToBigConstInt16(UCS_SEPARATOR1
))
303 flags
= UTF_NO_NULL_TERM
| UTF_DECOMPOSED
;
304 if (BYTE_ORDER
!= BIG_ENDIAN
)
305 flags
|= UTF_REVERSE_ENDIAN
;
307 (void) utf8_encodestr(infn
, fnidx
* 2, outfn
, &outbytes
, ISO_JOLIET_NAMEMAX
, 0, flags
);
308 *outfnlen
= assoc
? outbytes
+ 2 : outbytes
;
314 * count the number of children by enumerating the directory
317 isochildcount(struct vnode
*vdp
, int *dircnt
, int *filcnt
)
320 struct buf
*bp
= NULL
;
322 struct iso_directory_record
*ep
;
333 bmask
= imp
->im_sector_size
- 1;
334 logblksize
= imp
->im_sector_size
;
335 blkoffset
= diroffset
= 0;
338 while (diroffset
< dp
->i_size
) {
340 * If offset is on a block boundary, read the next
341 * directory block. Release previous if it exists.
343 if ((diroffset
& bmask
) == 0) {
346 if ( (error
= cd9660_blkatoff(vdp
, SECTOFF(imp
, diroffset
), NULL
, &bp
)) )
351 ep
= (struct iso_directory_record
*)
352 (buf_dataptr(bp
) + blkoffset
);
354 reclen
= isonum_711(ep
->length
);
356 /* skip to next block, if any */
358 (diroffset
& ~bmask
) + logblksize
;
362 if ((reclen
< ISO_DIRECTORY_RECORD_SIZE
) ||
363 (blkoffset
+ reclen
> logblksize
) ||
364 (reclen
< ISO_DIRECTORY_RECORD_SIZE
+ isonum_711(ep
->name_len
))){
365 /* illegal, so give up */
370 * Some poorly mastered discs have an incorrect directory
371 * file size. If the '.' entry has a better size (bigger)
372 * then use that instead.
374 if ((diroffset
== 0) && (isonum_733(ep
->size
) > dp
->i_size
)) {
375 dp
->i_size
= isonum_733(ep
->size
);
378 if ( isonum_711(ep
->flags
) & directoryBit
)
380 else if ((isonum_711(ep
->flags
) & associatedBit
) == 0)
398 DerivePermissionSummary(uid_t owner
, gid_t group
, mode_t obj_mode
, __unused
struct iso_mnt
*imp
)
400 kauth_cred_t cred
= kauth_cred_get();
401 uint32_t permissions
;
404 /* User id 0 (root) always gets access. */
405 if (!suser(cred
, NULL
)) {
406 permissions
= R_OK
| X_OK
;
410 /* Otherwise, check the owner. */
411 if (owner
== kauth_cred_getuid(cred
)) {
412 permissions
= ((uint32_t)obj_mode
& S_IRWXU
) >> 6;
416 /* Otherwise, check the groups. */
417 if (kauth_cred_ismember_gid(cred
, group
, &is_member
) == 0 && is_member
) {
418 permissions
= ((uint32_t)obj_mode
& S_IRWXG
) >> 3;
422 /* Otherwise, settle for 'others' access. */
423 permissions
= (uint32_t)obj_mode
& S_IRWXO
;
426 return permissions
& ~W_OK
; /* Write access is always impossible */
431 attrcalcsize(struct attrlist
*attrlist
)
435 boolean_t is_64_bit
= proc_is64bit(current_proc());
437 #if ((ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_FSID | ATTR_CMN_OBJTYPE | \
438 ATTR_CMN_OBJTAG | ATTR_CMN_OBJID | ATTR_CMN_OBJPERMANENTID | ATTR_CMN_PAROBJID | \
439 ATTR_CMN_SCRIPT | ATTR_CMN_CRTIME | ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME | \
440 ATTR_CMN_ACCTIME | ATTR_CMN_BKUPTIME | ATTR_CMN_FNDRINFO | ATTR_CMN_OWNERID | \
441 ATTR_CMN_GRPID | ATTR_CMN_ACCESSMASK | ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST| \
442 ATTR_CMN_FLAGS | ATTR_CMN_USERACCESS) != ATTR_CMN_VALIDMASK)
443 #error AttributeBlockSize: Missing bits in common mask computation!
445 assert((attrlist
->commonattr
& ~ATTR_CMN_VALIDMASK
) == 0);
447 #if ((ATTR_VOL_FSTYPE | ATTR_VOL_SIGNATURE | ATTR_VOL_SIZE | ATTR_VOL_SPACEFREE | \
448 ATTR_VOL_SPACEAVAIL | ATTR_VOL_MINALLOCATION | ATTR_VOL_ALLOCATIONCLUMP | ATTR_VOL_IOBLOCKSIZE | \
449 ATTR_VOL_OBJCOUNT | ATTR_VOL_FILECOUNT | ATTR_VOL_DIRCOUNT | ATTR_VOL_MAXOBJCOUNT | \
450 ATTR_VOL_MOUNTPOINT | ATTR_VOL_NAME | ATTR_VOL_MOUNTFLAGS | ATTR_VOL_INFO | \
451 ATTR_VOL_MOUNTEDDEVICE| ATTR_VOL_ENCODINGSUSED | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES) != ATTR_VOL_VALIDMASK)
452 #error AttributeBlockSize: Missing bits in volume mask computation!
454 assert((attrlist
->volattr
& ~ATTR_VOL_VALIDMASK
) == 0);
456 #if ((ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT | ATTR_DIR_MOUNTSTATUS) != ATTR_DIR_VALIDMASK)
457 #error AttributeBlockSize: Missing bits in directory mask computation!
459 assert((attrlist
->dirattr
& ~ATTR_DIR_VALIDMASK
) == 0);
460 #if ((ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE | ATTR_FILE_ALLOCSIZE | ATTR_FILE_IOBLOCKSIZE | \
461 ATTR_FILE_CLUMPSIZE | ATTR_FILE_DEVTYPE | ATTR_FILE_FILETYPE | ATTR_FILE_FORKCOUNT | \
462 ATTR_FILE_FORKLIST | ATTR_FILE_DATALENGTH | ATTR_FILE_DATAALLOCSIZE | ATTR_FILE_DATAEXTENTS | \
463 ATTR_FILE_RSRCLENGTH | ATTR_FILE_RSRCALLOCSIZE | ATTR_FILE_RSRCEXTENTS) != ATTR_FILE_VALIDMASK)
464 #error AttributeBlockSize: Missing bits in file mask computation!
466 assert((attrlist
->fileattr
& ~ATTR_FILE_VALIDMASK
) == 0);
468 #if ((ATTR_FORK_TOTALSIZE | ATTR_FORK_ALLOCSIZE) != ATTR_FORK_VALIDMASK)
469 #error AttributeBlockSize: Missing bits in fork mask computation!
471 assert((attrlist
->forkattr
& ~ATTR_FORK_VALIDMASK
) == 0);
475 if ((a
= attrlist
->commonattr
) != 0) {
476 if (a
& ATTR_CMN_NAME
) size
+= sizeof(struct attrreference
);
477 if (a
& ATTR_CMN_DEVID
) size
+= sizeof(dev_t
);
478 if (a
& ATTR_CMN_FSID
) size
+= sizeof(fsid_t
);
479 if (a
& ATTR_CMN_OBJTYPE
) size
+= sizeof(fsobj_type_t
);
480 if (a
& ATTR_CMN_OBJTAG
) size
+= sizeof(fsobj_tag_t
);
481 if (a
& ATTR_CMN_OBJID
) size
+= sizeof(fsobj_id_t
);
482 if (a
& ATTR_CMN_OBJPERMANENTID
) size
+= sizeof(fsobj_id_t
);
483 if (a
& ATTR_CMN_PAROBJID
) size
+= sizeof(fsobj_id_t
);
484 if (a
& ATTR_CMN_SCRIPT
) size
+= sizeof(text_encoding_t
);
485 if (a
& ATTR_CMN_CRTIME
) {
487 size
+= sizeof(struct user_timespec
);
489 size
+= sizeof(struct timespec
);
491 if (a
& ATTR_CMN_MODTIME
) {
493 size
+= sizeof(struct user_timespec
);
495 size
+= sizeof(struct timespec
);
497 if (a
& ATTR_CMN_CHGTIME
) {
499 size
+= sizeof(struct user_timespec
);
501 size
+= sizeof(struct timespec
);
503 if (a
& ATTR_CMN_ACCTIME
) {
505 size
+= sizeof(struct user_timespec
);
507 size
+= sizeof(struct timespec
);
509 if (a
& ATTR_CMN_BKUPTIME
) {
511 size
+= sizeof(struct user_timespec
);
513 size
+= sizeof(struct timespec
);
515 if (a
& ATTR_CMN_FNDRINFO
) size
+= 32 * sizeof(u_int8_t
);
516 if (a
& ATTR_CMN_OWNERID
) size
+= sizeof(uid_t
);
517 if (a
& ATTR_CMN_GRPID
) size
+= sizeof(gid_t
);
518 if (a
& ATTR_CMN_ACCESSMASK
) size
+= sizeof(uint32_t);
519 if (a
& ATTR_CMN_NAMEDATTRCOUNT
) size
+= sizeof(uint32_t);
520 if (a
& ATTR_CMN_NAMEDATTRLIST
) size
+= sizeof(struct attrreference
);
521 if (a
& ATTR_CMN_FLAGS
) size
+= sizeof(uint32_t);
522 if (a
& ATTR_CMN_USERACCESS
) size
+= sizeof(uint32_t);
524 if ((a
= attrlist
->volattr
) != 0) {
525 if (a
& ATTR_VOL_FSTYPE
) size
+= sizeof(uint32_t);
526 if (a
& ATTR_VOL_SIGNATURE
) size
+= sizeof(uint32_t);
527 if (a
& ATTR_VOL_SIZE
) size
+= sizeof(off_t
);
528 if (a
& ATTR_VOL_SPACEFREE
) size
+= sizeof(off_t
);
529 if (a
& ATTR_VOL_SPACEAVAIL
) size
+= sizeof(off_t
);
530 if (a
& ATTR_VOL_MINALLOCATION
) size
+= sizeof(off_t
);
531 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) size
+= sizeof(off_t
);
532 if (a
& ATTR_VOL_IOBLOCKSIZE
) size
+= sizeof(uint32_t);
533 if (a
& ATTR_VOL_OBJCOUNT
) size
+= sizeof(uint32_t);
534 if (a
& ATTR_VOL_FILECOUNT
) size
+= sizeof(uint32_t);
535 if (a
& ATTR_VOL_DIRCOUNT
) size
+= sizeof(uint32_t);
536 if (a
& ATTR_VOL_MAXOBJCOUNT
) size
+= sizeof(uint32_t);
537 if (a
& ATTR_VOL_MOUNTPOINT
) size
+= sizeof(struct attrreference
);
538 if (a
& ATTR_VOL_NAME
) size
+= sizeof(struct attrreference
);
539 if (a
& ATTR_VOL_MOUNTFLAGS
) size
+= sizeof(uint32_t);
540 if (a
& ATTR_VOL_MOUNTEDDEVICE
) size
+= sizeof(struct attrreference
);
541 if (a
& ATTR_VOL_ENCODINGSUSED
) size
+= sizeof(unsigned long long);
542 if (a
& ATTR_VOL_CAPABILITIES
) size
+= sizeof(vol_capabilities_attr_t
);
543 if (a
& ATTR_VOL_ATTRIBUTES
) size
+= sizeof(vol_attributes_attr_t
);
545 if ((a
= attrlist
->dirattr
) != 0) {
546 if (a
& ATTR_DIR_LINKCOUNT
) size
+= sizeof(uint32_t);
547 if (a
& ATTR_DIR_ENTRYCOUNT
) size
+= sizeof(uint32_t);
548 if (a
& ATTR_DIR_MOUNTSTATUS
) size
+= sizeof(uint32_t);
550 if ((a
= attrlist
->fileattr
) != 0) {
551 if (a
& ATTR_FILE_LINKCOUNT
) size
+= sizeof(uint32_t);
552 if (a
& ATTR_FILE_TOTALSIZE
) size
+= sizeof(off_t
);
553 if (a
& ATTR_FILE_ALLOCSIZE
) size
+= sizeof(off_t
);
554 if (a
& ATTR_FILE_IOBLOCKSIZE
) size
+= sizeof(uint32_t);
555 if (a
& ATTR_FILE_CLUMPSIZE
) size
+= sizeof(uint32_t);
556 if (a
& ATTR_FILE_DEVTYPE
) size
+= sizeof(uint32_t);
557 if (a
& ATTR_FILE_FILETYPE
) size
+= sizeof(uint32_t);
558 if (a
& ATTR_FILE_FORKCOUNT
) size
+= sizeof(uint32_t);
559 if (a
& ATTR_FILE_FORKLIST
) size
+= sizeof(struct attrreference
);
560 if (a
& ATTR_FILE_DATALENGTH
) size
+= sizeof(off_t
);
561 if (a
& ATTR_FILE_DATAALLOCSIZE
) size
+= sizeof(off_t
);
562 if (a
& ATTR_FILE_DATAEXTENTS
) size
+= sizeof(extentrecord
);
563 if (a
& ATTR_FILE_RSRCLENGTH
) size
+= sizeof(off_t
);
564 if (a
& ATTR_FILE_RSRCALLOCSIZE
) size
+= sizeof(off_t
);
565 if (a
& ATTR_FILE_RSRCEXTENTS
) size
+= sizeof(extentrecord
);
567 if ((a
= attrlist
->forkattr
) != 0) {
568 if (a
& ATTR_FORK_TOTALSIZE
) size
+= sizeof(off_t
);
569 if (a
& ATTR_FORK_ALLOCSIZE
) size
+= sizeof(off_t
);
578 packvolattr (struct attrlist
*alist
,
579 struct iso_node
*ip
, /* ip for root directory */
580 void **attrbufptrptr
,
589 boolean_t is_64_bit
= proc_is64bit(current_proc());
591 attrbufptr
= *attrbufptrptr
;
592 varbufptr
= *varbufptrptr
;
596 if ((a
= alist
->commonattr
) != 0) {
597 if (a
& ATTR_CMN_NAME
) {
598 attrlength
= strlen( imp
->volume_id
) + 1;
599 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
600 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
601 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
603 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
604 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
605 ++((struct attrreference
*)attrbufptr
);
607 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = vnode_specrdev(imp
->im_devvp
);
608 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = vfs_statfs(vnode_mount(ITOV(ip
)))->f_fsid
;
609 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = 0;
610 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = VT_ISOFS
;
611 if (a
& ATTR_CMN_OBJID
) {
612 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
613 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
614 ++((fsobj_id_t
*)attrbufptr
);
616 if (a
& ATTR_CMN_OBJPERMANENTID
) {
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_PAROBJID
) {
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_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
627 if (a
& ATTR_CMN_CRTIME
) {
629 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
630 tmpp
->tv_sec
= (user_time_t
) imp
->creation_date
.tv_sec
;
631 tmpp
->tv_nsec
= imp
->creation_date
.tv_nsec
;
634 *((struct timespec
*)attrbufptr
)++ = imp
->creation_date
;
637 if (a
& ATTR_CMN_MODTIME
) {
639 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
640 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
641 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
644 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
647 if (a
& ATTR_CMN_CHGTIME
) {
649 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
650 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
651 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
654 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
657 if (a
& ATTR_CMN_ACCTIME
) {
659 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
660 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
661 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
664 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
667 if (a
& ATTR_CMN_BKUPTIME
) {
668 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
669 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
670 ++((struct timespec
*)attrbufptr
);
672 if (a
& ATTR_CMN_FNDRINFO
) {
673 bzero (attrbufptr
, 32 * sizeof(u_int8_t
));
674 (u_int8_t
*)attrbufptr
+= 32 * sizeof(u_int8_t
);
676 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
677 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
678 if (a
& ATTR_CMN_ACCESSMASK
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_mode
;
679 if (a
& ATTR_CMN_FLAGS
) *((uint32_t *)attrbufptr
)++ = 0;
680 if (a
& ATTR_CMN_USERACCESS
) {
681 *((uint32_t *)attrbufptr
)++ =
682 DerivePermissionSummary(ip
->inode
.iso_uid
,
689 if ((a
= alist
->volattr
) != 0) {
690 off_t blocksize
= (off_t
)imp
->logical_block_size
;
692 if (a
& ATTR_VOL_FSTYPE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)vfs_typenum(mp
);
693 if (a
& ATTR_VOL_SIGNATURE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ISO9660SIGNATURE
;
694 if (a
& ATTR_VOL_SIZE
) *((off_t
*)attrbufptr
)++ = (off_t
)imp
->volume_space_size
* blocksize
;
695 if (a
& ATTR_VOL_SPACEFREE
) *((off_t
*)attrbufptr
)++ = 0;
696 if (a
& ATTR_VOL_SPACEAVAIL
) *((off_t
*)attrbufptr
)++ = 0;
697 if (a
& ATTR_VOL_MINALLOCATION
) *((off_t
*)attrbufptr
)++ = blocksize
;
698 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) *((off_t
*)attrbufptr
)++ = blocksize
;
699 if (a
& ATTR_VOL_IOBLOCKSIZE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)blocksize
;
700 if (a
& ATTR_VOL_OBJCOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
701 if (a
& ATTR_VOL_FILECOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
702 if (a
& ATTR_VOL_DIRCOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
703 if (a
& ATTR_VOL_MAXOBJCOUNT
) *((uint32_t *)attrbufptr
)++ = 0xFFFFFFFF;
704 if (a
& ATTR_VOL_NAME
) {
705 attrlength
= strlen( imp
->volume_id
) + 1;
706 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
707 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
708 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
710 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
711 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
712 ++((struct attrreference
*)attrbufptr
);
714 if (a
& ATTR_VOL_MOUNTFLAGS
) {
715 *((uint32_t *)attrbufptr
)++ = (uint32_t)vfs_flags(mp
);
717 if (a
& ATTR_VOL_MOUNTEDDEVICE
) {
718 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
719 ((struct attrreference
*)attrbufptr
)->attr_length
= strlen(vfs_statfs(mp
)->f_mntfromname
) + 1;
720 attrlength
= ((struct attrreference
*)attrbufptr
)->attr_length
;
721 attrlength
= attrlength
+ ((4 - (attrlength
& 3)) & 3); /* round up to the next 4-byte boundary: */
722 (void) bcopy(vfs_statfs(mp
)->f_mntfromname
, varbufptr
, attrlength
);
724 /* Advance beyond the space just allocated: */
725 (u_int8_t
*)varbufptr
+= attrlength
;
726 ++((struct attrreference
*)attrbufptr
);
728 if (a
& ATTR_VOL_ENCODINGSUSED
) *((unsigned long long *)attrbufptr
)++ = (unsigned long long)0;
729 if (a
& ATTR_VOL_CAPABILITIES
) {
730 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_FORMAT
] =
731 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_SYMBOLICLINKS
: 0) |
732 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_HARDLINKS
: 0) |
733 (imp
->iso_ftype
== ISO_FTYPE_RRIP
|| imp
->iso_ftype
== ISO_FTYPE_JOLIET
734 ? VOL_CAP_FMT_CASE_SENSITIVE
: 0) |
735 VOL_CAP_FMT_CASE_PRESERVING
|
736 VOL_CAP_FMT_FAST_STATFS
;
737 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_INTERFACES
] =
738 VOL_CAP_INT_ATTRLIST
|
739 VOL_CAP_INT_NFSEXPORT
;
740 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED1
] = 0;
741 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED2
] = 0;
743 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_FORMAT
] =
744 VOL_CAP_FMT_PERSISTENTOBJECTIDS
|
745 VOL_CAP_FMT_SYMBOLICLINKS
|
746 VOL_CAP_FMT_HARDLINKS
|
747 VOL_CAP_FMT_JOURNAL
|
748 VOL_CAP_FMT_JOURNAL_ACTIVE
|
749 VOL_CAP_FMT_NO_ROOT_TIMES
|
750 VOL_CAP_FMT_SPARSE_FILES
|
751 VOL_CAP_FMT_ZERO_RUNS
|
752 VOL_CAP_FMT_CASE_SENSITIVE
|
753 VOL_CAP_FMT_CASE_PRESERVING
|
754 VOL_CAP_FMT_FAST_STATFS
|
755 VOL_CAP_FMT_2TB_FILESIZE
;
756 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_INTERFACES
] =
757 VOL_CAP_INT_SEARCHFS
|
758 VOL_CAP_INT_ATTRLIST
|
759 VOL_CAP_INT_NFSEXPORT
|
760 VOL_CAP_INT_READDIRATTR
|
761 VOL_CAP_INT_EXCHANGEDATA
|
762 VOL_CAP_INT_COPYFILE
|
763 VOL_CAP_INT_ALLOCATE
|
764 VOL_CAP_INT_VOL_RENAME
|
765 VOL_CAP_INT_ADVLOCK
|
767 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
768 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
770 ++((vol_capabilities_attr_t
*)attrbufptr
);
772 if (a
& ATTR_VOL_ATTRIBUTES
) {
773 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.commonattr
= ATTR_CMN_VALIDMASK
;
774 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.volattr
= ATTR_VOL_VALIDMASK
;
775 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.dirattr
= ATTR_DIR_VALIDMASK
;
776 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.fileattr
= ATTR_FILE_VALIDMASK
;
777 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.forkattr
= ATTR_FORK_VALIDMASK
;
779 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.commonattr
= ATTR_CMN_VALIDMASK
;
780 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.volattr
= ATTR_VOL_VALIDMASK
;
781 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.dirattr
= ATTR_DIR_VALIDMASK
;
782 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.fileattr
= ATTR_FILE_VALIDMASK
;
783 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.forkattr
= ATTR_FORK_VALIDMASK
;
785 ++((vol_attributes_attr_t
*)attrbufptr
);
789 *attrbufptrptr
= attrbufptr
;
790 *varbufptrptr
= varbufptr
;
795 packcommonattr (struct attrlist
*alist
,
797 void **attrbufptrptr
,
804 boolean_t is_64_bit
= proc_is64bit(current_proc());
806 attrbufptr
= *attrbufptrptr
;
807 varbufptr
= *varbufptrptr
;
809 if ((a
= alist
->commonattr
) != 0) {
810 struct iso_mnt
*imp
= ip
->i_mnt
;
812 if (a
& ATTR_CMN_NAME
) {
813 /* special case root since we know how to get it's name */
814 if (vnode_isvroot(ITOV(ip
))) {
815 attrlength
= strlen( imp
->volume_id
) + 1;
816 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
818 attrlength
= strlen(ip
->i_namep
) + 1;
819 (void) strncpy((unsigned char *)varbufptr
, ip
->i_namep
, attrlength
);
822 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
823 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
824 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
825 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
826 ++((struct attrreference
*)attrbufptr
);
828 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = ip
->i_dev
;
829 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = vfs_statfs(vnode_mount(ITOV(ip
)))->f_fsid
;
830 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = vnode_vtype(ITOV(ip
));
831 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = vnode_tag(ITOV(ip
));
832 if (a
& ATTR_CMN_OBJID
) {
833 if (vnode_isvroot(ITOV(ip
)))
834 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
836 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
837 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
838 ++((fsobj_id_t
*)attrbufptr
);
840 if (a
& ATTR_CMN_OBJPERMANENTID
) {
841 if (vnode_isvroot(ITOV(ip
)))
842 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
844 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
845 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
846 ++((fsobj_id_t
*)attrbufptr
);
848 if (a
& ATTR_CMN_PAROBJID
) {
849 struct iso_directory_record
*dp
= (struct iso_directory_record
*)imp
->root
;
850 ino_t rootino
= isodirino(dp
, imp
);
852 if (ip
->i_number
== rootino
)
853 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 1; /* force root parent to be 1 */
854 else if (ip
->i_parent
== rootino
)
855 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
857 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_parent
;
858 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
859 ++((fsobj_id_t
*)attrbufptr
);
861 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
862 if (a
& ATTR_CMN_CRTIME
) {
864 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
865 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_mtime
.tv_sec
;
866 tmpp
->tv_nsec
= ip
->inode
.iso_mtime
.tv_nsec
;
869 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
872 if (a
& ATTR_CMN_MODTIME
) {
874 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
875 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_mtime
.tv_sec
;
876 tmpp
->tv_nsec
= ip
->inode
.iso_mtime
.tv_nsec
;
879 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
882 if (a
& ATTR_CMN_CHGTIME
) {
884 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
885 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_ctime
.tv_sec
;
886 tmpp
->tv_nsec
= ip
->inode
.iso_ctime
.tv_nsec
;
889 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_ctime
;
892 if (a
& ATTR_CMN_ACCTIME
) {
894 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
895 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_atime
.tv_sec
;
896 tmpp
->tv_nsec
= ip
->inode
.iso_atime
.tv_nsec
;
899 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
902 if (a
& ATTR_CMN_BKUPTIME
) {
904 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
905 tmpp
->tv_sec
= (user_time_t
) 0;
909 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
910 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
911 ++((struct timespec
*)attrbufptr
);
912 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
915 if (a
& ATTR_CMN_FNDRINFO
) {
916 struct finder_info finfo
;
918 bzero(&finfo
, sizeof(finfo
));
919 finfo
.fdFlags
= ip
->i_FinderFlags
;
920 finfo
.fdLocation
.v
= -1;
921 finfo
.fdLocation
.h
= -1;
922 if (vnode_isreg(ITOV(ip
))) {
923 finfo
.fdType
= ip
->i_FileType
;
924 finfo
.fdCreator
= ip
->i_Creator
;
926 bcopy (&finfo
, attrbufptr
, sizeof(finfo
));
927 (u_int8_t
*)attrbufptr
+= sizeof(finfo
);
928 bzero (attrbufptr
, EXTFNDRINFOSIZE
);
929 (u_int8_t
*)attrbufptr
+= EXTFNDRINFOSIZE
;
931 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
932 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
933 if (a
& ATTR_CMN_ACCESSMASK
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_mode
;
934 if (a
& ATTR_CMN_FLAGS
) *((uint32_t *)attrbufptr
)++ = 0; /* could also use ip->i_flag */
935 if (a
& ATTR_CMN_USERACCESS
) {
936 *((uint32_t *)attrbufptr
)++ =
937 DerivePermissionSummary(ip
->inode
.iso_uid
,
944 *attrbufptrptr
= attrbufptr
;
945 *varbufptrptr
= varbufptr
;
950 packdirattr(struct attrlist
*alist
,
952 void **attrbufptrptr
,
953 __unused
void **varbufptrptr
)
959 attrbufptr
= *attrbufptrptr
;
963 if (vnode_isdir(ITOV(ip
)) && (a
!= 0)) {
965 * if we haven't counted our children yet, do it now...
967 if ((ip
->i_entries
== 0) &&
968 (a
& (ATTR_DIR_LINKCOUNT
| ATTR_DIR_ENTRYCOUNT
))) {
969 (void) isochildcount(ITOV(ip
), &dircnt
, &filcnt
);
971 if ((ip
->inode
.iso_links
== 1) && (dircnt
!= 0))
972 ip
->inode
.iso_links
= dircnt
;
973 if ((filcnt
+ dircnt
) > 0)
974 ip
->i_entries
= dircnt
+ filcnt
;
977 if (a
& ATTR_DIR_LINKCOUNT
) {
978 *((uint32_t *)attrbufptr
)++ = ip
->inode
.iso_links
;
980 if (a
& ATTR_DIR_ENTRYCOUNT
) {
981 /* exclude '.' and '..' from total caount */
982 *((uint32_t *)attrbufptr
)++ = ((ip
->i_entries
<= 2) ? 0 : (ip
->i_entries
- 2));
984 if (a
& ATTR_DIR_MOUNTSTATUS
) {
985 if (vnode_mountedhere(ITOV(ip
))) {
986 *((uint32_t *)attrbufptr
)++ = DIR_MNTSTATUS_MNTPOINT
;
988 *((uint32_t *)attrbufptr
)++ = 0;
993 *attrbufptrptr
= attrbufptr
;
998 packfileattr(struct attrlist
*alist
,
1000 void **attrbufptrptr
,
1001 void **varbufptrptr
)
1003 void *attrbufptr
= *attrbufptrptr
;
1004 void *varbufptr
= *varbufptrptr
;
1005 attrgroup_t a
= alist
->fileattr
;
1007 if (vnode_isreg(ITOV(ip
)) && (a
!= 0)) {
1008 if (a
& ATTR_FILE_LINKCOUNT
)
1009 *((uint32_t *)attrbufptr
)++ = ip
->inode
.iso_links
;
1010 if (a
& ATTR_FILE_TOTALSIZE
)
1011 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1012 if (a
& ATTR_FILE_ALLOCSIZE
)
1013 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1014 if (a
& ATTR_FILE_IOBLOCKSIZE
)
1015 *((uint32_t *)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
1016 if (a
& ATTR_FILE_CLUMPSIZE
)
1017 *((uint32_t *)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
1018 if (a
& ATTR_FILE_DEVTYPE
)
1019 *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_rdev
;
1020 if (a
& ATTR_FILE_DATALENGTH
)
1021 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1022 if (a
& ATTR_FILE_DATAALLOCSIZE
)
1023 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1024 if (a
& ATTR_FILE_RSRCLENGTH
)
1025 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
1026 if (a
& ATTR_FILE_RSRCALLOCSIZE
)
1027 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
1030 *attrbufptrptr
= attrbufptr
;
1031 *varbufptrptr
= varbufptr
;
1036 packattrblk(struct attrlist
*alist
,
1038 void **attrbufptrptr
,
1039 void **varbufptrptr
)
1041 struct iso_node
*ip
= VTOI(vp
);
1043 if (alist
->volattr
!= 0) {
1044 packvolattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1046 packcommonattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1048 switch (vnode_vtype(ITOV(ip
))) {
1050 packdirattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1054 packfileattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1057 /* Without this the compiler complains about VNON,VBLK,VCHR,VLNK,VSOCK,VFIFO,VBAD and VSTR
1058 not being handled...