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

Discussion in 'Mac Programming' started by info1686, Apr 14, 2009.

  1. info1686 macrumors newbie

    Jan 21, 2009
    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.

    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");
                            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?

  2. kainjow Moderator emeritus


    Jun 15, 2000
    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?
  3. wrldwzrd89 macrumors G5


    Jun 6, 2003
    Solon, OH
    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.
  4. info1686 thread starter macrumors newbie

    Jan 21, 2009
    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?
  5. wrldwzrd89 macrumors G5


    Jun 6, 2003
    Solon, OH
    Mac OS X is incompatible with the older HFS format. It has always required HFS Plus.

Share This Page