Skip to contentSkip to conversation

Idea: elimination of the normal mode (revised version)

DISCUSSION Bean 4 participants 12 messages Jul 7, 2008 – Jul 22, 2008

lore
Share & tools
lore

Bean

author
#0 lore raw

Hi,

First of all, we can still keep rescue and normal command. But instead of depending on normal.mod, normal command depends on module arg, which is an option parser. Also, these two type of commands are of the same command set. In fact, module arg is implemented as a pre parser, which goes through the list of arguments and extract the options. In the case of rescue command, the pre parser field is null, which means it wants to parse options itself.

Then, I think of a new structure to represent all configurable handlers of grub. Different types of handler have different fields, but they all share a command header:

struct grub_handler
{
.next,
.name,
.init,
.fini
};

Same type of handlers are linked together. We first define an enum to list all types. For example:

enum {
GRUB_HANDLER_INPUT,
GRUB_HANDLER_OUTPUT,
GRUB_HANDLER_CONSOLE,
GRUB_HANDLER_MENU,
GRUB_HANDLER_SCRIPT,
GRUB_HANDLER_NUM
};

Then, we define an array to point to the head of handler linked list:
grub_handler[GRUB_HANDLER_NUM];

Head is the default selection. When we insert a new handler module, it would automatically become the new default, although we can switch back to old handler using a command.

Here are more details about different handlers:

input:
This is the input component of terminal:

struct grub_handler_input
{
.next,
.name,
.init,
.fini,
.checkkey,
.getkey
.flags,
};

output:
This is the output component of terminal:

struct grub_handler_output
{
.next,
.name,
.init,
.fini,
.putchar,
.getcharwidth,
.getxy,
.gotoxy,
.cls,
.setcolorstate,
.setcursor,
.flags,
};

console interface:
It represent the grub console, users type commands and execute them line by line.

struct grub_handler_console
{
.next,
.name,
.init,
.fini,
.run
};

menu interface:
It represent the menu, users select a menu item and execute it.

struct grub_handler_menu
{
.next,
.name,
.init,
.fini,
.run
};

script engine:
It's responsible for parsing config file to get the menu list, and execution of commands.

struct grub_handler_script
{
.next,
.name,
.init,
.fini,
.readconfig
.getmenu
.execute
};

The handlers are independent of each other. When they need something, they called specific function of the default handler. For example, to read a key from the console, we can use grub_handler[GRUB_HANDLER_INPUT]->getkey. Also, to get the list of items to be displayed on screen, the menu handler can call grub_handler[GRUB_HANDLER_SCRIPT]->getmenu.

Signature · 1 line
Bean
author
#1 lore raw
Quoted 116 lines · Bean

Hi,

First of all, we can still keep rescue and normal command. But instead of depending on normal.mod, normal command depends on module arg, which is an option parser. Also, these two type of commands are of the same command set. In fact, module arg is implemented as a pre parser, which goes through the list of arguments and extract the options. In the case of rescue command, the pre parser field is null, which means it wants to parse options itself.

Then, I think of a new structure to represent all configurable handlers of grub. Different types of handler have different fields, but they all share a command header:

struct grub_handler
{
.next,
.name,
.init,
.fini
};

Same type of handlers are linked together. We first define an enum to list all types. For example:

enum {
GRUB_HANDLER_INPUT,
GRUB_HANDLER_OUTPUT,
GRUB_HANDLER_CONSOLE,
GRUB_HANDLER_MENU,
GRUB_HANDLER_SCRIPT,
GRUB_HANDLER_NUM
};

Then, we define an array to point to the head of handler linked list:
grub_handler[GRUB_HANDLER_NUM];

Head is the default selection. When we insert a new handler module, it would automatically become the new default, although we can switch back to old handler using a command.

Here are more details about different handlers:

input:
This is the input component of terminal:

struct grub_handler_input
{
.next,
.name,
.init,
.fini,
.checkkey,
.getkey
.flags,
};

output:
This is the output component of terminal:

struct grub_handler_output
{
.next,
.name,
.init,
.fini,
.putchar,
.getcharwidth,
.getxy,
.gotoxy,
.cls,
.setcolorstate,
.setcursor,
.flags,
};

console interface:
It represent the grub console, users type commands and execute them line by line.

struct grub_handler_console
{
.next,
.name,
.init,
.fini,
.run
};

menu interface:
It represent the menu, users select a menu item and execute it.

struct grub_handler_menu
{
.next,
.name,
.init,
.fini,
.run
};

script engine:
It's responsible for parsing config file to get the menu list, and execution of commands.

struct grub_handler_script
{
.next,
.name,
.init,
.fini,
.readconfig
.getmenu
.execute
};

Quoted 6 lines

The handlers are independent of each other. When they need something, they called specific function of the default handler. For example, to read a key from the console, we can use grub_handler[GRUB_HANDLER_INPUT]->getkey. Also, to get the list of items to be displayed on screen, the menu handler can call grub_handler[GRUB_HANDLER_SCRIPT]->getmenu.

Any comment for this idea ?

Signature · 1 line
Bean
#2 lore raw
Quoted 1 line · Bean

Any comment for this idea ?

Maybe you could describe was it will give us and what the drawbacks may be? It's hard to comment on the implementation ideas without seeing the bigger picture.

Signature · 2 lines
Regards,
Pavel Roskin
author
#3 lore raw
Quoted 7 lines · Pavel Roskin
Quoted 1 line · Bean

Any comment for this idea ?

Maybe you could describe was it will give us and what the drawbacks may be? It's hard to comment on the implementation ideas without seeing the bigger picture.

Hi,

In the previous thread "Idea: elimination of the normal mode", I have listed some of the reasons. Here are the advantages of this scheme:

1. One command set

One of the annoying thing of current implementation is that it has two command set, rescue command and normal command. Some command that can be called in both rescue mode and normal mode have two modules, like linux.mod and _linux.mod. What's more, normal mode command depend on normal.mod, so if we want to include search.mod in grub-mkimage, normal.mod will be included as well, which make the image quite big.

But if we take a look at the two command sets, one major different is that rescue command pass argument directly to command, while normal mode command parse it first to get options, then pass it and the rest of argument to the command.

Therefore, normal command is essentially rescue command plus argument parser, we can unify them into one command set. Also, normal command would only depend on argument parser, which is a lot smaller than normal.mod.

2. Separation of script engine and interface

Another thing about normal.mod is that it bundles script engine and interface handler together, which makes it more difficult to extend its function. We can split the two components:

Script engine is responsible for parsing config file, getting menu list, and execution of commands, etc.

Interface is responsible for drawing the menu, handling user input, etc.

These two component are independent. For example, when interface module want to know the menu list to draw on screen, it asks script engine for it, instead of calling a fixed function.

