Magellan Linux

Diff of /trunk/grubby/grubby.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1715 by niro, Sat Feb 18 00:35:46 2012 UTC revision 1721 by niro, Sat Feb 18 00:52:28 2012 UTC
# Line 51  Line 51 
51  #define MAX_EXTRA_INITRDS  16 /* code segment checked by --bootloader-probe */  #define MAX_EXTRA_INITRDS  16 /* code segment checked by --bootloader-probe */
52  #define CODE_SEG_SIZE  128 /* code segment checked by --bootloader-probe */  #define CODE_SEG_SIZE  128 /* code segment checked by --bootloader-probe */
53    
54    #define NOOP_OPCODE 0x90
55    #define JMP_SHORT_OPCODE 0xeb
56    
57  /* comments get lumped in with indention */  /* comments get lumped in with indention */
58  struct lineElement {  struct lineElement {
59      char * item;      char * item;
# Line 2468  int checkDeviceBootloader(const char * d Line 2471  int checkDeviceBootloader(const char * d
2471      if (memcmp(boot, bootSect, 3))      if (memcmp(boot, bootSect, 3))
2472   return 0;   return 0;
2473    
2474      if (boot[1] == 0xeb) {      if (boot[1] == JMP_SHORT_OPCODE) {
2475   offset = boot[2] + 2;   offset = boot[2] + 2;
2476      } else if (boot[1] == 0xe8 || boot[1] == 0xe9) {      } else if (boot[1] == 0xe8 || boot[1] == 0xe9) {
2477   offset = (boot[3] << 8) + boot[2] + 2;   offset = (boot[3] << 8) + boot[2] + 2;
2478      } else if (boot[0] == 0xeb) {      } else if (boot[0] == JMP_SHORT_OPCODE) {
2479   offset = boot[1] + 2;        offset = boot[1] + 2;
2480            /*
2481     * it looks like grub, when copying stage1 into the mbr, patches stage1
2482     * right after the JMP location, replacing other instructions such as
2483     * JMPs for NOOPs. So, relax the check a little bit by skipping those
2484     * different bytes.
2485     */
2486          if ((bootSect[offset + 1] == NOOP_OPCODE)
2487      && (bootSect[offset + 2] == NOOP_OPCODE)) {
2488     offset = offset + 3;
2489          }
2490      } else if (boot[0] == 0xe8 || boot[0] == 0xe9) {      } else if (boot[0] == 0xe8 || boot[0] == 0xe9) {
2491   offset = (boot[2] << 8) + boot[1] + 2;   offset = (boot[2] << 8) + boot[1] + 2;
2492      } else {      } else {
# Line 3147  int main(int argc, const char ** argv) { Line 3160  int main(int argc, const char ** argv) {
3160      struct singleEntry * template = NULL;      struct singleEntry * template = NULL;
3161      int copyDefault = 0, makeDefault = 0;      int copyDefault = 0, makeDefault = 0;
3162      int displayDefault = 0;      int displayDefault = 0;
3163        int displayDefaultIndex = 0;
3164        int displayDefaultTitle = 0;
3165      struct poptOption options[] = {      struct poptOption options[] = {
3166   { "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0,   { "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0,
3167      _("add an entry for the specified kernel"), _("kernel-path") },      _("add an entry for the specified kernel"), _("kernel-path") },
# Line 3179  int main(int argc, const char ** argv) { Line 3194  int main(int argc, const char ** argv) {
3194        "template"), NULL },        "template"), NULL },
3195   { "default-kernel", 0, 0, &displayDefault, 0,   { "default-kernel", 0, 0, &displayDefault, 0,
3196      _("display the path of the default kernel") },      _("display the path of the default kernel") },
3197     { "default-index", 0, 0, &displayDefaultIndex, 0,
3198        _("display the index of the default kernel") },
3199     { "default-title", 0, 0, &displayDefaultTitle, 0,
3200        _("display the title of the default kernel") },
3201   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,
3202      _("configure elilo bootloader") },      _("configure elilo bootloader") },
3203   { "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0,   { "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0,
# Line 3322  int main(int argc, const char ** argv) { Line 3341  int main(int argc, const char ** argv) {
3341    
3342      if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion ||      if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion ||
3343    newKernelPath || removeKernelPath || makeDefault ||    newKernelPath || removeKernelPath || makeDefault ||
3344    defaultKernel)) {    defaultKernel || displayDefaultIndex || displayDefaultTitle)) {
3345   fprintf(stderr, _("grubby: --bootloader-probe may not be used with "   fprintf(stderr, _("grubby: --bootloader-probe may not be used with "
3346    "specified option"));    "specified option"));
3347   return 1;   return 1;
# Line 3365  int main(int argc, const char ** argv) { Line 3384  int main(int argc, const char ** argv) {
3384   defaultKernel = NULL;   defaultKernel = NULL;
3385      }      }
3386    
3387      if (!strcmp(grubConfig, "-") && !outputFile) {      if (grubConfig && !strcmp(grubConfig, "-") && !outputFile) {
3388   fprintf(stderr, _("grubby: output file must be specified if stdin "   fprintf(stderr, _("grubby: output file must be specified if stdin "
3389   "is used\n"));   "is used\n"));
3390   return 1;   return 1;
# Line 3373  int main(int argc, const char ** argv) { Line 3392  int main(int argc, const char ** argv) {
3392    
3393      if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel      if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel
3394   && !kernelInfo && !bootloaderProbe && !updateKernelPath   && !kernelInfo && !bootloaderProbe && !updateKernelPath
3395          && !removeMBKernel) {          && !removeMBKernel && !displayDefaultIndex && !displayDefaultTitle) {
3396   fprintf(stderr, _("grubby: no action specified\n"));   fprintf(stderr, _("grubby: no action specified\n"));
3397   return 1;   return 1;
3398      }      }
# Line 3468  int main(int argc, const char ** argv) { Line 3487  int main(int argc, const char ** argv) {
3487                 ((rootspec != NULL) ? strlen(rootspec) : 0));                 ((rootspec != NULL) ? strlen(rootspec) : 0));
3488    
3489   return 0;   return 0;
3490    
3491        } else if (displayDefaultTitle) {
3492     struct singleLine * line;
3493     struct singleEntry * entry;
3494    
3495     if (config->defaultImage == -1) return 0;
3496     entry = findEntryByIndex(config, config->defaultImage);
3497     if (!entry) return 0;
3498    
3499     if (!configureGrub2) {
3500      line = getLineByType(LT_TITLE, entry->lines);
3501      if (!line) return 0;
3502      printf("%s\n", line->elements[1].item);
3503    
3504     } else {
3505      int i;
3506      size_t len;
3507      char * start;
3508      char * tmp;
3509    
3510      dbgPrintf("This is GRUB2, default title is embeded in menuentry\n");
3511      line = getLineByType(LT_MENUENTRY, entry->lines);
3512      if (!line) return 0;
3513    
3514      for (i = 0; i < line->numElements; i++) {
3515    
3516        if (!strcmp(line->elements[i].item, "menuentry"))
3517          continue;
3518    
3519        if (*line->elements[i].item == '\'')
3520          start = line->elements[i].item + 1;
3521        else
3522          start = line->elements[i].item;
3523    
3524        len = strlen(start);
3525        if (*(start + len - 1) == '\'') {
3526          tmp = strdup(start);
3527          *(tmp + len - 1) = '\0';
3528          printf("%s", tmp);
3529          free(tmp);
3530          break;
3531        } else {
3532          printf("%s ", start);
3533        }
3534      }
3535      printf("\n");
3536     }
3537     return 0;
3538    
3539        } else if (displayDefaultIndex) {
3540            if (config->defaultImage == -1) return 0;
3541            printf("%i\n", config->defaultImage);
3542    
3543      } else if (kernelInfo)      } else if (kernelInfo)
3544   return displayInfo(config, kernelInfo, bootPrefix);   return displayInfo(config, kernelInfo, bootPrefix);
3545    

Legend:
Removed from v.1715  
changed lines
  Added in v.1721