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