Technote 1111Programmatic Mounting of AppleShare VolumesBy Leland Wallace |
CONTENTS
Introduction |
This Technote shows how to mount
an AppleShare volume using the |
IntroductionThe AppleShare Client implements the The first method is best used when you are remounting a volume
that has been mounted by the user. Identify the volume that you wish
to remount and call The second method entails creating your own Snippet #1: Finding the version of the AppleShare Client const short kASver_3_5 = 1; const short kASver_3_6 = 2; const short kASver_3_6_1 = 3; const short kASver_3_6_2 = 4; const short kASver_3_6_3 = 5; // incld. 3.6.3, 3.6.4, 3.6.5 const short kASver_3_7 = 6; // incld. 3.7.1 const short kASver_3_7_2 = 7; short ClientVersion(void) { long result; OSError theError = noErr; theError = Gestalt('afps',&result); if(!theError) { return(result & 0x0000ffff); } return 0; } |
AppleShare Clients 3.0 - 3.6.5AppleShare clients prior to version 3.7 mount volumes over
AppleTalk only. The More Files sample code
has a good example of using the struct AFPVolMountInfo { short length; /* length of location data (including self) */ VolumeType media; /* type of media */ short flags; /* bits for no messages, no reconnect */ SInt8 nbpInterval; /* NBP Interval parameter (IM2, p.322) */ SInt8 nbpCount; /* NBP Interval parameter (IM2, p.322) */ short uamType; /* User Authentication Method */ short zoneNameOffset; /* short positive offset from start of struct to Zone Name */ short serverNameOffset; /* offset to pascal Server Name string */ short volNameOffset; /* offset to pascal Volume Name string */ short userNameOffset; /* offset to pascal User Name string */ short userPasswordOffset; /* offset to pascal User Password string */ short volPasswordOffset; /* offset to pascal Volume Password string */ char AFPData[176]; /* variable length data may follow */ }; typedef struct AFPVolMountInfo AFPVolMountInfo; |
AppleShare Client 3.7AppleShare Client 3.7 has several new features dealing with volume mounting:
As you can see, the AFPXVolMountInfo structure is an extension of the AFPVolMountInfo structure defined above. The three new fields and two new flag bits allow the developer to specify the information needed to support TCP/IP and UAMs. The 3.7 Client will also support the old AFPVolMountInfo struct. From the latest /* AFPXVolMountInfo is the new AFP volume mount info record, requires the 3.7 AppleShare Client */ struct AFPXVolMountInfo { short length; /* length of location data (including self) */ VolumeType media; /* type of media */ short flags; /* bits for no messages, no reconnect */ SInt8 nbpInterval; /* NBP Interval parameter (IM2, p.322) */ SInt8 nbpCount; /* NBP Interval parameter (IM2, p.322) */ short uamType; /* User Authentication Method type */ short zoneNameOffset; /* short positive offset from start of struct to Zone Name */ short serverNameOffset; /* offset to pascal Server Name string */ short volNameOffset; /* offset to pascal Volume Name string */ short userNameOffset; /* offset to pascal User Name string */ short userPasswordOffset; /* offset to pascal User Password string */ short volPasswordOffset; /* offset to pascal Volume Password string */ short extendedFlags; /* extended flags word */ short uamNameOffset; /* offset to a pascal UAM name string */ short alternateAddressOffset; /* offset to Alternate Addresses in tagged format */ char AFPData[176]; /* variable length data may follow */ }; typedef struct AFPXVolMountInfo AFPXVolMountInfo; typedef AFPXVolMountInfo * AFPXVolMountInfoPtr; /* volume mount flags */ enum { volMountNoLoginMsgFlagBit = 0, /* Input to VolumeMount: If set, the file system */ volMountNoLoginMsgFlagMask = 0x0001, /* should suppresss any log-in message/greeting dialog */ volMountExtendedFlagsBit = 7, /* Input to VolumeMount: If set, the mount info is a */ volMountExtendedFlagsMask = 0x0080, /* AFPXVolMountInfo record for 3.7 AppleShare Client */ volMountInteractBit = 15, /* Input to VolumeMount: If set, it's OK for the file system */ volMountInteractMask = 0x8000, /* to perform user interaction to mount the volume */ volMountChangedBit = 14, /* Output from VoumeMount: If set, the volume was mounted, but */ volMountChangedMask = 0x4000, /* the volume mounting information record needs to be updated. */ volMountFSReservedMask = 0x00FF, /* bits 0-7 are defined by each file system for its own use */ volMountSysReservedMask = 0xFF00 /* bits 8-15 are reserved for Apple system use */ }; enum { kAFPExtendedFlagsAlternateAddressMask = 1 /* bit in AFPXVolMountInfo.extendedFlags that means alternateAddressOffset is used*/ };
In order to use the new features of the To have the AppleShare Client put up the login dialog, set the volMountInteractBit in the flags word. Make sure you have an A5 world and have initialized QuickDraw and the DialogManager before making this call with the bit set. You also must have this bit set if you are using a UAM other than the standard Apple ones. AppleShare Client 3.7.2 and later: If you leave the volume name blank in the AFPXVolMountInfo structure, the Client will put up the volume select window, allowing the user to choose which volumes to mount. The The Alternate Address offset specifies an offset to a block of tagged data, containing IP addresses. The Block begins with a version byte and a count byte, followed by up to 255 tagged addresses, see below for the format. The current version byte is 0x00. Connecting to an IP addressTo connect to a server over TCP/IP, you need to copy the IP address into an address tag and put the address tag into the Alternate Address field. A server name is still required, though it is not currently used. If you also specify a zone name the Client will fall back to AppleTalk if it cannot connect via TCP/IP, it will set the volMountChangedBit in the flags word if it falls back. An example Alternate Address field for address 128.0.10.1 would look like this:
The client would use this address to connect to the default AFP over TCP/IP port 548 on the machine denoted by the address 128.0.10.1. Tagged data for Addresses.The new tagged data format accommodates changes in address
formats, which will allow this client to support new addressing
standards such as IPv6 (IPNG) without changing the interface. The
first byte of the Alternate Address area is a version byte, currently
set to 0. It is followed by an Each Data Item consists of a length byte followed by a tagID byte followed by up to 254 bytes of data. ie | len | tag | up to 254 bytes of data | The 3.7 Client understands the following tags:
The length byte specifies the length of the whole tag, including the length byte. All fields are in network byte order. (MSB first) From the latest enum { /* constants for use in AFPTagData.fType field*/ kAFPTagTypeIP = 0x01, kAFPTagTypeIPPort = 0x02, kAFPTagTypeDDP = 0x03 /* Currently unused*/ }; enum { /* constants for use in AFPTagData.fLength field*/ kAFPTagLengthIP = 0x06, kAFPTagLengthIPPort = 0x08, kAFPTagLengthDDP = 0x06 }; struct AFPTagData { UInt8 fLength; /* length of this data tag including the fLength field */ UInt8 fType; UInt8 fData[1]; /* variable length data */ }; typedef struct AFPTagData AFPTagData; struct AFPAlternateAddress { UInt8 fAddressCount; UInt8 fAddressList[1]; /* actually variable length packed set of AFPTagData */ }; typedef struct AFPAlternateAddress AFPAlternateAddress; Mounting a Volume using a Custom UAMA UAM is a code resource with a single entrypoint that takes a
selector. It lives in a file of type ' To use a Third-Party UAM for authentication, use the new VMIB
definition (with the extendedFlagsBit set in the flags
word), put the UAM type from the 'uamg' id 0 resource (from the UAM
file) in the uamType field, and put the
UAM Name into the VMIB at the
uamNameOffset. Then call You must make sure that you have an A5 world and have called
UAMNameThis is the AFP protocol name for the UAM, from the 'uamn' id 1 resource in the UAM file. It is a Pascal string.
|
Thanks to Pete Gontier, Joseph Husk, Barb Kozlowski, Rich Kubota, Peter N Lewis, and Alex Maluta.