From: Arvin Schnell Date: Fri, 18 Sep 2020 14:34:58 +0000 (+0200) Subject: - added function statvfs to class SDir X-Git-Tag: v0.8.14~7^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=60fe7d7f029442d6ba690760ebd7a58df496ba2a;p=thirdparty%2Fsnapper.git - added function statvfs to class SDir --- diff --git a/snapper/FileUtils.cc b/snapper/FileUtils.cc index 0b3c453d..4a4d8550 100644 --- a/snapper/FileUtils.cc +++ b/snapper/FileUtils.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -386,6 +387,21 @@ namespace snapper } + std::pair + SDir::statvfs() const + { + struct statvfs64 fsbuf; + if (fstatvfs64(dirfd, &fsbuf) != 0) + SN_THROW(IOErrorException(sformat("statvfs64 failed path:%s errno:%d (%s)", base_path.c_str(), + errno, stringerror(errno).c_str()))); + + // f_bavail is used (not f_bfree) since df seems to do the + // same. Thus it allows the user to check the result easily. + + return make_pair(fsbuf.f_blocks * fsbuf.f_bsize, fsbuf.f_bavail * fsbuf.f_bsize); + } + + int SDir::mktemp(string& name) const { diff --git a/snapper/FileUtils.h b/snapper/FileUtils.h index 3cd2e56e..b0a35f7e 100644 --- a/snapper/FileUtils.h +++ b/snapper/FileUtils.h @@ -93,6 +93,9 @@ namespace snapper int rename(const string& oldname, const string& newname) const; int fsync() const; + // Query size and free. + std::pair statvfs() const; + int mktemp(string& name) const; bool mkdtemp(string& name) const; diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 23086b1a..3366773b 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -1,6 +1,6 @@ /* * Copyright (c) [2011-2015] Novell, Inc. - * Copyright (c) [2016,2018] SUSE LLC + * Copyright (c) [2016-2020] SUSE LLC * * All Rights Reserved. * @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -795,13 +794,9 @@ namespace snapper quota_rescan(general_dir.fd()); sync(general_dir.fd()); - struct statvfs64 fsbuf; - if (fstatvfs64(general_dir.fd(), &fsbuf) != 0) - SN_THROW(QuotaException("statvfs64 failed")); - QuotaData quota_data; - quota_data.size = fsbuf.f_blocks * fsbuf.f_bsize; + std::tie(quota_data.size, std::ignore) = general_dir.statvfs(); QGroupUsage qgroup_usage = qgroup_query_usage(general_dir.fd(), btrfs->getQGroup()); quota_data.used = qgroup_usage.exclusive; @@ -833,17 +828,8 @@ namespace snapper filesystem->sync(); - struct statvfs64 fsbuf; - if (fstatvfs64(general_dir.fd(), &fsbuf) != 0) - SN_THROW(FreeSpaceException("statvfs64 failed")); - FreeSpaceData free_space_data; - - // f_bavail is used (not f_bfree) since df seems to do the - // same. Thus it allows the user to check the result easily. - - free_space_data.size = fsbuf.f_blocks * fsbuf.f_bsize; - free_space_data.free = fsbuf.f_bavail * fsbuf.f_bsize; + std::tie(free_space_data.size, free_space_data.free) = general_dir.statvfs(); y2mil("size:" << free_space_data.size << " free:" << free_space_data.free);