[comp.sys.mac.programmer] Volume Name + dirID == ?

janee@ima.isc.com (Jane Eisenstein) (06/12/91)

I've been following the discussion on how to obtain permanent file
references.  I now know how to obtain the file's volume name and
and directory ID.  How do I use them to open the file?  In particular,
how do I use them to open a file on an unmounted volume whose absolute
pathname is > 255 characters long?

Thanks,
Jane Eisenstein

keith@Apple.COM (Keith Rollin) (06/12/91)

In article <1991Jun11.195057.20315@ima.isc.com> janee@ima.isc.com (Jane Eisenstein) writes:
>
>I've been following the discussion on how to obtain permanent file
>references.  I now know how to obtain the file's volume name and
>and directory ID.  How do I use them to open the file?  In particular,
>how do I use them to open a file on an unmounted volume whose absolute
>pathname is > 255 characters long?

Most often, one gets a reference to a file through StandardFile. Under
6.0.x, you get a vRefNum (which is really a working directory ID) and a
file name. You can turn the WD into a real vRefNum and dirID by calling
GetWDInfo. Under 7.0, you can make the Standard File call that already
returns a real vRefNum and dirID.

To get the name of a volume if you have its vRefNum, call GetVInfo with
the vRefNum and a pointer to a string buffer. To turn the name back into
a vRefNum later, you should be able to make another GetVInfo call.

To access the file once you have the vRefNum and dirID again, simply
stuff those values into the right parameters of whatever call you need
to make. For instance, HOpen explicitly takes a vRefNum, dirID, and
file name as parameters. The length of the absolute pathname is
irrelevant, as you never need to generate it.

-- 
------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc. 
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"But where the senses fail us, reason must step in."  - Galileo

llama@eleazar.dartmouth.edu (Joe Francis) (06/13/91)

janee@ima.isc.com (Jane Eisenstein) writes:


>I've been following the discussion on how to obtain permanent file
>references.  I now know how to obtain the file's volume name and
>and directory ID.  How do I use them to open the file?  In particular,
>how do I use them to open a file on an unmounted volume whose absolute
>pathname is > 255 characters long?

OK.  The following is shortened code to do that.  I'm skipping the
part about mounting volumes (hiden in the imaginary function
"MountViewerVolume", which also return the name of the mounted
volume).  If you are trying to mount AppleShare volumes, let me
know and I can post on that subject.  This is consensed code - no
error checking, let the buyer beware:

#include <Types.h>
#include <Files.h>

void OpenFile(StringPtr fileName, long dirID)

/*open file filename in directory dirID on whatever */
/*volume MountViewerVolume mystically mounts.       */

{
 short          vRefNum,sourceRefnum = 0;
 Str255         sourceName;
 short          wdRefNum;
 HParamBlockRec pb;

 MountViewerVolume((char*)(&sourceName));         /* mount volume */
 SetVol((StringPtr)(&sourceName),0);              /* make it current */
 GetVol((StringPtr)(&sourceName),&sourceRefnum);  /* get it's vol refnum */
 OpenWD(sourceRefnum,dirID,0,&wdRefNum);          /* make working dir */

 pb.fileParam.ioCompletion  = 0L;                 /* set up param block */
 pb.fileParam.ioVRefNum     = sourceRefnum;
 pb.fileParam.ioDirID       = dirID;
 pb.fileParam.ioNamePtr     = fileName;
 pb.fileParam.ioPermssn     = fsCurPerm;
 pb.fileParam.ioMisc        = 0L;
 PBOpen(&pb,false);                               /* open file  */
}

----------------------------------------------------------------------------
"Read My Lips: No Nude Texans!" - George Bush clearing up a misunderstanding

Edward.Rice@p4214.f421.n109.z1.FidoNet.Org (Edward Rice) (06/18/91)

JE> I've been following the discussion on how to obtain permanent file
JE> references.  I now know how to obtain the file's volume name and
JE> and directory ID.  How do I use them to open the file?  In particular,
JE> how do I use them to open a file on an unmounted volume whose absolute
JE> pathname is > 255 characters long?


Inside Mac again...

FUNCTION PBOpen (paramBlock: ParmBlkPtr; async: BOOLEAN) : OSErr;

Parameter block
    Q>  12  ioCompletion    pointer
    <Q  16  ioResult        word
    Q>  18  ioNamePtr       pointer
    Q>  22  ioVRefNum       word
    <Q  24  ioRefNum        word
    Q>  26  ioVersNum       byte
    Q>  27  ioPermssn       byte
    Q>  28  ioMisc          pointer

PBOpen creates an access path to the file having the name pointed to by ioNamePtr (and on flat volumes, the version number ioVersNum) on the volume specified by ioVRefNum. A path reference number is returned in ioRefNum.

IOMisc either points to a portion of memory (522 bytes) to be used as the access pathUs buffer, or is NIL if you want the volume buffer to be used instead.


Of course, on S/7, you can use aliases to shorten pathnames, if you're trying to handle the ">255 character pathname" in that environment.

 * Origin: "It's still in beta testing," Tom said pointedly. (1:109/421.4214)

dorner@pequod.cso.uiuc.edu (Steve Dorner) (06/18/91)

In article <677239715.1@blkcat.FidoNet> Edward.Rice@p4214.f421.n109.z1.FidoNet.Org (Edward Rice) writes:

>IOMisc either points to a portion of memory (522 bytes) to be used as the
>access pathUs buffer, or is NIL if you want the volume buffer to be used
>instead.

Beware.  Failure to set this field properly will lead to very unpleasant
and mysterious results on SE's and earlier.  I think newer ROMS either
ignore the value or do some sort of sanity checking on it.

I speak from personal experience...
--
Steve Dorner, U of Illinois Computing Services Office
Internet: s-dorner@uiuc.edu  UUCP: uunet!uiucuxc!uiuc.edu!s-dorner