Hi All,
I am trying to use [NSWorspace getFileSystemInfoForPath:isRemovable:isWritable:isUnmountable:description:type:] to determine which volumes are network mounts, but I am not getting back what I expected for description and type. Ultimately I used statfs(), but am curious if I was using getFileSystemInfoForPath... correctly. Here is a test case:
- (IBAction)getMountInfo:(id)sender { NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
BOOL removableFlag, writableFlag, unmountableFlag; NSString *description = nil, *fileSystemType = nil; NSString *path;
NSEnumerator *mountedPathsEnumerator = [[sharedWorkspace mountedLocalVolumePaths] objectEnumerator]; while (path = [mountedPathsEnumerator nextObject] ) { BOOL isMountPoint = [sharedWorkspace getFileSystemInfoForPath:path isRemovable:&removableFlag isWritable:&writableFlag isUnmountable:&unmountableFlag description:&description type:&fileSystemType]; NSString *message = [NSString stringWithFormat: @"Path: %@ \nIs Mount Point: %i \nIs Removable: %i \nIs Writable: %i \nIsUnmountable: %i \nDescription: %@ \nType: %@ \n\n", path, isMountPoint, removableFlag, writableFlag, unmountableFlag, description, fileSystemType]; [textView insertText:message]; } }
When I run the above, I get the following output:
Path: / *** internal hard drive Is Mount Point: 1 Is Removable: 0 Is Writable: 1 IsUnmountable: 0 Description: (null) Type: (null)
Path: /Volumes/Tiger *** internal hard drive Is Mount Point: 1 Is Removable: 0 Is Writable: 1 IsUnmountable: 0 Description: (null) Type: (null)
Path: /Volumes/iDIskName *** my iDisk Is Mount Point: 1 Is Removable: 0 Is Writable: 0 IsUnmountable: 0 Description: (null) Type: (null)
Path: /Volumes/WorkingCopy *** a disk image Is Mount Point: 1 Is Removable: 1 Is Writable: 1 IsUnmountable: 1 Description: (null) Type: (null)
Path: /Volumes/LEXAR MEDIA *** thumb drive Is Mount Point: 1 Is Removable: 0 Is Writable: 1 IsUnmountable: 0 Description: (null) Type: (null)
Path: /Volumes/House Contents 1:25:04 *** CD Is Mount Point: 1 Is Removable: 1 Is Writable: 0 IsUnmountable: 1 Description: (null) Type: (null)
Two things jump out at me. First, the description and type are null for all devices. Second, the flags are not correct for the thumb drive, the iDisk, or the second internal drive (it should be unmountable). Am I doing something wrong, or should I submit a bug? For comparison, here is the similar info collected with statfs:
- (IBAction)getStatInfo:(id)sender { NSString *path; struct statfs buffer;
NSEnumerator *mountedPathsEnumerator = [[[NSWorkspace sharedWorkspace] mountedLocalVolumePaths] objectEnumerator]; while (path = [mountedPathsEnumerator nextObject] ) { int returnCode = statfs( [path fileSystemRepresentation], &buffer); if ( returnCode == 0 ) { NSString *fileSystemType = [NSString stringWithCString:buffer.f_fstypename]; NSString *mountToName = [NSString stringWithCString:buffer.f_mntonname]; NSString *mountFromName = [NSString stringWithCString:buffer.f_mntfromname];
NSString *message = [NSString stringWithFormat: @"Path: %@ \nBlock Size: %d \nFree Blocks: %d \nFile System Type: %@ \nMount To: %@ \nMount From: %@\n\n", path, buffer.f_bsize, buffer.f_bavail, fileSystemType, mountToName, mountFromName]; [textView insertText:message]; } } }
Which results in:
Path: / Block Size: 4096 Free Blocks: 2146071 File System Type: hfs Mount To: / Mount From: /dev/disk0s3
Path: /Volumes/Tiger Block Size: 4096 Free Blocks: 1006754 File System Type: hfs Mount To: /Volumes/Tiger Mount From: /dev/disk0s5
Path: /Volumes/iDIskName Block Size: 512 Free Blocks: 137035 File System Type: webdav Mount To: /Volumes/aburgh
Path: /Volumes/WorkingCopy Block Size: 4096 Free Blocks: 78279 File System Type: hfs Mount To: /Volumes/WorkingCopy Mount From: /dev/disk3s2
Path: /Volumes/LEXAR MEDIA Block Size: 16384 Free Blocks: 17628 File System Type: msdos Mount To: /Volumes/LEXAR MEDIA Mount From: /dev/disk2s1
Path: /Volumes/House Contents 1:25:04 Block Size: 2048 Free Blocks: 0 File System Type: hfs Mount To: /Volumes/House Contents 1:25:04 Mount From: /dev/disk1s1s2
Thanks,
Aaron Burghardt
|