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 |
|
|
681 |
int fallbackImage; /* just like defaultImage */ |
int fallbackImage; /* just like defaultImage */ |
682 |
int flags; |
int flags; |
683 |
struct configFileInfo *cfi; |
struct configFileInfo *cfi; |
684 |
|
int isModified; /* assumes only one entry added |
685 |
|
per invocation of grubby */ |
686 |
}; |
}; |
687 |
|
|
688 |
blkid_cache blkid; |
blkid_cache blkid; |
1302 |
cfg->theLines = NULL; |
cfg->theLines = NULL; |
1303 |
cfg->entries = NULL; |
cfg->entries = NULL; |
1304 |
cfg->fallbackImage = 0; |
cfg->fallbackImage = 0; |
1305 |
|
cfg->isModified = 0; |
1306 |
|
|
1307 |
/* copy everything we have */ |
/* copy everything we have */ |
1308 |
while (*head) { |
while (*head) { |
1622 |
*end == ' ' || *end == '\t')) |
*end == ' ' || *end == '\t')) |
1623 |
end++; |
end++; |
1624 |
if (*end) |
if (*end) |
1625 |
cfg->defaultImage = -1; |
cfg->defaultImage = NO_DEFAULT_ENTRY; |
1626 |
} else if (defaultLine->numElements == 3) { |
} else if (defaultLine->numElements == 3) { |
1627 |
char *value = defaultLine->elements[2].item; |
char *value = defaultLine->elements[2].item; |
1628 |
while (*value && (*value == '"' || |
while (*value && (*value == '"' || |
1635 |
*end == ' ' || *end == '\t')) |
*end == ' ' || *end == '\t')) |
1636 |
end++; |
end++; |
1637 |
if (*end) |
if (*end) |
1638 |
cfg->defaultImage = -1; |
cfg->defaultImage = NO_DEFAULT_ENTRY; |
1639 |
} |
} |
1640 |
} else if (cfi->defaultSupportSaved && |
} else if (cfi->defaultSupportSaved && |
1641 |
!strncmp(defaultLine->elements[1].item, "saved", |
!strncmp(defaultLine->elements[1].item, "saved", |
1645 |
cfg->defaultImage = |
cfg->defaultImage = |
1646 |
strtol(defaultLine->elements[1].item, &end, 10); |
strtol(defaultLine->elements[1].item, &end, 10); |
1647 |
if (*end) |
if (*end) |
1648 |
cfg->defaultImage = -1; |
cfg->defaultImage = NO_DEFAULT_ENTRY; |
1649 |
} else if (defaultLine->numElements >= 2) { |
} else if (defaultLine->numElements >= 2) { |
1650 |
int i = 0; |
int i = 0; |
1651 |
while ((entry = findEntryByIndex(cfg, i))) { |
while ((entry = findEntryByIndex(cfg, i))) { |
1673 |
if (entry) { |
if (entry) { |
1674 |
cfg->defaultImage = i; |
cfg->defaultImage = i; |
1675 |
} else { |
} else { |
1676 |
cfg->defaultImage = -1; |
cfg->defaultImage = NO_DEFAULT_ENTRY; |
1677 |
} |
} |
1678 |
} |
} |
1679 |
} else if (cfg->cfi->defaultIsSaved && cfg->cfi->getEnv) { |
} else if (cfg->cfi->defaultIsSaved && cfg->cfi->getEnv) { |
1690 |
cfg->defaultImage = index; |
cfg->defaultImage = index; |
1691 |
} |
} |
1692 |
} else { |
} else { |
1693 |
cfg->defaultImage = 0; |
cfg->defaultImage = FIRST_ENTRY_INDEX; |
1694 |
} |
} |
1695 |
|
|
1696 |
return cfg; |
return cfg; |
1710 |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
1711 |
else if (cfg->cfi->defaultIsSaved) { |
else if (cfg->cfi->defaultIsSaved) { |
1712 |
fprintf(out, "%sset default=\"${saved_entry}\"\n", indent); |
fprintf(out, "%sset default=\"${saved_entry}\"\n", indent); |
1713 |
if (cfg->defaultImage >= 0 && cfg->cfi->setEnv) { |
if (cfg->defaultImage >= FIRST_ENTRY_INDEX && cfg->cfi->setEnv) { |
1714 |
char *title; |
char *title; |
1715 |
entry = findEntryByIndex(cfg, cfg->defaultImage); |
entry = findEntryByIndex(cfg, cfg->defaultImage); |
1716 |
line = getLineByType(LT_MENUENTRY, entry->lines); |
line = getLineByType(LT_MENUENTRY, entry->lines); |
1723 |
"saved_entry", title); |
"saved_entry", title); |
1724 |
} |
} |
1725 |
} |
} |
1726 |
} else if (cfg->defaultImage > -1) { |
} else if (cfg->defaultImage >= FIRST_ENTRY_INDEX) { |
1727 |
if (cfg->cfi->defaultIsIndex) { |
if (cfg->cfi->defaultIsIndex) { |
1728 |
if (cfg->cfi->defaultIsVariable) { |
if (cfg->cfi->defaultIsVariable) { |
1729 |
fprintf(out, "%sset default=\"%d\"\n", indent, |
fprintf(out, "%sset default=\"%d\"\n", indent, |
2427 |
} |
} |
2428 |
} |
} |
2429 |
} |
} |
2430 |
} else if (cfg->defaultImage > -1) { |
} else if (cfg->defaultImage >= FIRST_ENTRY_INDEX) { |
2431 |
entry = findEntryByIndex(cfg, cfg->defaultImage); |
entry = findEntryByIndex(cfg, cfg->defaultImage); |
2432 |
if (entry && suitableImage(entry, prefix, skipRemoved, flags)) { |
if (entry && suitableImage(entry, prefix, skipRemoved, flags)) { |
2433 |
if (indexPtr) |
if (indexPtr) |
2501 |
entry->skip = 1; |
entry->skip = 1; |
2502 |
} |
} |
2503 |
|
|
2504 |
void setDefaultImage(struct grubConfig *config, int hasNew, |
void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath, |
2505 |
const char *defaultKernelPath, int newIsDefault, |
const char *defaultKernelPath, int newBootEntryIsDefault, |
2506 |
const char *prefix, int flags, int index) |
const char *prefix, int flags, int newDefaultBootEntryIndex) |
2507 |
{ |
{ |
2508 |
struct singleEntry *entry, *entry2, *newDefault; |
struct singleEntry *entry, *entry2, *newDefault; |
2509 |
int i, j; |
int i, j; |
2510 |
|
|
2511 |
if (newIsDefault) { |
if (newBootEntryIsDefault) { |
2512 |
config->defaultImage = 0; |
config->defaultImage = FIRST_ENTRY_INDEX; |
2513 |
return; |
return; |
2514 |
} else if ((index >= 0) && config->cfi->defaultIsIndex) { |
} else if ((newDefaultBootEntryIndex >= 0) && config->cfi->defaultIsIndex) { |
2515 |
if (findEntryByIndex(config, index)) |
if (findEntryByIndex(config, newDefaultBootEntryIndex)) |
2516 |
config->defaultImage = index; |
config->defaultImage = newDefaultBootEntryIndex; |
2517 |
else |
else |
2518 |
config->defaultImage = -1; |
config->defaultImage = NO_DEFAULT_ENTRY; |
2519 |
return; |
return; |
2520 |
} else if (defaultKernelPath) { |
} else if (defaultKernelPath) { |
2521 |
i = 0; |
i = 0; |
2522 |
if (findEntryByPath(config, defaultKernelPath, prefix, &i)) { |
if (findEntryByPath(config, defaultKernelPath, prefix, &i)) { |
2523 |
config->defaultImage = i; |
config->defaultImage = i; |
2524 |
} else { |
} else { |
2525 |
config->defaultImage = -1; |
config->defaultImage = NO_DEFAULT_ENTRY; |
2526 |
return; |
return; |
2527 |
} |
} |
2528 |
} |
} |
2534 |
/* default is set to saved, we don't want to change it */ |
/* default is set to saved, we don't want to change it */ |
2535 |
return; |
return; |
2536 |
|
|
2537 |
if (config->defaultImage > -1) |
if (config->defaultImage >= FIRST_ENTRY_INDEX) |
2538 |
entry = findEntryByIndex(config, config->defaultImage); |
entry = findEntryByIndex(config, config->defaultImage); |
2539 |
else |
else |
2540 |
entry = NULL; |
entry = NULL; |
2541 |
|
|
2542 |
if (entry && !entry->skip) { |
if (entry && !entry->skip) { |
2543 |
/* we can preserve the default */ |
/* we can preserve the default */ |
2544 |
if (hasNew) |
if (isUserSpecifiedKernelPath) |
2545 |
config->defaultImage++; |
config->defaultImage++; |
2546 |
|
|
2547 |
/* count the number of entries erased before this one */ |
/* count the number of entries erased before this one */ |
2550 |
if (entry2->skip) |
if (entry2->skip) |
2551 |
config->defaultImage--; |
config->defaultImage--; |
2552 |
} |
} |
2553 |
} else if (hasNew) { |
} else if (isUserSpecifiedKernelPath) { |
2554 |
config->defaultImage = 0; |
config->defaultImage = FIRST_ENTRY_INDEX; |
2555 |
} else { |
} else { |
2556 |
/* Either we just erased the default (or the default line was |
/* Either we just erased the default (or the default line was |
2557 |
* 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 |
2560 |
findTemplate(config, prefix, &config->defaultImage, 1, |
findTemplate(config, prefix, &config->defaultImage, 1, |
2561 |
flags); |
flags); |
2562 |
if (!newDefault) |
if (!newDefault) |
2563 |
config->defaultImage = -1; |
config->defaultImage = NO_DEFAULT_ENTRY; |
2564 |
} |
} |
2565 |
} |
} |
2566 |
|
|
4732 |
} |
} |
4733 |
|
|
4734 |
if (updateImage(config, indexs, prefix, newKernelArgs, NULL, |
if (updateImage(config, indexs, prefix, newKernelArgs, NULL, |
4735 |
newMBKernelArgs, NULL)) |
newMBKernelArgs, NULL)) { |
4736 |
|
config->isModified = 1; |
4737 |
return 1; |
return 1; |
4738 |
|
} |
4739 |
|
|
4740 |
return 0; |
return 0; |
4741 |
} |
} |
5187 |
struct singleEntry *entry; |
struct singleEntry *entry; |
5188 |
char *rootspec; |
char *rootspec; |
5189 |
|
|
5190 |
if (config->defaultImage == -1) |
if (config->defaultImage == NO_DEFAULT_ENTRY) |
5191 |
return 0; |
return 0; |
5192 |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
5193 |
cfi->defaultIsSaved) |
cfi->defaultIsSaved) |
5194 |
config->defaultImage = 0; |
config->defaultImage = FIRST_ENTRY_INDEX; |
5195 |
entry = findEntryByIndex(config, config->defaultImage); |
entry = findEntryByIndex(config, config->defaultImage); |
5196 |
if (!entry) |
if (!entry) |
5197 |
return 0; |
return 0; |
5214 |
struct singleLine *line; |
struct singleLine *line; |
5215 |
struct singleEntry *entry; |
struct singleEntry *entry; |
5216 |
|
|
5217 |
if (config->defaultImage == -1) |
if (config->defaultImage == NO_DEFAULT_ENTRY) |
5218 |
return 0; |
return 0; |
5219 |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
5220 |
cfi->defaultIsSaved) |
cfi->defaultIsSaved) |
5221 |
config->defaultImage = 0; |
config->defaultImage = FIRST_ENTRY_INDEX; |
5222 |
entry = findEntryByIndex(config, config->defaultImage); |
entry = findEntryByIndex(config, config->defaultImage); |
5223 |
if (!entry) |
if (!entry) |
5224 |
return 0; |
return 0; |
5248 |
return 0; |
return 0; |
5249 |
|
|
5250 |
} else if (displayDefaultIndex) { |
} else if (displayDefaultIndex) { |
5251 |
if (config->defaultImage == -1) |
if (config->defaultImage == NO_DEFAULT_ENTRY) |
5252 |
return 0; |
return 0; |
5253 |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
5254 |
cfi->defaultIsSaved) |
cfi->defaultIsSaved) |
5255 |
config->defaultImage = 0; |
config->defaultImage = FIRST_ENTRY_INDEX; |
5256 |
printf("%i\n", config->defaultImage); |
printf("%i\n", config->defaultImage); |
5257 |
return 0; |
return 0; |
5258 |
|
|