Checking to see if a server volume is already mounted?

  • Hello,

    I'm using FSMountServerVolumeSync in a thread to mount an iDisk:

    FSMountServerVolumeSync((CFURLRef)[dictionary valueForKey: @"url"],
    NULL, (CFStringRef)[dictionary valueForKey: @"username"],
    (CFStringRef)[dictionary valueForKey: @"password"], NULL, 1);

    However, I don't want to mount the iDisk again if its already
    mounted.  So far I haven't found a way to check and see if the iDisk
    is already other than checking to see if the /Volume/dotmac_username
    directory exists.  Checking for the directory just seems like a bad
    idea because the directory can exist even if the iDisk isn't actually
    mounted.

    Any suggestions?

    Thanks,

    Adhamh
  • Here's the solution, pretty straight forward.  [dictionary
    valueForKey:@"username"] is the .Mac username as returned by the
    username method of DMTransaction.

    NSString *mountediDisk = nil;
    struct statfs *buf;
    int i, count;
    const char *vol = [[NSString stringWithFormat: @"/Volumes/%@",
    [dictionary valueForKey: @"username"]] UTF8String];
    count = getmntinfo(&buf, 0);
    for(i=0; i < count; i++) {
      if(strcmp(buf[i].f_mntonname, vol) == 0)
      mountediDisk = [NSString stringWithUTF8String: buf[i].f_mntfromname];
    }

    mountediDisk ends up being @"http://idisk.mac.com/adhamh" for my user.

    On Oct 30, 2007, at 4:33 PM, Adhamh Findlay wrote:

    > Hello,
    >
    > I'm using FSMountServerVolumeSync in a thread to mount an iDisk:
    >
    > FSMountServerVolumeSync((CFURLRef)[dictionary valueForKey: @"url"],
    > NULL, (CFStringRef)[dictionary valueForKey: @"username"],
    > (CFStringRef)[dictionary valueForKey: @"password"], NULL, 1);
    >
    > However, I don't want to mount the iDisk again if its already
    > mounted.  So far I haven't found a way to check and see if the
    > iDisk is already other than checking to see if the /Volume/
    > dotmac_username directory exists.  Checking for the directory just
    > seems like a bad idea because the directory can exist even if the
    > iDisk isn't actually mounted.
    >
    > Any suggestions?
    >
    > Thanks,
    >
    > Adhamh
  • Be careful. Mountpoints in /Volumes are not guaranteed to have the
    same name as what you see in the Finder. For instance, rename your
    hard drive to "Adhamh" and then mount your iDisk and see what its
    mountpoint name is. (I'd guess Adhamh-1, but there's no guarantee of
    that either.)

    On Oct 30, 2007, at 7:03 PM, Adhamh Findlay wrote:

    > Here's the solution, pretty straight forward.  [dictionary
    > valueForKey:@"username"] is the .Mac username as returned by the
    > username method of DMTransaction.
    >
    > NSString *mountediDisk = nil;
    > struct statfs *buf;
    > int i, count;
    > const char *vol = [[NSString stringWithFormat: @"/Volumes/%@",
    > [dictionary valueForKey: @"username"]] UTF8String];
    > count = getmntinfo(&buf, 0);
    > for(i=0; i < count; i++) {
    > if(strcmp(buf[i].f_mntonname, vol) == 0)
    > mountediDisk = [NSString stringWithUTF8String: buf
    > [i].f_mntfromname];
    > }
    >
    > mountediDisk ends up being @"http://idisk.mac.com/adhamh" for my user.
    >
    >
    >
    > On Oct 30, 2007, at 4:33 PM, Adhamh Findlay wrote:
    >
    >> Hello,
    >>
    >> I'm using FSMountServerVolumeSync in a thread to mount an iDisk:
    >>
    >> FSMountServerVolumeSync((CFURLRef)[dictionary valueForKey:
    >> @"url"], NULL, (CFStringRef)[dictionary valueForKey: @"username"],
    >> (CFStringRef)[dictionary valueForKey: @"password"], NULL, 1);
    >>
    >> However, I don't want to mount the iDisk again if its already
    >> mounted.  So far I haven't found a way to check and see if the
    >> iDisk is already other than checking to see if the /Volume/
    >> dotmac_username directory exists.  Checking for the directory just
    >> seems like a bad idea because the directory can exist even if the
    >> iDisk isn't actually mounted.
    >>
    >> Any suggestions?
    >>
    >> Thanks,
    >>
    >> Adhamh

  • Excellent point!  This could should fix that problem:

    // check to see if the iDisk is already mounted.
    NSString *mountediDisk = nil;
    struct statfs *buf;
    int i, count;
    const char *idiskName = [[NSString stringWithFormat: @"http://
    idisk.mac.com/%@/", [dictionary valueForKey: @"username"]] UTF8String];
    count = getmntinfo(&buf, 0);
    for(i=0; i < count; i++) {
      if(strcmp(buf[i].f_mntfromname, idiskName) == 0)
      mountediDisk = [NSString stringWithUTF8String: buf[i].f_mntonname];
    }

    Instead of comparing f_mnttoname this compares f_mntfromname.  This
    should be a much more robust implementation.

    Thanks for catching that!

    Adhamh

    On Oct 30, 2007, at 9:49 PM, John Stiles wrote:

    > Be careful. Mountpoints in /Volumes are not guaranteed to have the
    > same name as what you see in the Finder. For instance, rename your
    > hard drive to "Adhamh" and then mount your iDisk and see what its
    > mountpoint name is. (I'd guess Adhamh-1, but there's no guarantee
    > of that either.)
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today