[SOLVED] Trouble with FSMountServerVolumeSync
[SOLVED] Trouble with FSMountServerVolumeSync
- Subject: [SOLVED] Trouble with FSMountServerVolumeSync
- From: email@hidden
- Date: Thu, 08 Sep 2005 17:54:56 +0000
After much searching I found out what my problem is. Basically CFURLCreateWithFileSystemPath() does work under Panther, but works under Tiger. If anyone needs to know what I did here it is:
NSString *urlStringOfVolumeToMount = [[[NSString alloc] initWithFormat:@"afp://%@/%@", m_serverAddress, m_volumeName] autorelease];
urlStringOfVolumeToMount = [urlStringOfVolumeToMount stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *urlOfVolumeToMount = [[[NSURL alloc] initWithString:urlStringOfVolumeToMount] autorelease];
OSErr error = -1;
FSVolumeRefNum refNum;
error = FSMountServerVolumeSync((CFURLRef) urlOfVolumeToMount, NULL, (CFStringRef) m_userName, (CFStringRef) m_passWord, &refNum, FALSE);
Of course my stupidity stopped me from realizing there was NSURL so I could keep more of my code in Cocoa.
Kris
> So, I am trying to mount a volume programmatically. I understand the easiest
> way to do this under OS X is to use FSMountServerVolumeSync. I do not want to
> fork a process and do mount_afp, because I want the refnum so I can eject the
> drive later.
>
> So here is the command:
> OSStatus FSMountServerVolumeSync (
> CFURLRef url,
> CFURLRef mountDir,
> CFStringRef user,
> CFStringRef password,
> FSVolumeRefNum * mountedVolumeRefNum,
> OptionBits flags
> );
>
> If I pass NULL for mountDir the command works perfectly under Tiger, but fails
> with a -36 under Panther. Therefor my assumption is I need to fill this in with
> something valid. Below is my feeble and obviously incorrect attempt, because I
> get the same error:
> -(OSErr)MountAFPVolume:(NSString *) m_serverAddress :(NSString *)m_volumeName
> :(NSString *) m_userName
> :(NSString *) m_passWord :(FSVolumeRefNum *)refNum
> {
> NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
>
> NSFileManager *fileManager = [[NSFileManager defaultManager]
> autorelease];
>
> NSString *pathToMount = [[[NSString alloc]
> initWithFormat:@"/Volumes/%@", m_volumeName] autorelease];
>
> if ([fileManager fileExistsAtPath:pathToMount] == NO)
> {
> [fileManager createDirectoryAtPath:pathToMount attributes: nil];
> } else
> {
> NSLog(@"The mount location already exists!");
> [pool release];
> return;
> }
>
> NSString *urlStringOfVolumeToMount = [[[NSString alloc]
> initWithFormat:@"afp://%@:%@@%@/%@", m_userName, m_passWord, m_serverAddress,
> m_volumeName] autorelease];
>
> OSErr error;
>
> CFURLRef CFUrl = CFURLCreateWithFileSystemPath( kCFAllocatorDefault,
> (CFStringRef) urlStringOfVolumeToMount, kCFURLPOSIXPathStyle, TRUE);
> CFURLRef CFMountPath = CFURLCreateWithFileSystemPath(
> kCFAllocatorDefault, (CFStringRef) pathToMount, kCFURLPOSIXPathStyle, TRUE);
>
> CFStringRef CFusername = (CFStringRef) m_userName;
> CFStringRef CFpassword = (CFStringRef) m_passWord;
>
> error = FSMountServerVolumeSync(CFUrl, CFMountPath, CFusername,
> CFpassword, refNum, FALSE);
>
> [pool release];
>
> return error;
> }
>
> Any ideas? Also any clue why it works fine on Tiger and fails on Panther?
>
> Thanks,
> Kris
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden