[net.micro.mac] Using file system calls in HFS - Beware of PMSP

mkg@lzaz.UUCP (Marsh Gosnell) (05/18/86)

I just discovered a feature of HFS that every programmer MUST watch out for.
If you get back "no error" from a FS call, the file that you accessed will
either be in the folder you thought it was or in the blessed folder (where the
System and Finder are).  Most of the time this is ok but if you assume that
success means the file is where you thought it was--watch out.

I have a program that copies files and was amazed when I was copying out of
the System folder, the "from" copy disappeared after the copy.  To get rid of
the destination file before copying, I was deleting it and ignoring any
"file not found" errors.  I hit the floor when the delete succeeded even though
there wasn't any destination file!!!

This behavior is caused by the Poor Man's Search Path or PMSP.  Here's a
description of how PMSP works from Mac Tech support:

        The PMSP is used for any call that can return a file not found error, 
such as PBOpen, PBClose, PBDelete, PBGetCatInfo, etc.  It is not used for 
indexed calls (that is, where ioFDirIndex is positive) or when a file is 
created (PBCreate) or when a file is being moved between directories (CatMove).
        Here's a brief description of how the PMSP works.  

1)  The specified directory is searched (specified by dirID or WDRefNum or 
pathname); if no file is found, 

2)  the volume/directory specified by boot drive (low-memory global at $210 is 
searched IF it is on the same volume as the specified directory (see #1 above); 
if no file is found, or the volume/directory is not on the same drive,  

3)  the 'blessed folder' is searched IF it is on the same volume as the 
specified directory (see #1 above);  if no file is found

4) fnfErr is returned.

Technotes will be fothcoming about PMSP.

As you can see, you have to be really careful when doing things like copying.
I looked at the source for Util in net.sources.mac and, if you try to copy out
of your blessed folder, you will distroy the file you're copying when Util
opens the "new" file and truncates it (assuming that there is no "new" file).

Hope this helps.
  Marsh Gosnell  ihnp4!lzma!mkg