1 // SPDX-License-Identifier: GPL-2.0+
3 #ifndef __BTRFS_COMPAT_H__
4 #define __BTRFS_COMPAT_H__
6 #include <linux/errno.h>
7 #include <fs_internal.h>
10 /* Provide a compatibility layer to make code syncing easier */
12 /* A simple wraper to for error() used in btrfs-progs */
13 #define error(fmt, ...) pr_err("BTRFS: " fmt "\n", ##__VA_ARGS__)
15 #define ASSERT(c) assert(c)
17 #define BTRFS_UUID_UNPARSED_SIZE 37
19 /* No <linux/limits.h> so have to define it here */
20 #define XATTR_NAME_MAX 255
24 * Macros to generate set/get funcs for the struct fields
25 * assume there is a lefoo_to_cpu for every type, so lets make a simple
28 #define le8_to_cpu(v) (v)
29 #define cpu_to_le8(v) (v)
33 * Macros to generate set/get funcs for the struct fields
34 * assume there is a lefoo_to_cpu for every type, so lets make a simple
37 #define le8_to_cpu(v) (v)
38 #define cpu_to_le8(v) (v)
41 #define get_unaligned_le8(p) (*((u8 *)(p)))
42 #define get_unaligned_8(p) (*((u8 *)(p)))
43 #define put_unaligned_le8(val,p) ((*((u8 *)(p))) = (val))
44 #define put_unaligned_8(val,p) ((*((u8 *)(p))) = (val))
47 * Read data from device specified by @desc and @part
49 * U-boot equivalent of pread().
51 * Return the bytes of data read.
52 * Return <0 for error.
54 static inline int __btrfs_devread(struct blk_desc *desc,
55 struct disk_partition *part,
56 void *buf, size_t size, u64 offset)
62 sector = offset >> desc->log2blksz;
63 byte_offset = offset % desc->blksz;
65 /* fs_devread() return 0 for error, >0 for success */
66 ret = fs_devread(desc, part, sector, byte_offset, size, buf);
72 static inline void uuid_unparse(const u8 *uuid, char *out)
74 return uuid_bin_to_str((unsigned char *)uuid, out, 0);
77 static inline int is_power_of_2(unsigned long n)
79 return (n != 0 && ((n & (n - 1)) == 0));