mirror of
https://github.com/mhx/dwarfs.git
synced 2025-08-04 10:16:34 -04:00
refactor: statvfs cannot actually fail
This commit is contained in:
parent
ce16e74646
commit
29e09d94c7
@ -155,7 +155,7 @@ class filesystem_v2 {
|
||||
return impl_->readlink(entry, mode);
|
||||
}
|
||||
|
||||
int statvfs(vfs_stat* stbuf) const { return impl_->statvfs(stbuf); }
|
||||
void statvfs(vfs_stat* stbuf) const { impl_->statvfs(stbuf); }
|
||||
|
||||
int open(inode_view entry) const { return impl_->open(entry); }
|
||||
|
||||
@ -279,7 +279,7 @@ class filesystem_v2 {
|
||||
std::error_code& ec) const = 0;
|
||||
virtual std::string
|
||||
readlink(inode_view entry, readlink_mode mode) const = 0;
|
||||
virtual int statvfs(vfs_stat* stbuf) const = 0;
|
||||
virtual void statvfs(vfs_stat* stbuf) const = 0;
|
||||
virtual int open(inode_view entry) const = 0;
|
||||
virtual int open(inode_view entry, std::error_code& ec) const = 0;
|
||||
virtual size_t
|
||||
|
@ -134,7 +134,7 @@ class metadata_v2 {
|
||||
return impl_->readlink(iv, mode, ec);
|
||||
}
|
||||
|
||||
int statvfs(vfs_stat* stbuf) const { return impl_->statvfs(stbuf); }
|
||||
void statvfs(vfs_stat* stbuf) const { impl_->statvfs(stbuf); }
|
||||
|
||||
std::optional<chunk_range> get_chunks(int inode) const {
|
||||
return impl_->get_chunks(inode);
|
||||
@ -210,7 +210,7 @@ class metadata_v2 {
|
||||
virtual std::string
|
||||
readlink(inode_view iv, readlink_mode mode, std::error_code& ec) const = 0;
|
||||
|
||||
virtual int statvfs(vfs_stat* stbuf) const = 0;
|
||||
virtual void statvfs(vfs_stat* stbuf) const = 0;
|
||||
|
||||
virtual std::optional<chunk_range> get_chunks(int inode) const = 0;
|
||||
|
||||
|
@ -430,7 +430,7 @@ class filesystem_ final : public filesystem_v2::impl {
|
||||
std::string readlink(inode_view entry, readlink_mode mode,
|
||||
std::error_code& ec) const override;
|
||||
std::string readlink(inode_view entry, readlink_mode mode) const override;
|
||||
int statvfs(vfs_stat* stbuf) const override;
|
||||
void statvfs(vfs_stat* stbuf) const override;
|
||||
int open(inode_view entry) const override;
|
||||
int open(inode_view entry, std::error_code& ec) const override;
|
||||
size_t read(uint32_t inode, char* buf, size_t size,
|
||||
@ -1120,10 +1120,10 @@ std::string filesystem_<LoggerPolicy>::readlink(inode_view entry,
|
||||
}
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
int filesystem_<LoggerPolicy>::statvfs(vfs_stat* stbuf) const {
|
||||
void filesystem_<LoggerPolicy>::statvfs(vfs_stat* stbuf) const {
|
||||
PERFMON_CLS_SCOPED_SECTION(statvfs)
|
||||
// TODO: not sure if that's the right abstraction...
|
||||
return meta_.statvfs(stbuf);
|
||||
meta_.statvfs(stbuf);
|
||||
}
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
|
@ -502,7 +502,7 @@ class metadata_ final : public metadata_v2::impl {
|
||||
std::string readlink(inode_view iv, readlink_mode mode,
|
||||
std::error_code& ec) const override;
|
||||
|
||||
int statvfs(vfs_stat* stbuf) const override;
|
||||
void statvfs(vfs_stat* stbuf) const override;
|
||||
|
||||
std::optional<chunk_range> get_chunks(int inode) const override;
|
||||
|
||||
@ -1712,7 +1712,7 @@ std::string metadata_<LoggerPolicy>::readlink(inode_view iv, readlink_mode mode,
|
||||
}
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
int metadata_<LoggerPolicy>::statvfs(vfs_stat* stbuf) const {
|
||||
void metadata_<LoggerPolicy>::statvfs(vfs_stat* stbuf) const {
|
||||
::memset(stbuf, 0, sizeof(*stbuf));
|
||||
|
||||
// Make sure bsize and frsize are the same, as doing otherwise can confuse
|
||||
@ -1728,8 +1728,6 @@ int metadata_<LoggerPolicy>::statvfs(vfs_stat* stbuf) const {
|
||||
stbuf->files = inode_count_;
|
||||
stbuf->readonly = true;
|
||||
stbuf->namemax = PATH_MAX;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
|
@ -849,20 +849,18 @@ int op_statfs_common(LogProxy& log_, dwarfs_userdata& userdata,
|
||||
return checked_call(log_, [&] {
|
||||
vfs_stat stbuf;
|
||||
|
||||
auto err = userdata.fs.statvfs(&stbuf);
|
||||
userdata.fs.statvfs(&stbuf);
|
||||
|
||||
if (err == 0) {
|
||||
::memset(st, 0, sizeof(*st));
|
||||
copy_vfs_stat(st, stbuf);
|
||||
::memset(st, 0, sizeof(*st));
|
||||
copy_vfs_stat(st, stbuf);
|
||||
|
||||
#ifndef _WIN32
|
||||
if (stbuf.readonly) {
|
||||
st->f_flag |= ST_RDONLY;
|
||||
}
|
||||
#endif
|
||||
if (stbuf.readonly) {
|
||||
st->f_flag |= ST_RDONLY;
|
||||
}
|
||||
#endif
|
||||
|
||||
return err;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -418,8 +418,8 @@ BENCHMARK_DEFINE_F(filesystem, readlink)(::benchmark::State& state) {
|
||||
BENCHMARK_DEFINE_F(filesystem, statvfs)(::benchmark::State& state) {
|
||||
for (auto _ : state) {
|
||||
vfs_stat buf;
|
||||
auto r = fs->statvfs(&buf);
|
||||
::benchmark::DoNotOptimize(r);
|
||||
fs->statvfs(&buf);
|
||||
::benchmark::DoNotOptimize(buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user