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 <dsterba@suse.com>
This commit is contained in:
parent
dc6da57e0a
commit
db1246039d
|
@ -21,6 +21,7 @@
|
||||||
#define BTRFS_UTIL_INTERNAL_H
|
#define BTRFS_UTIL_INTERNAL_H
|
||||||
|
|
||||||
#include <asm/byteorder.h>
|
#include <asm/byteorder.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "btrfsutil.h"
|
#include "btrfsutil.h"
|
||||||
#include "btrfs.h"
|
#include "btrfs.h"
|
||||||
|
@ -39,4 +40,43 @@
|
||||||
errno = saved_errno; \
|
errno = saved_errno; \
|
||||||
} while (0)
|
} 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 */
|
#endif /* BTRFS_UTIL_INTERNAL_H */
|
||||||
|
|
Loading…
Reference in New Issue