2 * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* $NetBSD: cd9660_util.c,v 1.8 1994/12/13 22:33:25 mycroft Exp $ */
29 * The Regents of the University of California. All rights reserved.
31 * This code is derived from software contributed to Berkeley
32 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
33 * Support code is derived from software contributed to Berkeley
34 * by Atsushi Murai (amurai@spec.co.jp).
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * @(#)cd9660_util.c 8.3 (Berkeley) 12/5/94
67 * 7-Dec-98 Add ATTR_VOL_MOUNTFLAGS attribute support - djb
68 * 18-Nov-98 Add support for volfs - djb
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/vnode.h>
74 #include <sys/mount.h>
75 #include <sys/namei.h>
76 #include <sys/resourcevar.h>
77 #include <sys/kernel.h>
83 #include <sys/utfconv.h>
84 #include <miscfs/specfs/specdev.h> /* XXX */
85 #include <miscfs/fifofs/fifo.h> /* XXX */
86 #include <sys/malloc.h>
89 #include <kern/assert.h>
90 #include <architecture/byte_order.h>
92 #include <isofs/cd9660/iso.h>
93 #include <isofs/cd9660/cd9660_node.h>
94 #include <isofs/cd9660/iso_rrip.h>
97 * translate and compare a filename
98 * Note: Version number plus ';' may be omitted.
101 isofncmp(fn
, fnlen
, isofn
, isolen
)
108 while (--fnlen
>= 0) {
111 if ((c
= *isofn
++) == ';') {
120 for (i
= 0; --fnlen
>= 0; i
= i
* 10 + *fn
++ - '0') {
121 if (*fn
< '0' || *fn
> '9') {
125 for (j
= 0; --isolen
>= 0; j
= j
* 10 + *isofn
++ - '0');
128 /* if raw comparison fails, check if char was mapped */
130 if (c
>= 'A' && c
<= 'Z') {
131 if (c
+ ('a' - 'A') != *fn
) {
132 if (*fn
>= 'a' && *fn
<= 'z')
133 return *fn
- ('a' - 'A') - c
;
137 } else if (c
== '/') {
140 } else if (c
> 0 || *fn
!= '_')
161 * translate and compare a UCS-2 filename
162 * Note: Version number plus ';' may be omitted.
166 ucsfncmp(fn
, fnlen
, ucsfn
, 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(infn
, infnlen
, outfn
, outfnlen
, original
)
223 u_char
*infn
, *outfn
;
230 for (; fnidx
< infnlen
; fnidx
++) {
234 * Some ISO 9600 CD names contain 8-bit chars.
235 * These chars are mapped to '_' because there
236 * is no context for mapping them to UTF-8.
237 * In addition '/' is mapped to ':'.
239 * isofncmp accounts for these mappings.
246 else if (c
== '.' && *infn
== ';')
259 * translate a UCS-2 filename to UTF-8
262 ucsfntrans(infn
, infnlen
, outfn
, outfnlen
, dir
)
272 if (*(u_char
*)infn
== 0)
274 else if (*(u_char
*)infn
== 1)
285 /* strip file version number */
286 for (fnidx
--; fnidx
> 0; fnidx
--) {
287 /* stop when ';' is found */
288 if (infn
[fnidx
] == UCS_SEPARATOR2
) {
289 /* drop dangling dot */
290 if (fnidx
> 0 && infn
[fnidx
-1] == UCS_SEPARATOR1
)
299 flags
= UTF_NO_NULL_TERM
| UTF_DECOMPOSED
;
300 if (BYTE_ORDER
!= BIG_ENDIAN
)
301 flags
|= UTF_REVERSE_ENDIAN
;
303 (void) utf8_encodestr(infn
, fnidx
* 2, outfn
, &outbytes
, ISO_JOLIET_NAMEMAX
, 0, flags
);
304 *outfnlen
= outbytes
;
310 * count the number of children by enumerating the directory
313 isochildcount(vdp
, dircnt
, filcnt
)
319 struct buf
*bp
= NULL
;
320 struct iso_directory_record
*ep
;
330 bmask
= dp
->i_mnt
->im_bmask
;
331 logblksize
= dp
->i_mnt
->logical_block_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
= VOP_BLKATOFF(vdp
, diroffset
, NULL
, &bp
)) )
348 ep
= (struct iso_directory_record
*)
349 ((char *)bp
->b_data
+ 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 */
366 if ( isonum_711(ep
->flags
) & directoryBit
)
368 else if ((isonum_711(ep
->flags
) & associatedBit
) == 0)
386 * There are two ways to qualify for ownership rights on an object:
388 * 1. Your UID matches the UID of the vnode
392 static int cd9660_owner_rights(uid_t owner
, struct iso_mnt
*imp
, struct ucred
*cred
, struct proc
*p
, int invokesuperuserstatus
) {
393 return ((cred
->cr_uid
== owner
) || /* [1] */
394 (invokesuperuserstatus
&& (suser(cred
, &p
->p_acflag
) == 0))) ? 0 : EPERM
; /* [2] */
399 static unsigned long DerivePermissionSummary(uid_t owner
, gid_t group
, mode_t obj_mode
, struct iso_mnt
*imp
, struct ucred
*cred
, struct proc
*p
) {
401 unsigned long permissions
;
404 /* User id 0 (root) always gets access. */
405 if (cred
->cr_uid
== 0) {
406 permissions
= R_OK
| X_OK
;
410 /* Otherwise, check the owner. */
411 if (cd9660_owner_rights(owner
, imp
, cred
, p
, 0) == 0) {
412 permissions
= ((unsigned long)obj_mode
& S_IRWXU
) >> 6;
416 /* Otherwise, check the groups. */
417 for (i
= 0, gp
= cred
->cr_groups
; i
< cred
->cr_ngroups
; i
++, gp
++) {
419 permissions
= ((unsigned long)obj_mode
& S_IRWXG
) >> 3;
424 /* Otherwise, settle for 'others' access. */
425 permissions
= (unsigned long)obj_mode
& S_IRWXO
;
428 return permissions
& ~W_OK
; /* Write access is always impossible */
433 attrcalcsize(struct attrlist
*attrlist
)
438 #if ((ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_FSID | ATTR_CMN_OBJTYPE | \
439 ATTR_CMN_OBJTAG | ATTR_CMN_OBJID | ATTR_CMN_OBJPERMANENTID | ATTR_CMN_PAROBJID | \
440 ATTR_CMN_SCRIPT | ATTR_CMN_CRTIME | ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME | \
441 ATTR_CMN_ACCTIME | ATTR_CMN_BKUPTIME | ATTR_CMN_FNDRINFO | ATTR_CMN_OWNERID | \
442 ATTR_CMN_GRPID | ATTR_CMN_ACCESSMASK | ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST| \
443 ATTR_CMN_FLAGS | ATTR_CMN_USERACCESS) != ATTR_CMN_VALIDMASK)
444 #error AttributeBlockSize: Missing bits in common mask computation!
446 assert((attrlist
->commonattr
& ~ATTR_CMN_VALIDMASK
) == 0);
448 #if ((ATTR_VOL_FSTYPE | ATTR_VOL_SIGNATURE | ATTR_VOL_SIZE | ATTR_VOL_SPACEFREE | \
449 ATTR_VOL_SPACEAVAIL | ATTR_VOL_MINALLOCATION | ATTR_VOL_ALLOCATIONCLUMP | ATTR_VOL_IOBLOCKSIZE | \
450 ATTR_VOL_OBJCOUNT | ATTR_VOL_FILECOUNT | ATTR_VOL_DIRCOUNT | ATTR_VOL_MAXOBJCOUNT | \
451 ATTR_VOL_MOUNTPOINT | ATTR_VOL_NAME | ATTR_VOL_MOUNTFLAGS | ATTR_VOL_INFO | \
452 ATTR_VOL_MOUNTEDDEVICE| ATTR_VOL_ENCODINGSUSED | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES) != ATTR_VOL_VALIDMASK)
453 #error AttributeBlockSize: Missing bits in volume mask computation!
455 assert((attrlist
->volattr
& ~ATTR_VOL_VALIDMASK
) == 0);
457 #if ((ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT | ATTR_DIR_MOUNTSTATUS) != ATTR_DIR_VALIDMASK)
458 #error AttributeBlockSize: Missing bits in directory mask computation!
460 assert((attrlist
->dirattr
& ~ATTR_DIR_VALIDMASK
) == 0);
461 #if ((ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE | ATTR_FILE_ALLOCSIZE | ATTR_FILE_IOBLOCKSIZE | \
462 ATTR_FILE_CLUMPSIZE | ATTR_FILE_DEVTYPE | ATTR_FILE_FILETYPE | ATTR_FILE_FORKCOUNT | \
463 ATTR_FILE_FORKLIST | ATTR_FILE_DATALENGTH | ATTR_FILE_DATAALLOCSIZE | ATTR_FILE_DATAEXTENTS | \
464 ATTR_FILE_RSRCLENGTH | ATTR_FILE_RSRCALLOCSIZE | ATTR_FILE_RSRCEXTENTS) != ATTR_FILE_VALIDMASK)
465 #error AttributeBlockSize: Missing bits in file mask computation!
467 assert((attrlist
->fileattr
& ~ATTR_FILE_VALIDMASK
) == 0);
469 #if ((ATTR_FORK_TOTALSIZE | ATTR_FORK_ALLOCSIZE) != ATTR_FORK_VALIDMASK)
470 #error AttributeBlockSize: Missing bits in fork mask computation!
472 assert((attrlist
->forkattr
& ~ATTR_FORK_VALIDMASK
) == 0);
476 if ((a
= attrlist
->commonattr
) != 0) {
477 if (a
& ATTR_CMN_NAME
) size
+= sizeof(struct attrreference
);
478 if (a
& ATTR_CMN_DEVID
) size
+= sizeof(dev_t
);
479 if (a
& ATTR_CMN_FSID
) size
+= sizeof(fsid_t
);
480 if (a
& ATTR_CMN_OBJTYPE
) size
+= sizeof(fsobj_type_t
);
481 if (a
& ATTR_CMN_OBJTAG
) size
+= sizeof(fsobj_tag_t
);
482 if (a
& ATTR_CMN_OBJID
) size
+= sizeof(fsobj_id_t
);
483 if (a
& ATTR_CMN_OBJPERMANENTID
) size
+= sizeof(fsobj_id_t
);
484 if (a
& ATTR_CMN_PAROBJID
) size
+= sizeof(fsobj_id_t
);
485 if (a
& ATTR_CMN_SCRIPT
) size
+= sizeof(text_encoding_t
);
486 if (a
& ATTR_CMN_CRTIME
) size
+= sizeof(struct timespec
);
487 if (a
& ATTR_CMN_MODTIME
) size
+= sizeof(struct timespec
);
488 if (a
& ATTR_CMN_CHGTIME
) size
+= sizeof(struct timespec
);
489 if (a
& ATTR_CMN_ACCTIME
) size
+= sizeof(struct timespec
);
490 if (a
& ATTR_CMN_BKUPTIME
) size
+= sizeof(struct timespec
);
491 if (a
& ATTR_CMN_FNDRINFO
) size
+= 32 * sizeof(u_int8_t
);
492 if (a
& ATTR_CMN_OWNERID
) size
+= sizeof(uid_t
);
493 if (a
& ATTR_CMN_GRPID
) size
+= sizeof(gid_t
);
494 if (a
& ATTR_CMN_ACCESSMASK
) size
+= sizeof(u_long
);
495 if (a
& ATTR_CMN_NAMEDATTRCOUNT
) size
+= sizeof(u_long
);
496 if (a
& ATTR_CMN_NAMEDATTRLIST
) size
+= sizeof(struct attrreference
);
497 if (a
& ATTR_CMN_FLAGS
) size
+= sizeof(u_long
);
498 if (a
& ATTR_CMN_USERACCESS
) size
+= sizeof(u_long
);
500 if ((a
= attrlist
->volattr
) != 0) {
501 if (a
& ATTR_VOL_FSTYPE
) size
+= sizeof(u_long
);
502 if (a
& ATTR_VOL_SIGNATURE
) size
+= sizeof(u_long
);
503 if (a
& ATTR_VOL_SIZE
) size
+= sizeof(off_t
);
504 if (a
& ATTR_VOL_SPACEFREE
) size
+= sizeof(off_t
);
505 if (a
& ATTR_VOL_SPACEAVAIL
) size
+= sizeof(off_t
);
506 if (a
& ATTR_VOL_MINALLOCATION
) size
+= sizeof(off_t
);
507 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) size
+= sizeof(off_t
);
508 if (a
& ATTR_VOL_IOBLOCKSIZE
) size
+= sizeof(size_t);
509 if (a
& ATTR_VOL_OBJCOUNT
) size
+= sizeof(u_long
);
510 if (a
& ATTR_VOL_FILECOUNT
) size
+= sizeof(u_long
);
511 if (a
& ATTR_VOL_DIRCOUNT
) size
+= sizeof(u_long
);
512 if (a
& ATTR_VOL_MAXOBJCOUNT
) size
+= sizeof(u_long
);
513 if (a
& ATTR_VOL_MOUNTPOINT
) size
+= sizeof(struct attrreference
);
514 if (a
& ATTR_VOL_NAME
) size
+= sizeof(struct attrreference
);
515 if (a
& ATTR_VOL_MOUNTFLAGS
) size
+= sizeof(u_long
);
516 if (a
& ATTR_VOL_MOUNTEDDEVICE
) size
+= sizeof(struct attrreference
);
517 if (a
& ATTR_VOL_ENCODINGSUSED
) size
+= sizeof(unsigned long long);
518 if (a
& ATTR_VOL_CAPABILITIES
) size
+= sizeof(vol_capabilities_attr_t
);
519 if (a
& ATTR_VOL_ATTRIBUTES
) size
+= sizeof(vol_attributes_attr_t
);
521 if ((a
= attrlist
->dirattr
) != 0) {
522 if (a
& ATTR_DIR_LINKCOUNT
) size
+= sizeof(u_long
);
523 if (a
& ATTR_DIR_ENTRYCOUNT
) size
+= sizeof(u_long
);
524 if (a
& ATTR_DIR_MOUNTSTATUS
) size
+= sizeof(u_long
);
526 if ((a
= attrlist
->fileattr
) != 0) {
527 if (a
& ATTR_FILE_LINKCOUNT
) size
+= sizeof(u_long
);
528 if (a
& ATTR_FILE_TOTALSIZE
) size
+= sizeof(off_t
);
529 if (a
& ATTR_FILE_ALLOCSIZE
) size
+= sizeof(off_t
);
530 if (a
& ATTR_FILE_IOBLOCKSIZE
) size
+= sizeof(size_t);
531 if (a
& ATTR_FILE_CLUMPSIZE
) size
+= sizeof(off_t
);
532 if (a
& ATTR_FILE_DEVTYPE
) size
+= sizeof(u_long
);
533 if (a
& ATTR_FILE_FILETYPE
) size
+= sizeof(u_long
);
534 if (a
& ATTR_FILE_FORKCOUNT
) size
+= sizeof(u_long
);
535 if (a
& ATTR_FILE_FORKLIST
) size
+= sizeof(struct attrreference
);
536 if (a
& ATTR_FILE_DATALENGTH
) size
+= sizeof(off_t
);
537 if (a
& ATTR_FILE_DATAALLOCSIZE
) size
+= sizeof(off_t
);
538 if (a
& ATTR_FILE_DATAEXTENTS
) size
+= sizeof(extentrecord
);
539 if (a
& ATTR_FILE_RSRCLENGTH
) size
+= sizeof(off_t
);
540 if (a
& ATTR_FILE_RSRCALLOCSIZE
) size
+= sizeof(off_t
);
541 if (a
& ATTR_FILE_RSRCEXTENTS
) size
+= sizeof(extentrecord
);
543 if ((a
= attrlist
->forkattr
) != 0) {
544 if (a
& ATTR_FORK_TOTALSIZE
) size
+= sizeof(off_t
);
545 if (a
& ATTR_FORK_ALLOCSIZE
) size
+= sizeof(off_t
);
554 packvolattr (struct attrlist
*alist
,
555 struct iso_node
*ip
, /* ip for root directory */
556 void **attrbufptrptr
,
566 attrbufptr
= *attrbufptrptr
;
567 varbufptr
= *varbufptrptr
;
571 if ((a
= alist
->commonattr
) != 0) {
572 if (a
& ATTR_CMN_NAME
) {
573 attrlength
= strlen( imp
->volume_id
) + 1;
574 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
575 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
576 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
578 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
579 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
580 ++((struct attrreference
*)attrbufptr
);
582 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = imp
->im_devvp
->v_rdev
;
583 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = ITOV(ip
)->v_mount
->mnt_stat
.f_fsid
;
584 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = 0;
585 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = VT_ISOFS
;
586 if (a
& ATTR_CMN_OBJID
) {
587 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
588 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
589 ++((fsobj_id_t
*)attrbufptr
);
591 if (a
& ATTR_CMN_OBJPERMANENTID
) {
592 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
593 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
594 ++((fsobj_id_t
*)attrbufptr
);
596 if (a
& ATTR_CMN_PAROBJID
) {
597 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 0;
598 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
599 ++((fsobj_id_t
*)attrbufptr
);
601 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
602 if (a
& ATTR_CMN_CRTIME
) *((struct timespec
*)attrbufptr
)++ = imp
->creation_date
;
603 if (a
& ATTR_CMN_MODTIME
) *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
604 if (a
& ATTR_CMN_CHGTIME
) *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
605 if (a
& ATTR_CMN_ACCTIME
) *((struct timespec
*)attrbufptr
)++ = imp
->modification_date
;
606 if (a
& ATTR_CMN_BKUPTIME
) {
607 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
608 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
609 ++((struct timespec
*)attrbufptr
);
611 if (a
& ATTR_CMN_FNDRINFO
) {
612 bzero (attrbufptr
, 32 * sizeof(u_int8_t
));
613 (u_int8_t
*)attrbufptr
+= 32 * sizeof(u_int8_t
);
615 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
616 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
617 if (a
& ATTR_CMN_ACCESSMASK
) *((u_long
*)attrbufptr
)++ = (u_long
)ip
->inode
.iso_mode
;
618 if (a
& ATTR_CMN_FLAGS
) *((u_long
*)attrbufptr
)++ = 0;
619 if (a
& ATTR_CMN_USERACCESS
) {
620 *((u_long
*)attrbufptr
)++ =
621 DerivePermissionSummary(ip
->inode
.iso_uid
,
625 current_proc()->p_ucred
,
630 if ((a
= alist
->volattr
) != 0) {
631 off_t blocksize
= (off_t
)imp
->logical_block_size
;
633 if (a
& ATTR_VOL_FSTYPE
) *((u_long
*)attrbufptr
)++ = (u_long
)imp
->im_mountp
->mnt_vfc
->vfc_typenum
;
634 if (a
& ATTR_VOL_SIGNATURE
) *((u_long
*)attrbufptr
)++ = (u_long
)ISO9660SIGNATURE
;
635 if (a
& ATTR_VOL_SIZE
) *((off_t
*)attrbufptr
)++ = (off_t
)imp
->volume_space_size
* blocksize
;
636 if (a
& ATTR_VOL_SPACEFREE
) *((off_t
*)attrbufptr
)++ = 0;
637 if (a
& ATTR_VOL_SPACEAVAIL
) *((off_t
*)attrbufptr
)++ = 0;
638 if (a
& ATTR_VOL_MINALLOCATION
) *((off_t
*)attrbufptr
)++ = blocksize
;
639 if (a
& ATTR_VOL_ALLOCATIONCLUMP
) *((off_t
*)attrbufptr
)++ = blocksize
;
640 if (a
& ATTR_VOL_IOBLOCKSIZE
) *((size_t *)attrbufptr
)++ = blocksize
;
641 if (a
& ATTR_VOL_OBJCOUNT
) *((u_long
*)attrbufptr
)++ = 0;
642 if (a
& ATTR_VOL_FILECOUNT
) *((u_long
*)attrbufptr
)++ = 0;
643 if (a
& ATTR_VOL_DIRCOUNT
) *((u_long
*)attrbufptr
)++ = 0;
644 if (a
& ATTR_VOL_MAXOBJCOUNT
) *((u_long
*)attrbufptr
)++ = 0xFFFFFFFF;
645 if (a
& ATTR_VOL_NAME
) {
646 attrlength
= strlen( imp
->volume_id
) + 1;
647 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
648 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
649 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
651 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
652 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
653 ++((struct attrreference
*)attrbufptr
);
655 if (a
& ATTR_VOL_MOUNTFLAGS
) *((u_long
*)attrbufptr
)++ = (u_long
)imp
->im_mountp
->mnt_flag
;
656 if (a
& ATTR_VOL_MOUNTEDDEVICE
) {
657 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
658 ((struct attrreference
*)attrbufptr
)->attr_length
= strlen(mp
->mnt_stat
.f_mntfromname
) + 1;
659 attrlength
= ((struct attrreference
*)attrbufptr
)->attr_length
;
660 attrlength
= attrlength
+ ((4 - (attrlength
& 3)) & 3); /* round up to the next 4-byte boundary: */
661 (void) bcopy(mp
->mnt_stat
.f_mntfromname
, varbufptr
, attrlength
);
663 /* Advance beyond the space just allocated: */
664 (u_int8_t
*)varbufptr
+= attrlength
;
665 ++((struct attrreference
*)attrbufptr
);
667 if (a
& ATTR_VOL_ENCODINGSUSED
) *((unsigned long long *)attrbufptr
)++ = (unsigned long long)0;
668 if (a
& ATTR_VOL_CAPABILITIES
) {
669 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_FORMAT
] = VOL_CAP_FMT_PERSISTENTOBJECTIDS
;
670 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_INTERFACES
] =
671 VOL_CAP_INT_ATTRLIST
| VOL_CAP_INT_NFSEXPORT
;
672 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED1
] = 0;
673 ((vol_capabilities_attr_t
*)attrbufptr
)->capabilities
[VOL_CAPABILITIES_RESERVED2
] = 0;
675 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_FORMAT
] =
676 VOL_CAP_FMT_PERSISTENTOBJECTIDS
| VOL_CAP_FMT_SYMBOLICLINKS
| VOL_CAP_FMT_HARDLINKS
;
677 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_INTERFACES
] =
678 VOL_CAP_INT_SEARCHFS
| VOL_CAP_INT_ATTRLIST
| VOL_CAP_INT_NFSEXPORT
;
679 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
680 ((vol_capabilities_attr_t
*)attrbufptr
)->valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
682 ++((vol_capabilities_attr_t
*)attrbufptr
);
684 if (a
& ATTR_VOL_ATTRIBUTES
) {
685 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.commonattr
= ATTR_CMN_VALIDMASK
;
686 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.volattr
= ATTR_VOL_VALIDMASK
;
687 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.dirattr
= ATTR_DIR_VALIDMASK
;
688 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.fileattr
= ATTR_FILE_VALIDMASK
;
689 ((vol_attributes_attr_t
*)attrbufptr
)->validattr
.forkattr
= ATTR_FORK_VALIDMASK
;
691 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.commonattr
= ATTR_CMN_VALIDMASK
;
692 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.volattr
= ATTR_VOL_VALIDMASK
;
693 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.dirattr
= ATTR_DIR_VALIDMASK
;
694 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.fileattr
= ATTR_FILE_VALIDMASK
;
695 ((vol_attributes_attr_t
*)attrbufptr
)->nativeattr
.forkattr
= ATTR_FORK_VALIDMASK
;
697 ++((vol_attributes_attr_t
*)attrbufptr
);
701 *attrbufptrptr
= attrbufptr
;
702 *varbufptrptr
= varbufptr
;
707 packcommonattr (struct attrlist
*alist
,
709 void **attrbufptrptr
,
717 attrbufptr
= *attrbufptrptr
;
718 varbufptr
= *varbufptrptr
;
720 if ((a
= alist
->commonattr
) != 0) {
721 struct iso_mnt
*imp
= ip
->i_mnt
;
723 if (a
& ATTR_CMN_NAME
) {
724 /* special case root since we know how to get it's name */
725 if (ITOV(ip
)->v_flag
& VROOT
) {
726 attrlength
= strlen( imp
->volume_id
) + 1;
727 (void) strncpy((unsigned char *)varbufptr
, imp
->volume_id
, attrlength
);
729 attrlength
= strlen(ip
->i_namep
) + 1;
730 (void) strncpy((unsigned char *)varbufptr
, ip
->i_namep
, attrlength
);
733 ((struct attrreference
*)attrbufptr
)->attr_dataoffset
= (u_int8_t
*)varbufptr
- (u_int8_t
*)attrbufptr
;
734 ((struct attrreference
*)attrbufptr
)->attr_length
= attrlength
;
735 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
736 (u_int8_t
*)varbufptr
+= attrlength
+ ((4 - (attrlength
& 3)) & 3);
737 ++((struct attrreference
*)attrbufptr
);
739 if (a
& ATTR_CMN_DEVID
) *((dev_t
*)attrbufptr
)++ = ip
->i_dev
;
740 if (a
& ATTR_CMN_FSID
) *((fsid_t
*)attrbufptr
)++ = ITOV(ip
)->v_mount
->mnt_stat
.f_fsid
;
741 if (a
& ATTR_CMN_OBJTYPE
) *((fsobj_type_t
*)attrbufptr
)++ = ITOV(ip
)->v_type
;
742 if (a
& ATTR_CMN_OBJTAG
) *((fsobj_tag_t
*)attrbufptr
)++ = ITOV(ip
)->v_tag
;
743 if (a
& ATTR_CMN_OBJID
) {
744 if (ITOV(ip
)->v_flag
& VROOT
)
745 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
747 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
748 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
749 ++((fsobj_id_t
*)attrbufptr
);
751 if (a
& ATTR_CMN_OBJPERMANENTID
) {
752 if (ITOV(ip
)->v_flag
& VROOT
)
753 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
755 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_number
;
756 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
757 ++((fsobj_id_t
*)attrbufptr
);
759 if (a
& ATTR_CMN_PAROBJID
) {
760 struct iso_directory_record
*dp
= (struct iso_directory_record
*)imp
->root
;
761 ino_t rootino
= isodirino(dp
, imp
);
763 if (ip
->i_number
== rootino
)
764 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 1; /* force root parent to be 1 */
765 else if (ip
->i_parent
== rootino
)
766 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= 2; /* force root to be 2 */
768 ((fsobj_id_t
*)attrbufptr
)->fid_objno
= ip
->i_parent
;
769 ((fsobj_id_t
*)attrbufptr
)->fid_generation
= 0;
770 ++((fsobj_id_t
*)attrbufptr
);
772 if (a
& ATTR_CMN_SCRIPT
) *((text_encoding_t
*)attrbufptr
)++ = 0;
773 if (a
& ATTR_CMN_CRTIME
) *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
774 if (a
& ATTR_CMN_MODTIME
) *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_mtime
;
775 if (a
& ATTR_CMN_CHGTIME
) *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_ctime
;
776 if (a
& ATTR_CMN_ACCTIME
) *((struct timespec
*)attrbufptr
)++ = ip
->inode
.iso_atime
;
777 if (a
& ATTR_CMN_BKUPTIME
) {
778 ((struct timespec
*)attrbufptr
)->tv_sec
= 0;
779 ((struct timespec
*)attrbufptr
)->tv_nsec
= 0;
780 ++((struct timespec
*)attrbufptr
);
782 if (a
& ATTR_CMN_FNDRINFO
) {
783 struct finder_info finfo
= {0};
785 finfo
.fdFlags
= ip
->i_FinderFlags
;
786 finfo
.fdLocation
.v
= -1;
787 finfo
.fdLocation
.h
= -1;
788 if (ITOV(ip
)->v_type
== VREG
) {
789 finfo
.fdType
= ip
->i_FileType
;
790 finfo
.fdCreator
= ip
->i_Creator
;
792 bcopy (&finfo
, attrbufptr
, sizeof(finfo
));
793 (u_int8_t
*)attrbufptr
+= sizeof(finfo
);
794 bzero (attrbufptr
, EXTFNDRINFOSIZE
);
795 (u_int8_t
*)attrbufptr
+= EXTFNDRINFOSIZE
;
797 if (a
& ATTR_CMN_OWNERID
) *((uid_t
*)attrbufptr
)++ = ip
->inode
.iso_uid
;
798 if (a
& ATTR_CMN_GRPID
) *((gid_t
*)attrbufptr
)++ = ip
->inode
.iso_gid
;
799 if (a
& ATTR_CMN_ACCESSMASK
) *((u_long
*)attrbufptr
)++ = (u_long
)ip
->inode
.iso_mode
;
800 if (a
& ATTR_CMN_FLAGS
) *((u_long
*)attrbufptr
)++ = 0; /* could also use ip->i_flag */
801 if (a
& ATTR_CMN_USERACCESS
) {
802 *((u_long
*)attrbufptr
)++ =
803 DerivePermissionSummary(ip
->inode
.iso_uid
,
807 current_proc()->p_ucred
,
812 *attrbufptrptr
= attrbufptr
;
813 *varbufptrptr
= varbufptr
;
818 packdirattr(struct attrlist
*alist
,
820 void **attrbufptrptr
,
827 attrbufptr
= *attrbufptrptr
;
831 if ((ITOV(ip
)->v_type
== VDIR
) && (a
!= 0)) {
833 * if we haven't counted our children yet, do it now...
835 if ((ip
->i_entries
== 0) &&
836 (a
& (ATTR_DIR_LINKCOUNT
| ATTR_DIR_ENTRYCOUNT
))) {
837 (void) isochildcount(ITOV(ip
), &dircnt
, &filcnt
);
839 if ((ip
->inode
.iso_links
== 1) && (dircnt
!= 0))
840 ip
->inode
.iso_links
= dircnt
;
841 if ((filcnt
+ dircnt
) > 0)
842 ip
->i_entries
= dircnt
+ filcnt
;
845 if (a
& ATTR_DIR_LINKCOUNT
) {
846 *((u_long
*)attrbufptr
)++ = ip
->inode
.iso_links
;
848 if (a
& ATTR_DIR_ENTRYCOUNT
) {
849 /* exclude '.' and '..' from total caount */
850 *((u_long
*)attrbufptr
)++ = ((ip
->i_entries
<= 2) ? 0 : (ip
->i_entries
- 2));
852 if (a
& ATTR_DIR_MOUNTSTATUS
) {
853 if (ITOV(ip
)->v_mountedhere
) {
854 *((u_long
*)attrbufptr
)++ = DIR_MNTSTATUS_MNTPOINT
;
856 *((u_long
*)attrbufptr
)++ = 0;
861 *attrbufptrptr
= attrbufptr
;
866 packfileattr(struct attrlist
*alist
,
868 void **attrbufptrptr
,
871 void *attrbufptr
= *attrbufptrptr
;
872 void *varbufptr
= *varbufptrptr
;
873 attrgroup_t a
= alist
->fileattr
;
875 if ((ITOV(ip
)->v_type
== VREG
) && (a
!= 0)) {
876 if (a
& ATTR_FILE_LINKCOUNT
)
877 *((u_long
*)attrbufptr
)++ = ip
->inode
.iso_links
;
878 if (a
& ATTR_FILE_TOTALSIZE
)
879 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
880 if (a
& ATTR_FILE_ALLOCSIZE
)
881 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
882 if (a
& ATTR_FILE_IOBLOCKSIZE
)
883 *((u_long
*)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
884 if (a
& ATTR_FILE_CLUMPSIZE
)
885 *((u_long
*)attrbufptr
)++ = ip
->i_mnt
->logical_block_size
;
886 if (a
& ATTR_FILE_DEVTYPE
)
887 *((u_long
*)attrbufptr
)++ = (u_long
)ip
->inode
.iso_rdev
;
888 if (a
& ATTR_FILE_DATALENGTH
)
889 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
890 if (a
& ATTR_FILE_DATAALLOCSIZE
)
891 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_size
;
892 if (a
& ATTR_FILE_RSRCLENGTH
)
893 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
894 if (a
& ATTR_FILE_RSRCALLOCSIZE
)
895 *((off_t
*)attrbufptr
)++ = (off_t
)ip
->i_rsrcsize
;
898 *attrbufptrptr
= attrbufptr
;
899 *varbufptrptr
= varbufptr
;
904 packattrblk(struct attrlist
*alist
,
906 void **attrbufptrptr
,
909 struct iso_node
*ip
= VTOI(vp
);
911 if (alist
->volattr
!= 0) {
912 packvolattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
914 packcommonattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
916 switch (ITOV(ip
)->v_type
) {
918 packdirattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
922 packfileattr(alist
, ip
, attrbufptrptr
, varbufptrptr
);
925 /* Without this the compiler complains about VNON,VBLK,VCHR,VLNK,VSOCK,VFIFO,VBAD and VSTR