Merge tag 'xilinx-for-v2021.01' of https://gitlab.denx.de/u-boot/custodians/u-boot...
[platform/kernel/u-boot.git] / fs / btrfs / compat.h
1 // SPDX-License-Identifier: GPL-2.0+
2
3 #ifndef __BTRFS_COMPAT_H__
4 #define __BTRFS_COMPAT_H__
5
6 #include <linux/errno.h>
7 #include <fs_internal.h>
8 #include <uuid.h>
9
10 /* Provide a compatibility layer to make code syncing easier */
11
12 /* A simple wraper to for error() used in btrfs-progs */
13 #define error(fmt, ...)         pr_err("BTRFS: " fmt "\n", ##__VA_ARGS__)
14
15 #define ASSERT(c) assert(c)
16
17 #define BTRFS_UUID_UNPARSED_SIZE        37
18
19 /* No <linux/limits.h> so have to define it here */
20 #define XATTR_NAME_MAX          255
21 #define PATH_MAX                4096
22
23 /*
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
26  * one for u8:
27  */
28 #define le8_to_cpu(v) (v)
29 #define cpu_to_le8(v) (v)
30 #define __le8 u8
31
32 /*
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
35  * one for u8:
36  */
37 #define le8_to_cpu(v) (v)
38 #define cpu_to_le8(v) (v)
39 #define __le8 u8
40
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))
45
46 /*
47  * Read data from device specified by @desc and @part
48  *
49  * U-boot equivalent of pread().
50  *
51  * Return the bytes of data read.
52  * Return <0 for error.
53  */
54 static inline int __btrfs_devread(struct blk_desc *desc,
55                                   struct disk_partition *part,
56                                   void *buf, size_t size, u64 offset)
57 {
58         lbaint_t sector;
59         int byte_offset;
60         int ret;
61
62         sector = offset >> desc->log2blksz;
63         byte_offset = offset % desc->blksz;
64
65         /* fs_devread() return 0 for error, >0 for success */
66         ret = fs_devread(desc, part, sector, byte_offset, size, buf);
67         if (!ret)
68                 return -EIO;
69         return size;
70 }
71
72 static inline void uuid_unparse(const u8 *uuid, char *out)
73 {
74         return uuid_bin_to_str((unsigned char *)uuid, out, 0);
75 }
76
77 static inline int is_power_of_2(unsigned long n)
78 {
79         return (n != 0 && ((n & (n - 1)) == 0));
80 }
81
82 #endif