Rescue mode and normal mode uses different script engine and interface.

Rescue mode:

The script engine is a basic line based scanner, which splits the command line using space.

The interface is the rescue shell, which accept user input, then calls the script engine to execute it.

Normal mode:

The script engine is a bash-like parser, it can return menu list as well.

The console interface is a little advanced than the rescue shell, it has auto completion and history.

The menu interface is the normal menu, it calls script engine to get the menu list, and uses it to execute commands when user select a menu item.

Other possible interface:

simple menu:

Some terminal doesn't support arbitrary cursor position, so we could implement a simple menu interface where the available items are displayed line by line, with a number indicator. User can choose them using the indicator.

graphic menu:

It's difficult to merge graphic menu with text menu, as graphic mode provide more features. Graphic menu can use a style config file to control the drawing of windows, while in text menu, there is really not much option available, so we just hard-coded the drawing in the module.

3. Highly configurable

After we seperate the above function from normal.mod, we have a highly configurable system. We can select the component we wanted in grub-mkimage. What's more, as there is a basic line based scanner, we can use it to setup the initial environment, like locating root using uuid, setup parameter for serial console, and so on. This feature looks like the preset menu in grub legacy.

It also works well in embedded environment. For example, if we want to use grub2 to boot directly, there is no need to include the interface components. Also, if we have included advanced console in core.img, there is no need for basic console.

Signature · 1 line
Bean
#4 lore raw
In reply to Bean
Quoted 118 lines · On Thu, 17 Jul 2008 11:24:23 +0800 Bean <[email protected]> wrote:
Quoted 117 lines · Bean

Hi,

First of all, we can still keep rescue and normal command. But instead of depending on normal.mod, normal command depends on module arg, which is an option parser. Also, these two type of commands are of the same command set. In fact, module arg is implemented as a pre parser, which goes through the list of arguments and extract the options. In the case of rescue command, the pre parser field is null, which means it wants to parse options itself.

Then, I think of a new structure to represent all configurable handlers of grub. Different types of handler have different fields, but they all share a command header:

struct grub_handler
{
.next,
.name,
.init,
.fini
};

Same type of handlers are linked together. We first define an enum to list all types. For example:

enum {
GRUB_HANDLER_INPUT,
GRUB_HANDLER_OUTPUT,
GRUB_HANDLER_CONSOLE,
GRUB_HANDLER_MENU,
GRUB_HANDLER_SCRIPT,
GRUB_HANDLER_NUM
};

Then, we define an array to point to the head of handler linked
list: grub_handler[GRUB_HANDLER_NUM];

Head is the default selection. When we insert a new handler module, it would automatically become the new default, although we can switch back to old handler using a command.

Here are more details about different handlers:

input:
This is the input component of terminal:

struct grub_handler_input
{
.next,
.name,
.init,
.fini,
.checkkey,
.getkey
.flags,
};

output:
This is the output component of terminal:

struct grub_handler_output
{
.next,
.name,
.init,
.fini,
.putchar,
.getcharwidth,
.getxy,
.gotoxy,
.cls,
.setcolorstate,
.setcursor,
.flags,
};

console interface:
It represent the grub console, users type commands and execute them line by line.

struct grub_handler_console
{
.next,
.name,
.init,
.fini,
.run
};

menu interface:
It represent the menu, users select a menu item and execute it.

struct grub_handler_menu
{
.next,
.name,
.init,
.fini,
.run
};

script engine:
It's responsible for parsing config file to get the menu list, and execution of commands.

struct grub_handler_script
{
.next,
.name,
.init,
.fini,
.readconfig
.getmenu
.execute
};

Quoted 8 lines
Quoted 6 lines

The handlers are independent of each other. When they need something, they called specific function of the default handler. For example, to read a key from the console, we can use grub_handler[GRUB_HANDLER_INPUT]->getkey. Also, to get the list of items to be displayed on screen, the menu handler can call grub_handler[GRUB_HANDLER_SCRIPT]->getmenu.

Any comment for this idea ?

I like the idea, especially the idea of separating the script engine and menu loading code from the character-terminal-based menu system.

I wonder whether it would be better just to have separate variables for the different handler types like

struct grub_handler_input grub_handler_input;
struct grub_handler_output grub_handler_output;
struct grub_handler_console grub_handler_console;

instead of an array indexed by a constant representing the type, for the following reasons:

1. You would have to use casting to be able to call the functions in the handler other than the common 4 (next, name, init, fini). For instance, you couldn't do grub_handler[GRUB_HANDLER_INPUT]->getkey()
since the type of grub_handler is struct grub_handler[].

2. If we did use casting for each call to a handler, it is more error prone since we would not get compiler type checking and could accidentally write GRUB_HANDLER_INPUT when we meant GRUB_HANDLER_OUTPUT with obvious consequences.

3. It is more code to write to do
grub_handler[GRUB_HANDLER_INPUT]->getkey()
instead of
grub_handler_input->getkey()

Now, suppose we did define grub_handler_input, grub_handler_output, etc. Then if there were a reason to iterate over all types of handlers, or treat handlers generically for some other reason, we could certainly also create and array of pointers to the handlers for that purpose:

extern struct grub_handler *grub_handlers[GRUB_HANDLER_NUM]; extern const char *grub_handler_types[GRUB_HANDLER_NUM];

void print_current_handlers (void)
{
int i;
for (i = 0; i < GRUB_HANDLER_NUM; i++)
grub_printf ("handler for %s: %s\n",
grub_handler_types[i],
grub_handlers[i]);
}

We would then have to make sure the list of all handlers was kept in sync with the separate variables. This would mean a little more code for each handler type (a global "set current handler" function for each) but we would probably rarely add a new handler type so it would not be a great burden. I don't see a need for this iteration over all handlers, anyway.

Regards,
Colin

author
#5 lore raw
Quoted 178 lines · Colin D Bennett
Quoted 118 lines · On Thu, 17 Jul 2008 11:24:23 +0800 Bean <[email protected]> wrote:
Quoted 117 lines · Bean

Hi,

First of all, we can still keep rescue and normal command. But instead of depending on normal.mod, normal command depends on module arg, which is an option parser. Also, these two type of commands are of the same command set. In fact, module arg is implemented as a pre parser, which goes through the list of arguments and extract the options. In the case of rescue command, the pre parser field is null, which means it wants to parse options itself.

Then, I think of a new structure to represent all configurable handlers of grub. Different types of handler have different fields, but they all share a command header:

struct grub_handler
{
.next,
.name,
.init,
.fini
};

Same type of handlers are linked together. We first define an enum to list all types. For example:

enum {
GRUB_HANDLER_INPUT,
GRUB_HANDLER_OUTPUT,
GRUB_HANDLER_CONSOLE,
GRUB_HANDLER_MENU,
GRUB_HANDLER_SCRIPT,
GRUB_HANDLER_NUM
};

Then, we define an array to point to the head of handler linked
list: grub_handler[GRUB_HANDLER_NUM];

Head is the default selection. When we insert a new handler module, it would automatically become the new default, although we can switch back to old handler using a command.

Here are more details about different handlers:

input:
This is the input component of terminal:

struct grub_handler_input
{
.next,
.name,
.init,
.fini,
.checkkey,
.getkey
.flags,
};

output:
This is the output component of terminal:

struct grub_handler_output
{
.next,
.name,
.init,
.fini,
.putchar,
.getcharwidth,
.getxy,
.gotoxy,
.cls,
.setcolorstate,
.setcursor,
.flags,
};

console interface:
It represent the grub console, users type commands and execute them line by line.

struct grub_handler_console
{
.next,
.name,
.init,
.fini,
.run
};

menu interface:
It represent the menu, users select a menu item and execute it.

struct grub_handler_menu
{
.next,
.name,
.init,
.fini,
.run
};

script engine:
It's responsible for parsing config file to get the menu list, and execution of commands.

struct grub_handler_script
{
.next,
.name,
.init,
.fini,
.readconfig
.getmenu
.execute
};

Quoted 8 lines
Quoted 6 lines

The handlers are independent of each other. When they need something, they called specific function of the default handler. For example, to read a key from the console, we can use grub_handler[GRUB_HANDLER_INPUT]->getkey. Also, to get the list of items to be displayed on screen, the menu handler can call grub_handler[GRUB_HANDLER_SCRIPT]->getmenu.

Any comment for this idea ?

I like the idea, especially the idea of separating the script engine and menu loading code from the character-terminal-based menu system.

I wonder whether it would be better just to have separate variables for the different handler types like

struct grub_handler_input grub_handler_input;
struct grub_handler_output grub_handler_output;
struct grub_handler_console grub_handler_console;

instead of an array indexed by a constant representing the type, for the following reasons:

1. You would have to use casting to be able to call the functions in the handler other than the common 4 (next, name, init, fini). For instance, you couldn't do grub_handler[GRUB_HANDLER_INPUT]->getkey()
since the type of grub_handler is struct grub_handler[].

2. If we did use casting for each call to a handler, it is more error prone since we would not get compiler type checking and could accidentally write GRUB_HANDLER_INPUT when we meant GRUB_HANDLER_OUTPUT with obvious consequences.

3. It is more code to write to do
grub_handler[GRUB_HANDLER_INPUT]->getkey()
instead of
grub_handler_input->getkey()

Now, suppose we did define grub_handler_input, grub_handler_output, etc. Then if there were a reason to iterate over all types of handlers, or treat handlers generically for some other reason, we could certainly also create and array of pointers to the handlers for that purpose:

extern struct grub_handler *grub_handlers[GRUB_HANDLER_NUM]; extern const char *grub_handler_types[GRUB_HANDLER_NUM];

void print_current_handlers (void)
{
int i;
for (i = 0; i < GRUB_HANDLER_NUM; i++)
grub_printf ("handler for %s: %s\n",

                 grub_handler_types[i],
                 grub_handlers[i]);
}
Quoted 6 lines

We would then have to make sure the list of all handlers was kept in sync with the separate variables. This would mean a little more code for each handler type (a global "set current handler" function for each) but we would probably rarely add a new handler type so it would not be a great burden. I don't see a need for this iteration over all handlers, anyway.

Hi,

I like the idea. In fact, I hate using cast, it makes the code ugly.

Also, we can use generic code to handle them, define a structure like this:

{
{ "input", &grub_handler_input_head},
{ "output", &grub_handler_output_head},
{0, 0}
};

As the first few fields of handler is the same, we can use casting to access them.

Signature · 1 line
Bean
#6 lore raw
In reply to Bean

Hi,

Quoted 7 lines · Bean

First of all, we can still keep rescue and normal command. But instead of depending on normal.mod, normal command depends on module arg, which is an option parser. Also, these two type of commands are of the same command set. In fact, module arg is implemented as a pre parser, which goes through the list of arguments and extract the options. In the case of rescue command, the pre parser field is null, which means it wants to parse options itself.

pre parser?

Quoted 3 lines

Then, I think of a new structure to represent all configurable handlers of grub. Different types of handler have different fields, but they all share a command header:

What is a handler and what are its responsibilities?

Quoted 46 lines

struct grub_handler
{
.next,
.name,
.init,
.fini
};

Same type of handlers are linked together. We first define an enum to list all types. For example:

enum {
GRUB_HANDLER_INPUT,
GRUB_HANDLER_OUTPUT,
GRUB_HANDLER_CONSOLE,
GRUB_HANDLER_MENU,
GRUB_HANDLER_SCRIPT,
GRUB_HANDLER_NUM
};

Then, we define an array to point to the head of handler linked list:
grub_handler[GRUB_HANDLER_NUM];

Head is the default selection. When we insert a new handler module, it would automatically become the new default, although we can switch back to old handler using a command.

Here are more details about different handlers:

input:
This is the input component of terminal:

struct grub_handler_input
{
.next,
.name,
.init,
.fini,
.checkkey,
.getkey
.flags,
};

output:
This is the output component of terminal:

Quoted 15 lines

struct grub_handler_output
{
.next,
.name,
.init,
.fini,
.putchar,
.getcharwidth,
.getxy,
.gotoxy,
.cls,
.setcolorstate,
.setcursor,
.flags,
};

Sometimes the input and output are tightly coupled. How do you want to handle this?

Quoted 29 lines

console interface:
It represent the grub console, users type commands and execute them line by line.

struct grub_handler_console
{
.next,
.name,
.init,
.fini,
.run
};

menu interface:
It represent the menu, users select a menu item and execute it.

struct grub_handler_menu
{
.next,
.name,
.init,
.fini,
.run
};

script engine:
It's responsible for parsing config file to get the menu list, and execution of commands.

Quoted 10 lines

struct grub_handler_script
{
.next,
.name,
.init,
.fini,
.readconfig
.getmenu
.execute
};

What I had in mind was a twofold. I wrote a parser part that actually parses the script and code to manage the AST and to execute it. It would be easy to extend the current design with other languages. Although I think we should not add more than one to SVN, otherwise it will become bloated.

Quoted 6 lines

The handlers are independent of each other. When they need something, they called specific function of the default handler. For example, to read a key from the console, we can use grub_handler[GRUB_HANDLER_INPUT]->getkey. Also, to get the list of items to be displayed on screen, the menu handler can call grub_handler[GRUB_HANDLER_SCRIPT]->getmenu.

How does this differ from what we have now? You can register all kinds of objects and deregister them.

--
Marco

author
#7 lore raw
Quoted 12 lines · Marco Gerards

