Вот еще код C ++, если вы хотите сделать это из C ++ ...
#include
#include
/// returns true if the path is a mount point
bool Stat::IsMount(const std::string& path)
{
if (path == "") return false;
if (path == "/") return true;
boost::filesystem::path path2(path);
auto parent = path2.parent_path();
struct stat sb_path;
if (lstat(path.c_str(), &sb_path) == -1) return false; // path does not exist
if (!S_ISDIR(sb_path.st_mode)) return false; // path is not a directory
struct stat sb_parent;
if (lstat(parent.string().c_str(), &sb_parent) == -1 ) return false; // parent does not exist
if (sb_path.st_dev == sb_parent.st_dev) return false; // parent and child have same device id
return true;
}
/// returns the path to the mount point that contains the path
std::string Stat::MountPoint(const std::string& path0)
{
// first find the first "real" part of the path, because this file may not exist yet
boost::filesystem::path path(path0);
while(!boost::filesystem::exists(path) )
{
path = path.parent_path();
}
// then look for the mount point
path = boost::filesystem::canonical(path);
while(! IsMount(path.string()) )
{
path = path.parent_path();
}
return path.string();
}
Дополнительные ссылки для программных способов