#include <fcntl.h>
#include <sys/ioctl.h>
#include <uuid/uuid.h>
+#include <limits.h>
+#include <errno.h>
#include "ctree.h"
#include "send-utils.h"
search_arg.key.max_transid = (u64)-1;
search_arg.key.nr_items = 1;
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &search_arg);
- if (ret) {
+ if (ret < 0) {
fprintf(stderr,
"ioctl(BTRFS_IOC_TREE_SEARCH, subvol_id %llu) ret=%d, error: %s\n",
(unsigned long long)subvol_id, ret, strerror(errno));
ino_lookup_arg.objectid =
btrfs_stack_root_ref_dirid(backref_item);
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &ino_lookup_arg);
- if (ret) {
+ if (ret < 0) {
fprintf(stderr,
"ioctl(BTRFS_IOC_INO_LOOKUP) ret=%d, error: %s\n",
ret, strerror(errno));
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:
int root_item_valid = 0;
unsigned long off = 0;
int i;
- int e;
char *path;
s->mnt_fd = mnt_fd;
while (1) {
ret = ioctl(mnt_fd, BTRFS_IOC_TREE_SEARCH, &args);
- e = errno;
if (ret < 0) {
fprintf(stderr, "ERROR: can't perform the search - %s\n",
- strerror(e));
+ strerror(errno));
return ret;
}
if (sk->nr_items == 0)
}
#endif
-char *path_cat(const char *p1, const char *p2)
+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))
+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))
+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;
}