PDA

View Full Version : Mac OS X 10.4: getattrlist() to know the File-system type




info1686
Apr 14, 2009, 04:06 AM
Hello All,
I need to identify via a program the file-system types of all mounted volumes. There are 2 options : using getattrlist() or getmntinfo().

With getattrlist() ATTR_VOL_FSTYPE gives the file-system type as an unsigned long. From this how do I know if the volume is HFS/HFS+/UFS etc.


#include<stdio.h>
#include<sys/param.h>
#include<sys/ucred.h>
#include<sys/mount.h>
#include<errno.h>
#include<sys/types.h>
#include<string.h>
#include<errno.h>

struct AttrBuf
{
unsigned long length;
unsigned long fstype;
unsigned long fssign;
};

int main()
{
int count, i,errno,j;
struct statfs *mntbufp;
struct attrlist attrList;
struct AttrBuf attrbuf;

unsigned long signature;
char sign[5];

memset(&attrList, 0, sizeof(attrList));
memset(&attrbuf, 0, sizeof(attrbuf));

attrList.bitmapcount = ATTR_BIT_MAP_COUNT ;
attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_FSTYPE | ATTR_VOL_SIGNATURE ;

if((count = getmntinfo(&mntbufp, MNT_NOWAIT)) == 0)
perror("getmntinfo() failed\n");
else
{
for(i=0;i<count;i++)
{
printf("-------------------------------------------------------------\n");
printf("Mount point = %s\n",mntbufp[i].f_mntonname);
printf("Filesystem type = %s\n",mntbufp[i].f_fstypename);
if(getattrlist(mntbufp[i].f_mntonname , &attrList, &attrbuf, sizeof(attrbuf), FSOPT_NOFOLLOW) == -1)
perror("getattrlist() failed\n");
printf("FS type = %lu\n",attrbuf.fstype);
printf("Volume signature = %lu\n",attrbuf.fssign);
}
}

return 0;
}


This prints HFS+ volumes as FS type=17. Is this constant or may change? Is there some sort of mapping from this number to a file-system type?

When I use getmntinfo() to print the file-system type, it prints HFS+ volumes as HFS. Any solution for this?

Thanks



kainjow
Apr 14, 2009, 08:23 AM
Why can't you use f_fstypename? I've used that reliably.

Edit: oh the problem is HFS+ and HFS both show as HFS? Isn't HFS not used anymore and came from the OS 9 days?

wrldwzrd89
Apr 14, 2009, 09:00 AM
Why can't you use f_fstypename? I've used that reliably.

Edit: oh the problem is HFS+ and HFS both show as HFS? Isn't HFS not used anymore and came from the OS 9 days?
You are correct - the old HFS (not HFS+) isn't used anymore, and hasn't been since Mac OS 8.5. If you're working exclusively in a Mac OS X environment and aren't dealing with Mac OS 9 and earlier, then this won't be a problem.

info1686
Apr 14, 2009, 11:03 PM
Hi,
I would be working only on Mac OS X 10.4 onwards.
Is it possible that a drive has been formatted using HFS ? Or Mac OS X does not allow HFS volumes?

wrldwzrd89
Apr 15, 2009, 05:50 AM
Hi,
I would be working only on Mac OS X 10.4 onwards.
Is it possible that a drive has been formatted using HFS ? Or Mac OS X does not allow HFS volumes?
Mac OS X is incompatible with the older HFS format. It has always required HFS Plus.