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.
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
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