transparent io
PATCH 1/1 transparent io
Hello,
New version with various fixes and suggestions from ML and IRC. 03_transparentio_indent.diff contains indetation fixes only not to blackout 04_transparentio.diff.
This patch depends on 02_fileseek.diff from previous post. Commenst and testing are welcome.
TODO:
disable filters where necessary
Signature · 2 lines
Szymon K. Janc [email protected] // GG: 1383435
=== modified file 'io/bufio.c'
bufio.c +48 -49
@@ -45,7 +45,7 @@grub_bufio_t bufio =0 ; file = (grub_file_t )grub_malloc (sizeof (*file)); -if (! file) +if (!file)return 0 ;if (size ==0 )
@@ -55,10 +55,10 @@if ((size <0 ) || ((unsigned ) size > io->size)) size = ((io->size >GRUB_BUFIO_MAX_SIZE ) ?GRUB_BUFIO_MAX_SIZE : - io->size); + io->size); bufio =grub_malloc (sizeof (struct grub_bufio ) + size); -if (! bufio) +if (!bufio) {grub_free (file);return 0 ;
@@ -84,11 +84,11 @@grub_file_t io, file; io =grub_file_open (name); -if (! io) +if (!io)return 0 ; file =grub_bufio_open (io, size); -if (! file) +if (!file) {grub_file_close (io);return 0 ;
@@ -112,12 +112,12 @@ pos = file->offset - bufio->file->offset; n = bufio->buffer_len - pos;if (n > len) - n = len; + n = len;grub_memcpy (buf, &bufio->buffer[pos], n); len -= n; -if (! len) -return res; +if (!len) +return res; buf += n; bufio->file->offset += bufio->buffer_len;
@@ -126,45 +126,45 @@else { bufio->file->offset =grub_divmod64 (file->offset, bufio->block_size, - &pos); + &pos); bufio->file->offset *= bufio->block_size; }if (pos + len >= bufio->block_size) {if (pos) - { -grub_size_t n; - - bufio->file->fs->read (bufio->file, bufio->buffer, - bufio->block_size); -if (grub_errno) -return -1 ; - - n = bufio->block_size - pos; -grub_memcpy (buf, &bufio->buffer[pos], n); - len -= n; - buf += n; - bufio->file->offset += bufio->block_size; - pos =0 ; - } + { +grub_size_t n; + + bufio->file->fs->read (bufio->file, bufio->buffer, + bufio->block_size); +if (grub_errno) +return -1 ; + + n = bufio->block_size - pos; +grub_memcpy (buf, &bufio->buffer[pos], n); + len -= n; + buf += n; + bufio->file->offset += bufio->block_size; + pos =0 ; + }while (len >= bufio->block_size) - { - bufio->file->fs->read (bufio->file, buf, bufio->block_size); -if (grub_errno) -return -1 ; - - len -= bufio->block_size; - buf += bufio->block_size; - bufio->file->offset += bufio->block_size; - } - -if (! len) - { - bufio->buffer_len =0 ; -return res; - } + { + bufio->file->fs->read (bufio->file, buf, bufio->block_size); +if (grub_errno) +return -1 ; + + len -= bufio->block_size; + buf += bufio->block_size; + bufio->file->offset += bufio->block_size; + } + +if (!len) + { + bufio->buffer_len =0 ; +return res; + } } bufio->buffer_len = bufio->file->size - bufio->file->offset;
@@ -193,13 +193,12 @@return grub_errno; } -static struct grub_fs grub_bufio_fs = - { - .name ="bufio" , - .dir =0 , - .open =0 , - .read = grub_bufio_read, - .close = grub_bufio_close, - .label =0 , - .next =0 - }; +static struct grub_fs grub_bufio_fs = { + .name ="bufio" , + .dir =0 , + .open =0 , + .read = grub_bufio_read, + .close = grub_bufio_close, + .label =0 , + .next =0 +};
=== modified file 'commands/acpi.c'
acpi.c +1 -2
@@ -23,7 +23,6 @@#include <grub/disk.h> #include <grub/term.h> #include <grub/misc.h> -#include <grub/gzio.h> #include <grub/acpi.h> #include <grub/mm.h> #include <grub/machine/memory.h>
@@ -627,7 +626,7 @@grub_size_t size;char *buf; - file =grub_gzfile_open (args[i],1 ); + file =grub_file_open (args[i]);if (! file) {free_tables ();
=== modified file 'commands/cat.c'
cat.c +1 -2
@@ -22,7 +22,6 @@#include <grub/disk.h> #include <grub/term.h> #include <grub/misc.h> -#include <grub/gzio.h> #include <grub/command.h> #include <grub/i18n.h>
@@ -39,7 +38,7 @@if (argc !=1 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"file name required" ); - file =grub_gzfile_open (args[0 ],1 ); + file =grub_file_open (args[0 ]);if (! file)return grub_errno;
=== modified file 'commands/cmp.c'
cmp.c +2 -3
@@ -21,7 +21,6 @@#include <grub/misc.h> #include <grub/file.h> #include <grub/mm.h> -#include <grub/gzio.h> #include <grub/command.h> #include <grub/i18n.h>
@@ -44,8 +43,8 @@grub_printf ("Compare file `%s' with `%s':\n" , args[0 ], args[1 ]); - file1 =grub_gzfile_open (args[0 ],1 ); - file2 =grub_gzfile_open (args[1 ],1 ); + file1 =grub_file_open (args[0 ]); + file2 =grub_file_open (args[1 ]);if (! file1 || ! file2) goto cleanup;
=== modified file 'commands/hexdump.c'
hexdump.c +2 -2
@@ -21,7 +21,6 @@#include <grub/file.h> #include <grub/disk.h> #include <grub/misc.h> -#include <grub/gzio.h> #include <grub/lib/hexdump.h> #include <grub/extcmd.h> #include <grub/i18n.h>
@@ -89,7 +88,8 @@ {grub_file_t file; - file =grub_gzfile_open (args[0 ],1 ); +grub_io_filter_disable_all (); + file =grub_file_open (args[0 ]);if (! file)return 0 ;
=== modified file 'gettext/gettext.c'
gettext.c +1 -2
@@ -26,7 +26,6 @@#include <grub/normal.h> #include <grub/file.h> #include <grub/kernel.h> -#include <grub/gzio.h> #include <grub/i18n.h> /*
@@ -229,7 +228,7 @@/* Using fd_mo and not another variable because it's needed for grub_gettext_get_info. */ - fd_mo =grub_gzfile_open (filename,1 ); + fd_mo =grub_file_open (filename); grub_errno =GRUB_ERR_NONE ;if (!fd_mo)
=== modified file 'include/grub/err.h'
grub/err.h +1 -1
@@ -50,7 +50,7 @@GRUB_ERR_BAD_FONT ,GRUB_ERR_NOT_IMPLEMENTED_YET ,GRUB_ERR_SYMLINK_LOOP , -GRUB_ERR_BAD_GZIP_DATA , +GRUB_ERR_BAD_IOFILTER_DATA ,GRUB_ERR_MENU ,GRUB_ERR_TIMEOUT , GRUB_ERR_IO,
=== modified file 'include/grub/file.h'
grub/file.h +98 -0
114 lines not on this page · raw message
=== removed file 'include/grub/gzio.h'
grub/gzio.h +0 -28
@@ -1,28 +0,0 @@ -/* gzio.h - prototypes for gzio */ -/* -* GRUB -- GRand Unified Bootloader -* Copyright (C) 2005,2007 Free Software Foundation, Inc. -* -* GRUB is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* GRUB is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with GRUB. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef GRUB_GZIO_H -#define GRUB_GZIO_H 1 - -#include <grub/file.h> - -grub_file_t grub_gzio_open (grub_file_t io,int transparent); -grub_file_t grub_gzfile_open (const char *name,int transparent); - -#endif /* ! GRUB_GZIO_H */
=== modified file 'io/bufio.c'
bufio.c +3 -0
@@ -83,6 +83,7 @@ {grub_file_t io, file; +grub_io_filter_disable_all (); io =grub_file_open (name);if (!io)return 0 ;
@@ -94,6 +95,8 @@return 0 ; } + +return file; }
=== modified file 'io/gzio.c'
gzio.c +38 -46
207 lines not on this page · raw message
=== modified file 'kern/elf.c'
elf.c +1 -2
@@ -21,7 +21,6 @@#include <grub/elf.h> #include <grub/elfload.h> #include <grub/file.h> -#include <grub/gzio.h> #include <grub/misc.h> #include <grub/mm.h>
@@ -95,7 +94,7 @@grub_file_t file;grub_elf_t elf; - file =grub_gzfile_open (name,1 ); + file =grub_file_open (name);if (! file)return 0 ;
=== modified file 'kern/file.c'
file.c +47 -1
66 lines not on this page · raw message
=== modified file 'loader/i386/bsd.c'
i386/bsd.c +5 -6
@@ -30,7 +30,6 @@#include <grub/elfload.h> #include <grub/env.h> #include <grub/misc.h> -#include <grub/gzio.h> #include <grub/aout.h> #include <grub/command.h> #include <grub/extcmd.h>
@@ -904,7 +903,7 @@ goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (!file) goto fail;
@@ -970,7 +969,7 @@if (err)return err; - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (! file)return grub_errno;
@@ -1086,7 +1085,7 @@ goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if ((!file) || (!file->size)) goto fail;
@@ -1191,7 +1190,7 @@return 0 ; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if ((!file) || (!file->size)) goto fail;
@@ -1257,7 +1256,7 @@return 0 ; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (!file)return grub_errno;if (!file->size)
=== modified file 'loader/i386/efi/linux.c'
i386/efi/linux.c +1 -0
@@ -919,6 +919,7 @@ goto fail; } +grub_io_filter_disable_all (); file =grub_file_open (argv[0 ]);if (! file) goto fail;
=== modified file 'loader/i386/ieee1275/linux.c'
i386/ieee1275/linux.c +1 -0
@@ -274,6 +274,7 @@ goto fail; } +grub_io_filter_disable_all (); file =grub_file_open (argv[0 ]);if (! file) goto fail;
=== modified file 'loader/i386/linux.c'
i386/linux.c +1 -0
@@ -934,6 +934,7 @@ goto fail; } +grub_io_filter_disable_all (); file =grub_file_open (argv[0 ]);if (! file) goto fail;
=== modified file 'loader/i386/pc/linux.c'
i386/pc/linux.c +1 -0
@@ -359,6 +359,7 @@ addr_min = (grub_addr_t ) grub_linux_tmp_addr +GRUB_LINUX_CL_END_OFFSET ; +grub_io_filter_disable_all (); file =grub_file_open (argv[0 ]);if (!file) goto fail;
=== modified file 'loader/i386/xnu.c'
i386/xnu.c +1 -2
@@ -31,7 +31,6 @@#include <grub/charset.h> #include <grub/term.h> #include <grub/command.h> -#include <grub/gzio.h> #include <grub/i18n.h> char grub_xnu_cmdline[1024 ];
@@ -530,7 +529,7 @@if (argc !=1 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"file name required" ); - file =grub_gzfile_open (args[0 ],1 ); + file =grub_file_open (args[0 ]);if (! file)return grub_error (GRUB_ERR_FILE_NOT_FOUND ,"couldn't load device-propertie dump" );
=== modified file 'loader/macho.c'
macho.c +1 -2
@@ -26,7 +26,6 @@#include <grub/cpu/macho.h> #include <grub/machoload.h> #include <grub/file.h> -#include <grub/gzio.h> #include <grub/misc.h> #include <grub/mm.h>
@@ -149,7 +148,7 @@grub_file_t file;grub_macho_t macho; - file =grub_gzfile_open (name,1 ); + file =grub_file_open (name);if (! file)return 0 ;
=== modified file 'loader/mips/linux.c'
mips/linux.c +1 -0
@@ -333,6 +333,7 @@if (initrd_loaded)return grub_error (GRUB_ERR_BAD_ARGUMENT ,"only one initrd can be loaded." ); +grub_io_filter_disable_all (); file =grub_file_open (argv[0 ]);if (! file)return grub_errno;
=== modified file 'loader/multiboot.c'
multiboot.c +2 -3
@@ -39,7 +39,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> #include <grub/env.h> #include <grub/cpu/relocator.h> #include <grub/video.h>
@@ -247,7 +246,7 @@if (argc ==0 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"no kernel specified" ); - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (! file)return grub_error (GRUB_ERR_BAD_ARGUMENT ,"couldn't open file" );
@@ -297,7 +296,7 @@return grub_error (GRUB_ERR_BAD_ARGUMENT ,"you need to load the multiboot kernel first" ); - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (! file)return grub_errno;
=== modified file 'loader/powerpc/ieee1275/linux.c'
powerpc/ieee1275/linux.c +1 -0
@@ -302,6 +302,7 @@ goto fail; } +grub_io_filter_disable_all (); file =grub_file_open (argv[0 ]);if (! file) goto fail;
=== modified file 'loader/sparc64/ieee1275/linux.c'
sparc64/ieee1275/linux.c +2 -1
@@ -306,7 +306,7 @@ goto out; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (!file) goto out;
@@ -394,6 +394,7 @@ goto fail; } +grub_io_filter_disable_all (); file =grub_file_open (argv[0 ]);if (! file) goto fail;
=== modified file 'loader/xnu.c'
xnu.c +6 -7
@@ -28,7 +28,6 @@#include <grub/machoload.h> #include <grub/macho.h> #include <grub/cpu/macho.h> -#include <grub/gzio.h> #include <grub/command.h> #include <grub/misc.h> #include <grub/extcmd.h>
@@ -667,7 +666,7 @@ macho =0 ;if (infoplistname) - infoplist =grub_gzfile_open (infoplistname,1 ); + infoplist =grub_file_open (infoplistname);else infoplist =0 ; grub_errno =GRUB_ERR_NONE ;
@@ -761,7 +760,7 @@if (! grub_xnu_heap_size)return grub_error (GRUB_ERR_BAD_OS ,"no xnu kernel loaded" ); - file =grub_gzfile_open (args[0 ],1 ); + file =grub_file_open (args[0 ]);if (! file)return grub_error (GRUB_ERR_FILE_NOT_FOUND ,"couldn't load driver package" );
@@ -873,7 +872,7 @@if (! grub_xnu_heap_size)return grub_error (GRUB_ERR_BAD_OS ,"no xnu kernel loaded" ); - file =grub_gzfile_open (args[0 ],1 ); + file =grub_file_open (args[0 ]);if (! file)return grub_error (GRUB_ERR_FILE_NOT_FOUND ,"couldn't load ramdisk" );
@@ -913,7 +912,7 @@if (binname) *binname =0 ; - file =grub_gzfile_open (plistname,1 ); + file =grub_file_open (plistname);if (! file) {grub_file_close (file);
@@ -1170,7 +1169,7 @@grub_strcpy (binname +grub_strlen (binname),"/" );grub_strcpy (binname +grub_strlen (binname), binsuffix);grub_dprintf ("xnu" ,"%s:%s\n" , plistname, binname); - binfile =grub_gzfile_open (binname,1 ); + binfile =grub_file_open (binname);if (! binfile) grub_errno =GRUB_ERR_NONE ;
@@ -1208,7 +1207,7 @@/* User explicitly specified plist and binary. */ if (grub_strcmp (args[1 ],"-" ) !=0 ) { - binfile =grub_gzfile_open (args[1 ],1 ); + binfile =grub_file_open (args[1 ]);if (! binfile) {grub_error (GRUB_ERR_BAD_OS ,"can't open file" );