Skip to contentSkip to conversation

transparent file reader

PATCH In review Szymon Janc 3 participants 7 messages Feb 16, 2010 – Mar 14, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 transparent file reader

Hello,

Attached patch makes file reader transparent. It should make adding new filters to file reader easier.

- gzio.h is gone
- gzio is no more transparent, transparency is handled in grub_file_open()
- renamed GRUB_ERR_BAD_GZIP_DATA to GRUB_ERR_BAD_IOFILTER_DATA, it will be used by other ios like xzio

What do You think about it?

Signature · 2 lines
Szymon K. Janc
[email protected] // GG: 1383435
/experimental/commands/acpi.c +1 -2
diff -urBN orig//experimental/commands/acpi.c transparentio//experimental/commands/acpi.c
@@ -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 ();
/experimental/commands/cat.c +1 -2
diff -urBN orig//experimental/commands/cat.c transparentio//experimental/commands/cat.c
@@ -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 0;
 
/experimental/commands/cmp.c +2 -3
diff -urBN orig//experimental/commands/cmp.c transparentio//experimental/commands/cmp.c
@@ -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;
 
/experimental/commands/hexdump.c +1 -2
diff -urBN orig//experimental/commands/hexdump.c transparentio//experimental/commands/hexdump.c
@@ -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,7 @@
     {
       grub_file_t file;
 
-      file = grub_gzfile_open (args[0], 1);
+      file = grub_file_open (args[0]);
       if (! file)
 	return 0;
 
/experimental/gettext/gettext.c +1 -2
diff -urBN orig//experimental/gettext/gettext.c transparentio//experimental/gettext/gettext.c
@@ -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)
/experimental/include/grub/err.h +1 -1
diff -urBN orig//experimental/include/grub/err.h transparentio//experimental/include/grub/err.h
@@ -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,
/experimental/include/grub/file.h +14 -0
diff -urBN orig//experimental/include/grub/file.h transparentio//experimental/include/grub/file.h
@@ -48,6 +48,20 @@
 };
 typedef struct grub_file *grub_file_t;
 
+/* The io filter structure.  */
+struct grub_io_filter
+{
+  grub_file_t (*grub_io_open)(grub_file_t file);
+  struct grub_io_filter *next;
+};
+typedef struct grub_io_filter *grub_io_filter_t;
+
+/* Register io filter.  */
+void EXPORT_FUNC(grub_io_register) (grub_io_filter_t filter);
+
+/* Unregister io filter.  */
+void EXPORT_FUNC(grub_io_unregister) (grub_io_filter_t filter);
+
 /* Get a device name from NAME.  */
 char *EXPORT_FUNC(grub_file_get_device_name) (const char *name);
 
/experimental/include/grub/gzio.h +0 -28
diff -urBN orig//experimental/include/grub/gzio.h transparentio//experimental/include/grub/gzio.h
@@ -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 */
/experimental/io/gzio.c +40 -44

196 lines not on this page · raw message

/experimental/kern/elf.c +1 -2
diff -urBN orig//experimental/kern/elf.c transparentio//experimental/kern/elf.c
@@ -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;
 
/experimental/kern/file.c +35 -0
diff -urBN orig//experimental/kern/file.c transparentio//experimental/kern/file.c
@@ -24,6 +24,27 @@
 #include <grub/fs.h>
 #include <grub/device.h>
 
+/* Registered filters list.  */
+static grub_io_filter_t grub_io_filter_list = NULL;
+
+void grub_io_register(grub_io_filter_t filter)
+{
+   filter->next = grub_io_filter_list;
+   grub_io_filter_list = filter;
+}
+
+void grub_io_unregister(grub_io_filter_t filter)
+{
+  grub_io_filter_t *p, q;
+
+  for (p = &grub_io_filter_list, q = *p; q; p = &(q->next), q = q->next)
+    if (q == filter)
+      {
+        *p = q->next;
+        break;
+      }
+}
+
 /* Get the device part of the filename NAME. It is enclosed by parentheses.  */
 char *
 grub_file_get_device_name (const char *name)
@@ -94,6 +115,20 @@
   if ((file->fs->open) (file, file_name) != GRUB_ERR_NONE)
     goto fail;
 
+  /* Check available filters.  */
+  grub_file_t ffile;
+  grub_io_filter_t filter = grub_io_filter_list;
+  while (filter)
+  {
+    ffile = filter->grub_io_open(file);
+    if (ffile)
+    {
+      file = ffile;
+      break;
+    }
+    filter = filter->next;
+  }
+  
   return file;
 
  fail:
/experimental/loader/i386/bsd.c +5 -6
diff -urBN orig//experimental/loader/i386/bsd.c transparentio//experimental/loader/i386/bsd.c
@@ -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)
/experimental/loader/i386/multiboot.c +2 -3
diff -urBN orig//experimental/loader/i386/multiboot.c transparentio//experimental/loader/i386/multiboot.c
@@ -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/i386/relocator.h>
 #include <grub/video.h>
