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>
88 #include <architecture/byte_order.h>
90 #include <isofs/cd9660/iso.h>
91 #include <isofs/cd9660/cd9660_node.h>
92 #include <isofs/cd9660/iso_rrip.h>
95 * translate and compare a filename
96 * Note: Version number plus ';' may be omitted.
99 isofncmp(u_char
*fn
, int fnlen
, u_char
*isofn
, int isolen
)
104 while (--fnlen
>= 0) {
107 if ((c
= *isofn
++) == ';') {
116 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
117 if (*fn
< '0' || *fn
> '9') {
121 for (j
= 0; --isolen
>= 0; j
= j
* 10 + *isofn
++ - '0');
124 /* if raw comparison fails, check if char was mapped */
126 if (c
>= 'A' && c
<= 'Z') {
127 if (c
+ ('a' - 'A') != *fn
) {
128 if (*fn
>= 'a' && *fn
<= 'z')
129 return *fn
- ('a' - 'A') - c
;
133 } else if (c
== '/') {
136 } else if (c
> 0 || *fn
!= '_')
157 * translate and compare a UCS-2 filename
158 * Note: Version number plus ';' may be omitted.
162 ucsfncmp(u_int16_t
*fn
, int fnlen
, u_int16_t
*ucsfn
, int ucslen
)
167 /* convert byte count to char count */
171 while (--fnlen
>= 0) {
174 if ((c
= *ucsfn
++) == UCS_SEPARATOR2
) {
183 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
184 if (*fn
< '0' || *fn
> '9') {
188 for (j
= 0; --ucslen
>= 0; j
= j
* 10 + *ucsfn
++ - '0');
200 if (ucsfn
[1] != UCS_SEPARATOR2
)
211 * translate a filename
214 isofntrans(u_char
*infn
, int infnlen
, u_char
*outfn
, u_short
*outfnlen
,
215 int original
, int assoc
)
220 * Add a "._" prefix for associated files
223 *outfn
++ = ASSOCCHAR1
;
224 *outfn
++ = ASSOCCHAR2
;
228 for (; fnidx
< infnlen
; fnidx
++) {
232 * Some ISO 9600 CD names contain 8-bit chars.
233 * These chars are mapped to '_' because there
234 * is no context for mapping them to UTF-8.
235 * In addition '/' is mapped to ':'.
237 * isofncmp accounts for these mappings.
244 else if (c
== '.' && *infn
== ';')
257 * translate a UCS-2 filename to UTF-8
260 ucsfntrans(u_int16_t
*infn
, int infnlen
, u_char
*outfn
, u_short
*outfnlen
,
266 if (*(u_char
*)infn
== 0)
268 else if (*(u_char
*)infn
== 1)
279 * Add a "._" prefix for associated files
282 *outfn
++ = ASSOCCHAR1
;
283 *outfn
++ = ASSOCCHAR2
;
286 /* strip file version number */
287 for (fnidx
--; fnidx
> 0; fnidx
--) {
288 /* stop when ';' is found */
289 if (infn
[fnidx
] == UCS_SEPARATOR2
) {
290 /* drop dangling dot */
291 if (fnidx
> 0 && infn
[fnidx
-1] == UCS_SEPARATOR1
)
300 flags
= UTF_NO_NULL_TERM
| UTF_DECOMPOSED
;
301 if (BYTE_ORDER
!= BIG_ENDIAN
)
302 flags
|= UTF_REVERSE_ENDIAN
;
304 (void) utf8_encodestr(infn
, fnidx
* 2, outfn
, &outbytes
, ISO_JOLIET_NAMEMAX
, 0, flags
);
305 *outfnlen
= assoc
? outbytes
+ 2 : outbytes
;
311 * count the number of children by enumerating the directory
314 isochildcount(struct vnode
*vdp
, int *dircnt
, int *filcnt
)
317 struct buf
*bp
= NULL
;
319 struct iso_directory_record
*ep
;
330 bmask
= imp
->im_sector_size
- 1;
331 logblksize
= imp
->im_sector_size
;
332 blkoffset
= diroffset
= 0;
335 while (diroffset
< dp
->i_size
) {
337 * If offset is on a block boundary, read the next
338 * directory block. Release previous if it exists.
340 if ((diroffset
& bmask
) == 0) {
343 if ( (error
= cd9660_blkatoff(vdp
, SECTOFF(imp
, diroffset
), NULL
, &bp
)) )
348 ep
= (struct iso_directory_record
*)
349 (buf_dataptr(bp
) + blkoffset
);
351 reclen
= isonum_711(ep
->length
);
353 /* skip to next block, if any */
355 (diroffset
& ~bmask
) + logblksize
;
359 if ((reclen
< ISO_DIRECTORY_RECORD_SIZE
) ||
360 (blkoffset
+ reclen
> logblksize
) ||
361 (reclen
< ISO_DIRECTORY_RECORD_SIZE
+ isonum_711(ep
->name_len
))){
362 /* illegal, so give up */
367 * Some poorly mastered discs have an incorrect directory
368 * file size. If the '.' entry has a better size (bigger)
369 * then use that instead.
371 if ((diroffset
== 0) && (isonum_733(ep
->size
) > dp
->i_size
)) {
372 dp
->i_size
= isonum_733(ep
->size
);
375 if ( isonum_711(ep
->flags
) & directoryBit
)
377 else if ((isonum_711(ep
->flags
) & associatedBit
) == 0)
395 DerivePermissionSummary(uid_t owner
, gid_t group
, mode_t obj_mode
, __unused
struct iso_mnt
*imp
)
397 kauth_cred_t cred
= kauth_cred_get();
398 uint32_t permissions
;
401 /* User id 0 (root) always gets access. */
402 if (!suser(cred
, NULL
)) {
403 permissions
= R_OK
| X_OK
;
407 /* Otherwise, check the owner. */
408 if (owner
== kauth_cred_getuid(cred
)) {
409 permissions
= ((uint32_t)obj_mode
& S_IRWXU
) >> 6;
413 /* Otherwise, check the groups. */
414 if (kauth_cred_ismember_gid(cred
, group
, &is_member
) == 0 && is_member
) {
415 permissions
= ((uint32_t)obj_mode
& S_IRWXG
) >> 3;
419 /* Otherwise, settle for 'others' access. */
420 permissions
= (uint32_t)obj_mode
& S_IRWXO
;
423 return permissions
& ~W_OK
; /* Write access is always impossible */
428 attrcalcsize(struct attrlist
*attrlist
)
432 boolean_t is_64_bit
= proc_is64bit(current_proc());
434 #if ((ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_FSID | ATTR_CMN_OBJTYPE | \
435 ATTR_CMN_OBJTAG | ATTR_CMN_OBJID | ATTR_CMN_OBJPERMANENTID | ATTR_CMN_PAROBJID | \
436 ATTR_CMN_SCRIPT | ATTR_CMN_CRTIME | ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME | \
437 ATTR_CMN_ACCTIME | ATTR_CMN_BKUPTIME | ATTR_CMN_FNDRINFO | ATTR_CMN_OWNERID | \
438 ATTR_CMN_GRPID | ATTR_CMN_ACCESSMASK | ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST| \
439 ATTR_CMN_FLAGS | ATTR_CMN_USERACCESS) != ATTR_CMN_VALIDMASK)
440 #error AttributeBlockSize: Missing bits in common mask computation!
442 assert((attrlist
->commonattr
& ~ATTR_CMN_VALIDMASK
) == 0);
444 #if ((ATTR_VOL_FSTYPE | ATTR_VOL_SIGNATURE | ATTR_VOL_SIZE | ATTR_VOL_SPACEFREE | \
445 ATTR_VOL_SPACEAVAIL | ATTR_VOL_MINALLOCATION | ATTR_VOL_ALLOCATIONCLUMP | ATTR_VOL_IOBLOCKSIZE | \
446 ATTR_VOL_OBJCOUNT | ATTR_VOL_FILECOUNT | ATTR_VOL_DIRCOUNT | ATTR_VOL_MAXOBJCOUNT | \
447 ATTR_VOL_MOUNTPOINT | ATTR_VOL_NAME | ATTR_VOL_MOUNTFLAGS | ATTR_VOL_INFO | \
448 ATTR_VOL_MOUNTEDDEVICE| ATTR_VOL_ENCODINGSUSED | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES) != ATTR_VOL_VALIDMASK)
449 #error AttributeBlockSize: Missing bits in volume mask computation!
451 assert((attrlist
->volattr
& ~ATTR_VOL_VALIDMASK
) == 0);
453 #if ((ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT | ATTR_DIR_MOUNTSTATUS) != ATTR_DIR_VALIDMASK)
454 #error AttributeBlockSize: Missing bits in directory mask computation!
456 assert((attrlist
->dirattr
& ~ATTR_DIR_VALIDMASK
) == 0);
457 #if ((ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE | ATTR_FILE_ALLOCSIZE | ATTR_FILE_IOBLOCKSIZE | \
458 ATTR_FILE_CLUMPSIZE | ATTR_FILE_DEVTYPE | ATTR_FILE_FILETYPE | ATTR_FILE_FORKCOUNT | \
459 ATTR_FILE_FORKLIST | ATTR_FILE_DATALENGTH | ATTR_FILE_DATAALLOCSIZE | ATTR_FILE_DATAEXTENTS | \
460 ATTR_FILE_RSRCLENGTH | ATTR_FILE_RSRCALLOCSIZE | ATTR_FILE_RSRCEXTENTS) != ATTR_FILE_VALIDMASK)
461 #error AttributeBlockSize: Missing bits in file mask computation!
463 assert((attrlist
->fileattr
& ~ATTR_FILE_VALIDMASK
) == 0);
465 #if ((ATTR_FORK_TOTALSIZE | ATTR_FORK_ALLOCSIZE) != ATTR_FORK_VALIDMASK)
466 #error AttributeBlockSize: Missing bits in fork mask computation!
468 assert((attrlist
->forkattr
& ~ATTR_FORK_VALIDMASK
) == 0);
472 if ((a
= attrlist
->commonattr
) != 0) {
473 if (a
& ATTR_CMN_NAME
) size
+= sizeof(struct attrreference
);
474 if (a
& ATTR_CMN_DEVID
) size
+= sizeof(dev_t
);
475 if (a
& ATTR_CMN_FSID
) size
+= sizeof(fsid_t
);
476 if (a
& ATTR_CMN_OBJTYPE
) size
+= sizeof(fsobj_type_t
);
477 if (a
& ATTR_CMN_OBJTAG
) size
+= sizeof(fsobj_tag_t
);
478 if (a
& ATTR_CMN_OBJID
) size
+= sizeof(fsobj_id_t
);
479 if (a
& ATTR_CMN_OBJPERMANENTID
) size
+= sizeof(fsobj_id_t
);
480 if (a
& ATTR_CMN_PAROBJID
) size
+= sizeof(fsobj_id_t
);
481 if (a
& ATTR_CMN_SCRIPT
) size
+= sizeof(text_encoding_t
);
482 if (a
& ATTR_CMN_CRTIME
) {
484 size
+= sizeof(struct user_timespec
);
486 size
+= sizeof(struct timespec
);
488 if (a
& ATTR_CMN_MODTIME
) {
490 size
+= sizeof(struct user_timespec
);
492 size
+= sizeof(struct timespec
);
494 if (a
& ATTR_CMN_CHGTIME
) {
496 size
+= sizeof(struct user_timespec
);
498 size
+= sizeof(struct timespec
);
500 if (a
& ATTR_CMN_ACCTIME
) {
502 size
+= sizeof(struct user_timespec
);
504 size
+= sizeof(struct timespec
);
506 if (a
& ATTR_CMN_BKUPTIME
) {
508 size
+= sizeof(struct user_timespec
);
510 size
+= sizeof(struct timespec
);
512 if (a
& ATTR_CMN_FNDRINFO
) size
+= 32 * sizeof(u_int8_t
);
513 if (a
& ATTR_CMN_OWNERID
) size
+= sizeof(uid_t
);
514 if (a
& ATTR_CMN_GRPID
) size
+= sizeof(gid_t
);
515 if (a
& ATTR_CMN_ACCESSMASK
) size
+= sizeof(uint32_t);
516 if (a
& ATTR_CMN_NAMEDATTRCOUNT
) size
+= sizeof(uint32_t);
517 if (a
& ATTR_CMN_NAMEDATTRLIST
) size
+= sizeof(struct attrreference
);
518 if (a
& ATTR_CMN_FLAGS
) size
+= sizeof(uint32_t);
519 if (a
& ATTR_CMN_USERACCESS
) size
+= sizeof(uint32_t);
521 if ((a
= attrlist
->volattr
) != 0) {
522 if (a
& ATTR_VOL_FSTYPE
) size
+= sizeof(uint32_t);
523 if (a
& ATTR_VOL_SIGNATURE
) size
+= sizeof(uint32_t);
524 if (a
& ATTR_VOL_SIZE
) size
+= sizeof(off_t
);
525 if (a
& ATTR_VOL_SPACEFREE
) size
+= sizeof(off_t
);
526 if (a
& ATTR_VOL_SPACEAVAIL
) size
+= sizeof(off_t
);
527 if (a
& ATTR_VOL_MINALLOCATION
) size
+= sizeof(off_t
);
528 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) size
+= sizeof(off_t
);
529 if (a
& ATTR_VOL_IOBLOCKSIZE
) size
+= sizeof(uint32_t);
530 if (a
& ATTR_VOL_OBJCOUNT
) size
+= sizeof(uint32_t);
531 if (a
& ATTR_VOL_FILECOUNT
) size
+= sizeof(uint32_t);
532 if (a
& ATTR_VOL_DIRCOUNT
) size
+= sizeof(uint32_t);
533 if (a
& ATTR_VOL_MAXOBJCOUNT
) size
+= sizeof(uint32_t);
534 if (a
& ATTR_VOL_MOUNTPOINT
) size
+= sizeof(struct attrreference
);
535 if (a
& ATTR_VOL_NAME
) size
+= sizeof(struct attrreference
);
536 if (a
& ATTR_VOL_MOUNTFLAGS
) size
+= sizeof(uint32_t);
537 if (a
& ATTR_VOL_MOUNTEDDEVICE
) size
+= sizeof(struct attrreference
);
538 if (a
& ATTR_VOL_ENCODINGSUSED
) size
+= sizeof(unsigned long long);
539 if (a
& ATTR_VOL_CAPABILITIES
) size
+= sizeof(vol_capabilities_attr_t
);
540 if (a
& ATTR_VOL_ATTRIBUTES
) size
+= sizeof(vol_attributes_attr_t
);
542 if ((a
= attrlist
->dirattr
) != 0) {
543 if (a
& ATTR_DIR_LINKCOUNT
) size
+= sizeof(uint32_t);
544 if (a
& ATTR_DIR_ENTRYCOUNT
) size
+= sizeof(uint32_t);
545 if (a
& ATTR_DIR_MOUNTSTATUS
) size
+= sizeof(uint32_t);
547 if ((a
= attrlist
->fileattr
) != 0) {
548 if (a
& ATTR_FILE_LINKCOUNT
) size
+= sizeof(uint32_t);
549 if (a
& ATTR_FILE_TOTALSIZE
) size
+= sizeof(off_t
);
550 if (a
& ATTR_FILE_ALLOCSIZE
) size
+= sizeof(off_t
);
551 if (a
& ATTR_FILE_IOBLOCKSIZE
) size
+= sizeof(uint32_t);
552 if (a
& ATTR_FILE_CLUMPSIZE
) size
+= sizeof(uint32_t);
553 if (a
& ATTR_FILE_DEVTYPE
) size
+= sizeof(uint32_t);
554 if (a
& ATTR_FILE_FILETYPE
) size
+= sizeof(uint32_t);
555 if (a
& ATTR_FILE_FORKCOUNT
) size
+= sizeof(uint32_t);
556 if (a
& ATTR_FILE_FORKLIST
) size
+= sizeof(struct attrreference
);
557 if (a
& ATTR_FILE_DATALENGTH
) size
+= sizeof(off_t
);
558 if (a
& ATTR_FILE_DATAALLOCSIZE
) size
+= sizeof(off_t
);
559 if (a
& ATTR_FILE_DATAEXTENTS
) size
+= sizeof(extentrecord
);
560 if (a
& ATTR_FILE_RSRCLENGTH
) size
+= sizeof(off_t
);
561 if (a
& ATTR_FILE_RSRCALLOCSIZE
) size
+= sizeof(off_t
);
562 if (a
& ATTR_FILE_RSRCEXTENTS
) size
+= sizeof(extentrecord
);
564 if ((a
= attrlist
->forkattr
) != 0) {
565 if (a
& ATTR_FORK_TOTALSIZE
) size
+= sizeof(off_t
);
566 if (a
& ATTR_FORK_ALLOCSIZE
) size
+= sizeof(off_t
);
575 packvolattr (struct attrlist
*alist
,
576 struct iso_node
*ip
, /* ip for root directory */
577 void **attrbufptrptr
,
586 boolean_t is_64_bit
= proc_is64bit(current_proc());
588 attrbufptr
= *attrbufptrptr
;
589 varbufptr
= *varbufptrptr
;
593 if ((a
= alist
->commonattr
) != 0) {
594 if (a
& ATTR_CMN_NAME
) {
595 attrlength
= strlen( imp
->volume_id
) + 1;
596 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
597 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
598 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
600 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
601 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
602 ++((struct attrreference
*)attrbufptr
);
604 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = vnode_specrdev(imp
->im_devvp
);
605 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = vfs_statfs(vnode_mount(ITOV(ip
)))->f_fsid
;
606 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = 0;
607 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = VT_ISOFS
;
608 if (a
& ATTR_CMN_OBJID
) {
609 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
610 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
611 ++((fsobj_id_t
*)attrbufptr
);
613 if (a
& ATTR_CMN_OBJPERMANENTID
) {
614 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
615 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
616 ++((fsobj_id_t
*)attrbufptr
);
618 if (a
& ATTR_CMN_PAROBJID
) {
619 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
620 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
621 ++((fsobj_id_t
*)attrbufptr
);
623 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
624 if (a
& ATTR_CMN_CRTIME
) {
626 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
627 tmpp
->tv_sec
= (user_time_t
) imp
->creation_date
.tv_sec
;
628 tmpp
->tv_nsec
= imp
->creation_date
.tv_nsec
;
631 *((struct timespec
*)attrbufptr
)++ = imp
->creation_date
;
634 if (a
& ATTR_CMN_MODTIME
) {
636 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
637 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
638 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
641 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
644 if (a
& ATTR_CMN_CHGTIME
) {
646 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
647 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
648 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
651 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
654 if (a
& ATTR_CMN_ACCTIME
) {
656 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
657 tmpp
->tv_sec
= (user_time_t
) imp
->modification_date
.tv_sec
;
658 tmpp
->tv_nsec
= imp
->modification_date
.tv_nsec
;
661 *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
664 if (a
& ATTR_CMN_BKUPTIME
) {
665 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
666 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
667 ++((struct timespec
*)attrbufptr
);
669 if (a
& ATTR_CMN_FNDRINFO
) {
670 bzero (attrbufptr
, 32 * sizeof(u_int8_t
));
671 (u_int8_t
*)attrbufptr
+= 32 * sizeof(u_int8_t
);
673 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
674 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
675 if (a
& ATTR_CMN_ACCESSMASK
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_mode
;
676 if (a
& ATTR_CMN_FLAGS
) *((uint32_t *)attrbufptr
)++ = 0;
677 if (a
& ATTR_CMN_USERACCESS
) {
678 *((uint32_t *)attrbufptr
)++ =
679 DerivePermissionSummary(ip
->inode
.iso_uid
,
686 if ((a
= alist
->volattr
) != 0) {
687 off_t blocksize
= (off_t
)imp
->logical_block_size
;
689 if (a
& ATTR_VOL_FSTYPE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)vfs_typenum(mp
);
690 if (a
& ATTR_VOL_SIGNATURE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ISO9660SIGNATURE
;
691 if (a
& ATTR_VOL_SIZE
) *((off_t
*)attrbufptr
)++ = (off_t
)imp
->volume_space_size
* blocksize
;
692 if (a
& ATTR_VOL_SPACEFREE
) *((off_t
*)attrbufptr
)++ = 0;
693 if (a
& ATTR_VOL_SPACEAVAIL
) *((off_t
*)attrbufptr
)++ = 0;
694 if (a
& ATTR_VOL_MINALLOCATION
) *((off_t
*)attrbufptr
)++ = blocksize
;
695 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) *((off_t
*)attrbufptr
)++ = blocksize
;
696 if (a
& ATTR_VOL_IOBLOCKSIZE
) *((uint32_t *)attrbufptr
)++ = (uint32_t)blocksize
;
697 if (a
& ATTR_VOL_OBJCOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
698 if (a
& ATTR_VOL_FILECOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
699 if (a
& ATTR_VOL_DIRCOUNT
) *((uint32_t *)attrbufptr
)++ = 0;
700 if (a
& ATTR_VOL_MAXOBJCOUNT
) *((uint32_t *)attrbufptr
)++ = 0xFFFFFFFF;
701 if (a
& ATTR_VOL_NAME
) {
702 attrlength
= strlen( imp
->volume_id
) + 1;
703 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
704 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
705 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
707 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
708 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
709 ++((struct attrreference
*)attrbufptr
);
711 if (a
& ATTR_VOL_MOUNTFLAGS
) {
712 *((uint32_t *)attrbufptr
)++ = (uint32_t)vfs_flags(mp
);
714 if (a
& ATTR_VOL_MOUNTEDDEVICE
) {
715 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
716 ((struct attrreference
*)attrbufptr
)->attr_length
= strlen(vfs_statfs(mp
)->f_mntfromname
) + 1;
717 attrlength
= ((struct attrreference
*)attrbufptr
)->attr_length
;
718 attrlength
= attrlength
+ ((4 - (attrlength
& 3)) & 3); /* round up to the next 4-byte boundary: */
719 (void) bcopy(vfs_statfs(mp
)->f_mntfromname
, varbufptr
, attrlength
);
721 /* Advance beyond the space just allocated: */
722 (u_int8_t
*)varbufptr
+= attrlength
;
723 ++((struct attrreference
*)attrbufptr
);
725 if (a
& ATTR_VOL_ENCODINGSUSED
) *((unsigned long long *)attrbufptr
)++ = (unsigned long long)0;
726 if (a
& ATTR_VOL_CAPABILITIES
) {
727 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_FORMAT
] =
728 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_SYMBOLICLINKS
: 0) |
729 (imp
->iso_ftype
== ISO_FTYPE_RRIP
? VOL_CAP_FMT_HARDLINKS
: 0) |
730 (imp
->iso_ftype
== ISO_FTYPE_RRIP
|| imp
->iso_ftype
== ISO_FTYPE_JOLIET
731 ? VOL_CAP_FMT_CASE_SENSITIVE
: 0) |
732 VOL_CAP_FMT_CASE_PRESERVING
|
733 VOL_CAP_FMT_FAST_STATFS
;
734 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_INTERFACES
] =
735 VOL_CAP_INT_ATTRLIST
|
736 VOL_CAP_INT_NFSEXPORT
;
737 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED1
] = 0;
738 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED2
] = 0;
740 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_FORMAT
] =
741 VOL_CAP_FMT_PERSISTENTOBJECTIDS
|
742 VOL_CAP_FMT_SYMBOLICLINKS
|
743 VOL_CAP_FMT_HARDLINKS
|
744 VOL_CAP_FMT_JOURNAL
|
745 VOL_CAP_FMT_JOURNAL_ACTIVE
|
746 VOL_CAP_FMT_NO_ROOT_TIMES
|
747 VOL_CAP_FMT_SPARSE_FILES
|
748 VOL_CAP_FMT_ZERO_RUNS
|
749 VOL_CAP_FMT_CASE_SENSITIVE
|
750 VOL_CAP_FMT_CASE_PRESERVING
|
751 VOL_CAP_FMT_FAST_STATFS
|
752 VOL_CAP_FMT_2TB_FILESIZE
;
753 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_INTERFACES
] =
754 VOL_CAP_INT_SEARCHFS
|
755 VOL_CAP_INT_ATTRLIST
|
756 VOL_CAP_INT_NFSEXPORT
|
757 VOL_CAP_INT_READDIRATTR
|
758 VOL_CAP_INT_EXCHANGEDATA
|
759 VOL_CAP_INT_COPYFILE
|
760 VOL_CAP_INT_ALLOCATE
|
761 VOL_CAP_INT_VOL_RENAME
|
762 VOL_CAP_INT_ADVLOCK
|
764 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
765 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
767 ++((vol_capabilities_attr_t
*)attrbufptr
);
769 if (a
& ATTR_VOL_ATTRIBUTES
) {
770 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.commonattr
= ATTR_CMN_VALIDMASK
;
771 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.volattr
= ATTR_VOL_VALIDMASK
;
772 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.dirattr
= ATTR_DIR_VALIDMASK
;
773 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.fileattr
= ATTR_FILE_VALIDMASK
;
774 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.forkattr
= ATTR_FORK_VALIDMASK
;
776 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.commonattr
= ATTR_CMN_VALIDMASK
;
777 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.volattr
= ATTR_VOL_VALIDMASK
;
778 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.dirattr
= ATTR_DIR_VALIDMASK
;
779 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.fileattr
= ATTR_FILE_VALIDMASK
;
780 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.forkattr
= ATTR_FORK_VALIDMASK
;
782 ++((vol_attributes_attr_t
*)attrbufptr
);
786 *attrbufptrptr
= attrbufptr
;
787 *varbufptrptr
= varbufptr
;
792 packcommonattr (struct attrlist
*alist
,
794 void **attrbufptrptr
,
801 boolean_t is_64_bit
= proc_is64bit(current_proc());
803 attrbufptr
= *attrbufptrptr
;
804 varbufptr
= *varbufptrptr
;
806 if ((a
= alist
->commonattr
) != 0) {
807 struct iso_mnt
*imp
= ip
->i_mnt
;
809 if (a
& ATTR_CMN_NAME
) {
810 /* special case root since we know how to get it's name */
811 if (vnode_isvroot(ITOV(ip
))) {
812 attrlength
= strlen( imp
->volume_id
) + 1;
813 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
815 attrlength
= strlen(ip
->i_namep
) + 1;
816 (void) strncpy((unsigned char *)varbufptr
, ip
->i_namep
, attrlength
);
819 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
820 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
821 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
822 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
823 ++((struct attrreference
*)attrbufptr
);
825 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = ip
->i_dev
;
826 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = vfs_statfs(vnode_mount(ITOV(ip
)))->f_fsid
;
827 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = vnode_vtype(ITOV(ip
));
828 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = vnode_tag(ITOV(ip
));
829 if (a
& ATTR_CMN_OBJID
) {
830 if (vnode_isvroot(ITOV(ip
)))
831 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
833 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
834 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
835 ++((fsobj_id_t
*)attrbufptr
);
837 if (a
& ATTR_CMN_OBJPERMANENTID
) {
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_PAROBJID
) {
846 struct iso_directory_record
*dp
= (struct iso_directory_record
*)imp
->root
;
847 ino_t rootino
= isodirino(dp
, imp
);
849 if (ip
->i_number
== rootino
)
850 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 1; /* force root parent to be 1 */
851 else if (ip
->i_parent
== rootino
)
852 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
854 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_parent
;
855 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
856 ++((fsobj_id_t
*)attrbufptr
);
858 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
859 if (a
& ATTR_CMN_CRTIME
) {
861 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
862 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_mtime
.tv_sec
;
863 tmpp
->tv_nsec
= ip
->inode
.iso_mtime
.tv_nsec
;
866 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
869 if (a
& ATTR_CMN_MODTIME
) {
871 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
872 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_mtime
.tv_sec
;
873 tmpp
->tv_nsec
= ip
->inode
.iso_mtime
.tv_nsec
;
876 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
879 if (a
& ATTR_CMN_CHGTIME
) {
881 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
882 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_ctime
.tv_sec
;
883 tmpp
->tv_nsec
= ip
->inode
.iso_ctime
.tv_nsec
;
886 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_ctime
;
889 if (a
& ATTR_CMN_ACCTIME
) {
891 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
892 tmpp
->tv_sec
= (user_time_t
) ip
->inode
.iso_atime
.tv_sec
;
893 tmpp
->tv_nsec
= ip
->inode
.iso_atime
.tv_nsec
;
896 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
899 if (a
& ATTR_CMN_BKUPTIME
) {
901 struct user_timespec
*tmpp
= ((struct user_timespec
*)attrbufptr
)++;
902 tmpp
->tv_sec
= (user_time_t
) 0;
906 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
907 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
908 ++((struct timespec
*)attrbufptr
);
909 *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
912 if (a
& ATTR_CMN_FNDRINFO
) {
913 struct finder_info finfo
;
915 bzero(&finfo
, sizeof(finfo
));
916 finfo
.fdFlags
= ip
->i_FinderFlags
;
917 finfo
.fdLocation
.v
= -1;
918 finfo
.fdLocation
.h
= -1;
919 if (vnode_isreg(ITOV(ip
))) {
920 finfo
.fdType
= ip
->i_FileType
;
921 finfo
.fdCreator
= ip
->i_Creator
;
923 bcopy (&finfo
, attrbufptr
, sizeof(finfo
));
924 (u_int8_t
*)attrbufptr
+= sizeof(finfo
);
925 bzero (attrbufptr
, EXTFNDRINFOSIZE
);
926 (u_int8_t
*)attrbufptr
+= EXTFNDRINFOSIZE
;
928 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
929 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
930 if (a
& ATTR_CMN_ACCESSMASK
) *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_mode
;
931 if (a
& ATTR_CMN_FLAGS
) *((uint32_t *)attrbufptr
)++ = 0; /* could also use ip->i_flag */
932 if (a
& ATTR_CMN_USERACCESS
) {
933 *((uint32_t *)attrbufptr
)++ =
934 DerivePermissionSummary(ip
->inode
.iso_uid
,
941 *attrbufptrptr
= attrbufptr
;
942 *varbufptrptr
= varbufptr
;
947 packdirattr(struct attrlist
*alist
,
949 void **attrbufptrptr
,
950 __unused
void **varbufptrptr
)
956 attrbufptr
= *attrbufptrptr
;
960 if (vnode_isdir(ITOV(ip
)) && (a
!= 0)) {
962 * if we haven't counted our children yet, do it now...
964 if ((ip
->i_entries
== 0) &&
965 (a
& (ATTR_DIR_LINKCOUNT
| ATTR_DIR_ENTRYCOUNT
))) {
966 (void) isochildcount(ITOV(ip
), &dircnt
, &filcnt
);
968 if ((ip
->inode
.iso_links
== 1) && (dircnt
!= 0))
969 ip
->inode
.iso_links
= dircnt
;
970 if ((filcnt
+ dircnt
) > 0)
971 ip
->i_entries
= dircnt
+ filcnt
;
974 if (a
& ATTR_DIR_LINKCOUNT
) {
975 *((uint32_t *)attrbufptr
)++ = ip
->inode
.iso_links
;
977 if (a
& ATTR_DIR_ENTRYCOUNT
) {
978 /* exclude '.' and '..' from total caount */
979 *((uint32_t *)attrbufptr
)++ = ((ip
->i_entries
<= 2) ? 0 : (ip
->i_entries
- 2));
981 if (a
& ATTR_DIR_MOUNTSTATUS
) {
982 if (vnode_mountedhere(ITOV(ip
))) {
983 *((uint32_t *)attrbufptr
)++ = DIR_MNTSTATUS_MNTPOINT
;
985 *((uint32_t *)attrbufptr
)++ = 0;
990 *attrbufptrptr
= attrbufptr
;
995 packfileattr(struct attrlist
*alist
,
997 void **attrbufptrptr
,
1000 void *attrbufptr
= *attrbufptrptr
;
1001 void *varbufptr
= *varbufptrptr
;
1002 attrgroup_t a
= alist
->fileattr
;
1004 if (vnode_isreg(ITOV(ip
)) && (a
!= 0)) {
1005 if (a
& ATTR_FILE_LINKCOUNT
)
1006 *((uint32_t *)attrbufptr
)++ = ip
->inode
.iso_links
;
1007 if (a
& ATTR_FILE_TOTALSIZE
)
1008 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1009 if (a
& ATTR_FILE_ALLOCSIZE
)
1010 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1011 if (a
& ATTR_FILE_IOBLOCKSIZE
)
1012 *((uint32_t *)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
1013 if (a
& ATTR_FILE_CLUMPSIZE
)
1014 *((uint32_t *)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
1015 if (a
& ATTR_FILE_DEVTYPE
)
1016 *((uint32_t *)attrbufptr
)++ = (uint32_t)ip
->inode
.iso_rdev
;
1017 if (a
& ATTR_FILE_DATALENGTH
)
1018 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1019 if (a
& ATTR_FILE_DATAALLOCSIZE
)
1020 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
1021 if (a
& ATTR_FILE_RSRCLENGTH
)
1022 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
1023 if (a
& ATTR_FILE_RSRCALLOCSIZE
)
1024 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
1027 *attrbufptrptr
= attrbufptr
;
1028 *varbufptrptr
= varbufptr
;
1033 packattrblk(struct attrlist
*alist
,
1035 void **attrbufptrptr
,
1036 void **varbufptrptr
)
1038 struct iso_node
*ip
= VTOI(vp
);
1040 if (alist
->volattr
!= 0) {
1041 packvolattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1043 packcommonattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1045 switch (vnode_vtype(ITOV(ip
))) {
1047 packdirattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1051 packfileattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
1054 /* Without this the compiler complains about VNON,VBLK,VCHR,VLNK,VSOCK,VFIFO,VBAD and VSTR
1055 not being handled...