diff --git a/libbtrfs/send-stream.c b/libbtrfs/send-stream.c index 31da516d..2b21d846 100644 --- a/libbtrfs/send-stream.c +++ b/libbtrfs/send-stream.c @@ -20,7 +20,6 @@ #include "kernel-shared/send.h" #include "libbtrfs/send-stream.h" #include "crypto/crc32c.h" -#include "common/utils.h" struct btrfs_send_stream { char read_buf[BTRFS_SEND_BUF_SIZE]; diff --git a/libbtrfs/send-stream.h b/libbtrfs/send-stream.h index 39901f86..d21964ef 100644 --- a/libbtrfs/send-stream.h +++ b/libbtrfs/send-stream.h @@ -34,6 +34,8 @@ extern "C" { #include #endif /* BTRFS_FLAT_INCLUDES */ +#include + struct btrfs_send_ops { int (*subvol)(const char *path, const u8 *uuid, u64 ctransid, void *user); diff --git a/libbtrfs/send-utils.c b/libbtrfs/send-utils.c index a0bdafae..f08e2888 100644 --- a/libbtrfs/send-utils.c +++ b/libbtrfs/send-utils.c @@ -24,12 +24,35 @@ #include "kernel-shared/ctree.h" #include "libbtrfs/send-utils.h" -#include "common/utils.h" #include "ioctl.h" #include "btrfs-list.h" static int btrfs_subvolid_resolve_sub(int fd, char *path, size_t *path_len, u64 subvol_id); +/* + * For a given: + * - file or directory return the containing tree root id + * - subvolume return its own tree id + * - BTRFS_EMPTY_SUBVOL_DIR_OBJECTID (directory with ino == 2) the result is + * undefined and function returns -1 + */ +static int lookup_path_rootid(int fd, u64 *rootid) +{ + struct btrfs_ioctl_ino_lookup_args args; + int ret; + + memset(&args, 0, sizeof(args)); + args.treeid = 0; + args.objectid = BTRFS_FIRST_FREE_OBJECTID; + + ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args); + if (ret < 0) + return -errno; + + *rootid = args.treeid; + + return 0; +} static int btrfs_get_root_id_by_sub_path(int mnt_fd, const char *sub_path, u64 *root_id)