Skip to content

Commit

Permalink
lkl tools: cpfromfs: fix root directory copy
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Octavian Purdila <[email protected]>
  • Loading branch information
tavip committed Jan 18, 2017
1 parent d747073 commit 98b31ca
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tools/lkl/cptofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));

Expand Down

0 comments on commit 98b31ca

Please sign in to comment.