]> git.saurik.com Git - apple/xnu.git/blob - bsd/isofs/cd9660/cd9660_util.c
6abbc84bf70b7871fc0ac9d7efebc764a5f80297
[apple/xnu.git] / bsd / isofs / cd9660 / cd9660_util.c
1 /*
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /* $NetBSD: cd9660_util.c,v 1.8 1994/12/13 22:33:25 mycroft Exp $ */
29
30 /*-
31 * Copyright (c) 1994
32 * The Regents of the University of California. All rights reserved.
33 *
34 * This code is derived from software contributed to Berkeley
35 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
36 * Support code is derived from software contributed to Berkeley
37 * by Atsushi Murai (amurai@spec.co.jp).
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed by the University of
50 * California, Berkeley and its contributors.
51 * 4. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)cd9660_util.c 8.3 (Berkeley) 12/5/94
68 *
69 * HISTORY
70 * 7-Dec-98 Add ATTR_VOL_MOUNTFLAGS attribute support - djb
71 * 18-Nov-98 Add support for volfs - djb
72 */
73
74 #include <sys/param.h>
75 #include <sys/systm.h>
76 #include <sys/vnode.h>
77 #include <sys/mount.h>
78 #include <sys/namei.h>
79 #include <sys/resourcevar.h>
80 #include <sys/kernel.h>
81 #include <sys/file.h>
82 #include <sys/stat.h>
83 #include <sys/buf.h>
84 #include <sys/proc.h>
85 #include <sys/kauth.h>
86 #include <sys/conf.h>
87 #include <sys/utfconv.h>
88 #include <miscfs/specfs/specdev.h> /* XXX */
89 #include <miscfs/fifofs/fifo.h> /* XXX */
90 #include <sys/malloc.h>
91 #include <sys/dir.h>
92 #include <sys/attr.h>
93 #include <kern/assert.h>
94
95 #include <isofs/cd9660/iso.h>
96 #include <isofs/cd9660/cd9660_node.h>
97 #include <isofs/cd9660/iso_rrip.h>
98
99 /*
100 * translate and compare a filename
101 * Note: Version number plus ';' may be omitted.
102 */
103 int
104 isofncmp(u_char *fn, int fnlen, u_char *isofn, int isolen)
105 {
106 int i, j;
107 char c;
108
109 while (--fnlen >= 0) {
110 if (--isolen < 0)
111 return *fn;
112 if ((c = *isofn++) == ';') {
113 switch (*fn++) {
114 default:
115 return *--fn;
116 case 0:
117 return 0;
118 case ';':
119 break;
120 }
121 for (i = 0; --fnlen >= 0; i = i * 10 + *fn++ - '0') {
122 if (*fn < '0' || *fn > '9') {
123 return -1;
124 }
125 }
126 for (j = 0; --isolen >= 0; j = j * 10 + *isofn++ - '0');
127 return i - j;
128 }
129 /* if raw comparison fails, check if char was mapped */
130 if (c != *fn) {
131 if (c >= 'A' && c <= 'Z') {
132 if (c + ('a' - 'A') != *fn) {
133 if (*fn >= 'a' && *fn <= 'z')
134 return *fn - ('a' - 'A') - c;
135 else
136 return *fn - c;
137 }
138 } else if (c == '/') {
139 if (*fn != ':')
140 return *fn - c;
141 } else if (c > 0 || *fn != '_')
142 return *fn - c;
143 }
144 fn++;
145 }
146 if (isolen > 0) {
147 switch (*isofn) {
148 default:
149 return -1;
150 case '.':
151 if (isofn[1] != ';')
152 return -1;
153 case ';':
154 return 0;
155 }
156 }
157 return 0;
158 }
159
160
161 /*
162 * translate and compare a UCS-2 filename
163 * Note: Version number plus ';' may be omitted.
164 *
165 * The name pointed to by "fn" is the search name, whose characters are
166 * in native endian order. The name "ucsfn" is the on-disk name, whose
167 * characters are in big endian order.
168 */
169
170 int
171 ucsfncmp(u_int16_t *fn, int fnlen, u_int16_t *ucsfn, int ucslen)
172 {
173 int i, j;
174 u_int16_t c;
175
176 /* convert byte count to char count */
177 ucslen /= 2;
178 fnlen /= 2;
179
180 while (--fnlen >= 0) {
181 if (--ucslen < 0)
182 return *fn;
183 if ((c = OSSwapBigToHostInt16(*ucsfn++)) == UCS_SEPARATOR2) {
184 switch (*fn++) {
185 default:
186 return *--fn;
187 case 0:
188 return 0;
189 case UCS_SEPARATOR2:
190 break;
191 }
192 for (i = 0; --fnlen >= 0; i = i * 10 + *fn++ - '0') {
193 if (*fn < '0' || *fn > '9') {
194 return -1;
195 }
196 }
197 for (j = 0; --ucslen >= 0; j = j * 10 + OSSwapBigToHostInt16(*ucsfn++) - '0');
198 return i - j;
199 }
200 if (c != *fn)
201 return *fn - c;
202 fn++;
203 }
204 if (ucslen > 0) {
205 switch (*ucsfn) {
206 default:
207 return -1;
208 case OSSwapHostToBigConstInt16(UCS_SEPARATOR1):
209 if (ucsfn[1] != OSSwapHostToBigConstInt16(UCS_SEPARATOR2))
210 return -1;
211 case OSSwapHostToBigConstInt16(UCS_SEPARATOR2):
212 return 0;
213 }
214 }
215 return 0;
216 }
217
218
219 /*
220 * translate a filename
221 */
222 void
223 isofntrans(u_char *infn, int infnlen, u_char *outfn, u_short *outfnlen,
224 int original, int assoc)
225 {
226 int fnidx = 0;
227
228 /*
229 * Add a "._" prefix for associated files
230 */
231 if (assoc) {
232 *outfn++ = ASSOCCHAR1;
233 *outfn++ = ASSOCCHAR2;
234 fnidx += 2;
235 infnlen +=2;
236 }
237 for (; fnidx < infnlen; fnidx++) {
238 char c = *infn++;
239
240 /*
241 * Some ISO 9600 CD names contain 8-bit chars.
242 * These chars are mapped to '_' because there
243 * is no context for mapping them to UTF-8.
244 * In addition '/' is mapped to ':'.
245 *
246 * isofncmp accounts for these mappings.
247 */
248 if (!original) {
249 if (c < 0)
250 c = '_';
251 else if (c == '/')
252 c = ':';
253 else if (c == '.' && *infn == ';')
254 break;
255 else if (c == ';')
256 break;
257 }
258 *outfn++ = c;
259 }
260 *outfnlen = fnidx;
261 }
262
263
264
265 /*
266 * translate a UCS-2 filename to UTF-8
267 */
268 void
269 ucsfntrans(u_int16_t *infn, int infnlen, u_char *outfn, u_short *outfnlen,
270 int dir, int assoc)
271 {
272 if (infnlen == 1) {
273 strcpy(outfn, "..");
274
275 if (*(u_char*)infn == 0)
276 *outfnlen = 1;
277 else if (*(u_char*)infn == 1)
278 *outfnlen = 2;
279 } else {
280 int fnidx;
281 size_t outbytes;
282 int flags;
283
284 fnidx = infnlen/2;
285 flags = 0;
286
287 /*
288 * Add a "._" prefix for associated files
289 */
290 if (assoc) {
291 *outfn++ = ASSOCCHAR1;
292 *outfn++ = ASSOCCHAR2;
293 }
294 if (!dir) {
295 /* strip file version number */
296 for (fnidx--; fnidx > 0; fnidx--) {
297 /* stop when ';' is found */
298 if (infn[fnidx] == OSSwapHostToBigConstInt16(UCS_SEPARATOR2)) {
299 /* drop dangling dot */
300 if (fnidx > 0 && infn[fnidx-1] == OSSwapHostToBigConstInt16(UCS_SEPARATOR1))
301 fnidx--;
302 break;
303 }
304 }
305 if (fnidx <= 0)
306 fnidx = infnlen/2;
307 }
308
309 flags = UTF_NO_NULL_TERM | UTF_DECOMPOSED;
310 if (BYTE_ORDER != BIG_ENDIAN)
311 flags |= UTF_REVERSE_ENDIAN;
312
313 (void) utf8_encodestr(infn, fnidx * 2, outfn, &outbytes, ISO_JOLIET_NAMEMAX, 0, flags);
314 *outfnlen = assoc ? outbytes + 2 : outbytes;
315 }
316 }
317
318
319 /*
320 * count the number of children by enumerating the directory
321 */
322 static int
323 isochildcount(struct vnode *vdp, int *dircnt, int *filcnt)
324 {
325 struct iso_node *dp;
326 struct buf *bp = NULL;
327 struct iso_mnt *imp;
328 struct iso_directory_record *ep;
329 uint32_t bmask;
330 int error = 0;
331 int reclen;
332 int dirs, files;
333 int blkoffset;
334 int logblksize;
335 int32_t diroffset;
336
337 dp = VTOI(vdp);
338 imp = dp->i_mnt;
339 bmask = imp->im_sector_size - 1;
340 logblksize = imp->im_sector_size;
341 blkoffset = diroffset = 0;
342 dirs = files = 0;
343
344 while (diroffset < dp->i_size) {
345 /*
346 * If offset is on a block boundary, read the next
347 * directory block. Release previous if it exists.
348 */
349 if ((diroffset & bmask) == 0) {
350 if (bp != NULL)
351 buf_brelse(bp);
352 if ( (error = cd9660_blkatoff(vdp, SECTOFF(imp, diroffset), NULL, &bp)) )
353 break;
354 blkoffset = 0;
355 }
356
357 ep = (struct iso_directory_record *)
358 (buf_dataptr(bp) + blkoffset);
359
360 reclen = isonum_711(ep->length);
361 if (reclen == 0) {
362 /* skip to next block, if any */
363 diroffset =
364 (diroffset & ~bmask) + logblksize;
365 continue;
366 }
367
368 if ((reclen < ISO_DIRECTORY_RECORD_SIZE) ||
369 (blkoffset + reclen > logblksize) ||
370 (reclen < ISO_DIRECTORY_RECORD_SIZE + isonum_711(ep->name_len))){
371 /* illegal, so give up */
372 break;
373 }
374
375 /*
376 * Some poorly mastered discs have an incorrect directory
377 * file size. If the '.' entry has a better size (bigger)
378 * then use that instead.
379 */
380 if ((diroffset == 0) && (isonum_733(ep->size) > dp->i_size)) {
381 dp->i_size = isonum_733(ep->size);
382 }
383
384 if ( isonum_711(ep->flags) & directoryBit )
385 dirs++;
386 else if ((isonum_711(ep->flags) & associatedBit) == 0)
387 files++;
388
389 diroffset += reclen;
390 blkoffset += reclen;
391 }
392
393 if (bp)
394 buf_brelse (bp);
395
396 *dircnt = dirs;
397 *filcnt = files;
398
399 return (error);
400 }
401
402
403 static uint32_t
404 DerivePermissionSummary(uid_t owner, gid_t group, mode_t obj_mode, __unused struct iso_mnt *imp)
405 {
406 kauth_cred_t cred = kauth_cred_get();
407 uint32_t permissions;
408 int is_member;
409
410 /* User id 0 (root) always gets access. */
411 if (!suser(cred, NULL)) {
412 permissions = R_OK | X_OK;
413 goto Exit;
414 };
415
416 /* Otherwise, check the owner. */
417 if (owner == kauth_cred_getuid(cred)) {
418 permissions = ((uint32_t)obj_mode & S_IRWXU) >> 6;
419 goto Exit;
420 }
421
422 /* Otherwise, check the groups. */
423 if (kauth_cred_ismember_gid(cred, group, &is_member) == 0 && is_member) {
424 permissions = ((uint32_t)obj_mode & S_IRWXG) >> 3;
425 goto Exit;
426 }
427
428 /* Otherwise, settle for 'others' access. */
429 permissions = (uint32_t)obj_mode & S_IRWXO;
430
431 Exit:
432 return permissions & ~W_OK; /* Write access is always impossible */
433 }
434
435
436 int
437 attrcalcsize(struct attrlist *attrlist)
438 {
439 int size;
440 attrgroup_t a;
441 boolean_t is_64_bit = proc_is64bit(current_proc());
442
443 #if ((ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_FSID | ATTR_CMN_OBJTYPE | \
444 ATTR_CMN_OBJTAG | ATTR_CMN_OBJID | ATTR_CMN_OBJPERMANENTID | ATTR_CMN_PAROBJID | \
445 ATTR_CMN_SCRIPT | ATTR_CMN_CRTIME | ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME | \
446 ATTR_CMN_ACCTIME | ATTR_CMN_BKUPTIME | ATTR_CMN_FNDRINFO | ATTR_CMN_OWNERID | \
447 ATTR_CMN_GRPID | ATTR_CMN_ACCESSMASK | ATTR_CMN_NAMEDATTRCOUNT | ATTR_CMN_NAMEDATTRLIST| \
448 ATTR_CMN_FLAGS | ATTR_CMN_USERACCESS) != ATTR_CMN_VALIDMASK)
449 #error AttributeBlockSize: Missing bits in common mask computation!
450 #endif
451 assert((attrlist->commonattr & ~ATTR_CMN_VALIDMASK) == 0);
452
453 #if ((ATTR_VOL_FSTYPE | ATTR_VOL_SIGNATURE | ATTR_VOL_SIZE | ATTR_VOL_SPACEFREE | \
454 ATTR_VOL_SPACEAVAIL | ATTR_VOL_MINALLOCATION | ATTR_VOL_ALLOCATIONCLUMP | ATTR_VOL_IOBLOCKSIZE | \
455 ATTR_VOL_OBJCOUNT | ATTR_VOL_FILECOUNT | ATTR_VOL_DIRCOUNT | ATTR_VOL_MAXOBJCOUNT | \
456 ATTR_VOL_MOUNTPOINT | ATTR_VOL_NAME | ATTR_VOL_MOUNTFLAGS | ATTR_VOL_INFO | \
457 ATTR_VOL_MOUNTEDDEVICE| ATTR_VOL_ENCODINGSUSED | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES) != ATTR_VOL_VALIDMASK)
458 #error AttributeBlockSize: Missing bits in volume mask computation!
459 #endif
460 assert((attrlist->volattr & ~ATTR_VOL_VALIDMASK) == 0);
461
462 #if ((ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT | ATTR_DIR_MOUNTSTATUS) != ATTR_DIR_VALIDMASK)
463 #error AttributeBlockSize: Missing bits in directory mask computation!
464 #endif
465 assert((attrlist->dirattr & ~ATTR_DIR_VALIDMASK) == 0);
466 #if ((ATTR_FILE_LINKCOUNT | ATTR_FILE_TOTALSIZE | ATTR_FILE_ALLOCSIZE | ATTR_FILE_IOBLOCKSIZE | \
467 ATTR_FILE_CLUMPSIZE | ATTR_FILE_DEVTYPE | ATTR_FILE_FILETYPE | ATTR_FILE_FORKCOUNT | \
468 ATTR_FILE_FORKLIST | ATTR_FILE_DATALENGTH | ATTR_FILE_DATAALLOCSIZE | ATTR_FILE_DATAEXTENTS | \
469 ATTR_FILE_RSRCLENGTH | ATTR_FILE_RSRCALLOCSIZE | ATTR_FILE_RSRCEXTENTS) != ATTR_FILE_VALIDMASK)
470 #error AttributeBlockSize: Missing bits in file mask computation!
471 #endif
472 assert((attrlist->fileattr & ~ATTR_FILE_VALIDMASK) == 0);
473
474 #if ((ATTR_FORK_TOTALSIZE | ATTR_FORK_ALLOCSIZE) != ATTR_FORK_VALIDMASK)
475 #error AttributeBlockSize: Missing bits in fork mask computation!
476 #endif
477 assert((attrlist->forkattr & ~ATTR_FORK_VALIDMASK) == 0);
478
479 size = 0;
480
481 if ((a = attrlist->commonattr) != 0) {
482 if (a & ATTR_CMN_NAME) size += sizeof(struct attrreference);
483 if (a & ATTR_CMN_DEVID) size += sizeof(dev_t);
484 if (a & ATTR_CMN_FSID) size += sizeof(fsid_t);
485 if (a & ATTR_CMN_OBJTYPE) size += sizeof(fsobj_type_t);
486 if (a & ATTR_CMN_OBJTAG) size += sizeof(fsobj_tag_t);
487 if (a & ATTR_CMN_OBJID) size += sizeof(fsobj_id_t);
488 if (a & ATTR_CMN_OBJPERMANENTID) size += sizeof(fsobj_id_t);
489 if (a & ATTR_CMN_PAROBJID) size += sizeof(fsobj_id_t);
490 if (a & ATTR_CMN_SCRIPT) size += sizeof(text_encoding_t);
491 if (a & ATTR_CMN_CRTIME) {
492 if (is_64_bit)
493 size += sizeof(struct user_timespec);
494 else
495 size += sizeof(struct timespec);
496 }
497 if (a & ATTR_CMN_MODTIME) {
498 if (is_64_bit)
499 size += sizeof(struct user_timespec);
500 else
501 size += sizeof(struct timespec);
502 }
503 if (a & ATTR_CMN_CHGTIME) {
504 if (is_64_bit)
505 size += sizeof(struct user_timespec);
506 else
507 size += sizeof(struct timespec);
508 }
509 if (a & ATTR_CMN_ACCTIME) {
510 if (is_64_bit)
511 size += sizeof(struct user_timespec);
512 else
513 size += sizeof(struct timespec);
514 }
515 if (a & ATTR_CMN_BKUPTIME) {
516 if (is_64_bit)
517 size += sizeof(struct user_timespec);
518 else
519 size += sizeof(struct timespec);
520 }
521 if (a & ATTR_CMN_FNDRINFO) size += 32 * sizeof(u_int8_t);
522 if (a & ATTR_CMN_OWNERID) size += sizeof(uid_t);
523 if (a & ATTR_CMN_GRPID) size += sizeof(gid_t);
524 if (a & ATTR_CMN_ACCESSMASK) size += sizeof(uint32_t);
525 if (a & ATTR_CMN_NAMEDATTRCOUNT) size += sizeof(uint32_t);
526 if (a & ATTR_CMN_NAMEDATTRLIST) size += sizeof(struct attrreference);
527 if (a & ATTR_CMN_FLAGS) size += sizeof(uint32_t);
528 if (a & ATTR_CMN_USERACCESS) size += sizeof(uint32_t);
529 };
530 if ((a = attrlist->volattr) != 0) {
531 if (a & ATTR_VOL_FSTYPE) size += sizeof(uint32_t);
532 if (a & ATTR_VOL_SIGNATURE) size += sizeof(uint32_t);
533 if (a & ATTR_VOL_SIZE) size += sizeof(off_t);
534 if (a & ATTR_VOL_SPACEFREE) size += sizeof(off_t);
535 if (a & ATTR_VOL_SPACEAVAIL) size += sizeof(off_t);
536 if (a & ATTR_VOL_MINALLOCATION) size += sizeof(off_t);
537 if (a & ATTR_VOL_ALLOCATIONCLUMP) size += sizeof(off_t);
538 if (a & ATTR_VOL_IOBLOCKSIZE) size += sizeof(uint32_t);
539 if (a & ATTR_VOL_OBJCOUNT) size += sizeof(uint32_t);
540 if (a & ATTR_VOL_FILECOUNT) size += sizeof(uint32_t);
541 if (a & ATTR_VOL_DIRCOUNT) size += sizeof(uint32_t);
542 if (a & ATTR_VOL_MAXOBJCOUNT) size += sizeof(uint32_t);
543 if (a & ATTR_VOL_MOUNTPOINT) size += sizeof(struct attrreference);
544 if (a & ATTR_VOL_NAME) size += sizeof(struct attrreference);
545 if (a & ATTR_VOL_MOUNTFLAGS) size += sizeof(uint32_t);
546 if (a & ATTR_VOL_MOUNTEDDEVICE) size += sizeof(struct attrreference);
547 if (a & ATTR_VOL_ENCODINGSUSED) size += sizeof(unsigned long long);
548 if (a & ATTR_VOL_CAPABILITIES) size += sizeof(vol_capabilities_attr_t);
549 if (a & ATTR_VOL_ATTRIBUTES) size += sizeof(vol_attributes_attr_t);
550 };
551 if ((a = attrlist->dirattr) != 0) {
552 if (a & ATTR_DIR_LINKCOUNT) size += sizeof(uint32_t);
553 if (a & ATTR_DIR_ENTRYCOUNT) size += sizeof(uint32_t);
554 if (a & ATTR_DIR_MOUNTSTATUS) size += sizeof(uint32_t);
555 };
556 if ((a = attrlist->fileattr) != 0) {
557 if (a & ATTR_FILE_LINKCOUNT) size += sizeof(uint32_t);
558 if (a & ATTR_FILE_TOTALSIZE) size += sizeof(off_t);
559 if (a & ATTR_FILE_ALLOCSIZE) size += sizeof(off_t);
560 if (a & ATTR_FILE_IOBLOCKSIZE) size += sizeof(uint32_t);
561 if (a & ATTR_FILE_CLUMPSIZE) size += sizeof(uint32_t);
562 if (a & ATTR_FILE_DEVTYPE) size += sizeof(uint32_t);
563 if (a & ATTR_FILE_FILETYPE) size += sizeof(uint32_t);
564 if (a & ATTR_FILE_FORKCOUNT) size += sizeof(uint32_t);
565 if (a & ATTR_FILE_FORKLIST) size += sizeof(struct attrreference);
566 if (a & ATTR_FILE_DATALENGTH) size += sizeof(off_t);
567 if (a & ATTR_FILE_DATAALLOCSIZE) size += sizeof(off_t);
568 if (a & ATTR_FILE_DATAEXTENTS) size += sizeof(extentrecord);
569 if (a & ATTR_FILE_RSRCLENGTH) size += sizeof(off_t);
570 if (a & ATTR_FILE_RSRCALLOCSIZE) size += sizeof(off_t);
571 if (a & ATTR_FILE_RSRCEXTENTS) size += sizeof(extentrecord);
572 };
573 if ((a = attrlist->forkattr) != 0) {
574 if (a & ATTR_FORK_TOTALSIZE) size += sizeof(off_t);
575 if (a & ATTR_FORK_ALLOCSIZE) size += sizeof(off_t);
576 };
577
578 return size;
579 }
580
581
582
583 static void
584 packvolattr (struct attrlist *alist,
585 struct iso_node *ip, /* ip for root directory */
586 void **attrbufptrptr,
587 void **varbufptrptr)
588 {
589 void *attrbufptr;
590 void *varbufptr;
591 struct iso_mnt *imp;
592 struct mount *mp;
593 attrgroup_t a;
594 uint32_t attrlength;
595 boolean_t is_64_bit = proc_is64bit(current_proc());
596
597 attrbufptr = *attrbufptrptr;
598 varbufptr = *varbufptrptr;
599 imp = ip->i_mnt;
600 mp = imp->im_mountp;
601
602 if ((a = alist->commonattr) != 0) {
603 if (a & ATTR_CMN_NAME) {
604 attrlength = strlen( imp->volume_id ) + 1;
605 ((struct attrreference *)attrbufptr)->attr_dataoffset = (u_int8_t *)varbufptr - (u_int8_t *)attrbufptr;
606 ((struct attrreference *)attrbufptr)->attr_length = attrlength;
607 (void) strncpy((unsigned char *)varbufptr, imp->volume_id, attrlength);
608
609 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
610 (u_int8_t *)varbufptr += attrlength + ((4 - (attrlength & 3)) & 3);
611 ++((struct attrreference *)attrbufptr);
612 };
613 if (a & ATTR_CMN_DEVID) *((dev_t *)attrbufptr)++ = vnode_specrdev(imp->im_devvp);
614 if (a & ATTR_CMN_FSID) *((fsid_t *)attrbufptr)++ = vfs_statfs(vnode_mount(ITOV(ip)))->f_fsid;
615 if (a & ATTR_CMN_OBJTYPE) *((fsobj_type_t *)attrbufptr)++ = 0;
616 if (a & ATTR_CMN_OBJTAG) *((fsobj_tag_t *)attrbufptr)++ = VT_ISOFS;
617 if (a & ATTR_CMN_OBJID) {
618 ((fsobj_id_t *)attrbufptr)->fid_objno = 0;
619 ((fsobj_id_t *)attrbufptr)->fid_generation = 0;
620 ++((fsobj_id_t *)attrbufptr);
621 };
622 if (a & ATTR_CMN_OBJPERMANENTID) {
623 ((fsobj_id_t *)attrbufptr)->fid_objno = 0;
624 ((fsobj_id_t *)attrbufptr)->fid_generation = 0;
625 ++((fsobj_id_t *)attrbufptr);
626 };
627 if (a & ATTR_CMN_PAROBJID) {
628 ((fsobj_id_t *)attrbufptr)->fid_objno = 0;
629 ((fsobj_id_t *)attrbufptr)->fid_generation = 0;
630 ++((fsobj_id_t *)attrbufptr);
631 };
632 if (a & ATTR_CMN_SCRIPT) *((text_encoding_t *)attrbufptr)++ = 0;
633 if (a & ATTR_CMN_CRTIME) {
634 if (is_64_bit) {
635 struct user_timespec *tmpp = ((struct user_timespec *)attrbufptr)++;
636 tmpp->tv_sec = (user_time_t) imp->creation_date.tv_sec;
637 tmpp->tv_nsec = imp->creation_date.tv_nsec;
638 }
639 else {
640 *((struct timespec *)attrbufptr)++ = imp->creation_date;
641 }
642 }
643 if (a & ATTR_CMN_MODTIME) {
644 if (is_64_bit) {
645 struct user_timespec *tmpp = ((struct user_timespec *)attrbufptr)++;
646 tmpp->tv_sec = (user_time_t) imp->modification_date.tv_sec;
647 tmpp->tv_nsec = imp->modification_date.tv_nsec;
648 }
649 else {
650 *((struct timespec *)attrbufptr)++ = imp->modification_date;
651 }
652 }
653 if (a & ATTR_CMN_CHGTIME) {
654 if (is_64_bit) {
655 struct user_timespec *tmpp = ((struct user_timespec *)attrbufptr)++;
656 tmpp->tv_sec = (user_time_t) imp->modification_date.tv_sec;
657 tmpp->tv_nsec = imp->modification_date.tv_nsec;
658 }
659 else {
660 *((struct timespec *)attrbufptr)++ = imp->modification_date;
661 }
662 }
663 if (a & ATTR_CMN_ACCTIME) {
664 if (is_64_bit) {
665 struct user_timespec *tmpp = ((struct user_timespec *)attrbufptr)++;
666 tmpp->tv_sec = (user_time_t) imp->modification_date.tv_sec;
667 tmpp->tv_nsec = imp->modification_date.tv_nsec;
668 }
669 else {
670 *((struct timespec *)attrbufptr)++ = imp->modification_date;
671 }
672 }
673 if (a & ATTR_CMN_BKUPTIME) {
674 ((struct timespec *)attrbufptr)->tv_sec = 0;
675 ((struct timespec *)attrbufptr)->tv_nsec = 0;
676 ++((struct timespec *)attrbufptr);
677 };
678 if (a & ATTR_CMN_FNDRINFO) {
679 bzero (attrbufptr, 32 * sizeof(u_int8_t));
680 (u_int8_t *)attrbufptr += 32 * sizeof(u_int8_t);
681 };
682 if (a & ATTR_CMN_OWNERID) *((uid_t *)attrbufptr)++ = ip->inode.iso_uid;
683 if (a & ATTR_CMN_GRPID) *((gid_t *)attrbufptr)++ = ip->inode.iso_gid;
684 if (a & ATTR_CMN_ACCESSMASK) *((uint32_t *)attrbufptr)++ = (uint32_t)ip->inode.iso_mode;
685 if (a & ATTR_CMN_FLAGS) *((uint32_t *)attrbufptr)++ = 0;
686 if (a & ATTR_CMN_USERACCESS) {
687 *((uint32_t *)attrbufptr)++ =
688 DerivePermissionSummary(ip->inode.iso_uid,
689 ip->inode.iso_gid,
690 ip->inode.iso_mode,
691 imp);
692 };
693 };
694
695 if ((a = alist->volattr) != 0) {
696 off_t blocksize = (off_t)imp->logical_block_size;
697
698 if (a & ATTR_VOL_FSTYPE) *((uint32_t *)attrbufptr)++ = (uint32_t)vfs_typenum(mp);
699 if (a & ATTR_VOL_SIGNATURE) *((uint32_t *)attrbufptr)++ = (uint32_t)ISO9660SIGNATURE;
700 if (a & ATTR_VOL_SIZE) *((off_t *)attrbufptr)++ = (off_t)imp->volume_space_size * blocksize;
701 if (a & ATTR_VOL_SPACEFREE) *((off_t *)attrbufptr)++ = 0;
702 if (a & ATTR_VOL_SPACEAVAIL) *((off_t *)attrbufptr)++ = 0;
703 if (a & ATTR_VOL_MINALLOCATION) *((off_t *)attrbufptr)++ = blocksize;
704 if (a & ATTR_VOL_ALLOCATIONCLUMP) *((off_t *)attrbufptr)++ = blocksize;
705 if (a & ATTR_VOL_IOBLOCKSIZE) *((uint32_t *)attrbufptr)++ = (uint32_t)blocksize;
706 if (a & ATTR_VOL_OBJCOUNT) *((uint32_t *)attrbufptr)++ = 0;
707 if (a & ATTR_VOL_FILECOUNT) *((uint32_t *)attrbufptr)++ = 0;
708 if (a & ATTR_VOL_DIRCOUNT) *((uint32_t *)attrbufptr)++ = 0;
709 if (a & ATTR_VOL_MAXOBJCOUNT) *((uint32_t *)attrbufptr)++ = 0xFFFFFFFF;
710 if (a & ATTR_VOL_NAME) {
711 attrlength = strlen( imp->volume_id ) + 1;
712 ((struct attrreference *)attrbufptr)->attr_dataoffset = (u_int8_t *)varbufptr - (u_int8_t *)attrbufptr;
713 ((struct attrreference *)attrbufptr)->attr_length = attrlength;
714 (void) strncpy((unsigned char *)varbufptr, imp->volume_id, attrlength);
715
716 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
717 (u_int8_t *)varbufptr += attrlength + ((4 - (attrlength & 3)) & 3);
718 ++((struct attrreference *)attrbufptr);
719 };
720 if (a & ATTR_VOL_MOUNTFLAGS) {
721 *((uint32_t *)attrbufptr)++ = (uint32_t)vfs_flags(mp);
722 }
723 if (a & ATTR_VOL_MOUNTEDDEVICE) {
724 ((struct attrreference *)attrbufptr)->attr_dataoffset = (u_int8_t *)varbufptr - (u_int8_t *)attrbufptr;
725 ((struct attrreference *)attrbufptr)->attr_length = strlen(vfs_statfs(mp)->f_mntfromname) + 1;
726 attrlength = ((struct attrreference *)attrbufptr)->attr_length;
727 attrlength = attrlength + ((4 - (attrlength & 3)) & 3); /* round up to the next 4-byte boundary: */
728 (void) bcopy(vfs_statfs(mp)->f_mntfromname, varbufptr, attrlength);
729
730 /* Advance beyond the space just allocated: */
731 (u_int8_t *)varbufptr += attrlength;
732 ++((struct attrreference *)attrbufptr);
733 };
734 if (a & ATTR_VOL_ENCODINGSUSED) *((unsigned long long *)attrbufptr)++ = (unsigned long long)0;
735 if (a & ATTR_VOL_CAPABILITIES) {
736 ((vol_capabilities_attr_t *)attrbufptr)->capabilities[VOL_CAPABILITIES_FORMAT] =
737 (imp->iso_ftype == ISO_FTYPE_RRIP ? VOL_CAP_FMT_SYMBOLICLINKS : 0) |
738 (imp->iso_ftype == ISO_FTYPE_RRIP ? VOL_CAP_FMT_HARDLINKS : 0) |
739 (imp->iso_ftype == ISO_FTYPE_RRIP || imp->iso_ftype == ISO_FTYPE_JOLIET
740 ? VOL_CAP_FMT_CASE_SENSITIVE : 0) |
741 VOL_CAP_FMT_CASE_PRESERVING |
742 VOL_CAP_FMT_FAST_STATFS;
743 ((vol_capabilities_attr_t *)attrbufptr)->capabilities[VOL_CAPABILITIES_INTERFACES] =
744 VOL_CAP_INT_ATTRLIST |
745 VOL_CAP_INT_NFSEXPORT;
746 ((vol_capabilities_attr_t *)attrbufptr)->capabilities[VOL_CAPABILITIES_RESERVED1] = 0;
747 ((vol_capabilities_attr_t *)attrbufptr)->capabilities[VOL_CAPABILITIES_RESERVED2] = 0;
748
749 ((vol_capabilities_attr_t *)attrbufptr)->valid[VOL_CAPABILITIES_FORMAT] =
750 VOL_CAP_FMT_PERSISTENTOBJECTIDS |
751 VOL_CAP_FMT_SYMBOLICLINKS |
752 VOL_CAP_FMT_HARDLINKS |
753 VOL_CAP_FMT_JOURNAL |
754 VOL_CAP_FMT_JOURNAL_ACTIVE |
755 VOL_CAP_FMT_NO_ROOT_TIMES |
756 VOL_CAP_FMT_SPARSE_FILES |
757 VOL_CAP_FMT_ZERO_RUNS |
758 VOL_CAP_FMT_CASE_SENSITIVE |
759 VOL_CAP_FMT_CASE_PRESERVING |
760 VOL_CAP_FMT_FAST_STATFS |
761 VOL_CAP_FMT_2TB_FILESIZE;
762 ((vol_capabilities_attr_t *)attrbufptr)->valid[VOL_CAPABILITIES_INTERFACES] =
763 VOL_CAP_INT_SEARCHFS |
764 VOL_CAP_INT_ATTRLIST |
765 VOL_CAP_INT_NFSEXPORT |
766 VOL_CAP_INT_READDIRATTR |
767 VOL_CAP_INT_EXCHANGEDATA |
768 VOL_CAP_INT_COPYFILE |
769 VOL_CAP_INT_ALLOCATE |
770 VOL_CAP_INT_VOL_RENAME |
771 VOL_CAP_INT_ADVLOCK |
772 VOL_CAP_INT_FLOCK;
773 ((vol_capabilities_attr_t *)attrbufptr)->valid[VOL_CAPABILITIES_RESERVED1] = 0;
774 ((vol_capabilities_attr_t *)attrbufptr)->valid[VOL_CAPABILITIES_RESERVED2] = 0;
775
776 ++((vol_capabilities_attr_t *)attrbufptr);
777 };
778 if (a & ATTR_VOL_ATTRIBUTES) {
779 ((vol_attributes_attr_t *)attrbufptr)->validattr.commonattr = ATTR_CMN_VALIDMASK;
780 ((vol_attributes_attr_t *)attrbufptr)->validattr.volattr = ATTR_VOL_VALIDMASK;
781 ((vol_attributes_attr_t *)attrbufptr)->validattr.dirattr = ATTR_DIR_VALIDMASK;
782 ((vol_attributes_attr_t *)attrbufptr)->validattr.fileattr = ATTR_FILE_VALIDMASK;
783 ((vol_attributes_attr_t *)attrbufptr)->validattr.forkattr = ATTR_FORK_VALIDMASK;
784
785 ((vol_attributes_attr_t *)attrbufptr)->nativeattr.commonattr = ATTR_CMN_VALIDMASK;
786 ((vol_attributes_attr_t *)attrbufptr)->nativeattr.volattr = ATTR_VOL_VALIDMASK;
787 ((vol_attributes_attr_t *)attrbufptr)->nativeattr.dirattr = ATTR_DIR_VALIDMASK;
788 ((vol_attributes_attr_t *)attrbufptr)->nativeattr.fileattr = ATTR_FILE_VALIDMASK;
789 ((vol_attributes_attr_t *)attrbufptr)->nativeattr.forkattr = ATTR_FORK_VALIDMASK;
790
791 ++((vol_attributes_attr_t *)attrbufptr);
792 };
793 };
794
795 *attrbufptrptr = attrbufptr;
796 *varbufptrptr = varbufptr;
797 }
798
799
800 void
801 packcommonattr (struct attrlist *alist,
802 struct iso_node *ip,
803 void **attrbufptrptr,
804 void **varbufptrptr)
805 {
806 void *attrbufptr;
807 void *varbufptr;
808 attrgroup_t a;
809 uint32_t attrlength;
810 boolean_t is_64_bit = proc_is64bit(current_proc());
811
812 attrbufptr = *attrbufptrptr;
813 varbufptr = *varbufptrptr;
814
815 if ((a = alist->commonattr) != 0) {
816 struct iso_mnt *imp = ip->i_mnt;
817
818 if (a & ATTR_CMN_NAME) {
819 /* special case root since we know how to get it's name */
820 if (vnode_isvroot(ITOV(ip))) {
821 attrlength = strlen( imp->volume_id ) + 1;
822 (void) strncpy((unsigned char *)varbufptr, imp->volume_id, attrlength);
823 } else {
824 attrlength = strlen(ip->i_namep) + 1;
825 (void) strncpy((unsigned char *)varbufptr, ip->i_namep, attrlength);
826 }
827
828 ((struct attrreference *)attrbufptr)->attr_dataoffset = (u_int8_t *)varbufptr - (u_int8_t *)attrbufptr;
829 ((struct attrreference *)attrbufptr)->attr_length = attrlength;
830 /* Advance beyond the space just allocated and round up to the next 4-byte boundary: */
831 (u_int8_t *)varbufptr += attrlength + ((4 - (attrlength & 3)) & 3);
832 ++((struct attrreference *)attrbufptr);
833 };
834 if (a & ATTR_CMN_DEVID) *((dev_t *)attrbufptr)++ = ip->i_dev;
835 if (a & ATTR_CMN_FSID) *((fsid_t *)attrbufptr)++ = vfs_statfs(vnode_mount(ITOV(ip)))->f_fsid;
836 if (a & ATTR_CMN_OBJTYPE) *((fsobj_type_t *)attrbufptr)++ = vnode_vtype(ITOV(ip));
837 if (a & ATTR_CMN_OBJTAG) *((fsobj_tag_t *)attrbufptr)++ = vnode_tag(ITOV(ip));
838 if (a & ATTR_CMN_OBJID) {
839 if (vnode_isvroot(ITOV(ip)))
840 ((fsobj_id_t *)attrbufptr)->fid_objno = 2; /* force root to be 2 */
841 else
842 ((fsobj_id_t *)attrbufptr)->fid_objno = ip->i_number;
843 ((fsobj_id_t *)attrbufptr)->fid_generation = 0;
844 ++((fsobj_id_t *)attrbufptr);
845 };
846 if (a & ATTR_CMN_OBJPERMANENTID) {
847 if (vnode_isvroot(ITOV(ip)))
848 ((fsobj_id_t *)attrbufptr)->fid_objno = 2; /* force root to be 2 */
849 else
850 ((fsobj_id_t *)attrbufptr)->fid_objno = ip->i_number;
851 ((fsobj_id_t *)attrbufptr)->fid_generation = 0;
852 ++((fsobj_id_t *)attrbufptr);
853 };
854 if (a & ATTR_CMN_PAROBJID) {
855 struct iso_directory_record *dp = (struct iso_directory_record *)imp->root;
856 ino_t rootino = isodirino(dp, imp);
857
858 if (ip->i_number == rootino)
859 ((fsobj_id_t *)attrbufptr)->fid_objno = 1; /* force root parent to be 1 */
860 else if (ip->i_parent == rootino)
861 ((fsobj_id_t *)attrbufptr)->fid_objno = 2; /* force root to be 2 */
862 else
863 ((fsobj_id_t *)attrbufptr)->fid_objno = ip->i_parent;
864 ((fsobj_id_t *)attrbufptr)->fid_generation = 0;
865 ++((fsobj_id_t *)attrbufptr);
866 };
867 if (a & ATTR_CMN_SCRIPT) *((text_encoding_t *)attrbufptr)++ = 0;
868 if (a & ATTR_CMN_CRTIME) {
869 if (is_64_bit) {
870 struct user_timespec *tmpp = ((struct user_timespec *)attrbufptr)++;
871 tmpp->tv_sec = (user_time_t) ip->inode.iso_mtime.tv_sec;
872 tmpp->tv_nsec = ip->inode.iso_mtime.tv_nsec;
873 }
874 else {
875 *((struct timespec *)attrbufptr)++ = ip->inode.iso_mtime;
876 }
877 }
878 if (a & ATTR_CMN_MODTIME) {
879 if (is_64_bit) {
880 struct user_timespec *tmpp = ((struct user_timespec *)attrbufptr)++;
881 tmpp->tv_sec = (user_time_t) ip->inode.iso_mtime.tv_sec;
882 tmpp->tv_nsec = ip->inode.iso_mtime.tv_nsec;
883 }
884 else {
885 *((struct timespec *)attrbufptr)++ = ip->inode.iso_mtime;
886 }
887 }
888 if (a & ATTR_CMN_CHGTIME) {
889 if (is_64_bit) {
890 struct user_timespec *tmpp = ((struct user_timespec *)attrbufptr)++;
891 tmpp->tv_sec = (user_time_t) ip->inode.iso_ctime.tv_sec;
892 tmpp->tv_nsec = ip->inode.iso_ctime.tv_nsec;
893 }
894 else {
895 *((struct timespec *)attrbufptr)++ = ip->inode.iso_ctime;
896 }
897 }
898 if (a & ATTR_CMN_ACCTIME) {
899 if (is_64_bit) {
900 struct user_timespec *tmpp = ((struct user_timespec *)attrbufptr)++;
901 tmpp->tv_sec = (user_time_t) ip->inode.iso_atime.tv_sec;
902 tmpp->tv_nsec = ip->inode.iso_atime.tv_nsec;
903 }
904 else {
905 *((struct timespec *)attrbufptr)++ = ip->inode.iso_atime;
906 }
907 }
908 if (a & ATTR_CMN_BKUPTIME) {
909 if (is_64_bit) {
910 struct user_timespec *tmpp = ((struct user_timespec *)attrbufptr)++;
911 tmpp->tv_sec = (user_time_t) 0;
912 tmpp->tv_nsec = 0;
913 }
914 else {
915 ((struct timespec *)attrbufptr)->tv_sec = 0;
916 ((struct timespec *)attrbufptr)->tv_nsec = 0;
917 ++((struct timespec *)attrbufptr);
918 *((struct timespec *)attrbufptr)++ = ip->inode.iso_atime;
919 }
920 }
921 if (a & ATTR_CMN_FNDRINFO) {
922 struct finder_info finfo;
923
924 bzero(&finfo, sizeof(finfo));
925 finfo.fdFlags = ip->i_FinderFlags;
926 finfo.fdLocation.v = -1;
927 finfo.fdLocation.h = -1;
928 if (vnode_isreg(ITOV(ip))) {
929 finfo.fdType = ip->i_FileType;
930 finfo.fdCreator = ip->i_Creator;
931 }
932 bcopy (&finfo, attrbufptr, sizeof(finfo));
933 (u_int8_t *)attrbufptr += sizeof(finfo);
934 bzero (attrbufptr, EXTFNDRINFOSIZE);
935 (u_int8_t *)attrbufptr += EXTFNDRINFOSIZE;
936 };
937 if (a & ATTR_CMN_OWNERID) *((uid_t *)attrbufptr)++ = ip->inode.iso_uid;
938 if (a & ATTR_CMN_GRPID) *((gid_t *)attrbufptr)++ = ip->inode.iso_gid;
939 if (a & ATTR_CMN_ACCESSMASK) *((uint32_t *)attrbufptr)++ = (uint32_t)ip->inode.iso_mode;
940 if (a & ATTR_CMN_FLAGS) *((uint32_t *)attrbufptr)++ = 0; /* could also use ip->i_flag */
941 if (a & ATTR_CMN_USERACCESS) {
942 *((uint32_t *)attrbufptr)++ =
943 DerivePermissionSummary(ip->inode.iso_uid,
944 ip->inode.iso_gid,
945 ip->inode.iso_mode,
946 imp);
947 };
948 };
949
950 *attrbufptrptr = attrbufptr;
951 *varbufptrptr = varbufptr;
952 }
953
954
955 void
956 packdirattr(struct attrlist *alist,
957 struct iso_node *ip,
958 void **attrbufptrptr,
959 __unused void **varbufptrptr)
960 {
961 void *attrbufptr;
962 attrgroup_t a;
963 int filcnt, dircnt;
964
965 attrbufptr = *attrbufptrptr;
966 filcnt = dircnt = 0;
967
968 a = alist->dirattr;
969 if (vnode_isdir(ITOV(ip)) && (a != 0)) {
970 /*
971 * if we haven't counted our children yet, do it now...
972 */
973 if ((ip->i_entries == 0) &&
974 (a & (ATTR_DIR_LINKCOUNT | ATTR_DIR_ENTRYCOUNT))) {
975 (void) isochildcount(ITOV(ip), &dircnt, &filcnt);
976
977 if ((ip->inode.iso_links == 1) && (dircnt != 0))
978 ip->inode.iso_links = dircnt;
979 if ((filcnt + dircnt) > 0)
980 ip->i_entries = dircnt + filcnt;
981 }
982
983 if (a & ATTR_DIR_LINKCOUNT) {
984 *((uint32_t *)attrbufptr)++ = ip->inode.iso_links;
985 }
986 if (a & ATTR_DIR_ENTRYCOUNT) {
987 /* exclude '.' and '..' from total caount */
988 *((uint32_t *)attrbufptr)++ = ((ip->i_entries <= 2) ? 0 : (ip->i_entries - 2));
989 }
990 if (a & ATTR_DIR_MOUNTSTATUS) {
991 if (vnode_mountedhere(ITOV(ip))) {
992 *((uint32_t *)attrbufptr)++ = DIR_MNTSTATUS_MNTPOINT;
993 } else {
994 *((uint32_t *)attrbufptr)++ = 0;
995 };
996 };
997 };
998
999 *attrbufptrptr = attrbufptr;
1000 }
1001
1002
1003 void
1004 packfileattr(struct attrlist *alist,
1005 struct iso_node *ip,
1006 void **attrbufptrptr,
1007 void **varbufptrptr)
1008 {
1009 void *attrbufptr = *attrbufptrptr;
1010 void *varbufptr = *varbufptrptr;
1011 attrgroup_t a = alist->fileattr;
1012
1013 if (vnode_isreg(ITOV(ip)) && (a != 0)) {
1014 if (a & ATTR_FILE_LINKCOUNT)
1015 *((uint32_t *)attrbufptr)++ = ip->inode.iso_links;
1016 if (a & ATTR_FILE_TOTALSIZE)
1017 *((off_t *)attrbufptr)++ = (off_t)ip->i_size;
1018 if (a & ATTR_FILE_ALLOCSIZE)
1019 *((off_t *)attrbufptr)++ = (off_t)ip->i_size;
1020 if (a & ATTR_FILE_IOBLOCKSIZE)
1021 *((uint32_t *)attrbufptr)++ = ip->i_mnt->logical_block_size;
1022 if (a & ATTR_FILE_CLUMPSIZE)
1023 *((uint32_t *)attrbufptr)++ = ip->i_mnt->logical_block_size;
1024 if (a & ATTR_FILE_DEVTYPE)
1025 *((uint32_t *)attrbufptr)++ = (uint32_t)ip->inode.iso_rdev;
1026 if (a & ATTR_FILE_DATALENGTH)
1027 *((off_t *)attrbufptr)++ = (off_t)ip->i_size;
1028 if (a & ATTR_FILE_DATAALLOCSIZE)
1029 *((off_t *)attrbufptr)++ = (off_t)ip->i_size;
1030 if (a & ATTR_FILE_RSRCLENGTH)
1031 *((off_t *)attrbufptr)++ = (off_t)ip->i_rsrcsize;
1032 if (a & ATTR_FILE_RSRCALLOCSIZE)
1033 *((off_t *)attrbufptr)++ = (off_t)ip->i_rsrcsize;
1034 }
1035
1036 *attrbufptrptr = attrbufptr;
1037 *varbufptrptr = varbufptr;
1038 }
1039
1040
1041 void
1042 packattrblk(struct attrlist *alist,
1043 struct vnode *vp,
1044 void **attrbufptrptr,
1045 void **varbufptrptr)
1046 {
1047 struct iso_node *ip = VTOI(vp);
1048
1049 if (alist->volattr != 0) {
1050 packvolattr(alist, ip, attrbufptrptr, varbufptrptr);
1051 } else {
1052 packcommonattr(alist, ip, attrbufptrptr, varbufptrptr);
1053
1054 switch (vnode_vtype(ITOV(ip))) {
1055 case VDIR:
1056 packdirattr(alist, ip, attrbufptrptr, varbufptrptr);
1057 break;
1058
1059 case VREG:
1060 packfileattr(alist, ip, attrbufptrptr, varbufptrptr);
1061 break;
1062
1063 /* Without this the compiler complains about VNON,VBLK,VCHR,VLNK,VSOCK,VFIFO,VBAD and VSTR
1064 not being handled...
1065 */
1066 default:
1067 break;
1068 };
1069 };
1070 };