Hi,

Quoted 7 lines · Bean

First of all, we can still keep rescue and normal command. But instead of depending on normal.mod, normal command depends on module arg, which is an option parser. Also, these two type of commands are of the same command set. In fact, module arg is implemented as a pre parser, which goes through the list of arguments and extract the options. In the case of rescue command, the pre parser field is null, which means it wants to parse options itself.

Quoted 1 line

pre parser?

Maybe not the best word, the idea is that normal command is just like rescue command, except that it goes through an extra parser that convert options to grub_arg_list.

Quoted 6 lines
Quoted 4 lines

Then, I think of a new structure to represent all configurable handlers of grub. Different types of handler have different fields, but they all share a command header:

What is a handler and what are its responsibilities?

Actually, handler is a genetic term. For terminal, there is grub_term. For video, there is grub_video_adapter. They're similar in operation. For example, there can have multiple objects, but only one is active, they all have basic field like init, fini, next, name. They can be handled by the same function. I also extend this concept to other objects, like script engine, console and menu interface.

Quoted 63 lines
Quoted 47 lines

struct grub_handler
{
.next,
.name,
.init,
.fini
};

Same type of handlers are linked together. We first define an enum to list all types. For example:

enum {
GRUB_HANDLER_INPUT,
GRUB_HANDLER_OUTPUT,
GRUB_HANDLER_CONSOLE,
GRUB_HANDLER_MENU,
GRUB_HANDLER_SCRIPT,
GRUB_HANDLER_NUM
};

Then, we define an array to point to the head of handler linked list:
grub_handler[GRUB_HANDLER_NUM];

Head is the default selection. When we insert a new handler module, it would automatically become the new default, although we can switch back to old handler using a command.

Here are more details about different handlers:

input:
This is the input component of terminal:

struct grub_handler_input
{
.next,
.name,
.init,
.fini,
.checkkey,
.getkey
.flags,
};

output:
This is the output component of terminal:

Quoted 15 lines

struct grub_handler_output
{
.next,
.name,
.init,
.fini,
.putchar,
.getcharwidth,
.getxy,
.gotoxy,
.cls,
.setcolorstate,
.setcursor,
.flags,
};

Quoted 2 lines

Sometimes the input and output are tightly coupled. How do you want to handle this?

Some module can export both input and output handler, like serial. But some only export input (like atkeyboard), or output (gfxterm).

Quoted 41 lines
Quoted 30 lines

console interface:
It represent the grub console, users type commands and execute them line by line.

struct grub_handler_console
{
.next,
.name,
.init,
.fini,
.run
};

menu interface:
It represent the menu, users select a menu item and execute it.

struct grub_handler_menu
{
.next,
.name,
.init,
.fini,
.run
};

script engine:
It's responsible for parsing config file to get the menu list, and execution of commands.

Quoted 10 lines

struct grub_handler_script
{
.next,
.name,
.init,
.fini,
.readconfig
.getmenu
.execute
};

Quoted 5 lines

What I had in mind was a twofold. I wrote a parser part that actually parses the script and code to manage the AST and to execute it. It would be easy to extend the current design with other languages. Although I think we should not add more than one to SVN, otherwise it will become bloated.

Right, but actually, there are already two script engine existing. One is the normal bash-like parser, another is the command line scanner in the rescue mode.

Quoted 10 lines
Quoted 7 lines

The handlers are independent of each other. When they need something, they called specific function of the default handler. For example, to read a key from the console, we can use grub_handler[GRUB_HANDLER_INPUT]->getkey. Also, to get the list of items to be displayed on screen, the menu handler can call grub_handler[GRUB_HANDLER_SCRIPT]->getmenu.

How does this differ from what we have now? You can register all kinds of objects and deregister them.

Yes, handler is just objects, but they share common fields, so that we can handle them together, other than writing different code for different object.

Signature · 1 line
Bean
#8 lore raw

Hi,

Quoted 13 lines · Bean
Quoted 12 lines · Marco Gerards

Hi,

Quoted 7 lines · Bean

First of all, we can still keep rescue and normal command. But instead of depending on normal.mod, normal command depends on module arg, which is an option parser. Also, these two type of commands are of the same command set. In fact, module arg is implemented as a pre parser, which goes through the list of arguments and extract the options. In the case of rescue command, the pre parser field is null, which means it wants to parse options itself.

Quoted 5 lines
Quoted 1 line

pre parser?

Maybe not the best word, the idea is that normal command is just like rescue command, except that it goes through an extra parser that convert options to grub_arg_list.

Sorry, but I still don't understand this. Do you propose:
svn move normal/arg.c kern/arg.c

?

If you propose a stripped down argument parser, how do arguments parsers differ amongst each other?

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

Then, I think of a new structure to represent all configurable handlers of grub. Different types of handler have different fields, but they all share a command header:

Quoted 8 lines
Quoted 1 line

What is a handler and what are its responsibilities?

Actually, handler is a genetic term. For terminal, there is grub_term. For video, there is grub_video_adapter. They're similar in operation. For example, there can have multiple objects, but only one is active, they all have basic field like init, fini, next, name. They can be handled by the same function. I also extend this concept to other objects, like script engine, console and menu interface.

Right...

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

struct grub_handler
{
.next,
.name,
.init,
.fini
};

Same type of handlers are linked together. We first define an enum to list all types. For example:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

enum {
GRUB_HANDLER_INPUT,
GRUB_HANDLER_OUTPUT,
GRUB_HANDLER_CONSOLE,
GRUB_HANDLER_MENU,
GRUB_HANDLER_SCRIPT,
GRUB_HANDLER_NUM
};

Seems ok to me.

Although what if we want additional handlers. Like image readers or so? We do not need to centralize this. What about this:

handler.c:

grub_handler_t
grub_handler_add (const char *name)
{
...
}

grub_err_t
grub_handler_remove (const char *name)
{
...
if (module uses handler)
return grub_error (...);
...
}

/* NAME is the name of the handler, HANDLER the handler struct. */ grub_err_t
grub_handler_register (const char *name, grub_handler_t handler) {
...
}

/* NAME is the name of the handler, HANDLER the handler struct. */ grub_err_t
grub_handler_deregister (const char *name, grub_handler_t handler) {
...
}

/* HANDLER the handler struct. Hook the hook function. */ grub_err_t
grub_handler_register (grub_handler_t handler,
int (*hook) (grub_handler_t handler))
{
...
}

handler.h:

struct grub_handler
{
struct grub_handler *next;
const char *name;
};

#define GRUB_CREATE_HANDLER_H(name, interfaces) \
grub_err_t grub_##name##_register (struct grub_##name##_handler h);

(same for the other functions)

