356 |
struct configFileInfo * cfi; |
struct configFileInfo * cfi; |
357 |
}; |
}; |
358 |
|
|
359 |
|
blkid_cache blkid; |
360 |
|
|
361 |
struct singleEntry * findEntryByIndex(struct grubConfig * cfg, int index); |
struct singleEntry * findEntryByIndex(struct grubConfig * cfg, int index); |
362 |
struct singleEntry * findEntryByPath(struct grubConfig * cfg, |
struct singleEntry * findEntryByPath(struct grubConfig * cfg, |
363 |
const char * path, const char * prefix, |
const char * path, const char * prefix, |
436 |
} |
} |
437 |
|
|
438 |
static char * getpathbyspec(char *device) { |
static char * getpathbyspec(char *device) { |
|
static blkid_cache blkid; |
|
|
|
|
439 |
if (!blkid) |
if (!blkid) |
440 |
blkid_get_cache(&blkid, NULL); |
blkid_get_cache(&blkid, NULL); |
441 |
|
|
442 |
return blkid_get_devname(blkid, device, NULL); |
return blkid_get_devname(blkid, device, NULL); |
443 |
} |
} |
444 |
|
|
445 |
|
static char * getuuidbydev(char *device) { |
446 |
|
if (!blkid) |
447 |
|
blkid_get_cache(&blkid, NULL); |
448 |
|
|
449 |
|
return blkid_get_tag_value(blkid, "UUID", device); |
450 |
|
} |
451 |
|
|
452 |
static enum lineType_e getTypeByKeyword(char * keyword, |
static enum lineType_e getTypeByKeyword(char * keyword, |
453 |
struct configFileInfo * cfi) { |
struct configFileInfo * cfi) { |
454 |
struct keywordTypes * kw; |
struct keywordTypes * kw; |
1162 |
return i; |
return i; |
1163 |
} |
} |
1164 |
|
|
1165 |
|
static char *findDiskForRoot() |
1166 |
|
{ |
1167 |
|
int fd; |
1168 |
|
char buf[65536]; |
1169 |
|
char *devname; |
1170 |
|
char *chptr; |
1171 |
|
int rc; |
1172 |
|
|
1173 |
|
if ((fd = open(_PATH_MOUNTED, O_RDONLY)) < 0) { |
1174 |
|
fprintf(stderr, "grubby: failed to open %s: %s\n", |
1175 |
|
_PATH_MOUNTED, strerror(errno)); |
1176 |
|
return NULL; |
1177 |
|
} |
1178 |
|
|
1179 |
|
rc = read(fd, buf, sizeof(buf) - 1); |
1180 |
|
if (rc <= 0) { |
1181 |
|
fprintf(stderr, "grubby: failed to read %s: %s\n", |
1182 |
|
_PATH_MOUNTED, strerror(errno)); |
1183 |
|
close(fd); |
1184 |
|
return NULL; |
1185 |
|
} |
1186 |
|
close(fd); |
1187 |
|
buf[rc] = '\0'; |
1188 |
|
chptr = buf; |
1189 |
|
|
1190 |
|
while (chptr && chptr != buf+rc) { |
1191 |
|
devname = chptr; |
1192 |
|
|
1193 |
|
/* |
1194 |
|
* The first column of a mtab entry is the device, but if the entry is a |
1195 |
|
* special device it won't start with /, so move on to the next line. |
1196 |
|
*/ |
1197 |
|
if (*devname != '/') { |
1198 |
|
chptr = strchr(chptr, '\n'); |
1199 |
|
if (chptr) |
1200 |
|
chptr++; |
1201 |
|
continue; |
1202 |
|
} |
1203 |
|
|
1204 |
|
/* Seek to the next space */ |
1205 |
|
chptr = strchr(chptr, ' '); |
1206 |
|
if (!chptr) { |
1207 |
|
fprintf(stderr, "grubby: error parsing %s: %s\n", |
1208 |
|
_PATH_MOUNTED, strerror(errno)); |
1209 |
|
return NULL; |
1210 |
|
} |
1211 |
|
|
1212 |
|
/* |
1213 |
|
* The second column of a mtab entry is the mount point, we are looking |
1214 |
|
* for '/' obviously. |
1215 |
|
*/ |
1216 |
|
if (*(++chptr) == '/' && *(++chptr) == ' ') { |
1217 |
|
/* |
1218 |
|
* Move back 2, which is the first space after the device name, set |
1219 |
|
* it to \0 so strdup will just get the devicename. |
1220 |
|
*/ |
1221 |
|
chptr -= 2; |
1222 |
|
*chptr = '\0'; |
1223 |
|
return strdup(devname); |
1224 |
|
} |
1225 |
|
|
1226 |
|
/* Next line */ |
1227 |
|
chptr = strchr(chptr, '\n'); |
1228 |
|
if (chptr) |
1229 |
|
chptr++; |
1230 |
|
} |
1231 |
|
|
1232 |
|
return NULL; |
1233 |
|
} |
1234 |
|
|
1235 |
int suitableImage(struct singleEntry * entry, const char * bootPrefix, |
int suitableImage(struct singleEntry * entry, const char * bootPrefix, |
1236 |
int skipRemoved, int flags) { |
int skipRemoved, int flags) { |
1237 |
struct singleLine * line; |
struct singleLine * line; |
1238 |
char * fullName; |
char * fullName; |
1239 |
int i; |
int i; |
|
struct stat sb, sb2; |
|
1240 |
char * dev; |
char * dev; |
1241 |
char * rootspec; |
char * rootspec; |
1242 |
|
char * rootdev; |
1243 |
|
|
1244 |
if (skipRemoved && entry->skip) return 0; |
if (skipRemoved && entry->skip) return 0; |
1245 |
|
|
1289 |
if (!dev) |
if (!dev) |
1290 |
return 0; |
return 0; |
1291 |
|
|
1292 |
i = stat(dev, &sb); |
rootdev = findDiskForRoot(); |
1293 |
if (i) |
if (!rootdev) |
1294 |
return 0; |
return 0; |
1295 |
|
|
1296 |
stat("/", &sb2); |
if (!getuuidbydev(rootdev) || !getuuidbydev(dev)) { |
1297 |
|
free(rootdev); |
1298 |
|
return 0; |
1299 |
|
} |
1300 |
|
|
1301 |
if (sb.st_rdev != sb2.st_dev) |
if (strcmp(getuuidbydev(rootdev), getuuidbydev(dev))) { |
1302 |
|
free(rootdev); |
1303 |
return 0; |
return 0; |
1304 |
|
} |
1305 |
|
|
1306 |
|
free(rootdev); |
1307 |
|
|
1308 |
return 1; |
return 1; |
1309 |
} |
} |
1666 |
char * start; |
char * start; |
1667 |
char * param; |
char * param; |
1668 |
|
|
1669 |
in = fopen("/etc/sysconfig/grub", "r"); |
in = fopen("/etc/conf.d/grub", "r"); |
1670 |
if (!in) return 1; |
if (!in) return 1; |
1671 |
|
|
1672 |
if (lbaPtr) *lbaPtr = 0; |
if (lbaPtr) *lbaPtr = 0; |
1728 |
return 1; |
return 1; |
1729 |
} |
} |
1730 |
|
|
1731 |
/* this is a horrible hack to support /etc/sysconfig/grub; there must |
/* this is a horrible hack to support /etc/conf.d/grub; there must |
1732 |
be a better way */ |
be a better way */ |
1733 |
if (config->cfi == &grubConfigType) { |
if (config->cfi == &grubConfigType) { |
1734 |
dumpSysconfigGrub(); |
dumpSysconfigGrub(); |
2203 |
return rc; |
return rc; |
2204 |
} |
} |
2205 |
|
|
2206 |
|
int updateInitrd(struct grubConfig * cfg, const char * image, |
2207 |
|
const char * prefix, const char * initrd) { |
2208 |
|
struct singleEntry * entry; |
2209 |
|
struct singleLine * line, * kernelLine; |
2210 |
|
int index = 0; |
2211 |
|
|
2212 |
|
if (!image) return 0; |
2213 |
|
|
2214 |
|
for (; (entry = findEntryByPath(cfg, image, prefix, &index)); index++) { |
2215 |
|
kernelLine = getLineByType(LT_KERNEL, entry->lines); |
2216 |
|
if (!kernelLine) continue; |
2217 |
|
|
2218 |
|
line = getLineByType(LT_INITRD, entry->lines); |
2219 |
|
if (line) |
2220 |
|
removeLine(entry, line); |
2221 |
|
if (prefix) { |
2222 |
|
int prefixLen = strlen(prefix); |
2223 |
|
if (!strncmp(initrd, prefix, prefixLen)) |
2224 |
|
initrd += prefixLen; |
2225 |
|
} |
2226 |
|
line = addLine(entry, cfg->cfi, LT_INITRD, kernelLine->indent, initrd); |
2227 |
|
if (!line) return 1; |
2228 |
|
break; |
2229 |
|
} |
2230 |
|
|
2231 |
|
return 0; |
2232 |
|
} |
2233 |
|
|
2234 |
int checkDeviceBootloader(const char * device, const unsigned char * boot) { |
int checkDeviceBootloader(const char * device, const unsigned char * boot) { |
2235 |
int fd; |
int fd; |
2236 |
unsigned char bootSect[512]; |
unsigned char bootSect[512]; |
3060 |
if (newKernelPath && !newKernelTitle) { |
if (newKernelPath && !newKernelTitle) { |
3061 |
fprintf(stderr, _("grubby: kernel title must be specified\n")); |
fprintf(stderr, _("grubby: kernel title must be specified\n")); |
3062 |
return 1; |
return 1; |
3063 |
} else if (!newKernelPath && (newKernelTitle || newKernelInitrd || |
} else if (!newKernelPath && (newKernelTitle || copyDefault || |
3064 |
newKernelInitrd || copyDefault || |
(newKernelInitrd && !updateKernelPath)|| |
3065 |
makeDefault || extraInitrdCount > 0)) { |
makeDefault || extraInitrdCount > 0)) { |
3066 |
fprintf(stderr, _("grubby: kernel path expected\n")); |
fprintf(stderr, _("grubby: kernel path expected\n")); |
3067 |
return 1; |
return 1; |
3194 |
setFallbackImage(config, newKernelPath != NULL); |
setFallbackImage(config, newKernelPath != NULL); |
3195 |
if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs, |
if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs, |
3196 |
removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1; |
removeArgs, newMBKernelArgs, removeMBKernelArgs)) return 1; |
3197 |
|
if (updateKernelPath && newKernelInitrd) { |
3198 |
|
if (updateInitrd(config, updateKernelPath, bootPrefix, |
3199 |
|
newKernelInitrd)) return 1; |
3200 |
|
} |
3201 |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
if (addNewKernel(config, template, bootPrefix, newKernelPath, |
3202 |
newKernelTitle, newKernelArgs, newKernelInitrd, |
newKernelTitle, newKernelArgs, newKernelInitrd, |
3203 |
extraInitrds, extraInitrdCount, |
extraInitrds, extraInitrdCount, |