]> git.saurik.com Git - apple/xnu.git/blame - bsd/isofs/cd9660/cd9660_util.c
xnu-792.6.61.tar.gz
[apple/xnu.git] / bsd / isofs / cd9660 / cd9660_util.c
CommitLineData
1c79356b 1/*
55e303ae 2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
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.
1c79356b 11 *
37839358
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/* $NetBSD: cd9660_util.c,v 1.8 1994/12/13 22:33:25 mycroft Exp $ */
23
24/*-
25 * Copyright (c) 1994
26 * The Regents of the University of California. All rights reserved.
27 *
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).
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
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.
48 *
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
59 * SUCH DAMAGE.
60 *
61 * @(#)cd9660_util.c 8.3 (Berkeley) 12/5/94
62 *
63 * HISTORY
64 * 7-Dec-98 Add ATTR_VOL_MOUNTFLAGS attribute support - djb
65 * 18-Nov-98 Add support for volfs - djb
66 */
67
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>
75#include <sys/file.h>
76#include <sys/stat.h>
77#include <sys/buf.h>
78#include <sys/proc.h>
91447636 79#include <sys/kauth.h>
1c79356b
A
80#include <sys/conf.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>
85#include <sys/dir.h>
86#include <sys/attr.h>
87#include <kern/assert.h>
88#include <architecture/byte_order.h>
89
90#include <isofs/cd9660/iso.h>
91#include <isofs/cd9660/cd9660_node.h>
92#include <isofs/cd9660/iso_rrip.h>
93
94/*
95 * translate and compare a filename
96 * Note: Version number plus ';' may be omitted.
97 */
98int
91447636 99isofncmp(u_char *fn, int fnlen, u_char *isofn, int isolen)
1c79356b
A
100{
101 int i, j;
102 char c;
103
104 while (--fnlen >= 0) {
105 if (--isolen < 0)
106 return *fn;
107 if ((c = *isofn++) == ';') {
108 switch (*fn++) {
109 default:
110 return *--fn;
111 case 0:
112 return 0;
113 case ';':
114 break;
115 }
116 for (i = 0; --fnlen >= 0; i = i * 10 + *fn++ - '0') {
117 if (*fn < '0' || *fn > '9') {
118 return -1;
119 }
120 }
121 for (j = 0; --isolen >= 0; j = j * 10 + *isofn++ - '0');
122 return i - j;
123 }
124 /* if raw comparison fails, check if char was mapped */
125 if (c != *fn) {
126 if (c >= 'A' && c <= 'Z') {
127 if (c + ('a' - 'A') != *fn) {
128 if (*fn >= 'a' && *fn <= 'z')
129 return *fn - ('a' - 'A') - c;
130 else
131 return *fn - c;
132 }
133 } else if (c == '/') {
134 if (*fn != ':')
135 return *fn - c;
136 } else if (c > 0 || *fn != '_')
137 return *fn - c;
138 }
139 fn++;
140 }
141 if (isolen > 0) {
142 switch (*isofn) {
143 default:
144 return -1;
145 case '.':
146 if (isofn[1] != ';')
147 return -1;
148 case ';':
149 return 0;
150 }
151 }
152 return 0;
153}
154
155
156/*
157 * translate and compare a UCS-2 filename
158 * Note: Version number plus ';' may be omitted.
159 */
160
161int
91447636 162ucsfncmp(u_int16_t *fn, int fnlen, u_int16_t *ucsfn, int ucslen)
1c79356b
A
163{
164 int i, j;
165 u_int16_t c;
166
167 /* convert byte count to char count */
168 ucslen /= 2;
169 fnlen /= 2;
170
171 while (--fnlen >= 0) {
172 if (--ucslen < 0)
173 return *fn;
174 if ((c = *ucsfn++) == UCS_SEPARATOR2) {
175 switch (*fn++) {
176 default:
177 return *--fn;
178 case 0:
179 return 0;
180 case UCS_SEPARATOR2:
181 break;
182 }
183 for (i = 0; --fnlen >= 0; i = i * 10 + *fn++ - '0') {
184 if (*fn < '0' || *fn > '9') {
185 return -1;
186 }
187 }
188 for (j = 0; --ucslen >= 0; j = j * 10 + *ucsfn++ - '0');
189 return i - j;
190 }
191 if (c != *fn)
192 return *fn - c;
193 fn++;
194 }
195 if (ucslen > 0) {
196 switch (*ucsfn) {
197 default:
198 return -1;
199 case UCS_SEPARATOR1:
200 if (ucsfn[1] != UCS_SEPARATOR2)
201 return -1;
202 case UCS_SEPARATOR2:
203 return 0;
204 }
205 }
206 return 0;
207}
208
209
210/*
211 * translate a filename
212 */
213void
91447636
A
214isofntrans(u_char *infn, int infnlen, u_char *outfn, u_short *outfnlen,
215 int original, int assoc)
1c79356b
A
216{
217 int fnidx = 0;
218
55e303ae
A
219 /*
220 * Add a "._" prefix for associated files
221 */
222 if (assoc) {
223 *outfn++ = ASSOCCHAR1;
224 *outfn++ = ASSOCCHAR2;
225 fnidx += 2;
226 infnlen +=2;
227 }
1c79356b
A
228 for (; fnidx < infnlen; fnidx++) {
229 char c = *infn++;
230
231 /*
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 ':'.
236 *
237 * isofncmp accounts for these mappings.
238 */
239 if (!original) {
240 if (c < 0)
241 c = '_';
242 else if (c == '/')
243 c = ':';
244 else if (c == '.' && *infn == ';')
245 break;
246 else if (c == ';')
247 break;
248 }
249 *outfn++ = c;
250 }
251 *outfnlen = fnidx;
252}
253
254
255
256/*
257 * translate a UCS-2 filename to UTF-8
258 */
259void
91447636
A
260ucsfntrans(u_int16_t *infn, int infnlen, u_char *outfn, u_short *outfnlen,
261 int dir, int assoc)
1c79356b
A
262{
263 if (infnlen == 1) {
264 strcpy(outfn, "..");
265
266 if (*(u_char*)infn == 0)
267 *outfnlen = 1;
268 else if (*(u_char*)infn == 1)
269 *outfnlen = 2;
270 } else {
271 int fnidx;
272 size_t outbytes;
273 int flags;
274
275 fnidx = infnlen/2;
276 flags = 0;
277
55e303ae
A
278 /*
279 * Add a "._" prefix for associated files
280 */
281 if (assoc) {
282 *outfn++ = ASSOCCHAR1;
283 *outfn++ = ASSOCCHAR2;
284 }
1c79356b
A
285 if (!dir) {
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)
292 fnidx--;
293 break;
294 }
295 }
296 if (fnidx <= 0)
297 fnidx = infnlen/2;
298 }
299
0b4e3aa0 300 flags = UTF_NO_NULL_TERM | UTF_DECOMPOSED;
1c79356b
A
301 if (BYTE_ORDER != BIG_ENDIAN)
302 flags |= UTF_REVERSE_ENDIAN;
303
304 (void) utf8_encodestr(infn, fnidx * 2, outfn, &outbytes, ISO_JOLIET_NAMEMAX, 0, flags);
55e303ae 305 *outfnlen = assoc ? outbytes + 2 : outbytes;
1c79356b
A
306 }
307}
308
309
310/*
311 * count the number of children by enumerating the directory
312 */
313static int
91447636 314isochildcount(struct vnode *vdp, int *dircnt, int *filcnt)
1c79356b
A
315{
316 struct iso_node *dp;
317 struct buf *bp = NULL;
55e303ae 318 struct iso_mnt *imp;
1c79356b 319 struct iso_directory_record *ep;
91447636 320 uint32_t bmask;
1c79356b
A
321 int error = 0;
322 int reclen;
323 int dirs, files;
324 int blkoffset;
325 int logblksize;
91447636 326 int32_t diroffset;
1c79356b
A
327
328 dp = VTOI(vdp);
55e303ae
A
329 imp = dp->i_mnt;
330 bmask = imp->im_sector_size - 1;
331 logblksize = imp->im_sector_size;
1c79356b
A
332 blkoffset = diroffset = 0;
333 dirs = files = 0;
334
335 while (diroffset < dp->i_size) {
336 /*
337 * If offset is on a block boundary, read the next
338 * directory block. Release previous if it exists.
339 */
340 if ((diroffset & bmask) == 0) {
341 if (bp != NULL)
91447636
A
342 buf_brelse(bp);
343 if ( (error = cd9660_blkatoff(vdp, SECTOFF(imp, diroffset), NULL, &bp)) )
1c79356b
A
344 break;
345 blkoffset = 0;
346 }
347
348 ep = (struct iso_directory_record *)
91447636 349 (buf_dataptr(bp) + blkoffset);
1c79356b
A
350
351 reclen = isonum_711(ep->length);
352 if (reclen == 0) {
353 /* skip to next block, if any */
354 diroffset =
355 (diroffset & ~bmask) + logblksize;
356 continue;
357 }
358
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 */
363 break;
364 }
365
55e303ae
A
366 /*
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.
370 */
371 if ((diroffset == 0) && (isonum_733(ep->size) > dp->i_size)) {
372 dp->i_size = isonum_733(ep->size);
373 }
374
1c79356b
A
375 if ( isonum_711(ep->flags) & directoryBit )
376 dirs++;
377 else if ((isonum_711(ep->flags) & associatedBit) == 0)
378 files++;
379
380 diroffset += reclen;
381 blkoffset += reclen;
382 }
383
384 if (bp)
91447636 385 buf_brelse (bp);
1c79356b
A
386
387 *dircnt = dirs;
388 *filcnt = files;
389
390 return (error);
391}
392
393
91447636
A
394static uint32_t
395DerivePermissionSummary(uid_t owner, gid_t group, mode_t obj_mode, __unused struct iso_mnt *imp)
396{
397 kauth_cred_t cred = kauth_cred_get();
398 uint32_t permissions;
399 int is_member;
1c79356b
A
400
401 /* User id 0 (root) always gets access. */
91447636 402 if (!suser(cred, NULL)) {
1c79356b
A
403 permissions = R_OK | X_OK;
404 goto Exit;
405 };
406
407 /* Otherwise, check the owner. */
91447636
A
408 if (owner == kauth_cred_getuid(cred)) {
409 permissions = ((uint32_t)obj_mode & S_IRWXU) >> 6;
1c79356b
A
410 goto Exit;
411 }
412
413 /* Otherwise, check the groups. */
91447636
A
414 if (kauth_cred_ismember_gid(cred, group, &is_member) == 0 && is_member) {
415 permissions = ((uint32_t)obj_mode & S_IRWXG) >> 3;
1c79356b 416 goto Exit;
91447636 417 }
1c79356b
A
418
419 /* Otherwise, settle for 'others' access. */
91447636 420 permissions = (uint32_t)obj_mode & S_IRWXO;
1c79356b
A
421
422Exit:
423 return permissions & ~W_OK; /* Write access is always impossible */
424}
425
426
427int
428attrcalcsize(struct attrlist *attrlist)
429{
430 int size;
431 attrgroup_t a;
91447636 432 boolean_t is_64_bit = proc_is64bit(current_proc());
1c79356b
A
433
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!
441#endif
442 assert((attrlist->commonattr & ~ATTR_CMN_VALIDMASK) == 0);
443
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!
450#endif
451 assert((attrlist->volattr & ~ATTR_VOL_VALIDMASK) == 0);
452
453#if ((ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT | ATTR_DIR_MOUNTSTATUS) != ATTR_DIR_VALIDMASK)
454#error AttributeBlockSize: Missing bits in directory mask computation!
455#endif
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!
462#endif
463 assert((attrlist->fileattr & ~ATTR_FILE_VALIDMASK) == 0);
464
465#if ((ATTR_FORK_TOTALSIZE | ATTR_FORK_ALLOCSIZE) != ATTR_FORK_VALIDMASK)
466#error AttributeBlockSize: Missing bits in fork mask computation!
467#endif
468 assert((attrlist->forkattr & ~ATTR_FORK_VALIDMASK) == 0);
469
470 size = 0;
471
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);
91447636
A
482 if (a & ATTR_CMN_CRTIME) {
483 if (is_64_bit)
484 size += sizeof(struct user_timespec);
485 else
486 size += sizeof(struct timespec);
487 }
488 if (a & ATTR_CMN_MODTIME) {
489 if (is_64_bit)
490 size += sizeof(struct user_timespec);
491 else
492 size += sizeof(struct timespec);
493 }
494 if (a & ATTR_CMN_CHGTIME) {
495 if (is_64_bit)
496 size += sizeof(struct user_timespec);
497 else
498 size += sizeof(struct timespec);
499 }
500 if (a & ATTR_CMN_ACCTIME) {
501 if (is_64_bit)
502 size += sizeof(struct user_timespec);
503 else
504 size += sizeof(struct timespec);
505 }
506 if (a & ATTR_CMN_BKUPTIME) {
507 if (is_64_bit)
508 size += sizeof(struct user_timespec);
509 else
510 size += sizeof(struct timespec);
511 }
1c79356b
A
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);
91447636
A
515 if (a & ATTR_CMN_ACCESSMASK) size += sizeof(uint32_t);
516 if (a & ATTR_CMN_NAMEDATTRCOUNT) size += sizeof(uint32_t);
1c79356b 517 if (a & ATTR_CMN_NAMEDATTRLIST) size += sizeof(struct attrreference);
91447636
A
518 if (a & ATTR_CMN_FLAGS) size += sizeof(uint32_t);
519 if (a & ATTR_CMN_USERACCESS) size += sizeof(uint32_t);
1c79356b
A
520 };
521 if ((a = attrlist->volattr) != 0) {
91447636
A
522 if (a & ATTR_VOL_FSTYPE) size += sizeof(uint32_t);
523 if (a & ATTR_VOL_SIGNATURE) size += sizeof(uint32_t);
1c79356b
A
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);
91447636
A
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);
1c79356b
A
534 if (a & ATTR_VOL_MOUNTPOINT) size += sizeof(struct attrreference);
535 if (a & ATTR_VOL_NAME) size += sizeof(struct attrreference);
91447636 536 if (a & ATTR_VOL_MOUNTFLAGS) size += sizeof(uint32_t);
1c79356b
A
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);
541 };
542 if ((a = attrlist->dirattr) != 0) {
91447636
A
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);
1c79356b
A
546 };
547 if ((a = attrlist->fileattr) != 0) {
91447636 548 if (a & ATTR_FILE_LINKCOUNT) size += sizeof(uint32_t);
1c79356b
A
549 if (a & ATTR_FILE_TOTALSIZE) size += sizeof(off_t);
550 if (a & ATTR_FILE_ALLOCSIZE) size += sizeof(off_t);
91447636
A
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);
1c79356b
A
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);
563 };
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);
567 };
568
569 return size;
570}
571
572
573
91447636 574static void
1c79356b
A
575packvolattr (struct attrlist *alist,
576 struct iso_node *ip, /* ip for root directory */
577 void **attrbufptrptr,
578 void **varbufptrptr)
579{
580 void *attrbufptr;
581 void *varbufptr;
582 struct iso_mnt *imp;
583 struct mount *mp;
584 attrgroup_t a;
91447636
A
585 uint32_t attrlength;
586 boolean_t is_64_bit = proc_is64bit(current_proc());
1c79356b
A
587
588 attrbufptr = *attrbufptrptr;
589 varbufptr = *varbufptrptr;
590 imp = ip->i_mnt;
591 mp = imp->im_mountp;
592
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);
599
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);
603 };
91447636
A
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;
1c79356b
A
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);
612 };
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);
617 };
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);
622 };
623 if (a & ATTR_CMN_SCRIPT) *((text_encoding_t *)attrbufptr)++ = 0;
91447636
A
624 if (a & ATTR_CMN_CRTIME) {
625 if (is_64_bit) {
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;
629 }
630 else {
631 *((struct timespec *)attrbufptr)++ = imp->creation_date;
632 }
633 }
634 if (a & ATTR_CMN_MODTIME) {
635 if (is_64_bit) {
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;
639 }
640 else {
641 *((struct timespec *)attrbufptr)++ = imp->modification_date;
642 }
643 }
644 if (a & ATTR_CMN_CHGTIME) {
645 if (is_64_bit) {
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;
649 }
650 else {
651 *((struct timespec *)attrbufptr)++ = imp->modification_date;
652 }
653 }
654 if (a & ATTR_CMN_ACCTIME) {
655 if (is_64_bit) {
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;
659 }
660 else {
661 *((struct timespec *)attrbufptr)++ = imp->modification_date;
662 }
663 }
1c79356b
A
664 if (a & ATTR_CMN_BKUPTIME) {
665 ((struct timespec *)attrbufptr)->tv_sec = 0;
666 ((struct timespec *)attrbufptr)->tv_nsec = 0;
667 ++((struct timespec *)attrbufptr);
668 };
669 if (a & ATTR_CMN_FNDRINFO) {
670 bzero (attrbufptr, 32 * sizeof(u_int8_t));
671 (u_int8_t *)attrbufptr += 32 * sizeof(u_int8_t);
672 };
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;
91447636
A
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;
1c79356b 677 if (a & ATTR_CMN_USERACCESS) {
91447636 678 *((uint32_t *)attrbufptr)++ =
1c79356b
A
679 DerivePermissionSummary(ip->inode.iso_uid,
680 ip->inode.iso_gid,
681 ip->inode.iso_mode,
91447636 682 imp);
1c79356b
A
683 };
684 };
685
686 if ((a = alist->volattr) != 0) {
687 off_t blocksize = (off_t)imp->logical_block_size;
688
91447636
A
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;
1c79356b
A
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;
91447636
A
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;
1c79356b
A
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);
706
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);
710 };
91447636
A
711 if (a & ATTR_VOL_MOUNTFLAGS) {
712 *((uint32_t *)attrbufptr)++ = (uint32_t)vfs_flags(mp);
713 }
1c79356b
A
714 if (a & ATTR_VOL_MOUNTEDDEVICE) {
715 ((struct attrreference *)attrbufptr)->attr_dataoffset = (u_int8_t *)varbufptr - (u_int8_t *)attrbufptr;
91447636 716 ((struct attrreference *)attrbufptr)->attr_length = strlen(vfs_statfs(mp)->f_mntfromname) + 1;
1c79356b
A
717 attrlength = ((struct attrreference *)attrbufptr)->attr_length;
718 attrlength = attrlength + ((4 - (attrlength & 3)) & 3); /* round up to the next 4-byte boundary: */
91447636 719 (void) bcopy(vfs_statfs(mp)->f_mntfromname, varbufptr, attrlength);
1c79356b
A
720
721 /* Advance beyond the space just allocated: */
722 (u_int8_t *)varbufptr += attrlength;
723 ++((struct attrreference *)attrbufptr);
724 };
725 if (a & ATTR_VOL_ENCODINGSUSED) *((unsigned long long *)attrbufptr)++ = (unsigned long long)0;
726 if (a & ATTR_VOL_CAPABILITIES) {
55e303ae
A
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;
1c79356b 734 ((vol_capabilities_attr_t *)attrbufptr)->capabilities[VOL_CAPABILITIES_INTERFACES] =
55e303ae
A
735 VOL_CAP_INT_ATTRLIST |
736 VOL_CAP_INT_NFSEXPORT;
1c79356b
A
737 ((vol_capabilities_attr_t *)attrbufptr)->capabilities[VOL_CAPABILITIES_RESERVED1] = 0;
738 ((vol_capabilities_attr_t *)attrbufptr)->capabilities[VOL_CAPABILITIES_RESERVED2] = 0;
739
740 ((vol_capabilities_attr_t *)attrbufptr)->valid[VOL_CAPABILITIES_FORMAT] =
55e303ae
A
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 |
91447636
A
751 VOL_CAP_FMT_FAST_STATFS |
752 VOL_CAP_FMT_2TB_FILESIZE;
1c79356b 753 ((vol_capabilities_attr_t *)attrbufptr)->valid[VOL_CAPABILITIES_INTERFACES] =
55e303ae
A
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 |
763 VOL_CAP_INT_FLOCK;
1c79356b
A
764 ((vol_capabilities_attr_t *)attrbufptr)->valid[VOL_CAPABILITIES_RESERVED1] = 0;
765 ((vol_capabilities_attr_t *)attrbufptr)->valid[VOL_CAPABILITIES_RESERVED2] = 0;
766
767 ++((vol_capabilities_attr_t *)attrbufptr);
768 };
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;
775
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;
781
782 ++((vol_attributes_attr_t *)attrbufptr);
783 };
784 };
785
786 *attrbufptrptr = attrbufptr;
787 *varbufptrptr = varbufptr;
788}
789
790
791void
792packcommonattr (struct attrlist *alist,
793 struct iso_node *ip,
794 void **attrbufptrptr,
795 void **varbufptrptr)
796{
797 void *attrbufptr;
798 void *varbufptr;
799 attrgroup_t a;
91447636
A
800 uint32_t attrlength;
801 boolean_t is_64_bit = proc_is64bit(current_proc());
1c79356b
A
802
803 attrbufptr = *attrbufptrptr;
804 varbufptr = *varbufptrptr;
805
806 if ((a = alist->commonattr) != 0) {
807 struct iso_mnt *imp = ip->i_mnt;
808
809 if (a & ATTR_CMN_NAME) {
810 /* special case root since we know how to get it's name */
91447636 811 if (vnode_isvroot(ITOV(ip))) {
1c79356b
A
812 attrlength = strlen( imp->volume_id ) + 1;
813 (void) strncpy((unsigned char *)varbufptr, imp->volume_id, attrlength);
814 } else {
815 attrlength = strlen(ip->i_namep) + 1;
816 (void) strncpy((unsigned char *)varbufptr, ip->i_namep, attrlength);
817 }
818
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);
824 };
825 if (a & ATTR_CMN_DEVID) *((dev_t *)attrbufptr)++ = ip->i_dev;
91447636
A
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));
1c79356b 829 if (a & ATTR_CMN_OBJID) {
91447636 830 if (vnode_isvroot(ITOV(ip)))
1c79356b
A
831 ((fsobj_id_t *)attrbufptr)->fid_objno = 2; /* force root to be 2 */
832 else
833 ((fsobj_id_t *)attrbufptr)->fid_objno = ip->i_number;
834 ((fsobj_id_t *)attrbufptr)->fid_generation = 0;
835 ++((fsobj_id_t *)attrbufptr);
836 };
837 if (a & ATTR_CMN_OBJPERMANENTID) {
91447636 838 if (vnode_isvroot(ITOV(ip)))
1c79356b
A
839 ((fsobj_id_t *)attrbufptr)->fid_objno = 2; /* force root to be 2 */
840 else
841 ((fsobj_id_t *)attrbufptr)->fid_objno = ip->i_number;
842 ((fsobj_id_t *)attrbufptr)->fid_generation = 0;
843 ++((fsobj_id_t *)attrbufptr);
844 };
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);
848
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 */
853 else
854 ((fsobj_id_t *)attrbufptr)->fid_objno = ip->i_parent;
855 ((fsobj_id_t *)attrbufptr)->fid_generation = 0;
856 ++((fsobj_id_t *)attrbufptr);
857 };
858 if (a & ATTR_CMN_SCRIPT) *((text_encoding_t *)attrbufptr)++ = 0;
91447636
A
859 if (a & ATTR_CMN_CRTIME) {
860 if (is_64_bit) {
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;
864 }
865 else {
866 *((struct timespec *)attrbufptr)++ = ip->inode.iso_mtime;
867 }
868 }
869 if (a & ATTR_CMN_MODTIME) {
870 if (is_64_bit) {
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;
874 }
875 else {
876 *((struct timespec *)attrbufptr)++ = ip->inode.iso_mtime;
877 }
878 }
879 if (a & ATTR_CMN_CHGTIME) {
880 if (is_64_bit) {
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;
884 }
885 else {
886 *((struct timespec *)attrbufptr)++ = ip->inode.iso_ctime;
887 }
888 }
889 if (a & ATTR_CMN_ACCTIME) {
890 if (is_64_bit) {
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;
894 }
895 else {
896 *((struct timespec *)attrbufptr)++ = ip->inode.iso_atime;
897 }
898 }
1c79356b 899 if (a & ATTR_CMN_BKUPTIME) {
91447636
A
900 if (is_64_bit) {
901 struct user_timespec *tmpp = ((struct user_timespec *)attrbufptr)++;
902 tmpp->tv_sec = (user_time_t) 0;
903 tmpp->tv_nsec = 0;
904 }
905 else {
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;
910 }
911 }
1c79356b 912 if (a & ATTR_CMN_FNDRINFO) {
91447636 913 struct finder_info finfo;
1c79356b 914
91447636 915 bzero(&finfo, sizeof(finfo));
1c79356b 916 finfo.fdFlags = ip->i_FinderFlags;
0b4e3aa0
A
917 finfo.fdLocation.v = -1;
918 finfo.fdLocation.h = -1;
91447636 919 if (vnode_isreg(ITOV(ip))) {
1c79356b
A
920 finfo.fdType = ip->i_FileType;
921 finfo.fdCreator = ip->i_Creator;
922 }
923 bcopy (&finfo, attrbufptr, sizeof(finfo));
924 (u_int8_t *)attrbufptr += sizeof(finfo);
925 bzero (attrbufptr, EXTFNDRINFOSIZE);
926 (u_int8_t *)attrbufptr += EXTFNDRINFOSIZE;
927 };
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;
91447636
A
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 */
1c79356b 932 if (a & ATTR_CMN_USERACCESS) {
91447636 933 *((uint32_t *)attrbufptr)++ =
1c79356b
A
934 DerivePermissionSummary(ip->inode.iso_uid,
935 ip->inode.iso_gid,
936 ip->inode.iso_mode,
91447636 937 imp);
1c79356b
A
938 };
939 };
940
941 *attrbufptrptr = attrbufptr;
942 *varbufptrptr = varbufptr;
943}
944
945
946void
947packdirattr(struct attrlist *alist,
948 struct iso_node *ip,
949 void **attrbufptrptr,
91447636 950 __unused void **varbufptrptr)
1c79356b
A
951{
952 void *attrbufptr;
953 attrgroup_t a;
954 int filcnt, dircnt;
955
956 attrbufptr = *attrbufptrptr;
957 filcnt = dircnt = 0;
958
959 a = alist->dirattr;
91447636 960 if (vnode_isdir(ITOV(ip)) && (a != 0)) {
1c79356b
A
961 /*
962 * if we haven't counted our children yet, do it now...
963 */
964 if ((ip->i_entries == 0) &&
965 (a & (ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT))) {
966 (void) isochildcount(ITOV(ip), &dircnt, &filcnt);
967
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;
972 }
973
974 if (a & ATTR_DIR_LINKCOUNT) {
91447636 975 *((uint32_t *)attrbufptr)++ = ip->inode.iso_links;
1c79356b
A
976 }
977 if (a & ATTR_DIR_ENTRYCOUNT) {
978 /* exclude '.' and '..' from total caount */
91447636 979 *((uint32_t *)attrbufptr)++ = ((ip->i_entries <= 2) ? 0 : (ip->i_entries - 2));
1c79356b
A
980 }
981 if (a & ATTR_DIR_MOUNTSTATUS) {
91447636
A
982 if (vnode_mountedhere(ITOV(ip))) {
983 *((uint32_t *)attrbufptr)++ = DIR_MNTSTATUS_MNTPOINT;
1c79356b 984 } else {
91447636 985 *((uint32_t *)attrbufptr)++ = 0;
1c79356b
A
986 };
987 };
988 };
989
990 *attrbufptrptr = attrbufptr;
991}
992
993
994void
995packfileattr(struct attrlist *alist,
996 struct iso_node *ip,
997 void **attrbufptrptr,
998 void **varbufptrptr)
999{
1000 void *attrbufptr = *attrbufptrptr;
1001 void *varbufptr = *varbufptrptr;
1002 attrgroup_t a = alist->fileattr;
1003
91447636 1004 if (vnode_isreg(ITOV(ip)) && (a != 0)) {
1c79356b 1005 if (a & ATTR_FILE_LINKCOUNT)
91447636 1006 *((uint32_t *)attrbufptr)++ = ip->inode.iso_links;
1c79356b
A
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)
91447636 1012 *((uint32_t *)attrbufptr)++ = ip->i_mnt->logical_block_size;
1c79356b 1013 if (a & ATTR_FILE_CLUMPSIZE)
91447636 1014 *((uint32_t *)attrbufptr)++ = ip->i_mnt->logical_block_size;
1c79356b 1015 if (a & ATTR_FILE_DEVTYPE)
91447636 1016 *((uint32_t *)attrbufptr)++ = (uint32_t)ip->inode.iso_rdev;
1c79356b
A
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;
1025 }
1026
1027 *attrbufptrptr = attrbufptr;
1028 *varbufptrptr = varbufptr;
1029}
1030
1031
1032void
1033packattrblk(struct attrlist *alist,
1034 struct vnode *vp,
1035 void **attrbufptrptr,
1036 void **varbufptrptr)
1037{
1038 struct iso_node *ip = VTOI(vp);
1039
1040 if (alist->volattr != 0) {
1041 packvolattr(alist, ip, attrbufptrptr, varbufptrptr);
1042 } else {
1043 packcommonattr(alist, ip, attrbufptrptr, varbufptrptr);
1044
91447636 1045 switch (vnode_vtype(ITOV(ip))) {
1c79356b
A
1046 case VDIR:
1047 packdirattr(alist, ip, attrbufptrptr, varbufptrptr);
1048 break;
1049
1050 case VREG:
1051 packfileattr(alist, ip, attrbufptrptr, varbufptrptr);
1052 break;
1053
1054 /* Without this the compiler complains about VNON,VBLK,VCHR,VLNK,VSOCK,VFIFO,VBAD and VSTR
1055 not being handled...
1056 */
1057 default:
1058 break;
1059 };
1060 };
1061};