PDA

View Full Version : API to get the list of Volumes on Mac?




vishal.chauhan
Feb 4, 2008, 11:17 PM
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.

Thanks.
Vishal



kainjow
Feb 5, 2008, 01:36 AM
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);
}

gnasher729
Feb 5, 2008, 03:08 AM
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.

Thanks.
Vishal

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.

vishal.chauhan
Feb 5, 2008, 11:16 PM
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.

gnasher729
Feb 6, 2008, 03:36 AM
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.

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.

vishal.chauhan
Feb 6, 2008, 04:49 AM
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.