mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35:45 +02:00
fs: get rid of silly base class that causes build failures now
The base class thing was an ugly way to get around the lack of C99 compound literals in C++, and also to make the bare ioctls usable with the derived classes. Today, both clang and gcc have C99 compound literals, so there's no need to do crazy things with memset. We never used the derived classes for ioctls, and for this specific ioctl it would have been a very, very bad idea, so there's no need to support that either. We do need to jump through hoops for ostream& operator<<() but we had to do those anyway as there are other members in the derived type. So we can simply drop the base class, and build the args object on the stack in `do_ioctl`. This also removes the need to verify initialization. There's no bug here since the `info` member of the base class was never used in place by the derived class, but new compilers reject the flexible array member in the base class because the derived class makes `info` be not at the end of the struct any more: error: flexible array member btrfs_ioctl_same_args::info not at end of struct crucible::BtrfsExtentSame Fixes: https://github.com/Zygo/bees/issues/232 Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
parent
dffd6e0b13
commit
14ce81c081
@ -31,12 +31,14 @@ namespace crucible {
|
|||||||
BtrfsExtentInfo(int dst_fd, off_t dst_offset);
|
BtrfsExtentInfo(int dst_fd, off_t dst_offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BtrfsExtentSame : public btrfs_ioctl_same_args {
|
struct BtrfsExtentSame {
|
||||||
virtual ~BtrfsExtentSame();
|
virtual ~BtrfsExtentSame();
|
||||||
BtrfsExtentSame(int src_fd, off_t src_offset, off_t src_length);
|
BtrfsExtentSame(int src_fd, off_t src_offset, off_t src_length);
|
||||||
void add(int fd, off_t offset);
|
void add(int fd, off_t offset);
|
||||||
virtual void do_ioctl();
|
virtual void do_ioctl();
|
||||||
|
|
||||||
|
uint64_t m_logical_offset = 0;
|
||||||
|
uint64_t m_length = 0;
|
||||||
int m_fd;
|
int m_fd;
|
||||||
vector<BtrfsExtentInfo> m_info;
|
vector<BtrfsExtentInfo> m_info;
|
||||||
};
|
};
|
||||||
|
22
lib/fs.cc
22
lib/fs.cc
@ -45,13 +45,10 @@ namespace crucible {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BtrfsExtentSame::BtrfsExtentSame(int src_fd, off_t src_offset, off_t src_length) :
|
BtrfsExtentSame::BtrfsExtentSame(int src_fd, off_t src_offset, off_t src_length) :
|
||||||
btrfs_ioctl_same_args( (btrfs_ioctl_same_args) { } ),
|
m_logical_offset(src_offset),
|
||||||
|
m_length(src_length),
|
||||||
m_fd(src_fd)
|
m_fd(src_fd)
|
||||||
{
|
{
|
||||||
assert(logical_offset == 0);
|
|
||||||
assert(length == 0);
|
|
||||||
logical_offset = src_offset;
|
|
||||||
length = src_length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BtrfsExtentSame::~BtrfsExtentSame()
|
BtrfsExtentSame::~BtrfsExtentSame()
|
||||||
@ -118,11 +115,8 @@ namespace crucible {
|
|||||||
os << " '" << fd_name << "'";
|
os << " '" << fd_name << "'";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
os << ", .logical_offset = " << to_hex(bes.logical_offset);
|
os << ", .logical_offset = " << to_hex(bes.m_logical_offset);
|
||||||
os << ", .length = " << to_hex(bes.length);
|
os << ", .length = " << to_hex(bes.m_length);
|
||||||
os << ", .dest_count = " << bes.dest_count;
|
|
||||||
os << ", .reserved1 = " << bes.reserved1;
|
|
||||||
os << ", .reserved2 = " << bes.reserved2;
|
|
||||||
os << ", .info[] = {";
|
os << ", .info[] = {";
|
||||||
for (size_t i = 0; i < bes.m_info.size(); ++i) {
|
for (size_t i = 0; i < bes.m_info.size(); ++i) {
|
||||||
os << " [" << i << "] = " << &(bes.m_info[i]) << ",";
|
os << " [" << i << "] = " << &(bes.m_info[i]) << ",";
|
||||||
@ -145,9 +139,11 @@ namespace crucible {
|
|||||||
void
|
void
|
||||||
BtrfsExtentSame::do_ioctl()
|
BtrfsExtentSame::do_ioctl()
|
||||||
{
|
{
|
||||||
dest_count = m_info.size();
|
const size_t buf_size = sizeof(btrfs_ioctl_same_args) + m_info.size() * sizeof(btrfs_ioctl_same_extent_info);
|
||||||
const size_t buf_size = sizeof(btrfs_ioctl_same_args) + dest_count * sizeof(btrfs_ioctl_same_extent_info);
|
ByteVector ioctl_arg( (btrfs_ioctl_same_args) {
|
||||||
ByteVector ioctl_arg(static_cast<btrfs_ioctl_same_args&>(*this), buf_size);
|
.logical_offset = m_logical_offset,
|
||||||
|
.length = m_length,
|
||||||
|
}, buf_size);
|
||||||
btrfs_ioctl_same_args *const ioctl_ptr = ioctl_arg.get<btrfs_ioctl_same_args>();
|
btrfs_ioctl_same_args *const ioctl_ptr = ioctl_arg.get<btrfs_ioctl_same_args>();
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
for (auto i = m_info.cbegin(); i != m_info.cend(); ++i) {
|
for (auto i = m_info.cbegin(); i != m_info.cend(); ++i) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user