mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2024-11-15 08:14:21 +08:00
a223764093
Add wrappers around v1 and v2 of TREE_SEARCH ioctl so it can be transparently used by code. The structures partially overlap but due to the buffer size the v2 is offset and also needs a filler to expand the flexible buffer. Usage: - define struct btrfs_tree_search_args, all zeros - btrfs_tree_search_sk() reads offset of the search key within the structures - btrfs_tree_search_ioctl() detect support and call the highest supported ioctl version, v2 has been supported since 3.14 but we want to keep backward compatibility - btrfs_tree_search_data() read data from the buffer previously filled by ioctl, a sequence of (search header, data) Signed-off-by: David Sterba <dsterba@suse.com>
34 lines
885 B
C
34 lines
885 B
C
#ifndef __COMMON_TREE_SEARCH_H__
|
|
#define __COMMON_TREE_SEARCH_H__
|
|
|
|
#include "kernel-shared/uapi/btrfs_tree.h"
|
|
#include "kernel-shared/uapi/btrfs.h"
|
|
|
|
#define BTRFS_TREE_SEARCH_V2_BUF_SIZE 65536
|
|
|
|
struct btrfs_tree_search_args {
|
|
union {
|
|
struct btrfs_ioctl_search_args args1;
|
|
struct btrfs_ioctl_search_args_v2 args2;
|
|
u8 filler[sizeof(struct btrfs_ioctl_search_args_v2) +
|
|
BTRFS_TREE_SEARCH_V2_BUF_SIZE];
|
|
};
|
|
bool use_v2;
|
|
};
|
|
|
|
int btrfs_tree_search_ioctl(int fd, struct btrfs_tree_search_args *sa);
|
|
|
|
static inline struct btrfs_ioctl_search_key *btrfs_tree_search_sk(struct btrfs_tree_search_args *sa)
|
|
{
|
|
/* Same offset for v1 and v2. */
|
|
return &sa->args1.key;
|
|
}
|
|
|
|
static inline void *btrfs_tree_search_data(struct btrfs_tree_search_args *sa, unsigned long offset) {
|
|
if (sa->use_v2)
|
|
return (void *)(sa->args2.buf + offset);
|
|
return (void *)(sa->args1.buf + offset);
|
|
}
|
|
|
|
#endif
|