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