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