Currently we use stafs to determine the information about the filesystem volume we are on.
#include <string>
#include <iostream>
#include <sys/mount.h>
#include <sys/param.h>
void statFileSys(const std::string f)
{
struct statfs fileStat;
if(statfs(f.data(),&fileStat) == 0)
{
std::cout << "File type: " << fileStat.f_type <<'\n';
std::cout << "File system name: "<<fileStat.f_fstypename << '\n';
}
else
{
std::cout << "statfs failed !!!"<<std::endl;
}
}
int main()
{
statFileSys("/some/network/path");
statFileSys("/tmp");
return 0;
}
We rely on
f_type
value to make decisions based on whether its HFS+ or APFS or network file system.
However, we are seeing following weird output on three different macOS systems for above small standalone reproducible code.
1]
macOS 10.12 + HFS+
File type: 25
File system name: autofs
File type: 23
File system name: hfs
2]
macOS 10.13 (beta) + HFS+
File type: 24
File system name: autofs
File type: 23
File system name: hfs
3]
macOS 10.13 (beta) + APFS
File type: 25
File system name: autofs
File type: 24
File system name: apfs
For 2]
we get the f_type
value for the network path (autofs) as 24 and while in 3]
we get f_type
as 24 for APFS whch doesnt seem consistent.
This brings us to the qustion, is statfs
the correct programmatic way to find the filesystem volume info on macOS ?
If its not, then what would be the right way to do the same ?