51 |
#define MAX_EXTRA_INITRDS 16 /* code segment checked by --bootloader-probe */ |
#define MAX_EXTRA_INITRDS 16 /* code segment checked by --bootloader-probe */ |
52 |
#define CODE_SEG_SIZE 128 /* code segment checked by --bootloader-probe */ |
#define CODE_SEG_SIZE 128 /* code segment checked by --bootloader-probe */ |
53 |
|
|
54 |
|
#define NOOP_OPCODE 0x90 |
55 |
|
#define JMP_SHORT_OPCODE 0xeb |
56 |
|
|
57 |
/* comments get lumped in with indention */ |
/* comments get lumped in with indention */ |
58 |
struct lineElement { |
struct lineElement { |
59 |
char * item; |
char * item; |
2471 |
if (memcmp(boot, bootSect, 3)) |
if (memcmp(boot, bootSect, 3)) |
2472 |
return 0; |
return 0; |
2473 |
|
|
2474 |
if (boot[1] == 0xeb) { |
if (boot[1] == JMP_SHORT_OPCODE) { |
2475 |
offset = boot[2] + 2; |
offset = boot[2] + 2; |
2476 |
} else if (boot[1] == 0xe8 || boot[1] == 0xe9) { |
} else if (boot[1] == 0xe8 || boot[1] == 0xe9) { |
2477 |
offset = (boot[3] << 8) + boot[2] + 2; |
offset = (boot[3] << 8) + boot[2] + 2; |
2478 |
} else if (boot[0] == 0xeb) { |
} else if (boot[0] == JMP_SHORT_OPCODE) { |
2479 |
offset = boot[1] + 2; |
offset = boot[1] + 2; |
2480 |
|
/* |
2481 |
|
* it looks like grub, when copying stage1 into the mbr, patches stage1 |
2482 |
|
* right after the JMP location, replacing other instructions such as |
2483 |
|
* JMPs for NOOPs. So, relax the check a little bit by skipping those |
2484 |
|
* different bytes. |
2485 |
|
*/ |
2486 |
|
if ((bootSect[offset + 1] == NOOP_OPCODE) |
2487 |
|
&& (bootSect[offset + 2] == NOOP_OPCODE)) { |
2488 |
|
offset = offset + 3; |
2489 |
|
} |
2490 |
} else if (boot[0] == 0xe8 || boot[0] == 0xe9) { |
} else if (boot[0] == 0xe8 || boot[0] == 0xe9) { |
2491 |
offset = (boot[2] << 8) + boot[1] + 2; |
offset = (boot[2] << 8) + boot[1] + 2; |
2492 |
} else { |
} else { |
3160 |
struct singleEntry * template = NULL; |
struct singleEntry * template = NULL; |
3161 |
int copyDefault = 0, makeDefault = 0; |
int copyDefault = 0, makeDefault = 0; |
3162 |
int displayDefault = 0; |
int displayDefault = 0; |
3163 |
|
int displayDefaultIndex = 0; |
3164 |
struct poptOption options[] = { |
struct poptOption options[] = { |
3165 |
{ "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0, |
{ "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0, |
3166 |
_("add an entry for the specified kernel"), _("kernel-path") }, |
_("add an entry for the specified kernel"), _("kernel-path") }, |
3193 |
"template"), NULL }, |
"template"), NULL }, |
3194 |
{ "default-kernel", 0, 0, &displayDefault, 0, |
{ "default-kernel", 0, 0, &displayDefault, 0, |
3195 |
_("display the path of the default kernel") }, |
_("display the path of the default kernel") }, |
3196 |
|
{ "default-index", 0, 0, &displayDefaultIndex, 0, |
3197 |
|
_("display the index of the default kernel") }, |
3198 |
{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, |
{ "elilo", 0, POPT_ARG_NONE, &configureELilo, 0, |
3199 |
_("configure elilo bootloader") }, |
_("configure elilo bootloader") }, |
3200 |
{ "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0, |
{ "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0, |
3338 |
|
|
3339 |
if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion || |
if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion || |
3340 |
newKernelPath || removeKernelPath || makeDefault || |
newKernelPath || removeKernelPath || makeDefault || |
3341 |
defaultKernel)) { |
defaultKernel || displayDefaultIndex)) { |
3342 |
fprintf(stderr, _("grubby: --bootloader-probe may not be used with " |
fprintf(stderr, _("grubby: --bootloader-probe may not be used with " |
3343 |
"specified option")); |
"specified option")); |
3344 |
return 1; |
return 1; |
3381 |
defaultKernel = NULL; |
defaultKernel = NULL; |
3382 |
} |
} |
3383 |
|
|
3384 |
if (!strcmp(grubConfig, "-") && !outputFile) { |
if (grubConfig && !strcmp(grubConfig, "-") && !outputFile) { |
3385 |
fprintf(stderr, _("grubby: output file must be specified if stdin " |
fprintf(stderr, _("grubby: output file must be specified if stdin " |
3386 |
"is used\n")); |
"is used\n")); |
3387 |
return 1; |
return 1; |
3389 |
|
|
3390 |
if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel |
if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel |
3391 |
&& !kernelInfo && !bootloaderProbe && !updateKernelPath |
&& !kernelInfo && !bootloaderProbe && !updateKernelPath |
3392 |
&& !removeMBKernel) { |
&& !removeMBKernel && !displayDefaultIndex) { |
3393 |
fprintf(stderr, _("grubby: no action specified\n")); |
fprintf(stderr, _("grubby: no action specified\n")); |
3394 |
return 1; |
return 1; |
3395 |
} |
} |
3484 |
((rootspec != NULL) ? strlen(rootspec) : 0)); |
((rootspec != NULL) ? strlen(rootspec) : 0)); |
3485 |
|
|
3486 |
return 0; |
return 0; |
3487 |
|
|
3488 |
|
} else if (displayDefaultIndex) { |
3489 |
|
if (config->defaultImage == -1) return 0; |
3490 |
|
printf("%i\n", config->defaultImage); |
3491 |
|
|
3492 |
} else if (kernelInfo) |
} else if (kernelInfo) |
3493 |
return displayInfo(config, kernelInfo, bootPrefix); |
return displayInfo(config, kernelInfo, bootPrefix); |
3494 |
|
|