#include <fcntl.h>
#include <sys/ioctl.h>
#include <uuid/uuid.h>
+#include <limits.h>
+#include <errno.h>
#include "ctree.h"
#include "send-utils.h"
return 0;
}
+#ifdef BTRFS_COMPAT_SEND_NO_UUID_TREE
static struct rb_node *tree_insert(struct rb_root *root,
struct subvol_info *si,
enum subvol_search_type type)
}
return NULL;
}
+#endif
int btrfs_subvolid_resolve(int fd, char *path, size_t path_len, u64 subvol_id)
{
return 0;
}
+#ifdef BTRFS_COMPAT_SEND_NO_UUID_TREE
static int count_bytes(void *buf, int len, char b)
{
int cnt = 0;
return NULL;
return tree_search(root, root_id, uuid, transid, path, type);
}
+#else
+void subvol_uuid_search_add(struct subvol_uuid_search *s,
+ struct subvol_info *si)
+{
+ if (si) {
+ free(si->path);
+ free(si);
+ }
+}
+#endif
struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s,
u64 root_id, const u8 *uuid, u64 transid,
struct btrfs_root_item root_item;
struct subvol_info *info = NULL;
+#ifdef BTRFS_COMPAT_SEND_NO_UUID_TREE
if (!s->uuid_tree_existed)
return subvol_uuid_search_old(s, root_id, uuid, transid,
path, type);
+#endif
switch (type) {
case subvol_search_by_received_uuid:
ret = btrfs_lookup_uuid_received_subvol_item(s->mnt_fd, uuid,
if (type == subvol_search_by_path) {
info->path = strdup(path);
} else {
- info->path = malloc(BTRFS_PATH_NAME_MAX);
+ info->path = malloc(PATH_MAX);
ret = btrfs_subvolid_resolve(s->mnt_fd, info->path,
- BTRFS_PATH_NAME_MAX, root_id);
+ PATH_MAX, root_id);
}
out:
return info;
}
+#ifdef BTRFS_COMPAT_SEND_NO_UUID_TREE
static int is_uuid_tree_supported(int fd)
{
int ret;
struct btrfs_ioctl_search_key *sk = &args.key;
struct btrfs_ioctl_search_header *sh;
struct btrfs_root_item *root_item_ptr;
- struct btrfs_root_item root_item;
+ struct btrfs_root_item root_item = {};
struct subvol_info *si = NULL;
int root_item_valid = 0;
unsigned long off = 0;
ret = is_uuid_tree_supported(mnt_fd);
if (ret < 0) {
fprintf(stderr,
- "ERROR: check if we support uuid tree fails- %s\n",
+ "ERROR: check if we support uuid tree fails - %s\n",
strerror(errno));
return ret;
} else if (ret) {
ret = ioctl(mnt_fd, BTRFS_IOC_TREE_SEARCH, &args);
e = errno;
if (ret < 0) {
- fprintf(stderr, "ERROR: can't perform the search- %s\n",
+ fprintf(stderr, "ERROR: can't perform the search - %s\n",
strerror(e));
return ret;
}
s->received_subvols = RB_ROOT;
s->path_subvols = RB_ROOT;
}
+#else
+int subvol_uuid_search_init(int mnt_fd, struct subvol_uuid_search *s)
+{
+ s->mnt_fd = mnt_fd;
-char *path_cat(const char *p1, const char *p2)
+ return 0;
+}
+
+void subvol_uuid_search_finit(struct subvol_uuid_search *s)
+{
+}
+#endif
+
+int path_cat_out(char *out, const char *p1, const char *p2)
{
int p1_len = strlen(p1);
int p2_len = strlen(p2);
- char *new = malloc(p1_len + p2_len + 2);
+
+ if (p1_len + p2_len + 2 >= PATH_MAX)
+ return -ENAMETOOLONG;
if (p1_len && p1[p1_len - 1] == '/')
p1_len--;
if (p2_len && p2[p2_len - 1] == '/')
p2_len--;
- sprintf(new, "%.*s/%.*s", p1_len, p1, p2_len, p2);
+ sprintf(out, "%.*s/%.*s", p1_len, p1, p2_len, p2);
+
+ return 0;
+}
+
+__attribute__((deprecated("please use path_cat_out")))
+char *path_cat(const char *p1, const char *p2)
+{
+ int p1_len = strlen(p1);
+ int p2_len = strlen(p2);
+ char *new = malloc(p1_len + p2_len + 2);
+
+ path_cat_out(new, p1, p2);
+
return new;
}
-char *path_cat3(const char *p1, const char *p2, const char *p3)
+int path_cat3_out(char *out, const char *p1, const char *p2, const char *p3)
{
int p1_len = strlen(p1);
int p2_len = strlen(p2);
int p3_len = strlen(p3);
- char *new = malloc(p1_len + p2_len + p3_len + 3);
+
+ if (p1_len + p2_len + p3_len + 3 >= PATH_MAX)
+ return -ENAMETOOLONG;
if (p1_len && p1[p1_len - 1] == '/')
p1_len--;
p2_len--;
if (p3_len && p3[p3_len - 1] == '/')
p3_len--;
- sprintf(new, "%.*s/%.*s/%.*s", p1_len, p1, p2_len, p2, p3_len, p3);
+ sprintf(out, "%.*s/%.*s/%.*s", p1_len, p1, p2_len, p2, p3_len, p3);
+
+ return 0;
+}
+
+__attribute__((deprecated("please use path_cat3_out")))
+char *path_cat3(const char *p1, const char *p2, const char *p3)
+{
+ int p1_len = strlen(p1);
+ int p2_len = strlen(p2);
+ int p3_len = strlen(p3);
+ char *new = malloc(p1_len + p2_len + p3_len + 3);
+
+ path_cat3_out(new, p1, p2, p3);
+
return new;
}