From db1246039d3b8c98e2e0ee448392c539ab78ac54 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 4 Jul 2019 14:26:47 +0200 Subject: [PATCH] libbtrfsutil: add accessors for search header items Add helpers that do proper unaligned access of search heade items. This is done in the non-libbtrfsutil code already, use the same helpers here too. We can't use the get_unaligned_* helpers that are defined in kerncompat, so use plain memcpy that will work everywhere. Signed-off-by: David Sterba --- libbtrfsutil/btrfsutil_internal.h | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/libbtrfsutil/btrfsutil_internal.h b/libbtrfsutil/btrfsutil_internal.h index 8bbf01f4..eba8c297 100644 --- a/libbtrfsutil/btrfsutil_internal.h +++ b/libbtrfsutil/btrfsutil_internal.h @@ -21,6 +21,7 @@ #define BTRFS_UTIL_INTERNAL_H #include +#include #include "btrfsutil.h" #include "btrfs.h" @@ -39,4 +40,43 @@ errno = saved_errno; \ } while (0) +/* + * Accessors of search header that is commonly mapped to a byte buffer so the + * alignment is not guraranteed + */ +static inline __u64 btrfs_search_header_transid(const struct btrfs_ioctl_search_header *sh) +{ + __u64 tmp; + memcpy(&tmp, &sh->transid, sizeof(__u64)); + return tmp; +} + +static inline __u64 btrfs_search_header_objectid(const struct btrfs_ioctl_search_header *sh) +{ + __u64 tmp; + memcpy(&tmp, &sh->objectid, sizeof(__u64)); + return tmp; +} + +static inline __u64 btrfs_search_header_offset(const struct btrfs_ioctl_search_header *sh) +{ + __u64 tmp; + memcpy(&tmp, &sh->offset, sizeof(__u64)); + return tmp; +} + +static inline __u32 btrfs_search_header_type(const struct btrfs_ioctl_search_header *sh) +{ + __u32 tmp; + memcpy(&tmp, &sh->type, sizeof(__u32)); + return tmp; +} + +static inline __u32 btrfs_search_header_len(const struct btrfs_ioctl_search_header *sh) +{ + __u32 tmp; + memcpy(&tmp, &sh->len, sizeof(__u32)); + return tmp; +} + #endif /* BTRFS_UTIL_INTERNAL_H */