blob: b354c17a5cdc2c0fdaa8cbf611c706d2f6278867 [file] [log] [blame]
Qu Wenruo1a618082020-06-24 18:02:49 +02001// 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 BTRFS_UUID_UNPARSED_SIZE 37
16
17/*
18 * Macros to generate set/get funcs for the struct fields
19 * assume there is a lefoo_to_cpu for every type, so lets make a simple
20 * one for u8:
21 */
22#define le8_to_cpu(v) (v)
23#define cpu_to_le8(v) (v)
24#define __le8 u8
25
26/*
27 * Read data from device specified by @desc and @part
28 *
29 * U-boot equivalent of pread().
30 *
31 * Return the bytes of data read.
32 * Return <0 for error.
33 */
34static inline int __btrfs_devread(struct blk_desc *desc,
35 struct disk_partition *part,
36 void *buf, size_t size, u64 offset)
37{
38 lbaint_t sector;
39 int byte_offset;
40 int ret;
41
42 sector = offset >> desc->log2blksz;
43 byte_offset = offset % desc->blksz;
44
45 /* fs_devread() return 0 for error, >0 for success */
46 ret = fs_devread(desc, part, sector, byte_offset, size, buf);
47 if (!ret)
48 return -EIO;
49 return size;
50}
51
52static inline void uuid_unparse(const u8 *uuid, char *out)
53{
54 return uuid_bin_to_str((unsigned char *)uuid, out, 0);
55}
56
57#endif