Important: The information in this document is obsolete and should not be used for new development.
Sharing Volumes and Directories
The File Manager includes several functions that allow you to manipulate share points on local volumes that have file sharing enabled and to obtain a list of user and group names and IDs recognized by the local file server. These functions are especially useful
if you need to implement a dialog box that allows the user to designate a volume or directory as a share point or to set the owner, user, and group of a shared folder.The
PBShare
function makes a volume or directory a share point, hence available on the network. ThePBUnshare
function undoes the effects ofPBShare
: it makes an existing share point unavailable on the network. ThePBGetUGEntry
function lets you create a list of user and group names and IDs on the local server.Before calling any of these functions, you should check whether file sharing is
enabled on the local machine and, if so, whether the desired local volume is sharable. You can determine whether a particular volume is sharable by using the functionVolIsSharable
defined in Listing 2-7.Listing 2-7 Determining whether a volume is sharable
FUNCTION VolIsSharable (vRefNum: Integer): Boolean; VAR myHPB: HParamBlockRec; myInfoBuffer: GetVolParmsInfoBuffer; myErr: OSErr; BEGIN WITH myHPB DO BEGIN ioNamePtr := NIL; ioVRefNum := vRefNum; ioBuffer := @myInfoBuffer; ioReqCount := SizeOf(myInfoBuffer); END; myErr := PBHGetVolParms(@myHPB, FALSE); IF myErr = noErr THEN IF BTst(myInfoBuffer.vMAttrib, bHasPersonalAccessPrivileges) THEN VolIsSharable := TRUE ELSE VolIsSharable := FALSE ELSE VolIsSharable := FALSE; END;TheVolIsSharable
function inspects thebHasPersonalAccessPrivileges
bit returned in thevMAttrib
field of the volume attributes buffer it passed toPBHGetVolParms
. If this bit is set, local file sharing is enabled on the specified volume.You can use the function
SharingIsOn
defined in Listing 2-8 to determine whether file sharing is enabled on the local machine.Listing 2-8 Determining whether file sharing is enabled
FUNCTION SharingIsOn: Boolean; VAR myHPB: HParamBlockRec; myErr: OSErr; volIndex: Integer; sharing: Boolean; BEGIN sharing := FALSE; {assume file sharing is off} volIndex := 1; REPEAT WITH myHPB DO BEGIN ioNamePtr := NIL; ioVolIndex := volIndex; END; myErr := PBHGetVInfo(@myHPB, FALSE); IF myErr = noErr THEN sharing := VolIsSharable(myHPB.ioVRefNum); volIndex := volIndex + 1; UNTIL (myErr <> noErr) OR sharing; SharingIsOn := sharing; END;TheSharingIsOn
function simply calls theVolIsSharable
function for each local volume (or until a sharable volume is found). It uses indexed calls toPBHGetVInfo
to obtain the volume reference number of each mounted volume.