Rewrite grub-install, grub-mkrescue, grub-mkstandalone and grub-mknetdir
the function of these files exceeds what can be sanely handled in shell in posix-comaptible way. Also writing it in C extends the functionality to non-UNIX-like OS and minimal environments.
This commit is contained in:
parent
9ef81064a3
commit
cd46aa6cef
52 changed files with 5811 additions and 2101 deletions
48
include/grub/emu/config.h
Normal file
48
include/grub/emu/config.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2013 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/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_CONFIG_EMU_HEADER
|
||||
#define GRUB_CONFIG_EMU_HEADER 1
|
||||
|
||||
#include <grub/disk.h>
|
||||
#include <grub/partition.h>
|
||||
#include <grub/emu/hostfile.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const char *
|
||||
grub_util_get_config_filename (void);
|
||||
const char *
|
||||
grub_util_get_pkgdatadir (void);
|
||||
const char *
|
||||
grub_util_get_pkglibdir (void);
|
||||
const char *
|
||||
grub_util_get_localedir (void);
|
||||
|
||||
struct grub_util_config
|
||||
{
|
||||
int is_cryptodisk_enabled;
|
||||
char *grub_distributor;
|
||||
};
|
||||
|
||||
void
|
||||
grub_util_load_config (struct grub_util_config *cfg);
|
||||
|
||||
void
|
||||
grub_util_parse_config (FILE *f, struct grub_util_config *cfg, int simple);
|
||||
|
||||
#endif
|
|
@ -20,8 +20,10 @@
|
|||
#define GRUB_UTIL_GETROOT_HEADER 1
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/device.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
enum grub_dev_abstraction_types {
|
||||
GRUB_DEV_ABSTRACTION_NONE,
|
||||
|
@ -89,4 +91,14 @@ grub_util_get_grub_dev_os (const char *os_dev);
|
|||
grub_disk_addr_t
|
||||
grub_util_find_partition_start_os (const char *dev);
|
||||
|
||||
char *
|
||||
grub_util_guess_bios_drive (const char *orig_path);
|
||||
char *
|
||||
grub_util_guess_efi_drive (const char *orig_path);
|
||||
char *
|
||||
grub_util_guess_baremetal_drive (const char *orig_path);
|
||||
void
|
||||
grub_util_fprint_full_disk_name (FILE *f,
|
||||
const char *drive, grub_device_t dev);
|
||||
|
||||
#endif /* ! GRUB_UTIL_GETROOT_HEADER */
|
||||
|
|
|
@ -31,6 +31,11 @@ grub_util_is_special_file (const char *path);
|
|||
int
|
||||
grub_util_is_regular (const char *path);
|
||||
|
||||
char *
|
||||
grub_util_path_concat (size_t n, ...);
|
||||
char *
|
||||
grub_util_path_concat_ext (size_t n, ...);
|
||||
|
||||
int
|
||||
grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off);
|
||||
ssize_t
|
||||
|
@ -49,5 +54,13 @@ EXPORT_FUNC(grub_util_fd_close) (grub_util_fd_t fd);
|
|||
|
||||
grub_uint64_t
|
||||
grub_util_get_fd_size (grub_util_fd_t fd, const char *name, unsigned *log_secsize);
|
||||
char *
|
||||
grub_util_make_temporary_file (void);
|
||||
char *
|
||||
grub_util_make_temporary_dir (void);
|
||||
void
|
||||
grub_util_unlink_recursive (const char *name);
|
||||
grub_uint32_t
|
||||
grub_util_get_mtime (const char *name);
|
||||
|
||||
#endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */
|
||||
|
|
39
include/grub/osdep/exec_unix.h
Normal file
39
include/grub/osdep/exec_unix.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2013 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/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_EMU_EXEC_H
|
||||
#define GRUB_EMU_EXEC_H 1
|
||||
|
||||
#include <config.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
pid_t
|
||||
grub_util_exec_pipe (const char *const *argv, int *fd);
|
||||
pid_t
|
||||
grub_util_exec_pipe_stderr (const char *const *argv, int *fd);
|
||||
|
||||
int
|
||||
grub_util_exec (const char *const *argv);
|
||||
int
|
||||
grub_util_exec_redirect (const char *const *argv, const char *stdin_file,
|
||||
const char *stdout_file);
|
||||
int
|
||||
grub_util_exec_redirect_null (const char *const *argv);
|
||||
|
||||
#endif
|
|
@ -50,6 +50,12 @@ grub_util_fd_readdir (grub_util_fd_dir_t dirp)
|
|||
return readdir (dirp);
|
||||
}
|
||||
|
||||
static inline int
|
||||
grub_util_rmdir (const char *pathname)
|
||||
{
|
||||
return rmdir (pathname);
|
||||
}
|
||||
|
||||
static inline int
|
||||
grub_util_unlink (const char *pathname)
|
||||
{
|
||||
|
@ -62,7 +68,7 @@ grub_util_rename (const char *from, const char *to)
|
|||
return rename (from, to);
|
||||
}
|
||||
|
||||
#define grub_util_mkdir(a) mkdir (a)
|
||||
#define grub_util_mkdir(a) mkdir (a, 0700)
|
||||
|
||||
struct grub_util_fd
|
||||
{
|
||||
|
@ -86,7 +92,7 @@ enum grub_util_fd_open_flags_t
|
|||
GRUB_UTIL_FD_O_RDONLY = O_RDONLY,
|
||||
GRUB_UTIL_FD_O_WRONLY = O_WRONLY,
|
||||
GRUB_UTIL_FD_O_RDWR = O_RDWR,
|
||||
GRUB_UTIL_FD_O_CREAT = O_CREAT,
|
||||
GRUB_UTIL_FD_O_CREATTRUNC = O_CREAT | O_TRUNC,
|
||||
GRUB_UTIL_FD_O_SYNC = (0
|
||||
#ifdef O_SYNC
|
||||
| O_SYNC
|
||||
|
|
|
@ -59,6 +59,12 @@ grub_util_unlink (const char *pathname)
|
|||
return unlink (pathname);
|
||||
}
|
||||
|
||||
static inline int
|
||||
grub_util_rmdir (const char *pathname)
|
||||
{
|
||||
return rmdir (pathname);
|
||||
}
|
||||
|
||||
static inline int
|
||||
grub_util_rename (const char *from, const char *to)
|
||||
{
|
||||
|
|
|
@ -55,6 +55,9 @@ grub_util_fd_closedir (grub_util_fd_dir_t dirp);
|
|||
grub_util_fd_dirent_t
|
||||
grub_util_fd_readdir (grub_util_fd_dir_t dirp);
|
||||
|
||||
int
|
||||
grub_util_rmdir (const char *pathname);
|
||||
|
||||
enum grub_util_fd_open_flags_t
|
||||
{
|
||||
GRUB_UTIL_FD_O_RDONLY = 1,
|
||||
|
|
|
@ -26,6 +26,104 @@
|
|||
#include <grub/disk.h>
|
||||
#include <grub/emu/hostfile.h>
|
||||
|
||||
#define GRUB_INSTALL_OPTIONS \
|
||||
{ "modules", GRUB_INSTALL_OPTIONS_MODULES, N_("MODULES"), \
|
||||
0, N_("pre-load specified modules MODULES"), 1 }, \
|
||||
{ "install-modules", GRUB_INSTALL_OPTIONS_INSTALL_MODULES, \
|
||||
N_("MODULES"), 0, \
|
||||
N_("install only MODULES and their dependencies [default=all]"), 1 }, \
|
||||
{ "themes", GRUB_INSTALL_OPTIONS_INSTALL_THEMES, N_("THEMES"), \
|
||||
0, N_("install THEMES [default=%s]"), 1 }, \
|
||||
{ "fonts", GRUB_INSTALL_OPTIONS_INSTALL_FONTS, N_("FONTS"), \
|
||||
0, N_("install FONTS [default=%s]"), 1 }, \
|
||||
{ "locales", GRUB_INSTALL_OPTIONS_INSTALL_LOCALES, N_("LOCALES"),\
|
||||
0, N_("install only LOCALES [default=all]"), 1 }, \
|
||||
{ "compress", GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS, \
|
||||
"no,xz,gz,lzo", OPTION_ARG_OPTIONAL, \
|
||||
N_("compress GRUB files [optional]"), 1 }, \
|
||||
/* TRANSLATORS: platform here isn't identifier. It can be translated. */ \
|
||||
{ "directory", 'd', N_("DIR"), 0, \
|
||||
N_("use images and modules under DIR [default=%s/<platform>]"), 1 }, \
|
||||
{ "override-directory", GRUB_INSTALL_OPTIONS_DIRECTORY2, \
|
||||
N_("DIR"), OPTION_HIDDEN, \
|
||||
N_("use images and modules under DIR [default=%s/<platform>]"), 1 }, \
|
||||
{ "grub-mkimage", GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE, \
|
||||
"FILE", OPTION_HIDDEN, 0, 1 }, \
|
||||
/* TRANSLATORS: "embed" is a verb (command description). "*/ \
|
||||
{ "pubkey", 'k', N_("FILE"), 0, \
|
||||
N_("embed FILE as public key for signature checking"), 0}, \
|
||||
{ "verbose", 'v', 0, 0, \
|
||||
N_("increase verbosity"), 1 }
|
||||
|
||||
int
|
||||
grub_install_parse (int key, char *arg);
|
||||
|
||||
void
|
||||
grub_install_push_module (const char *val);
|
||||
|
||||
void
|
||||
grub_install_pop_module (void);
|
||||
|
||||
char *
|
||||
grub_install_help_filter (int key, const char *text,
|
||||
void *input __attribute__ ((unused)));
|
||||
|
||||
enum grub_install_plat
|
||||
{
|
||||
GRUB_INSTALL_PLATFORM_I386_PC,
|
||||
GRUB_INSTALL_PLATFORM_I386_EFI,
|
||||
GRUB_INSTALL_PLATFORM_I386_QEMU,
|
||||
GRUB_INSTALL_PLATFORM_I386_COREBOOT,
|
||||
GRUB_INSTALL_PLATFORM_I386_MULTIBOOT,
|
||||
GRUB_INSTALL_PLATFORM_I386_IEEE1275,
|
||||
GRUB_INSTALL_PLATFORM_X86_64_EFI,
|
||||
GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON,
|
||||
GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275,
|
||||
GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275,
|
||||
GRUB_INSTALL_PLATFORM_MIPSEL_ARC,
|
||||
GRUB_INSTALL_PLATFORM_MIPS_ARC,
|
||||
GRUB_INSTALL_PLATFORM_IA64_EFI,
|
||||
GRUB_INSTALL_PLATFORM_ARM_UBOOT,
|
||||
GRUB_INSTALL_PLATFORM_ARM_EFI,
|
||||
GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS,
|
||||
GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS,
|
||||
GRUB_INSTALL_PLATFORM_MAX
|
||||
};
|
||||
|
||||
enum grub_install_options {
|
||||
GRUB_INSTALL_OPTIONS_DIRECTORY = 'd',
|
||||
GRUB_INSTALL_OPTIONS_VERBOSITY = 'v',
|
||||
GRUB_INSTALL_OPTIONS_MODULES = 0x201,
|
||||
GRUB_INSTALL_OPTIONS_INSTALL_MODULES,
|
||||
GRUB_INSTALL_OPTIONS_INSTALL_THEMES,
|
||||
GRUB_INSTALL_OPTIONS_INSTALL_FONTS,
|
||||
GRUB_INSTALL_OPTIONS_INSTALL_LOCALES,
|
||||
GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS,
|
||||
GRUB_INSTALL_OPTIONS_DIRECTORY2,
|
||||
GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE
|
||||
};
|
||||
|
||||
extern char *grub_install_source_directory;
|
||||
|
||||
enum grub_install_plat
|
||||
grub_install_get_target (const char *src);
|
||||
void
|
||||
grub_install_mkdir_p (const char *dst);
|
||||
|
||||
void
|
||||
grub_install_copy_files (const char *src,
|
||||
const char *dst,
|
||||
enum grub_install_plat platid);
|
||||
char *
|
||||
grub_install_get_platform_name (enum grub_install_plat platid);
|
||||
|
||||
const char *
|
||||
grub_install_get_platform_cpu (enum grub_install_plat platid);
|
||||
|
||||
const char *
|
||||
grub_install_get_platform_platform (enum grub_install_plat platid);
|
||||
|
||||
|
||||
typedef enum {
|
||||
GRUB_COMPRESSION_AUTO,
|
||||
GRUB_COMPRESSION_NONE,
|
||||
|
@ -33,6 +131,25 @@ typedef enum {
|
|||
GRUB_COMPRESSION_LZMA
|
||||
} grub_compression_t;
|
||||
|
||||
void
|
||||
grub_install_make_image_wrap (const char *dir, const char *prefix,
|
||||
const char *outname, char *memdisk_path,
|
||||
char *config_path,
|
||||
const char *format, int note,
|
||||
grub_compression_t comp);
|
||||
void
|
||||
grub_install_make_image_wrap_file (const char *dir, const char *prefix,
|
||||
FILE *fp, const char *outname,
|
||||
char *memdisk_path,
|
||||
char *config_path,
|
||||
const char *mkimage_target, int note,
|
||||
grub_compression_t comp);
|
||||
|
||||
int
|
||||
grub_install_copy_file (const char *src,
|
||||
const char *dst,
|
||||
int is_critical);
|
||||
|
||||
struct grub_install_image_target_desc;
|
||||
|
||||
void
|
||||
|
@ -66,6 +183,32 @@ grub_install_get_image_targets_string (void);
|
|||
const char *
|
||||
grub_util_get_target_dirname (const struct grub_install_image_target_desc *t);
|
||||
|
||||
void
|
||||
grub_install_create_envblk_file (const char *name);
|
||||
|
||||
const char *
|
||||
grub_install_get_default_x86_platform (void);
|
||||
|
||||
void
|
||||
grub_install_register_efi (const char *efidir_disk, int efidir_part,
|
||||
const char *efifile_path,
|
||||
const char *efi_distributor);
|
||||
|
||||
void
|
||||
grub_install_register_ieee1275 (int is_prep, const char *install_device,
|
||||
int partno, const char *relpath);
|
||||
|
||||
void
|
||||
grub_install_sgi_setup (const char *install_device,
|
||||
const char *imgfile, const char *destname);
|
||||
|
||||
int
|
||||
grub_install_compress_gzip (const char *src, const char *dest);
|
||||
int
|
||||
grub_install_compress_lzop (const char *src, const char *dest);
|
||||
int
|
||||
grub_install_compress_xz (const char *src, const char *dest);
|
||||
|
||||
void
|
||||
grub_install_get_blocklist (grub_device_t root_dev,
|
||||
const char *core_path, const char *core_img,
|
||||
|
@ -89,4 +232,10 @@ grub_util_render_label (const char *label_font,
|
|||
const char *label_string,
|
||||
const char *label);
|
||||
|
||||
const char *
|
||||
grub_util_get_target_name (const struct grub_install_image_target_desc *t);
|
||||
|
||||
extern char *grub_install_copy_buffer;
|
||||
#define GRUB_INSTALL_COPY_BUFFER_SIZE 1048576
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue