mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-01-20 05:42:49 +08:00
use stat/2 rather than statvfs/2 to find file drive
This commit is contained in:
parent
476a8a50ea
commit
792c9b9808
21
src/fs.cpp
21
src/fs.cpp
|
@ -112,29 +112,30 @@ namespace fs
|
|||
string &basepath)
|
||||
{
|
||||
int rv;
|
||||
dev_t dev;
|
||||
string fullpath;
|
||||
unsigned long fsid;
|
||||
struct statvfs buf;
|
||||
struct stat st;
|
||||
|
||||
rv = ::fstatvfs(fd,&buf);
|
||||
if(rv == -1)
|
||||
rv = ::fstat(fd,&st);
|
||||
if(FSTAT_FAILED(rv))
|
||||
return -1;
|
||||
|
||||
fsid = buf.f_fsid;
|
||||
dev = st.st_dev;
|
||||
for(int i = 0, ei = srcmounts.size(); i != ei; i++)
|
||||
{
|
||||
fs::path::make(&srcmounts[i],fusepath,fullpath);
|
||||
|
||||
rv = ::statvfs(fullpath.c_str(),&buf);
|
||||
if(rv == -1)
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
if(FSTAT_FAILED(rv))
|
||||
continue;
|
||||
|
||||
if(st.st_dev != dev)
|
||||
continue;
|
||||
|
||||
if(buf.f_fsid == fsid)
|
||||
{
|
||||
basepath = srcmounts[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return (errno=ENOENT,-1);
|
||||
}
|
||||
|
|
|
@ -31,4 +31,9 @@
|
|||
#define LSTAT_FAIL -1
|
||||
#define LSTAT_FAILED(RV) ((RV) == LSTAT_FAIL)
|
||||
|
||||
#define FSTAT_SUCCESS 0
|
||||
#define FSTAT_SUCCEEDED(RV) ((RV) == FSTAT_SUCCESS)
|
||||
#define FSTAT_FAIL -1
|
||||
#define FSTAT_FAILED(RV) ((RV) == FSTAT_FAIL)
|
||||
|
||||
#endif /*__MERGERFS_SUCCESS_FAIL_HPP__ */
|
||||
|
|
Loading…
Reference in New Issue
Block a user