]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfs_search.c
xnu-2422.90.20.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_search.c
1 /*
2 * Copyright (c) 1997-2013 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 *
28 * @(#)hfs_search.c
29 */
30 /*
31 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
32 * support for mandatory and extensible security protections. This notice
33 * is included in support of clause 2.2 (b) of the Apple Public License,
34 * Version 2.0.
35 */
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/file.h>
41 #include <sys/proc.h>
42 #include <sys/conf.h>
43 #include <mach/machine/vm_types.h>
44 #include <sys/vnode.h>
45 #include <sys/malloc.h>
46 #include <sys/signalvar.h>
47 #include <sys/attr.h>
48 #include <sys/utfconv.h>
49 #include <sys/kauth.h>
50 #include <sys/vnode_internal.h>
51 #include <sys/mount_internal.h>
52
53 #if CONFIG_MACF
54 #include <security/mac_framework.h>
55 #endif
56
57 #include "hfs.h"
58 #include "hfs_dbg.h"
59 #include "hfs_catalog.h"
60 #include "hfs_attrlist.h"
61 #include "hfs_endian.h"
62
63 #include "hfscommon/headers/FileMgrInternal.h"
64 #include "hfscommon/headers/HFSUnicodeWrappers.h"
65 #include "hfscommon/headers/BTreesPrivate.h"
66 #include "hfscommon/headers/BTreeScanner.h"
67 #include "hfscommon/headers/CatalogPrivate.h"
68
69 #if CONFIG_SEARCHFS
70
71 /* Search criterea. */
72 struct directoryInfoSpec
73 {
74 u_int32_t numFiles;
75 };
76
77 struct fileInfoSpec
78 {
79 off_t dataLogicalLength;
80 off_t dataPhysicalLength;
81 off_t resourceLogicalLength;
82 off_t resourcePhysicalLength;
83 };
84
85 struct searchinfospec
86 {
87 u_char name[kHFSPlusMaxFileNameBytes];
88 u_int32_t nameLength;
89 char attributes; // see IM:Files 2-100
90 u_int32_t nodeID;
91 u_int32_t parentDirID;
92 struct timespec creationDate;
93 struct timespec modificationDate;
94 struct timespec changeDate;
95 struct timespec accessDate;
96 struct timespec lastBackupDate;
97 u_int8_t finderInfo[32];
98 uid_t uid;
99 gid_t gid;
100 mode_t mask;
101 struct fileInfoSpec f;
102 struct directoryInfoSpec d;
103 };
104 typedef struct searchinfospec searchinfospec_t;
105
106 static void ResolveHardlink(struct hfsmount *hfsmp, HFSPlusCatalogFile *recp);
107
108
109 static int UnpackSearchAttributeBlock(struct hfsmount *hfsmp, struct attrlist *alist,
110 searchinfospec_t *searchInfo, void *attributeBuffer, int firstblock);
111
112 static int CheckCriteria( ExtendedVCB *vcb,
113 u_long searchBits,
114 struct attrlist *attrList,
115 CatalogRecord *rec,
116 CatalogKey *key,
117 searchinfospec_t *searchInfo1,
118 searchinfospec_t *searchInfo2,
119 struct vfs_context *ctx);
120
121 static int CheckAccess(ExtendedVCB *vcb, u_long searchBits, CatalogKey *key, struct vfs_context *ctx);
122
123 static int InsertMatch(struct hfsmount *hfsmp, uio_t a_uio, CatalogRecord *rec,
124 CatalogKey *key, struct attrlist *returnAttrList,
125 void *attributesBuffer, void *variableBuffer,
126 uint32_t * nummatches );
127
128 static Boolean CompareRange(u_long val, u_long low, u_long high);
129 static Boolean CompareWideRange(u_int64_t val, u_int64_t low, u_int64_t high);
130
131 static Boolean CompareRange( u_long val, u_long low, u_long high )
132 {
133 return( (val >= low) && (val <= high) );
134 }
135
136 static Boolean CompareWideRange( u_int64_t val, u_int64_t low, u_int64_t high )
137 {
138 return( (val >= low) && (val <= high) );
139 }
140 //#define CompareRange(val, low, high) ((val >= low) && (val <= high))
141
142
143 /************************************************************************/
144 /* Entry for searchfs() */
145 /************************************************************************/
146
147 #define errSearchBufferFull 101 /* Internal search errors */
148 /*
149 #
150 #% searchfs vp L L L
151 #
152 vnop_searchfs {
153 IN struct vnode *vp;
154 IN off_t length;
155 IN int flags;
156 IN kauth_cred_t cred;
157 IN struct proc *p;
158 };
159 */
160
161 int
162 hfs_vnop_search(ap)
163 struct vnop_searchfs_args *ap; /*
164 struct vnodeop_desc *a_desc;
165 struct vnode *a_vp;
166 void *a_searchparams1;
167 void *a_searchparams2;
168 struct attrlist *a_searchattrs;
169 u_long a_maxmatches;
170 struct timeval *a_timelimit;
171 struct attrlist *a_returnattrs;
172 u_long *a_nummatches;
173 u_long a_scriptcode;
174 u_long a_options;
175 struct uio *a_uio;
176 struct searchstate *a_searchstate;
177 vfs_context_t a_context;
178 */
179 {
180 ExtendedVCB *vcb = VTOVCB(ap->a_vp);
181 struct hfsmount *hfsmp;
182 FCB * catalogFCB;
183 searchinfospec_t searchInfo1;
184 searchinfospec_t searchInfo2;
185 void *attributesBuffer = NULL;
186 void *variableBuffer;
187 u_int32_t fixedBlockSize;
188 u_int32_t eachReturnBufferSize;
189 struct proc *p = current_proc();
190 int err = E_NONE;
191 int isHFSPlus;
192 CatalogKey * myCurrentKeyPtr;
193 CatalogRecord * myCurrentDataPtr;
194 CatPosition * myCatPositionPtr;
195 BTScanState myBTScanState;
196 user_addr_t user_start = 0;
197 user_size_t user_len = 0;
198 int32_t searchTime;
199 int lockflags;
200 struct uthread *ut;
201 boolean_t timerExpired = FALSE;
202 boolean_t needThrottle = FALSE;
203
204 /* XXX Parameter check a_searchattrs? */
205
206 *(ap->a_nummatches) = 0;
207
208 if (ap->a_options & ~SRCHFS_VALIDOPTIONSMASK) {
209 return (EINVAL);
210 }
211
212 /*
213 * Fail requests for attributes that HFS does not support for the
214 * items that match the search criteria. Note that these checks
215 * are for the OUTBOUND attributes to be returned (not search criteria).
216 */
217 if ((ap->a_returnattrs->commonattr & ~HFS_ATTR_CMN_VALID) ||
218 (ap->a_returnattrs->volattr != 0) ||
219 (ap->a_returnattrs->dirattr & ~HFS_ATTR_DIR_VALID) ||
220 (ap->a_returnattrs->fileattr & ~HFS_ATTR_FILE_VALID) ||
221 (ap->a_returnattrs->forkattr != 0)) {
222
223 return (EINVAL);
224 }
225
226 /* SRCHFS_SKIPLINKS requires root access.
227 * This option cannot be used with either
228 * the ATTR_CMN_NAME or ATTR_CMN_PAROBJID
229 * attributes.
230 */
231 if (ap->a_options & SRCHFS_SKIPLINKS) {
232 attrgroup_t attrs;
233
234 attrs = ap->a_searchattrs->commonattr | ap->a_returnattrs->commonattr;
235 if (attrs & (ATTR_CMN_NAME | ATTR_CMN_PAROBJID)) {
236 return (EINVAL);
237 }
238
239 if ((err = vfs_context_suser(ap->a_context))) {
240 return (err);
241 }
242 }
243
244 // If both 32-bit and 64-bit parent ids or file ids are given
245 // then return an error.
246
247 attrgroup_t test_attrs=ap->a_searchattrs->commonattr;
248
249 if (((test_attrs & ATTR_CMN_OBJID) && (test_attrs & ATTR_CMN_FILEID)) ||
250 ((test_attrs & ATTR_CMN_PARENTID) && (test_attrs & ATTR_CMN_PAROBJID))) {
251 return (EINVAL);
252 }
253
254 if (uio_resid(ap->a_uio) <= 0) {
255 return (EINVAL);
256 }
257
258 isHFSPlus = (vcb->vcbSigWord == kHFSPlusSigWord);
259 hfsmp = VTOHFS(ap->a_vp);
260
261 searchTime = kMaxMicroSecsInKernel;
262 if (ap->a_timelimit->tv_sec == 0 &&
263 ap->a_timelimit->tv_usec > 0 &&
264 ap->a_timelimit->tv_usec < kMaxMicroSecsInKernel) {
265 searchTime = ap->a_timelimit->tv_usec;
266 }
267
268 /* UnPack the search boundries, searchInfo1, searchInfo2 */
269 err = UnpackSearchAttributeBlock(hfsmp, ap->a_searchattrs,
270 &searchInfo1, ap->a_searchparams1, 1);
271 if (err) {
272 return err;
273 }
274 err = UnpackSearchAttributeBlock(hfsmp, ap->a_searchattrs,
275 &searchInfo2, ap->a_searchparams2, 0);
276 if (err) {
277 return err;
278 }
279 //shadow search bits if 64-bit file/parent ids are used
280 if (ap->a_searchattrs->commonattr & ATTR_CMN_FILEID)
281 ap->a_searchattrs->commonattr |= ATTR_CMN_OBJID;
282 if (ap->a_searchattrs->commonattr & ATTR_CMN_PARENTID)
283 ap->a_searchattrs->commonattr |= ATTR_CMN_PAROBJID;
284
285 fixedBlockSize = sizeof(u_int32_t) + hfs_attrblksize(ap->a_returnattrs); /* u_int32_t for length word */
286
287 eachReturnBufferSize = fixedBlockSize;
288
289 if ( ap->a_returnattrs->commonattr & ATTR_CMN_NAME ) /* XXX should be more robust! */
290 eachReturnBufferSize += kHFSPlusMaxFileNameBytes + 1;
291
292 MALLOC( attributesBuffer, void *, eachReturnBufferSize, M_TEMP, M_WAITOK );
293 if (attributesBuffer == NULL) {
294 err = ENOMEM;
295 goto ExitThisRoutine;
296 }
297 bzero(attributesBuffer, eachReturnBufferSize);
298 variableBuffer = (void*)((char*) attributesBuffer + fixedBlockSize);
299
300 // XXXdbg - have to lock the user's buffer so we don't fault
301 // while holding the shared catalog file lock. see the comment
302 // in hfs_readdir() for more details.
303 //
304 if (hfsmp->jnl && uio_isuserspace(ap->a_uio)) {
305 user_start = uio_curriovbase(ap->a_uio);
306 user_len = uio_curriovlen(ap->a_uio);
307
308 if ((err = vslock(user_start, user_len)) != 0) {
309 user_start = 0;
310 goto ExitThisRoutine;
311 }
312 }
313
314 lockflags = hfs_systemfile_lock(hfsmp, SFL_CATALOG, HFS_SHARED_LOCK);
315
316 catalogFCB = GetFileControlBlock(vcb->catalogRefNum);
317 myCurrentKeyPtr = NULL;
318 myCurrentDataPtr = NULL;
319 myCatPositionPtr = (CatPosition *)ap->a_searchstate;
320
321 if (ap->a_options & SRCHFS_START) {
322 /* Starting a new search. */
323 /* Make sure the on-disk Catalog file is current */
324 (void) hfs_fsync(vcb->catalogRefNum, MNT_WAIT, 0, p);
325 if (hfsmp->jnl) {
326 hfs_systemfile_unlock(hfsmp, lockflags);
327 hfs_journal_flush(hfsmp, FALSE);
328 lockflags = hfs_systemfile_lock(hfsmp, SFL_CATALOG, HFS_SHARED_LOCK);
329 }
330
331 ap->a_options &= ~SRCHFS_START;
332 bzero((caddr_t)myCatPositionPtr, sizeof(*myCatPositionPtr));
333 err = BTScanInitialize(catalogFCB, 0, 0, 0, kCatSearchBufferSize, &myBTScanState);
334 if (err) {
335 goto ExitThisRoutine;
336 }
337 } else {
338 /* Resuming a search. */
339 err = BTScanInitialize(catalogFCB, myCatPositionPtr->nextNode,
340 myCatPositionPtr->nextRecord,
341 myCatPositionPtr->recordsFound,
342 kCatSearchBufferSize,
343 &myBTScanState);
344 /* Make sure Catalog hasn't changed. */
345 if (err == 0
346 && myCatPositionPtr->writeCount != myBTScanState.btcb->writeCount) {
347 myCatPositionPtr->writeCount = myBTScanState.btcb->writeCount;
348 err = EBUSY; /* catChangedErr */
349 }
350 }
351 hfs_systemfile_unlock(hfsmp, lockflags);
352
353 if (err)
354 goto ExitThisRoutine;
355
356 if (throttle_get_io_policy(&ut) == IOPOL_THROTTLE)
357 needThrottle = TRUE;
358 /*
359 * Check all the catalog btree records...
360 * return the attributes for matching items
361 */
362 for (;;) {
363 struct timeval myCurrentTime;
364 struct timeval myElapsedTime;
365
366 err = BTScanNextRecord(&myBTScanState, timerExpired,
367 (void **)&myCurrentKeyPtr, (void **)&myCurrentDataPtr,
368 NULL);
369 if (err)
370 break;
371
372 /* Resolve any hardlinks */
373 if (isHFSPlus && (ap->a_options & SRCHFS_SKIPLINKS) == 0) {
374 ResolveHardlink(vcb, (HFSPlusCatalogFile *)myCurrentDataPtr);
375 }
376 if (CheckCriteria( vcb, ap->a_options, ap->a_searchattrs, myCurrentDataPtr,
377 myCurrentKeyPtr, &searchInfo1, &searchInfo2, ap->a_context )
378 && CheckAccess(vcb, ap->a_options, myCurrentKeyPtr, ap->a_context)) {
379 err = InsertMatch(hfsmp, ap->a_uio, myCurrentDataPtr,
380 myCurrentKeyPtr, ap->a_returnattrs,
381 attributesBuffer, variableBuffer, ap->a_nummatches);
382 if (err) {
383 /*
384 * The last match didn't fit so come back
385 * to this record on the next trip.
386 */
387 --myBTScanState.recordsFound;
388 --myBTScanState.recordNum;
389 break;
390 }
391
392 if (*(ap->a_nummatches) >= ap->a_maxmatches)
393 break;
394 }
395 if (timerExpired == FALSE) {
396 /*
397 * Check our elapsed time and bail if we've hit the max.
398 * The idea here is to throttle the amount of time we
399 * spend in the kernel.
400 */
401 microuptime(&myCurrentTime);
402 timersub(&myCurrentTime, &myBTScanState.startTime, &myElapsedTime);
403 /*
404 * Note: assumes kMaxMicroSecsInKernel is less than 1,000,000
405 */
406 if (myElapsedTime.tv_sec > 0
407 || myElapsedTime.tv_usec >= searchTime) {
408 timerExpired = TRUE;
409 } else if (needThrottle == TRUE) {
410 if (throttle_io_will_be_throttled(ut->uu_lowpri_window, HFSTOVFS(hfsmp)))
411 timerExpired = TRUE;
412 }
413 }
414 }
415
416 /* Update catalog position */
417 myCatPositionPtr->writeCount = myBTScanState.btcb->writeCount;
418
419 BTScanTerminate(&myBTScanState, &myCatPositionPtr->nextNode,
420 &myCatPositionPtr->nextRecord,
421 &myCatPositionPtr->recordsFound);
422
423 if ( err == E_NONE ) {
424 err = EAGAIN; /* signal to the user to call searchfs again */
425 } else if ( err == errSearchBufferFull ) {
426 if ( *(ap->a_nummatches) > 0 )
427 err = EAGAIN;
428 else
429 err = ENOBUFS;
430 } else if ( err == btNotFound ) {
431 err = E_NONE; /* the entire disk has been searched */
432 } else if ( err == fsBTTimeOutErr ) {
433 err = EAGAIN;
434 }
435
436 ExitThisRoutine:
437 if (attributesBuffer)
438 FREE(attributesBuffer, M_TEMP);
439
440 if (user_start) {
441 vsunlock(user_start, user_len, TRUE);
442 }
443
444 return (MacToVFSError(err));
445 }
446
447
448 static void
449 ResolveHardlink(struct hfsmount *hfsmp, HFSPlusCatalogFile *recp)
450 {
451 u_int32_t type, creator;
452 int isdirlink = 0;
453 int isfilelink = 0;
454 time_t filecreatedate;
455
456 if (recp->recordType != kHFSPlusFileRecord) {
457 return;
458 }
459 type = SWAP_BE32(recp->userInfo.fdType);
460 creator = SWAP_BE32(recp->userInfo.fdCreator);
461 filecreatedate = to_bsd_time(recp->createDate);
462
463 if ((type == kHardLinkFileType && creator == kHFSPlusCreator) &&
464 (filecreatedate == (time_t)hfsmp->hfs_itime ||
465 filecreatedate == (time_t)hfsmp->hfs_metadata_createdate)) {
466 isfilelink = 1;
467 } else if ((type == kHFSAliasType && creator == kHFSAliasCreator) &&
468 (recp->flags & kHFSHasLinkChainMask) &&
469 (filecreatedate == (time_t)hfsmp->hfs_itime ||
470 filecreatedate == (time_t)hfsmp->hfs_metadata_createdate)) {
471 isdirlink = 1;
472 }
473
474 if (isfilelink || isdirlink) {
475 cnid_t saved_cnid;
476 int lockflags;
477
478 /* Export link's cnid (a unique value) instead of inode's cnid */
479 saved_cnid = recp->fileID;
480 lockflags = hfs_systemfile_lock(hfsmp, SFL_CATALOG, HFS_SHARED_LOCK);
481
482 (void) cat_resolvelink(hfsmp, recp->hl_linkReference, isdirlink, recp);
483
484 recp->fileID = saved_cnid;
485 hfs_systemfile_unlock(hfsmp, lockflags);
486 }
487 }
488
489
490 static Boolean
491 CompareMasked(const u_int32_t *thisValue, const u_int32_t *compareData,
492 const u_int32_t *compareMask, u_int32_t count)
493 {
494 Boolean matched;
495 u_int32_t i;
496
497 matched = true; /* Assume it will all match */
498
499 for (i=0; i<count; i++) {
500 if (((*thisValue++ ^ *compareData++) & *compareMask++) != 0) {
501 matched = false;
502 break;
503 }
504 }
505
506 return matched;
507 }
508
509
510 static Boolean
511 ComparePartialUnicodeName (register ConstUniCharArrayPtr str, register ItemCount s_len,
512 register ConstUniCharArrayPtr find, register ItemCount f_len, int caseSensitive )
513 {
514 if (f_len == 0 || s_len == 0) {
515 return FALSE;
516 }
517
518 if (caseSensitive) {
519 do {
520 if (s_len-- < f_len)
521 return FALSE;
522 } while (UnicodeBinaryCompare(str++, f_len, find, f_len) != 0);
523 }
524 else {
525 do {
526 if (s_len-- < f_len)
527 return FALSE;
528 } while (FastUnicodeCompare(str++, f_len, find, f_len) != 0);
529 }
530
531 return TRUE;
532 }
533
534 #if CONFIG_HFS_STD
535 static Boolean
536 ComparePartialPascalName ( register ConstStr31Param str, register ConstStr31Param find )
537 {
538 register u_char s_len = str[0];
539 register u_char f_len = find[0];
540 register u_char *tsp;
541 Str31 tmpstr;
542
543 if (f_len == 0 || s_len == 0)
544 return FALSE;
545
546 bcopy(str, tmpstr, s_len + 1);
547 tsp = &tmpstr[0];
548
549 while (s_len-- >= f_len) {
550 *tsp = f_len;
551
552 if (FastRelString(tsp++, find) == 0)
553 return TRUE;
554 }
555
556 return FALSE;
557 }
558 #endif
559
560
561 /*
562 * Check to see if caller has access rights to this item
563 */
564
565 static int
566 CheckAccess(ExtendedVCB *theVCBPtr, u_long searchBits, CatalogKey *theKeyPtr, struct vfs_context *ctx)
567 {
568 Boolean isHFSPlus;
569 int myErr;
570 int myResult;
571 HFSCatalogNodeID myNodeID;
572 hfsmount_t * hfsmp;
573 struct FndrDirInfo *finfop;
574 struct vnode * vp = NULL;
575
576 myResult = 0; /* default to "no access" */
577
578 if (!vfs_context_suser(ctx)) {
579 myResult = 1; /* allow access */
580 goto ExitThisRoutine; /* root always has access */
581 }
582
583 hfsmp = VCBTOHFS( theVCBPtr );
584 isHFSPlus = ( theVCBPtr->vcbSigWord == kHFSPlusSigWord );
585 if ( isHFSPlus )
586 myNodeID = theKeyPtr->hfsPlus.parentID;
587 #if CONFIG_HFS_STD
588 else
589 myNodeID = theKeyPtr->hfs.parentID;
590 #endif
591
592 while ( myNodeID >= kRootDirID ) {
593 cnode_t * cp;
594
595 /* now go get catalog data for this directory */
596 myErr = hfs_vget(hfsmp, myNodeID, &vp, 0, 0);
597 if ( myErr ) {
598 goto ExitThisRoutine; /* no access */
599 }
600
601 cp = VTOC(vp);
602 finfop = (struct FndrDirInfo *)&cp->c_attr.ca_finderinfo[0];
603
604 if ( searchBits & SRCHFS_SKIPPACKAGES ) {
605 if ( (SWAP_BE16(finfop->frFlags) & kHasBundle)
606 || (cp->c_desc.cd_nameptr != NULL
607 && is_package_name((const char *)cp->c_desc.cd_nameptr, cp->c_desc.cd_namelen)) ) {
608 myResult = 0;
609 goto ExitThisRoutine;
610 }
611 }
612
613 if ( searchBits & SRCHFS_SKIPINAPPROPRIATE ) {
614 if ( cp->c_parentcnid == kRootDirID && cp->c_desc.cd_nameptr != NULL &&
615 vn_searchfs_inappropriate_name((const char *)cp->c_desc.cd_nameptr, cp->c_desc.cd_namelen) ) {
616 myResult = 0;
617 goto ExitThisRoutine;
618 }
619 }
620
621 if ( (searchBits & SRCHFS_SKIPINVISIBLE) &&
622 (SWAP_BE16(finfop->frFlags) & kIsInvisible) ) {
623 myResult = 0;
624 goto ExitThisRoutine;
625 }
626
627 myNodeID = cp->c_parentcnid; /* move up the hierarchy */
628 hfs_unlock(VTOC(vp));
629
630 #if CONFIG_MACF
631 if (vp->v_type == VDIR) {
632 myErr = mac_vnode_check_readdir(ctx, vp);
633 } else {
634 myErr = mac_vnode_check_stat(ctx, NOCRED, vp);
635 }
636 if (myErr) {
637 vnode_put(vp);
638 vp = NULL;
639 goto ExitThisRoutine;
640 }
641 #endif /* MAC */
642
643 if (vp->v_type == VDIR) {
644 myErr = vnode_authorize(vp, NULL, (KAUTH_VNODE_SEARCH | KAUTH_VNODE_LIST_DIRECTORY), ctx);
645 } else {
646 myErr = vnode_authorize(vp, NULL, (KAUTH_VNODE_SEARCH), ctx);
647 }
648 vnode_put(vp);
649 vp = NULL;
650 if ( myErr ) {
651 goto ExitThisRoutine; /* no access */
652 }
653 }
654 myResult = 1; /* allow access */
655
656 ExitThisRoutine:
657 if ( vp != NULL ) {
658 hfs_unlock(VTOC(vp));
659 vnode_put(vp);
660 }
661 return ( myResult );
662
663 }
664
665 static int
666 CheckCriteria( ExtendedVCB *vcb,
667 u_long searchBits,
668 struct attrlist *attrList,
669 CatalogRecord *rec,
670 CatalogKey *key,
671 searchinfospec_t *searchInfo1,
672 searchinfospec_t *searchInfo2,
673 struct vfs_context *ctx)
674 {
675 Boolean matched, atleastone;
676 Boolean isHFSPlus;
677 attrgroup_t searchAttributes;
678 struct cat_attr c_attr;
679 struct cat_fork datafork;
680 struct cat_fork rsrcfork;
681 struct hfsmount *hfsmp = (struct hfsmount*)vcb;
682 int force_case_sensitivity = proc_is_forcing_hfs_case_sensitivity(vfs_context_proc(ctx));
683
684 bzero(&c_attr, sizeof(c_attr));
685 isHFSPlus = (vcb->vcbSigWord == kHFSPlusSigWord);
686
687 switch (rec->recordType) {
688
689 #if CONFIG_HFS_STD
690 case kHFSFolderRecord:
691 if ( (searchBits & SRCHFS_MATCHDIRS) == 0 ) { /* If we are NOT searching folders */
692 matched = false;
693 goto TestDone;
694 }
695 break;
696
697 case kHFSFileRecord:
698 if ( (searchBits & SRCHFS_MATCHFILES) == 0 ) { /* If we are NOT searching files */
699 matched = false;
700 goto TestDone;
701 }
702 break;
703 #endif
704
705 case kHFSPlusFolderRecord:
706 if ( (searchBits & SRCHFS_MATCHDIRS) == 0 ) { /* If we are NOT searching folders */
707 matched = false;
708 goto TestDone;
709 }
710 break;
711
712 case kHFSPlusFileRecord:
713 /* Check if hardlink links should be skipped. */
714 if (searchBits & SRCHFS_SKIPLINKS) {
715 cnid_t parid = key->hfsPlus.parentID;
716 HFSPlusCatalogFile *filep = (HFSPlusCatalogFile *)rec;
717
718 if ((SWAP_BE32(filep->userInfo.fdType) == kHardLinkFileType) &&
719 (SWAP_BE32(filep->userInfo.fdCreator) == kHFSPlusCreator)) {
720 return (false); /* skip over file link records */
721 } else if ((parid == vcb->hfs_private_desc[FILE_HARDLINKS].cd_cnid) &&
722 (filep->bsdInfo.special.linkCount == 0)) {
723 return (false); /* skip over unlinked files */
724 } else if ((SWAP_BE32(filep->userInfo.fdType) == kHFSAliasType) &&
725 (SWAP_BE32(filep->userInfo.fdCreator) == kHFSAliasCreator) &&
726 (filep->flags & kHFSHasLinkChainMask)) {
727 return (false); /* skip over dir link records */
728 }
729 } else if (key->hfsPlus.parentID == vcb->hfs_private_desc[FILE_HARDLINKS].cd_cnid) {
730 return (false); /* skip over private files */
731 } else if (key->hfsPlus.parentID == vcb->hfs_private_desc[DIR_HARDLINKS].cd_cnid) {
732 return (false); /* skip over private files */
733 }
734
735 if ( (searchBits & SRCHFS_MATCHFILES) == 0 ) { /* If we are NOT searching files */
736 matched = false;
737 goto TestDone;
738 }
739 break;
740
741 default: /* Never match a thread record or any other type. */
742 return( false ); /* Not a file or folder record, so can't search it */
743 }
744
745 matched = true; /* Assume we got a match */
746 atleastone = false; /* Dont insert unless we match at least one criteria */
747
748 /* First, attempt to match the name -- either partial or complete */
749 if ( attrList->commonattr & ATTR_CMN_NAME ) {
750 if (isHFSPlus) {
751 int case_sensitive = 0;
752
753 if (hfsmp->hfs_flags & HFS_CASE_SENSITIVE) {
754 case_sensitive = 1;
755 } else if (force_case_sensitivity) {
756 case_sensitive = 1;
757 }
758
759 /* Check for partial/full HFS Plus name match */
760
761 if ( searchBits & SRCHFS_MATCHPARTIALNAMES ) {
762 matched = ComparePartialUnicodeName(key->hfsPlus.nodeName.unicode,
763 key->hfsPlus.nodeName.length,
764 (UniChar*)searchInfo1->name,
765 searchInfo1->nameLength, case_sensitive);
766 }
767 else {
768 /* Full name match. Are we HFSX (case sensitive) or HFS+ ? */
769 if (case_sensitive) {
770 matched = (UnicodeBinaryCompare(key->hfsPlus.nodeName.unicode,
771 key->hfsPlus.nodeName.length,
772 (UniChar*)searchInfo1->name,
773 searchInfo1->nameLength ) == 0);
774 }
775 else {
776 matched = (FastUnicodeCompare(key->hfsPlus.nodeName.unicode,
777 key->hfsPlus.nodeName.length,
778 (UniChar*)searchInfo1->name,
779 searchInfo1->nameLength ) == 0);
780 }
781 }
782 }
783 #if CONFIG_HFS_STD
784 else {
785 /* Check for partial/full HFS name match */
786
787 if ( searchBits & SRCHFS_MATCHPARTIALNAMES )
788 matched = ComparePartialPascalName(key->hfs.nodeName, (u_char*)searchInfo1->name);
789 else /* full HFS name match */
790 matched = (FastRelString(key->hfs.nodeName, (u_char*)searchInfo1->name) == 0);
791 }
792 #endif
793
794 if ( matched == false || (searchBits & ~SRCHFS_MATCHPARTIALNAMES) == 0 )
795 goto TestDone; /* no match, or nothing more to compare */
796
797 atleastone = true;
798 }
799
800 /* Convert catalog record into cat_attr format. */
801 cat_convertattr(VCBTOHFS(vcb), rec, &c_attr, &datafork, &rsrcfork);
802
803 if (searchBits & SRCHFS_SKIPINVISIBLE) {
804 int flags;
805
806 switch (rec->recordType) {
807 #if CONFIG_HFS_STD
808 case kHFSFolderRecord:
809 {
810 struct FndrDirInfo *finder_info;
811
812 finder_info = (struct FndrDirInfo *)&c_attr.ca_finderinfo[0];
813 flags = SWAP_BE16(finder_info->frFlags);
814 break;
815 }
816
817 case kHFSFileRecord:
818 {
819 struct FndrFileInfo *finder_info;
820
821 finder_info = (struct FndrFileInfo *)&c_attr.ca_finderinfo[0];
822 flags = SWAP_BE16(finder_info->fdFlags);
823 break;
824 }
825 #endif
826
827 case kHFSPlusFolderRecord:
828 {
829 struct FndrDirInfo *finder_info;
830
831 finder_info = (struct FndrDirInfo *)&c_attr.ca_finderinfo[0];
832 flags = SWAP_BE16(finder_info->frFlags);
833 break;
834 }
835
836 case kHFSPlusFileRecord:
837 {
838 struct FndrFileInfo *finder_info;
839
840 finder_info = (struct FndrFileInfo *)&c_attr.ca_finderinfo[0];
841 flags = SWAP_BE16(finder_info->fdFlags);
842 break;
843 }
844
845 default:
846 {
847 flags = kIsInvisible;
848 break;
849 }
850 }
851
852 if (flags & kIsInvisible) {
853 matched = false;
854 goto TestDone;
855 }
856 }
857
858
859
860 /* Now that we have a record worth searching, see if it matches the search attributes */
861 #if CONFIG_HFS_STD
862 if (rec->recordType == kHFSFileRecord ||
863 rec->recordType == kHFSPlusFileRecord) {
864 #else
865 if (rec->recordType == kHFSPlusFileRecord) {
866 #endif
867
868 if ((attrList->fileattr & ~ATTR_FILE_VALIDMASK) != 0) { /* attr we do know about */
869 matched = false;
870 goto TestDone;
871 }
872 else if ((attrList->fileattr & ATTR_FILE_VALIDMASK) != 0) {
873 searchAttributes = attrList->fileattr;
874
875 #if HFS_COMPRESSION
876 if ( c_attr.ca_flags & UF_COMPRESSED ) {
877 /* for compressed files, set the data length to the uncompressed data size */
878 if (( searchAttributes & ATTR_FILE_DATALENGTH ) ||
879 ( searchAttributes & ATTR_FILE_DATAALLOCSIZE ) ) {
880 if ( 0 == hfs_uncompressed_size_of_compressed_file(vcb, NULL, c_attr.ca_fileid, &datafork.cf_size, 1) ) { /* 1 == don't take the cnode lock */
881 datafork.cf_blocks = rsrcfork.cf_blocks;
882 }
883 }
884 /* treat compressed files as if their resource fork is empty */
885 if (( searchAttributes & ATTR_FILE_RSRCLENGTH ) ||
886 ( searchAttributes & ATTR_FILE_RSRCALLOCSIZE ) ) {
887 rsrcfork.cf_size = 0;
888 rsrcfork.cf_blocks = 0;
889 }
890 }
891 #endif /* HFS_COMPRESSION */
892
893 /* File logical length (data fork) */
894 if ( searchAttributes & ATTR_FILE_DATALENGTH ) {
895 matched = CompareWideRange(
896 datafork.cf_size,
897 searchInfo1->f.dataLogicalLength,
898 searchInfo2->f.dataLogicalLength);
899 if (matched == false) goto TestDone;
900 atleastone = true;
901 }
902
903 /* File physical length (data fork) */
904 if ( searchAttributes & ATTR_FILE_DATAALLOCSIZE ) {
905 matched = CompareWideRange(
906 (u_int64_t)datafork.cf_blocks * (u_int64_t)vcb->blockSize,
907 searchInfo1->f.dataPhysicalLength,
908 searchInfo2->f.dataPhysicalLength);
909 if (matched == false) goto TestDone;
910 atleastone = true;
911 }
912
913 /* File logical length (resource fork) */
914 if ( searchAttributes & ATTR_FILE_RSRCLENGTH ) {
915 matched = CompareWideRange(
916 rsrcfork.cf_size,
917 searchInfo1->f.resourceLogicalLength,
918 searchInfo2->f.resourceLogicalLength);
919 if (matched == false) goto TestDone;
920 atleastone = true;
921 }
922
923 /* File physical length (resource fork) */
924 if ( searchAttributes & ATTR_FILE_RSRCALLOCSIZE ) {
925 matched = CompareWideRange(
926 (u_int64_t)rsrcfork.cf_blocks * (u_int64_t)vcb->blockSize,
927 searchInfo1->f.resourcePhysicalLength,
928 searchInfo2->f.resourcePhysicalLength);
929 if (matched == false) goto TestDone;
930 atleastone = true;
931 }
932 }
933 else {
934 atleastone = true; /* to match SRCHFS_MATCHFILES */
935 }
936 }
937 /*
938 * Check the directory attributes
939 */
940 #if CONFIG_HFS_STD
941 else if (rec->recordType == kHFSFolderRecord ||
942 rec->recordType == kHFSPlusFolderRecord) {
943 #else
944 else if (rec->recordType == kHFSPlusFolderRecord) {
945 #endif
946 if ((attrList->dirattr & ~ATTR_DIR_VALIDMASK) != 0) { /* attr we do know about */
947 matched = false;
948 goto TestDone;
949 }
950 else if ((attrList->dirattr & ATTR_DIR_VALIDMASK) != 0) {
951 searchAttributes = attrList->dirattr;
952
953 /* Directory valence */
954 if ( searchAttributes & ATTR_DIR_ENTRYCOUNT ) {
955 matched = CompareRange(c_attr.ca_entries,
956 searchInfo1->d.numFiles,
957 searchInfo2->d.numFiles );
958 if (matched == false) goto TestDone;
959 atleastone = true;
960 }
961 }
962 else {
963 atleastone = true; /* to match SRCHFS_MATCHDIRS */
964 }
965 }
966
967 /*
968 * Check the common attributes
969 */
970 searchAttributes = attrList->commonattr;
971 if ( (searchAttributes & ATTR_CMN_VALIDMASK) != 0 ) {
972 /* node ID */
973 if ( searchAttributes & ATTR_CMN_OBJID ) {
974 matched = CompareRange(c_attr.ca_fileid,
975 searchInfo1->nodeID,
976 searchInfo2->nodeID );
977 if (matched == false) goto TestDone;
978 atleastone = true;
979 }
980
981 /* Parent ID */
982 if ( searchAttributes & ATTR_CMN_PAROBJID ) {
983 HFSCatalogNodeID parentID;
984
985 if (isHFSPlus)
986 parentID = key->hfsPlus.parentID;
987 #if CONFIG_HFS_STD
988 else
989 parentID = key->hfs.parentID;
990 #endif
991
992 matched = CompareRange(parentID, searchInfo1->parentDirID,
993 searchInfo2->parentDirID );
994 if (matched == false) goto TestDone;
995 atleastone = true;
996 }
997
998 /* Finder Info & Extended Finder Info where extFinderInfo is last 32 bytes */
999 if ( searchAttributes & ATTR_CMN_FNDRINFO ) {
1000 u_int32_t *thisValue;
1001 thisValue = (u_int32_t *) &c_attr.ca_finderinfo;
1002
1003 /*
1004 * Note: ioFlFndrInfo and ioDrUsrWds have the same offset in search info, so
1005 * no need to test the object type here.
1006 */
1007 matched = CompareMasked(thisValue,
1008 (u_int32_t *)&searchInfo1->finderInfo,
1009 (u_int32_t *) &searchInfo2->finderInfo, 8);
1010 if (matched == false) goto TestDone;
1011 atleastone = true;
1012 }
1013
1014 /* Create date */
1015 if ( searchAttributes & ATTR_CMN_CRTIME ) {
1016 matched = CompareRange(c_attr.ca_itime,
1017 searchInfo1->creationDate.tv_sec,
1018 searchInfo2->creationDate.tv_sec);
1019 if (matched == false) goto TestDone;
1020 atleastone = true;
1021 }
1022
1023 /* Mod date */
1024 if ( searchAttributes & ATTR_CMN_MODTIME ) {
1025 matched = CompareRange(c_attr.ca_mtime,
1026 searchInfo1->modificationDate.tv_sec,
1027 searchInfo2->modificationDate.tv_sec);
1028 if (matched == false) goto TestDone;
1029 atleastone = true;
1030 }
1031
1032 /* Change Time */
1033 if ( searchAttributes & ATTR_CMN_CHGTIME ) {
1034 matched = CompareRange(c_attr.ca_ctime,
1035 searchInfo1->changeDate.tv_sec,
1036 searchInfo2->changeDate.tv_sec);
1037 if (matched == false) goto TestDone;
1038 atleastone = true;
1039 }
1040
1041 /* Access date */
1042 if ( searchAttributes & ATTR_CMN_ACCTIME ) {
1043 matched = CompareRange(c_attr.ca_atime,
1044 searchInfo1->accessDate.tv_sec,
1045 searchInfo2->accessDate.tv_sec);
1046 if (matched == false) goto TestDone;
1047 atleastone = true;
1048 }
1049
1050 /* Backup date */
1051 if ( searchAttributes & ATTR_CMN_BKUPTIME ) {
1052 matched = CompareRange(c_attr.ca_btime,
1053 searchInfo1->lastBackupDate.tv_sec,
1054 searchInfo2->lastBackupDate.tv_sec);
1055 if (matched == false) goto TestDone;
1056 atleastone = true;
1057 }
1058
1059 /* User ID */
1060 if ( searchAttributes & ATTR_CMN_OWNERID ) {
1061 matched = CompareRange(c_attr.ca_uid,
1062 searchInfo1->uid, searchInfo2->uid);
1063 if (matched == false) goto TestDone;
1064 atleastone = true;
1065 }
1066
1067 /* Group ID */
1068 if ( searchAttributes & ATTR_CMN_GRPID ) {
1069 matched = CompareRange(c_attr.ca_gid,
1070 searchInfo1->gid, searchInfo2->gid);
1071 if (matched == false) goto TestDone;
1072 atleastone = true;
1073 }
1074
1075 /* mode */
1076 if ( searchAttributes & ATTR_CMN_ACCESSMASK ) {
1077 matched = CompareRange((u_int32_t)c_attr.ca_mode,
1078 (u_int32_t)searchInfo1->mask,
1079 (u_int32_t)searchInfo2->mask);
1080 if (matched == false) goto TestDone;
1081 atleastone = true;
1082 }
1083 }
1084
1085 /* If we got here w/o matching any, then set to false */
1086 if (! atleastone)
1087 matched = false;
1088
1089 TestDone:
1090 /*
1091 * Finally, determine whether we need to negate the sense of the match
1092 * (i.e. find all objects that DON'T match).
1093 */
1094 if ( searchBits & SRCHFS_NEGATEPARAMS )
1095 matched = !matched;
1096
1097 return( matched );
1098 }
1099
1100
1101 /*
1102 * Adds another record to the packed array for output
1103 */
1104 static int
1105 InsertMatch(struct hfsmount *hfsmp, uio_t a_uio, CatalogRecord *rec,
1106 CatalogKey *key, struct attrlist *returnAttrList,
1107 void *attributesBuffer, void *variableBuffer, uint32_t * nummatches)
1108 {
1109 int err;
1110 void *rovingAttributesBuffer;
1111 void *rovingVariableBuffer;
1112 long packedBufferSize;
1113 struct attrblock attrblk;
1114 struct cat_desc c_desc;
1115 struct cat_attr c_attr;
1116 struct cat_fork datafork;
1117 struct cat_fork rsrcfork;
1118
1119 bzero(&c_desc, sizeof(c_desc));
1120 bzero(&c_attr, sizeof(c_attr));
1121 rovingAttributesBuffer = (char*)attributesBuffer + sizeof(u_int32_t); /* Reserve space for length field */
1122 rovingVariableBuffer = variableBuffer;
1123
1124 /* Convert catalog record into cat_attr format. */
1125 cat_convertattr(hfsmp, rec, &c_attr, &datafork, &rsrcfork);
1126
1127 /* Hide our private meta data directories */
1128 if (c_attr.ca_fileid == hfsmp->hfs_private_desc[FILE_HARDLINKS].cd_cnid ||
1129 c_attr.ca_fileid == hfsmp->hfs_private_desc[DIR_HARDLINKS].cd_cnid) {
1130 err = 0;
1131 goto exit;
1132 }
1133
1134 /* Hide the private journal files */
1135 if (hfsmp->jnl &&
1136 ((c_attr.ca_fileid == hfsmp->hfs_jnlfileid) ||
1137 (c_attr.ca_fileid == hfsmp->hfs_jnlinfoblkid))) {
1138 err = 0;
1139 goto exit;
1140 }
1141
1142 if (returnAttrList->commonattr & ATTR_CMN_NAME) {
1143 err = cat_convertkey(hfsmp, key, rec, &c_desc);
1144 if (err) {
1145 /* This means that we probably had a CNID error */
1146 goto exit;
1147 }
1148 } else {
1149 c_desc.cd_cnid = c_attr.ca_fileid;
1150 if ((hfsmp->hfs_flags & HFS_STANDARD) == 0)
1151 c_desc.cd_parentcnid = key->hfsPlus.parentID;
1152 #if CONFIG_HFS_STD
1153 else
1154 c_desc.cd_parentcnid = key->hfs.parentID;
1155 #endif
1156
1157 }
1158
1159 attrblk.ab_attrlist = returnAttrList;
1160 attrblk.ab_attrbufpp = &rovingAttributesBuffer;
1161 attrblk.ab_varbufpp = &rovingVariableBuffer;
1162 attrblk.ab_flags = 0;
1163 attrblk.ab_blocksize = 0;
1164 attrblk.ab_context = vfs_context_current();
1165
1166 hfs_packattrblk(&attrblk, hfsmp, NULL, &c_desc, &c_attr, &datafork, &rsrcfork, vfs_context_current());
1167
1168 packedBufferSize = (char*)rovingVariableBuffer - (char*)attributesBuffer;
1169
1170 if ( packedBufferSize > uio_resid(a_uio) )
1171 return( errSearchBufferFull );
1172
1173 (* nummatches)++;
1174
1175 *((u_int32_t *)attributesBuffer) = packedBufferSize; /* Store length of fixed + var block */
1176
1177 err = uiomove( (caddr_t)attributesBuffer, packedBufferSize, a_uio );
1178 exit:
1179 cat_releasedesc(&c_desc);
1180
1181 return( err );
1182 }
1183
1184
1185 static int
1186 UnpackSearchAttributeBlock( struct hfsmount *hfsmp, struct attrlist *alist,
1187 searchinfospec_t *searchInfo, void *attributeBuffer, int firstblock)
1188 {
1189 attrgroup_t a;
1190 u_int32_t bufferSize;
1191 boolean_t is_64_bit;
1192
1193 DBG_ASSERT(searchInfo != NULL);
1194
1195 is_64_bit = proc_is64bit(current_proc());
1196
1197 bufferSize = *((u_int32_t *)attributeBuffer);
1198 if (bufferSize == 0)
1199 return (EINVAL); /* XXX -DJB is a buffer size of zero ever valid for searchfs? */
1200
1201 attributeBuffer = (u_int32_t *)attributeBuffer + 1; /* advance past the size */
1202
1203 /*
1204 * UnPack common attributes
1205 */
1206 a = alist->commonattr;
1207 if ( a != 0 ) {
1208 if ( a & ATTR_CMN_NAME ) {
1209 if (firstblock) {
1210 /* Only use the attrreference_t for the first searchparams */
1211 char *s;
1212 u_int32_t len;
1213
1214 s = (char*) attributeBuffer + ((attrreference_t *) attributeBuffer)->attr_dataoffset;
1215 len = ((attrreference_t *) attributeBuffer)->attr_length;
1216
1217 if (len > sizeof(searchInfo->name))
1218 return (EINVAL);
1219
1220
1221 if ((hfsmp->hfs_flags & HFS_STANDARD) == 0) {
1222 size_t ucslen;
1223 /* Convert name to Unicode to match HFS Plus B-Tree names */
1224
1225 if (len > 0) {
1226 if (utf8_decodestr((u_int8_t *)s, len-1, (UniChar*)searchInfo->name, &ucslen,
1227 sizeof(searchInfo->name), ':', UTF_DECOMPOSED | UTF_ESCAPE_ILLEGAL))
1228 return (EINVAL);
1229
1230 searchInfo->nameLength = ucslen / sizeof(UniChar);
1231 } else {
1232 searchInfo->nameLength = 0;
1233 }
1234 }
1235 #if CONFIG_HFS_STD
1236 else {
1237 /* Convert name to pascal string to match HFS (Standard) B-Tree names */
1238
1239 if (len > 0) {
1240 if (utf8_to_hfs(HFSTOVCB(hfsmp), len-1, (u_char *)s, (u_char*)searchInfo->name) != 0)
1241 return (EINVAL);
1242
1243 searchInfo->nameLength = searchInfo->name[0];
1244 } else {
1245 searchInfo->name[0] = searchInfo->nameLength = 0;
1246 }
1247 }
1248 #endif
1249 }
1250 attributeBuffer = (attrreference_t*) attributeBuffer +1;
1251 }
1252 if ( a & ATTR_CMN_OBJID ) {
1253 searchInfo->nodeID = ((fsobj_id_t *) attributeBuffer)->fid_objno; /* ignore fid_generation */
1254 attributeBuffer = (fsobj_id_t *)attributeBuffer + 1;
1255 }
1256 if ( a & ATTR_CMN_PAROBJID ) {
1257 searchInfo->parentDirID = ((fsobj_id_t *) attributeBuffer)->fid_objno; /* ignore fid_generation */
1258 attributeBuffer = (fsobj_id_t *)attributeBuffer + 1;
1259 }
1260
1261 if ( a & ATTR_CMN_CRTIME ) {
1262 if (is_64_bit) {
1263 struct user64_timespec tmp;
1264 tmp = *((struct user64_timespec *)attributeBuffer);
1265 searchInfo->creationDate.tv_sec = (time_t)tmp.tv_sec;
1266 searchInfo->creationDate.tv_nsec = tmp.tv_nsec;
1267 attributeBuffer = (struct user64_timespec *)attributeBuffer + 1;
1268 }
1269 else {
1270 struct user32_timespec tmp;
1271 tmp = *((struct user32_timespec *)attributeBuffer);
1272 searchInfo->creationDate.tv_sec = (time_t)tmp.tv_sec;
1273 searchInfo->creationDate.tv_nsec = tmp.tv_nsec;
1274 attributeBuffer = (struct user32_timespec *)attributeBuffer + 1;
1275 }
1276 }
1277 if ( a & ATTR_CMN_MODTIME ) {
1278 if (is_64_bit) {
1279 struct user64_timespec tmp;
1280 tmp = *((struct user64_timespec *)attributeBuffer);
1281 searchInfo->modificationDate.tv_sec = (time_t)tmp.tv_sec;
1282 searchInfo->modificationDate.tv_nsec = tmp.tv_nsec;
1283 attributeBuffer = (struct user64_timespec *)attributeBuffer + 1;
1284 }
1285 else {
1286 struct user32_timespec tmp;
1287 tmp = *((struct user32_timespec *)attributeBuffer);
1288 searchInfo->modificationDate.tv_sec = (time_t)tmp.tv_sec;
1289 searchInfo->modificationDate.tv_nsec = tmp.tv_nsec;
1290 attributeBuffer = (struct user32_timespec *)attributeBuffer + 1;
1291 }
1292 }
1293 if ( a & ATTR_CMN_CHGTIME ) {
1294 if (is_64_bit) {
1295 struct user64_timespec tmp;
1296 tmp = *((struct user64_timespec *)attributeBuffer);
1297 searchInfo->changeDate.tv_sec = (time_t)tmp.tv_sec;
1298 searchInfo->changeDate.tv_nsec = tmp.tv_nsec;
1299 attributeBuffer = (struct user64_timespec *)attributeBuffer + 1;
1300 }
1301 else {
1302 struct user32_timespec tmp;
1303 tmp = *((struct user32_timespec *)attributeBuffer);
1304 searchInfo->changeDate.tv_sec = (time_t)tmp.tv_sec;
1305 searchInfo->changeDate.tv_nsec = tmp.tv_nsec;
1306 attributeBuffer = (struct user32_timespec *)attributeBuffer + 1;
1307 }
1308 }
1309 if ( a & ATTR_CMN_ACCTIME ) {
1310 if (is_64_bit) {
1311 struct user64_timespec tmp;
1312 tmp = *((struct user64_timespec *)attributeBuffer);
1313 searchInfo->accessDate.tv_sec = (time_t)tmp.tv_sec;
1314 searchInfo->accessDate.tv_nsec = tmp.tv_nsec;
1315 attributeBuffer = (struct user64_timespec *)attributeBuffer + 1;
1316 }
1317 else {
1318 struct user32_timespec tmp;
1319 tmp = *((struct user32_timespec *)attributeBuffer);
1320 searchInfo->accessDate.tv_sec = (time_t)tmp.tv_sec;
1321 searchInfo->accessDate.tv_nsec = tmp.tv_nsec;
1322 attributeBuffer = (struct user32_timespec *)attributeBuffer + 1;
1323 }
1324 }
1325 if ( a & ATTR_CMN_BKUPTIME ) {
1326 if (is_64_bit) {
1327 struct user64_timespec tmp;
1328 tmp = *((struct user64_timespec *)attributeBuffer);
1329 searchInfo->lastBackupDate.tv_sec = (time_t)tmp.tv_sec;
1330 searchInfo->lastBackupDate.tv_nsec = tmp.tv_nsec;
1331 attributeBuffer = (struct user64_timespec *)attributeBuffer + 1;
1332 }
1333 else {
1334 struct user32_timespec tmp;
1335 tmp = *((struct user32_timespec *)attributeBuffer);
1336 searchInfo->lastBackupDate.tv_sec = (time_t)tmp.tv_sec;
1337 searchInfo->lastBackupDate.tv_nsec = tmp.tv_nsec;
1338 attributeBuffer = (struct user32_timespec *)attributeBuffer + 1;
1339 }
1340 }
1341 if ( a & ATTR_CMN_FNDRINFO ) {
1342 bcopy( attributeBuffer, searchInfo->finderInfo, sizeof(searchInfo->finderInfo) );
1343 attributeBuffer = (u_int8_t *)attributeBuffer + 32;
1344 }
1345 if ( a & ATTR_CMN_OWNERID ) {
1346 searchInfo->uid = *((uid_t *)attributeBuffer);
1347 attributeBuffer = (uid_t *)attributeBuffer + 1;
1348 }
1349 if ( a & ATTR_CMN_GRPID ) {
1350 searchInfo->gid = *((gid_t *)attributeBuffer);
1351 attributeBuffer = (gid_t *)attributeBuffer + 1;
1352 }
1353 if ( a & ATTR_CMN_ACCESSMASK ) {
1354 searchInfo->mask = *((mode_t *)attributeBuffer);
1355 attributeBuffer = (mode_t *)attributeBuffer + 1;
1356 }
1357 if ( a & ATTR_CMN_FILEID ) {
1358 searchInfo->nodeID = (u_int32_t)*((u_int64_t *) attributeBuffer);
1359 attributeBuffer = (u_int64_t *)attributeBuffer + 1;
1360 }
1361 if ( a & ATTR_CMN_PARENTID ) {
1362 searchInfo->parentDirID = (u_int32_t)*((u_int64_t *) attributeBuffer);
1363 attributeBuffer = (u_int64_t *)attributeBuffer + 1;
1364 }
1365 }
1366
1367 a = alist->dirattr;
1368 if ( a != 0 ) {
1369 if ( a & ATTR_DIR_ENTRYCOUNT ) {
1370 searchInfo->d.numFiles = *((u_int32_t *)attributeBuffer);
1371 attributeBuffer = (u_int32_t *)attributeBuffer + 1;
1372 }
1373 }
1374
1375 a = alist->fileattr;
1376 if ( a != 0 ) {
1377 if ( a & ATTR_FILE_DATALENGTH ) {
1378 searchInfo->f.dataLogicalLength = *((off_t *)attributeBuffer);
1379 attributeBuffer = (off_t *)attributeBuffer + 1;
1380 }
1381 if ( a & ATTR_FILE_DATAALLOCSIZE ) {
1382 searchInfo->f.dataPhysicalLength = *((off_t *)attributeBuffer);
1383 attributeBuffer = (off_t *)attributeBuffer + 1;
1384 }
1385 if ( a & ATTR_FILE_RSRCLENGTH ) {
1386 searchInfo->f.resourceLogicalLength = *((off_t *)attributeBuffer);
1387 attributeBuffer = (off_t *)attributeBuffer + 1;
1388 }
1389 if ( a & ATTR_FILE_RSRCALLOCSIZE ) {
1390 searchInfo->f.resourcePhysicalLength = *((off_t *)attributeBuffer);
1391 attributeBuffer = (off_t *)attributeBuffer + 1;
1392 }
1393 }
1394
1395 return (0);
1396 }
1397 #endif /* CONFIG_SEARCHFS */