/*
- * Copyright (c) 1997-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 1997-2013 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <sys/utfconv.h>
#include <sys/kauth.h>
#include <sys/vnode_internal.h>
+#include <sys/mount_internal.h>
#if CONFIG_MACF
#include <security/mac_framework.h>
#include "hfscommon/headers/BTreeScanner.h"
#include "hfscommon/headers/CatalogPrivate.h"
+#if CONFIG_SEARCHFS
+
/* Search criterea. */
struct directoryInfoSpec
{
struct searchinfospec
{
u_char name[kHFSPlusMaxFileNameBytes];
- u_long nameLength;
+ u_int32_t nameLength;
char attributes; // see IM:Files 2-100
- u_long nodeID;
- u_long parentDirID;
+ u_int32_t nodeID;
+ u_int32_t parentDirID;
struct timespec creationDate;
struct timespec modificationDate;
struct timespec changeDate;
static int UnpackSearchAttributeBlock(struct hfsmount *hfsmp, struct attrlist *alist,
- searchinfospec_t *searchInfo, void *attributeBuffer);
+ searchinfospec_t *searchInfo, void *attributeBuffer, int firstblock);
static int CheckCriteria( ExtendedVCB *vcb,
u_long searchBits,
CatalogRecord *rec,
CatalogKey *key,
searchinfospec_t *searchInfo1,
- searchinfospec_t *searchInfo2 );
+ searchinfospec_t *searchInfo2,
+ struct vfs_context *ctx);
static int CheckAccess(ExtendedVCB *vcb, u_long searchBits, CatalogKey *key, struct vfs_context *ctx);
static int InsertMatch(struct hfsmount *hfsmp, uio_t a_uio, CatalogRecord *rec,
CatalogKey *key, struct attrlist *returnAttrList,
void *attributesBuffer, void *variableBuffer,
- u_long * nummatches );
+ uint32_t * nummatches );
static Boolean CompareRange(u_long val, u_long low, u_long high);
static Boolean CompareWideRange(u_int64_t val, u_int64_t low, u_int64_t high);
};
*/
-__private_extern__
int
hfs_vnop_search(ap)
struct vnop_searchfs_args *ap; /*
FCB * catalogFCB;
searchinfospec_t searchInfo1;
searchinfospec_t searchInfo2;
- void *attributesBuffer;
+ void *attributesBuffer = NULL;
void *variableBuffer;
- u_long fixedBlockSize;
- u_long eachReturnBufferSize;
+ u_int32_t fixedBlockSize;
+ u_int32_t eachReturnBufferSize;
struct proc *p = current_proc();
int err = E_NONE;
int isHFSPlus;
- int timerExpired = false;
CatalogKey * myCurrentKeyPtr;
CatalogRecord * myCurrentDataPtr;
CatPosition * myCatPositionPtr;
user_size_t user_len = 0;
int32_t searchTime;
int lockflags;
+ struct uthread *ut;
+ boolean_t timerExpired = FALSE;
+ boolean_t needThrottle = FALSE;
/* XXX Parameter check a_searchattrs? */
*(ap->a_nummatches) = 0;
- if (ap->a_options & ~SRCHFS_VALIDOPTIONSMASK)
+ if (ap->a_options & ~SRCHFS_VALIDOPTIONSMASK) {
return (EINVAL);
+ }
/*
- * Reject requests for unsupported attributes.
+ * Fail requests for attributes that HFS does not support for the
+ * items that match the search criteria. Note that these checks
+ * are for the OUTBOUND attributes to be returned (not search criteria).
*/
if ((ap->a_returnattrs->commonattr & ~HFS_ATTR_CMN_VALID) ||
(ap->a_returnattrs->volattr != 0) ||
(ap->a_returnattrs->dirattr & ~HFS_ATTR_DIR_VALID) ||
(ap->a_returnattrs->fileattr & ~HFS_ATTR_FILE_VALID) ||
(ap->a_returnattrs->forkattr != 0)) {
+
return (EINVAL);
}
attrgroup_t attrs;
attrs = ap->a_searchattrs->commonattr | ap->a_returnattrs->commonattr;
- if (attrs & (ATTR_CMN_NAME | ATTR_CMN_PAROBJID))
+ if (attrs & (ATTR_CMN_NAME | ATTR_CMN_PAROBJID)) {
return (EINVAL);
- if ((err = vfs_context_suser(ap->a_context)))
+ }
+
+ if ((err = vfs_context_suser(ap->a_context))) {
return (err);
+ }
}
// If both 32-bit and 64-bit parent ids or file ids are given
attrgroup_t test_attrs=ap->a_searchattrs->commonattr;
if (((test_attrs & ATTR_CMN_OBJID) && (test_attrs & ATTR_CMN_FILEID)) ||
- ((test_attrs & ATTR_CMN_PARENTID) && (test_attrs & ATTR_CMN_PAROBJID)))
+ ((test_attrs & ATTR_CMN_PARENTID) && (test_attrs & ATTR_CMN_PAROBJID))) {
return (EINVAL);
+ }
-
- if (uio_resid(ap->a_uio) <= 0)
+ if (uio_resid(ap->a_uio) <= 0) {
return (EINVAL);
+ }
isHFSPlus = (vcb->vcbSigWord == kHFSPlusSigWord);
hfsmp = VTOHFS(ap->a_vp);
/* UnPack the search boundries, searchInfo1, searchInfo2 */
err = UnpackSearchAttributeBlock(hfsmp, ap->a_searchattrs,
- &searchInfo1, ap->a_searchparams1);
- if (err) return err;
+ &searchInfo1, ap->a_searchparams1, 1);
+ if (err) {
+ return err;
+ }
err = UnpackSearchAttributeBlock(hfsmp, ap->a_searchattrs,
- &searchInfo2, ap->a_searchparams2);
- if (err) return err;
-
+ &searchInfo2, ap->a_searchparams2, 0);
+ if (err) {
+ return err;
+ }
//shadow search bits if 64-bit file/parent ids are used
if (ap->a_searchattrs->commonattr & ATTR_CMN_FILEID)
ap->a_searchattrs->commonattr |= ATTR_CMN_OBJID;
eachReturnBufferSize += kHFSPlusMaxFileNameBytes + 1;
MALLOC( attributesBuffer, void *, eachReturnBufferSize, M_TEMP, M_WAITOK );
+ if (attributesBuffer == NULL) {
+ err = ENOMEM;
+ goto ExitThisRoutine;
+ }
+ bzero(attributesBuffer, eachReturnBufferSize);
variableBuffer = (void*)((char*) attributesBuffer + fixedBlockSize);
// XXXdbg - have to lock the user's buffer so we don't fault
(void) hfs_fsync(vcb->catalogRefNum, MNT_WAIT, 0, p);
if (hfsmp->jnl) {
hfs_systemfile_unlock(hfsmp, lockflags);
- journal_flush(hfsmp->jnl);
+ hfs_journal_flush(hfsmp, FALSE);
lockflags = hfs_systemfile_lock(hfsmp, SFL_CATALOG, HFS_SHARED_LOCK);
}
if (err)
goto ExitThisRoutine;
+ if (throttle_get_io_policy(&ut) == IOPOL_THROTTLE)
+ needThrottle = TRUE;
/*
* Check all the catalog btree records...
* return the attributes for matching items
ResolveHardlink(vcb, (HFSPlusCatalogFile *)myCurrentDataPtr);
}
if (CheckCriteria( vcb, ap->a_options, ap->a_searchattrs, myCurrentDataPtr,
- myCurrentKeyPtr, &searchInfo1, &searchInfo2 )
+ myCurrentKeyPtr, &searchInfo1, &searchInfo2, ap->a_context )
&& CheckAccess(vcb, ap->a_options, myCurrentKeyPtr, ap->a_context)) {
err = InsertMatch(hfsmp, ap->a_uio, myCurrentDataPtr,
myCurrentKeyPtr, ap->a_returnattrs,
if (*(ap->a_nummatches) >= ap->a_maxmatches)
break;
}
-
- /*
- * Check our elapsed time and bail if we've hit the max.
- * The idea here is to throttle the amount of time we
- * spend in the kernel.
- */
- microuptime(&myCurrentTime);
- timersub(&myCurrentTime, &myBTScanState.startTime, &myElapsedTime);
- /* Note: assumes kMaxMicroSecsInKernel is less than 1,000,000 */
- if (myElapsedTime.tv_sec > 0
- || myElapsedTime.tv_usec >= searchTime) {
- timerExpired = true;
+ if (timerExpired == FALSE) {
+ /*
+ * Check our elapsed time and bail if we've hit the max.
+ * The idea here is to throttle the amount of time we
+ * spend in the kernel.
+ */
+ microuptime(&myCurrentTime);
+ timersub(&myCurrentTime, &myBTScanState.startTime, &myElapsedTime);
+ /*
+ * Note: assumes kMaxMicroSecsInKernel is less than 1,000,000
+ */
+ if (myElapsedTime.tv_sec > 0
+ || myElapsedTime.tv_usec >= searchTime) {
+ timerExpired = TRUE;
+ } else if (needThrottle == TRUE) {
+ if (throttle_io_will_be_throttled(ut->uu_lowpri_window, HFSTOVFS(hfsmp)))
+ timerExpired = TRUE;
+ }
}
}
}
ExitThisRoutine:
- FREE( attributesBuffer, M_TEMP );
+ if (attributesBuffer)
+ FREE(attributesBuffer, M_TEMP);
- if (hfsmp->jnl && user_start) {
+ if (user_start) {
vsunlock(user_start, user_len, TRUE);
}
filecreatedate = to_bsd_time(recp->createDate);
if ((type == kHardLinkFileType && creator == kHFSPlusCreator) &&
- (filecreatedate == (time_t)hfsmp->vcbCrDate ||
+ (filecreatedate == (time_t)hfsmp->hfs_itime ||
filecreatedate == (time_t)hfsmp->hfs_metadata_createdate)) {
isfilelink = 1;
} else if ((type == kHFSAliasType && creator == kHFSAliasCreator) &&
(recp->flags & kHFSHasLinkChainMask) &&
- (filecreatedate == (time_t)hfsmp->vcbCrDate ||
+ (filecreatedate == (time_t)hfsmp->hfs_itime ||
filecreatedate == (time_t)hfsmp->hfs_metadata_createdate)) {
isdirlink = 1;
}
static Boolean
ComparePartialUnicodeName (register ConstUniCharArrayPtr str, register ItemCount s_len,
- register ConstUniCharArrayPtr find, register ItemCount f_len )
+ register ConstUniCharArrayPtr find, register ItemCount f_len, int caseSensitive )
{
- if (f_len == 0 || s_len == 0)
+ if (f_len == 0 || s_len == 0) {
return FALSE;
+ }
- do {
- if (s_len-- < f_len)
- return FALSE;
- } while (FastUnicodeCompare(str++, f_len, find, f_len) != 0);
+ if (caseSensitive) {
+ do {
+ if (s_len-- < f_len)
+ return FALSE;
+ } while (UnicodeBinaryCompare(str++, f_len, find, f_len) != 0);
+ }
+ else {
+ do {
+ if (s_len-- < f_len)
+ return FALSE;
+ } while (FastUnicodeCompare(str++, f_len, find, f_len) != 0);
+ }
return TRUE;
}
-
+#if CONFIG_HFS_STD
static Boolean
ComparePartialPascalName ( register ConstStr31Param str, register ConstStr31Param find )
{
return FALSE;
}
-
-
-//
-// Determine if a name is "inappropriate" where the definition
-// of "inappropriate" is up to higher level execs. Currently
-// that's limited to /System.
-//
-static int
-is_inappropriate_name(const char *name, int len)
-{
- const char *bad_names[] = { "System" };
- int bad_len[] = { 6 };
- int i;
-
- for(i=0; i < (int) (sizeof(bad_names) / sizeof(bad_names[0])); i++) {
- if (len == bad_len[i] && strncmp(name, bad_names[i], strlen(bad_names[i]) + 1) == 0) {
- return 1;
- }
- }
-
- // if we get here, no name matched
- return 0;
-}
-
+#endif
/*
isHFSPlus = ( theVCBPtr->vcbSigWord == kHFSPlusSigWord );
if ( isHFSPlus )
myNodeID = theKeyPtr->hfsPlus.parentID;
+#if CONFIG_HFS_STD
else
myNodeID = theKeyPtr->hfs.parentID;
+#endif
while ( myNodeID >= kRootDirID ) {
cnode_t * cp;
/* now go get catalog data for this directory */
- myErr = hfs_vget(hfsmp, myNodeID, &vp, 0);
+ myErr = hfs_vget(hfsmp, myNodeID, &vp, 0, 0);
if ( myErr ) {
goto ExitThisRoutine; /* no access */
}
if ( searchBits & SRCHFS_SKIPINAPPROPRIATE ) {
if ( cp->c_parentcnid == kRootDirID && cp->c_desc.cd_nameptr != NULL &&
- is_inappropriate_name((const char *)cp->c_desc.cd_nameptr, cp->c_desc.cd_namelen) ) {
+ vn_searchfs_inappropriate_name((const char *)cp->c_desc.cd_nameptr, cp->c_desc.cd_namelen) ) {
myResult = 0;
goto ExitThisRoutine;
}
CatalogRecord *rec,
CatalogKey *key,
searchinfospec_t *searchInfo1,
- searchinfospec_t *searchInfo2 )
+ searchinfospec_t *searchInfo2,
+ struct vfs_context *ctx)
{
Boolean matched, atleastone;
Boolean isHFSPlus;
struct cat_attr c_attr;
struct cat_fork datafork;
struct cat_fork rsrcfork;
+ int force_case_sensitivity = proc_is_forcing_hfs_case_sensitivity(vfs_context_proc(ctx));
bzero(&c_attr, sizeof(c_attr));
isHFSPlus = (vcb->vcbSigWord == kHFSPlusSigWord);
switch (rec->recordType) {
- case kHFSFolderRecord:
- case kHFSPlusFolderRecord:
- if ( (searchBits & SRCHFS_MATCHDIRS) == 0 ) { /* If we are NOT searching folders */
- matched = false;
- goto TestDone;
- }
- break;
-
- case kHFSFileRecord:
- if ( (searchBits & SRCHFS_MATCHFILES) == 0 ) { /* If we are NOT searching files */
- matched = false;
- goto TestDone;
- }
- break;
-
- case kHFSPlusFileRecord:
- /* Check if hardlink links should be skipped. */
- if (searchBits & SRCHFS_SKIPLINKS) {
- cnid_t parid = key->hfsPlus.parentID;
- HFSPlusCatalogFile *filep = (HFSPlusCatalogFile *)rec;
-
- if ((SWAP_BE32(filep->userInfo.fdType) == kHardLinkFileType) &&
- (SWAP_BE32(filep->userInfo.fdCreator) == kHFSPlusCreator)) {
- return (false); /* skip over file link records */
- } else if ((parid == vcb->hfs_private_desc[FILE_HARDLINKS].cd_cnid) &&
- (filep->bsdInfo.special.linkCount == 0)) {
- return (false); /* skip over unlinked files */
- } else if ((SWAP_BE32(filep->userInfo.fdType) == kHFSAliasType) &&
- (SWAP_BE32(filep->userInfo.fdCreator) == kHFSAliasCreator) &&
- (filep->flags & kHFSHasLinkChainMask)) {
- return (false); /* skip over dir link records */
+
+#if CONFIG_HFS_STD
+ case kHFSFolderRecord:
+ if ( (searchBits & SRCHFS_MATCHDIRS) == 0 ) { /* If we are NOT searching folders */
+ matched = false;
+ goto TestDone;
}
- } else if (key->hfsPlus.parentID == vcb->hfs_private_desc[FILE_HARDLINKS].cd_cnid) {
- return (false); /* skip over private files */
- } else if (key->hfsPlus.parentID == vcb->hfs_private_desc[DIR_HARDLINKS].cd_cnid) {
- return (false); /* skip over private files */
- }
+ break;
- if ( (searchBits & SRCHFS_MATCHFILES) == 0 ) { /* If we are NOT searching files */
- matched = false;
- goto TestDone;
- }
- break;
+ case kHFSFileRecord:
+ if ( (searchBits & SRCHFS_MATCHFILES) == 0 ) { /* If we are NOT searching files */
+ matched = false;
+ goto TestDone;
+ }
+ break;
+#endif
+
+ case kHFSPlusFolderRecord:
+ if ( (searchBits & SRCHFS_MATCHDIRS) == 0 ) { /* If we are NOT searching folders */
+ matched = false;
+ goto TestDone;
+ }
+ break;
- default: /* Never match a thread record or any other type. */
- return( false ); /* Not a file or folder record, so can't search it */
+ case kHFSPlusFileRecord:
+ /* Check if hardlink links should be skipped. */
+ if (searchBits & SRCHFS_SKIPLINKS) {
+ cnid_t parid = key->hfsPlus.parentID;
+ HFSPlusCatalogFile *filep = (HFSPlusCatalogFile *)rec;
+
+ if ((SWAP_BE32(filep->userInfo.fdType) == kHardLinkFileType) &&
+ (SWAP_BE32(filep->userInfo.fdCreator) == kHFSPlusCreator)) {
+ return (false); /* skip over file link records */
+ } else if ((parid == vcb->hfs_private_desc[FILE_HARDLINKS].cd_cnid) &&
+ (filep->bsdInfo.special.linkCount == 0)) {
+ return (false); /* skip over unlinked files */
+ } else if ((SWAP_BE32(filep->userInfo.fdType) == kHFSAliasType) &&
+ (SWAP_BE32(filep->userInfo.fdCreator) == kHFSAliasCreator) &&
+ (filep->flags & kHFSHasLinkChainMask)) {
+ return (false); /* skip over dir link records */
+ }
+ } else if (key->hfsPlus.parentID == vcb->hfs_private_desc[FILE_HARDLINKS].cd_cnid) {
+ return (false); /* skip over private files */
+ } else if (key->hfsPlus.parentID == vcb->hfs_private_desc[DIR_HARDLINKS].cd_cnid) {
+ return (false); /* skip over private files */
+ }
+
+ if ( (searchBits & SRCHFS_MATCHFILES) == 0 ) { /* If we are NOT searching files */
+ matched = false;
+ goto TestDone;
+ }
+ break;
+
+ default: /* Never match a thread record or any other type. */
+ return( false ); /* Not a file or folder record, so can't search it */
}
matched = true; /* Assume we got a match */
/* First, attempt to match the name -- either partial or complete */
if ( attrList->commonattr & ATTR_CMN_NAME ) {
if (isHFSPlus) {
+ int case_sensitive = 0;
+
+ /*
+ * Longstanding default behavior here is to use a non-case-sensitive
+ * search, even on case-sensitive filesystems.
+ *
+ * We only force case sensitivity if the controlling process has explicitly
+ * asked for it in the proc flags, and only if they are not doing
+ * a partial name match. Consider that if you are doing a partial
+ * name match ("all files that begin with 'image'"), the likelihood is
+ * high that you would want to see all matches, even those that do not
+ * explicitly match the case.
+ */
+ if (force_case_sensitivity) {
+ case_sensitive = 1;
+ }
+
/* Check for partial/full HFS Plus name match */
if ( searchBits & SRCHFS_MATCHPARTIALNAMES ) {
+ /* always use a case-INSENSITIVE search here */
matched = ComparePartialUnicodeName(key->hfsPlus.nodeName.unicode,
key->hfsPlus.nodeName.length,
(UniChar*)searchInfo1->name,
- searchInfo1->nameLength );
- } else /* full HFS Plus name match */ {
- matched = (FastUnicodeCompare(key->hfsPlus.nodeName.unicode,
- key->hfsPlus.nodeName.length,
- (UniChar*)searchInfo1->name,
- searchInfo1->nameLength ) == 0);
+ searchInfo1->nameLength, 0);
+ }
+ else {
+ /* Full name match. Are we HFSX (case sensitive) or HFS+ ? */
+ if (case_sensitive) {
+ matched = (UnicodeBinaryCompare(key->hfsPlus.nodeName.unicode,
+ key->hfsPlus.nodeName.length,
+ (UniChar*)searchInfo1->name,
+ searchInfo1->nameLength ) == 0);
+ }
+ else {
+ matched = (FastUnicodeCompare(key->hfsPlus.nodeName.unicode,
+ key->hfsPlus.nodeName.length,
+ (UniChar*)searchInfo1->name,
+ searchInfo1->nameLength ) == 0);
+ }
}
- } else {
+ }
+#if CONFIG_HFS_STD
+ else {
/* Check for partial/full HFS name match */
if ( searchBits & SRCHFS_MATCHPARTIALNAMES )
else /* full HFS name match */
matched = (FastRelString(key->hfs.nodeName, (u_char*)searchInfo1->name) == 0);
}
+#endif
if ( matched == false || (searchBits & ~SRCHFS_MATCHPARTIALNAMES) == 0 )
goto TestDone; /* no match, or nothing more to compare */
int flags;
switch (rec->recordType) {
- case kHFSFolderRecord:
- case kHFSPlusFolderRecord: {
- struct FndrDirInfo *finder_info;
-
- finder_info = (struct FndrDirInfo *)&c_attr.ca_finderinfo[0];
- flags = SWAP_BE16(finder_info->frFlags);
- break;
- }
-
- case kHFSFileRecord:
- case kHFSPlusFileRecord: {
- struct FndrFileInfo *finder_info;
-
- finder_info = (struct FndrFileInfo *)&c_attr.ca_finderinfo[0];
- flags = SWAP_BE16(finder_info->fdFlags);
- break;
+#if CONFIG_HFS_STD
+ case kHFSFolderRecord:
+ {
+ struct FndrDirInfo *finder_info;
+
+ finder_info = (struct FndrDirInfo *)&c_attr.ca_finderinfo[0];
+ flags = SWAP_BE16(finder_info->frFlags);
+ break;
+ }
+
+ case kHFSFileRecord:
+ {
+ struct FndrFileInfo *finder_info;
+
+ finder_info = (struct FndrFileInfo *)&c_attr.ca_finderinfo[0];
+ flags = SWAP_BE16(finder_info->fdFlags);
+ break;
+ }
+#endif
+
+ case kHFSPlusFolderRecord:
+ {
+ struct FndrDirInfo *finder_info;
+
+ finder_info = (struct FndrDirInfo *)&c_attr.ca_finderinfo[0];
+ flags = SWAP_BE16(finder_info->frFlags);
+ break;
+ }
+
+ case kHFSPlusFileRecord:
+ {
+ struct FndrFileInfo *finder_info;
+
+ finder_info = (struct FndrFileInfo *)&c_attr.ca_finderinfo[0];
+ flags = SWAP_BE16(finder_info->fdFlags);
+ break;
+ }
+
+ default:
+ {
+ flags = kIsInvisible;
+ break;
+ }
}
- default: {
- flags = kIsInvisible;
- break;
+ if (flags & kIsInvisible) {
+ matched = false;
+ goto TestDone;
}
- }
-
- if (flags & kIsInvisible) {
- matched = false;
- goto TestDone;
- }
}
/* Now that we have a record worth searching, see if it matches the search attributes */
+#if CONFIG_HFS_STD
if (rec->recordType == kHFSFileRecord ||
rec->recordType == kHFSPlusFileRecord) {
+#else
+ if (rec->recordType == kHFSPlusFileRecord) {
+#endif
+
if ((attrList->fileattr & ~ATTR_FILE_VALIDMASK) != 0) { /* attr we do know about */
matched = false;
goto TestDone;
}
else if ((attrList->fileattr & ATTR_FILE_VALIDMASK) != 0) {
searchAttributes = attrList->fileattr;
-
+
+#if HFS_COMPRESSION
+ if ( c_attr.ca_flags & UF_COMPRESSED ) {
+ /* for compressed files, set the data length to the uncompressed data size */
+ if (( searchAttributes & ATTR_FILE_DATALENGTH ) ||
+ ( searchAttributes & ATTR_FILE_DATAALLOCSIZE ) ) {
+ 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 */
+ datafork.cf_blocks = rsrcfork.cf_blocks;
+ }
+ }
+ /* treat compressed files as if their resource fork is empty */
+ if (( searchAttributes & ATTR_FILE_RSRCLENGTH ) ||
+ ( searchAttributes & ATTR_FILE_RSRCALLOCSIZE ) ) {
+ rsrcfork.cf_size = 0;
+ rsrcfork.cf_blocks = 0;
+ }
+ }
+#endif /* HFS_COMPRESSION */
+
/* File logical length (data fork) */
if ( searchAttributes & ATTR_FILE_DATALENGTH ) {
matched = CompareWideRange(
/*
* Check the directory attributes
*/
+#if CONFIG_HFS_STD
else if (rec->recordType == kHFSFolderRecord ||
rec->recordType == kHFSPlusFolderRecord) {
+#else
+ else if (rec->recordType == kHFSPlusFolderRecord) {
+#endif
if ((attrList->dirattr & ~ATTR_DIR_VALIDMASK) != 0) { /* attr we do know about */
matched = false;
goto TestDone;
if (isHFSPlus)
parentID = key->hfsPlus.parentID;
+#if CONFIG_HFS_STD
else
parentID = key->hfs.parentID;
+#endif
matched = CompareRange(parentID, searchInfo1->parentDirID,
searchInfo2->parentDirID );
static int
InsertMatch(struct hfsmount *hfsmp, uio_t a_uio, CatalogRecord *rec,
CatalogKey *key, struct attrlist *returnAttrList,
- void *attributesBuffer, void *variableBuffer, u_long * nummatches)
+ void *attributesBuffer, void *variableBuffer, uint32_t * nummatches)
{
int err;
void *rovingAttributesBuffer;
void *rovingVariableBuffer;
- u_long packedBufferSize;
+ long packedBufferSize;
struct attrblock attrblk;
struct cat_desc c_desc;
struct cat_attr c_attr;
bzero(&c_desc, sizeof(c_desc));
bzero(&c_attr, sizeof(c_attr));
- rovingAttributesBuffer = (char*)attributesBuffer + sizeof(u_long); /* Reserve space for length field */
+ rovingAttributesBuffer = (char*)attributesBuffer + sizeof(u_int32_t); /* Reserve space for length field */
rovingVariableBuffer = variableBuffer;
/* Convert catalog record into cat_attr format. */
}
if (returnAttrList->commonattr & ATTR_CMN_NAME) {
- cat_convertkey(hfsmp, key, rec, &c_desc);
+ err = cat_convertkey(hfsmp, key, rec, &c_desc);
+ if (err) {
+ /* This means that we probably had a CNID error */
+ goto exit;
+ }
} else {
c_desc.cd_cnid = c_attr.ca_fileid;
- if (hfsmp->hfs_flags & HFS_STANDARD)
- c_desc.cd_parentcnid = key->hfs.parentID;
- else
+ if ((hfsmp->hfs_flags & HFS_STANDARD) == 0)
c_desc.cd_parentcnid = key->hfsPlus.parentID;
+#if CONFIG_HFS_STD
+ else
+ c_desc.cd_parentcnid = key->hfs.parentID;
+#endif
+
}
attrblk.ab_attrlist = returnAttrList;
attrblk.ab_blocksize = 0;
attrblk.ab_context = vfs_context_current();
- hfs_packattrblk(&attrblk, hfsmp, NULL, &c_desc, &c_attr, &datafork, &rsrcfork, current_proc());
+ hfs_packattrblk(&attrblk, hfsmp, NULL, &c_desc, &c_attr, &datafork, &rsrcfork, vfs_context_current());
packedBufferSize = (char*)rovingVariableBuffer - (char*)attributesBuffer;
(* nummatches)++;
- *((u_long *)attributesBuffer) = packedBufferSize; /* Store length of fixed + var block */
+ *((u_int32_t *)attributesBuffer) = packedBufferSize; /* Store length of fixed + var block */
- err = uiomove( (caddr_t)attributesBuffer, packedBufferSize, a_uio ); /* XXX should be packedBufferSize */
+ err = uiomove( (caddr_t)attributesBuffer, packedBufferSize, a_uio );
exit:
cat_releasedesc(&c_desc);
static int
-UnpackSearchAttributeBlock( struct hfsmount *hfsmp, struct attrlist *alist, searchinfospec_t *searchInfo, void *attributeBuffer )
+UnpackSearchAttributeBlock( struct hfsmount *hfsmp, struct attrlist *alist,
+ searchinfospec_t *searchInfo, void *attributeBuffer, int firstblock)
{
attrgroup_t a;
- u_long bufferSize;
+ u_int32_t bufferSize;
boolean_t is_64_bit;
DBG_ASSERT(searchInfo != NULL);
a = alist->commonattr;
if ( a != 0 ) {
if ( a & ATTR_CMN_NAME ) {
- char *s;
- u_int32_t len;
+ if (firstblock) {
+ /* Only use the attrreference_t for the first searchparams */
+ char *s;
+ u_int32_t len;
+
+ s = (char*) attributeBuffer + ((attrreference_t *) attributeBuffer)->attr_dataoffset;
+ len = ((attrreference_t *) attributeBuffer)->attr_length;
- s = (char*) attributeBuffer + ((attrreference_t *) attributeBuffer)->attr_dataoffset;
- len = ((attrreference_t *) attributeBuffer)->attr_length;
+ if (len > sizeof(searchInfo->name))
+ return (EINVAL);
- if (len > sizeof(searchInfo->name))
- return (EINVAL);
- if (hfsmp->hfs_flags & HFS_STANDARD) {
- /* Convert name to pascal string to match HFS B-Tree names */
+ if ((hfsmp->hfs_flags & HFS_STANDARD) == 0) {
+ size_t ucslen;
+ /* Convert name to Unicode to match HFS Plus B-Tree names */
- if (len > 0) {
- if (utf8_to_hfs(HFSTOVCB(hfsmp), len-1, (u_char *)s, (u_char*)searchInfo->name) != 0)
- return (EINVAL);
+ if (len > 0) {
+ if (utf8_decodestr((u_int8_t *)s, len-1, (UniChar*)searchInfo->name, &ucslen,
+ sizeof(searchInfo->name), ':', UTF_DECOMPOSED | UTF_ESCAPE_ILLEGAL))
+ return (EINVAL);
- searchInfo->nameLength = searchInfo->name[0];
- } else {
- searchInfo->name[0] = searchInfo->nameLength = 0;
+ searchInfo->nameLength = ucslen / sizeof(UniChar);
+ } else {
+ searchInfo->nameLength = 0;
+ }
}
- attributeBuffer = (attrreference_t *)attributeBuffer + 1;
- } else {
- size_t ucslen;
- /* Convert name to Unicode to match HFS Plus B-Tree names */
-
- if (len > 0) {
- if (utf8_decodestr((u_int8_t *)s, len-1, (UniChar*)searchInfo->name, &ucslen,
- sizeof(searchInfo->name), ':', UTF_DECOMPOSED | UTF_ESCAPE_ILLEGAL))
- return (EINVAL);
-
- searchInfo->nameLength = ucslen / sizeof(UniChar);
- } else {
- searchInfo->nameLength = 0;
+#if CONFIG_HFS_STD
+ else {
+ /* Convert name to pascal string to match HFS (Standard) B-Tree names */
+
+ if (len > 0) {
+ if (utf8_to_hfs(HFSTOVCB(hfsmp), len-1, (u_char *)s, (u_char*)searchInfo->name) != 0)
+ return (EINVAL);
+
+ searchInfo->nameLength = searchInfo->name[0];
+ } else {
+ searchInfo->name[0] = searchInfo->nameLength = 0;
+ }
}
- attributeBuffer = (attrreference_t *)attributeBuffer + 1;
+#endif
}
+ attributeBuffer = (attrreference_t*) attributeBuffer +1;
}
if ( a & ATTR_CMN_OBJID ) {
searchInfo->nodeID = ((fsobj_id_t *) attributeBuffer)->fid_objno; /* ignore fid_generation */
if ( a & ATTR_CMN_CRTIME ) {
if (is_64_bit) {
- struct user_timespec tmp;
- tmp = *((struct user_timespec *)attributeBuffer);
+ struct user64_timespec tmp;
+ tmp = *((struct user64_timespec *)attributeBuffer);
searchInfo->creationDate.tv_sec = (time_t)tmp.tv_sec;
searchInfo->creationDate.tv_nsec = tmp.tv_nsec;
- attributeBuffer = (struct user_timespec *)attributeBuffer + 1;
+ attributeBuffer = (struct user64_timespec *)attributeBuffer + 1;
}
else {
- searchInfo->creationDate = *((struct timespec *)attributeBuffer);
- attributeBuffer = (struct timespec *)attributeBuffer + 1;
+ struct user32_timespec tmp;
+ tmp = *((struct user32_timespec *)attributeBuffer);
+ searchInfo->creationDate.tv_sec = (time_t)tmp.tv_sec;
+ searchInfo->creationDate.tv_nsec = tmp.tv_nsec;
+ attributeBuffer = (struct user32_timespec *)attributeBuffer + 1;
}
}
if ( a & ATTR_CMN_MODTIME ) {
if (is_64_bit) {
- struct user_timespec tmp;
- tmp = *((struct user_timespec *)attributeBuffer);
+ struct user64_timespec tmp;
+ tmp = *((struct user64_timespec *)attributeBuffer);
searchInfo->modificationDate.tv_sec = (time_t)tmp.tv_sec;
searchInfo->modificationDate.tv_nsec = tmp.tv_nsec;
- attributeBuffer = (struct user_timespec *)attributeBuffer + 1;
+ attributeBuffer = (struct user64_timespec *)attributeBuffer + 1;
}
else {
- searchInfo->modificationDate = *((struct timespec *)attributeBuffer);
- attributeBuffer = (struct timespec *)attributeBuffer + 1;
+ struct user32_timespec tmp;
+ tmp = *((struct user32_timespec *)attributeBuffer);
+ searchInfo->modificationDate.tv_sec = (time_t)tmp.tv_sec;
+ searchInfo->modificationDate.tv_nsec = tmp.tv_nsec;
+ attributeBuffer = (struct user32_timespec *)attributeBuffer + 1;
}
}
if ( a & ATTR_CMN_CHGTIME ) {
if (is_64_bit) {
- struct user_timespec tmp;
- tmp = *((struct user_timespec *)attributeBuffer);
+ struct user64_timespec tmp;
+ tmp = *((struct user64_timespec *)attributeBuffer);
searchInfo->changeDate.tv_sec = (time_t)tmp.tv_sec;
searchInfo->changeDate.tv_nsec = tmp.tv_nsec;
- attributeBuffer = (struct user_timespec *)attributeBuffer + 1;
+ attributeBuffer = (struct user64_timespec *)attributeBuffer + 1;
}
else {
- searchInfo->changeDate = *((struct timespec *)attributeBuffer);
- attributeBuffer = (struct timespec *)attributeBuffer + 1;
+ struct user32_timespec tmp;
+ tmp = *((struct user32_timespec *)attributeBuffer);
+ searchInfo->changeDate.tv_sec = (time_t)tmp.tv_sec;
+ searchInfo->changeDate.tv_nsec = tmp.tv_nsec;
+ attributeBuffer = (struct user32_timespec *)attributeBuffer + 1;
}
}
if ( a & ATTR_CMN_ACCTIME ) {
if (is_64_bit) {
- struct user_timespec tmp;
- tmp = *((struct user_timespec *)attributeBuffer);
+ struct user64_timespec tmp;
+ tmp = *((struct user64_timespec *)attributeBuffer);
searchInfo->accessDate.tv_sec = (time_t)tmp.tv_sec;
searchInfo->accessDate.tv_nsec = tmp.tv_nsec;
- attributeBuffer = (struct user_timespec *)attributeBuffer + 1;
+ attributeBuffer = (struct user64_timespec *)attributeBuffer + 1;
}
else {
- searchInfo->accessDate = *((struct timespec *)attributeBuffer);
- attributeBuffer = (struct timespec *)attributeBuffer + 1;
+ struct user32_timespec tmp;
+ tmp = *((struct user32_timespec *)attributeBuffer);
+ searchInfo->accessDate.tv_sec = (time_t)tmp.tv_sec;
+ searchInfo->accessDate.tv_nsec = tmp.tv_nsec;
+ attributeBuffer = (struct user32_timespec *)attributeBuffer + 1;
}
}
if ( a & ATTR_CMN_BKUPTIME ) {
if (is_64_bit) {
- struct user_timespec tmp;
- tmp = *((struct user_timespec *)attributeBuffer);
+ struct user64_timespec tmp;
+ tmp = *((struct user64_timespec *)attributeBuffer);
searchInfo->lastBackupDate.tv_sec = (time_t)tmp.tv_sec;
searchInfo->lastBackupDate.tv_nsec = tmp.tv_nsec;
- attributeBuffer = (struct user_timespec *)attributeBuffer + 1;
+ attributeBuffer = (struct user64_timespec *)attributeBuffer + 1;
}
else {
- searchInfo->lastBackupDate = *((struct timespec *)attributeBuffer);
- attributeBuffer = (struct timespec *)attributeBuffer + 1;
+ struct user32_timespec tmp;
+ tmp = *((struct user32_timespec *)attributeBuffer);
+ searchInfo->lastBackupDate.tv_sec = (time_t)tmp.tv_sec;
+ searchInfo->lastBackupDate.tv_nsec = tmp.tv_nsec;
+ attributeBuffer = (struct user32_timespec *)attributeBuffer + 1;
}
}
if ( a & ATTR_CMN_FNDRINFO ) {
return (0);
}
-
+#endif /* CONFIG_SEARCHFS */