🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #22803

Re: Reading a full pathname in HFS - source code

#22803
From: Tim Maroney
Date: Sat, 12 Dec 1987 03:21
86 lines
2576 bytes
You're quite correct, Justin.  The disadvantage of modular source code is
that, six months later, you forget how the function works.  Here is my
source code for getting a full path name.  fullname is a return parameter
which receives the full name of the (file, volume, dirID) triplet.

void
GetFullName(fullname, file, volume, dirID)
char *fullname, *file;
word volume;
longword dirID;
{
	char buffer[256], buf2[256], *name, *accum, *tmp;
	HVolumeParam hvp;
	DirInfo di;

	hvp.ioNamePtr = (StringPtr)fullname;
	hvp.ioVRefNum = volume;
	hvp.ioVolIndex = 0;
	PBHGetVInfo(&hvp, false);
	fullname[++fullname[0]] = ':';
	p2cstr(fullname);

	if (FSFCBLen > 0) {
		/* runnning HFS */
		if (hvp.ioVSigWord != 0xd2d7) {
			/* HFS volume, use CurDirStore and GetCatInfo */
			name = buffer;
			accum = buf2;
			accum[0] = '\0';
			while (dirID != 2) {
				di.ioNamePtr = name;
				di.ioVRefNum = volume;
				di.ioFDirIndex = -1;
				di.ioDrDirID = dirID;
				PBGetCatInfo(&di, false);
				name[++name[0]] = ':';
				p2cstr(name);
				strcat(name, accum);
				tmp = accum;
				accum = name;
				name = tmp;
				dirID = di.ioDrParID;
			}
			strcat(fullname, accum);
		}
	}

	/* concatenate the volume and file names */
	strcat(fullname, file);
}

and as an extra, this-week-only bonus, here's what I call on Standard File's
vRefNum to get a (volume, directory) pair:

void
GetVolDir(invol, volume, directory)
word invol, *volume;
longword *directory;
{
	WDPBRec wdpb;
	String(70) name;

	if (FSFCBLen < 0) {
		*volume = invol;
		*directory = 2;
		return;
	}

	/* in HFS, it's a working directory */
	wdpb.ioNamePtr = &name;
	wdpb.ioVRefNum = invol;
	wdpb.ioWDIndex = 0;
	wdpb.ioWDProcID = 0;
	wdpb.ioWDVRefNum = 0;
	PBGetWDInfo(&wdpb, false);
	*volume = wdpb.ioWDVRefNum;
	*directory = wdpb.ioWDDirID;
}

Sorry for the earlier misinformation.
-- 
Tim Maroney, {ihnp4,sun,well,ptsfa,lll-crg}!hoptoad!tim; hoptoad!tim@lll-crg
"What's bad? What's the use of turning?
 In Hell I'll be there a-burning!
 Meanwhile, think of what I'm earning
 All on account of my name." - Bill Sykes, "Oliver"
Technical Details
Message-ID: <3604@hoptoad.uucp>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!cbosgd!ucbvax!hoptoad!tim
References: <wVjwa3y00UhngLo0D3@andrew.cmu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!cbosgd!ucbvax!hoptoad!tim
From: tim@hoptoad.uucp (Tim Maroney)
Newsgroups: comp.sys.mac
Subject: Re: Reading a full pathname in HFS - source code
Message-ID: <3604@hoptoad.uucp>
Date: 12 Dec 87 03:21:00 GMT
References: <wVjwa3y00UhngLo0D3@andrew.cmu.edu>
Reply-To: tim@hoptoad.UUCP (Tim Maroney)
Organization: Sun Microsystems, TOPS Division, Berkeley
Lines: 86