@@ -154,7 +153,7 @@
       goto fail;
     }
 
-  file = grub_gzfile_open (argv[0], 1);
+  file = grub_file_open (argv[0]);
   if (! file)
     {
       grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file");
@@ -305,7 +304,7 @@
       goto fail;
     }
 
-  file = grub_gzfile_open (argv[0], 1);
+  file = grub_file_open (argv[0]);
   if (! file)
     goto fail;
 
/experimental/loader/i386/xnu.c +1 -2
diff -urBN orig//experimental/loader/i386/xnu.c transparentio//experimental/loader/i386/xnu.c
@@ -31,7 +31,6 @@
 #include <grub/charset.h>
 #include <grub/term.h>
 #include <grub/command.h>
-#include <grub/gzio.h>
 #include <grub/bitmap_scale.h>
 #include <grub/i18n.h>
 
@@ -536,7 +535,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");
/experimental/loader/macho.c +1 -2
diff -urBN orig//experimental/loader/macho.c transparentio//experimental/loader/macho.c
@@ -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;
 
/experimental/loader/multiboot_loader.c +1 -2
diff -urBN orig//experimental/loader/multiboot_loader.c transparentio//experimental/loader/multiboot_loader.c
@@ -24,7 +24,6 @@
 #include <grub/dl.h>
 #include <grub/mm.h>
 #include <grub/misc.h>
-#include <grub/gzio.h>
 #include <grub/command.h>
 #include <grub/i18n.h>
 
@@ -74,7 +73,7 @@
       goto fail;
     }
 
-  file = grub_gzfile_open (argv[0], 1);
+  file = grub_file_open (argv[0]);
   if (! file)
     {
       grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file");
/experimental/loader/sparc64/ieee1275/linux.c +1 -2
diff -urBN orig//experimental/loader/sparc64/ieee1275/linux.c transparentio//experimental/loader/sparc64/ieee1275/linux.c
@@ -25,7 +25,6 @@
 #include <grub/misc.h>
 #include <grub/ieee1275/ieee1275.h>
 #include <grub/machine/loader.h>
-#include <grub/gzio.h>
 #include <grub/command.h>
 #include <grub/i18n.h>
 
@@ -306,7 +305,7 @@
       goto out;
     }
 
-  file = grub_gzfile_open (argv[0], 1);
+  file = grub_file_open (argv[0]);
   if (!file)
     goto out;
 
/experimental/loader/xnu.c +6 -7
diff -urBN orig//experimental/loader/xnu.c transparentio//experimental/loader/xnu.c
@@ -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/env.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");
#1 lore raw
Quoted 11 lines · Szymon Janc

Hello,

Attached patch makes file reader transparent. It should make adding new filters to file reader easier.

- gzio.h is gone
- gzio is no more transparent, transparency is handled in grub_file_open()
- renamed GRUB_ERR_BAD_GZIP_DATA to GRUB_ERR_BAD_IOFILTER_DATA, it will be used by other ios like xzio

I like the patch however few comments:
1) How are filters ordered?
2) How would I selectively disable a filter. E.g. for hexdump or when payload expects compressed data?

+/* Registered filters list. */
+static grub_io_filter_t grub_io_filter_list = NULL; +
+void grub_io_register(grub_io_filter_t filter) +{
+ filter->next = grub_io_filter_list;
+ grub_io_filter_list = filter;
+}
+

list.h can be used for this.

Quoted 10 lines

What do You think about it?

------------------------------------------------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#2 lore raw

Dnia wtorek 16 luty 2010 o 19:16:19 Vladimir 'φ-coder/phcoder' Serbinenko napisał(a):

Quoted 2 lines

I like the patch however few comments:
1) How are filters ordered?

Filters are tested in order that last registered filter is tested first. First match stop further tests.

Quoted 2 lines

2) How would I selectively disable a filter. E.g. for hexdump or when payload expects compressed data?

Currently one would have to unregister filters before calling grub_file_open() and reregister them afterwards. However this can mix up filters order. Not a best option.

I was thinking about something like:
grub_file_open("name", NO_XFILTER|NO_YFILTER); grub_file_open("name",NO_ALL);
to allow selectable filters or fopen() style maybe.

And a priority based filter registration if there is a need for that.

Signature · 2 lines
Szymon K. Janc
[email protected] // GG: 1383435
#3 lore raw
In reply to Vladimir 'φ-coder/phcoder' Serbinenko

Dnia wtorek 16 luty 2010 o 19:16:19 Vladimir 'φ-coder/phcoder' Serbinenko napisał(a):

Quoted 15 lines

I like the patch however few comments:
1) How are filters ordered?
2) How would I selectively disable a filter. E.g. for hexdump or when payload expects compressed data?

(quoted diff) +9 -0
+/* Registered filters list.  */
+static grub_io_filter_t grub_io_filter_list = NULL;
+
+void grub_io_register(grub_io_filter_t filter)
+{
+   filter->next = grub_io_filter_list;
+   grub_io_filter_list = filter;
+}
+
Quoted 1 line

list.h can be used for this.

Attached is new version, changes since previous one:
- use list.h
- filter registration is priority based
- filter can be disabled for next open by grub_io_filter_disable()

Interface could be simpler if make it only transparent/non-transparent but this is somewhat less flexible. Yet, is it really needed?

Signature · 2 lines
Szymon K. Janc
[email protected] // GG: 1383435
/experimental/commands/acpi.c +1 -2
diff -urBN orig//experimental/commands/acpi.c transparentio//experimental/commands/acpi.c
@@ -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 ();
/experimental/commands/cat.c +1 -2
diff -urBN orig//experimental/commands/cat.c transparentio//experimental/commands/cat.c
@@ -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 0;
 
/experimental/commands/cmp.c +2 -3
diff -urBN orig//experimental/commands/cmp.c transparentio//experimental/commands/cmp.c
@@ -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;
 
/experimental/commands/hexdump.c +1 -2
diff -urBN orig//experimental/commands/hexdump.c transparentio//experimental/commands/hexdump.c
@@ -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,7 @@
     {
       grub_file_t file;
 
-      file = grub_gzfile_open (args[0], 1);
+      file = grub_file_open (args[0]);
       if (! file)
 	return 0;
 
/experimental/gettext/gettext.c +1 -2
diff -urBN orig//experimental/gettext/gettext.c transparentio//experimental/gettext/gettext.c
@@ -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)
/experimental/include/grub/err.h +1 -1
diff -urBN orig//experimental/include/grub/err.h transparentio//experimental/include/grub/err.h
@@ -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,
/experimental/include/grub/file.h +23 -0
diff -urBN orig//experimental/include/grub/file.h transparentio//experimental/include/grub/file.h
@@ -39,6 +39,9 @@
   /* The file size.  */
   grub_off_t size;
 
+  /* If underlying filesystem is not easly seekable.  */
+  int not_easly_seekable;
+
   /* Filesystem-specific data.  */
   void *data;
 
@@ -48,6 +51,26 @@
 };
 typedef struct grub_file *grub_file_t;
 
+/* The io filter structure.  */
+struct grub_io_filter
+{
+  struct grub_io_filter *next;
+  char *name;
+  int prio;
+  grub_file_t (*grub_io_open) (grub_file_t file);
+};
+typedef struct grub_io_filter *grub_io_filter_t;
+
+/* Register io filter.  */
+void EXPORT_FUNC(grub_io_register) (grub_io_filter_t filter);
+
+/* Unregister io filter.  */
+void EXPORT_FUNC(grub_io_unregister) (grub_io_filter_t filter);
+
+/* Disable selected filter for next opened file. Last parameter must be "".
+ * Disable all for only "".  */
+void EXPORT_FUNC(grub_io_filter_disable) (char *filter_name, ...);
+
 /* Get a device name from NAME.  */
 char *EXPORT_FUNC(grub_file_get_device_name) (const char *name);
 
/experimental/include/grub/gzio.h +0 -28
diff -urBN orig//experimental/include/grub/gzio.h transparentio//experimental/include/grub/gzio.h
@@ -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 */
/experimental/io/gzio.c +48 -52

229 lines not on this page · raw message

/experimental/kern/elf.c +1 -2
diff -urBN orig//experimental/kern/elf.c transparentio//experimental/kern/elf.c
@@ -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;
 
/experimental/kern/file.c +97 -0

109 lines not on this page · raw message

/experimental/loader/i386/bsd.c +5 -6
diff -urBN orig//experimental/loader/i386/bsd.c transparentio//experimental/loader/i386/bsd.c
@@ -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)
/experimental/loader/i386/multiboot.c +2 -3
diff -urBN orig//experimental/loader/i386/multiboot.c transparentio//experimental/loader/i386/multiboot.c
@@ -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/i386/relocator.h>
 #include <grub/video.h>
@@ -154,7 +153,7 @@
       goto fail;
     }
 
-  file = grub_gzfile_open (argv[0], 1);
+  file = grub_file_open (argv[0]);
   if (! file)
     {
       grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file");
@@ -305,7 +304,7 @@
       goto fail;
     }
 
-  file = grub_gzfile_open (argv[0], 1);
+  file = grub_file_open (argv[0]);
   if (! file)
     goto fail;
 
