iso9660 support
Hi,
Here is a patch to add iso9660 support to GRUB 2. There is support for rockridge (including stuff like symlinks), but there is no joliet support. I've also fixed a few filesystems so they do not fail when the block read is out of range.
I hope someone can have a close look at iso9660.c, there could be some ugly things, but I stared too long at the code to see them. :)
If no one replies before Tuesday I will assume it is ok and check it in.
Next on my list is hacking xfs and reiser[34] support. But I think I will fix the VGA driver first and perhaps add splashscreen support while I am doing that.
Thanks,
Marco
2004-10-15 Marco Gerards <[email protected]>
Add support for iso9660 (including rockrigde).
* conf/i386-pc.rmk (grub_emu_SOURCES): Add fs/iso9660.c. (iso9660_mod_SOURCES): New variable. (iso9660_mod_CFLAGS): Likewise.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Add fs/iso9660.c.
* include/grub/fs.h (grub_iso9660_init): New prototype.
* util/grub-emu.c (main): Call `grub_iso9660_init'.
* fs/iso9660.c: New file.
* include/grub/misc.h (grub_strncat): New prototype.
* kern/misc.c (grub_strncat): New function.
* fs/hfs.c (grub_hfs_mount): Translate the error GRUB_ERR_OUT_OF_RANGE' to GRUB_ERR_BAD_FS'.
* fs/jfs.c (grub_jfs_mount): Likewise.
* fs/ufs.c (grub_ufs_mount): Likewise.
Index: conf/i386-pc.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/i386-pc.rmk,v
retrieving revision 1.21
i386-pc.rmk +5 -1
@@ -69,7 +69,7 @@ grub_emu_SOURCES = kern/main.c kern/devi kern/misc.c kern/loader.c kern/rescue.c kern/term.c \ disk/i386/pc/partition.c kern/env.c commands/ls.c \ commands/terminal.c commands/boot.c commands/cmp.c commands/cat.c \ - util/i386/pc/biosdisk.c fs/fat.c fs/ext2.c fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c\ + util/i386/pc/biosdisk.c fs/fat.c fs/ext2.c fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c fs/iso9660.c \ normal/cmdline.c normal/command.c normal/main.c normal/menu.c normal/arg.c \ util/console.c util/grub-emu.c util/misc.c util/i386/pc/getroot.c grub_emu_LDFLAGS = -lncurses
@@ -118,6 +118,10 @@ hfs_mod_CFLAGS = $(COMMON_CFLAGS) jfs_mod_SOURCES = fs/jfs.c jfs_mod_CFLAGS = $(COMMON_CFLAGS) +# For iso9660.mod. +iso9660_mod_SOURCES = fs/iso9660.c +iso9660_mod_CFLAGS = $(COMMON_CFLAGS) + # For _linux.mod. _linux_mod_SOURCES = loader/i386/pc/linux.c _linux_mod_CFLAGS = $(COMMON_CFLAGS)
Index: conf/powerpc-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/powerpc-ieee1275.rmk,v retrieving revision 1.10
powerpc-ieee1275.rmk +2 -1
@@ -26,7 +26,8 @@ grub_emu_SOURCES = kern/main.c kern/devi kern/misc.c kern/loader.c kern/rescue.c kern/term.c \ disk/powerpc/ieee1275/partition.c fs/fshelp.c \ util/i386/pc/biosdisk.c fs/fat.c fs/ext2.c fs/ufs.c fs/minix.c fs/hfs.c \ - fs/jfs.c normal/cmdline.c normal/command.c normal/main.c normal/menu.c \ + fs/jfs.c fs/iso9660.c kern/fshelp.c \ + normal/cmdline.c normal/command.c normal/main.c normal/menu.c \ normal/arg.c \ util/console.c util/grub-emu.c util/misc.c util/i386/pc/getroot.c \ kern/env.c commands/ls.c \
Index: fs/hfs.c
===================================================================
RCS file: /cvsroot/grub/grub2/fs/hfs.c,v
retrieving revision 1.2
hfs.c +7 -7
@@ -391,14 +391,14 @@ grub_hfs_mount (grub_disk_t disk) data->rootdir =grub_be_to_cpu32 (dir.dirid); - fail: -if (grub_errno) - { -grub_free (data); - data =0 ; - } -return data; + fail: +grub_free (data); + +if (grub_errno ==GRUB_ERR_OUT_OF_RANGE ) +grub_error (GRUB_ERR_BAD_FS ,"not a hfs filesystem" ); + +return 0 ; }
Index: fs/iso9660.c
===================================================================
RCS file: fs/iso9660.c
iso9660.c new file +841 -0
841 lines not on this page · raw message
Index: fs/jfs.c
===================================================================
RCS file: /cvsroot/grub/grub2/fs/jfs.c,v
retrieving revision 1.1
jfs.c +4 -0
@@ -361,6 +361,10 @@ grub_jfs_mount (grub_disk_t disk) fail:grub_free (data); + +if (grub_errno ==GRUB_ERR_OUT_OF_RANGE ) +grub_error (GRUB_ERR_BAD_FS ,"not a jfs filesystem" ); +return 0 ; }
Index: fs/ufs.c
===================================================================
RCS file: /cvsroot/grub/grub2/fs/ufs.c,v
retrieving revision 1.1
ufs.c +4 -0
@@ -522,6 +522,10 @@ grub_ufs_mount (grub_disk_t disk) fail:grub_free (data); + +if (grub_errno ==GRUB_ERR_OUT_OF_RANGE ) +grub_error (GRUB_ERR_BAD_FS ,"not a ufs filesystem" ); +return 0 ; }
Index: include/grub/fs.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/fs.h,v
retrieving revision 1.9
grub/fs.h +1 -0
@@ -78,6 +78,7 @@ void grub_hfs_init (void);void grub_hfs_fini (void );void grub_jfs_init (void );void grub_jfs_fini (void ); +void grub_iso9660_init (void );#endif /* GRUB_UTIL */ #endif /* ! GRUB_FS_HEADER */
Index: include/grub/misc.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/misc.h,v retrieving revision 1.10
grub/misc.h +1 -0
@@ -34,6 +34,7 @@ char *EXPORT_FUNC(grub_strcpy) (char *dechar *EXPORT_FUNC (grub_strncpy ) (char *dest,const char *src,int c);char *EXPORT_FUNC (grub_stpcpy ) (char *dest,const char *src);char *EXPORT_FUNC (grub_strcat ) (char *dest,const char *src); +char *EXPORT_FUNC (grub_strncat ) (char *dest,const char *src,int c);int EXPORT_FUNC (grub_memcmp ) (const void *s1,const void *s2,grub_size_t n);
Index: kern/misc.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/misc.c,v
retrieving revision 1.15
misc.c +15 -0
@@ -100,6 +100,21 @@ grub_strcat (char *dest, const char *srcreturn dest; } +char * +grub_strncat (char *dest,const char *src,int c) +{ +char *p = dest; + +while (*p) + p++; + +while ((*p++ = *src++) !='\0' && --c) + ; + *(--p) ='\0' ; + +return dest; +} +int grub_printf (const char *fmt, ...) {
Index: util/grub-emu.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/grub-emu.c,v
retrieving revision 1.7
grub-emu.c +1 -0
@@ -156,6 +156,7 @@ main (int argc, char *argv[])grub_util_biosdisk_init (args.dev_map);/* Initialize the default modules. */ +grub_iso9660_init ();grub_fat_init ();grub_ext2_init ();grub_ufs_init ();
Quoted 4 lines · Marco Gerards
Here is a patch to add iso9660 support to GRUB 2. There is support for rockridge (including stuff like symlinks), but there is no joliet support. I've also fixed a few filesystems so they do not fail when the block read is out of range.
This might be a stupid request, but could you split the patch into two? One with iso9660 support, and one with the small fixes. Just for the sake of making clean change sets. That would simplify, for example, the process of reversing one of the patches if they turn out to be buggy and ugly. :)
A few comments:
iso9660.c line 357
Quoted 10 lines
iso9660.c new file +9
-0+#if 0 +/* XXX: This code is used to lookup directories using the path tables. +This code is currently disabled, but should be enabled again to +speed up the lookup of nested files. */ +static grub_err_t +grub_iso9660_finddir (struct grub_iso9660_data *data,int parent, +const char *name,int *dirid,int *first_sector) +{ +#endif /* 0 */
Why include dead code in the patch? If you want to keep it around, store it on your local disk instead of the repository.
I know it's easy to include half-done future enhancements. But instead write a (lengthy) comment on how things could be tuned for performance.
Though, I don't think that you should remove code that is disabled just temporary, that used to be "alive."
Just my 2 cents.
iso9660.c line 394
Quoted 3 lines
iso9660.c new file +3
-0+/* The symlink is not stored as a POSIX symlink, translate it. */ +while (pos <grub_le_to_cpu32 (entry->len)) + {
Are grub_le_to_cpu32 and friends implemented as macros? If not, break out the grub_le_to_cpu32 (entry->len) expr into a variable and use that for comparison.
Quoted 8 lines
iso9660.c new file +8
-0+static grub_err_t +grub_iso9660_dir (grub_device_t device,const char *path, +int (*hook) (const char *filename,int dir)) +{ +struct grub_iso9660_data *data =0 ; +struct grub_fshelp_node rootnode; +struct grub_fshelp_node *foundnode; +
iso9660.c line 663
Quoted 10 lines
iso9660.c new file +10
-0+ auto int NESTED_FUNC_ATTR iterate (const char *filename, +enum grub_fshelp_filetype filetype, +grub_fshelp_node_t node); + + int NESTED_FUNC_ATTR iterate (const char *filename, +enum grub_fshelp_filetype filetype, +grub_fshelp_node_t node) + { +grub_free (node); +
I do not know what NESTED_FUNC_ATTR do or is good for, but I guess it is needed for all nested functions. I could of course be wrong. If I'm right, I think I saw another function (that currently is somewhere in my kill-ring) without the attribute (lua_read or something.)
iso9660.c line 769
Quoted 13 lines
iso9660.c new file +13
-0+static grub_ssize_t +grub_iso9660_read (grub_file_t file,char *buf,grub_ssize_t len) +{ +struct grub_iso9660_data *data = + (struct grub_iso9660_data *) file->data; + +/* XXX: The file is stored in as a single extent. */ + data->disk->read_hook = file->read_hook; +grub_disk_read (data->disk, + data->first_sector <<GRUB_ISO9660_LOG2_BLKSZ , + file->offset, + len, buf); + data->disk->read_hook =0 ;
I know it's easy to add "XXX" or "FIXME" comments. But try to write a real comment instead. In this case, why not just remove the "XXX:"
So, now I'm finished playing police. Hope you have had as much fun as I have.
~j
NESTED_FUNC_ATTR (was: Re: iso9660 support)
Quoted 4 lines
I do not know what
NESTED_FUNC_ATTRdo or is good for, but I guess it is needed for all nested functions. I could of course be wrong. If I'm right, I think I saw another function (that currently is somewhere in my kill-ring) without the attribute (lua_reador something.)
The NESTED_FUNC_ATTR is need for buggy versions of gcc, because we compile i386 grub (bootime) with mregparm=3. And there are versions of gcc that don't save content of one of registers when calling such function or something similar.
My opinion on mregparm=3 is not good, because this is only obstacle (and it is BIG obstacle) to use same modules at boottime and in posix-userland.
Signature · 3 lines
Tomas 'ebi' Ebenlendr
http://get.to/ebik
PF 2004.78714088747Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
Quoted 2 lines · Tomas Ebenlendr
My opinion on mregparm=3 is not good, because this is only obstacle (and it is BIG obstacle) to use same modules at boottime and in posix-userland.
So why not just stop using -mregparm=3? I'm pretty sure it isn't needed in GRUB, since a boot loader doesn't have very high performance constrains.
~j
Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
Quoted 3 lines · Johan Rydberg
So why not just stop using -mregparm=3? I'm pretty sure it isn't needed in GRUB, since a boot loader doesn't have very high performance constrains.
It is necessary for the size constraint. Note that we don't need to use the same binary between the real GRUB and the emulated one. And, the emulation is only useful for debugging. So if grub-emu is difficult to maintain, I vote for just dropping it.
Okuji
Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
Quoted 11 lines · Johan Rydberg
Quoted 3 lines
So why not just stop using -mregparm=3? I'm pretty sure it isn't needed in GRUB, since a boot loader doesn't have very high performance constrains.
It is necessary for the size constraint. Note that we don't need to use the same binary between the real GRUB and the emulated one. And, the emulation is only useful for debugging. So if grub-emu is difficult to maintain, I vote for just dropping it.
Okuji
No, it isn't. I think grub-emu is important for example for saving default menu entry mechanism or so. I also thought that grub-setup will be replaced by install mechanism which will be in grub (and grub-emu). And I think, that in such case will be less confusing, when there will be one binary (module) for both grub-emu and grub (boottime).
So, what is the size constraint? Is it for machines with small stack? If so, do we recurse so deep somewhere?
Signature · 3 lines
Tomas 'ebi' Ebenlendr
http://get.to/ebik
PF 2004.7946652373Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
Quoted 10 lines · Tomas Ebenlendr
Quoted 10 lines · Johan Rydberg
Quoted 3 lines
So why not just stop using -mregparm=3? I'm pretty sure it isn't needed in GRUB, since a boot loader doesn't have very high performance constrains.
It is necessary for the size constraint. Note that we don't need to use the same binary between the real GRUB and the emulated one. And, the emulation is only useful for debugging. So if grub-emu is difficult to maintain, I vote for just dropping it.
Quoted 7 lines
Quoted 1 line
Okuji
No, it isn't. I think grub-emu is important for example for saving default menu entry mechanism or so. I also thought that grub-setup will be replaced by install mechanism which will be in grub (and grub-emu). And I think, that in such case will be less confusing, when there will be one binary (module) for both grub-emu and grub (boottime).
The main reason why I made grub-emu is because it is convenient when I am debugging things. So please do not drop it.
As for module support, it is really important for me to have in grub-emu. But I do not care too much about compatibility between the normal modules and those of grub-emu.
Perhaps it would be even best if grub-emu is disabled when GRUB is built by normal users. And it is the best that a debugging tool like this does not have any impact of GRUB itself. Therefore I agree with Okuji.
I really hope install mechanisms will not be added to grub-emu in a way people will all start using it. But that is just a matter of personal taste.
Thanks,
Marco
Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
Quoted 4 lines
I really hope install mechanisms will not be added to grub-emu in a way people will all start using it. But that is just a matter of personal taste.
Hmm, so you want to have grub-setup, and install mechanism in grub (because of some grub rescue floppy, or so). I thought there will be one mechanism common for both cases. (This is grub legacy feature, isn't it?)
Quoted 2 lines
Thanks,
Marco
Signature · 3 lines
Tomas 'ebi' Ebenlendr
http://get.to/ebik
PF 2004.79490620573Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
Quoted 4 lines · Tomas Ebenlendr
Hmm, so you want to have grub-setup, and install mechanism in grub (because of some grub rescue floppy, or so). I thought there will be one mechanism common for both cases. (This is grub legacy feature, isn't it?)
In GRUB 2, I don't intend to have an install mechanism in GRUB itself.
This feature is rarely useful nowadays, because it is necessary to put GRUB files in an appropriate place, reboot your machine then install it. After I wrote the grub shell, almost all people install GRUB under an OS but not from a boot floppy, since you don't need to reboot your machine any longer.
Okuji
Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
In reply to Tomas EbenlendrQuoted 9 lines · Tomas Ebenlendr
Quoted 4 lines
I really hope install mechanisms will not be added to grub-emu in a way people will all start using it. But that is just a matter of personal taste.
Hmm, so you want to have grub-setup, and install mechanism in grub (because of some grub rescue floppy, or so). I thought there will be one mechanism common for both cases. (This is grub legacy feature, isn't it?)
Personally I have not thought a lot about how to install it. AFAIK grub-setup can handle any case. Which cases are you thinking about and how do you want to see those implemented?
Thanks,
Marco
Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
In reply to Marco GerardsQuoted 3 lines · Marco Gerards
I really hope install mechanisms will not be added to grub-emu in a way people will all start using it. But that is just a matter of personal taste.
I agree. You can use noinst_UTILITIES if you don't want to install it.
Okuji
Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
In reply to Tomas EbenlendrQuoted 2 lines · Tomas Ebenlendr
No, it isn't. I think grub-emu is important for example for saving default menu entry mechanism or so.
I don't agree. Please look at GRUB legacy. It does not use the grub shell to save a defaule entry.
Quoted 3 lines
And I think, that in such case will be less confusing, when there will be one binary (module) for both grub-emu and grub (boottime).
I don't think so, because grub-emu is useful only for developers. Ordinary users don't care.
Quoted 1 line
So, what is the size constraint? Is it for machines with small stack?
No. This is the same as GRUB legacy. We want to use free space right after the MBR, but this region is quite small (normally, 31KB). I reduced the binary size very seriously to make core.img fit in this region, and I don't want to give it up.
Okuji
Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
Quoted 6 lines · Yoshinori K. Okuji
Quoted 1 line
So, what is the size constraint? Is it for machines with small stack?
No. This is the same as GRUB legacy. We want to use free space right after the MBR, but this region is quite small (normally, 31KB). I reduced the binary size very seriously to make core.img fit in this region, and I don't want to give it up.
Do you remember how much is gained by doing this? I do agree with you, I am just asking out of curiosity.
Thanks,
Marco
Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
Quoted 1 line · Marco Gerards
Do you remember how much is gained by doing this?
I don't remember well, but my paper in Japanese says that it was about 2KB. Since the kernel has grown a bit more since that time, I guess the gain could be about 3KB in the current implementation. -mregparm=3 has a significant effect on functions with a few arguments.
Okuji
Re: NESTED_FUNC_ATTR (was: Re: iso9660 support)
Quoted 7 lines · Yoshinori K. Okuji
Quoted 1 line · Marco Gerards
Do you remember how much is gained by doing this?
I don't remember well, but my paper in Japanese says that it was about 2KB. Since the kernel has grown a bit more since that time, I guess the gain could be about 3KB in the current implementation. -mregparm=3 has a significant effect on functions with a few arguments.
Nice. Is there more interesting information like this in the Japanese paper you wrote? I know this is a really vague question. :/
Thanks,
Marco
Quoted 5 lines · Johan Rydberg
This might be a stupid request, but could you split the patch into two? One with iso9660 support, and one with the small fixes. Just for the sake of making clean change sets. That would simplify, for example, the process of reversing one of the patches if they turn out to be buggy and ugly. :)
The other parts of the patch are kind of related. It fixes some bugs in the probe of filesystems which result in problems with some iso9660 images I used. Therefore I have included them.
Quoted 16 lines
A few comments:
iso9660.c line 357
Quoted 10 lines
iso9660.c new file +9
-0+#if 0 +/* XXX: This code is used to lookup directories using the path tables. +This code is currently disabled, but should be enabled again to +speed up the lookup of nested files. */ +static grub_err_t +grub_iso9660_finddir (struct grub_iso9660_data *data,int parent, +const char *name,int *dirid,int *first_sector) +{ +#endif /* 0 */ Why include dead code in the patch? If you want to keep it around, store it on your local disk instead of the repository.
Quoted 7 lines
I know it's easy to include half-done future enhancements. But instead write a (lengthy) comment on how things could be tuned for performance.
Though, I don't think that you should remove code that is disabled just temporary, that used to be "alive."
Just my 2 cents.
I could remove that. Personally I like to keep this around so it is there when people need it.
Quoted 7 lines
iso9660.c line 394
Quoted 3 lines
iso9660.c new file +3
-0+/* The symlink is not stored as a POSIX symlink, translate it. */ +while (pos <grub_le_to_cpu32 (entry->len)) + {Are
grub_le_to_cpu32and friends implemented as macros? If not, break out thegrub_le_to_cpu32(entry->len) expr into a variable and use that for comparison.
They are.
Quoted 15 lines
Quoted 15 lines
iso9660.c new file +15
-0+static grub_err_t +grub_iso9660_dir (grub_device_t device,const char *path, +int (*hook) (const char *filename,int dir)) +{ +struct grub_iso9660_data *data =0 ; +struct grub_fshelp_node rootnode; +struct grub_fshelp_node *foundnode; + + auto int NESTED_FUNC_ATTR iterate (const char *filename, +enum grub_fshelp_filetype filetype, +grub_fshelp_node_t node); + + int NESTED_FUNC_ATTR iterate (const char *filename, +enum grub_fshelp_filetype filetype, +grub_fshelp_node_t node)
Quoted 8 lines
iso9660.c line 663
Quoted 3 lines
iso9660.c new file +3
-0+ { +grub_free (node); +I do not know what
NESTED_FUNC_ATTRdo or is good for, but I guess it is needed for all nested functions. I could of course be wrong. If I'm right, I think I saw another function (that currently is somewhere in my kill-ring) without the attribute (lua_reador something.)
NESTED_FUNC_ATTR is there to work around a bug in gcc. It is only triggered when 3 or ore arguments are used. Because of that it is used here and not in the other function you mentioned.
Quoted 8 lines
Quoted 8 lines
iso9660.c new file +8
-0+static grub_ssize_t +grub_iso9660_read (grub_file_t file,char *buf,grub_ssize_t len) +{ +struct grub_iso9660_data *data = + (struct grub_iso9660_data *) file->data; + +/* XXX: The file is stored in as a single extent. */ + data->disk->read_hook = file->read_hook;
Quoted 8 lines
iso9660.c line 769
Quoted 5 lines
iso9660.c new file +5
-0+grub_disk_read (data->disk, + data->first_sector <<GRUB_ISO9660_LOG2_BLKSZ , + file->offset, + len, buf); + data->disk->read_hook =0 ;I know it's easy to add "XXX" or "FIXME" comments. But try to write a real comment instead. In this case, why not just remove the "XXX:"
I'm used to Hurd hacking and this is the style that is used in the Hurd. Comments like XXX and FIXME are useful because it is the first thing you want to look at in case of problems. This is such case. I am not really convinced yet that it should be removed.
Thanks,
Marco