Skip to content

Commit c874d36

Browse files
authored
Merge pull request torvalds#300 from lkl/issue-294
lkl tools: cpfromfs: fix root directory copy
2 parents d747073 + 98b31ca commit c874d36

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tools/lkl/cptofs.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,27 @@ static int searchdir(const char *src, const char *dst, const char *match)
480480
return ret;
481481
}
482482

483+
static int match_root(const char *src)
484+
{
485+
const char *c = src;
486+
487+
while (*c) {
488+
switch (*c) {
489+
case '.':
490+
if (c > src && c[-1] == '.')
491+
return 0;
492+
break;
493+
case '/':
494+
break;
495+
default:
496+
return 0;
497+
}
498+
c++;
499+
}
500+
501+
return 1;
502+
}
503+
483504
int copy_one(const char *src, const char *mpoint, const char *dst)
484505
{
485506
char *src_path_dir, *src_path_base;
@@ -493,6 +514,9 @@ int copy_one(const char *src, const char *mpoint, const char *dst)
493514
snprintf(dst_path, sizeof(dst_path), "%s", dst);
494515
}
495516

517+
if (match_root(src))
518+
return searchdir(src_path, dst, NULL);
519+
496520
src_path_dir = dirname(strdup(src_path));
497521
src_path_base = basename(strdup(src_path));
498522

0 commit comments

Comments
 (0)