* [PATCH] sprintf modifiers in usr/gen_init_cpio.c
@ 2004-02-18 0:26 Pragnesh Sampat
2004-02-18 0:44 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Pragnesh Sampat @ 2004-02-18 0:26 UTC (permalink / raw)
To: bos; +Cc: linux-kernel, akpm
The file initramfs_data.cpio is slightly different when generated on
cygwin, compared to linux, which causes the kernel to panic with the
message "no cpio magic" (See Documentation/early-userspace/README).
The problem in cpio generation is due to the difference in sprintf
modifiers on cygwin. The code uses "%08ZX" for strlen of a device
node. printf man pages discourages "Z" and has 'z' instead.
Both of these are not available on cygwin sprintf (at least some
versions of cygwin). The net result of all of this is that the
generated file literally contains "ZX" and then the strlen after that
and messes up that 110 offset etc. The file is 516 bytes long on the
system that I tested and on linux it is 512 bytes.
The fix below just uses "%08X" for that field. Any basic portable
modifier should be ok, I think.
-Pragnesh
--- usr/gen_init_cpio.c-orig
+++ usr/gen_init_cpio.c
@@ -56,7 +56,7 @@
const char name[] = "TRAILER!!!";
sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
- "%08X%08X%08X%08X%08X%08ZX%08X",
+ "%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
0, /* ino */
0, /* mode */
@@ -87,7 +87,7 @@
time_t mtime = time(NULL);
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
- "%08X%08X%08X%08X%08X%08ZX%08X",
+ "%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
ino++, /* ino */
S_IFDIR | mode, /* mode */
@@ -119,7 +119,7 @@
mode |= S_IFCHR;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
- "%08X%08X%08X%08X%08X%08ZX%08X",
+ "%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
ino++, /* ino */
mode, /* mode */
@@ -176,7 +176,7 @@
}
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
- "%08X%08X%08X%08X%08X%08ZX%08X",
+ "%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
ino++, /* ino */
mode, /* mode */
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sprintf modifiers in usr/gen_init_cpio.c
2004-02-18 0:26 [PATCH] sprintf modifiers in usr/gen_init_cpio.c Pragnesh Sampat
@ 2004-02-18 0:44 ` Andrew Morton
2004-02-18 4:05 ` Pragnesh Sampat
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2004-02-18 0:44 UTC (permalink / raw)
To: Pragnesh Sampat; +Cc: bos, linux-kernel
Pragnesh Sampat <pragnesh.sampat@timesys.com> wrote:
>
> The file initramfs_data.cpio is slightly different when generated on
> cygwin, compared to linux, which causes the kernel to panic with the
> message "no cpio magic" (See Documentation/early-userspace/README).
>
> The problem in cpio generation is due to the difference in sprintf
> modifiers on cygwin. The code uses "%08ZX" for strlen of a device
> node. printf man pages discourages "Z" and has 'z' instead.
> Both of these are not available on cygwin sprintf (at least some
> versions of cygwin). The net result of all of this is that the
> generated file literally contains "ZX" and then the strlen after that
> and messes up that 110 offset etc. The file is 516 bytes long on the
> system that I tested and on linux it is 512 bytes.
>
> The fix below just uses "%08X" for that field. Any basic portable
> modifier should be ok, I think.
ugh, OK.
We'll also need to cast the return value of strlen to the correct type. On
ppc64 (at least) size_t is 8 bytes and the printf will otherwise grab the wrong
things off the stack.
diff -puN usr/gen_init_cpio.c~cygwin-cpio-fix usr/gen_init_cpio.c
--- 25/usr/gen_init_cpio.c~cygwin-cpio-fix Tue Feb 17 16:42:36 2004
+++ 25-akpm/usr/gen_init_cpio.c Tue Feb 17 16:43:49 2004
@@ -56,7 +56,7 @@ static void cpio_trailer(void)
const char name[] = "TRAILER!!!";
sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
- "%08X%08X%08X%08X%08X%08ZX%08X",
+ "%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
0, /* ino */
0, /* mode */
@@ -69,7 +69,7 @@ static void cpio_trailer(void)
0, /* minor */
0, /* rmajor */
0, /* rminor */
- strlen(name) + 1, /* namesize */
+ (unsigned)strlen(name) + 1, /* namesize */
0); /* chksum */
push_hdr(s);
push_rest(name);
@@ -87,7 +87,7 @@ static void cpio_mkdir(const char *name,
time_t mtime = time(NULL);
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
- "%08X%08X%08X%08X%08X%08ZX%08X",
+ "%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
ino++, /* ino */
S_IFDIR | mode, /* mode */
@@ -100,7 +100,7 @@ static void cpio_mkdir(const char *name,
1, /* minor */
0, /* rmajor */
0, /* rminor */
- strlen(name) + 1, /* namesize */
+ (unsigned)strlen(name) + 1,/* namesize */
0); /* chksum */
push_hdr(s);
push_rest(name);
@@ -119,7 +119,7 @@ static void cpio_mknod(const char *name,
mode |= S_IFCHR;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
- "%08X%08X%08X%08X%08X%08ZX%08X",
+ "%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
ino++, /* ino */
mode, /* mode */
@@ -132,7 +132,7 @@ static void cpio_mknod(const char *name,
1, /* minor */
maj, /* rmajor */
min, /* rminor */
- strlen(name) + 1, /* namesize */
+ (unsigned)strlen(name) + 1,/* namesize */
0); /* chksum */
push_hdr(s);
push_rest(name);
@@ -176,7 +176,7 @@ void cpio_mkfile(const char *filename, c
}
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
- "%08X%08X%08X%08X%08X%08ZX%08X",
+ "%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
ino++, /* ino */
mode, /* mode */
@@ -189,7 +189,7 @@ void cpio_mkfile(const char *filename, c
1, /* minor */
0, /* rmajor */
0, /* rminor */
- strlen(location) + 1, /* namesize */
+ (unsigned)strlen(location) + 1,/* namesize */
0); /* chksum */
push_hdr(s);
push_string(location);
_
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sprintf modifiers in usr/gen_init_cpio.c
2004-02-18 0:44 ` Andrew Morton
@ 2004-02-18 4:05 ` Pragnesh Sampat
0 siblings, 0 replies; 3+ messages in thread
From: Pragnesh Sampat @ 2004-02-18 4:05 UTC (permalink / raw)
To: Andrew Morton; +Cc: bos, linux-kernel
On Tue, 2004-02-17 at 19:44, Andrew Morton wrote:
> Pragnesh Sampat <pragnesh.sampat@timesys.com> wrote:
> >
> > The file initramfs_data.cpio is slightly different when generated on
> > cygwin, compared to linux, which causes the kernel to panic with the
> > message "no cpio magic" (See Documentation/early-userspace/README).
> >
> > The problem in cpio generation is due to the difference in sprintf
> > modifiers on cygwin. The code uses "%08ZX" for strlen of a device
> > node. printf man pages discourages "Z" and has 'z' instead.
> > Both of these are not available on cygwin sprintf (at least some
> > versions of cygwin). The net result of all of this is that the
> > generated file literally contains "ZX" and then the strlen after that
> > and messes up that 110 offset etc. The file is 516 bytes long on the
> > system that I tested and on linux it is 512 bytes.
> >
> > The fix below just uses "%08X" for that field. Any basic portable
> > modifier should be ok, I think.
>
> ugh, OK.
>
> We'll also need to cast the return value of strlen to the correct type. On
> ppc64 (at least) size_t is 8 bytes and the printf will otherwise grab the wrong
> things off the stack.
[ Removed the patch ]
Yes, agree with your change, I think all 64 bit archs using
longs/pointer = 8 probably benefit from the cast. Thanks,
-Pragnesh
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-02-18 4:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-18 0:26 [PATCH] sprintf modifiers in usr/gen_init_cpio.c Pragnesh Sampat
2004-02-18 0:44 ` Andrew Morton
2004-02-18 4:05 ` Pragnesh Sampat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®