#define GRUB_CREATE_HANDLER_FUNCS(name, interfaces) \
grub_err_t \
grub_##name##_register (struct grub_##name##_handler h); \
{ \
grub_handler_register (name, &h->handler);
}

(same for other functions)

So the handler framework is opaque to the user. The user just works with this like it works now. For example:

foo.h:

struct grub_foo
{
/* This is *required*. */
grub_handler_t handle;

/* Every FOO needs to foo. */
int (*foo) (int bar);
};

GRUB_CREATE_HANDLER_T ("foo", struct grub_foo);

this creates all prototypes

foo.c:

GRUB_CREATE_HANDLER ("foo", struct grub_foo);

this creates functions that are very light and are mainly there to cast the structs back and forth so we can do type checking and get sane warnings and maximal cleaness. Furthermore, users can now use:

grub_foo_register (...);

^^ Every foo can register itself

grub_foo_iterate (...);

^^ You can iterate over every foo

The only "weird" thing is that when you register a handler, you have to know its name. For example disk.c would do:

{
err = grub_handler_add ("disk");
...
}

So as a summary:

grub_handler_add will be used to add new handler lists, grub_handler_remove will remove them

grub_handler_register will register specific handlers (like disk handlers), a macro can be used to add a wrapper that passes along the name. grub_handler_register can fill in the mandatory member "handle" such that later on the name is not required anymore. Requiring strings only at register time is not very expensive.

Sorry for the crappy code, but hopefully you get the idea, otherwise I can hack a bit or comment on your patches :-)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Then, we define an array to point to the head of handler linked list:
grub_handler[GRUB_HANDLER_NUM];

Right. Although what I proposed above you do not need an array, but you can register anything for free :-)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Head is the default selection. When we insert a new handler module, it would automatically become the new default, although we can switch back to old handler using a command.

Are you sure this is the right way to go? This needs more feedback from other people, I think...?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Here are more details about different handlers:

input:
This is the input component of terminal:

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

struct grub_handler_input
{
.next,
.name,
.init,
.fini,
.checkkey,
.getkey
.flags,
};

This is what we had, right?

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

output:
This is the output component of terminal:

struct grub_handler_output
{
.next,
.name,
.init,
.fini,
.putchar,
.getcharwidth,
.getxy,
.gotoxy,
.cls,
.setcolorstate,
.setcursor,
.flags,
};

Quoted 5 lines
Quoted 2 lines

Sometimes the input and output are tightly coupled. How do you want to handle this?

Some module can export both input and output handler, like serial. But some only export input (like atkeyboard), or output (gfxterm).

Okay...

Quoted 46 lines
Quoted 40 lines
Quoted 29 lines

console interface:
It represent the grub console, users type commands and execute them line by line.

struct grub_handler_console
{
.next,
.name,
.init,
.fini,
.run
};

menu interface:
It represent the menu, users select a menu item and execute it.

struct grub_handler_menu
{
.next,
.name,
.init,
.fini,
.run
};

script engine:
It's responsible for parsing config file to get the menu list, and execution of commands.

Quoted 10 lines

struct grub_handler_script
{
.next,
.name,
.init,
.fini,
.readconfig
.getmenu
.execute
};

Quoted 5 lines

What I had in mind was a twofold. I wrote a parser part that actually parses the script and code to manage the AST and to execute it. It would be easy to extend the current design with other languages. Although I think we should not add more than one to SVN, otherwise it will become bloated.

Quoted 3 lines

Right, but actually, there are already two script engine existing. One is the normal bash-like parser, another is the command line scanner in the rescue mode.

Ah, right.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

The handlers are independent of each other. When they need something, they called specific function of the default handler. For example, to read a key from the console, we can use grub_handler[GRUB_HANDLER_INPUT]->getkey. Also, to get the list of items to be displayed on screen, the menu handler can call grub_handler[GRUB_HANDLER_SCRIPT]->getmenu.

Quoted 6 lines
Quoted 2 lines

How does this differ from what we have now? You can register all kinds of objects and deregister them.

Yes, handler is just objects, but they share common fields, so that we can handle them together, other than writing different code for different object.

Right, I agree with this.

--
Marco

author
#9 lore raw
Quoted 23 lines · Marco Gerards

Hi,

Quoted 13 lines · Bean
Quoted 12 lines · Marco Gerards

Hi,

Quoted 7 lines · Bean

First of all, we can still keep rescue and normal command. But instead of depending on normal.mod, normal command depends on module arg, which is an option parser. Also, these two type of commands are of the same command set. In fact, module arg is implemented as a pre parser, which goes through the list of arguments and extract the options. In the case of rescue command, the pre parser field is null, which means it wants to parse options itself.

Quoted 5 lines
Quoted 1 line

pre parser?

Maybe not the best word, the idea is that normal command is just like rescue command, except that it goes through an extra parser that convert options to grub_arg_list.

Quoted 8 lines

Sorry, but I still don't understand this. Do you propose:
svn move normal/arg.c kern/arg.c

?

If you propose a stripped down argument parser, how do arguments parsers differ amongst each other?

Actually, no need to move normal/arg.c to kernel, it can be a standalone module. Normal command depend on it, while rescue command don't.

there is only one argument parser, it's job is to scan the argument for options like -f, --file and convert them to grub_arg_list, so that the command handler don't have to parse option itself.

Quoted 120 lines

Seems ok to me.

Although what if we want additional handlers. Like image readers or so? We do not need to centralize this. What about this:

handler.c:

grub_handler_t
grub_handler_add (const char *name)
{
...
}

grub_err_t
grub_handler_remove (const char *name)
{
...
if (module uses handler)
return grub_error (...);
...
}

/* NAME is the name of the handler, HANDLER the handler struct. */ grub_err_t
grub_handler_register (const char *name, grub_handler_t handler) {
...
}

/* NAME is the name of the handler, HANDLER the handler struct. */ grub_err_t
grub_handler_deregister (const char *name, grub_handler_t handler) {
...
}

/* HANDLER the handler struct. Hook the hook function. */ grub_err_t
grub_handler_register (grub_handler_t handler,
int (*hook) (grub_handler_t handler))
{
...
}

handler.h:

struct grub_handler
{
struct grub_handler *next;
const char *name;
};

#define GRUB_CREATE_HANDLER_H(name, interfaces) \
grub_err_t grub_##name##_register (struct grub_##name##_handler h);

(same for the other functions)

#define GRUB_CREATE_HANDLER_FUNCS(name, interfaces) \
grub_err_t \
grub_##name##_register (struct grub_##name##_handler h); \
{ \
grub_handler_register (name, &h->handler);
}

(same for other functions)

So the handler framework is opaque to the user. The user just works with this like it works now. For example:

foo.h:

struct grub_foo
{
/* This is *required*. */
grub_handler_t handle;

/* Every FOO needs to foo. */
int (*foo) (int bar);
};

