114 |
|
|
115 |
#define MAIN_DEFAULT (1 << 0) |
#define MAIN_DEFAULT (1 << 0) |
116 |
#define DEFAULT_SAVED -2 |
#define DEFAULT_SAVED -2 |
117 |
|
#define DEFAULT_SAVED_GRUB2 -3 |
118 |
|
|
119 |
struct keywordTypes { |
struct keywordTypes { |
120 |
char * key; |
char * key; |
242 |
return configFiles[i]; |
return configFiles[i]; |
243 |
} |
} |
244 |
|
|
245 |
|
int sizeOfSingleLine(struct singleLine * line) { |
246 |
|
int i; |
247 |
|
int count = 0; |
248 |
|
|
249 |
|
for (i = 0; i < line->numElements; i++) { |
250 |
|
int indentSize = 0; |
251 |
|
|
252 |
|
count = count + strlen(line->elements[i].item); |
253 |
|
|
254 |
|
indentSize = strlen(line->elements[i].indent); |
255 |
|
if (indentSize > 0) |
256 |
|
count = count + indentSize; |
257 |
|
else |
258 |
|
/* be extra safe and add room for whitespaces */ |
259 |
|
count = count + 1; |
260 |
|
} |
261 |
|
|
262 |
|
/* room for trailing terminator */ |
263 |
|
count = count + 1; |
264 |
|
|
265 |
|
return count; |
266 |
|
} |
267 |
|
|
268 |
|
char *grub2ExtractTitle(struct singleLine * line) { |
269 |
|
char * current; |
270 |
|
char * current_indent; |
271 |
|
int current_len; |
272 |
|
int current_indent_len; |
273 |
|
int i; |
274 |
|
|
275 |
|
/* bail out if line does not start with menuentry */ |
276 |
|
if (strcmp(line->elements[0].item, "menuentry")) |
277 |
|
return NULL; |
278 |
|
|
279 |
|
i = 1; |
280 |
|
current = line->elements[i].item; |
281 |
|
current_len = strlen(current); |
282 |
|
|
283 |
|
/* if second word is quoted, strip the quotes and return single word */ |
284 |
|
if ((*current == '\'') && (*(current + current_len - 1) == '\'')) { |
285 |
|
char *tmp; |
286 |
|
|
287 |
|
tmp = strdup(current); |
288 |
|
*(tmp + current_len - 1) = '\0'; |
289 |
|
return ++tmp; |
290 |
|
} |
291 |
|
|
292 |
|
/* if no quotes, return second word verbatim */ |
293 |
|
if (*current != '\'') { |
294 |
|
return current; |
295 |
|
} |
296 |
|
|
297 |
|
/* second element start with a quote, so we have to find the element |
298 |
|
* whose last character is also quote (assuming it's the closing one) */ |
299 |
|
if (*current == '\'') { |
300 |
|
int resultMaxSize; |
301 |
|
char * result; |
302 |
|
|
303 |
|
resultMaxSize = sizeOfSingleLine(line); |
304 |
|
result = malloc(resultMaxSize); |
305 |
|
snprintf(result, resultMaxSize, "%s", ++current); |
306 |
|
|
307 |
|
i++; |
308 |
|
for (; i < line->numElements; ++i) { |
309 |
|
current = line->elements[i].item; |
310 |
|
current_len = strlen(current); |
311 |
|
current_indent = line->elements[i].indent; |
312 |
|
current_indent_len = strlen(current_indent); |
313 |
|
|
314 |
|
strncat(result, current_indent, current_indent_len); |
315 |
|
if (*(current + current_len - 1) != '\'') { |
316 |
|
strncat(result, current, current_len); |
317 |
|
} else { |
318 |
|
strncat(result, current, current_len - 1); |
319 |
|
break; |
320 |
|
} |
321 |
|
} |
322 |
|
return result; |
323 |
|
} |
324 |
|
|
325 |
|
return NULL; |
326 |
|
} |
327 |
|
|
328 |
struct configFileInfo grub2ConfigType = { |
struct configFileInfo grub2ConfigType = { |
329 |
.findConfig = grub2FindConfig, |
.findConfig = grub2FindConfig, |
330 |
.keywords = grub2Keywords, |
.keywords = grub2Keywords, |
331 |
.defaultIsIndex = 1, |
.defaultIsIndex = 1, |
332 |
.defaultSupportSaved = 0, |
.defaultSupportSaved = 1, |
333 |
.defaultIsVariable = 1, |
.defaultIsVariable = 1, |
334 |
.entryStart = LT_MENUENTRY, |
.entryStart = LT_MENUENTRY, |
335 |
.entryEnd = LT_ENTRY_END, |
.entryEnd = LT_ENTRY_END, |
1124 |
|
|
1125 |
dbgPrintf("defaultLine is %s\n", defaultLine ? "set" : "unset"); |
dbgPrintf("defaultLine is %s\n", defaultLine ? "set" : "unset"); |
1126 |
if (defaultLine) { |
if (defaultLine) { |
1127 |
if (cfi->defaultIsVariable) { |
if (defaultLine->numElements > 2 && |
1128 |
|
cfi->defaultSupportSaved && |
1129 |
|
!strncmp(defaultLine->elements[2].item,"\"${saved_entry}\"", 16)) { |
1130 |
|
cfg->defaultImage = DEFAULT_SAVED_GRUB2; |
1131 |
|
} else if (cfi->defaultIsVariable) { |
1132 |
char *value = defaultLine->elements[2].item; |
char *value = defaultLine->elements[2].item; |
1133 |
while (*value && (*value == '"' || *value == '\'' || |
while (*value && (*value == '"' || *value == '\'' || |
1134 |
*value == ' ' || *value == '\t')) |
*value == ' ' || *value == '\t')) |
1185 |
|
|
1186 |
if (cfg->defaultImage == DEFAULT_SAVED) |
if (cfg->defaultImage == DEFAULT_SAVED) |
1187 |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
1188 |
|
else if (cfg->defaultImage == DEFAULT_SAVED_GRUB2) |
1189 |
|
fprintf(out, "%sset default=\"${saved_entry}\"\n", indent); |
1190 |
else if (cfg->defaultImage > -1) { |
else if (cfg->defaultImage > -1) { |
1191 |
if (cfg->cfi->defaultIsIndex) { |
if (cfg->cfi->defaultIsIndex) { |
1192 |
if (cfg->cfi->defaultIsVariable) { |
if (cfg->cfi->defaultIsVariable) { |
1458 |
va_end(argp); |
va_end(argp); |
1459 |
} |
} |
1460 |
|
|
1461 |
|
#define beginswith(s, c) ((s) && (s)[0] == (c)) |
1462 |
|
|
1463 |
|
static int endswith(const char *s, char c) |
1464 |
|
{ |
1465 |
|
int slen; |
1466 |
|
|
1467 |
|
if (!s || !s[0]) |
1468 |
|
return 0; |
1469 |
|
slen = strlen(s) - 1; |
1470 |
|
|
1471 |
|
return s[slen] == c; |
1472 |
|
} |
1473 |
|
|
1474 |
int suitableImage(struct singleEntry * entry, const char * bootPrefix, |
int suitableImage(struct singleEntry * entry, const char * bootPrefix, |
1475 |
int skipRemoved, int flags) { |
int skipRemoved, int flags) { |
1476 |
struct singleLine * line; |
struct singleLine * line; |
1501 |
fullName = alloca(strlen(bootPrefix) + |
fullName = alloca(strlen(bootPrefix) + |
1502 |
strlen(line->elements[1].item) + 1); |
strlen(line->elements[1].item) + 1); |
1503 |
rootspec = getRootSpecifier(line->elements[1].item); |
rootspec = getRootSpecifier(line->elements[1].item); |
1504 |
sprintf(fullName, "%s%s", bootPrefix, |
int rootspec_offset = rootspec ? strlen(rootspec) : 0; |
1505 |
line->elements[1].item + (rootspec ? strlen(rootspec) : 0)); |
int hasslash = endswith(bootPrefix, '/') || |
1506 |
|
beginswith(line->elements[1].item + rootspec_offset, '/'); |
1507 |
|
sprintf(fullName, "%s%s%s", bootPrefix, hasslash ? "" : "/", |
1508 |
|
line->elements[1].item + rootspec_offset); |
1509 |
if (access(fullName, R_OK)) { |
if (access(fullName, R_OK)) { |
1510 |
notSuitablePrintf(entry, "access to %s failed\n", fullName); |
notSuitablePrintf(entry, "access to %s failed\n", fullName); |
1511 |
return 0; |
return 0; |
1794 |
|
|
1795 |
/* defaultImage now points to what we'd like to use, but before any order |
/* defaultImage now points to what we'd like to use, but before any order |
1796 |
changes */ |
changes */ |
1797 |
if (config->defaultImage == DEFAULT_SAVED) |
if ((config->defaultImage == DEFAULT_SAVED) || |
1798 |
|
(config->defaultImage == DEFAULT_SAVED_GRUB2)) |
1799 |
/* default is set to saved, we don't want to change it */ |
/* default is set to saved, we don't want to change it */ |
1800 |
return; |
return; |
1801 |
|
|
1862 |
return; |
return; |
1863 |
} |
} |
1864 |
|
|
1865 |
printf("kernel=%s\n", line->elements[1].item); |
printf("kernel=%s%s\n", prefix, line->elements[1].item); |
1866 |
|
|
1867 |
if (line->numElements >= 3) { |
if (line->numElements >= 3) { |
1868 |
printf("args=\""); |
printf("args=\""); |
1926 |
printf("%s%s", line->elements[i].item, line->elements[i].indent); |
printf("%s%s", line->elements[i].item, line->elements[i].indent); |
1927 |
printf("\n"); |
printf("\n"); |
1928 |
} |
} |
1929 |
|
|
1930 |
|
line = getLineByType(LT_TITLE, entry->lines); |
1931 |
|
if (line) { |
1932 |
|
printf("title=%s\n", line->elements[1].item); |
1933 |
|
} else { |
1934 |
|
char * title; |
1935 |
|
line = getLineByType(LT_MENUENTRY, entry->lines); |
1936 |
|
title = grub2ExtractTitle(line); |
1937 |
|
if (title) |
1938 |
|
printf("title=%s\n", title); |
1939 |
|
} |
1940 |
} |
} |
1941 |
|
|
1942 |
int parseSysconfigGrub(int * lbaPtr, char ** bootPtr) { |
int parseSysconfigGrub(int * lbaPtr, char ** bootPtr) { |
3679 |
printf("%s\n", line->elements[1].item); |
printf("%s\n", line->elements[1].item); |
3680 |
|
|
3681 |
} else { |
} else { |
3682 |
int i; |
char * title; |
|
size_t len; |
|
|
char * start; |
|
|
char * tmp; |
|
3683 |
|
|
3684 |
dbgPrintf("This is GRUB2, default title is embeded in menuentry\n"); |
dbgPrintf("This is GRUB2, default title is embeded in menuentry\n"); |
3685 |
line = getLineByType(LT_MENUENTRY, entry->lines); |
line = getLineByType(LT_MENUENTRY, entry->lines); |
3686 |
if (!line) return 0; |
if (!line) return 0; |
3687 |
|
title = grub2ExtractTitle(line); |
3688 |
for (i = 0; i < line->numElements; i++) { |
if (title) |
3689 |
|
printf("%s\n", title); |
|
if (!strcmp(line->elements[i].item, "menuentry")) |
|
|
continue; |
|
|
|
|
|
if (*line->elements[i].item == '\'') |
|
|
start = line->elements[i].item + 1; |
|
|
else |
|
|
start = line->elements[i].item; |
|
|
|
|
|
len = strlen(start); |
|
|
if (*(start + len - 1) == '\'') { |
|
|
tmp = strdup(start); |
|
|
*(tmp + len - 1) = '\0'; |
|
|
printf("%s", tmp); |
|
|
free(tmp); |
|
|
break; |
|
|
} else { |
|
|
printf("%s ", start); |
|
|
} |
|
|
} |
|
|
printf("\n"); |
|
3690 |
} |
} |
3691 |
return 0; |
return 0; |
3692 |
|
|