• 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: FSGetVolumeMountInfoSize returns error -36?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FSGetVolumeMountInfoSize returns error -36?


  • Subject: Re: FSGetVolumeMountInfoSize returns error -36?
  • From: Jim Luther <email@hidden>
  • Date: Wed, 18 Aug 2010 22:15:36 -0700

As Quinn mentioned earlier, that won't catch all cases -- it only finds the simple cases. For example, if I mount a disk image from an image file that's on my hard disk (/dev/disk0s5), the mounted image volume is on a different device (/dev/disk3).

- Jim

On Aug 18, 2010, at 6:36 PM, Chris Suter wrote:



On Thu, Aug 19, 2010 at 8:33 AM, James Bucanek <email@hidden> wrote:
James Bucanek <mailto:email@hidden> wrote (Tuesday, August 17, 2010 11:04 AM -0700):


Poking around the I/O Registry, I think my best bet is walk up the tree and
find the highest IOMedia node. There appears to be one parent IOMedia node for
each partition of volumes, whether that's on a single hard disk or a RAID;
this is exactly what I'm looking for.

For anyone stumbling across this thread in the future, it's actually even simpler than I imagined. All you have to do is walk up the I/O Registry nodes (for which there's a convenient iterator) and look for the IOMedia node that has a 'Whole' property set to 'true'. The Whole=true property indicates a media object that represents a "whole" storage device, such as a hard disk, RAID, USB drive, CD/DVD, or disk image.

All of this is clearly demonstrated in the VolumeToBSDNode example. :)

For my application, I then extract the kIOBSDNameKey property which gives me a unique identifier for that device. I the volume has no I/O Registry node, or there's no "Whole" IOMedia node to be found, (which will be true in the case of network volumes) I fall back to using the filesystem number as my identifier. What you use in the non-device case will depend on your application.

That seems a whole lot more complicated than just calling statfs and looking at f_mntfromname. For example:

#include <strings.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <stdbool.h>
#include <ctype.h>

bool paths_on_same_device (const char *path_a, const char *path_b)
{
  struct statfs sfs_a, sfs_b;

  if (statfs (path_a, &sfs_a) || statfs (path_b, &sfs_b))
    return false;

  /* Check that the prefixes (which should be <prefix><unit>) of
     f_mntfromname match. */
  const char *pa = sfs_a.f_mntfromname, *pb = sfs_b.f_mntfromname;

  // First check the prefix
  do {
    if (*pa != *pb)
      return false;
    ++pa, ++pb;
  } while (*pa && *pb && !isdigit (*pa));

  // Now check the unit number
  while (*pa && *pb && isdigit (*pa)) {
    if (*pa != *pb)
      return false;
    ++pa, ++pb;
  }

  // We need this in case we have, say, /dev/disk1 & /dev/disk10
  return !isdigit (*pb);
}

I've not thoroughly tested it so there might be bugs.

Kind regards,

Chris
Do not post admin requests to the list. They will be ignored. Filesystem-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: FSGetVolumeMountInfoSize returns error -36?
      • From: Chris Suter <email@hidden>
References: 
 >Re: FSGetVolumeMountInfoSize returns error -36? (From: James Bucanek <email@hidden>)
 >Re: FSGetVolumeMountInfoSize returns error -36? (From: James Bucanek <email@hidden>)
 >Re: FSGetVolumeMountInfoSize returns error -36? (From: Chris Suter <email@hidden>)

  • Prev by Date: Re: FSGetVolumeMountInfoSize returns error -36?
  • Next by Date: Re: FSGetVolumeMountInfoSize returns error -36?
  • Previous by thread: Re: FSGetVolumeMountInfoSize returns error -36?
  • Next by thread: Re: FSGetVolumeMountInfoSize returns error -36?
  • Index(es):
    • Date
    • Thread