GRUB_CREATE_HANDLER_T ("foo", struct grub_foo);

this creates all prototypes

foo.c:

GRUB_CREATE_HANDLER ("foo", struct grub_foo);

this creates functions that are very light and are mainly there to cast the structs back and forth so we can do type checking and get sane warnings and maximal cleaness. Furthermore, users can now use:

grub_foo_register (...);

^^ Every foo can register itself

grub_foo_iterate (...);

^^ You can iterate over every foo

The only "weird" thing is that when you register a handler, you have to know its name. For example disk.c would do:

{
err = grub_handler_add ("disk");
...
}

So as a summary:

grub_handler_add will be used to add new handler lists, grub_handler_remove will remove them

Quoted 9 lines

grub_handler_register will register specific handlers (like disk handlers), a macro can be used to add a wrapper that passes along the name. grub_handler_register can fill in the mandatory member "handle" such that later on the name is not required anymore. Requiring strings only at register time is not very expensive.

Sorry for the crappy code, but hopefully you get the idea, otherwise I can hack a bit or comment on your patches :-)

Your idea seems fine, but there is a slightly efficiency issue. For example, when we need to call a function in the handler, we need to acquire it using name. We need to do this in every call, as the handler could be changed next time.

My suggestion is to use function pointer instead of name, for example,

grub_handler_register (&grub_handler_input_head, my_handler);

Then we can always use grub_handler_input_head->getkey() to read a key.

The drawback is that we need to define grub_handler_**_head as global variable.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Then, we define an array to point to the head of handler linked list:
grub_handler[GRUB_HANDLER_NUM];

Right. Although what I proposed above you do not need an array, but you can register anything for free :-)

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Head is the default selection. When we insert a new handler module, it would automatically become the new default, although we can switch back to old handler using a command.

Are you sure this is the right way to go? This needs more feedback from other people, I think...?

This is used to save handler switching command. Normally, when we push a new handler, we want to use it right away. Although this behavior is up for discussion ...

Signature · 1 line
Bean
author
#10 lore raw
Quoted 5 lines · Bean

Your idea seems fine, but there is a slightly efficiency issue. For example, when we need to call a function in the handler, we need to acquire it using name. We need to do this in every call, as the handler could be changed next time.

Quoted 8 lines

My suggestion is to use function pointer instead of name, for example,

grub_handler_register (&grub_handler_input_head, my_handler);

Then we can always use grub_handler_input_head->getkey() to read a key.

The drawback is that we need to define grub_handler_**_head as global variable.

Hi,

Ok, I come up with a mixed solution. We can still register handler using string, like this:

grub_handler_register ("input", my_input_handler);

We don't need grub_handler_add. Whenever it sees a new string, grub_handler_register would create a item in the handler table.

To get the handler, we use:

grub_get_handler ("input", &local_input_handler_head);

The handler is managed as linked list, the head always points to current selection, so we can use local_input_handler_head to call the handler function.

To reduce unnecessary grub_get_handler calls, we export important handler head as global variable, for example, we can use the following in grub_main:

grub_get_handler ("input", &grub_input_handler_head); grub_get_handler ("output", &grub_output_handler_head);
...

Other modules can use grub_input_handler_head directly to access input handlers, but for custom handler such as "foo", they need to use grub_get_handler to get the handler pointer.

Signature · 1 line
Bean
#11 lore raw
In reply to Marco Gerards

Marco Gerards <[email protected]> writes:

[...]

Quoted 2 lines

Although what if we want additional handlers. Like image readers or so? We do not need to centralize this. What about this:

[...]

Here is a patch to register and deal with handlers. It decentralizes handlers and should remove some maintainance burden and boring code duplication. Please tell me what you think of this.

Okuji, can you please comment on this, as this is important, it changes all core functionality eventually.

--
Marco

2008-07-22 Marco Gerards <[email protected]>

* conf/i386-efi.rmk (grub_emu_SOURCES): Add `kern/handler.c'. (kernel_img_SOURCES): Likewise. (grub_setup_SOURCES): Likewise. (kernel_mod_HEADERS): Add handler.h.

* conf/common.rmk (grub_probe_SOURCES): Add `kern/handler.c'. (grub_fstest_SOURCES): Likewise.

* conf/i386-efi.rmk (grub_emu_SOURCES): Add kern/handler.c'. (kernel_mod_SOURCES): Likewise. (kernel_mod_HEADERS): Add handler.h'.

* conf/x86_64-efi.rmk (grub_emu_SOURCES): Add kern/handler.c'. (kernel_mod_SOURCES): Likewise. (kernel_mod_HEADERS): Add handler.h'.

* conf/powerpc-ieee1275.rmk (kernel_elf_HEADERS): Add handler.h'. (grub_emu_SOURCES): Add kern/handler.c'. (kernel_elf_SOURCES): Likewise.

* conf/i386-coreboot.rmk (kernel_elf_HEADERS): Add `handler.h'. (grub_emu_SOURCES): Add kern/handler.c (kernel_elf_SOURCES): Likewise.

* conf/sparc64-ieee1275.rmk (kernel_elf_HEADERS): Add `handler.h'. (kernel_elf_SOURCES): Likewise.

* conf/i386-ieee1275.rmk (kernel_elf_HEADERS): Add handler.h'. (grub_emu_SOURCES): Add kern/handler.c'. (kernel_elf_SOURCES): Likewise.

* kern/fs.c: Register fs handler using GRUB_HANDLER_CREATE_C. (grub_fs_list): Removed.
(grub_fs_register): Likewise. (grub_fs_unregister): Likewise.
(grub_fs_iterate): Likewise.

* kern/handler.c: New file.

* include/grub/handler.h: Likewise.

* include/grub/fs.h: Include <grub/handler.h>. Create handler using GRUB_HANDLER_CREATE_H_KERNEL.
(grub_fs): Removed members name' and next'. Use GRUB_HANDLER_CREATE_STRUCT to recreate these members. (grub_fs_t): Removed.

common.rmk +3 -3
Index: conf/common.rmk
===================================================================
@@ -14,7 +14,7 @@ grub_probe_SOURCES = util/grub-probe.c	\
 	fs/ufs.c fs/xfs.c fs/afs.c				\
 	\
 	partmap/pc.c partmap/apple.c partmap/gpt.c 		\
-	kern/fs.c kern/env.c fs/fshelp.c			\
+	kern/fs.c kern/env.c kern/handler.c fs/fshelp.c		\
 	disk/lvm.c disk/raid.c grub_probe_init.c
 
 ifeq ($(enable_grub_fstest), yes)
@@ -34,8 +34,8 @@ grub_fstest_SOURCES = util/grub-fstest.c
 	fs/ufs.c fs/xfs.c fs/afs.c					\
 	\
 	kern/partition.c partmap/pc.c partmap/apple.c partmap/gpt.c 	\
