summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-18 01:35:58 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-18 01:36:28 +0100
commitf2cbe59e113f08549949a76ac5b9b3972df4cc30 (patch)
tree8c1210688113dae9dab2ac088a043c1f6f3692e4 /src/shared
parent20b63d12b533daf2e9b2936ffb03074861e1673e (diff)
machinectl: add new commands for copying files from/to containers
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/btrfs-util.c2
-rw-r--r--src/shared/copy.c24
-rw-r--r--src/shared/copy.h3
3 files changed, 18 insertions, 11 deletions
diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c
index fcf543a465..492d7fc777 100644
--- a/src/shared/btrfs-util.c
+++ b/src/shared/btrfs-util.c
@@ -122,7 +122,7 @@ int btrfs_subvol_snapshot(const char *old_path, const char *new_path, bool read_
if (r < 0)
return r;
- r = copy_tree_fd(old_fd, new_path, true);
+ r = copy_directory_fd(old_fd, new_path, true);
if (r < 0) {
btrfs_subvol_remove(new_path);
return r;
diff --git a/src/shared/copy.c b/src/shared/copy.c
index b4a85c7bff..0c2cdc8d94 100644
--- a/src/shared/copy.c
+++ b/src/shared/copy.c
@@ -25,6 +25,8 @@
#include "btrfs-util.h"
#include "copy.h"
+#define COPY_BUFFER_SIZE (16*1024)
+
int copy_bytes(int fdf, int fdt, off_t max_bytes, bool try_reflink) {
bool try_sendfile = true;
int r;
@@ -40,7 +42,7 @@ int copy_bytes(int fdf, int fdt, off_t max_bytes, bool try_reflink) {
}
for (;;) {
- size_t m = PIPE_BUF;
+ size_t m = COPY_BUFFER_SIZE;
ssize_t n;
if (max_bytes != (off_t) -1) {
@@ -279,30 +281,34 @@ static int fd_copy_directory(
return r;
}
-int copy_tree(const char *from, const char *to, bool merge) {
+int copy_tree_at(int fdf, const char *from, int fdt, const char *to, bool merge) {
struct stat st;
assert(from);
assert(to);
- if (lstat(from, &st) < 0)
+ if (fstatat(fdf, from, &st, AT_SYMLINK_NOFOLLOW) < 0)
return -errno;
if (S_ISREG(st.st_mode))
- return fd_copy_regular(AT_FDCWD, from, &st, AT_FDCWD, to);
+ return fd_copy_regular(fdf, from, &st, fdt, to);
else if (S_ISDIR(st.st_mode))
- return fd_copy_directory(AT_FDCWD, from, &st, AT_FDCWD, to, st.st_dev, merge);
+ return fd_copy_directory(fdf, from, &st, fdt, to, st.st_dev, merge);
else if (S_ISLNK(st.st_mode))
- return fd_copy_symlink(AT_FDCWD, from, &st, AT_FDCWD, to);
+ return fd_copy_symlink(fdf, from, &st, fdt, to);
else if (S_ISFIFO(st.st_mode))
- return fd_copy_fifo(AT_FDCWD, from, &st, AT_FDCWD, to);
+ return fd_copy_fifo(fdf, from, &st, fdt, to);
else if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
- return fd_copy_node(AT_FDCWD, from, &st, AT_FDCWD, to);
+ return fd_copy_node(fdf, from, &st, fdt, to);
else
return -ENOTSUP;
}
-int copy_tree_fd(int dirfd, const char *to, bool merge) {
+int copy_tree(const char *from, const char *to, bool merge) {
+ return copy_tree_at(AT_FDCWD, from, AT_FDCWD, to, merge);
+}
+
+int copy_directory_fd(int dirfd, const char *to, bool merge) {
struct stat st;
diff --git a/src/shared/copy.h b/src/shared/copy.h
index 201fe692ce..714addf4cb 100644
--- a/src/shared/copy.h
+++ b/src/shared/copy.h
@@ -27,5 +27,6 @@
int copy_file_fd(const char *from, int to, bool try_reflink);
int copy_file(const char *from, const char *to, int flags, mode_t mode);
int copy_tree(const char *from, const char *to, bool merge);
-int copy_tree_fd(int dirfd, const char *to, bool merge);
+int copy_tree_at(int fdf, const char *from, int fdt, const char *to, bool merge);
+int copy_directory_fd(int dirfd, const char *to, bool merge);
int copy_bytes(int fdf, int fdt, off_t max_bytes, bool try_reflink);