Search code examples
c++linuxmount

In Linux in C/C++ how to determine filesystem type of a mounted or unmounted partition


# blkid /dev/sdX gives the filesystem type of the partition whether mounted or unmounted. How can I do it from C/C++ with out invoking a system call and parsing the out put? How can I do it programatically? Is there any blkid-dev package?


Solution

  • You always can use the blkid libraries (for ubuntu it's as easy as installing libblkid-dev). And for the real usage see: https://github.com/fritzone/sinfonifry/blob/master/plugins/disk_status/client/disk_status.cpp (sorry for advertising code from my own repository, but it has exactly this functionality developed there). And do not forget, that you will need to run the application with sudo in order to have full access to the disk.