-
Notifications
You must be signed in to change notification settings - Fork 16
/
SLDiskManager.m
586 lines (522 loc) · 21.8 KB
/
SLDiskManager.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
//
// SLDiskManager.m
// Semulov
//
// Created by Kevin Wojniak on 9/1/11.
// Copyright 2011-2014 Kevin Wojniak. All rights reserved.
//
#import "SLDiskManager.h"
#import <AppKit/AppKit.h>
#import <DiskArbitration/DiskArbitration.h>
#import <IOKit/kext/KextManager.h>
#import <sys/mount.h>
#import "SLDiskImageManager.h"
#import "NSTaskAdditions.h"
NSString * const SLDiskManagerUnmountedVolumesDidChangeNotification = @"SLDiskManagerUnmountedVolumesDidChangeNotification";
NSString * const SLDiskManagerDidBlockMountNotification = @"SLDiskManagerDidBlockMountNotification";
@interface SLDiskEjector : NSObject
typedef void (^SLDiskEjectorHandler)(BOOL succeeded, SLDisk *failureDisk);
- (instancetype)initWithDisk:(SLDisk *)disk manager:(SLDiskManager *)manager handler:(SLDiskEjectorHandler)handler;
@end
@interface SLDiskManager (Private)
typedef enum {
kSLDiskChangeModeAppeared,
kSLDiskChangeModeDisappeared,
kSLDiskChangeModeDescriptionChanged,
} SLDiskChangeMode;
- (void)diskChanged:(DADiskRef)disk mode:(SLDiskChangeMode)mode;
@end
void diskAppearedCallback(DADiskRef disk, void *context)
{
[(__bridge SLDiskManager *)context diskChanged:disk mode:kSLDiskChangeModeAppeared];
}
void diskDisappearedCallback(DADiskRef disk, void *context)
{
[(__bridge SLDiskManager *)context diskChanged:disk mode:kSLDiskChangeModeDisappeared];
}
void diskDescriptionChangedCallback(DADiskRef disk, CFArrayRef keys __unused, void *context)
{
[(__bridge SLDiskManager *)context diskChanged:disk mode:kSLDiskChangeModeDescriptionChanged];
}
CF_RETURNS_RETAINED DADissenterRef diskMountApproval(DADiskRef disk, void *context)
{
if (((__bridge SLDiskManager *)context).blockMounts) {
NSDictionary *description = (__bridge_transfer NSDictionary *)DADiskCopyDescription(disk);
[[NSNotificationCenter defaultCenter] postNotificationName:SLDiskManagerDidBlockMountNotification object:description userInfo:nil];
return DADissenterCreate(kCFAllocatorDefault, kDAReturnNotPermitted, NULL);
}
return NULL;
}
@implementation SLDiskManager {
DASessionRef _session;
NSMutableDictionary *_pendingDisks;
NSMutableArray *_disks;
SLDiskImageManager *_diskImageManager;
NSMutableArray *_ejectors;
}
@dynamic disks, diskImageManager;
- (SLDiskImageManager *)diskImageManager
{
return _diskImageManager;
}
- (NSArray *)unmountedDisks {
NSMutableArray *unmountedDisks = [NSMutableArray array];
for (SLDisk *disk in _disks) {
if (disk.mountable && !disk.mounted) {
[unmountedDisks addObject:disk];
}
for (SLDisk *childDisk in disk.children) {
if (childDisk.mountable && !childDisk.mounted) {
[unmountedDisks addObject:childDisk];
}
}
}
return [unmountedDisks count] > 0 ? unmountedDisks : nil;
}
- (NSArray *)disks {
return _disks;
}
- (instancetype)init
{
if ((self = [super init]) != nil) {
_session = DASessionCreate(kCFAllocatorDefault);
if (!_session) {
NSLog(@"Failed to create session");
return nil;
}
_pendingDisks = [NSMutableDictionary dictionary];
_disks = [NSMutableArray array];
_diskImageManager = [[SLDiskImageManager alloc] init];
_ejectors = [NSMutableArray array];
DARegisterDiskAppearedCallback(_session, NULL, diskAppearedCallback, (__bridge void *)self);
DARegisterDiskDisappearedCallback(_session, NULL, diskDisappearedCallback, (__bridge void *)self);
DARegisterDiskDescriptionChangedCallback(_session, kDADiskDescriptionMatchVolumeMountable, kDADiskDescriptionWatchVolumePath, diskDescriptionChangedCallback, (__bridge void *)self);
DARegisterDiskMountApprovalCallback(_session, kDADiskDescriptionMatchVolumeMountable, diskMountApproval, (__bridge void *)self);
DASessionScheduleWithRunLoop(_session, [[NSRunLoop currentRunLoop] getCFRunLoop], kCFRunLoopDefaultMode);
}
return self;
}
- (void)updateDisk:(SLDisk *)disk fromDescription:(NSDictionary *)description
{
NSDictionary *mediaIcon = [description objectForKey:(NSString *)kDADiskDescriptionMediaIconKey];
NSString *bundleIdent = [mediaIcon objectForKey:(NSString *)kCFBundleIdentifierKey];
NSString *iconFile = [mediaIcon objectForKey:@kIOBundleResourceFileKey];
if (bundleIdent && iconFile) {
NSURL *bundleURL = (__bridge_transfer NSURL *)KextManagerCreateURLForBundleIdentifier(kCFAllocatorDefault, (__bridge CFStringRef)bundleIdent);
if (bundleURL) {
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
disk.icon = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:iconFile ofType:nil]];
}
}
disk.name = [description objectForKey:(NSString *)kDADiskDescriptionVolumeNameKey];
NSString *model = [[description objectForKey:(NSString *)kDADiskDescriptionDeviceModelKey] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *vendor = [[description objectForKey:(NSString *)kDADiskDescriptionDeviceVendorKey] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (model && vendor) {
disk.deviceName = [NSString stringWithFormat:@"%@ %@", vendor, model];
} else if (model) {
disk.deviceName = model;
}
disk.volumePath = [description objectForKey:(NSString *)kDADiskDescriptionVolumePathKey];
// If the volume exists, use its volume so we show custom icons
if (disk.volumePath && [disk.volumePath checkResourceIsReachableAndReturnError:nil]) {
disk.icon = [[NSWorkspace sharedWorkspace] iconForFile:[disk.volumePath path]];
}
disk.mountable = [[description objectForKey:(NSString *)kDADiskDescriptionVolumeMountableKey] boolValue];
disk.ejectable = [[description objectForKey:(NSString *)kDADiskDescriptionMediaEjectableKey] boolValue];
disk.whole = [[description objectForKey:(NSString *)kDADiskDescriptionMediaWholeKey] boolValue];
disk.diskImage = [_diskImageManager diskImageForDiskID:disk.diskID];
if (disk.diskImage) {
disk.isDiskImage = YES;
if (disk.whole) {
disk.deviceName = [disk.diskImage lastPathComponent];
}
}
disk.volumeKind = [description objectForKey:(NSString *)kDADiskDescriptionVolumeKindKey];
NSString* volumeType = [description objectForKey:@"DAVolumeType"]; // kDADiskDescriptionVolumeTypeKey is 10.11+
disk.encrypted = [volumeType rangeOfString:@"encrypt" options:NSCaseInsensitiveSearch].location != NSNotFound;
CFUUIDRef uuidRef = (__bridge CFUUIDRef)[description objectForKey:(NSString *)kDADiskDescriptionVolumeUUIDKey];
if (uuidRef) {
disk.volumeUUID = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, uuidRef);
}
}
- (SLDisk *)diskFromDescription:(NSDictionary *)description diskID:(NSString *)diskID
{
SLDisk *disk = [[SLDisk alloc] init];
disk.children = [NSMutableArray array];
disk.diskID = diskID;
[self updateDisk:disk fromDescription:description];
return disk;
}
// Converts disk0s4 to disk0
+ (NSString *)diskIDStripSlice:(NSString *)diskID
{
if ([diskID hasPrefix:@"disk"]) {
NSRange range = [diskID rangeOfString:@"s" options:NSBackwardsSearch];
if (range.location > 2) {
return [diskID substringToIndex:range.location];
}
}
return diskID;
}
- (void)diskChanged:(DADiskRef)disk mode:(SLDiskChangeMode)mode
{
NSDictionary *description = (__bridge_transfer NSDictionary *)DADiskCopyDescription(disk);
[_diskImageManager reloadInfo:^{
[self diskChangedWithDescription:description mode:mode];
}];
}
- (void)diskChangedWithDescription:(NSDictionary*)description mode:(SLDiskChangeMode)mode
{
NSString *diskID = [description objectForKey:(NSString *)kDADiskDescriptionMediaBSDNameKey];
if (!diskID) {
return;
}
NSNumber *wholeNum = [description objectForKey:(NSString *)kDADiskDescriptionMediaWholeKey];
BOOL isWhole = wholeNum && [wholeNum boolValue];
if (mode == kSLDiskChangeModeDisappeared) {
// Disk disappeared, remove entire object
for (NSInteger i = (NSInteger)_disks.count - 1; i >= 0; --i) {
SLDisk *disk = _disks[(NSUInteger)i];
if ([disk.diskID isEqualToString:diskID]) {
[_disks removeObjectAtIndex:(NSUInteger)i];
break;
}
BOOL removedChild = NO;
NSMutableArray *children = disk.children;
for (NSInteger j = (NSInteger)children.count - 1; j >= 0; --j) {
SLDisk *childDisk = children[(NSUInteger)j];
if ([childDisk.diskID isEqualToString:diskID]) {
[children removeObjectAtIndex:(NSUInteger)j];
removedChild = YES;
break;
}
}
if (removedChild) {
break;
}
}
} else {
// Disk appeared or had a description changed
BOOL found = NO;
for (SLDisk *disk in _disks) {
if ([disk.diskID isEqualToString:diskID]) {
[self updateDisk:disk fromDescription:description];
found = YES;
break;
}
for (SLDisk *childDisk in disk.children) {
if ([childDisk.diskID isEqualToString:diskID]) {
[self updateDisk:childDisk fromDescription:description];
found = YES;
break;
}
}
}
if (!found) {
if (mode == kSLDiskChangeModeDescriptionChanged) {
// Sometimes a disk changed event can be sent after a disk disappeared event.
// We just ignore these.
return;
}
if (isWhole) {
SLDisk *disk = [self diskFromDescription:description diskID:diskID];
// Process pending disks
NSMutableArray *pendingDiskIDsToRemove = [NSMutableArray array];
[_pendingDisks enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop __unused) {
NSString *pendingDiskID = key;
if ([[[self class] diskIDStripSlice:pendingDiskID] isEqualToString:diskID]) {
SLDisk *childDisk = [self diskFromDescription:obj diskID:pendingDiskID];
childDisk.parent = disk;
[disk.children addObject:childDisk];
[pendingDiskIDsToRemove addObject:pendingDiskID];
}
}];
[_pendingDisks removeObjectsForKeys:pendingDiskIDsToRemove];
[_disks addObject:disk];
} else {
NSString *wholeDiskID = [[self class] diskIDStripSlice:diskID];
for (SLDisk *disk in _disks) {
if ([disk.diskID isEqualToString:wholeDiskID]) {
SLDisk *childDisk = [self diskFromDescription:description diskID:diskID];
childDisk.parent = disk;
[disk.children addObject:childDisk];
found = YES;
break;
}
}
if (!found) {
// DiskArbitration can send child disks before the parent, so we have to wait for the parent to arrive to process the children
if (_pendingDisks[diskID] != nil) {
// bug?
NSLog(@"Replacing existing pending disk for %@?", diskID);
}
_pendingDisks[diskID] = description;
}
}
}
}
[[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
if (disk.encrypted && [self canUnlock:disk]) {
NSString* service = disk.volumeUUID;
UInt32 pwLength = 0;
void* pwData = NULL;
SecKeychainItemRef itemRef = NULL;
OSStatus status = SecKeychainFindGenericPassword(
NULL,
(UInt32)service.length,
[service UTF8String],
0,
NULL,
&pwLength,
&pwData,
&itemRef
);
if (status == errSecSuccess && pwData) {
NSLog(@"Volume encryption password fetched successfully from the keychain");
NSData* data = [NSData dataWithBytes:pwData length:pwLength];
SecKeychainItemFreeContent(NULL, pwData);
NSString* password = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[self unlockDisk:disk withPassword:password];
} else {
NSLog(@"Error when fetching the encryption password from the keychain: %@ Prompting the user for it.", (__bridge_transfer NSString *)SecCopyErrorMessageString(status, NULL));
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat: NSLocalizedString(@"Introduce the encryption password to unlock the volume once:", nil), (__bridge_transfer NSString *)SecCopyErrorMessageString(status, NULL)] defaultButton:nil alternateButton:NSLocalizedString(@"Cancel", nil) otherButton:nil informativeTextWithFormat:NSLocalizedString(@"If you want to mount an encrypted volume automatically without manually introducing the password:\na) Mount it using Disk Utility\nb) Save the password in the keychain", nil)];
#pragma clang diagnostic pop
NSSecureTextField *input = [[NSSecureTextField alloc] initWithFrame:NSZeroRect];
[input sizeToFit];
[input setFrameSize:NSMakeSize(250, input.frame.size.height)];
[alert setAccessoryView:input];
// Set the focus to the textField, so the user can type the password right away
[NSApp activateIgnoringOtherApps:YES];
[[alert window] setInitialFirstResponder:input];
NSInteger button = [alert runModal];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
const BOOL clickedOK = button == NSAlertDefaultReturn;
#pragma clang diagnostic pop
if (clickedOK) {
[input validateEditing];
[self unlockDisk:disk withPassword:input.stringValue];
} else {
NSLog(@"Unlocking disk was cancelled by the user");
}
}
} else {
DADiskRef diskref = DADiskCreateFromBSDName(kCFAllocatorDefault, _session, [disk.diskID UTF8String]);
if (diskref) {
DADiskMount(diskref, NULL, kDADiskMountOptionDefault, diskMountCallback, NULL);
CFRelease(diskref);
}
}
}
- (BOOL)canUnlock:(SLDisk *)disk
{
NSArray *unlockable = @[@"apfs", @"coreStorage"];
return [unlockable containsObject:disk.volumeKind];
}
- (void)unlockDisk:(SLDisk *)disk withPassword:(NSString *)password
{
NSString *volumeKind = disk.volumeKind;
NSString *diskID = disk.diskID;
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// Execute diskutil, passing the volumeKind and the encryption password
int status = -1;
NSArray *args = @[volumeKind, @"unlockVolume", diskID, @"-passphrase", password];
NSString *output = [NSTask outputStringForTaskAtPath:@"/usr/sbin/diskutil" arguments:args encoding:NSUTF8StringEncoding status:&status];
dispatch_async(dispatch_get_main_queue(), ^{
// In case return code is not zero, there was an error
if (status != 0) {
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = NSLocalizedString(@"There was an error unlocking the disk", nil);
alert.informativeText = output;
[alert runModal];
}
});
});
}
typedef void (^SLEjectHandler)(BOOL ejected);
static void diskUnmountCallback(DADiskRef disk, DADissenterRef dissenter, void *context)
{
NSDictionary *description = (__bridge_transfer NSDictionary *)DADiskCopyDescription(disk);
NSString *diskID = [description objectForKey:(NSString *)kDADiskDescriptionMediaBSDNameKey];
if (!diskID) {
return;
}
if (context) {
SLUnmountHandler handler = (__bridge_transfer SLUnmountHandler)context;
if (handler) {
handler(dissenter == NULL);
}
}
}
static void diskEjectCallback(DADiskRef disk, DADissenterRef dissenter, void *context)
{
NSDictionary *description = (__bridge_transfer NSDictionary *)DADiskCopyDescription(disk);
NSString *diskID = [description objectForKey:(NSString *)kDADiskDescriptionMediaBSDNameKey];
if (!diskID) {
return;
}
if (context) {
SLEjectHandler handler = (__bridge_transfer SLEjectHandler)context;
if (handler) {
handler(dissenter == NULL);
}
}
}
- (void)unmountDisk:(SLDisk *)disk handler:(SLUnmountHandler)handler
{
DADiskRef diskref = DADiskCreateFromBSDName(kCFAllocatorDefault, _session, disk.diskID.UTF8String);
if (!disk) {
NSLog(@"Can't create disk for unmounted %@", disk.diskID);
return;
}
DADiskUnmount(diskref, kDADiskUnmountOptionDefault, diskUnmountCallback, (__bridge_retained void *)handler);
CFRelease(diskref);
}
- (void)ejectDisk:(SLDisk *)disk handler:(SLEjectHandler)handler
{
DADiskRef diskref = DADiskCreateFromBSDName(kCFAllocatorDefault, _session, disk.diskID.UTF8String);
if (!disk) {
NSLog(@"Can't create disk for ejecting %@", disk.diskID);
return;
}
DADiskEject(diskref, kDADiskEjectOptionDefault, diskEjectCallback, (__bridge_retained void *)handler);
CFRelease(diskref);
}
- (void)unmountAndMaybeEject:(SLDisk *)disk handler:(SLUnmountHandler)handler
{
SLDiskEjector *ejector = nil;
if (disk.children.count > 0) {
ejector = [[SLDiskEjector alloc] initWithDisk:disk manager:self handler:^(BOOL succeeded, SLDisk *failureDisk __unused) {
handler(succeeded);
[self->_ejectors removeObject:ejector];
}];
[_ejectors addObject:ejector];
} else if (disk.mounted) {
unsigned numOtherMounted = 0;
for (SLDisk *childDisk in disk.parent.children) {
if (childDisk.mounted && childDisk != disk) {
++numOtherMounted;
}
}
if (numOtherMounted == 0) {
// The disk has no other mounted volumes, so unmount then eject it.
ejector = [[SLDiskEjector alloc] initWithDisk:disk.parent ? disk.parent : disk manager:self handler:^(BOOL succeeded, SLDisk *failureDisk __unused) {
handler(succeeded);
[self->_ejectors removeObject:ejector];
}];
[_ejectors addObject:ejector];
} else {
[self unmountDisk:disk handler:handler];
}
}
}
- (NSString *)diskIDForPath:(NSString *)path
{
struct statfs sb;
if (statfs([path fileSystemRepresentation], &sb) != 0) {
return nil;
}
return [[NSString stringWithUTF8String:sb.f_mntfromname] lastPathComponent];
}
- (SLDisk *)diskForPath:(NSString *)path
{
return [self diskForDiskID:[self diskIDForPath:path]];
}
- (SLDisk *)diskForDiskID:(NSString *)diskID
{
for (SLDisk *disk in _disks) {
if ([disk.diskID isEqualToString:diskID]) {
return disk;
}
for (SLDisk *childDisk in disk.children) {
if ([childDisk.diskID isEqualToString:diskID]) {
return childDisk;
}
}
}
return nil;
}
@end
@implementation SLDisk
- (BOOL)mounted {
return self.volumePath != nil;
}
- (BOOL)isStartupDisk
{
return [self.volumePath.path isEqualToString:@"/"];
}
- (BOOL)containsStartupDisk
{
for (SLDisk *childDisk in self.children) {
if (childDisk.isStartupDisk) {
return YES;
}
}
return NO;
}
@end
@implementation SLDiskEjector
{
SLDisk *_disk;
__weak SLDiskManager *_manager;
SLDiskEjectorHandler _handler;
NSMutableArray *_children;
}
- (void)unmountNext
{
if (_children.count == 0) {
[_manager ejectDisk:_disk handler:^(BOOL ejected) {
self->_handler(ejected, ejected ? nil : self->_disk);
}];
return;
}
SLDisk *disk = [_children objectAtIndex:0];
[_children removeObjectAtIndex:0];
[_manager unmountDisk:disk handler:^(BOOL unmounted) {
if (unmounted) {
[self unmountNext];
} else {
self->_handler(NO, disk);
}
}];
}
- (instancetype)initWithDisk:(SLDisk *)disk manager:(SLDiskManager *)manager handler:(SLDiskEjectorHandler)handler
{
if ((self = [super init]) != nil) {
_disk = disk;
_manager = manager;
_handler = handler;
_children = [NSMutableArray array];
for (SLDisk *childDisk in disk.children) {
if (childDisk.mounted) {
[_children addObject:childDisk];
}
}
if (disk.mounted) {
[_children addObject:disk];
}
[self unmountNext];
}
return self;
}
@end