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);
|
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); }
|
int open(inode_view entry) const { return impl_->open(entry); }
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ class filesystem_v2 {
|
|||||||
std::error_code& ec) const = 0;
|
std::error_code& ec) const = 0;
|
||||||
virtual std::string
|
virtual std::string
|
||||||
readlink(inode_view entry, readlink_mode mode) const = 0;
|
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) const = 0;
|
||||||
virtual int open(inode_view entry, std::error_code& ec) const = 0;
|
virtual int open(inode_view entry, std::error_code& ec) const = 0;
|
||||||
virtual size_t
|
virtual size_t
|
||||||
|
@ -134,7 +134,7 @@ class metadata_v2 {
|
|||||||
return impl_->readlink(iv, mode, ec);
|
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 {
|
std::optional<chunk_range> get_chunks(int inode) const {
|
||||||
return impl_->get_chunks(inode);
|
return impl_->get_chunks(inode);
|
||||||
@ -210,7 +210,7 @@ class metadata_v2 {
|
|||||||
virtual std::string
|
virtual std::string
|
||||||
readlink(inode_view iv, readlink_mode mode, std::error_code& ec) const = 0;
|
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;
|
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::string readlink(inode_view entry, readlink_mode mode,
|
||||||
std::error_code& ec) const override;
|
std::error_code& ec) const override;
|
||||||
std::string readlink(inode_view entry, readlink_mode mode) 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) const override;
|
||||||
int open(inode_view entry, std::error_code& ec) const override;
|
int open(inode_view entry, std::error_code& ec) const override;
|
||||||
size_t read(uint32_t inode, char* buf, size_t size,
|
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>
|
template <typename LoggerPolicy>
|
||||||
int filesystem_<LoggerPolicy>::statvfs(vfs_stat* stbuf) const {
|
void filesystem_<LoggerPolicy>::statvfs(vfs_stat* stbuf) const {
|
||||||
PERFMON_CLS_SCOPED_SECTION(statvfs)
|
PERFMON_CLS_SCOPED_SECTION(statvfs)
|
||||||
// TODO: not sure if that's the right abstraction...
|
// TODO: not sure if that's the right abstraction...
|
||||||
return meta_.statvfs(stbuf);
|
meta_.statvfs(stbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename LoggerPolicy>
|
template <typename LoggerPolicy>
|
||||||
|
@ -502,7 +502,7 @@ class metadata_ final : public metadata_v2::impl {
|
|||||||
std::string readlink(inode_view iv, readlink_mode mode,
|
std::string readlink(inode_view iv, readlink_mode mode,
|
||||||
std::error_code& ec) const override;
|
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;
|
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>
|
template <typename LoggerPolicy>
|
||||||
int metadata_<LoggerPolicy>::statvfs(vfs_stat* stbuf) const {
|
void metadata_<LoggerPolicy>::statvfs(vfs_stat* stbuf) const {
|
||||||
::memset(stbuf, 0, sizeof(*stbuf));
|
::memset(stbuf, 0, sizeof(*stbuf));
|
||||||
|
|
||||||
// Make sure bsize and frsize are the same, as doing otherwise can confuse
|
// 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->files = inode_count_;
|
||||||
stbuf->readonly = true;
|
stbuf->readonly = true;
|
||||||
stbuf->namemax = PATH_MAX;
|
stbuf->namemax = PATH_MAX;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename LoggerPolicy>
|
template <typename LoggerPolicy>
|
||||||
|
@ -849,20 +849,18 @@ int op_statfs_common(LogProxy& log_, dwarfs_userdata& userdata,
|
|||||||
return checked_call(log_, [&] {
|
return checked_call(log_, [&] {
|
||||||
vfs_stat stbuf;
|
vfs_stat stbuf;
|
||||||
|
|
||||||
auto err = userdata.fs.statvfs(&stbuf);
|
userdata.fs.statvfs(&stbuf);
|
||||||
|
|
||||||
if (err == 0) {
|
::memset(st, 0, sizeof(*st));
|
||||||
::memset(st, 0, sizeof(*st));
|
copy_vfs_stat(st, stbuf);
|
||||||
copy_vfs_stat(st, stbuf);
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (stbuf.readonly) {
|
if (stbuf.readonly) {
|
||||||
st->f_flag |= ST_RDONLY;
|
st->f_flag |= ST_RDONLY;
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#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) {
|
BENCHMARK_DEFINE_F(filesystem, statvfs)(::benchmark::State& state) {
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
vfs_stat buf;
|
vfs_stat buf;
|
||||||
auto r = fs->statvfs(&buf);
|
fs->statvfs(&buf);
|
||||||
::benchmark::DoNotOptimize(r);
|
::benchmark::DoNotOptimize(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user