132 |
#define NEED_DEVTREE (1 << 6) |
#define NEED_DEVTREE (1 << 6) |
133 |
|
|
134 |
#define MAIN_DEFAULT (1 << 0) |
#define MAIN_DEFAULT (1 << 0) |
135 |
|
#define FIRST_ENTRY_INDEX 0 /* boot entry index value begin and increment |
136 |
|
from this initial value */ |
137 |
|
#define NO_DEFAULT_ENTRY -1 /* indicates that no specific default boot |
138 |
|
entry was set or currently exists */ |
139 |
#define DEFAULT_SAVED -2 |
#define DEFAULT_SAVED -2 |
140 |
#define DEFAULT_SAVED_GRUB2 -3 |
#define DEFAULT_SAVED_GRUB2 -3 |
141 |
|
|
1619 |
*end == ' ' || *end == '\t')) |
*end == ' ' || *end == '\t')) |
1620 |
end++; |
end++; |
1621 |
if (*end) |
if (*end) |
1622 |
cfg->defaultImage = -1; |
cfg->defaultImage = NO_DEFAULT_ENTRY; |
1623 |
} else if (defaultLine->numElements == 3) { |
} else if (defaultLine->numElements == 3) { |
1624 |
char *value = defaultLine->elements[2].item; |
char *value = defaultLine->elements[2].item; |
1625 |
while (*value && (*value == '"' || |
while (*value && (*value == '"' || |
1632 |
*end == ' ' || *end == '\t')) |
*end == ' ' || *end == '\t')) |
1633 |
end++; |
end++; |
1634 |
if (*end) |
if (*end) |
1635 |
cfg->defaultImage = -1; |
cfg->defaultImage = NO_DEFAULT_ENTRY; |
1636 |
} |
} |
1637 |
} else if (cfi->defaultSupportSaved && |
} else if (cfi->defaultSupportSaved && |
1638 |
!strncmp(defaultLine->elements[1].item, "saved", |
!strncmp(defaultLine->elements[1].item, "saved", |
1642 |
cfg->defaultImage = |
cfg->defaultImage = |
1643 |
strtol(defaultLine->elements[1].item, &end, 10); |
strtol(defaultLine->elements[1].item, &end, 10); |
1644 |
if (*end) |
if (*end) |
1645 |
cfg->defaultImage = -1; |
cfg->defaultImage = NO_DEFAULT_ENTRY; |
1646 |
} else if (defaultLine->numElements >= 2) { |
} else if (defaultLine->numElements >= 2) { |
1647 |
int i = 0; |
int i = 0; |
1648 |
while ((entry = findEntryByIndex(cfg, i))) { |
while ((entry = findEntryByIndex(cfg, i))) { |
1670 |
if (entry) { |
if (entry) { |
1671 |
cfg->defaultImage = i; |
cfg->defaultImage = i; |
1672 |
} else { |
} else { |
1673 |
cfg->defaultImage = -1; |
cfg->defaultImage = NO_DEFAULT_ENTRY; |
1674 |
} |
} |
1675 |
} |
} |
1676 |
} else if (cfg->cfi->defaultIsSaved && cfg->cfi->getEnv) { |
} else if (cfg->cfi->defaultIsSaved && cfg->cfi->getEnv) { |
1687 |
cfg->defaultImage = index; |
cfg->defaultImage = index; |
1688 |
} |
} |
1689 |
} else { |
} else { |
1690 |
cfg->defaultImage = 0; |
cfg->defaultImage = FIRST_ENTRY_INDEX; |
1691 |
} |
} |
1692 |
|
|
1693 |
return cfg; |
return cfg; |
1707 |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
1708 |
else if (cfg->cfi->defaultIsSaved) { |
else if (cfg->cfi->defaultIsSaved) { |
1709 |
fprintf(out, "%sset default=\"${saved_entry}\"\n", indent); |
fprintf(out, "%sset default=\"${saved_entry}\"\n", indent); |
1710 |
if (cfg->defaultImage >= 0 && cfg->cfi->setEnv) { |
if (cfg->defaultImage >= FIRST_ENTRY_INDEX && cfg->cfi->setEnv) { |
1711 |
char *title; |
char *title; |
1712 |
entry = findEntryByIndex(cfg, cfg->defaultImage); |
entry = findEntryByIndex(cfg, cfg->defaultImage); |
1713 |
line = getLineByType(LT_MENUENTRY, entry->lines); |
line = getLineByType(LT_MENUENTRY, entry->lines); |
1720 |
"saved_entry", title); |
"saved_entry", title); |
1721 |
} |
} |
1722 |
} |
} |
1723 |
} else if (cfg->defaultImage > -1) { |
} else if (cfg->defaultImage >= FIRST_ENTRY_INDEX) { |
1724 |
if (cfg->cfi->defaultIsIndex) { |
if (cfg->cfi->defaultIsIndex) { |
1725 |
if (cfg->cfi->defaultIsVariable) { |
if (cfg->cfi->defaultIsVariable) { |
1726 |
fprintf(out, "%sset default=\"%d\"\n", indent, |
fprintf(out, "%sset default=\"%d\"\n", indent, |
2424 |
} |
} |
2425 |
} |
} |
2426 |
} |
} |
2427 |
} else if (cfg->defaultImage > -1) { |
} else if (cfg->defaultImage >= FIRST_ENTRY_INDEX) { |
2428 |
entry = findEntryByIndex(cfg, cfg->defaultImage); |
entry = findEntryByIndex(cfg, cfg->defaultImage); |
2429 |
if (entry && suitableImage(entry, prefix, skipRemoved, flags)) { |
if (entry && suitableImage(entry, prefix, skipRemoved, flags)) { |
2430 |
if (indexPtr) |
if (indexPtr) |
2498 |
entry->skip = 1; |
entry->skip = 1; |
2499 |
} |
} |
2500 |
|
|
2501 |
void setDefaultImage(struct grubConfig *config, int hasNew, |
void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath, |
2502 |
const char *defaultKernelPath, int newIsDefault, |
const char *defaultKernelPath, int newBootEntryIsDefault, |
2503 |
const char *prefix, int flags, int index) |
const char *prefix, int flags, int newDefaultBootEntryIndex) |
2504 |
{ |
{ |
2505 |
struct singleEntry *entry, *entry2, *newDefault; |
struct singleEntry *entry, *entry2, *newDefault; |
2506 |
int i, j; |
int i, j; |
2507 |
|
|
2508 |
if (newIsDefault) { |
if (newBootEntryIsDefault) { |
2509 |
config->defaultImage = 0; |
config->defaultImage = FIRST_ENTRY_INDEX; |
2510 |
return; |
return; |
2511 |
} else if ((index >= 0) && config->cfi->defaultIsIndex) { |
} else if ((newDefaultBootEntryIndex >= 0) && config->cfi->defaultIsIndex) { |
2512 |
if (findEntryByIndex(config, index)) |
if (findEntryByIndex(config, newDefaultBootEntryIndex)) |
2513 |
config->defaultImage = index; |
config->defaultImage = newDefaultBootEntryIndex; |
2514 |
else |
else |
2515 |
config->defaultImage = -1; |
config->defaultImage = NO_DEFAULT_ENTRY; |
2516 |
return; |
return; |
2517 |
} else if (defaultKernelPath) { |
} else if (defaultKernelPath) { |
2518 |
i = 0; |
i = 0; |
2519 |
if (findEntryByPath(config, defaultKernelPath, prefix, &i)) { |
if (findEntryByPath(config, defaultKernelPath, prefix, &i)) { |
2520 |
config->defaultImage = i; |
config->defaultImage = i; |
2521 |
} else { |
} else { |
2522 |
config->defaultImage = -1; |
config->defaultImage = NO_DEFAULT_ENTRY; |
2523 |
return; |
return; |
2524 |
} |
} |
2525 |
} |
} |
2531 |
/* default is set to saved, we don't want to change it */ |
/* default is set to saved, we don't want to change it */ |
2532 |
return; |
return; |
2533 |
|
|
2534 |
if (config->defaultImage > -1) |
if (config->defaultImage >= FIRST_ENTRY_INDEX) |
2535 |
entry = findEntryByIndex(config, config->defaultImage); |
entry = findEntryByIndex(config, config->defaultImage); |
2536 |
else |
else |
2537 |
entry = NULL; |
entry = NULL; |
2538 |
|
|
2539 |
if (entry && !entry->skip) { |
if (entry && !entry->skip) { |
2540 |
/* we can preserve the default */ |
/* we can preserve the default */ |
2541 |
if (hasNew) |
if (isUserSpecifiedKernelPath) |
2542 |
config->defaultImage++; |
config->defaultImage++; |
2543 |
|
|
2544 |
/* count the number of entries erased before this one */ |
/* count the number of entries erased before this one */ |
2547 |
if (entry2->skip) |
if (entry2->skip) |
2548 |
config->defaultImage--; |
config->defaultImage--; |
2549 |
} |
} |
2550 |
} else if (hasNew) { |
} else if (isUserSpecifiedKernelPath) { |
2551 |
config->defaultImage = 0; |
config->defaultImage = FIRST_ENTRY_INDEX; |
2552 |
} else { |
} else { |
2553 |
/* Either we just erased the default (or the default line was |
/* Either we just erased the default (or the default line was |
2554 |
* bad to begin with) and didn't put a new one in. We'll use |
* bad to begin with) and didn't put a new one in. We'll use |
2557 |
findTemplate(config, prefix, &config->defaultImage, 1, |
findTemplate(config, prefix, &config->defaultImage, 1, |
2558 |
flags); |
flags); |
2559 |
if (!newDefault) |
if (!newDefault) |
2560 |
config->defaultImage = -1; |
config->defaultImage = NO_DEFAULT_ENTRY; |
2561 |
} |
} |
2562 |
} |
} |
2563 |
|
|
4214 |
const char *newKernelArgs, const char *newKernelInitrd, |
const char *newKernelArgs, const char *newKernelInitrd, |
4215 |
const char **extraInitrds, int extraInitrdCount, |
const char **extraInitrds, int extraInitrdCount, |
4216 |
const char *newMBKernel, const char *newMBKernelArgs, |
const char *newMBKernel, const char *newMBKernelArgs, |
4217 |
const char *newDevTreePath) |
const char *newDevTreePath, int newIndex) |
4218 |
{ |
{ |
4219 |
struct singleEntry *new; |
struct singleEntry *new, *entry, *prev = NULL; |
4220 |
struct singleLine *newLine = NULL, *tmplLine = NULL, *masterLine = NULL; |
struct singleLine *newLine = NULL, *tmplLine = NULL, *masterLine = NULL; |
4221 |
int needs; |
int needs; |
4222 |
|
char *indexs; |
4223 |
char *chptr; |
char *chptr; |
4224 |
|
int rc; |
4225 |
|
|
4226 |
if (!newKernelPath) |
if (!newKernelPath) |
4227 |
return 0; |
return 0; |
4228 |
|
|
4229 |
|
rc = asprintf(&indexs, "%d", newIndex); |
4230 |
|
if (rc < 0) |
4231 |
|
return 1; |
4232 |
|
|
4233 |
/* if the newKernelTitle is too long silently munge it into something |
/* if the newKernelTitle is too long silently munge it into something |
4234 |
* we can live with. truncating is first check, then we'll just mess with |
* we can live with. truncating is first check, then we'll just mess with |
4235 |
* it until it looks better */ |
* it until it looks better */ |
4252 |
new = malloc(sizeof(*new)); |
new = malloc(sizeof(*new)); |
4253 |
new->skip = 0; |
new->skip = 0; |
4254 |
new->multiboot = 0; |
new->multiboot = 0; |
|
new->next = config->entries; |
|
4255 |
new->lines = NULL; |
new->lines = NULL; |
4256 |
config->entries = new; |
entry = config->entries; |
4257 |
|
for (unsigned int i = 0; i < newIndex; i++) { |
4258 |
|
if (!entry) |
4259 |
|
break; |
4260 |
|
prev = entry; |
4261 |
|
entry = entry->next; |
4262 |
|
} |
4263 |
|
new->next = entry; |
4264 |
|
|
4265 |
|
if (prev) |
4266 |
|
prev->next = new; |
4267 |
|
else |
4268 |
|
config->entries = new; |
4269 |
|
|
4270 |
/* copy/update from the template */ |
/* copy/update from the template */ |
4271 |
needs = NEED_KERNEL | NEED_TITLE; |
needs = NEED_KERNEL | NEED_TITLE; |
4728 |
abort(); |
abort(); |
4729 |
} |
} |
4730 |
|
|
4731 |
if (updateImage(config, "0", prefix, newKernelArgs, NULL, |
if (updateImage(config, indexs, prefix, newKernelArgs, NULL, |
4732 |
newMBKernelArgs, NULL)) |
newMBKernelArgs, NULL)) |
4733 |
return 1; |
return 1; |
4734 |
|
|
4758 |
char *newDevTreePath = NULL; |
char *newDevTreePath = NULL; |
4759 |
char *newMBKernel = NULL; |
char *newMBKernel = NULL; |
4760 |
char *newMBKernelArgs = NULL; |
char *newMBKernelArgs = NULL; |
4761 |
|
int newIndex = 0; |
4762 |
char *removeMBKernelArgs = NULL; |
char *removeMBKernelArgs = NULL; |
4763 |
char *removeMBKernel = NULL; |
char *removeMBKernel = NULL; |
4764 |
char *bootPrefix = NULL; |
char *bootPrefix = NULL; |
4793 |
NULL}, |
NULL}, |
4794 |
{"boot-filesystem", 0, POPT_ARG_STRING, &bootPrefix, 0, |
{"boot-filesystem", 0, POPT_ARG_STRING, &bootPrefix, 0, |
4795 |
_ |
_ |
4796 |
("filestystem which contains /boot directory (for testing only)"), |
("filesystem which contains /boot directory (for testing only)"), |
4797 |
_("bootfs")}, |
_("bootfs")}, |
4798 |
#if defined(__i386__) || defined(__x86_64__) || defined (__powerpc64__) || defined (__ia64__) |
#if defined(__i386__) || defined(__x86_64__) || defined (__powerpc64__) || defined (__ia64__) |
4799 |
{"bootloader-probe", 0, POPT_ARG_NONE, &bootloaderProbe, 0, |
{"bootloader-probe", 0, POPT_ARG_NONE, &bootloaderProbe, 0, |
4865 |
{"set-default-index", 0, POPT_ARG_INT, &defaultIndex, 0, |
{"set-default-index", 0, POPT_ARG_INT, &defaultIndex, 0, |
4866 |
_("make the given entry index the default entry"), |
_("make the given entry index the default entry"), |
4867 |
_("entry-index")}, |
_("entry-index")}, |
4868 |
|
{"set-index", 0, POPT_ARG_INT, &newIndex, 0, |
4869 |
|
_("use the given index when creating a new entry"), |
4870 |
|
_("entry-index")}, |
4871 |
{"silo", 0, POPT_ARG_NONE, &configureSilo, 0, |
{"silo", 0, POPT_ARG_NONE, &configureSilo, 0, |
4872 |
_("configure silo bootloader")}, |
_("configure silo bootloader")}, |
4873 |
{"title", 0, POPT_ARG_STRING, &newKernelTitle, 0, |
{"title", 0, POPT_ARG_STRING, &newKernelTitle, 0, |
5182 |
struct singleEntry *entry; |
struct singleEntry *entry; |
5183 |
char *rootspec; |
char *rootspec; |
5184 |
|
|
5185 |
if (config->defaultImage == -1) |
if (config->defaultImage == NO_DEFAULT_ENTRY) |
5186 |
return 0; |
return 0; |
5187 |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
5188 |
cfi->defaultIsSaved) |
cfi->defaultIsSaved) |
5189 |
config->defaultImage = 0; |
config->defaultImage = FIRST_ENTRY_INDEX; |
5190 |
entry = findEntryByIndex(config, config->defaultImage); |
entry = findEntryByIndex(config, config->defaultImage); |
5191 |
if (!entry) |
if (!entry) |
5192 |
return 0; |
return 0; |
5209 |
struct singleLine *line; |
struct singleLine *line; |
5210 |
struct singleEntry *entry; |
struct singleEntry *entry; |
5211 |
|
|
5212 |
if (config->defaultImage == -1) |
if (config->defaultImage == NO_DEFAULT_ENTRY) |
5213 |
return 0; |
return 0; |
5214 |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
5215 |
cfi->defaultIsSaved) |
cfi->defaultIsSaved) |
5216 |
config->defaultImage = 0; |
config->defaultImage = FIRST_ENTRY_INDEX; |
5217 |
entry = findEntryByIndex(config, config->defaultImage); |
entry = findEntryByIndex(config, config->defaultImage); |
5218 |
if (!entry) |
if (!entry) |
5219 |
return 0; |
return 0; |
5243 |
return 0; |
return 0; |
5244 |
|
|
5245 |
} else if (displayDefaultIndex) { |
} else if (displayDefaultIndex) { |
5246 |
if (config->defaultImage == -1) |
if (config->defaultImage == NO_DEFAULT_ENTRY) |
5247 |
return 0; |
return 0; |
5248 |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
5249 |
cfi->defaultIsSaved) |
cfi->defaultIsSaved) |
5250 |
config->defaultImage = 0; |
config->defaultImage = FIRST_ENTRY_INDEX; |
5251 |
printf("%i\n", config->defaultImage); |
printf("%i\n", config->defaultImage); |
5252 |
return 0; |
return 0; |
5253 |
|
|
5283 |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
5284 |
newKernelTitle, newKernelArgs, newKernelInitrd, |
newKernelTitle, newKernelArgs, newKernelInitrd, |
5285 |
(const char **)extraInitrds, extraInitrdCount, |
(const char **)extraInitrds, extraInitrdCount, |
5286 |
newMBKernel, newMBKernelArgs, newDevTreePath)) |
newMBKernel, newMBKernelArgs, newDevTreePath, |
5287 |
|
newIndex)) |
5288 |
return 1; |
return 1; |
5289 |
|
|
5290 |
if (numEntries(config) == 0) { |
if (numEntries(config) == 0) { |