[comp.sys.mac.programmer] The Prefered Way to Refer to Files...

wayner@svax.cs.cornell.edu (Peter Wayner) (03/13/90)

I've been coding up an application which needs to keep a list of files
and their locations on the disk. This list needs to be stable from boot
to boot and even between restores from backup. There are several ways this can
be done:

1) Full Path name
2) file name and DirId

Tech Note #240 something says that path names are not as robust as
directory ids because directory ids are preserved when directories are
moved. On the other hand, it admits that restoring a file from backups
will probably not preserve Directory Id's. 

My questions are;

Are there any other problems with pathnames? 

How can I convert a DirId into a vRef which I can then use
with SFOpen? Or more generally, how can I open a file with 
a name and a DirId?

What about System 7.0? The tech note mentions that file id numbers
will be the best when System 7.0 comes around because they will be
stable even after renaming.


Thanks to every kind hearted and knowledgable soul on the net,

Peter Wayner
(wayner@cs.cornell.edu)

Peter Wayner   Department of Computer Science Cornell Univ. Ithaca, NY 14850
EMail:wayner@svax.cs.cornell.edu    Office: 607-255-9202
Home: 119 Ferris Place, Ithaca, NY 14850  Phone: 607-277-0785

brecher@well.sf.ca.us (Steve Brecher) (03/14/90)

In article <38534@cornell.UUCP>, wayner@svax.cs.cornell.edu (Peter Wayner)
writes:
> I've been coding up an application which needs to keep a list of files
> and their locations on the disk. This list needs to be stable from boot
> to boot and even between restores from backup. There are several ways
> this can be done:
> 
> 1) Full Path name
> 2) file name and DirId
>

2) should be volume name, file name, and DirID.

> Tech Note #240 something says that path names are not as robust as
> directory ids because directory ids are preserved when directories are
> moved. On the other hand, it admits that restoring a file from backups
> will probably not preserve Directory Id's.
> 
> My questions are;
> 
> Are there any other problems with pathnames?

The other problem with pathnames is that they may exceed 255 bytes in
length, which may make them difficult to use.

The best approach would be to store both (1) and (2), with code to
handle the 256+ length problem mentioned above.  When accessing the
file, use (2); if that works, update (1).  If (2) doesn't work, use (1)
and update (2). However, few if any products actually do this; my own
current products use (2) only.  One of them (PowerStation) has a command
to search all online disks for "lost" files, as typically occurs after
an initialize/restore.

> How can I convert a DirId into a vRef which I can then use with [FSOpen]?
> Or more generally, how can I open a file with a name and a DirId?

As noted above, you will nead a volume specifier in addition to file
name and DirID.  Instead of using FSOpen, you can use PBHOpen.  But to
answer the question:  you would create a WD with OpenWD, and then pass a
WDRefNum instead of a VRefNum to FSOpen.  Since WDs occupy a system-wide
table of limited size, you would clean up afterwards with CloseWD.

> What about System 7.0? The tech note mentions that file id numbers will
> be the best when System 7.0 comes around because they will be stable
> even after renaming.

Right, but it ain't here yet; also, you will probably want your
application to run under earlier systems.  In a couple of years or so it
will be feasible to require System 7 or later, just as circa 1988 it
became feasible to require the Mac Plus feature set (introduced in early
1986).
-- 

brecher@well.sf.ca.us (Steve Brecher)

russotto@eng.umd.edu (Matthew T. Russotto) (03/15/90)

In article <16681@well.sf.ca.us> brecher@well.sf.ca.us (Steve Brecher) writes:
>
>In article <38534@cornell.UUCP>, wayner@svax.cs.cornell.edu (Peter Wayner)
>writes:
>
>> What about System 7.0? The tech note mentions that file id numbers will
>> be the best when System 7.0 comes around because they will be stable
>> even after renaming.
>
>Right, but it ain't here yet; also, you will probably want your
>application to run under earlier systems.  In a couple of years or so it
>will be feasible to require System 7 or later, just as circa 1988 it
>became feasible to require the Mac Plus feature set (introduced in early
>1986).
File IDs (though apparently not the same as Sys 7 file IDs) are actually stable
now-- they are one way of finding a file after it has been moved/renamed.
The problem currently is that you need to search the entire catalog structure
to find it, and a backup/initialize/restore still changes it.
--
Matthew T. Russotto	russotto@eng.umd.edu	russotto@wam.umd.edu
][, ][+, ///, ///+, //e, //c, IIGS, //c+ --- Any questions?