Q: How can I reliably determine if a volume is
mounted over the network ?
A: The best way to determine whether a volume
is mounted over the network is to compare the vMServerAdr field of the
GetVolParmsInfoBuffer (returned by PBHGetVolParms ) to zero. This field is zero on local
volumes and non-zero on network volumes. This technique is illustrated by the isNetworkVolume routine defined in
the DTS sample code MoreFiles.
The vMServerAdr field is actually defined to be the
AppleTalk address (an AddrBlock ) of the server which
exports the volume. This makes sense for volumes mounted over
AppleTalk, but not for other types of network file systems, such as
AppleShare IP. However, a vMServerAdr value of non-zero
implies a network file system, even for non-AppleTalk network file
systems.
If you merely wish to determine whether a volume is an AppleShare
volume, you can do so by comparing the volume's controlling driver
reference number to the driver reference number of the ".AFPTranslator" driver.
The following code iterates the volume list, printing all the
volumes that are controlled by AFP:
static void PrintAFPVolumes()
{
OSErr err;
HVolumeParam volPB;
Str255 volName;
DriverRefNum afpRefNum;
SInt16 index;
err = OpenDriver("\p.AFPTranslator", &afpRefNum);
if (err == noErr) {
index = 1;
do {
volName[0] = 0;
volPB.ioNamePtr = volName;
volPB.ioVRefNum = 0;
volPB.ioVolIndex = index;
err = PBHGetVInfoSync((HParmBlkPtr) &volPB);
if (err == noErr) {
if (volPB.ioVDrvInfo != 0 &&
volPB.ioVDRefNum == afpRefNum) {
printf("%#s\n", volName);
}
}
index += 1;
} while (err == noErr);
}
} |
|