void QStorageInfoPrivate::retrieveUrlProperties(bool initRootPath) { static const void *rootPathKeys[] = { kCFURLVolumeURLKey }; static const void *propertyKeys[] = { // kCFURLVolumeNameKey, // 10.7 // kCFURLVolumeLocalizedNameKey, // 10.7 kCFURLVolumeTotalCapacityKey, kCFURLVolumeAvailableCapacityKey, // kCFURLVolumeIsReadOnlyKey // 10.7 }; size_t size = (initRootPath ? sizeof(rootPathKeys) : sizeof(propertyKeys)) / sizeof(void*); QCFType<CFArrayRef> keys = CFArrayCreate(kCFAllocatorDefault, initRootPath ? rootPathKeys : propertyKeys, size, Q_NULLPTR); if (!keys) return; const QCFString cfPath = rootPath; if (initRootPath) rootPath.clear(); QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfPath, kCFURLPOSIXPathStyle, true); if (!url) return; CFErrorRef error; QCFType<CFDictionaryRef> map = CFURLCopyResourcePropertiesForKeys(url, keys, &error); if (!map) return; if (initRootPath) { const CFURLRef rootUrl = (CFURLRef)CFDictionaryGetValue(map, kCFURLVolumeURLKey); if (!rootUrl) return; rootPath = QCFString(CFURLCopyFileSystemPath(rootUrl, kCFURLPOSIXPathStyle)); valid = true; ready = true; return; } bytesTotal = CFDictionaryGetInt64(map, kCFURLVolumeTotalCapacityKey); bytesAvailable = CFDictionaryGetInt64(map, kCFURLVolumeAvailableCapacityKey); bytesFree = bytesAvailable; }
CFURLEnumeratorResult CFURLEnumeratorGetNextURL(CFURLEnumeratorRef enumer, CFURLRef *url, CFErrorRef *error) { struct __CFURLEnumerator *enumerator = (struct __CFURLEnumerator *)enumer; if (url != NULL) { *url = NULL; } if (error != NULL) { *error = NULL; } CFIndex count = 0; CFDictionaryRef fileInfo = NULL; CFURLRef parent = NULL; do { CFURLEnumeratorPeek(enumerator, &parent); if (parent != NULL) { fileInfo = CFURLEnumeratorDequeueFileInfo(enumerator); } if (fileInfo == NULL) { count = CFURLEnumeratorPopURL(enumerator); } else { count = 0; } } while (count > 0); if (fileInfo == NULL || parent == NULL) { // the parent being null might be an error if it happens... it doesnt seem possible however return kCFURLEnumeratorEnd; } Boolean isDir = CFBooleanGetValue(CFDictionaryGetValue(fileInfo, fileInfoIsDirKey)); CFURLRef item = NULL; if (url != NULL) { CFStringRef name = (CFStringRef)CFDictionaryGetValue(fileInfo, fileInfoNameKey); item = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, parent, name, isDir); *url = item; } if (fileInfo) { CFRelease(fileInfo); } if (isDir && (enumerator->options & kCFURLEnumeratorDescendRecursively) == 0) { if (CFURLEnumeratorPushURL(enumerator, item, error) <= 0) { return kCFURLEnumeratorError; // error populated by push } } if (enumerator->propertyKeys) { CFDictionaryRef properties = CFURLCopyResourcePropertiesForKeys(item, enumerator->propertyKeys, error); if (properties != NULL) { CFRelease(properties); return kCFURLEnumeratorSuccess; } else { return kCFURLEnumeratorError; } } else { return kCFURLEnumeratorSuccess; } }