API to get the list of Volumes on Mac?

Discussion in 'Mac Programming' started by vishal.chauhan, Feb 4, 2008.

  1. macrumors newbie

    Feb 4, 2008
    Hi All,

    I am working on Mac OS 10.4.10 on my Mac Intel.
    I can get the list of all the Disk on my MAC by following..

    CFMutableDictionaryRef classesToMatch;
    kern_return_t kernResult = KERN_FAILURE;

    classesToMatch = IOServiceMatching( kIOMediaClass );
    if ( classesToMatch == NULL ) goto Bail;
    CFDictionarySetValue( classesToMatch, CFSTR(kIOMediaWholeKey), kCFBooleanTrue );

    kernResult = IOServiceGetMatchingServices( kIOMasterPortDefault, classesToMatch, mediaIterator );

    then Iterate through the mediaIterator.

    Now I want to search the volume on my Mac through programming.
    I have search for the APIs for the same but with no luck thus I have found the function to get the properties of the Volume by FSGetVolumeInfo but I donot know how to get the list of volumes.

  2. Moderator emeritus


    Jun 15, 2000
    You can use the getmntinfo function. Here's some sample code:

    #include <sys/mount.h>
    struct statfs *buf = NULL;
    unsigned i, count = 0;
    count = getmntinfo(&buf, 0);
    for (i=0; i<count; i++)
    	char *volName = buf[i].f_mntonname;
    	printf("Volume: %s\n", volName);
  3. macrumors G5


    Nov 25, 2005
    Call FSGetVolumeInfo and pass numbers 1, 2, 3 etc. as the volumeIndex parameter. That will give you the information about the 1st, 2nd, 3rd etc. volume. Eventually one call will return an error because there are no more volumes.
  4. thread starter macrumors newbie

    Feb 4, 2008
    Thanks for Reply.

    Yes I do getting the list of volumes on my Mac now.
    But now I have another problem that I can get various properties of the Voulme but I also want to know the start of the volume(either in terms of Sector no or in terms of block).

    So would it is possible to get the start of the volume in the disk.
  5. macrumors G5


    Nov 25, 2005
    That is a question that might not even make sense. Connect to another computer using Samba or mount a volume on another Macintosh. Mount a Disk Image. Put a recordable CD into your computer. Check how your list of volumes changes. A good one is this: In XCode 3, create a snapshot of your project. Then check the list of volumes again.

    I think it might be better if you describe what you actually want to achieve.
  6. thread starter macrumors newbie

    Feb 4, 2008
    Actually I mean by sector starting that suppose a disk has 100000 sector and it has 2 volumes.

    So first few sector is for the of disk own information and then there should be the start of the volume for which we have signature H+ or BD.

    So I want to know how can I get the start of the volume within a disk that is logical start of volume.

Share This Page