linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] 2.5.29-rdunzip
@ 2002-10-17 10:45 Russell King
  0 siblings, 0 replies; 3+ messages in thread
From: Russell King @ 2002-10-17 10:45 UTC (permalink / raw)
  To: LKML; +Cc: Linus Torvalds

This patch appears not to be in 2.5.43, but applies cleanly.

This patch ensures that we report failures when unzipping ramdisks and the
like, including if we fail to write to the ramdisk.

Unfortunately, there is no way to guarantee that the gunzip function will
ever terminate (gzip itself uses a setjmp and longjmp to achieve this).

 init/do_mounts.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions, 3 deletions

diff -urN orig/init/do_mounts.c linux/init/do_mounts.c
--- orig/init/do_mounts.c	Sat Jul 27 13:55:25 2002
+++ linux/init/do_mounts.c	Sat Jul 27 14:13:56 2002
@@ -877,6 +877,7 @@
 static unsigned inptr;   /* index of next byte to be processed in inbuf */
 static unsigned outcnt;  /* bytes in output buffer */
 static int exit_code;
+static int unzip_error;
 static long bytes_out;
 static int crd_infd, crd_outfd;
 
@@ -924,13 +925,17 @@
 /* ===========================================================================
  * Fill the input buffer. This is called only when the buffer is empty
  * and at least one byte is really needed.
+ * Returning -1 does not guarantee that gunzip() will ever return.
  */
 static int __init fill_inbuf(void)
 {
 	if (exit_code) return -1;
 	
 	insize = read(crd_infd, inbuf, INBUFSIZ);
-	if (insize == 0) return -1;
+	if (insize == 0) {
+		error("RAMDISK: ran out of compressed data\n");
+		return -1;
+	}
 
 	inptr = 1;
 
@@ -944,10 +949,15 @@
 static void __init flush_window(void)
 {
     ulg c = crc;         /* temporary variable */
-    unsigned n;
+    unsigned n, written;
     uch *in, ch;
     
-    write(crd_outfd, window, outcnt);
+    written = write(crd_outfd, window, outcnt);
+    if (written != outcnt && unzip_error == 0) {
+	printk(KERN_ERR "RAMDISK: incomplete write (%d != %d) %d\n",
+	       written, outcnt, bytes_out);
+	unzip_error = 1;
+    }
     in = window;
     for (n = 0; n < outcnt; n++) {
 	    ch = *in++;
@@ -962,6 +972,7 @@
 {
 	printk(KERN_ERR "%s", x);
 	exit_code = 1;
+	unzip_error = 1;
 }
 
 static int __init crd_load(int in_fd, int out_fd)
@@ -990,6 +1001,8 @@
 	}
 	makecrc();
 	result = gunzip();
+	if (unzip_error)
+		result = 1;
 	kfree(inbuf);
 	kfree(window);
 	return result;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] 2.5.29-rdunzip
@ 2002-11-18 10:15 Russell King
  0 siblings, 0 replies; 3+ messages in thread
From: Russell King @ 2002-11-18 10:15 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: LKML

This patch appears not to be in 2.5.48, but applies cleanly.

This patch ensures that we report failures when unzipping ramdisks and the
like, including if we fail to write to the ramdisk.

Unfortunately, there is no way to guarantee that the gunzip function will
ever terminate (gzip itself uses a setjmp and longjmp to achieve this).

I wish that the ramdisk gunzip code would disappear for 2.6, replaced by
an initramfs solution which should be able to handle such failure cases
more cleanly.

 init/do_mounts.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions, 3 deletions

diff -urN orig/init/do_mounts.c linux/init/do_mounts.c
--- orig/init/do_mounts.c	Sat Jul 27 13:55:25 2002
+++ linux/init/do_mounts.c	Sat Jul 27 14:13:56 2002
@@ -877,6 +877,7 @@
 static unsigned inptr;   /* index of next byte to be processed in inbuf */
 static unsigned outcnt;  /* bytes in output buffer */
 static int exit_code;
+static int unzip_error;
 static long bytes_out;
 static int crd_infd, crd_outfd;
 
@@ -924,13 +925,17 @@
 /* ===========================================================================
  * Fill the input buffer. This is called only when the buffer is empty
  * and at least one byte is really needed.
+ * Returning -1 does not guarantee that gunzip() will ever return.
  */
 static int __init fill_inbuf(void)
 {
 	if (exit_code) return -1;
 	
 	insize = read(crd_infd, inbuf, INBUFSIZ);
-	if (insize == 0) return -1;
+	if (insize == 0) {
+		error("RAMDISK: ran out of compressed data\n");
+		return -1;
+	}
 
 	inptr = 1;
 
@@ -944,10 +949,15 @@
 static void __init flush_window(void)
 {
     ulg c = crc;         /* temporary variable */
-    unsigned n;
+    unsigned n, written;
     uch *in, ch;
     
-    write(crd_outfd, window, outcnt);
+    written = write(crd_outfd, window, outcnt);
+    if (written != outcnt && unzip_error == 0) {
+	printk(KERN_ERR "RAMDISK: incomplete write (%d != %d) %d\n",
+	       written, outcnt, bytes_out);
+	unzip_error = 1;
+    }
     in = window;
     for (n = 0; n < outcnt; n++) {
 	    ch = *in++;
@@ -962,6 +972,7 @@
 {
 	printk(KERN_ERR "%s", x);
 	exit_code = 1;
+	unzip_error = 1;
 }
 
 static int __init crd_load(int in_fd, int out_fd)
@@ -990,6 +1001,8 @@
 	}
 	makecrc();
 	result = gunzip();
+	if (unzip_error)
+		result = 1;
 	kfree(inbuf);
 	kfree(window);
 	return result;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] 2.5.29-rdunzip
@ 2002-08-30 21:39 Russell King
  0 siblings, 0 replies; 3+ messages in thread
From: Russell King @ 2002-08-30 21:39 UTC (permalink / raw)
  To: LKML

This patch appears not to be in 2.5.32, but applies cleanly.

This patch ensures that we report failures when unzipping ramdisks and the
like, including if we fail to write to the ramdisk.

Unfortunately, there is no way to guarantee that the gunzip function will
ever terminate (gzip itself uses a setjmp and longjmp to achieve this).

 init/do_mounts.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions, 3 deletions

diff -urN orig/init/do_mounts.c linux/init/do_mounts.c
--- orig/init/do_mounts.c	Sat Jul 27 13:55:25 2002
+++ linux/init/do_mounts.c	Sat Jul 27 14:13:56 2002
@@ -877,6 +877,7 @@
 static unsigned inptr;   /* index of next byte to be processed in inbuf */
 static unsigned outcnt;  /* bytes in output buffer */
 static int exit_code;
+static int unzip_error;
 static long bytes_out;
 static int crd_infd, crd_outfd;
 
@@ -924,13 +925,17 @@
 /* ===========================================================================
  * Fill the input buffer. This is called only when the buffer is empty
  * and at least one byte is really needed.
+ * Returning -1 does not guarantee that gunzip() will ever return.
  */
 static int __init fill_inbuf(void)
 {
 	if (exit_code) return -1;
 	
 	insize = read(crd_infd, inbuf, INBUFSIZ);
-	if (insize == 0) return -1;
+	if (insize == 0) {
+		error("RAMDISK: ran out of compressed data\n");
+		return -1;
+	}
 
 	inptr = 1;
 
@@ -944,10 +949,15 @@
 static void __init flush_window(void)
 {
     ulg c = crc;         /* temporary variable */
-    unsigned n;
+    unsigned n, written;
     uch *in, ch;
     
-    write(crd_outfd, window, outcnt);
+    written = write(crd_outfd, window, outcnt);
+    if (written != outcnt && unzip_error == 0) {
+	printk(KERN_ERR "RAMDISK: incomplete write (%d != %d) %d\n",
+	       written, outcnt, bytes_out);
+	unzip_error = 1;
+    }
     in = window;
     for (n = 0; n < outcnt; n++) {
 	    ch = *in++;
@@ -962,6 +972,7 @@
 {
 	printk(KERN_ERR "%s", x);
 	exit_code = 1;
+	unzip_error = 1;
 }
 
 static int __init crd_load(int in_fd, int out_fd)
@@ -990,6 +1001,8 @@
 	}
 	makecrc();
 	result = gunzip();
+	if (unzip_error)
+		result = 1;
 	kfree(inbuf);
 	kfree(window);
 	return result;


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-11-18 10:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-17 10:45 [PATCH] 2.5.29-rdunzip Russell King
  -- strict thread matches above, loose matches on Subject: below --
2002-11-18 10:15 Russell King
2002-08-30 21:39 Russell King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).