Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Files /
Chapter 2 - File Manager / Identifying Files, Directories, and Volumes


Working Directory Reference Numbers

The File Manager provides a method of identifying directories known as working directory reference numbers. A working directory is a temporary directory reference that the File Manager uses to specify both a directory and the volume on which it resides. Each working directory is assigned a working directory reference number at the time it is created. You can use this number in place of a volume reference number in all File Manager routines.

Note
Working directories were developed to allow applications written for the now-obsolete Macintosh file system to execute correctly when accessing volumes using the hierarchical file system. In general, your application should not create working directories and, in the few instances a working directory reference number is returned to your application, it should immediately convert that number to a volume reference number and directory ID.
The first file system available on Macintosh computers was the Macintosh file system (MFS), a "flat" file system in which all files are stored in a single directory. The hierarchical organization of folders within folders is an illusion maintained by the system software. As a result, you can identify a file under MFS simply by specifying its name and its volume. Typically, MFS routines require a volume reference number and a filename to specify a file.

To improve performance, especially with larger volumes, Apple Computer, Inc., introduced the hierarchical file system (HFS) on the Macintosh Plus computer and later
models. In HFS, a volume can be divided into smaller units known as directories, which can themselves contain files or other directories. This hierarchical relationship of folders corresponds to an actual hierarchical directory structure maintained on disk. (See "Data Organization on Volumes" beginning on page 2-52 for the precise details of this hierarchical directory structure.)

Each file on an HFS volume is stored in a directory, called the file's parent directory. To identify a file in HFS, you must specify its volume, its parent directory, and its name. The File Manager assigns each directory a directory ID, and the user or the system software assigns each directory a name. The HFS File Manager routines include an additional parameter to handle the directory specification.

To keep existing applications running smoothly, Apple Computer, Inc. introduced the concept of working directories. A working directory is a combined directory and volume specification. To make a directory into a working directory, the File Manager establishes a working directory control block that contains both the volume and the directory ID of the target directory. The File Manager returns a unique working directory reference number, which you can use instead of the volume reference number in all routines.

Note
If your application provides both a directory ID and a working directory reference number, the directory ID is used to specify the directory (overriding the working directory specified by the working directory reference number). The working directory reference number is used to specify the volume (unless a volume name, which overrides all other forms of volume specification, is also provided).
The best course of action is to avoid using working directories altogether. In the few cases where system software returns a working directory reference number to your application, the recommended practice is to immediately convert that working directory reference number into its corresponding directory ID and volume reference number (using PBGetWDInfo or its high-level equivalent, GetWDInfo).

In system software versions 7.0 and later, the Process Manager closes all working directories opened on behalf of your application when it terminates (quits or crashes).
If your application might also run under earlier system software versions, you need to
be careful to close any such working directories before you quit (using PBCloseWD or
its high-level equivalent, CloseWD).


Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996