Cocoa objective-c for os x: get volume mount point from path

I would like to find the mount point of the volume for the given NSString path.

Although I am new to Cocoa and objective-C, I try to make it "elegant", i.e. using one of the provided class, instead of making an external shell call or listing mounted file systems and finding which path it belongs to.

I found NSWorkspace and getFileSystemInfoForPath but don't mention mount point.

Does anyone help?

thank

+3
source share
2 answers

This should go something like this:

+ (NSString*)volumeNameForPath:(NSString *)inPath
{
    HFSUniStr255 volumeName;
    FSRef volumeFSRef;
    unsigned int volumeIndex = 1;

    while (FSGetVolumeInfo(kFSInvalidVolumeRefNum, volumeIndex++, NULL, kFSVolInfoNone, NULL, &volumeName, &volumeFSRef) == noErr) {
        NSURL *url = [(NSURL *)CFURLCreateFromFSRef(NULL, &volumeFSRef) autorelease];
        NSString *path = [url path];

        if ([inPath hasPrefix:path]) {
            return [NSString stringWithCharacters:volumeName.unicode length:volumeName.length]
        }
    }

    return nil;
}
+4
source

, : Python os.path.ismount() , , . :

, path, path/.., , path, path/.. path i- node - Unix POSIX.

+1

Source: https://habr.com/ru/post/1727855/


All Articles