2020-06-24 16:02:49 +00:00
|
|
|
// 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__)
|
|
|
|
|
2020-06-24 16:03:01 +00:00
|
|
|
#define ASSERT(c) assert(c)
|
|
|
|
|
2020-06-24 16:02:49 +00:00
|
|
|
#define BTRFS_UUID_UNPARSED_SIZE 37
|
|
|
|
|
2020-06-24 16:03:02 +00:00
|
|
|
/* No <linux/limits.h> so have to define it here */
|
|
|
|
#define XATTR_NAME_MAX 255
|
2020-06-24 16:03:12 +00:00
|
|
|
#define PATH_MAX 4096
|
2020-06-24 16:03:02 +00:00
|
|
|
|
2020-06-24 16:02:49 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2020-06-24 16:02:53 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
#define get_unaligned_le8(p) (*((u8 *)(p)))
|
|
|
|
#define get_unaligned_8(p) (*((u8 *)(p)))
|
|
|
|
#define put_unaligned_le8(val,p) ((*((u8 *)(p))) = (val))
|
|
|
|
#define put_unaligned_8(val,p) ((*((u8 *)(p))) = (val))
|
|
|
|
|
2020-06-24 16:02:49 +00:00
|
|
|
/*
|
|
|
|
* Read data from device specified by @desc and @part
|
|
|
|
*
|
2023-05-17 07:17:16 +00:00
|
|
|
* U-Boot equivalent of pread().
|
2020-06-24 16:02:49 +00:00
|
|
|
*
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2020-06-24 16:02:54 +00:00
|
|
|
static inline int is_power_of_2(unsigned long n)
|
|
|
|
{
|
|
|
|
return (n != 0 && ((n & (n - 1)) == 0));
|
|
|
|
}
|
|
|
|
|
2020-06-24 16:02:49 +00:00
|
|
|
#endif
|