1 |
/* chainloader.c - boot another boot loader */ |
/* chainloader.c - boot another boot loader */ |
2 |
/* |
/* |
3 |
* GRUB -- GRand Unified Bootloader |
* GRUB -- GRand Unified Bootloader |
4 |
* Copyright (C) 2002 Free Software Foundation, Inc. |
* Copyright (C) 2002,2004 Free Software Foundation, Inc. |
5 |
* |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
20 |
|
|
21 |
#include <grub/loader.h> |
#include <grub/loader.h> |
22 |
#include <grub/machine/loader.h> |
#include <grub/machine/loader.h> |
23 |
|
#include <grub/machine/chainloader.h> |
24 |
#include <grub/file.h> |
#include <grub/file.h> |
25 |
#include <grub/err.h> |
#include <grub/err.h> |
26 |
#include <grub/device.h> |
#include <grub/device.h> |
83 |
} |
} |
84 |
|
|
85 |
void |
void |
86 |
grub_rescue_cmd_chainloader (int argc, char *argv[]) |
grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags) |
87 |
{ |
{ |
88 |
grub_file_t file = 0; |
grub_file_t file = 0; |
89 |
grub_uint16_t signature; |
grub_uint16_t signature; |
|
int force = 0; |
|
90 |
|
|
91 |
grub_dl_ref (my_mod); |
grub_dl_ref (my_mod); |
92 |
|
|
93 |
if (argc > 0 && grub_strcmp (argv[0], "--force") == 0) |
file = grub_file_open (filename); |
|
{ |
|
|
force = 1; |
|
|
argc--; |
|
|
argv++; |
|
|
} |
|
|
|
|
|
if (argc == 0) |
|
|
{ |
|
|
grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified"); |
|
|
goto fail; |
|
|
} |
|
|
|
|
|
file = grub_file_open (argv[0]); |
|
94 |
if (! file) |
if (! file) |
95 |
goto fail; |
goto fail; |
96 |
|
|
106 |
|
|
107 |
/* Check the signature. */ |
/* Check the signature. */ |
108 |
signature = *((grub_uint16_t *) (0x7C00 + GRUB_DISK_SECTOR_SIZE - 2)); |
signature = *((grub_uint16_t *) (0x7C00 + GRUB_DISK_SECTOR_SIZE - 2)); |
109 |
if (signature != grub_le_to_cpu16 (0xaa55) && ! force) |
if (signature != grub_le_to_cpu16 (0xaa55) |
110 |
|
&& ! (flags & GRUB_CHAINLOADER_FORCE)) |
111 |
{ |
{ |
112 |
grub_error (GRUB_ERR_BAD_OS, "invalid signature"); |
grub_error (GRUB_ERR_BAD_OS, "invalid signature"); |
113 |
goto fail; |
goto fail; |
125 |
grub_dl_unref (my_mod); |
grub_dl_unref (my_mod); |
126 |
} |
} |
127 |
|
|
128 |
|
static void |
129 |
|
grub_rescue_cmd_chainloader (int argc, char *argv[]) |
130 |
|
{ |
131 |
|
grub_chainloader_flags_t flags = 0; |
132 |
|
|
133 |
|
if (argc > 0 && grub_strcmp (argv[0], "--force") == 0) |
134 |
|
{ |
135 |
|
flags |= GRUB_CHAINLOADER_FORCE; |
136 |
|
argc--; |
137 |
|
argv++; |
138 |
|
} |
139 |
|
|
140 |
|
if (argc == 0) |
141 |
|
grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified"); |
142 |
|
else |
143 |
|
grub_chainloader_cmd (argv[0], flags); |
144 |
|
} |
145 |
|
|
146 |
static const char loader_name[] = "chainloader"; |
static const char loader_name[] = "chainloader"; |
147 |
|
|
148 |
GRUB_MOD_INIT |
GRUB_MOD_INIT |