44{
45
46
47
48
49 NSArray *mountedRemovableMedia = [[NSFileManager defaultManager] mountedVolumeURLsIncludingResourceValuesForKeys:nil options:NSVolumeEnumerationSkipHiddenVolumes];
50 NSMutableArray *result = [NSMutableArray array];
51 for(NSURL *volURL in mountedRemovableMedia)
52 {
53 int err = 0;
54 DADiskRef disk;
55 CFDictionaryRef descDict = nullptr;
56 DASessionRef session = DASessionCreate(nullptr);
57 if (session == nullptr)
58 err = EINVAL;
59 if (err == 0) {
60 disk = DADiskCreateFromVolumePath(nullptr,session,(CFURLRef)volURL);
61 if (session == nullptr)
62 err = EINVAL;
63 }
64 if (err == 0) {
65 descDict = DADiskCopyDescription(disk);
66 if (descDict == nullptr)
67 err = EINVAL;
68 }
69 if (err == 0) {
70 CFTypeRef mediaEjectableKey = CFDictionaryGetValue(descDict,kDADiskDescriptionMediaEjectableKey);
71 BOOL ejectable = [(id)mediaEjectableKey boolValue];
72 CFTypeRef deviceProtocolName = CFDictionaryGetValue(descDict,kDADiskDescriptionDeviceProtocolKey);
73
74 CFTypeRef deviceModelKey = CFDictionaryGetValue(descDict, kDADiskDescriptionDeviceModelKey);
75
76
77
78
79
80
81
82 if (mediaEjectableKey != nullptr) {
83 BOOL op = ejectable &&
84 ( (deviceProtocolName != nullptr && (CFEqual(deviceProtocolName, CFSTR("USB")) || CFEqual(deviceProtocolName, CFSTR("Secure Digital")))) ||
85 (deviceModelKey != nullptr && CFEqual(deviceModelKey, CFSTR("SD Card Reader"))) );
87 if (op)
88 [result addObject:volURL.path];
89 }
90 }
91 if (descDict != nullptr)
92 CFRelease(descDict);
93 }
94 return result;
95}