Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Pdtzf-0004co-8t for mharc-grub-devel@gnu.org; Fri, 14 Jan 2011 19:27:47 -0500 Received: from [140.186.70.92] (port=55233 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pdtza-0004XG-Um for grub-devel@gnu.org; Fri, 14 Jan 2011 19:27:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PdtzY-0006AV-Im for grub-devel@gnu.org; Fri, 14 Jan 2011 19:27:42 -0500 Received: from cox.rootnode.net ([89.248.165.14]:57953) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PdtzY-0006A7-65 for grub-devel@gnu.org; Fri, 14 Jan 2011 19:27:40 -0500 Received: from DSPAM-Daemon (localhost [127.0.0.1]) by cox.rootnode.net (Postfix) with SMTP id 13C168015242 for ; Sat, 15 Jan 2011 01:21:58 +0100 (CET) Received: from athlon.localnet (89-78-157-238.dynamic.chello.pl [89.78.157.238]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by cox.rootnode.net (Postfix) with ESMTPSA id D84AC801481E for ; Sat, 15 Jan 2011 01:21:57 +0100 (CET) From: Szymon Janc To: The development of GNU GRUB Date: Sat, 15 Jan 2011 01:21:58 +0100 User-Agent: KMail/1.13.5 (Linux/2.6.32-5-686; KDE/4.5.3; i686; ; ) MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_miOMNptxIcViCQ4" Message-Id: <201101150121.59016.szymon@janc.net.pl> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.3.7 (cox.rootnode.net [0.0.0.0]); Sat, 15 Jan 2011 01:21:57 +0100 (CET) X-DSPAM-Result: Whitelisted X-DSPAM-Processed: Sat Jan 15 01:21:58 2011 X-DSPAM-Confidence: 0.9911 X-DSPAM-Probability: 0.0000 X-DSPAM-Signature: 4d30e8a6164201804284693 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [PATCH] Support for unknown size and not seekable files X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Jan 2011 00:27:45 -0000 --Boundary-00=_miOMNptxIcViCQ4 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hello, First patch adds support for GRUB_FILE_SIZE_UNKNOW file size in grub_file_read and grub_file_seek functions. Second and third add GRUB_FILE_SIZE_UNKNOW support for gzio and xzio when dealing with not easily seekable files. Should be usefull for reading compressed files over pxe. Testing and comments are welcome :) -- Szymon K. Janc szymon@janc.net.pl // GG: 1383435 --Boundary-00=_miOMNptxIcViCQ4 Content-Type: text/x-patch; charset="UTF-8"; name="01_unknown_file_size_support.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="01_unknown_file_size_support.diff" === modified file 'ChangeLog' --- ChangeLog 2011-01-13 21:25:56 +0000 +++ ChangeLog 2011-01-14 23:53:37 +0000 @@ -1,3 +1,8 @@ +2011-01-15 Szymon Janc + + * grub-core/kern/file.c (grub_file_read): Handle unknown file size. + (grub_file_seek): Likewise. + 2011-01-13 Vladimir Serbinenko * grub-core/fs/zfs/zfsinfo.c (grub_cmd_zfs_bootfs): Quote bootpath and === modified file 'grub-core/kern/file.c' --- grub-core/kern/file.c 2010-09-05 11:05:36 +0000 +++ grub-core/kern/file.c 2011-01-14 23:53:37 +0000 @@ -132,15 +132,18 @@ grub_file_read (grub_file_t file, void * { grub_ssize_t res; - if (file->offset > file->size) + if (file->size != GRUB_FILE_SIZE_UNKNOWN) { - grub_error (GRUB_ERR_OUT_OF_RANGE, - "attempt to read past the end of file"); - return -1; - } + if (file->offset > file->size) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, + "attempt to read past the end of file"); + return -1; + } - if (len == 0 || len > file->size - file->offset) - len = file->size - file->offset; + if (len == 0 || len > file->size - file->offset) + len = file->size - file->offset; + } /* Prevent an overflow. */ if ((grub_ssize_t) len < 0) @@ -171,16 +174,22 @@ grub_file_close (grub_file_t file) grub_off_t grub_file_seek (grub_file_t file, grub_off_t offset) { - grub_off_t old; + grub_off_t old = file->offset; + + if (file->size == GRUB_FILE_SIZE_UNKNOWN && offset > file->offset) + { + if (grub_file_read (file, NULL, offset - file->offset) < 0) + return -1; + else + return old; + } if (offset > file->size) { - grub_error (GRUB_ERR_OUT_OF_RANGE, - "attempt to seek outside of the file"); + grub_error (GRUB_ERR_OUT_OF_RANGE, "attempt to seek outside of the file"); return -1; } - old = file->offset; file->offset = offset; return old; } --Boundary-00=_miOMNptxIcViCQ4 Content-Type: text/x-patch; charset="UTF-8"; name="02_notseekable_file_gzio.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="02_notseekable_file_gzio.diff" === modified file 'ChangeLog' --- ChangeLog 2011-01-14 23:53:37 +0000 +++ ChangeLog 2011-01-15 00:03:32 +0000 @@ -1,5 +1,13 @@ 2011-01-15 Szymon Janc + * grub-core/io/gzio.c (test_header): For not seekable files: don't + check footer and set size to unknown. + (inflate_window): Set real size for unknown size file when it is + known. + (grub_gzio_read): Handle NULL buffer pointer. + +2011-01-15 Szymon Janc + * grub-core/kern/file.c (grub_file_read): Handle unknown file size. (grub_file_seek): Likewise. === modified file 'grub-core/io/gzio.c' --- grub-core/io/gzio.c 2010-12-26 20:15:31 +0000 +++ grub-core/io/gzio.c 2011-01-15 00:03:32 +0000 @@ -212,7 +212,7 @@ test_header (grub_file_t file) gzio->data_offset = grub_file_tell (gzio->file); - /* FIXME: don't do this on not easily seekable files. */ + if(grub_file_seekable(gzio->file)) { grub_file_seek (gzio->file, grub_file_size (gzio->file) - 4); if (grub_file_read (gzio->file, &orig_len, 4) != 4) @@ -224,6 +224,8 @@ test_header (grub_file_t file) But how can we know the real original size? */ file->size = grub_le_to_cpu32 (orig_len); } + else + file->size = GRUB_FILE_SIZE_UNKNOWN; initialize_tables (file); @@ -1034,7 +1036,11 @@ inflate_window (grub_file_t file) if (! gzio->block_len) { if (gzio->last_block) - break; + { + if (file->size == GRUB_FILE_SIZE_UNKNOWN) + file->size = file->offset + gzio->wp; + break; + } get_new_block (file); } @@ -1186,9 +1192,11 @@ grub_gzio_read (grub_file_t file, char * if (size > len) size = len; - grub_memmove (buf, srcaddr, size); - - buf += size; + if (buf) + { + grub_memmove (buf, srcaddr, size); + buf += size; + } len -= size; ret += size; offset += size; --Boundary-00=_miOMNptxIcViCQ4 Content-Type: text/x-patch; charset="UTF-8"; name="03_notseekable_file_xzio.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="03_notseekable_file_xzio.diff" === modified file 'ChangeLog' --- ChangeLog 2011-01-15 00:03:32 +0000 +++ ChangeLog 2011-01-15 00:08:24 +0000 @@ -1,5 +1,12 @@ 2011-01-15 Szymon Janc + * grub-core/io/xzio.c (test_footer): Return true for not seekable file. + (grub_xzio_open): FIXME comment removed. + (grub_xzio_read): Set real size for unknown size file when it is known. + Handle NULL buffer pointer. + +2011-01-15 Szymon Janc + * grub-core/io/gzio.c (test_header): For not seekable files: don't check footer and set size to unknown. (inflate_window): Set real size for unknown size file when it is === modified file 'grub-core/io/xzio.c' --- grub-core/io/xzio.c 2010-12-26 20:15:31 +0000 +++ grub-core/io/xzio.c 2011-01-15 00:08:24 +0000 @@ -129,6 +129,10 @@ test_footer (grub_file_t file) grub_uint64_t uncompressed_size; grub_uint64_t records; + /* Don't test footer on not easily seekable files. */ + if (! grub_file_seekable(xzio->file)) + return 1; + grub_file_seek (xzio->file, xzio->file->size - FOOTER_MAGIC_SIZE); if (grub_file_read (xzio->file, footer, FOOTER_MAGIC_SIZE) != FOOTER_MAGIC_SIZE @@ -222,7 +226,6 @@ grub_xzio_open (grub_file_t io) xzio->buf.out_pos = 0; xzio->buf.out_size = XZBUFSIZ; - /* FIXME: don't test footer on not easily seekable files. */ if (!test_header (file) || !test_footer (file)) { grub_errno = GRUB_ERR_NONE; @@ -297,10 +300,14 @@ grub_xzio_read (grub_file_t file, char * /* Store first chunk of data in buffer. */ { grub_size_t delta = new_offset - (file->offset + ret); - grub_memmove (buf, xzio->buf.out + (xzio->buf.out_pos - delta), + + if (buf) + { + grub_memmove (buf, xzio->buf.out + (xzio->buf.out_pos - delta), delta); + buf += delta; + } len -= delta; - buf += delta; ret += delta; } current_offset = new_offset; @@ -308,7 +315,11 @@ grub_xzio_read (grub_file_t file, char * xzio->buf.out_pos = 0; if (xzret == XZ_STREAM_END) /* Stream end, EOF. */ - break; + { + if(file->size == GRUB_FILE_SIZE_UNKNOWN) + file->size = file->offset + ret; + break; + } } if (ret >= 0) --Boundary-00=_miOMNptxIcViCQ4--