Next: , Previous: Filesystem interface, Up: Internals


D.4 The generic interface for built-ins

GRUB built-in commands are defined in a uniformal interface, whether they are menu-specific or can be used anywhere. The definition of a builtin command consists of two parts: the code itself and the table of the information.

The code must be a function which takes two arguments, a command-line string and flags, and returns an `int' value. The flags argument specifies how the function is called, using a bit mask. The return value must be zero if successful, otherwise non-zero. So it is normally enough to return errnum.

The table of the information is represented by the structure struct builtin, which contains the name of the command, a pointer to the function, flags, a short description of the command and a long description of the command. Since the descriptions are used only for help messages interactively, you don't have to define them, if the command may not be called interactively (such as title).

The table is finally registered in the table builtin_table, so that run_script and enter_cmdline can find the command. See the files cmdline.c and builtins.c, for more details.