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