Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

info1686

macrumors newbie
Original poster
Jan 21, 2009
13
0
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.

Code:
#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

Moderator emeritus
Jun 15, 2000
7,958
7
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

macrumors G5
Jun 6, 2003
12,110
77
Solon, OH
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

macrumors newbie
Original poster
Jan 21, 2009
13
0
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.