I need to check filesystem type on a thumb drive in my C++ application. It must be done before mounting a new partition. I also prefer not to call system() function. I tried to use the following test code:
#include <blkid/blkid.h>
#include <stdio.h>
int main()
{
blkid_probe pr;
const char *ptname;
const char* devname = "/dev/sdb1";
pr = blkid_new_probe_from_filename(devname);
if (!pr)
printf("faild to open device\n");
else
{
blkid_probe_enable_partitions(pr, true);
blkid_do_fullprobe(pr);
blkid_probe_lookup_value(pr, "PTTYPE", &ptname, NULL);
printf("%s partition type detected\n", ptname);
blkid_free_probe(pr);
}
}
When I plug in thumb drive with ntfs this piece of code shows that my partions is dos. When I plug in thumb drive with fat or ext4 the code returns strange string but the same for these two filesystems:
AWAVI��AUATL�%� .
What causes these strange outputs? Maybe there is a better way to check a filesystem? Thank you in advance for any help.