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 / Using the File Manager


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. The PBUnshare function undoes the effects of PBShare: it makes an existing share point unavailable on the network. The PBGetUGEntry 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 function VolIsSharable 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;
The VolIsSharable function inspects the bHasPersonalAccessPrivileges
bit returned in the vMAttrib field of the volume attributes buffer it passed to PBHGetVolParms. 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;
The SharingIsOn function simply calls the VolIsSharable function for each local volume (or until a sharable volume is found). It uses indexed calls to PBHGetVInfo to obtain the volume reference number of each mounted volume.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996