Re: mount() from Cocoa App
Re: mount() from Cocoa App
- Subject: Re: mount() from Cocoa App
- From: Dalton Hamilton <email@hidden>
- Date: Sat, 5 Nov 2005 08:00:07 +0100
Jim (and ALL), thanks very much for helping me figure this out. Your
last email pointed me to what I needed. Here is the code that works:
//
// main.m
#import <Cocoa/Cocoa.h>
enum
{
kBufferLength = 0x1000 /* 4K */
};
static void DisplayURLComponent(CFURLRef url, UInt8 *buffer,
CFURLComponentType componentType, char *componentTypeStr)
{
CFRange range;
CFRange rangeIncludingSeparators;
/* now, get the components and display them */
range = CFURLGetByteRangeForComponent(url, componentType,
&rangeIncludingSeparators);
if ( range.location != kCFNotFound )
{
char componentStr[kBufferLength];
char componentIncludingSeparatorsStr[kBufferLength];
strncpy(componentStr, (const char *)&buffer[range.location],
range.length);
componentStr[range.length] = 0;
strncpy(componentIncludingSeparatorsStr, (const char *)&buffer
[rangeIncludingSeparators.location], rangeIncludingSeparators.length);
componentIncludingSeparatorsStr[rangeIncludingSeparators.length] = 0;
fprintf(stdout, "%s: \"%s\" including separators: \"%s\"\n",
componentTypeStr, componentStr, componentIncludingSeparatorsStr);
}
else
{
fprintf(stdout, "%s not found\n", componentTypeStr);
}
}
int main(int argc, char *argv[])
{
//return NSApplicationMain(argc, (const char **) argv);
ItemCount volumeIndex;
FSRef ref;
// Used in PBHGetVInfoSync
HParamBlockRec
hpb;
FSVolumeRefNum
actualVolumeRefNum;
OSErr result=0,ec=0;
char name[100];
CFURLRef url;
CFStringRef urlStr;
UInt8 buffer[kBufferLength];
CFIndex componentLength;
bzero(&hpb,sizeof(HParamBlockRec));
hpb.ioParam.ioNamePtr = (StringPtr)name;
/* Call FSGetVolumeInfo in loop to get all volumes starting with the
first */
volumeIndex = 1;
do
{
bzero(name,100);
result = FSGetVolumeInfo(kFSInvalidVolumeRefNum, volumeIndex,
&actualVolumeRefNum, kFSVolInfoNone, NULL, NULL, &ref);
if ( noErr == result )
{
hpb.volumeParam.ioVRefNum = (short)actualVolumeRefNum;
ec = PBHGetVInfoSync(&hpb);
if(ec == noErr)
{
if(hpb.volumeParam.ioVFSID != 0) // Means this is a mounted volume
{
printf("share name = %s\n",&hpb.ioParam.ioNamePtr[1]);
ec = FSCopyURLForVolume(actualVolumeRefNum, &url);
if (ec == noErr)
urlStr = CFURLGetString(url);
/* get the bytes from the URL */
componentLength = CFURLGetBytes(url, buffer, kBufferLength);
buffer[componentLength] = 0;
fprintf(stdout, "url: \"%s\"\n", buffer);
DisplayURLComponent(url, buffer, kCFURLComponentHost,
"kCFURLComponentHost");
if (url != NULL) {
CFRelease(url);
}
}
}
++volumeIndex; // and the volumeIndex to get the next volume
}else
return(0);
} while ( noErr == result );
return(0);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden