aboutsummaryrefslogtreecommitdiff
path: root/fs/btrfs/compat.h
blob: b354c17a5cdc2c0fdaa8cbf611c706d2f6278867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: GPL-2.0+

#ifndef __BTRFS_COMPAT_H__
#define __BTRFS_COMPAT_H__

#include <linux/errno.h>
#include <fs_internal.h>
#include <uuid.h>

/* Provide a compatibility layer to make code syncing easier */

/* A simple wraper to for error() used in btrfs-progs */
#define error(fmt, ...)		pr_err("BTRFS: " fmt "\n", ##__VA_ARGS__)

#define BTRFS_UUID_UNPARSED_SIZE	37

/*
 * Macros to generate set/get funcs for the struct fields
 * assume there is a lefoo_to_cpu for every type, so lets make a simple
 * one for u8:
 */
#define le8_to_cpu(v) (v)
#define cpu_to_le8(v) (v)
#define __le8 u8

/*
 * Read data from device specified by @desc and @part
 *
 * U-boot equivalent of pread().
 *
 * Return the bytes of data read.
 * Return <0 for error.
 */
static inline int __btrfs_devread(struct blk_desc *desc,
				  struct disk_partition *part,
				  void *buf, size_t size, u64 offset)
{
	lbaint_t sector;
	int byte_offset;
	int ret;

	sector = offset >> desc->log2blksz;
	byte_offset = offset % desc->blksz;

	/* fs_devread() return 0 for error, >0 for success */
	ret = fs_devread(desc, part, sector, byte_offset, size, buf);
	if (!ret)
		return -EIO;
	return size;
}

static inline void uuid_unparse(const u8 *uuid, char *out)
{
	return uuid_bin_to_str((unsigned char *)uuid, out, 0);
}

#endif