determine volume name for folder that does not exist

  • Hey,

    I have been trying to determine the volume for a specific file path.
    I have been using NSFileManager's componentsToDisplayForPath to get
    the volume name, and then fileSystemAttributesAtPath to get info. The
    problem is componentsToDisplayForPath doesn't seem to work when the
    path doesn't exist. Is there a better way to give a potential path
    and determine if its volume exists?

    Thanks,
    Mitchell Livingston
  • Well, paths don't actually have any knowledge of what volume they are
    on (or if they're on a volume at all). Paths use mount points, which
    have arbitrary locations (in Mac OS X, this is defaulted to a folder
    in /Volumes/). However, if a volume is unmounted incorrectly, Mac OS
    X will append a number to the name of the mount point, thereby making
    the volume's name completely inconsistent with the path.

    It'd be much better (for the user) if you stored an alias instead of
    the path. Then even if the Alias does not resolve, you can call
    FSCopyAliasInfo() to get the volume name (the real volume name). Note
    that calling FSCopyAliasInfo() does no disk I/O and does not attempt
    to resolve the alias, which is actually a good thing if all you want
    is the info it returns.

    Ack, at 9/9/07, Mitchell Livingston said:

    > I have been trying to determine the volume for a specific file path.
    > I have been using NSFileManager's componentsToDisplayForPath to get
    > the volume name, and then fileSystemAttributesAtPath to get info.
    > The problem is componentsToDisplayForPath doesn't seem to work when
    > the path doesn't exist. Is there a better way to give a potential
    > path and determine if its volume exists?

    --

    Sincerely,
    Rosyna Keller
    Technical Support/Carbon troll/Always needs a hug

    Unsanity: Unsane Tools for Insanely Great People

    It's either this, or imagining Phil Schiller in a thong.
  • On 10 Sep 2007, at 01:42, Rosyna wrote:

    > Well, paths don't actually have any knowledge of what volume they
    > are on (or if they're on a volume at all). Paths use mount points,
    > which have arbitrary locations (in Mac OS X, this is defaulted to a
    > folder in /Volumes/). However, if a volume is unmounted
    > incorrectly, Mac OS X will append a number to the name of the mount
    > point, thereby making the volume's name completely inconsistent
    > with the path.

    You don't need a volume to be unmounted incorrectly to get this
    behaviour.  All you need to do is mount two volumes with the same
    volume name---volume names aren't unique, at least not on Mac OS X
    (maybe they were on previous Mac OS versions?)

    Incidentally, I don't know exactly how Carbon's aliases refer to
    volumes; I'd hope that they use the UUID in the HFS+ volume header
    (or similar UUID fields on other filesystems), but I'm not certain
    whether they actually do.  (Any Carbon experts?  Rosyna?)

    Anyway, this is a tricky problem and as Rosyna said, aliases are
    probably the best thing to use.

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net
previous month september 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
Go to today