Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating FSRef from vrn, dirID, and name




On Mar 13, 2007, at 11:03 AM, Steve Mills wrote:

On Mar 13, 2007, at 08:52:01, Steve Mills wrote:

I'm sure this has an obvious answer, but I'm having a senior moment or something. How can I create an FSRef for a folder given a volume ref num, parent directory ID, and folder name given as Unicode? I thought it was possible with PBMakeFSRefUnicodeSync, but it looks like it only takes the parent directory as an FSRef in the ref field, not as a pair of ioVRefNum and ioDirID.

I found one way to do this, but it requires 2 steps:

OSErr MakeFSRef(const FSVolumeRefNum vrn, const UInt32 dirID, const ustring& name, FSRef* const fsr)
{
FSRefParam parm;
Str255 s;
OSErr err;
FSRef parent;

parm.ioCompletion = nil;
parm.ioNamePtr = s;
*s = 0;
parm.ioVRefNum = vrn;
parm.ioDirID = dirID;
parm.newRef = &parent;
PBMakeFSRefSync(&parm);

Not checking the return code? Brings up an interesting question, though, about the returned error code and the one stored in ioResult. Apple's sample code relies on the returned error code and I think ioResult is more for use with PBMakeFSRefAsync. Someone can correct me if I'm wrong.
if((err = parm.ioResult) == noErr)
err = FSMakeFSRefUnicode(&parent, name.size(), name.data(), kTextEncodingUnknown, fsr);

return err;
}


Is this the best method for doing this?

As far as I know.

Seems like there should be a 1-step api.

Not really, since this isn't a very common need. Normally you would have an FSRef for the parent, and you would normally get a directory ID from the directory's FSRef.


You can simplify the above a little with the following:

	FSRefParam		parm = { 0 };
	OSErr			err;
	FSRef			parent;
	
	parm.ioVRefNum = vrn;
	parm.ioDirID = dirID;
	parm.newRef = &parent;
	err = PBMakeFSRefSync(&parm);

if ( err == noErr)
err = FSMakeFSRefUnicode(&parent, name.size(), name.data(), kTextEncodingUnknown, fsr);

return err;
}


Larry

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Creating FSRef from vrn, dirID, and name (From: "Steve Mills" <email@hidden>)
 >Re: Creating FSRef from vrn, dirID, and name (From: "Steve Mills" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.