• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to identify the server from which a volume was mounted?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to identify the server from which a volume was mounted?


  • Subject: Re: How to identify the server from which a volume was mounted?
  • From: Jerry Krinock <email@hidden>
  • Date: Thu, 2 Jul 2009 14:10:16 -0700


On 2009 Jul 02, at 01:11, Quinn wrote:

There's no really good way to do this....

Generally I'd recommend you get the server URL using FSCopyURLForVolume and proceed from there.

Well, it seems to work good enough for me. Just document in such a way that someone won't expect it to work with the Klingon Filing Protocol of year 2025.


Thanks, Quinn.


#import <Cocoa/Cocoa.h>


@interface SSYVolumeServerGuy : NSObject { }

/*!
 @brief    Gets the volume reference number of a given path.

 @details  This method is a wrapper around FSGetCatalogInfo,
 which does return an OSErr, but we don't return it because
 most of the time the error is simply that your path is not
 a currently-mounted volume, unless something really weird
 happened.
 @result   The volume reference number of the given path,
 or 0 if it could not be obtained for any reason.
 */
+ (FSVolumeRefNum)volumeRefNumberForPath:(NSString*)path ;

/*!
 @brief    Returns the identifier of the host (server) from which
 a given mounted volume was mounted.

 @details  The host name of a volume mounted via Apple
 Filing Protocol (afp://) also includes the transport type
 after a dot separator.&nbsp;  In any case, another dot and
 the domain completes the identifier.  Example:
 *   "Suzie's Old Powerbook._afpovertcp._tcp.local"
 @param    volumeName  The mounted volume name (the path
 component after "/Volumes/") for which the host name
 is desired.
*/
+ (NSString*)hostForVolumeName:(NSString*)volumeName ;

/*!
 @brief    Returns the name of the server of a given volume
 which is mounted via Apple Filing Protocol (afp://)

 @details  Sends -hostnameForVolumeName and returns only the
 first path component of the result.
 @param    volumeName  See -hostnameForVolumeName
*/
+ (NSString*)afpServerDisplayNameForVolumeName:(NSString*)volumeName ;

@end


@implementation SSYVolumeServerGuy

+ (FSVolumeRefNum)volumeRefNumberForPath:(NSString*)path {
    FSRef pathRef;
    FSPathMakeRef(
                  (UInt8*)[path UTF8String],
                  &pathRef,
                  NULL
                  ) ;

    OSErr osErr;

    FSCatalogInfo catInfo;
    osErr = FSGetCatalogInfo(
                             &pathRef,
                             kFSCatInfoVolume,
                             &catInfo,
                             NULL,
                             NULL,
                             NULL
                             ) ;

    FSVolumeRefNum volumeRefNum = 0;

    if(osErr == noErr) {
        volumeRefNum = catInfo.volume;
    }

    return volumeRefNum ;
}

+ (NSString*)hostForVolumeName:(NSString*)volumeName {
NSString* path = [@"/Volumes" stringByAppendingPathComponent:volumeName] ;
FSVolumeRefNum volRefNum = [SSYVolumeServerGuy volumeRefNumberForPath:path] ;
NSString* host = nil ;
if (volRefNum != 0) {
CFURLRef url ;
// Note: OSStatus return value of this is ignored:
FSCopyURLForVolume (
volRefNum,
&url
) ;
host = [(NSURL*)url host] ;
}


    return host ;
}

+ (NSString*)afpServerDisplayNameForVolumeName:(NSString*)volumeName {
    NSString* host = [self hostForVolumeName:volumeName] ;
    NSArray* components = [host componentsSeparatedByString:@"."] ;
    NSString* serverDisplayName = nil ;
    if ([components count] > 0) {
        serverDisplayName = [components objectAtIndex:0] ;
    }

    return serverDisplayName ;
}

@end

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: How to identify the server from which a volume was mounted? (From: Quinn <email@hidden>)
 >Re: How to identify the server from which a volume was mounted? (From: Jerry Krinock <email@hidden>)
 >Re: How to identify the server from which a volume was mounted? (From: Quinn <email@hidden>)

  • Prev by Date: Re: Connecting To Wireless Network Using Application
  • Next by Date: Getting started communicating with AFP -- on the right track?
  • Previous by thread: Re: How to identify the server from which a volume was mounted?
  • Next by thread: How to get the tcp statistics counter "tcps_rcvbadsum"
  • Index(es):
    • Date
    • Thread