Magellan Linux

Diff of /tags/grubby-8_32/grubby.c

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

revision 1717 by niro, Sat Feb 18 00:47:17 2012 UTC revision 1722 by niro, Sat Feb 18 00:53:14 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 2948  int addNewKernel(struct grubConfig * con Line 2961  int addNewKernel(struct grubConfig * con
2961   }   }
2962      } else if (tmplLine->type == LT_ECHO) {      } else if (tmplLine->type == LT_ECHO) {
2963      requote(tmplLine, config->cfi);      requote(tmplLine, config->cfi);
2964        static const char *prefix = "'Loading ";
2965      if (tmplLine->numElements > 1 &&      if (tmplLine->numElements > 1 &&
2966      strstr(tmplLine->elements[1].item, "'Loading Linux ")) {      strstr(tmplLine->elements[1].item, prefix) &&
2967   char *prefix = "'Loading ";      masterLine->next && masterLine->next->type == LT_KERNEL) {
2968   char *newTitle = malloc(strlen(prefix) +   char *newTitle = malloc(strlen(prefix) +
2969   strlen(newKernelTitle) + 2);   strlen(newKernelTitle) + 2);
2970    
# Line 3147  int main(int argc, const char ** argv) { Line 3161  int main(int argc, const char ** argv) {
3161      struct singleEntry * template = NULL;      struct singleEntry * template = NULL;
3162      int copyDefault = 0, makeDefault = 0;      int copyDefault = 0, makeDefault = 0;
3163      int displayDefault = 0;      int displayDefault = 0;
3164        int displayDefaultIndex = 0;
3165        int displayDefaultTitle = 0;
3166      struct poptOption options[] = {      struct poptOption options[] = {
3167   { "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0,   { "add-kernel", 0, POPT_ARG_STRING, &newKernelPath, 0,
3168      _("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 3195  int main(int argc, const char ** argv) {
3195        "template"), NULL },        "template"), NULL },
3196   { "default-kernel", 0, 0, &displayDefault, 0,   { "default-kernel", 0, 0, &displayDefault, 0,
3197      _("display the path of the default kernel") },      _("display the path of the default kernel") },
3198     { "default-index", 0, 0, &displayDefaultIndex, 0,
3199        _("display the index of the default kernel") },
3200     { "default-title", 0, 0, &displayDefaultTitle, 0,
3201        _("display the title of the default kernel") },
3202   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,   { "elilo", 0, POPT_ARG_NONE, &configureELilo, 0,
3203      _("configure elilo bootloader") },      _("configure elilo bootloader") },
3204   { "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0,   { "extlinux", 0, POPT_ARG_NONE, &configureExtLinux, 0,
# Line 3322  int main(int argc, const char ** argv) { Line 3342  int main(int argc, const char ** argv) {
3342    
3343      if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion ||      if (bootloaderProbe && (displayDefault || kernelInfo || newKernelVersion ||
3344    newKernelPath || removeKernelPath || makeDefault ||    newKernelPath || removeKernelPath || makeDefault ||
3345    defaultKernel)) {    defaultKernel || displayDefaultIndex || displayDefaultTitle)) {
3346   fprintf(stderr, _("grubby: --bootloader-probe may not be used with "   fprintf(stderr, _("grubby: --bootloader-probe may not be used with "
3347    "specified option"));    "specified option"));
3348   return 1;   return 1;
# Line 3373  int main(int argc, const char ** argv) { Line 3393  int main(int argc, const char ** argv) {
3393    
3394      if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel      if (!removeKernelPath && !newKernelPath && !displayDefault && !defaultKernel
3395   && !kernelInfo && !bootloaderProbe && !updateKernelPath   && !kernelInfo && !bootloaderProbe && !updateKernelPath
3396          && !removeMBKernel) {          && !removeMBKernel && !displayDefaultIndex && !displayDefaultTitle) {
3397   fprintf(stderr, _("grubby: no action specified\n"));   fprintf(stderr, _("grubby: no action specified\n"));
3398   return 1;   return 1;
3399      }      }
# Line 3468  int main(int argc, const char ** argv) { Line 3488  int main(int argc, const char ** argv) {
3488                 ((rootspec != NULL) ? strlen(rootspec) : 0));                 ((rootspec != NULL) ? strlen(rootspec) : 0));
3489    
3490   return 0;   return 0;
3491    
3492        } else if (displayDefaultTitle) {
3493     struct singleLine * line;
3494     struct singleEntry * entry;
3495    
3496     if (config->defaultImage == -1) return 0;
3497     entry = findEntryByIndex(config, config->defaultImage);
3498     if (!entry) return 0;
3499    
3500     if (!configureGrub2) {
3501      line = getLineByType(LT_TITLE, entry->lines);
3502      if (!line) return 0;
3503      printf("%s\n", line->elements[1].item);
3504    
3505     } else {
3506      int i;
3507      size_t len;
3508      char * start;
3509      char * tmp;
3510    
3511      dbgPrintf("This is GRUB2, default title is embeded in menuentry\n");
3512      line = getLineByType(LT_MENUENTRY, entry->lines);
3513      if (!line) return 0;
3514    
3515      for (i = 0; i < line->numElements; i++) {
3516    
3517        if (!strcmp(line->elements[i].item, "menuentry"))
3518          continue;
3519    
3520        if (*line->elements[i].item == '\'')
3521          start = line->elements[i].item + 1;
3522        else
3523          start = line->elements[i].item;
3524    
3525        len = strlen(start);
3526        if (*(start + len - 1) == '\'') {
3527          tmp = strdup(start);
3528          *(tmp + len - 1) = '\0';
3529          printf("%s", tmp);
3530          free(tmp);
3531          break;
3532        } else {
3533          printf("%s ", start);
3534        }
3535      }
3536      printf("\n");
3537     }
3538     return 0;
3539    
3540        } else if (displayDefaultIndex) {
3541            if (config->defaultImage == -1) return 0;
3542            printf("%i\n", config->defaultImage);
3543    
3544      } else if (kernelInfo)      } else if (kernelInfo)
3545   return displayInfo(config, kernelInfo, bootPrefix);   return displayInfo(config, kernelInfo, bootPrefix);
3546    

Legend:
Removed from v.1717  
changed lines
  Added in v.1722