mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-22 16:06:27 -05:00
misc cleanups
This commit is contained in:
parent
47bf58eae9
commit
9e0ab1f518
40 changed files with 559 additions and 432 deletions
94
src/fs.cpp
94
src/fs.cpp
|
|
@ -27,93 +27,57 @@
|
|||
#include "fs_base_realpath.hpp"
|
||||
#include "fs_base_stat.hpp"
|
||||
#include "fs_base_statvfs.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_xattr.hpp"
|
||||
#include "statvfs_util.hpp"
|
||||
#include "str.hpp"
|
||||
#include "success_fail.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace fs
|
||||
{
|
||||
bool
|
||||
exists(const string &path,
|
||||
struct stat &st)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = fs::lstat(path,st);
|
||||
|
||||
return LSTAT_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
bool
|
||||
exists(const string &path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
return exists(path,st);
|
||||
}
|
||||
|
||||
bool
|
||||
info(const string &path,
|
||||
bool &readonly,
|
||||
uint64_t &spaceavail,
|
||||
uint64_t &spaceused)
|
||||
int
|
||||
readonly(const string *path_,
|
||||
bool *readonly_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
{
|
||||
readonly = StatVFS::readonly(st);
|
||||
spaceavail = StatVFS::spaceavail(st);
|
||||
spaceused = StatVFS::spaceused(st);
|
||||
}
|
||||
rv = fs::statvfs(*path_,st);
|
||||
if(rv == 0)
|
||||
*readonly_ = StatVFS::readonly(st);
|
||||
|
||||
return STATVFS_SUCCEEDED(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool
|
||||
readonly(const string &path)
|
||||
int
|
||||
spaceavail(const string *path_,
|
||||
uint64_t *spaceavail_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
rv = fs::statvfs(*path_,st);
|
||||
if(rv == 0)
|
||||
*spaceavail_ = StatVFS::spaceavail(st);
|
||||
|
||||
return (STATVFS_SUCCEEDED(rv) && StatVFS::readonly(st));
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool
|
||||
spaceavail(const string &path,
|
||||
uint64_t &spaceavail)
|
||||
int
|
||||
spaceused(const string *path_,
|
||||
uint64_t *spaceused_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
spaceavail = StatVFS::spaceavail(st);
|
||||
rv = fs::statvfs(*path_,st);
|
||||
if(rv == 0)
|
||||
*spaceused_ = StatVFS::spaceused(st);
|
||||
|
||||
return STATVFS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
bool
|
||||
spaceused(const string &path,
|
||||
uint64_t &spaceused)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs(path,st);
|
||||
if(STATVFS_SUCCEEDED(rv))
|
||||
spaceused = StatVFS::spaceused(st);
|
||||
|
||||
return STATVFS_SUCCEEDED(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -146,7 +110,7 @@ namespace fs
|
|||
struct stat st;
|
||||
|
||||
rv = fs::fstat(fd,st);
|
||||
if(FSTAT_FAILED(rv))
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
dev = st.st_dev;
|
||||
|
|
@ -155,7 +119,7 @@ namespace fs
|
|||
fs::path::make(&srcmounts[i],fusepath,fullpath);
|
||||
|
||||
rv = fs::lstat(fullpath,st);
|
||||
if(FSTAT_FAILED(rv))
|
||||
if(rv == -1)
|
||||
continue;
|
||||
|
||||
if(st.st_dev != dev)
|
||||
|
|
@ -204,19 +168,21 @@ namespace fs
|
|||
const uint64_t minfreespace,
|
||||
string &path)
|
||||
{
|
||||
int rv;
|
||||
uint64_t mfs;
|
||||
uint64_t spaceavail;
|
||||
const string *basepath;
|
||||
const string *mfsbasepath;
|
||||
|
||||
mfs = 0;
|
||||
mfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
uint64_t spaceavail;
|
||||
const string &basepath = basepaths[i];
|
||||
basepath = &basepaths[i];
|
||||
|
||||
if(!fs::spaceavail(basepath,spaceavail))
|
||||
rv = fs::spaceavail(basepath,&spaceavail);
|
||||
if(rv == -1)
|
||||
continue;
|
||||
|
||||
if(spaceavail < minfreespace)
|
||||
continue;
|
||||
if(spaceavail <= mfs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue