add true and false commands
PATCH 1/1 add true and false commands
Hi,
here's a simple patch which adds a true' and a false' command. `true' is actually needed by the compatibility code generated by grub-mkconfig for the terminal.
--
Felix Zielcke
2009-05-27 Felix Zielcke <[email protected]>
* commands/minicmd.c (grub_mini_cmd_true): New function. (grub_mini_cmd_false): Likewise.
(cmd_true, cmd_false): New static variables. (GRUB_MOD_INIT(minicmd)): Register commands true and false. (GRUB_MOD_FINI(minicmd)): Unregister commands true and false.
minicmd.c +27 -0
@@ -336,8 +336,27 @@ grub_mini_cmd_exit (struct grub_commandreturn 0 ; } +/* true */ +static grub_err_t +grub_mini_cmd_true (struct grub_command *cmd __attribute__ ((unused)), +int argc __attribute__ ((unused)), +char *argv[] __attribute__ ((unused))) +{ +return 0 ; +} + +/* false */ +static grub_err_t +grub_mini_cmd_false (struct grub_command *cmd __attribute__ ((unused)), +int argc __attribute__ ((unused)), +char *argv[] __attribute__ ((unused))) +{ +return 1 ; +} +static grub_command_t cmd_cat, cmd_help, cmd_root;static grub_command_t cmd_dump, cmd_rmmod, cmd_lsmod, cmd_exit; +static grub_command_t cmd_true, cmd_false;GRUB_MOD_INIT (minicmd) {
@@ -362,6 +381,12 @@ GRUB_MOD_INIT(minicmd) cmd_exit =grub_register_command ("exit" , grub_mini_cmd_exit,0 ,"exit from GRUB" ); + cmd_true = +grub_register_command ("true" , grub_mini_cmd_true, +0 ,"do nothing, successfully" ); + cmd_false = +grub_register_command ("false" , grub_mini_cmd_true, +0 ,"do nothing, unsuccessfully" ); }GRUB_MOD_FINI (minicmd)
@@ -373,4 +398,6 @@ GRUB_MOD_FINI(minicmd)grub_unregister_command (cmd_rmmod);grub_unregister_command (cmd_lsmod);grub_unregister_command (cmd_exit); +grub_unregister_command (cmd_true); +grub_unregister_command (cmd_false); }
Quoted 5 lines · Felix Zielcke
Hi,
here's a simple patch which adds a
true' and afalse' command. `true' is actually needed by the compatibility code generated by grub-mkconfig for the terminal.
As far as I understand they are useful only in normal mode. Perhaps putting them into normal.mod or sh.mod would make more sense?
Quoted 10 lines
--
Felix Zielcke_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Am Samstag, den 30.05.2009, 17:14 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 8 lines · Felix Zielcke
Quoted 5 lines
Hi,
here's a simple patch which adds a
true' and afalse' command. `true' is actually needed by the compatibility code generated by grub-mkconfig for the terminal.As far as I understand they are useful only in normal mode. Perhaps putting them into normal.mod or sh.mod would make more sense?
Ok here's a new patch which places them into normal.mod. Does a `false' command actually make sense in grub?
Signature · 1 line
Felix Zielcke
2009-06-01 Felix Zielcke <[email protected]>
* normal/main.c (grub_cmd_true): New function. (grub_mini_cmd_false): Likewise.
(cmd_true): New static variable.
(cmd_false): Likewise.
(GRUB_MOD_INIT(minicmd)): Register commands true and false. (GRUB_MOD_FINI(minicmd)): Unregister commands true and false.
normal/main.c +29 -0
@@ -536,6 +536,26 @@ grub_env_write_pager (struct grub_env_var *var __attribute__ ((unused)),return grub_strdup (val); } +/* true */ +static grub_err_t +grub_cmd_true (struct grub_command *cmd __attribute__ ((unused)), +int argc __attribute__ ((unused)), +char *argv[] __attribute__ ((unused))) +{ +return 0 ; +} + +/* false */ +static grub_err_t +grub_cmd_false (struct grub_command *cmd __attribute__ ((unused)), +int argc __attribute__ ((unused)), +char *argv[] __attribute__ ((unused))) +{ +return 1 ; +} + +static grub_command_t cmd_true, cmd_false; +GRUB_MOD_INIT (normal) {/* Normal mode shouldn't be unloaded. */
@@ -561,6 +581,13 @@ GRUB_MOD_INIT(normal)/* Preserve hooks after context changes. */ grub_env_export ("color_normal" );grub_env_export ("color_highlight" ); + + cmd_true = +grub_register_command ("true" , grub_cmd_true, +0 ,"do nothing, successfully" ); + cmd_false = +grub_register_command ("false" , grub_cmd_true, +0 ,"do nothing, unsuccessfully" ); }GRUB_MOD_FINI (normal)
@@ -570,4 +597,6 @@ GRUB_MOD_FINI(normal)grub_register_variable_hook ("pager" ,0 ,0 ); grub_fs_autoload_hook =0 ;free_handler_list (); +grub_unregister_command (cmd_true); +grub_unregister_command (cmd_false); }
Quoted 5 lines · Felix Zielcke
Am Samstag, den 30.05.2009, 17:14 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 3 lines · Felix Zielcke
Quoted 2 lines
Hi,
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
here's a simple patch which adds a
true' and afalse' command. `true' is actually needed by the compatibility code generated by grub-mkconfig for the terminal.As far as I understand they are useful only in normal mode. Perhaps putting them into normal.mod or sh.mod would make more sense?
Ok here's a new patch which places them into normal.mod. Does a `false' command actually make sense in grub?
It does since we make bash-similar scripting. However convention for creating false is:
return grub_error (GRUB_ERR_TEST_FAILURE, "false");
and not
return 1;
Quoted 9 lines
--
Felix Zielcke_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Am Montag, den 01.06.2009, 16:24 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 5 lines
However convention for
creating false is:
returngrub_error(GRUB_ERR_TEST_FAILURE, "false");
and not
return 1;
Ok changed it. If everyone is fine with placing this in normal/main.c, I commit it.
Signature · 1 line
Felix Zielcke
2009-06-03 Felix Zielcke <[email protected]>
* normal/main.c (grub_cmd_true): New function. (grub_cmd_false): Likewise.
(cmd_true): New static variable.
(cmd_false): Likewise.
(GRUB_MOD_INIT(normal)): Register commands true and false. (GRUB_MOD_FINI(normal)): Unregister commands true and false.
normal/main.c +29 -0
@@ -536,6 +536,26 @@ grub_env_write_pager (struct grub_env_var *var __attribute__ ((unused)),return grub_strdup (val); } +/* true */ +static grub_err_t +grub_cmd_true (struct grub_command *cmd __attribute__ ((unused)), +int argc __attribute__ ((unused)), +char *argv[] __attribute__ ((unused))) +{ +return 0 ; +} + +/* false */ +static grub_err_t +grub_cmd_false (struct grub_command *cmd __attribute__ ((unused)), +int argc __attribute__ ((unused)), +char *argv[] __attribute__ ((unused))) +{ +return grub_error (GRUB_ERR_TEST_FAILURE ,"false" ); +} + +static grub_command_t cmd_true, cmd_false; +GRUB_MOD_INIT (normal) {/* Normal mode shouldn't be unloaded. */
@@ -561,6 +581,13 @@ GRUB_MOD_INIT(normal)/* Preserve hooks after context changes. */ grub_env_export ("color_normal" );grub_env_export ("color_highlight" ); + + cmd_true = +grub_register_command ("true" , grub_cmd_true, +0 ,"do nothing, successfully" ); + cmd_false = +grub_register_command ("false" , grub_cmd_true, +0 ,"do nothing, unsuccessfully" ); }GRUB_MOD_FINI (normal)
@@ -570,4 +597,6 @@ GRUB_MOD_FINI(normal)grub_register_variable_hook ("pager" ,0 ,0 ); grub_fs_autoload_hook =0 ;free_handler_list (); +grub_unregister_command (cmd_true); +grub_unregister_command (cmd_false); }
Quoted 10 lines · Felix Zielcke
Am Montag, den 01.06.2009, 16:24 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 5 lines
However convention for
creating false is:
returngrub_error(GRUB_ERR_TEST_FAILURE, "false");
and not
return 1;Ok changed it. If everyone is fine with placing this in
normal/main.c, I commit it.
Unless it is essential to do so, please do not place it in normal/main.c.
--
Marco
Am Donnerstag, den 04.06.2009, 10:21 +0200 schrieb Marco Gerards:
Quoted 10 lines
Quoted 8 lines · Felix Zielcke
Am Montag, den 01.06.2009, 16:24 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 5 lines
However convention for
creating false is:
returngrub_error(GRUB_ERR_TEST_FAILURE, "false");
and not
return 1;
Quoted 6 lines
Quoted 2 lines
Ok changed it. If everyone is fine with placing this in
normal/main.c, I commit it.Unless it is essential to do so, please do not place it in
normal/main.c.
would normal/misc.c be okay or maybe a new file normal/true.c? I just don't think it's worth to create a new module for these 2 very little commands.
Signature · 1 line
Felix Zielcke
Quoted 14 lines · Felix Zielcke
Am Donnerstag, den 04.06.2009, 10:21 +0200 schrieb Marco Gerards:
Quoted 13 lines
Quoted 10 lines · Felix Zielcke
Am Montag, den 01.06.2009, 16:24 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 5 lines
However convention for
creating false is:
returngrub_error(GRUB_ERR_TEST_FAILURE, "false");
and not
return 1;Ok changed it. If everyone is fine with placing this in
normal/main.c, I commit it.
Quoted 6 lines
Quoted 2 lines
Unless it is essential to do so, please do not place it in
normal/main.c.would
normal/misc.cbe okay or maybe a new filenormal/true.c? I just don't think it's worth to create a new module for these 2 very little commands.
The problem is with too many little commands, the size of normal.mod grows. Although the commands are *very* small and I do not strongly object to inclusion in normal.mod, if noone else has any objection.
--
Marco
Am Freitag, den 05.06.2009, 12:00 +0200 schrieb Marco Gerards:
Quoted 19 lines
Quoted 17 lines · Felix Zielcke
Am Donnerstag, den 04.06.2009, 10:21 +0200 schrieb Marco Gerards:
Quoted 15 lines
Quoted 10 lines · Felix Zielcke
Am Montag, den 01.06.2009, 16:24 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 5 lines
However convention for
creating false is:
returngrub_error(GRUB_ERR_TEST_FAILURE, "false");
and not
return 1;Ok changed it. If everyone is fine with placing this in
normal/main.c, I commit it.Unless it is essential to do so, please do not place it in
normal/main.c.
Quoted 7 lines
Quoted 3 lines
would
normal/misc.cbe okay or maybe a new filenormal/true.c? I just don't think it's worth to create a new module for these 2 very little commands.The problem is with too many little commands, the size of normal.mod grows. Although the commands are *very* small and I do not strongly object to inclusion in normal.mod, if noone else has any objection.
The binary size of normal.mod would grow about 264 bytes whereas in minicmd.mod it would be just 260 bytes.
But I already forgot that Bean wants to get rid of normal.mod.
So what should I do now?
Placing it in normal.mod or minicmd.mod where it's included in rescue mode or placing it into a true.mod where the size increase would be bigger?
Signature · 1 line
Felix Zielcke
Quoted 28 lines · Felix Zielcke
Am Freitag, den 05.06.2009, 12:00 +0200 schrieb Marco Gerards:
Quoted 19 lines
Quoted 17 lines · Felix Zielcke
Am Donnerstag, den 04.06.2009, 10:21 +0200 schrieb Marco Gerards:
Quoted 15 lines
Quoted 10 lines · Felix Zielcke
Am Montag, den 01.06.2009, 16:24 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 5 lines
However convention for
creating false is:
returngrub_error(GRUB_ERR_TEST_FAILURE, "false");
and not
return 1;Ok changed it. If everyone is fine with placing this in
normal/main.c, I commit it.Unless it is essential to do so, please do not place it in
normal/main.c.Quoted 7 lines
Quoted 3 lines
would
normal/misc.cbe okay or maybe a new filenormal/true.c? I just don't think it's worth to create a new module for these 2 very little commands.The problem is with too many little commands, the size of normal.mod grows. Although the commands are *very* small and I do not strongly object to inclusion in normal.mod, if noone else has any objection.
Quoted 8 lines
The binary size of normal.mod would grow about 264 bytes whereas in minicmd.mod it would be just 260 bytes.
But I already forgot that Bean wants to get rid of normal.mod.So what should I do now?
Placing it in normal.mod or minicmd.mod where it's included in rescue mode or placing it into a true.mod where the size increase would be bigger?
minicmd.mod is not a very descriptive name. Better call is truefalse.mod or something like that.
--
Marco
Am Freitag, den 05.06.2009, 14:26 +0200 schrieb Marco Gerards:
Quoted 9 lines
Quoted 4 lines · Felix Zielcke
So what should I do now?
Placing it in normal.mod or minicmd.mod where it's included in rescue mode or placing it into a true.mod where the size increase would be bigger?minicmd.mod is not a very descriptive name. Better call is truefalse.mod or something like that.
minicmd.mod already exists, see commands/minicmd.c (or my first patch). That's where I put it in the first patch.
Anyway here's a new one which adds true.mod which gets 1264 bytes big.
Thanks Marco that you take the time for it.
Signature · 1 line
Felix Zielcke
2009-06-05 Felix Zielcke <[email protected]>
* commands/true.c: New file. Implement the true and false commands.
* conf/common.rmk.c (pkglib_MODULES): Add `true.mod'. (true_mod_SOURCES): New variable.
(true_mod_CFLAGS): Likewise.
(true_mod_LDFLAGS): Likewise.
commands/true.c +56 -0
@@ -0,0 +1,56 @@ +/* true.c - true and false commands. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2009 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/>. +*/ + +#include <grub/dl.h> +#include <grub/command.h> + +static grub_err_t +grub_cmd_true (struct grub_command *cmd __attribute__ ((unused)), +int argc __attribute__ ((unused)), +char *argv[] __attribute__ ((unused))) +{ +return 0 ; +} + +static grub_err_t +grub_cmd_false (struct grub_command *cmd __attribute__ ((unused)), +int argc __attribute__ ((unused)), +char *argv[] __attribute__ ((unused))) +{ +return grub_error (GRUB_ERR_TEST_FAILURE ,"false" ); +} + +static grub_command_t cmd_true, cmd_false; + + +GRUB_MOD_INIT (true) +{ + cmd_true = +grub_register_command ("true" , grub_cmd_true, +0 ,"do nothing, successfully" ); + cmd_false = +grub_register_command ("false" , grub_cmd_false, +0 ,"do nothing, unsuccessfully" ); +} + +GRUB_MOD_FINI (true) +{ +grub_unregister_command (cmd_true); +grub_unregister_command (cmd_false); +}
conf/common.rmk +6 -1
@@ -344,7 +344,7 @@ pkglib_MODULES += minicmd.mod extcmd.mod hello.mod handler.mod \ terminfo.mod test.mod blocklist.mod hexdump.mod \ read.mod sleep.mod loadenv.mod crc.mod parttool.mod \ pcpart.mod memrw.mod boot.mod normal.mod sh.mod lua.mod \ - gptsync.mod + gptsync.mod true.mod # For gptsync.mod. gptsync_mod_SOURCES = commands/gptsync.c
@@ -476,6 +476,11 @@ memrw_mod_SOURCES = commands/memrw.c memrw_mod_CFLAGS = $(COMMON_CFLAGS) memrw_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For true.mod +true_mod_SOURCES = commands/true.c +true_mod_CFLAGS = $(COMMON_CFLAGS) +true_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For normal.mod. normal_mod_SOURCES = normal/main.c normal/cmdline.c normal/dyncmd.c \ normal/autofs.c normal/handler.c \
Quoted 8 lines · Felix Zielcke
Am Freitag, den 05.06.2009, 14:26 +0200 schrieb Marco Gerards:
Quoted 7 lines
Quoted 4 lines · Felix Zielcke
So what should I do now?
Placing it in normal.mod or minicmd.mod where it's included in rescue mode or placing it into a true.mod where the size increase would be bigger?
Quoted 6 lines
Quoted 2 lines
minicmd.mod is not a very descriptive name. Better call is truefalse.mod or something like that.
minicmd.mod already exists, see
commands/minicmd.c(or my first patch). That's where I put it in the first patch.
Anyway here's a new one which adds true.mod which gets 1264 bytes big.
Oh, I didn't know minicmd.mod. Is it useful to have one instead of a few separate modules? Space of these smaller modules is not really a concern to me.
--
Marco
Am Freitag, den 05.06.2009, 15:29 +0200 schrieb Marco Gerards:
Quoted 3 lines
Oh, I didn't know minicmd.mod. Is it useful to have one instead of a few separate modules? Space of these smaller modules is not really a concern to me.
Bean split the commands out from kernel.
So especially help and lsmod are in rescue mode only avaible if minicmd.mod gets embed into core.img, where size does matter.
That's why Vladimir suggest normal.mod or sh.mod. But sh.mod just contains the parser/lexer so I don't think that's a solution. I'm now now that sure what to do but I think I just make it now a seperate true.mod like in the last patch.
Signature · 1 line
Felix Zielcke
Am Freitag, den 05.06.2009, 15:04 +0200 schrieb Felix Zielcke:
Quoted 8 lines
Am Freitag, den 05.06.2009, 14:26 +0200 schrieb Marco Gerards:
Quoted 7 lines
Quoted 4 lines · Felix Zielcke
So what should I do now?
Placing it in normal.mod or minicmd.mod where it's included in rescue mode or placing it into a true.mod where the size increase would be bigger?
Quoted 8 lines
Quoted 2 lines
minicmd.mod is not a very descriptive name. Better call is truefalse.mod or something like that.
minicmd.mod already exists, see
commands/minicmd.c(or my first patch). That's where I put it in the first patch.
Anyway here's a new one which adds true.mod which gets 1264 bytes big.Thanks Marco that you take the time for it.
Commited that one.
Signature · 1 line
Felix Zielcke