Skip to content

Commit

Permalink
Show error if mount fails
Browse files Browse the repository at this point in the history
kainjow committed Feb 25, 2018
1 parent c12ad2c commit 309e177
Showing 2 changed files with 16 additions and 1 deletion.
Binary file modified English.lproj/Localizable.strings
Binary file not shown.
17 changes: 16 additions & 1 deletion SLDiskManager.m
Original file line number Diff line number Diff line change
@@ -286,6 +286,21 @@ - (void)diskChangedWithDescription:(NSDictionary*)description mode:(SLDiskChange
[[NSNotificationCenter defaultCenter] postNotificationName:SLDiskManagerUnmountedVolumesDidChangeNotification object:nil];
}

static void diskMountCallback(DADiskRef disk, DADissenterRef dissenter, void *context __unused)
{
if (dissenter) {
const char *bsdName = DADiskGetBSDName(disk);
NSString *diskStr = bsdName ? [NSString stringWithUTF8String:bsdName] : [NSString stringWithFormat:@"%@", disk];
DAReturn status = DADissenterGetStatus(dissenter);
dispatch_async(dispatch_get_main_queue(), ^{
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = [NSString stringWithFormat:NSLocalizedString(@"Failed to mount %@", ""), diskStr];
alert.informativeText = [NSString stringWithFormat:NSLocalizedString(@"Status: %ld", ""), (long)status & 0xFFL];
(void)[alert runModal];
});
}
}

- (void)mount:(SLDisk *)disk
{
// DiskArbitration does not seem to support encrypted disk. In order to be able to mount an encrypted disk we have to use the diskutil command
@@ -337,7 +352,7 @@ - (void)mount:(SLDisk *)disk
} else {
DADiskRef diskref = DADiskCreateFromBSDName(kCFAllocatorDefault, _session, [disk.diskID UTF8String]);
if (diskref) {
DADiskMount(diskref, NULL, kDADiskMountOptionDefault, NULL, NULL);
DADiskMount(diskref, NULL, kDADiskMountOptionDefault, diskMountCallback, NULL);
CFRelease(diskref);
}
}

0 comments on commit 309e177

Please sign in to comment.