From 5953ea6d3c564686c3ed1f1edd1e3ff72ca694d6 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Mon, 24 Oct 2022 11:48:35 -0400 Subject: [PATCH] fs: update btrfs compatibility header: add csum types, BTRFS_FS_INFO_FLAG_GENERATION and _METADATA_UUID I guess this means it's "args_v3" now? Signed-off-by: Zygo Blaxell --- include/crucible/btrfs.h | 27 +++++++++++++++++++++++++-- include/crucible/fs.h | 3 ++- lib/fs.cc | 19 ++++++++++++++----- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/include/crucible/btrfs.h b/include/crucible/btrfs.h index 798c4b7..f8c9408 100644 --- a/include/crucible/btrfs.h +++ b/include/crucible/btrfs.h @@ -216,7 +216,28 @@ enum btrfs_compression_type { #define BTRFS_FS_INFO_FLAG_CSUM_INFO (1 << 0) #endif -struct btrfs_ioctl_fs_info_args_v2 { +#ifndef BTRFS_FS_INFO_FLAG_GENERATION +/* Request information about filesystem generation */ +#define BTRFS_FS_INFO_FLAG_GENERATION (1 << 1) +#endif + +#ifndef BTRFS_FS_INFO_FLAG_METADATA_UUID +/* Request information about filesystem metadata UUID */ +#define BTRFS_FS_INFO_FLAG_METADATA_UUID (1 << 2) +#endif + +// BTRFS_CSUM_TYPE_CRC32 was a #define from 2008 to 2019. +// After that, it's an enum with the other 3 types. +// So if we do _not_ have CRC32 defined, it means we have the other 3; +// if we _do_ have CRC32 defined, it means we need the other 3. +// This seems likely to break some day. +#ifdef BTRFS_CSUM_TYPE_CRC32 + #define BTRFS_CSUM_TYPE_XXHASH 1 + #define BTRFS_CSUM_TYPE_SHA256 2 + #define BTRFS_CSUM_TYPE_BLAKE2 3 +#endif + +struct btrfs_ioctl_fs_info_args_v3 { __u64 max_id; /* out */ __u64 num_devices; /* out */ __u8 fsid[BTRFS_FSID_SIZE]; /* out */ @@ -227,7 +248,9 @@ struct btrfs_ioctl_fs_info_args_v2 { __u16 csum_type; /* out */ __u16 csum_size; /* out */ __u64 flags; /* in/out */ - __u8 reserved[968]; /* pad to 1k */ + __u64 generation; /* out */ + __u8 metadata_uuid[BTRFS_FSID_SIZE]; /* out */ + __u8 reserved[944]; /* pad to 1k */ }; #endif // CRUCIBLE_BTRFS_H diff --git a/include/crucible/fs.h b/include/crucible/fs.h index 0b34619..c3a91df 100644 --- a/include/crucible/fs.h +++ b/include/crucible/fs.h @@ -248,11 +248,12 @@ namespace crucible { template ostream &hexdump(ostream &os, const V &v); - struct BtrfsIoctlFsInfoArgs : public btrfs_ioctl_fs_info_args_v2 { + struct BtrfsIoctlFsInfoArgs : public btrfs_ioctl_fs_info_args_v3 { BtrfsIoctlFsInfoArgs(); void do_ioctl(int fd); uint16_t csum_type() const; uint16_t csum_size() const; + uint64_t generation() const; }; ostream & operator<<(ostream &os, const BtrfsIoctlFsInfoArgs &a); diff --git a/lib/fs.cc b/lib/fs.cc index 902b056..a630d50 100644 --- a/lib/fs.cc +++ b/lib/fs.cc @@ -1136,8 +1136,11 @@ namespace crucible { }; BtrfsIoctlFsInfoArgs::BtrfsIoctlFsInfoArgs() : - btrfs_ioctl_fs_info_args_v2( (btrfs_ioctl_fs_info_args_v2) { - .flags = BTRFS_FS_INFO_FLAG_CSUM_INFO, + btrfs_ioctl_fs_info_args_v3( (btrfs_ioctl_fs_info_args_v3) { + .flags = 0 + | BTRFS_FS_INFO_FLAG_CSUM_INFO + | BTRFS_FS_INFO_FLAG_GENERATION + , }) { } @@ -1145,7 +1148,7 @@ namespace crucible { void BtrfsIoctlFsInfoArgs::do_ioctl(int fd) { - btrfs_ioctl_fs_info_args_v2 *p = static_cast(this); + btrfs_ioctl_fs_info_args_v3 *p = static_cast(this); if (ioctl(fd, BTRFS_IOC_FS_INFO, p)) { THROW_ERRNO("BTRFS_IOC_FS_INFO: fd " << fd); } @@ -1154,13 +1157,19 @@ namespace crucible { uint16_t BtrfsIoctlFsInfoArgs::csum_type() const { - return this->btrfs_ioctl_fs_info_args_v2::csum_type; + return this->btrfs_ioctl_fs_info_args_v3::csum_type; } uint16_t BtrfsIoctlFsInfoArgs::csum_size() const { - return this->btrfs_ioctl_fs_info_args_v2::csum_size; + return this->btrfs_ioctl_fs_info_args_v3::csum_size; + } + + uint64_t + BtrfsIoctlFsInfoArgs::generation() const + { + return this->btrfs_ioctl_fs_info_args_v3::generation; } };