Skip to content

Commit

Permalink
Make the TypeOfVolumeAtPath NSWorkspace category build with only one …
Browse files Browse the repository at this point in the history
…warning (deprecation of a file manager call).
  • Loading branch information
uliwitness committed Nov 19, 2010
1 parent 212479d commit bca242f
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions NSWorkspace+TypeOfVolumeAtPath.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
io_name_t className;
kern_return_t kernResult;

if (IOObjectConformsTo(service, kIOMediaClass)) {
if( IOObjectConformsTo(service, kIOMediaClass) )
{
CFTypeRef wholeMedia;

// Find out whether it's a whole media:
Expand All @@ -66,16 +66,18 @@
kCFAllocatorDefault,
0);

if (NULL == wholeMedia) {
if( NULL == wholeMedia )
{
printf("Could not retrieve Whole property\n");
}
else {
else
{
isWholeMedia = CFBooleanGetValue(wholeMedia);
CFRelease(wholeMedia);
}
}

if (isWholeMedia)
if( isWholeMedia )
{
kernResult = IOObjectGetClass(service, className);
mediaType = [NSString stringWithUTF8String: className];
Expand All @@ -96,18 +98,22 @@
kIORegistryIterateRecursively | kIORegistryIterateParents,
&iter);

if (KERN_SUCCESS != kernResult) {
if (KERN_SUCCESS != kernResult)
{
printf("IORegistryEntryCreateIterator returned %d\n", kernResult);
}
else if (NULL == iter) {
else if (IO_OBJECT_NULL == iter)
{
printf("IORegistryEntryCreateIterator returned a NULL iterator\n");
}
else {
else
{
// A reference on the initial service object is released in the do-while loop below,
// so add a reference to balance
IOObjectRetain(service);

do {
do
{
mediaType = IsWholeMedia(service);
IOObjectRelease(service);
} while ((service = IOIteratorNext(iter)) && !mediaType);
Expand Down Expand Up @@ -182,31 +188,37 @@ -(NSString*) typeOfVolumeAtPath: (NSString*)path

NSLog(@"%s",bsdName);
matchingDict = IOBSDNameMatching( gMasterPort, 0, bsdName );
if (NULL == matchingDict) {
if (NULL == matchingDict)
{
printf("IOBSDNameMatching returned a NULL dictionary.\n");
}
else {
// Return an iterator across all objects with the matching BSD node name. Note that there
// should only be one match!
kernResult = IOServiceGetMatchingServices(gMasterPort, matchingDict, &iter);

if (KERN_SUCCESS != kernResult) {
if (KERN_SUCCESS != kernResult)
{
printf("IOServiceGetMatchingServices returned %d\n", kernResult);
}
else if (NULL == iter) {
else if (IO_OBJECT_NULL == iter)
{
printf("IOServiceGetMatchingServices returned a NULL iterator\n");
}
else {
else
{
service = IOIteratorNext(iter);

// Release this now because we only expect the iterator to contain
// a single io_service_t.
IOObjectRelease(iter);

if (NULL == service) {
if (IO_OBJECT_NULL == service)
{
printf("IOIteratorNext returned NULL\n");
}
else {
else
{
mediaType = FindWholeMedia(service);
NSMutableDictionary* propDict = nil;
IORegistryEntryCreateCFProperties( service, (CFMutableDictionaryRef*) &propDict, kCFAllocatorDefault, 0 );
Expand Down

0 comments on commit bca242f

Please sign in to comment.