この情報を取得するには、いくつかの下位レベルのファイル マネージャー ルーチンを使用する必要があります。通常の Cocoa 呼び出しでそれを行う方法はありません。URL は以下を使用しFSCopyURLForVolume()
て取得されますが、それを使用するには、マウントされたボリュームのボリューム参照番号を取得する必要があります。
#import <CoreServices/CoreServices.h>
//this is the path to the mounted network volume
NSString* pathToVolume = @"/Volumes/MountedNetworkVolume/";
//get the volume reference number
FSRef pathRef;
FSPathMakeRef((UInt8*)[pathToVolume fileSystemRepresentation],&pathRef,NULL);
FSCatalogInfo catalogInfo;
OSErr osErr = FSGetCatalogInfo(
&pathRef,
kFSCatInfoVolume,
&catalogInfo,
NULL,
NULL,
NULL
) ;
FSVolumeRefNum volumeRefNum = 0;
if(osErr == noErr)
volumeRefNum = catalogInfo.volume;
//get the server URL for the volume
CFURLRef serverLocation;
OSStatus result = FSCopyURLForVolume (volumeRefNum,&serverLocation);
if(result == noErr)
NSLog(@"The server location is: %@",serverLocation);
else
NSLog(@"An error occurred: %i",result);
CFRelease(serverLocation);
FSMountServerVolumeAsync
リモートボリュームをマウントする正しい方法です。