Commit 43f901fb authored by Thomas Chou's avatar Thomas Chou Committed by Michal Marek

gen_init_cpio: remove leading `/' from file names

When we extracted the generated cpio archive using "cpio -id" command,
it complained,

cpio: Removing leading `/' from member names
var/run
cpio: Removing leading `/' from member names
var/lib
cpio: Removing leading `/' from member names
var/lib/misc

It is worse with the latest "cpio" or "pax", which tries to overwrite
the host file system with the leading '/'.

So the leading '/' of file names should be removed. This is consistent
with the initramfs come with major distributions such as Fedora or
Debian, etc.
Signed-off-by: default avatarThomas Chou <thomas@wytron.com.tw>
Acked-by: Mike Frysinger<vapier@gentoo.org>
Signed-off-by: default avatarMichal Marek <mmarek@suse.cz>
parent 01660dfc
...@@ -104,6 +104,8 @@ static int cpio_mkslink(const char *name, const char *target, ...@@ -104,6 +104,8 @@ static int cpio_mkslink(const char *name, const char *target,
char s[256]; char s[256];
time_t mtime = time(NULL); time_t mtime = time(NULL);
if (name[0] == '/')
name++;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X", "%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */ "070701", /* magic */
...@@ -152,6 +154,8 @@ static int cpio_mkgeneric(const char *name, unsigned int mode, ...@@ -152,6 +154,8 @@ static int cpio_mkgeneric(const char *name, unsigned int mode,
char s[256]; char s[256];
time_t mtime = time(NULL); time_t mtime = time(NULL);
if (name[0] == '/')
name++;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X", "%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */ "070701", /* magic */
...@@ -245,6 +249,8 @@ static int cpio_mknod(const char *name, unsigned int mode, ...@@ -245,6 +249,8 @@ static int cpio_mknod(const char *name, unsigned int mode,
else else
mode |= S_IFCHR; mode |= S_IFCHR;
if (name[0] == '/')
name++;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X", "%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */ "070701", /* magic */
...@@ -332,6 +338,8 @@ static int cpio_mkfile(const char *name, const char *location, ...@@ -332,6 +338,8 @@ static int cpio_mkfile(const char *name, const char *location,
/* data goes on last link */ /* data goes on last link */
if (i == nlinks) size = buf.st_size; if (i == nlinks) size = buf.st_size;
if (name[0] == '/')
name++;
namesize = strlen(name) + 1; namesize = strlen(name) + 1;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
"%08lX%08X%08X%08X%08X%08X%08X", "%08lX%08X%08X%08X%08X%08X%08X",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment