Transparent decompression with file system filter
Currently, grub2 support gziped file with the gzio module. To open a gziped file,
you have to use a special function grub_gzfile_open, I think it could be better ifgrub_file_open could handle compressed file transparently.
The implementation is actually quite simple. We define a file system filter interface,
modules can use it to register its filter. Then, as the last step of opening a file, we
can the filters. If a filter recognized the file format, it will create a new file object
to represent the file. If none of the filter want to handle this file, the orginal file
object is used.
We can add a new function grub_file_rawopen, which will always skip the filters. We can
also use variable to control behavior, for example, if nocomp=1, no filter is called.
The advantage of this scheme is that it's extensible. For example. if we want to support
bzip2 format, we just need to add a new decompression filter.
Signature · 1 line
Bean
Quoted 5 lines · Bean
Currently, grub2 support gziped file with the gzio module. To open a gziped file,
you have to use a special functiongrub_gzfile_open, I think it could be better ifgrub_file_opencould handle compressed file transparently.
Are you still interested in working on this?
--
Marco
Hi,
Quoted 1 line
Are you still interested in working on this?
Yes, if you think this is an useful feature, I can start working on it.
Signature · 1 line
Bean
Quoted 6 lines · Bean
Hi,
Quoted 1 line
Are you still interested in working on this?
Yes, if you think this is an useful feature, I can start working on it.
I am just wondering is there need to read compressed files without being compressed?
I like the idea that opening compressed file is in a separate function, but perhaps there should be some new generic open() function that can handle both compressed (gz, bz2?, others with modules?) and in case compression cannot be detected then use traditional file access.
Quoted 7 lines · Vesa Jääskeläinen
Quoted 5 lines · Bean
Hi,
Quoted 1 line
Are you still interested in working on this?
Yes, if you think this is an useful feature, I can start working on it.
Quoted 8 lines
I am just wondering is there need to read compressed files without being compressed?
I like the idea that opening compressed file is in a separate function, but perhaps there should be some new generic
open()function that can handle both compressed (gz, bz2?, others with modules?) and in case compression cannot be detected then use traditional file access.
It would be nice if an archive is handled just as a filesystem, like with a loopback device. That would make the support both optional and transparent.
Quoted 7 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 8 lines · Vesa Jääskeläinen
Quoted 6 lines · Bean
Hi,
Quoted 1 line
Are you still interested in working on this?
Yes, if you think this is an useful feature, I can start working on it.
Quoted 7 lines
I am just wondering is there need to read compressed files without being compressed?
I like the idea that opening compressed file is in a separate function, but perhaps there should be some new generic
open()function that can handle both compressed (gz, bz2?, others with modules?) and in case compression cannot be detected then use traditional file access.
That sounds like a good idea.
--
Marco
Hi,
I've just written a patch for this feature. In order to enable gzip support, you just need to load the gzio module, then grub_file_open will handle gz file just like they're not compressed. If you don't want auto decompression, use grub_file_open_raw instead of grub_file_open. You can also disable auto decompression by setting nocomp=1.
btw, the current cvs code seems to have problem, i can't access partition from hd! but i'm able to test this feature using (host) in grub-emu.
Signature · 1 line
Bean
2007-11-19 Bean <[email protected]>
* include/grub/file.h (grub_fshook): New structure. (grub_fshook_register): New function. (grub_fshook_unregister): New function. (grub_open_file_raw): New function.
* kern/file.c (grub_fshook_list): New variable. (grub_fshook_register): New function. (grub_fshook_unregister): New function. (grub_open_file_raw): The original grub_open_file. (grub_open_file): New function.
* io/gzio.c (grub_fshook_open): New function. (grub_fshook_gzio): New variable.
* commands/cat.c (grub_cmd_cat): Replace grub_gzfile_open with grub_file_open.
* commands/cmp.c (grub_cmd_cmp): The same.
* commands/hexdump.c (grub_cmd_hexdump): The same.
Index: commands/cat.c
===================================================================
RCS file: /sources/grub/grub2/commands/cat.c,v
retrieving revision 1.6
cat.c +1 -2
@@ -24,7 +24,6 @@#include <grub/disk.h> #include <grub/term.h> #include <grub/misc.h> -#include <grub/gzio.h> static grub_err_t grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),
@@ -38,7 +37,7 @@ grub_cmd_cat (struct grub_arg_list *statif (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 ;
Index: commands/cmp.c
===================================================================
RCS file: /sources/grub/grub2/commands/cmp.c,v
retrieving revision 1.8
cmp.c +2 -3
@@ -23,7 +23,6 @@#include <grub/misc.h> #include <grub/file.h> #include <grub/mm.h> -#include <grub/gzio.h> #define BUFFER_SIZE 512
@@ -44,8 +43,8 @@ grub_cmd_cmp (struct grub_arg_list *statgrub_printf ("Compare `%s' and `%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;
Index: commands/hexdump.c
===================================================================
RCS file: /sources/grub/grub2/commands/hexdump.c,v retrieving revision 1.1
hexdump.c +1 -2
@@ -23,7 +23,6 @@#include <grub/file.h> #include <grub/disk.h> #include <grub/misc.h> -#include <grub/gzio.h> #include <grub/hexdump.h> static const struct grub_arg_option options[] = {
@@ -100,7 +99,7 @@ grub_cmd_hexdump (struct grub_arg_list *if (is_file) { - file =grub_gzfile_open (args[0 ],1 ); + file =grub_file_open (args[0 ]);if (!file)return 0 ;
Index: include/grub/file.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/file.h,v retrieving revision 1.6
grub/file.h +11 -0
@@ -48,9 +48,20 @@ struct grub_file };typedef struct grub_file *grub_file_t ; +struct grub_fshook +{ +grub_file_t (*open_func)(grub_file_t file); +struct grub_fshook *next; +}; +typedef struct grub_fshook *grub_fshook_t ; + +void EXPORT_FUNC (grub_fshook_register ) (grub_fshook_t fshook); +void EXPORT_FUNC (grub_fshook_unregister ) (grub_fshook_t fshook); +/* Get a device name from NAME. */ char *EXPORT_FUNC (grub_file_get_device_name ) (const char *name); +grub_file_t EXPORT_FUNC (grub_file_open_raw ) (const char *name);grub_file_t EXPORT_FUNC (grub_file_open ) (const char *name);grub_ssize_t EXPORT_FUNC (grub_file_read ) (grub_file_t file,char *buf,grub_size_t len);
Index: io/gzio.c
===================================================================
RCS file: /sources/grub/grub2/io/gzio.c,v
retrieving revision 1.5
gzio.c +23 -0
@@ -36,6 +36,7 @@#include <grub/err.h> #include <grub/types.h> +#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> #include <grub/fs.h>
@@ -1241,3 +1242,25 @@ static struct grub_fs grub_gzio_fs = .label = 0, .next = 0 }; + +static grub_file_t grub_fshook_open (grub_file_t file) +{ +return grub_gzio_open (file,1 ); +} + +static struct grub_fshook grub_fshook_gzio = + { + .open_func = grub_fshook_open, + .next =0 + }; + +GRUB_MOD_INIT (gzio) +{ + (void ) mod;/* To stop warning. */ +grub_fshook_register (&grub_fshook_gzio); +} + +GRUB_MOD_FINI (gzio) +{ +grub_fshook_unregister (&grub_fshook_gzio); +}
Index: kern/file.c
===================================================================
RCS file: /sources/grub/grub2/kern/file.c,v
retrieving revision 1.7
file.c +53 -1
72 lines not on this page · raw message
Hi,
Quoted 3 lines · Bean
btw, the current cvs code seems to have problem, i can't access partition from hd! but i'm able to test this feature using (host) in grub-emu.
Ok, i figure it out now, i need to add the biosdisk module to core.img, then it can access hard disk just as before.
I find more grub_gzfile_open to change in the elf and multiboot loader, I also change the name of controlling variable from "nocomp" to "nofshook" as it seems more natural, please check out the new patch.
I test the auto decompression is various situation, it work out fine, for example, you can now use loopback on a compressed file:
loopback lo1 (hd0,1)/aa.img.gz
Signature · 1 line
Bean
2007-11-19 Bean <[email protected]>
* include/grub/file.h (grub_fshook): New structure. (grub_fshook_register): New function. (grub_fshook_unregister): New function. (grub_open_file_raw): New function.
* kern/file.c (grub_fshook_list): New variable. (grub_fshook_register): New function. (grub_fshook_unregister): New function. (grub_open_file_raw): The original grub_open_file. (grub_open_file): New function.
* io/gzio.c (grub_fshook_open): New function. (grub_fshook_gzio): New variable.
* commands/cat.c (grub_cmd_cat): Replace grub_gzfile_open with grub_file_open.
* commands/cmp.c (grub_cmd_cmp): The same.
* commands/hexdump.c (grub_cmd_hexdump): The same.
* kern/elf.c (grub_elf_open): The same.
* loader/multiboot2.c (grub_multiboot2): The same. (grub_module2): The same.
* loader/multiboot_loader.c (grub_rescue_cmd_multiboot_loader): The same.
* loader/i386/pc/multiboot.c (grub_multiboot): The same. (grub_module): The same.
Index: commands/cat.c
===================================================================
RCS file: /sources/grub/grub2/commands/cat.c,v
retrieving revision 1.6
cat.c +1 -2
@@ -24,7 +24,6 @@#include <grub/disk.h> #include <grub/term.h> #include <grub/misc.h> -#include <grub/gzio.h> static grub_err_t grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),
@@ -38,7 +37,7 @@ grub_cmd_cat (struct grub_arg_list *statif (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 ;
Index: commands/cmp.c
===================================================================
RCS file: /sources/grub/grub2/commands/cmp.c,v
retrieving revision 1.8
cmp.c +2 -3
@@ -23,7 +23,6 @@#include <grub/misc.h> #include <grub/file.h> #include <grub/mm.h> -#include <grub/gzio.h> #define BUFFER_SIZE 512
@@ -44,8 +43,8 @@ grub_cmd_cmp (struct grub_arg_list *statgrub_printf ("Compare `%s' and `%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;
Index: commands/hexdump.c
===================================================================
RCS file: /sources/grub/grub2/commands/hexdump.c,v retrieving revision 1.1
hexdump.c +1 -2
@@ -23,7 +23,6 @@#include <grub/file.h> #include <grub/disk.h> #include <grub/misc.h> -#include <grub/gzio.h> #include <grub/hexdump.h> static const struct grub_arg_option options[] = {
@@ -100,7 +99,7 @@ grub_cmd_hexdump (struct grub_arg_list *if (is_file) { - file =grub_gzfile_open (args[0 ],1 ); + file =grub_file_open (args[0 ]);if (!file)return 0 ;
Index: include/grub/file.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/file.h,v retrieving revision 1.6
grub/file.h +11 -0
@@ -48,9 +48,20 @@ struct grub_file };typedef struct grub_file *grub_file_t ; +struct grub_fshook +{ +grub_file_t (*open_func)(grub_file_t file); +struct grub_fshook *next; +}; +typedef struct grub_fshook *grub_fshook_t ; + +void EXPORT_FUNC (grub_fshook_register ) (grub_fshook_t fshook); +void EXPORT_FUNC (grub_fshook_unregister ) (grub_fshook_t fshook); +/* Get a device name from NAME. */ char *EXPORT_FUNC (grub_file_get_device_name ) (const char *name); +grub_file_t EXPORT_FUNC (grub_file_open_raw ) (const char *name);grub_file_t EXPORT_FUNC (grub_file_open ) (const char *name);grub_ssize_t EXPORT_FUNC (grub_file_read ) (grub_file_t file,char *buf,grub_size_t len);
Index: io/gzio.c
===================================================================
RCS file: /sources/grub/grub2/io/gzio.c,v
retrieving revision 1.5
gzio.c +23 -0
@@ -36,6 +36,7 @@#include <grub/err.h> #include <grub/types.h> +#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> #include <grub/fs.h>
@@ -1241,3 +1242,25 @@ static struct grub_fs grub_gzio_fs = .label = 0, .next = 0 }; + +static grub_file_t grub_fshook_open (grub_file_t file) +{ +return grub_gzio_open (file,1 ); +} + +static struct grub_fshook grub_fshook_gzio = + { + .open_func = grub_fshook_open, + .next =0 + }; + +GRUB_MOD_INIT (gzio) +{ + (void ) mod;/* To stop warning. */ +grub_fshook_register (&grub_fshook_gzio); +} + +GRUB_MOD_FINI (gzio) +{ +grub_fshook_unregister (&grub_fshook_gzio); +}
Index: kern/elf.c
===================================================================
RCS file: /sources/grub/grub2/kern/elf.c,v
retrieving revision 1.7
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>
@@ -96,7 +95,7 @@ grub_elf_open (const char *name) {grub_file_t file; - file =grub_gzfile_open (name,1 ); + file =grub_file_open (name);if (! file)return 0 ;
Index: kern/file.c
===================================================================
RCS file: /sources/grub/grub2/kern/file.c,v
retrieving revision 1.7
file.c +53 -1
72 lines not on this page · raw message
Index: loader/multiboot2.c
===================================================================
RCS file: /sources/grub/grub2/loader/multiboot2.c,v retrieving revision 1.1
multiboot2.c +2 -3
@@ -28,7 +28,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> static grub_addr_t entry;extern grub_dl_t my_mod;
@@ -323,7 +322,7 @@ grub_multiboot2 (int argc, char *argv[]) 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" );
@@ -423,7 +422,7 @@ grub_module2 (int argc, char *argv[]) }/* Load module data. */ - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (! file) goto out;
Index: loader/multiboot_loader.c
===================================================================
RCS file: /sources/grub/grub2/loader/multiboot_loader.c,v retrieving revision 1.1
multiboot_loader.c +1 -2
@@ -28,7 +28,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> grub_dl_t my_mod;
@@ -85,7 +84,7 @@ grub_rescue_cmd_multiboot_loader (int ar 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" );
Index: loader/i386/pc/multiboot.c
===================================================================
RCS file: /sources/grub/grub2/loader/i386/pc/multiboot.c,v retrieving revision 1.14
i386/pc/multiboot.c +2 -3
@@ -42,7 +42,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> extern grub_dl_t my_mod;static struct grub_multiboot_info *mbi;
@@ -253,7 +252,7 @@ grub_multiboot (int argc, char *argv[]) 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" );
@@ -362,7 +361,7 @@ grub_module (int argc, char *argv[]) goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (! file) goto fail;
Hi,
Changes in this new patch:
1, change function name grub_file_open_raw to grub_file_ropen 2, replace grub_file_open in command/blocklist.c and util/i386/pc/grub-setup.c to grub_file_ropen.
If nobody objects, i would like to commit this in a few days.
Signature · 1 line
Bean
2007-12-31 Bean <[email protected]>
* include/grub/file.h (grub_fshook): New structure. (grub_fshook_register): New function. (grub_fshook_unregister): New function. (grub_open_file_raw): New function.
* kern/file.c (grub_fshook_list): New variable. (grub_fshook_register): New function. (grub_fshook_unregister): New function. (grub_open_rfile): The original grub_open_file. (grub_open_file): New function.
* io/gzio.c (grub_fshook_open): New function. (grub_fshook_gzio): New variable.
* commands/cat.c (grub_cmd_cat): Replace grub_gzfile_open with grub_file_open.
* commands/cmp.c (grub_cmd_cmp): Likewise.
* commands/hexdump.c (grub_cmd_hexdump): Likewise.
* kern/elf.c (grub_elf_open): Likewise.
* loader/multiboot2.c (grub_multiboot2): Likewise. (grub_module2): Likewise.
* loader/multiboot_loader.c (grub_rescue_cmd_multiboot_loader): Likewise.
* loader/i386/pc/multiboot.c (grub_multiboot): Likewise. (grub_module): Likewise.
* command/blocklist.c (grub_cmd_blocklist): Replace grub_file_open with grub_file_ropen.
* util/i386/pc/grub-setup.c (setup): Likewise.
commands/blocklist.c +1 -1
@@ -82,7 +82,7 @@ grub_cmd_blocklist (struct grub_arg_list *state __attribute__ ((unused)),if (argc <1 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"no file specified" ); - file =grub_file_open (args[0 ]); + file =grub_file_ropen (args[0 ]);if (! file)return grub_errno;
commands/cat.c +1 -2
@@ -24,7 +24,6 @@#include <grub/disk.h> #include <grub/term.h> #include <grub/misc.h> -#include <grub/gzio.h> static grub_err_t grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),
@@ -38,7 +37,7 @@ grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),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 ;
commands/cmp.c +2 -3
@@ -23,7 +23,6 @@#include <grub/misc.h> #include <grub/file.h> #include <grub/mm.h> -#include <grub/gzio.h> #define BUFFER_SIZE 512
@@ -44,8 +43,8 @@ grub_cmd_cmp (struct grub_arg_list *state __attribute__ ((unused)),grub_printf ("Compare `%s' and `%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;
commands/hexdump.c +1 -2
@@ -23,7 +23,6 @@#include <grub/file.h> #include <grub/disk.h> #include <grub/misc.h> -#include <grub/gzio.h> #include <grub/hexdump.h> static const struct grub_arg_option options[] = {
@@ -100,7 +99,7 @@ grub_cmd_hexdump (struct grub_arg_list *state, int argc, char **args)if (is_file) { - file =grub_gzfile_open (args[0 ],1 ); + file =grub_file_open (args[0 ]);if (!file)return 0 ;
include/grub/file.h +11 -0
@@ -48,9 +48,20 @@ struct grub_file };typedef struct grub_file *grub_file_t ; +struct grub_fshook +{ +grub_file_t (*open_func)(grub_file_t file); +struct grub_fshook *next; +}; +typedef struct grub_fshook *grub_fshook_t ; + +void EXPORT_FUNC (grub_fshook_register ) (grub_fshook_t fshook); +void EXPORT_FUNC (grub_fshook_unregister ) (grub_fshook_t fshook); +/* Get a device name from NAME. */ char *EXPORT_FUNC (grub_file_get_device_name ) (const char *name); +grub_file_t EXPORT_FUNC (grub_file_ropen ) (const char *name);grub_file_t EXPORT_FUNC (grub_file_open ) (const char *name);grub_ssize_t EXPORT_FUNC (grub_file_read ) (grub_file_t file,char *buf,grub_size_t len);
io/gzio.c +23 -0
@@ -36,6 +36,7 @@#include <grub/err.h> #include <grub/types.h> +#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> #include <grub/fs.h>
@@ -1241,3 +1242,25 @@ static struct grub_fs grub_gzio_fs = .label = 0, .next = 0 }; + +static grub_file_t grub_fshook_open (grub_file_t file) +{ +return grub_gzio_open (file,1 ); +} + +static struct grub_fshook grub_fshook_gzio = + { + .open_func = grub_fshook_open, + .next =0 + }; + +GRUB_MOD_INIT (gzio) +{ + (void ) mod;/* To stop warning. */ +grub_fshook_register (&grub_fshook_gzio); +} + +GRUB_MOD_FINI (gzio) +{ +grub_fshook_unregister (&grub_fshook_gzio); +}
kern/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>
@@ -96,7 +95,7 @@ grub_elf_open (const char *name) {grub_file_t file; - file =grub_gzfile_open (name,1 ); + file =grub_file_open (name);if (! file)return 0 ;
kern/file.c +53 -1
72 lines not on this page · raw message
loader/i386/pc/multiboot.c +2 -3
@@ -42,7 +42,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> extern grub_dl_t my_mod;static struct grub_multiboot_info *mbi;
@@ -253,7 +252,7 @@ grub_multiboot (int argc, char *argv[]) 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" );
@@ -362,7 +361,7 @@ grub_module (int argc, char *argv[]) goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (! file) goto fail;
loader/multiboot2.c +2 -3
@@ -28,7 +28,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> static grub_addr_t entry;extern grub_dl_t my_mod;
@@ -323,7 +322,7 @@ grub_multiboot2 (int argc, char *argv[]) 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" );
@@ -423,7 +422,7 @@ grub_module2 (int argc, char *argv[]) }/* Load module data. */ - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (! file) goto out;
loader/multiboot_loader.c +1 -2
@@ -28,7 +28,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> grub_dl_t my_mod;
@@ -85,7 +84,7 @@ grub_rescue_cmd_multiboot_loader (int argc, char *argv[]) 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" );
util/i386/pc/grub-setup.c +2 -2
@@ -356,7 +356,7 @@ setup (const char *prefix, const char *dir,grub_disk_cache_invalidate_all (); - file =grub_file_open (core_path); + file =grub_file_ropen (core_path);if (file) {if (grub_file_size (file) != core_size)
@@ -426,7 +426,7 @@ setup (const char *prefix, const char *dir, }/* Now read the core image to determine where the sectors are. */ - file =grub_file_open (core_path); + file =grub_file_ropen (core_path);if (! file)grub_util_error ("%s" , grub_errmsg);
Quoted 9 lines · Bean
Hi,
Changes in this new patch:
1, change function name
grub_file_open_rawtogrub_file_ropen2, replacegrub_file_openincommand/blocklist.candutil/i386/pc/grub-setup.ctogrub_file_ropen.If nobody objects, i would like to commit this in a few days.
Please add the missing spaces in:
+grub_file_t
+grub_file_open (const char *name)
+{
+ grub_file_t file;
+ grub_fshook_t p;
+ char *val;
+
+ file=grub_file_ropen (name);
^^+
+ if (! file)
+ return file;
+
+ val= grub_env_get ("nofshook");
+ if ((val) && (val[0]=='1'))
^^^
+ return file;
+
+ for (p=grub_fshook_list;p;p=p->next)
^^ ^^^^^
+ {
+ grub_file_t new_file;
+
+ new_file = (*p->open_func) (file);
+ if (new_file)
+ return new_file;
+ }
+
+ return file;
+}
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
Quoted 57 lines · Robert Millan
Quoted 9 lines · Bean
Hi,
Changes in this new patch:
1, change function name
grub_file_open_rawtogrub_file_ropen2, replacegrub_file_openincommand/blocklist.candutil/i386/pc/grub-setup.ctogrub_file_ropen.If nobody objects, i would like to commit this in a few days.
Please add the missing spaces in:
(quoted diff) +27
-1+grub_file_t +grub_file_open (const char *name) +{ + grub_file_t file; + grub_fshook_t p; + char *val; + + file=grub_file_ropen (name); ^^ + + if (! file) + return file; + + val= grub_env_get ("nofshook"); + if ((val) && (val[0]=='1')) ^^^ + return file; + + for (p=grub_fshook_list;p;p=p->next) ^^ ^^^^^ + { + grub_file_t new_file; + + new_file = (*p->open_func) (file); + if (new_file) + return new_file; + } + + return file; +} --Robert Millan
<GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
Quoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Ok.
Signature · 1 line
Bean
2007-12-31 Bean <[email protected]>
* include/grub/file.h (grub_fshook): New structure. (grub_fshook_register): New function. (grub_fshook_unregister): New function. (grub_open_file_raw): New function.
* kern/file.c (grub_fshook_list): New variable. (grub_fshook_register): New function. (grub_fshook_unregister): New function. (grub_open_rfile): The original grub_open_file. (grub_open_file): New function.
* io/gzio.c (grub_fshook_open): New function. (grub_fshook_gzio): New variable.
* commands/cat.c (grub_cmd_cat): Replace grub_gzfile_open with grub_file_open.
* commands/cmp.c (grub_cmd_cmp): Likewise.
* commands/hexdump.c (grub_cmd_hexdump): Likewise.
* kern/elf.c (grub_elf_open): Likewise.
* loader/multiboot2.c (grub_multiboot2): Likewise. (grub_module2): Likewise.
* loader/multiboot_loader.c (grub_rescue_cmd_multiboot_loader): Likewise.
* loader/i386/pc/multiboot.c (grub_multiboot): Likewise. (grub_module): Likewise.
* command/blocklist.c (grub_cmd_blocklist): Replace grub_file_open with grub_file_ropen.
* util/i386/pc/grub-setup.c (setup): Likewise.
commands/blocklist.c +1 -1
@@ -82,7 +82,7 @@ grub_cmd_blocklist (struct grub_arg_list *state __attribute__ ((unused)),if (argc <1 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"no file specified" ); - file =grub_file_open (args[0 ]); + file =grub_file_ropen (args[0 ]);if (! file)return grub_errno;
commands/cat.c +1 -2
@@ -24,7 +24,6 @@#include <grub/disk.h> #include <grub/term.h> #include <grub/misc.h> -#include <grub/gzio.h> static grub_err_t grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),
@@ -38,7 +37,7 @@ grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),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 ;
commands/cmp.c +2 -3
@@ -23,7 +23,6 @@#include <grub/misc.h> #include <grub/file.h> #include <grub/mm.h> -#include <grub/gzio.h> #define BUFFER_SIZE 512
@@ -44,8 +43,8 @@ grub_cmd_cmp (struct grub_arg_list *state __attribute__ ((unused)),grub_printf ("Compare `%s' and `%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;
commands/hexdump.c +1 -2
@@ -23,7 +23,6 @@#include <grub/file.h> #include <grub/disk.h> #include <grub/misc.h> -#include <grub/gzio.h> #include <grub/hexdump.h> static const struct grub_arg_option options[] = {
@@ -100,7 +99,7 @@ grub_cmd_hexdump (struct grub_arg_list *state, int argc, char **args)if (is_file) { - file =grub_gzfile_open (args[0 ],1 ); + file =grub_file_open (args[0 ]);if (!file)return 0 ;
include/grub/file.h +11 -0
@@ -48,9 +48,20 @@ struct grub_file };typedef struct grub_file *grub_file_t ; +struct grub_fshook +{ +grub_file_t (*open_func) (grub_file_t file); +struct grub_fshook *next; +}; +typedef struct grub_fshook *grub_fshook_t ; + +void EXPORT_FUNC (grub_fshook_register ) (grub_fshook_t fshook); +void EXPORT_FUNC (grub_fshook_unregister ) (grub_fshook_t fshook); +/* Get a device name from NAME. */ char *EXPORT_FUNC (grub_file_get_device_name ) (const char *name); +grub_file_t EXPORT_FUNC (grub_file_ropen ) (const char *name);grub_file_t EXPORT_FUNC (grub_file_open ) (const char *name);grub_ssize_t EXPORT_FUNC (grub_file_read ) (grub_file_t file,char *buf,grub_size_t len);
io/gzio.c +23 -0
@@ -36,6 +36,7 @@#include <grub/err.h> #include <grub/types.h> +#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> #include <grub/fs.h>
@@ -1241,3 +1242,25 @@ static struct grub_fs grub_gzio_fs = .label = 0, .next = 0 }; + +static grub_file_t grub_fshook_open (grub_file_t file) +{ +return grub_gzio_open (file,1 ); +} + +static struct grub_fshook grub_fshook_gzio = + { + .open_func = grub_fshook_open, + .next =0 + }; + +GRUB_MOD_INIT (gzio) +{ + (void ) mod;/* To stop warning. */ +grub_fshook_register (&grub_fshook_gzio); +} + +GRUB_MOD_FINI (gzio) +{ +grub_fshook_unregister (&grub_fshook_gzio); +}
kern/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>
@@ -96,7 +95,7 @@ grub_elf_open (const char *name) {grub_file_t file; - file =grub_gzfile_open (name,1 ); + file =grub_file_open (name);if (! file)return 0 ;
kern/file.c +53 -1
72 lines not on this page · raw message
loader/i386/pc/multiboot.c +2 -3
@@ -42,7 +42,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> extern grub_dl_t my_mod;static struct grub_multiboot_info *mbi;
@@ -253,7 +252,7 @@ grub_multiboot (int argc, char *argv[]) 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" );
@@ -362,7 +361,7 @@ grub_module (int argc, char *argv[]) goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (! file) goto fail;
loader/multiboot2.c +2 -3
@@ -28,7 +28,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> static grub_addr_t entry;extern grub_dl_t my_mod;
@@ -323,7 +322,7 @@ grub_multiboot2 (int argc, char *argv[]) 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" );
@@ -423,7 +422,7 @@ grub_module2 (int argc, char *argv[]) }/* Load module data. */ - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open (argv[0 ]);if (! file) goto out;
loader/multiboot_loader.c +1 -2
@@ -28,7 +28,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> grub_dl_t my_mod;
@@ -85,7 +84,7 @@ grub_rescue_cmd_multiboot_loader (int argc, char *argv[]) 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" );
util/i386/pc/grub-setup.c +2 -2
@@ -356,7 +356,7 @@ setup (const char *prefix, const char *dir,grub_disk_cache_invalidate_all (); - file =grub_file_open (core_path); + file =grub_file_ropen (core_path);if (file) {if (grub_file_size (file) != core_size)
@@ -426,7 +426,7 @@ setup (const char *prefix, const char *dir, }/* Now read the core image to determine where the sectors are. */ - file =grub_file_open (core_path); + file =grub_file_ropen (core_path);if (! file)grub_util_error ("%s" , grub_errmsg);
Quoted 9 lines · Bean
Hi,
Changes in this new patch:
1, change function name
grub_file_open_rawtogrub_file_ropen2, replacegrub_file_openincommand/blocklist.candutil/i386/pc/grub-setup.ctogrub_file_ropen.If nobody objects, i would like to commit this in a few days.
Please wait a minute. Personally, I don't want grub_file_open to decompress a content automatically. The name should stand for what it does. That was why I named grub_file_open and grub_gzfile_open like this. This was really one of what I didn't like in GRUB Legacy.
If you want to have a function to open any kind of compressed file, please add something else (e.g. grub_compressed_file_open).
Okuji
Quoted 12 lines · Yoshinori K. Okuji
Quoted 9 lines · Bean
Hi,
Changes in this new patch:
1, change function name
grub_file_open_rawtogrub_file_ropen2, replacegrub_file_openincommand/blocklist.candutil/i386/pc/grub-setup.ctogrub_file_ropen.If nobody objects, i would like to commit this in a few days.
Quoted 7 lines
Please wait a minute. Personally, I don't want
grub_file_opento decompress a content automatically. The name should stand for what it does. That was why I namedgrub_file_openandgrub_gzfile_openlike this. This was really one of what I didn't like in GRUB Legacy.If you want to have a function to open any kind of compressed file, please add something else (e.g.
grub_compressed_file_open).
ok, i keep grub_file_open as it is, and add a new function grub_zfile_open to handle compressed file. i also expand the list of commands that use auto decompression:
ls
to get the uncompressed file size in long list
loopback
to open compressed image file
font
to open compressed font file.
Signature · 1 line
Bean
2008-01-03 Bean <[email protected]>
* include/grub/file.h (grub_fshook): New structure. (grub_fshook_register): New function. (grub_fshook_unregister): New function. (grub_zfile_open): New function.
* kern/file.c (grub_fshook_list): New variable. (grub_fshook_register): New function. (grub_fshook_unregister): New function. (grub_zfile_open): New function.
* io/gzio.c (grub_fshook_open): New function. (grub_fshook_gzio): New variable.
* commands/cat.c (grub_cmd_cat): Use grub_zfile_open instead of grub_gzfile_open.
* commands/cmp.c (grub_cmd_cmp): Likewise.
* commands/hexdump.c (grub_cmd_hexdump): Likewise.
* kern/elf.c (grub_elf_open): Likewise.
* loader/multiboot2.c (grub_multiboot2): Likewise. (grub_module2): Likewise.
* loader/multiboot_loader.c (grub_rescue_cmd_multiboot_loader): Likewise.
* loader/i386/pc/multiboot.c (grub_multiboot): Likewise. (grub_module): Likewise.
* commands/ls.c (grub_ls_list_files): Use grub_zfile_open instead of grub_file_open.
* disk/loopback.c (grub_loopback_open): Likewise.
* font/manager.c (add_font): Likewise.
commands/cat.c +1 -2
@@ -24,7 +24,6 @@#include <grub/disk.h> #include <grub/term.h> #include <grub/misc.h> -#include <grub/gzio.h> static grub_err_t grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),
@@ -38,7 +37,7 @@ grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),if (argc !=1 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"file name required" ); - file =grub_gzfile_open (args[0 ],1 ); + file =grub_zfile_open (args[0 ]);if (! file)return 0 ;
commands/cmp.c +2 -3
@@ -23,7 +23,6 @@#include <grub/misc.h> #include <grub/file.h> #include <grub/mm.h> -#include <grub/gzio.h> #define BUFFER_SIZE 512
@@ -44,8 +43,8 @@ grub_cmd_cmp (struct grub_arg_list *state __attribute__ ((unused)),grub_printf ("Compare `%s' and `%s':\n" , args[0 ], args[1 ]); - file1 =grub_gzfile_open (args[0 ],1 ); - file2 =grub_gzfile_open (args[1 ],1 ); + file1 =grub_zfile_open (args[0 ]); + file2 =grub_zfile_open (args[1 ]);if (! file1 || ! file2) goto cleanup;
commands/hexdump.c +1 -2
@@ -23,7 +23,6 @@#include <grub/file.h> #include <grub/disk.h> #include <grub/misc.h> -#include <grub/gzio.h> #include <grub/hexdump.h> static const struct grub_arg_option options[] = {
@@ -100,7 +99,7 @@ grub_cmd_hexdump (struct grub_arg_list *state, int argc, char **args)if (is_file) { - file =grub_gzfile_open (args[0 ],1 ); + file =grub_zfile_open (args[0 ]);if (!file)return 0 ;
commands/ls.c +1 -1
@@ -97,7 +97,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)/* XXX: For ext2fs symlinks are detected as files while they should be reported as directories. */ - file =grub_file_open (pathname); + file =grub_zfile_open (pathname);if (! file) { grub_errno =0 ;
disk/loopback.c +1 -1
@@ -171,7 +171,7 @@ grub_loopback_open (const char *name, grub_disk_t disk)if (! dev)return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"Can't open device" ); - file =grub_file_open (dev->filename); + file =grub_zfile_open (dev->filename);if (! file)return grub_errno;
font/manager.c +1 -1
@@ -48,7 +48,7 @@ add_font (const char *filename)grub_uint32_t num, i;struct font *font =0 ; - file =grub_file_open (filename); + file =grub_zfile_open (filename);if (! file) goto fail;
include/grub/file.h +11 -0
@@ -48,10 +48,21 @@ struct grub_file };typedef struct grub_file *grub_file_t ; +struct grub_fshook +{ +grub_file_t (*open_func) (grub_file_t file); +struct grub_fshook *next; +}; +typedef struct grub_fshook *grub_fshook_t ; + +void EXPORT_FUNC (grub_fshook_register ) (grub_fshook_t fshook); +void EXPORT_FUNC (grub_fshook_unregister ) (grub_fshook_t fshook); +/* Get a device name from NAME. */ char *EXPORT_FUNC (grub_file_get_device_name ) (const char *name);grub_file_t EXPORT_FUNC (grub_file_open ) (const char *name); +grub_file_t EXPORT_FUNC (grub_zfile_open ) (const char *name);grub_ssize_t EXPORT_FUNC (grub_file_read ) (grub_file_t file,char *buf,grub_size_t len);grub_off_t EXPORT_FUNC (grub_file_seek ) (grub_file_t file,grub_off_t offset);
io/gzio.c +23 -0
@@ -36,6 +36,7 @@#include <grub/err.h> #include <grub/types.h> +#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> #include <grub/fs.h>
@@ -1241,3 +1242,25 @@ static struct grub_fs grub_gzio_fs = .label = 0, .next = 0 }; + +static grub_file_t grub_fshook_open (grub_file_t file) +{ +return grub_gzio_open (file,1 ); +} + +static struct grub_fshook grub_fshook_gzio = + { + .open_func = grub_fshook_open, + .next =0 + }; + +GRUB_MOD_INIT (gzio) +{ + (void ) mod;/* To stop warning. */ +grub_fshook_register (&grub_fshook_gzio); +} + +GRUB_MOD_FINI (gzio) +{ +grub_fshook_unregister (&grub_fshook_gzio); +}
kern/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>
@@ -96,7 +95,7 @@ grub_elf_open (const char *name) {grub_file_t file; - file =grub_gzfile_open (name,1 ); + file =grub_zfile_open (name);if (! file)return 0 ;
kern/file.c +52 -0
64 lines not on this page · raw message
loader/i386/pc/multiboot.c +2 -3
@@ -42,7 +42,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> extern grub_dl_t my_mod;static struct grub_multiboot_info *mbi;
@@ -253,7 +252,7 @@ grub_multiboot (int argc, char *argv[]) goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_zfile_open (argv[0 ]);if (! file) {grub_error (GRUB_ERR_BAD_ARGUMENT ,"Couldn't open file" );
@@ -362,7 +361,7 @@ grub_module (int argc, char *argv[]) goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_zfile_open (argv[0 ]);if (! file) goto fail;
loader/multiboot2.c +2 -3
@@ -28,7 +28,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> static grub_addr_t entry;extern grub_dl_t my_mod;
@@ -323,7 +322,7 @@ grub_multiboot2 (int argc, char *argv[]) goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_zfile_open (argv[0 ]);if (! file) {grub_error (GRUB_ERR_BAD_ARGUMENT ,"Couldn't open file" );
@@ -423,7 +422,7 @@ grub_module2 (int argc, char *argv[]) }/* Load module data. */ - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_zfile_open (argv[0 ]);if (! file) goto out;
loader/multiboot_loader.c +1 -2
@@ -28,7 +28,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> grub_dl_t my_mod;
@@ -85,7 +84,7 @@ grub_rescue_cmd_multiboot_loader (int argc, char *argv[]) goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_zfile_open (argv[0 ]);if (! file) {grub_error (GRUB_ERR_BAD_ARGUMENT ,"Couldn't open file" );
Quoted 18 lines · Bean
Quoted 17 lines · Yoshinori K. Okuji
Quoted 9 lines · Bean
Hi,
Changes in this new patch:
1, change function name
grub_file_open_rawtogrub_file_ropen2, replacegrub_file_openincommand/blocklist.candutil/i386/pc/grub-setup.ctogrub_file_ropen.If nobody objects, i would like to commit this in a few days.
Please wait a minute. Personally, I don't want
grub_file_opento decompress a content automatically. The name should stand for what it does. That was why I namedgrub_file_openandgrub_gzfile_openlike this. This was really one of what I didn't like in GRUB Legacy.
Quoted 5 lines
Quoted 2 lines
If you want to have a function to open any kind of compressed file, please add something else (e.g.
grub_compressed_file_open).ok, i keep
grub_file_openas it is, and add a new functiongrub_zfile_opento handle compressed file.
How does grub_zfile_open differ from grub_gzfile_open ?
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
Quoted 1 line · Robert Millan
How does
grub_zfile_opendiffer fromgrub_gzfile_open?
grub_gzfile_open only handle gzip file, while grub_zfile_open handle compressed file in general. when module like gzio starts, it register a structure that grub_zfile_open would use to call the decompression routine. the binding is dynamic, the modules that use grub_zfile_open doesn't depend on the specific decompression module.
Signature · 1 line
Bean
Quoted 8 lines · Bean
Quoted 1 line · Robert Millan
How does
grub_zfile_opendiffer fromgrub_gzfile_open?
grub_gzfile_openonly handle gzip file, whilegrub_zfile_openhandle compressed file in general. when module like gzio starts, it register a structure thatgrub_zfile_openwould use to call the decompression routine. the binding is dynamic, the modules that usegrub_zfile_opendoesn't depend on the specific decompression module.
Ah, sounds nice.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
Quoted 6 lines · Bean
Quoted 5 lines · Yoshinori K. Okuji
Please wait a minute. Personally, I don't want
grub_file_opento decompress a content automatically. The name should stand for what it does. That was why I namedgrub_file_openandgrub_gzfile_openlike this. This was really one of what I didn't like in GRUB Legacy.
Quoted 6 lines
Quoted 2 lines
If you want to have a function to open any kind of compressed file, please add something else (e.g.
grub_compressed_file_open).ok, i keep
grub_file_openas it is, and add a new functiongrub_zfile_opento handle compressed file. i also expand the list of commands that use auto decompression:
For me zfile doesn't say a thing. Where as name proposed by Okuji is clear to me instantly. Our current compilers can handle long symbol names fine, so why not use them if they make things clearer :) ?
Quoted 10 lines · Vesa Jääskeläinen
Quoted 9 lines · Bean
Quoted 7 lines · Yoshinori K. Okuji
Please wait a minute. Personally, I don't want
grub_file_opento decompress a content automatically. The name should stand for what it does. That was why I namedgrub_file_openandgrub_gzfile_openlike this. This was really one of what I didn't like in GRUB Legacy.If you want to have a function to open any kind of compressed file, please add something else (e.g.
grub_compressed_file_open).
Quoted 7 lines
Quoted 3 lines
ok, i keep
grub_file_openas it is, and add a new functiongrub_zfile_opento handle compressed file. i also expand the list of commands that use auto decompression:For me zfile doesn't say a thing. Where as name proposed by Okuji is clear to me instantly. Our current compilers can handle long symbol names fine, so why not use them if they make things clearer :) ?
Agreed.
Okuji
Quoted 15 lines · Yoshinori K. Okuji
Quoted 14 lines · Vesa Jääskeläinen
Quoted 12 lines · Bean
Quoted 7 lines · Yoshinori K. Okuji
Please wait a minute. Personally, I don't want
grub_file_opento decompress a content automatically. The name should stand for what it does. That was why I namedgrub_file_openandgrub_gzfile_openlike this. This was really one of what I didn't like in GRUB Legacy.If you want to have a function to open any kind of compressed file, please add something else (e.g.
grub_compressed_file_open).ok, i keep
grub_file_openas it is, and add a new functiongrub_zfile_opento handle compressed file. i also expand the list of commands that use auto decompression:
Quoted 5 lines
Quoted 3 lines
For me zfile doesn't say a thing. Where as name proposed by Okuji is clear to me instantly. Our current compilers can handle long symbol names fine, so why not use them if they make things clearer :) ?
Agreed.
I'm thinking that compressed might not be the right word, as filter doesn't limit to decompression, it can support decryption or format conversion as well. I guess the name grub_file_open_ex may be better. I also add a flag to the function, if flag!=0, filters are used, and if flag=0, grub_file_open_ex is just like grub_file_open.
I also change the name fshook to filehook, as these filters only affect file based operation. The controlling variable is now filehook. When filehook=0, filters are disabled globally.
Signature · 1 line
Bean
2008-01-05 Bean <[email protected]>
* include/grub/file.h (grub_filehook): New structure. (grub_filehook_register): New function. (grub_filehook_unregister): New function. (grub_file_open_ex): New function.
* kern/file.c (grub_filehook_list): New variable. (grub_filehook_register): New function. (grub_filehook_unregister): New function. (grub_file_open_ex): New function.
* io/gzio.c (grub_filehook_open): New function. (grub_filehook_gzio): New variable.
* commands/cat.c (grub_cmd_cat): Use grub_file_open_ex instead of grub_gzfile_open.
* commands/cmp.c (grub_cmd_cmp): Likewise.
* commands/hexdump.c (grub_cmd_hexdump): Likewise.
* kern/elf.c (grub_elf_open): Likewise.
* loader/multiboot2.c (grub_multiboot2): Likewise. (grub_module2): Likewise.
* loader/multiboot_loader.c (grub_rescue_cmd_multiboot_loader): Likewise.
* loader/i386/pc/multiboot.c (grub_multiboot): Likewise. (grub_module): Likewise.
* commands/ls.c (grub_ls_list_files): Use grub_file_open_ex instead of grub_file_open.
* disk/loopback.c (grub_loopback_open): Likewise.
* font/manager.c (add_font): Likewise.
commands/cat.c +1 -2
@@ -24,7 +24,6 @@#include <grub/disk.h> #include <grub/term.h> #include <grub/misc.h> -#include <grub/gzio.h> static grub_err_t grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),
@@ -38,7 +37,7 @@ grub_cmd_cat (struct grub_arg_list *state __attribute__ ((unused)),if (argc !=1 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"file name required" ); - file =grub_gzfile_open (args[0 ],1 ); + file =grub_file_open_ex (args[0 ],1 );if (! file)return 0 ;
commands/cmp.c +2 -3
@@ -23,7 +23,6 @@#include <grub/misc.h> #include <grub/file.h> #include <grub/mm.h> -#include <grub/gzio.h> #define BUFFER_SIZE 512
@@ -44,8 +43,8 @@ grub_cmd_cmp (struct grub_arg_list *state __attribute__ ((unused)),grub_printf ("Compare `%s' and `%s':\n" , args[0 ], args[1 ]); - file1 =grub_gzfile_open (args[0 ],1 ); - file2 =grub_gzfile_open (args[1 ],1 ); + file1 =grub_file_open_ex (args[0 ],1 ); + file2 =grub_file_open_ex (args[1 ],1 );if (! file1 || ! file2) goto cleanup;
commands/hexdump.c +1 -2
@@ -23,7 +23,6 @@#include <grub/file.h> #include <grub/disk.h> #include <grub/misc.h> -#include <grub/gzio.h> #include <grub/hexdump.h> static const struct grub_arg_option options[] = {
@@ -100,7 +99,7 @@ grub_cmd_hexdump (struct grub_arg_list *state, int argc, char **args)if (is_file) { - file =grub_gzfile_open (args[0 ],1 ); + file =grub_file_open_ex (args[0 ],1 );if (!file)return 0 ;
commands/ls.c +1 -1
@@ -97,7 +97,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)/* XXX: For ext2fs symlinks are detected as files while they should be reported as directories. */ - file =grub_file_open (pathname); + file =grub_file_open_ex (pathname,1 );if (! file) { grub_errno =0 ;
disk/loopback.c +1 -1
@@ -171,7 +171,7 @@ grub_loopback_open (const char *name, grub_disk_t disk)if (! dev)return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"Can't open device" ); - file =grub_file_open (dev->filename); + file =grub_file_open_ex (dev->filename,1 );if (! file)return grub_errno;
font/manager.c +1 -1
@@ -48,7 +48,7 @@ add_font (const char *filename)grub_uint32_t num, i;struct font *font =0 ; - file =grub_file_open (filename); + file =grub_file_open_ex (filename,1 );if (! file) goto fail;
include/grub/file.h +11 -0
@@ -48,10 +48,21 @@ struct grub_file };typedef struct grub_file *grub_file_t ; +struct grub_filehook +{ +grub_file_t (*open_func) (grub_file_t file); +struct grub_filehook *next; +}; +typedef struct grub_filehook *grub_filehook_t ; + +void EXPORT_FUNC (grub_filehook_register ) (grub_filehook_t filehook); +void EXPORT_FUNC (grub_filehook_unregister ) (grub_filehook_t filehook); +/* Get a device name from NAME. */ char *EXPORT_FUNC (grub_file_get_device_name ) (const char *name);grub_file_t EXPORT_FUNC (grub_file_open ) (const char *name); +grub_file_t EXPORT_FUNC (grub_file_open_ex ) (const char *name,int flag);grub_ssize_t EXPORT_FUNC (grub_file_read ) (grub_file_t file,char *buf,grub_size_t len);grub_off_t EXPORT_FUNC (grub_file_seek ) (grub_file_t file,grub_off_t offset);
io/gzio.c +23 -0
@@ -36,6 +36,7 @@#include <grub/err.h> #include <grub/types.h> +#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> #include <grub/fs.h>
@@ -1241,3 +1242,25 @@ static struct grub_fs grub_gzio_fs = .label = 0, .next = 0 }; + +static grub_file_t grub_filehook_open (grub_file_t file) +{ +return grub_gzio_open (file,1 ); +} + +static struct grub_filehook grub_filehook_gzio = + { + .open_func = grub_filehook_open, + .next =0 + }; + +GRUB_MOD_INIT (gzio) +{ + (void ) mod;/* To stop warning. */ +grub_filehook_register (&grub_filehook_gzio); +} + +GRUB_MOD_FINI (gzio) +{ +grub_filehook_unregister (&grub_filehook_gzio); +}
kern/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>
@@ -96,7 +95,7 @@ grub_elf_open (const char *name) {grub_file_t file; - file =grub_gzfile_open (name,1 ); + file =grub_file_open_ex (name,1 );if (! file)return 0 ;
kern/file.c +51 -0
63 lines not on this page · raw message
loader/i386/pc/multiboot.c +2 -3
@@ -42,7 +42,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> extern grub_dl_t my_mod;static struct grub_multiboot_info *mbi;
@@ -253,7 +252,7 @@ grub_multiboot (int argc, char *argv[]) goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open_ex (argv[0 ],1 );if (! file) {grub_error (GRUB_ERR_BAD_ARGUMENT ,"Couldn't open file" );
@@ -362,7 +361,7 @@ grub_module (int argc, char *argv[]) goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open_ex (argv[0 ],1 );if (! file) goto fail;
loader/multiboot2.c +2 -3
@@ -28,7 +28,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> static grub_addr_t entry;extern grub_dl_t my_mod;
@@ -323,7 +322,7 @@ grub_multiboot2 (int argc, char *argv[]) goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open_ex (argv[0 ],1 );if (! file) {grub_error (GRUB_ERR_BAD_ARGUMENT ,"Couldn't open file" );
@@ -423,7 +422,7 @@ grub_module2 (int argc, char *argv[]) }/* Load module data. */ - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open_ex (argv[0 ],1 );if (! file) goto out;
loader/multiboot_loader.c +1 -2
@@ -28,7 +28,6 @@#include <grub/dl.h> #include <grub/mm.h> #include <grub/misc.h> -#include <grub/gzio.h> grub_dl_t my_mod;
@@ -85,7 +84,7 @@ grub_rescue_cmd_multiboot_loader (int argc, char *argv[]) goto fail; } - file =grub_gzfile_open (argv[0 ],1 ); + file =grub_file_open_ex (argv[0 ],1 );if (! file) {grub_error (GRUB_ERR_BAD_ARGUMENT ,"Couldn't open file" );
Quoted 5 lines · Bean
I'm thinking that compressed might not be the right word, as filter doesn't limit to decompression, it can support decryption or format conversion as well. I guess the name
grub_file_open_exmay be better. I also add a flag to the function, if flag!=0, filters are used, and if flag=0,grub_file_open_exis just likegrub_file_open.
I feel that this is too theoretical. In reality, if you want to support, say, an encrypted file to be decrypted automatically, you need to supply a private key or a passphrase or something like that. How can this be unified and transparent?
Okuji
Quoted 11 lines · Yoshinori K. Okuji
Quoted 5 lines · Bean
I'm thinking that compressed might not be the right word, as filter doesn't limit to decompression, it can support decryption or format conversion as well. I guess the name
grub_file_open_exmay be better. I also add a flag to the function, if flag!=0, filters are used, and if flag=0,grub_file_open_exis just likegrub_file_open.I feel that this is too theoretical. In reality, if you want to support, say, an encrypted file to be decrypted automatically, you need to supply a private key or a passphrase or something like that. How can this be unified and transparent?
the filter can export a command/function to set key, then it can use it to decrypted files. if the password is file based, it can prompt the user before opening the file.
Signature · 1 line
Bean
Hi,
any suggestion about this patch ? i would like to commit it soon.
Signature · 1 line
Bean
Quoted 3 lines · Bean
Hi,
any suggestion about this patch ? i would like to commit it soon.
I am sorry that I forgot to reply.
I would like to know how you intend to approach the following issues:
- If you want to support, for example, an ecrypted and compressed file, in the current implementation, each hook must try other hooks recursively. I believe that this should be done at grub_file_open_ex rather than at every hook. Is there any pitfall with this way?
- There are some cases where the user wants to skip some decoding features (i.e. decryptions and decompressions). For instance, gunzip does not make sense for initrd, since the linux kernel performs this. But if the user uses other compression algorithms (e.g. LZMA), GRUB must decompress it before transferring control to the kernel. Or, in the case of Multiboot modules, an OS image might want to keep compressed modules as they are, but have GRUB to decrypt them, if they are encrypted. How does the user select which hooks should be applied (from the viewpoint of UI)?
Because your aim is quite broad (which is a good thing), I think we need to consider possible use cases carefully, to make sure that the API is good enough.
Okuji
Quoted 5 lines · Yoshinori K. Okuji
Quoted 3 lines · Bean
Hi,
any suggestion about this patch ? i would like to commit it soon.
Quoted 8 lines
I am sorry that I forgot to reply.
I would like to know how you intend to approach the following issues:
- If you want to support, for example, an ecrypted and compressed file, in the current implementation, each hook must try other hooks recursively. I believe that this should be done at
grub_file_open_exrather than at every hook. Is there any pitfall with this way?
currently, at most one hook is applied to one file, recursive hook can be messy. but we can add a priority value, this would allow the hooks to be apply in a particular order.
Quoted 9 lines
- There are some cases where the user wants to skip some decoding features (i.e. decryptions and decompressions). For instance, gunzip does not make sense for initrd, since the linux kernel performs this. But if the user uses other compression algorithms (e.g. LZMA), GRUB must decompress it before transferring control to the kernel. Or, in the case of Multiboot modules, an OS image might want to keep compressed modules as they are, but have GRUB to decrypt them, if they are encrypted. How does the user select which hooks should be applied (from the viewpoint of UI)?
i think this can be controlled by variables, for example, we can use filehook.gzip to control whether or not to use gzip, etc.
Signature · 5 lines
Bean -- Bean
Quoted 8 lines · Bean
Quoted 4 lines
- If you want to support, for example, an ecrypted and compressed file, in the current implementation, each hook must try other hooks recursively. I believe that this should be done at
grub_file_open_exrather than at every hook. Is there any pitfall with this way?currently, at most one hook is applied to one file, recursive hook can be messy. but we can add a priority value, this would allow the hooks to be apply in a particular order.
In reality, the user can do both encryption+compression and compression+encryption, thus I don't think we can put priorities a priori.
Quoted 10 lines
Quoted 9 lines
- There are some cases where the user wants to skip some decoding features (i.e. decryptions and decompressions). For instance, gunzip does not make sense for initrd, since the linux kernel performs this. But if the user uses other compression algorithms (e.g. LZMA), GRUB must decompress it before transferring control to the kernel. Or, in the case of Multiboot modules, an OS image might want to keep compressed modules as they are, but have GRUB to decrypt them, if they are encrypted. How does the user select which hooks should be applied (from the viewpoint of UI)?
Quoted 2 lines
i think this can be controlled by variables, for example, we can use filehook.gzip to control whether or not to use gzip, etc.
Using variables has too much side effect. For example:
grub> set something=foo,bar
grub> command
Since the value of the variable is applied to all files the command opens, it can lead to undesired results. Even if it is a rare case that a command wants to open multiple files differently, I don't think this is really clean.
The traditional approach in GRUB is to specify options to a command. For example, --no-decompression. Then, the command hardcodes where the options are applied. As long as the combinations of such options fulfill all (realistic) use cases, this approach works quite well.
But it is a nightmare to specify all possibilities, such
as --no-gunzip, --no-bunzip2, and so on. So my feeling is that we need a kind of categorization in hooks. For example, gzio belongs to "compression". Once this is done, I think it would be good enough for Multiboot.
For other boot protocols (such as Linux), I think loaders would require hardcoding more specific filtering (such as excluding only gzip). If hooks are named, we might be able to use the same trick as for grub_dprintf.
Okuji