-	kern/fs.c kern/env.c fs/fshelp.c disk/lvm.c disk/raid.c	\
-	grub_fstest_init.c
+	kern/handler.c kern/fs.c kern/env.c fs/fshelp.c disk/lvm.c 	\
+	disk/raid.c grub_fstest_init.c
 
 # For the parser.
 grub_script.tab.c grub_script.tab.h: normal/parser.y
i386-pc.rmk +6 -5
Index: conf/i386-pc.rmk
===================================================================
@@ -40,14 +40,14 @@ cdboot_img_LDFLAGS = $(COMMON_LDFLAGS) -
 
 # For kernel.img.
 kernel_img_SOURCES = kern/i386/pc/startup.S kern/main.c kern/device.c \
-	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
+	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c kern/handler.c \
 	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
 	kern/i386/dl.c kern/i386/pc/init.c kern/parser.c kern/partition.c \
 	kern/env.c \
 	term/i386/pc/console.c \
 	symlist.c
 kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
-	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+	env.h err.h file.h fs.h handler.h kernel.h loader.h misc.h mm.h net.h parser.h \
 	partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
 	machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \
 	machine/memory.h machine/loader.h machine/vga.h machine/vbe.h machine/kernel.h
@@ -87,8 +87,9 @@ util/i386/pc/grub-mkimage.c_DEPENDENCIES
 util/i386/pc/grub-setup.c_DEPENDENCIES = grub_setup_init.h
 grub_setup_SOURCES = util/i386/pc/grub-setup.c util/biosdisk.c	\
 	util/misc.c util/getroot.c kern/device.c kern/disk.c	\
-	kern/err.c kern/misc.c kern/parser.c kern/partition.c	\
-	kern/file.c kern/fs.c kern/env.c fs/fshelp.c		\
+	kern/err.c kern/handler.c kern/misc.c kern/parser.c	\
+	kern/partition.c kern/file.c kern/fs.c kern/env.c	\
+	fs/fshelp.c						\
 	\
 	fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c		\
 	fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c	\
@@ -118,7 +119,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	\
 	io/gzio.c							\
 	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
-	kern/err.c							\
+	kern/err.c kern/handler.c					\
 	normal/execute.c kern/file.c kern/fs.c normal/lexer.c 		\
 	kern/loader.c kern/main.c kern/misc.c kern/parser.c		\
 	grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c	\
i386-efi.rmk +3 -3
Index: conf/i386-efi.rmk
===================================================================
@@ -48,7 +48,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	\
 	io/gzio.c							\
 	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
-	kern/err.c							\
+	kern/err.c kern/handler.c					\
 	normal/execute.c kern/file.c kern/fs.c normal/lexer.c 		\
 	kern/loader.c kern/main.c kern/misc.c kern/parser.c		\
 	grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c	\
@@ -80,13 +80,13 @@ pkglib_MODULES = kernel.mod normal.mod _
 # For kernel.mod.
 kernel_mod_EXPORTS = no
 kernel_mod_SOURCES = kern/i386/efi/startup.S kern/main.c kern/device.c \
-	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
+	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c kern/handler.c \
 	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
 	kern/i386/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \
 	kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \
 	term/efi/console.c disk/efi/efidisk.c
 kernel_mod_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
-	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+	env.h err.h handler.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
 	partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
 	efi/efi.h efi/time.h efi/disk.h
 kernel_mod_CFLAGS = $(COMMON_CFLAGS)
x86_64-efi.rmk +3 -3
Index: conf/x86_64-efi.rmk
===================================================================
@@ -50,7 +50,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	\
 	io/gzio.c							\
 	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
-	kern/err.c							\
+	kern/err.c kern/handler.c					\
 	normal/execute.c kern/file.c kern/fs.c normal/lexer.c 		\
 	kern/loader.c kern/main.c kern/misc.c kern/parser.c		\
 	grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c	\
@@ -83,13 +83,13 @@ pkglib_MODULES = kernel.mod normal.mod _
 kernel_mod_EXPORTS = no
 kernel_mod_SOURCES = kern/x86_64/efi/startup.S kern/x86_64/efi/callwrap.S \
 	kern/main.c kern/device.c \
-	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
+	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c kern/handler.c \
 	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
 	kern/x86_64/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \
 	kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \
 	term/efi/console.c disk/efi/efidisk.c
 kernel_mod_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
-	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+	env.h err.h handler.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
 	partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
 	efi/efi.h efi/time.h efi/disk.h machine/loader.h
 kernel_mod_CFLAGS = $(COMMON_CFLAGS)
powerpc-ieee1275.rmk +7 -6
Index: conf/powerpc-ieee1275.rmk
===================================================================
@@ -14,7 +14,7 @@ MOSTLYCLEANFILES += symlist.c kernel_sym
 DEFSYMFILES += kernel_syms.lst
 
 kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
-	env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \
+	env.h err.h file.h fs.h handler.h kernel.h misc.h mm.h net.h parser.h rescue.h \
 	symbol.h term.h time.h types.h powerpc/libgcc.h loader.h partition.h \
 	pc_partition.h ieee1275/ieee1275.h machine/kernel.h
 
@@ -59,7 +59,8 @@ grub_emu_SOURCES = commands/boot.c comma
 	\
 	io/gzio.c							\
 	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
-	kern/err.c kern/file.c kern/fs.c kern/loader.c kern/main.c	\
+	kern/err.c kern/file.c kern/fs.c kern/handler.c kern/loader.c	\
+	kern/main.c							\
 	kern/misc.c kern/parser.c kern/partition.c kern/rescue.c	\
 	kern/term.c fs/fshelp.c						\
 	normal/arg.c normal/cmdline.c normal/command.c			\
@@ -80,10 +81,10 @@ grub_emu_LDFLAGS = $(LIBCURSES)
 
 kernel_elf_SOURCES = kern/powerpc/ieee1275/crt0.S kern/ieee1275/cmain.c \
 	kern/ieee1275/ieee1275.c kern/main.c kern/device.c 		\
-	kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c 		\
-	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c 	\
-	kern/ieee1275/init.c term/ieee1275/ofconsole.c 		\
-	kern/ieee1275/openfw.c disk/ieee1275/ofdisk.c 		\
+	kern/disk.c kern/dl.c kern/err.c kern/handler.c kern/file.c	\
+	kern/fs.c kern/misc.c kern/mm.c kern/loader.c kern/rescue.c	\
+	kern/term.c kern/ieee1275/init.c term/ieee1275/ofconsole.c	\
+	kern/ieee1275/openfw.c disk/ieee1275/ofdisk.c 			\
 	kern/parser.c kern/partition.c kern/env.c kern/powerpc/dl.c 	\
 	symlist.c kern/powerpc/cache.S
 kernel_elf_HEADERS = grub/powerpc/ieee1275/ieee1275.h
