Magellan Linux

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

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

revision 1714 by niro, Sat Feb 18 00:32:14 2012 UTC revision 1718 by niro, Sat Feb 18 00:49:41 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 156  struct keywordTypes grubKeywords[] = { Line 159  struct keywordTypes grubKeywords[] = {
159      { NULL,    0, 0 },      { NULL,    0, 0 },
160  };  };
161    
162    const char *grubFindConfig(struct configFileInfo *cfi) {
163        static const char *configFiles[] = {
164     "/etc/grub.conf",
165     "/boot/grub/grub.conf",
166     "/boot/grub/menu.lst",
167     NULL
168        };
169        static int i = -1;
170    
171        if (i == -1) {
172     for (i = 0; configFiles[i] != NULL; i++) {
173        dbgPrintf("Checking \"%s\": ", configFiles[i]);
174        if (!access(configFiles[i], R_OK)) {
175     dbgPrintf("found\n");
176     return configFiles[i];
177        }
178        dbgPrintf("not found\n");
179     }
180        }
181        return configFiles[i];
182    }
183    
184  struct configFileInfo grubConfigType = {  struct configFileInfo grubConfigType = {
185      .defaultConfig = "/boot/grub/grub.conf",      .findConfig = grubFindConfig,
186      .keywords = grubKeywords,      .keywords = grubKeywords,
187      .defaultIsIndex = 1,      .defaultIsIndex = 1,
188      .defaultSupportSaved = 1,      .defaultSupportSaved = 1,
# Line 2446  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 3343  int main(int argc, const char ** argv) { Line 3378  int main(int argc, const char ** argv) {
3378   defaultKernel = NULL;   defaultKernel = NULL;
3379      }      }
3380    
3381      if (!strcmp(grubConfig, "-") && !outputFile) {      if (grubConfig && !strcmp(grubConfig, "-") && !outputFile) {
3382   fprintf(stderr, _("grubby: output file must be specified if stdin "   fprintf(stderr, _("grubby: output file must be specified if stdin "
3383   "is used\n"));   "is used\n"));
3384   return 1;   return 1;
# Line 3390  int main(int argc, const char ** argv) { Line 3425  int main(int argc, const char ** argv) {
3425   gr2c = checkForGrub2(gconfig);   gr2c = checkForGrub2(gconfig);
3426   }   }
3427    
3428   if (!access(grubConfigType.defaultConfig, F_OK)) {   const char *grubconfig = grubFindConfig(&grubConfigType);
3429      gconfig = readConfig(grubConfigType.defaultConfig, &grubConfigType);   if (!access(grubconfig, F_OK)) {
3430        gconfig = readConfig(grubconfig, &grubConfigType);
3431      if (!gconfig)      if (!gconfig)
3432   grc = 1;   grc = 1;
3433      else      else

Legend:
Removed from v.1714  
changed lines
  Added in v.1718