Determining the Features of the File Manager
Some of the capabilities provided by the File Manager depend on the version of system software that is running, and some others depend on the characteristics of the target volume. For example, the routines that acceptFSSpec
records as file or directory specifications were introduced in system software version 7.0 and are unavailable in earlier system software versions--unless your software development system provides "glue" that allows you to call those routines when running in earlier system software versions (or unless some system extension provides those routines). Similarly, some volumes support features that other volumes do not; a volume that has local file
sharing enabled, for instance, allows you to lock byte ranges in any files on a volume
that is sharable.Before using any of the File Manager features that are not universally available in all system software versions and on all volumes, you should check for that feature's availability by calling either the
Gestalt
function or thePBHGetVolParms
function, according to whether the feature's presence depends on the system software or the characteristics of the volume.You can use
Gestalt
to determine whether or not you can call the functions that accept and supportFSSpec
records. CallGestalt
with thegestaltFSAttr
selector to check for File Manager features. Theresponse
parameter currently has two relevant bits:
CONST gestaltFullExtFSDispatching = 0; {exports HFSDispatch traps} gestaltHasFSSpecCalls = 1; {supports FSSpec records}Constant descriptions
The chapter "Introduction to File Management" in this book illustrates how to use the
gestaltFullExtFSDispatching
If set, all of the routines selected through the_HFSDispatch
trap are available to external file systems. If this bit is clear, the File Manager checks the selector passed to_HFSDispatch
and ensures that it is valid; if the selector is invalid, the result codeparamErr
is returned to the caller. If this bit is set, no such validity checking is performed.gestaltHasFSSpecCalls
If set, the operating environment provides the file system specification versions of the basic file-manipulation functions, plus theFSMakeFSSpec
function.Gestalt
function to determine whether the operating environment supports the routines that acceptFSSpec
records. For a complete description of theGestalt
function, see the chapter "Gestalt Manager" in Inside Macintosh: Operating System Utilities.To test for the availability of the features that depend on the volume, you can call the low-level function
PBHGetVolParms
. Listing 2-1 illustrates how you can determine whether thePBCatSearch
function is available before using it to search a volume's catalog. Note that the SupportsCatSearch function defined in Listing 2-1 first callsGestalt
to determine whether the File Manager supportsPBCatSearch
. If it does, the SupportsCatSearch function callsPBHGetVolParms
to see if the indicated volume also supportsPBCatSearch
.Listing 2-1 Testing for
PBCatSearch
FUNCTION SupportsCatSearch (vRefNum: Integer): Boolean; VAR myHPB: HParamBlockRec; infoBuffer: GetVolParmsInfoBuffer; attrib: LongInt; BEGIN SupportsCatSearch := FALSE; {assume no PBCatSearch support} IF gHasGestalt THEN {set this somewhere else} IF Gestalt(gestaltFSAttr, attrib) = noErr THEN IF BTst(attrib, gestaltFullExtFSDispatching) THEN BEGIN {this File Mgr has PBCatSearch} WITH myHPB DO BEGIN ioNamePtr := NIL; ioVRefNum := vRefNum; ioBuffer := @infoBuffer; ioReqCount := SIZEOF(infoBuffer); END; IF PBHGetVolParms(@myHPB, FALSE) = noErr THEN IF BTST(infoBuffer.vMAttrib, bHasCatSearch) THEN SupportsCatSearch := TRUE; END; END;TheSupportsCatSearch
function callsPBHGetVolParms
for the volume whose reference number is passed as a parameter toSupportsCatSearch
. ThePBHGetVolParms
function returns information about a volume in a record of typeGetVolParmsInfoBuffer
. ThevMAttrib
field of that record contains a number of bits that encode information about the capabilities of the target volume. In particular, the bitbHasCatSearch
is set if the specified volume supports thePBCatSearch
function.
- Note
- Some features of volumes might change dynamically during the execution of your application. For example, the user can turn File Sharing on and off, thereby changing the capabilities of volumes. See "Locking and Unlocking File Ranges" on page 2-50 for more details.