From 98b31cac579a3d3e0243c7fb0c6cde79aebcfda1 Mon Sep 17 00:00:00 2001 From: Octavian Purdila Date: Wed, 18 Jan 2017 23:04:07 +0200 Subject: [PATCH] lkl tools: cpfromfs: fix root directory copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently copying the disk image root is broken: cptofs -P 1 -t ext4 -i test.img ~/linux / cpfromfs -P 1 -t ext4 -i test.img / ~/linuxcopy leads to the following in ~/linuxcopy: /home/ec2-user/linuxcopy └── 0000fe01 ├── linux │ ├── arch The problem is that basename("/mnt/0000fe01/") returns 0000fe01 where we would expect /. Fix that by making the root folder copy case special. Reported-by: Dan Peebles Signed-off-by: Octavian Purdila --- tools/lkl/cptofs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/lkl/cptofs.c b/tools/lkl/cptofs.c index d4f32df2f10f6d..a43e6b016b83db 100644 --- a/tools/lkl/cptofs.c +++ b/tools/lkl/cptofs.c @@ -480,6 +480,27 @@ static int searchdir(const char *src, const char *dst, const char *match) return ret; } +static int match_root(const char *src) +{ + const char *c = src; + + while (*c) { + switch (*c) { + case '.': + if (c > src && c[-1] == '.') + return 0; + break; + case '/': + break; + default: + return 0; + } + c++; + } + + return 1; +} + int copy_one(const char *src, const char *mpoint, const char *dst) { char *src_path_dir, *src_path_base; @@ -493,6 +514,9 @@ int copy_one(const char *src, const char *mpoint, const char *dst) snprintf(dst_path, sizeof(dst_path), "%s", dst); } + if (match_root(src)) + return searchdir(src_path, dst, NULL); + src_path_dir = dirname(strdup(src_path)); src_path_base = basename(strdup(src_path));