i386-coreboot.rmk +3 -3
Index: conf/i386-coreboot.rmk
===================================================================
@@ -14,7 +14,7 @@ pkglib_PROGRAMS = kernel.elf
 kernel_elf_SOURCES = kern/i386/linuxbios/startup.S kern/i386/linuxbios/init.c \
 	kern/i386/linuxbios/table.c \
 	kern/main.c kern/device.c \
-	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
+	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c kern/handler.c \
 	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
 	kern/i386/dl.c kern/parser.c kern/partition.c \
 	kern/env.c \
@@ -22,7 +22,7 @@ kernel_elf_SOURCES = kern/i386/linuxbios
 	term/i386/pc/at_keyboard.c term/i386/pc/vga_text.c \
 	symlist.c
 kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
-	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+	env.h err.h file.h fs.h handler.h kernel.h loader.h misc.h mm.h net.h parser.h \
 	partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
 	machine/boot.h machine/console.h machine/init.h \
 	machine/memory.h machine/loader.h
@@ -72,7 +72,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	fs/fshelp.c							\
 	io/gzio.c							\
 	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
-	kern/err.c							\
+	kern/err.c kern/handler.c					\
 	normal/execute.c kern/file.c kern/fs.c normal/lexer.c 		\
 	kern/loader.c kern/main.c kern/misc.c kern/parser.c		\
 	grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c	\
sparc64-ieee1275.rmk +2 -2
Index: conf/sparc64-ieee1275.rmk
===================================================================
@@ -14,7 +14,7 @@ MOSTLYCLEANFILES += symlist.c kernel_sym
 DEFSYMFILES += kernel_syms.lst
 
 kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
-	env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \
+	env.h err.h handler.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \
 	symbol.h term.h time.h types.h sparc64/libgcc.h loader.h partition.h \
 	pc_partition.h ieee1275/ieee1275.h machine/kernel.h
 
@@ -69,7 +69,7 @@ grub_emu_LDFLAGS = $(LIBCURSES)
 
 kernel_elf_SOURCES = kern/sparc64/ieee1275/init.c kern/ieee1275/ieee1275.c \
 	kern/main.c kern/device.c kern/disk.c kern/dl.c kern/file.c \
-	kern/fs.c kern/err.c kern/misc.c kern/mm.c kern/loader.c \
+	kern/fs.c kern/err.c kern/handler.c kern/misc.c kern/mm.c kern/loader.c \
 	kern/rescue.c kern/term.c term/ieee1275/ofconsole.c \
 	kern/sparc64/ieee1275/openfw.c disk/ieee1275/ofdisk.c \
 	kern/partition.c kern/env.c kern/sparc64/dl.c symlist.c \
i386-ieee1275.rmk +3 -3
Index: conf/i386-ieee1275.rmk
===================================================================
@@ -18,13 +18,13 @@ kernel_elf_SOURCES = kern/i386/ieee1275/
 	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
 	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
 	kern/i386/dl.c kern/parser.c kern/partition.c \
-	kern/env.c \
+	kern/env.c kern/handler.c \
 	kern/ieee1275/ieee1275.c \
 	term/ieee1275/ofconsole.c term/i386/pc/at_keyboard.c \
 	disk/ieee1275/ofdisk.c \
 	symlist.c
 kernel_elf_HEADERS = arg.h cache.h device.h disk.h dl.h elf.h elfload.h \
-	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+	env.h err.h file.h fs.h handler.h kernel.h loader.h misc.h mm.h net.h parser.h \
 	partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
 	ieee1275/ieee1275.h machine/kernel.h machine/loader.h machine/memory.h
 kernel_elf_CFLAGS = $(COMMON_CFLAGS)
@@ -74,7 +74,7 @@ grub_emu_SOURCES = commands/boot.c comma
 	fs/fshelp.c							\
 	io/gzio.c							\
 	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
-	kern/err.c							\
+	kern/err.c kern/handler.c					\
 	normal/execute.c kern/file.c kern/fs.c normal/lexer.c 		\
 	kern/loader.c kern/main.c kern/misc.c kern/parser.c		\
 	grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c	\
fs.c +1 -31
Index: kern/fs.c
===================================================================
@@ -27,39 +27,9 @@
 #include <grub/mm.h>
 #include <grub/term.h>
 
-static grub_fs_t grub_fs_list;
-
 grub_fs_autoload_hook_t grub_fs_autoload_hook = 0;
 
-void
-grub_fs_register (grub_fs_t fs)
-{
-  fs->next = grub_fs_list;
-  grub_fs_list = fs;
-}
-
-void
-grub_fs_unregister (grub_fs_t fs)
-{
-  grub_fs_t *p, q;
-
-  for (p = &grub_fs_list, q = *p; q; p = &(q->next), q = q->next)
-    if (q == fs)
-      {
-	*p = q->next;
-	break;
-      }
-}
-
-void
-grub_fs_iterate (int (*hook) (const grub_fs_t fs))
-{
-  grub_fs_t p;
-
-  for (p = grub_fs_list; p; p = p->next)
-    if (hook (p))
-      break;
-}
+GRUB_HANDLER_CREATE_C (fs, grub_fs);
 
 grub_fs_t
 grub_fs_probe (grub_device_t device)
handler.c +56 -0

56 lines not on this page · raw message

grub/fs.h +4 -6
Index: include/grub/fs.h
===================================================================
@@ -23,6 +23,7 @@
 #include <grub/device.h>
 #include <grub/symbol.h>
 #include <grub/types.h>
+#include <grub/handler.h>
 
 /* Forward declaration is required, because of mutual reference.  */
 struct grub_file;
@@ -30,8 +31,7 @@ struct grub_file;
 /* Filesystem descriptor.  */
 struct grub_fs
 {
-  /* My name.  */
-  const char *name;
+  GRUB_HANDLER_CREATE_STRUCT(fs, grub_fs);
 
   /* Call HOOK with each file under DIR.  */
   grub_err_t (*dir) (grub_device_t device, const char *path,
@@ -55,11 +55,9 @@ struct grub_fs
      returned in a grub_malloc'ed buffer and should be freed by the
      caller.  */
   grub_err_t (*uuid) (grub_device_t device, char **uuid);
-
-  /* The next filesystem.  */
-  struct grub_fs *next;
 };
-typedef struct grub_fs *grub_fs_t;
+
+GRUB_HANDLER_CREATE_H_KERNEL(fs, grub_fs);
 
 /* This is special, because block lists are not files in usual sense.  */
 extern struct grub_fs grub_fs_blocklist;
grub/handler.h +100 -0

100 lines not on this page · raw message