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 |
|
|
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, |
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 |
|
|