+
+ catalogFCB = GetFileControlBlock(vcb->catalogRefNum);
+ myCurrentKeyPtr = NULL;
+ myCurrentDataPtr = NULL;
+ myCatPositionPtr = (CatPosition *)ap->a_searchstate;
+
+ if (ap->a_options & SRCHFS_START) {
+ /* Starting a new search. */
+ /* Make sure the on-disk Catalog file is current */
+ (void) VOP_FSYNC(vcb->catalogRefNum, NOCRED, MNT_WAIT, p);
+ if (VTOHFS(ap->a_vp)->jnl) {
+ journal_flush(VTOHFS(ap->a_vp)->jnl);
+ }
+
+ ap->a_options &= ~SRCHFS_START;
+ bzero( (caddr_t)myCatPositionPtr, sizeof( *myCatPositionPtr ) );
+ err = BTScanInitialize(catalogFCB, 0, 0, 0, kCatSearchBufferSize, &myBTScanState);
+
+#if 1 // Installer workaround (2940423)
+ // hack to get around installer problems when the installer expects search results
+ // to be in key order. At this point the problem appears to be limited to
+ // searches for "Library". The idea here is to go get the "Library" at root
+ // and return it first to the caller then continue the search as normal with
+ // the exception of taking care not to return a duplicate hit (see CheckCriteria)
+ if ( err == E_NONE &&
+ (ap->a_searchattrs->commonattr & ATTR_CMN_NAME) != 0 &&
+ IsTargetName( &searchInfo1, isHFSPlus ) )
+ {
+ CatalogRecord rec;
+ BTreeIterator iterator;
+ FSBufferDescriptor btrec;
+ CatalogKey * keyp;
+ UInt16 reclen;
+ OSErr result;
+
+ bzero( (caddr_t)&iterator, sizeof( iterator ) );
+ keyp = (CatalogKey *) &iterator.key;
+ (void) BuildCatalogKeyUTF8(vcb, kRootDirID, "Library", kUndefinedStrLen, keyp, NULL);
+
+ btrec.bufferAddress = &rec;
+ btrec.itemCount = 1;
+ btrec.itemSize = sizeof( rec );
+
+ result = BTSearchRecord( catalogFCB, &iterator, &btrec, &reclen, &iterator );
+ if ( result == E_NONE ) {
+ if (CheckCriteria(vcb, ap->a_options, ap->a_searchattrs, &rec,
+ keyp, &searchInfo1, &searchInfo2, false) &&
+ CheckAccess(vcb, ap->a_options, keyp, ap->a_uio->uio_procp)) {
+
+ result = InsertMatch(ap->a_vp, ap->a_uio, &rec,
+ keyp, ap->a_returnattrs,
+ attributesBuffer, variableBuffer,
+ eachReturnBufferSize, ap->a_nummatches);
+ if (result == E_NONE && *(ap->a_nummatches) >= ap->a_maxmatches)
+ doQuickExit = true;
+ }
+ }
+ }
+#endif // Installer workaround
+ } else {
+ /* Resuming a search. */
+ err = BTScanInitialize(catalogFCB, myCatPositionPtr->nextNode,
+ myCatPositionPtr->nextRecord,
+ myCatPositionPtr->recordsFound,
+ kCatSearchBufferSize,
+ &myBTScanState);
+ /* Make sure Catalog hasn't changed. */
+ if (err == 0
+ && myCatPositionPtr->writeCount != myBTScanState.btcb->writeCount) {
+ myCatPositionPtr->writeCount = myBTScanState.btcb->writeCount;
+ err = EBUSY; /* catChangedErr */
+ }
+ }
+
+ /* Unlock catalog b-tree */
+ (void) hfs_metafilelocking(VTOHFS(ap->a_vp), kHFSCatalogFileID, LK_RELEASE, p);
+ if (err)
+ goto ExitThisRoutine;
+#if 1 // Installer workaround (2940423)
+ if ( doQuickExit )
+ goto QuickExit;
+#endif // Installer workaround