From 3759a35f757924867450ec3c8ffca6e64cd9b7c5 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sat, 4 Sep 2010 18:28:42 +0200 Subject: [PATCH] * include/grub/file.h (grub_file): New member not_easly_seekable. (grub_file_seekable): New inline function. * grub-core/io/gzio.c (test_header): Don't test end magic if file isn't easily seekable. (grub_gzio_open): Set not_easly_seekable. * grub-core/fs/i386/pc/pxe.c (grub_pxefs_open): Set not_easily_seekable. * grub-core/io/bufio.c (grub_bufio_open): Propagate not_easily_seekable. --- ChangeLog | 10 ++++++++++ grub-core/fs/i386/pc/pxe.c | 1 + grub-core/io/bufio.c | 1 + grub-core/io/gzio.c | 11 +++++++---- include/grub/file.h | 9 +++++++++ 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index a155853d9..fee952996 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-09-04 Szymon Janc + + * include/grub/file.h (grub_file): New member not_easly_seekable. + (grub_file_seekable): New inline function. + * grub-core/io/gzio.c (test_header): Don't test end magic if file isn't + easily seekable. + (grub_gzio_open): Set not_easly_seekable. + * grub-core/fs/i386/pc/pxe.c (grub_pxefs_open): Set not_easily_seekable. + * grub-core/io/bufio.c (grub_bufio_open): Propagate not_easily_seekable. + 2010-09-04 BVK Chaitanya Support for options to appear multiple times on cmdline. diff --git a/grub-core/fs/i386/pc/pxe.c b/grub-core/fs/i386/pc/pxe.c index 90dfd5067..baaff0ffc 100644 --- a/grub-core/fs/i386/pc/pxe.c +++ b/grub-core/fs/i386/pc/pxe.c @@ -282,6 +282,7 @@ grub_pxefs_open (struct grub_file *file, const char *name) } file->data = data; + file->not_easly_seekable = 1; grub_memcpy (file_int, file, sizeof (struct grub_file)); curr_file = file_int; diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c index 92f29279e..8a72ecd79 100644 --- a/grub-core/io/bufio.c +++ b/grub-core/io/bufio.c @@ -74,6 +74,7 @@ grub_bufio_open (grub_file_t io, int size) file->data = bufio; file->read_hook = 0; file->fs = &grub_bufio_fs; + file->not_easly_seekable = io->not_easly_seekable; return file; } diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c index 9bf609105..0545e32bd 100644 --- a/grub-core/io/gzio.c +++ b/grub-core/io/gzio.c @@ -214,12 +214,14 @@ test_header (grub_file_t file) grub_file_seek (gzio->file, grub_file_size (gzio->file) - 4); - if (grub_file_read (gzio->file, &orig_len, 4) != 4) + if (grub_file_seekable (gzio->file)) { - grub_error (GRUB_ERR_BAD_FILE_TYPE, "unsupported gzip format"); - return 0; + if (grub_file_read (gzio->file, &orig_len, 4) != 4) + { + grub_error (GRUB_ERR_BAD_FILE_TYPE, "unsupported gzip format"); + return 0; + } } - /* FIXME: this does not handle files whose original size is over 4GB. But how can we know the real original size? */ file->size = grub_le_to_cpu32 (orig_len); @@ -1135,6 +1137,7 @@ grub_gzio_open (grub_file_t io, int transparent) file->data = gzio; file->read_hook = 0; file->fs = &grub_gzio_fs; + file->not_easly_seekable = 1; if (! test_header (file)) { diff --git a/include/grub/file.h b/include/grub/file.h index 2aacf936f..05c9907d5 100644 --- a/include/grub/file.h +++ b/include/grub/file.h @@ -39,6 +39,9 @@ struct grub_file /* The file size. */ grub_off_t size; + /* If file is not easly seekable. Should be set by underlying layer. */ + int not_easly_seekable; + /* Filesystem-specific data. */ void *data; @@ -69,4 +72,10 @@ grub_file_tell (const grub_file_t file) return file->offset; } +static inline int +grub_file_seekable (const grub_file_t file) +{ + return !file->not_easly_seekable; +} + #endif /* ! GRUB_FILE_HEADER */