/experimental/loader/i386/xnu.c +1 -2
diff -urBN orig//experimental/loader/i386/xnu.c transparentio//experimental/loader/i386/xnu.c
@@ -31,7 +31,6 @@
 #include <grub/charset.h>
 #include <grub/term.h>
 #include <grub/command.h>
-#include <grub/gzio.h>
 #include <grub/bitmap_scale.h>
 #include <grub/i18n.h>
 
@@ -536,7 +535,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");
/experimental/loader/macho.c +1 -2
diff -urBN orig//experimental/loader/macho.c transparentio//experimental/loader/macho.c
@@ -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;
 
/experimental/loader/multiboot_loader.c +1 -2
diff -urBN orig//experimental/loader/multiboot_loader.c transparentio//experimental/loader/multiboot_loader.c
@@ -24,7 +24,6 @@
 #include <grub/dl.h>
 #include <grub/mm.h>
 #include <grub/misc.h>
-#include <grub/gzio.h>
 #include <grub/command.h>
 #include <grub/i18n.h>
 
@@ -74,7 +73,7 @@
       goto fail;
     }
 
-  file = grub_gzfile_open (argv[0], 1);
+  file = grub_file_open (argv[0]);
   if (! file)
     {
       grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file");
/experimental/loader/sparc64/ieee1275/linux.c +1 -2
diff -urBN orig//experimental/loader/sparc64/ieee1275/linux.c transparentio//experimental/loader/sparc64/ieee1275/linux.c
@@ -25,7 +25,6 @@
 #include <grub/misc.h>
 #include <grub/ieee1275/ieee1275.h>
 #include <grub/machine/loader.h>
-#include <grub/gzio.h>
 #include <grub/command.h>
 #include <grub/i18n.h>
 
@@ -306,7 +305,7 @@
       goto out;
     }
 
-  file = grub_gzfile_open (argv[0], 1);
+  file = grub_file_open (argv[0]);
   if (!file)
     goto out;
 
/experimental/loader/xnu.c +6 -7
diff -urBN orig//experimental/loader/xnu.c transparentio//experimental/loader/xnu.c
@@ -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/env.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");
#4 lore raw
Quoted 27 lines · Szymon Janc

Dnia wtorek 16 luty 2010 o 19:16:19 Vladimir 'φ-coder/phcoder' Serbinenko napisał(a):

Quoted 15 lines

I like the patch however few comments:
1) How are filters ordered?
2) How would I selectively disable a filter. E.g. for hexdump or when payload expects compressed data?

/experimental/kern/file.c +9 -0
+/* Registered filters list.  */
+static grub_io_filter_t grub_io_filter_list = NULL;
+
+void grub_io_register(grub_io_filter_t filter)
+{
+   filter->next = grub_io_filter_list;
+   grub_io_filter_list = filter;
+}
+
Quoted 2 lines

list.h can be used for this.

Attached is new version, changes since previous one:
- use list.h
- filter registration is priority based
- filter can be disabled for next open by grub_io_filter_disable()

Quoted 4 lines

Interface could be simpler if make it only transparent/non-transparent but this is somewhat less flexible. Yet, is it really needed?

First of all I would prefer not_easily_seekable part to be a separate patches so it would be easier to pinpoint bugs by bisecting.

+ .prio = 1,
This should be macroifyed e.g
GRUB_IOFILTER_PRIO_COMPRESSOR

grub_io_register, grub_io_unregister and grub_io_filter_disable must be inlined. Last one has to be splitted into grub_io_filter_disable and grub_io_filter_disable_all to avoid special case with "". va_arg in grub_io_filter_disable doesn't justify itself (one can always make 2 calls, especially if function would be inlined

Quoted 6 lines

------------------------------------------------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#5 lore raw
In reply to Szymon Janc

How do consumers of this interface determine the underlying cause of the
problem? Sometimes, more layering creates more problems than it solves. Think about how you determine the message to display when getting a return value from a function.

--S

Quoting Szymon Janc, who wrote the following on Tue, 16 Feb 2010:

Quoted 18 lines

Hello,

Attached patch makes file reader transparent. It should make adding new filters to file reader easier.

- gzio.h is gone
- gzio is no more transparent, transparency is handled in grub_file_open()
- renamed GRUB_ERR_BAD_GZIP_DATA to GRUB_ERR_BAD_IOFILTER_DATA, it will be used by other ios like xzio

What do You think about it?

Signature · 2 lines
Szymon K. Janc
[email protected] // GG: 1383435
#6 lore raw

Dnia wtorek 16 luty 2010 o 20:38:28 Seth Goldberg napisał(a):

Quoted 4 lines

How do consumers of this interface determine the underlying cause of the
problem? Sometimes, more layering creates more problems than it solves. Think about how you determine the message to display when getting a return value from a function.

Right, should check grub_errno when filter returns null file handler. I'll add that in next version of patch.

Signature · 2 lines
Szymon K. Janc
[email protected] // GG: 1383435