Volume name

Discussion in 'Mac Programming' started by VijayKumar, Sep 30, 2005.

  1. VijayKumar macrumors newbie

    Joined:
    Sep 30, 2005
    #1
    Hi,

    Can someone please help me to obtain programmatically (preferably C) the volume name of a usb storage device that is connected to a Mac (10.4) system?

    Thanks in advance,
    Vijay
     
  2. chaithrika macrumors newbie

    Joined:
    Nov 24, 2008
    #2
    You can use DiskArbitration framework. There are APIs that can solve your problem.
     
  3. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  4. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #4
    You can use this (C and Carbon.framework):

    Code:
        // Iterate across all mounted volumes
        for (volIndex=1; noErr == result || nsvErr != result; volIndex++) {
            FSVolumeRefNum 	volRef;
            HFSUniStr255 	volName;
            FSVolumeInfo 	volInfo;
            
            bzero((void *) &volInfo, sizeof(volInfo));
            result = FSGetVolumeInfo(kFSInvalidVolumeRefNum, 
                                    volIndex,
                                    &volRef,
                                    kFSVolInfoFSInfo + kFSVolInfoSizes + kFSVolInfoFlags,
                                    &volInfo,
                                    &volName,
                                    NULL);
        }
    
    Volume name will be in volName for each volume found. Volume names are unicode-based and the HFSUniStr255 is a special string format used only here, you must convert it to something else for more wide-spread use in Mac OS X.

    You can make an NSString (Objective-C Cocoa framework from volName using:

    Code:
    [NSString stringWithCharacters:volName.unicode length:volName.length]
    And similar for a CFStringRef for C Carbon framework.
     

Share This Page