/// Create a list of all bsd partitions␊ |
+(NSArray*) createBSDPartitionList␊ |
{␊ |
␉NSMutableArray* arr = [[NSMutableArray alloc] init];␊ |
␉NSMutableArray* arr = [[[NSMutableArray alloc] init] autorelease];␊ |
␉␊ |
␉char line[256];␊ |
␉ShellProcess p;␊ |
|
␉␉if (l==0 || strstr(line, "ls:")!=NULL) continue;␊ |
␉␉if (line[l-1]) line[l-1]='\0';␊ |
␉␉const char * p = strstr(line, "disk");␊ |
␉␉NSString* s = [[NSString stringWithUTF8String: p] retain];␊ |
␉␉NSString* s = [NSString stringWithUTF8String: p] ;␊ |
␉␉[arr addObject: s];␉␊ |
␉␉␊ |
␉}␊ |
|
}␊ |
␊ |
/// Extract a particular information from the disk partition dictionary from a key, generate a string value output␊ |
-(NSString*) createStringValueWithKey: (NSString*) key␊ |
-(NSString*) stringValueWithKey: (NSString*) key␊ |
{␊ |
␉if (err) return @"";␊ |
␉CFTypeRef o = [descDict objectForKey: key];␊ |
|
␉{␊ |
␉␉session = DASessionCreate(NULL);␊ |
␉}␊ |
␊ |
DADiskRef disk;␊ |
␉␊ |
␉if (session == NULL)␉err = EINVAL;␊ |
␉␊ |
␉if (err == 0) {␊ |
␉␉disk = DADiskCreateFromBSDName(NULL, session, [name UTF8String] );␊ |
␉␉DADiskRef disk = DADiskCreateFromBSDName(NULL, session, [name UTF8String] );␊ |
␉␉if (disk == NULL) err = EINVAL;␊ |
else␊ |
{␊ |
[self cleanup];␊ |
CFDictionaryRef␉dr = DADiskCopyDescription(disk);␊ |
if (dr!=NULL)␊ |
{␊ |
descDict = (NSDictionary*) dr;␊ |
CFRelease(dr);␊ |
}␊ |
}␊ |
if (disk) CFRelease(disk);␊ |
␉}␊ |
␉␊ |
␉[self cleanup];␊ |
␊ |
␉if (err == 0) {␊ |
␉␉CFDictionaryRef␉dr = DADiskCopyDescription(disk);␊ |
␉␉if (dr!=NULL)␊ |
␉␉{␊ |
␉␉␉self.descDict = [((NSDictionary*) dr) copy];␊ |
␉␉␉CFRelease(dr);␊ |
␉␉␉if (self.descDict == NULL) err = EINVAL;␊ |
␉␉}␊ |
␉}␊ |
␊ |
␉if (err == 0) {␊ |
␉␉diskNum = [sDisk␉intValue];␊ |
␉␉partNum = [sPart␉intValue];␊ |
␉␉␊ |
␉␉self.vUUID = [self createStringValueWithKey: @"DAVolumeUUID"];␊ |
␉␉self.vName = [self createStringValueWithKey: @"DAVolumeName"];␊ |
␉␉self.vUUID = [self stringValueWithKey: @"DAVolumeUUID"];␊ |
␉␉self.vName = [self stringValueWithKey: @"DAVolumeName"];␊ |
␉␉self.vAliasName = self.vName; // by default renamed = original part name ␊ |
␉␉self.vKind = [self createStringValueWithKey: @"DAVolumeKind"];␊ |
␉␉self.mediaPath = [self createStringValueWithKey: @"DAMediaPath"];␊ |
␉␉self.devProtocol = [self createStringValueWithKey: @"DADeviceProtocol"];␊ |
␉␉self.bsdName = [[NSString stringWithString:name] retain];␊ |
␉␉self.vKind = [self stringValueWithKey: @"DAVolumeKind"];␊ |
␉␉self.mediaPath = [self stringValueWithKey: @"DAMediaPath"];␊ |
␉␉self.devProtocol = [self stringValueWithKey: @"DADeviceProtocol"];␊ |
␉␉self.bsdName = [NSString stringWithString:name];␊ |
␉␉␊ |
␉␉self.devInternal = (bool) [[descDict objectForKey: @"DADeviceInternal"] boolValue];␊ |
␉␉self.mediaRemovable = (bool) [[descDict objectForKey: @"DAMediaRemovable"] boolValue];␊ |
|
␉␊ |
␉// Clean up.␊ |
␉␊ |
␉if (disk != NULL)␉CFRelease(disk);␊ |
␉if (session != NULL && mustRelease) CFRelease(session);␊ |
␉␊ |
␉return err;␊ |
|
{␉␉␊ |
␉NSArray* partArr = [PartitionInfoElement createBSDPartitionList];␊ |
␉if (arr == nil)␊ |
␉␉arr = [[NSMutableArray alloc ] init];␊ |
␉␉arr = [[[NSMutableArray alloc ] init] autorelease];␊ |
␉␊ |
␉if (partArr!=nil && [partArr count]>0)␊ |
␉{␊ |
|
␉␉␉for (NSString* part in partArr)␊ |
␉␉␉{␊ |
␉␉␉␉PartitionInfoElement* elt = ␊ |
␉␉␉␉[[PartitionInfoElement alloc] initWithBSDName: part withinSession: session];␊ |
␉␉␉␉[[[PartitionInfoElement alloc] initWithBSDName: part withinSession: session] autorelease];␊ |
␉␉␉␉if (elt!=nil && [[elt vName] length] >0 && [elt isValid] ) ␊ |
␉␉␉␉␉[arr addObject:elt];␊ |
␉␉␉␉␉[arr addObject: elt];␊ |
␉␉␉}␊ |
␉␉␉if (session!=nil) CFRelease(session);␊ |
␉}␊ |
␉[partArr release];␊ |
␉return arr;␊ |
}␊ |
␊ |
|
/// initialize a partition element with DA partition info␊ |
-(id) initWithBSDName:(NSString*) name ␊ |
{␊ |
␉[super init];␊ |
␉self = [super init];␊ |
␉diskNum = partNum = -1;␊ |
␉err = [self extractInfoWithBSDName: name withinSession: nil];␊ |
␉return self;␊ |
|
/// initialize a partition element with DA partition info and an optional opened session␊ |
-(id) initWithBSDName:(NSString*) name withinSession:(DASessionRef) session␊ |
{␊ |
␉[super init];␊ |
␉self = [super init];␊ |
␉diskNum = partNum = -1;␊ |
␉err = [self extractInfoWithBSDName: name withinSession: session];␊ |
␉␊ |