Magellan Linux

Diff of /trunk/grubby/grubby.c

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

revision 1850 by niro, Mon Jul 2 13:09:12 2012 UTC revision 1853 by niro, Mon Jul 2 13:12:07 2012 UTC
# Line 164  struct keywordTypes grubKeywords[] = { Line 164  struct keywordTypes grubKeywords[] = {
164    
165  const char *grubFindConfig(struct configFileInfo *cfi) {  const char *grubFindConfig(struct configFileInfo *cfi) {
166      static const char *configFiles[] = {      static const char *configFiles[] = {
  "/etc/grub.conf",  
167   "/boot/grub/grub.conf",   "/boot/grub/grub.conf",
168   "/boot/grub/menu.lst",   "/boot/grub/menu.lst",
169     "/etc/grub.conf",
170   NULL   NULL
171      };      };
172      static int i = -1;      static int i = -1;
# Line 2350  void dumpSysconfigGrub(void) { Line 2350  void dumpSysconfigGrub(void) {
2350      char * boot = NULL;      char * boot = NULL;
2351      int lba;      int lba;
2352    
2353      if (!isSuseSystem()) {      if (isSuseSystem()) {
2354          if (parseSysconfigGrub(&lba, &boot)) {          if (parseSuseGrubConf(&lba, &boot)) {
2355      free(boot);      free(boot);
2356      return;      return;
2357   }   }
2358      } else {      } else {
2359          if (parseSuseGrubConf(&lba, &boot)) {          if (parseSysconfigGrub(&lba, &boot)) {
2360      free(boot);      free(boot);
2361      return;      return;
2362   }   }
# Line 3179  int checkForGrub(struct grubConfig * con Line 3179  int checkForGrub(struct grubConfig * con
3179      int fd;      int fd;
3180      unsigned char bootSect[512];      unsigned char bootSect[512];
3181      char * boot;      char * boot;
3182      int onSuse;      int onSuse = isSuseSystem();
3183    
3184      onSuse = isSuseSystem();  
3185      if (!onSuse) {      if (onSuse) {
3186   if (parseSysconfigGrub(NULL, &boot)) return 0;   if (parseSuseGrubConf(NULL, &boot))
3187        return 0;
3188      } else {      } else {
3189   if (parseSuseGrubConf(NULL, &boot)) return 0;   if (parseSysconfigGrub(NULL, &boot))
3190        return 0;
3191      }      }
3192    
3193      /* assume grub is not installed -- not an error condition */      /* assume grub is not installed -- not an error condition */
# Line 3205  int checkForGrub(struct grubConfig * con Line 3207  int checkForGrub(struct grubConfig * con
3207      }      }
3208      close(fd);      close(fd);
3209    
3210      if (!onSuse)      /* The more elaborate checks do not work on SuSE. The checks done
3211   return checkDeviceBootloader(boot, bootSect);       * seem to be reasonble (at least for now), so just return success
3212      else       */
3213   /*      if (onSuse)
  * The more elaborate checks do not work on SuSE. The checks done  
  * seem to be reasonble (at least for now), so just return success  
  */  
3214   return 2;   return 2;
3215    
3216        return checkDeviceBootloader(boot, bootSect);
3217  }  }
3218    
3219  int checkForExtLinux(struct grubConfig * config) {  int checkForExtLinux(struct grubConfig * config) {
# Line 3245  int checkForExtLinux(struct grubConfig * Line 3246  int checkForExtLinux(struct grubConfig *
3246      return checkDeviceBootloader(boot, bootSect);      return checkDeviceBootloader(boot, bootSect);
3247  }  }
3248    
3249    int checkForYaboot(struct grubConfig * config) {
3250        /*
3251         * This is a simplistic check that we consider good enough for own puporses
3252         *
3253         * If we were to properly check if yaboot is *installed* we'd need to:
3254         * 1) get the system boot device (LT_BOOT)
3255         * 2) considering it's a raw filesystem, check if the yaboot binary matches
3256         *    the content on the boot device
3257         * 3) if not, copy the binary to a temporary file and run "addnote" on it
3258         * 4) check again if binary and boot device contents match
3259         */
3260        if (!access("/etc/yaboot.conf", R_OK))
3261     return 2;
3262    
3263        return 1;
3264    }
3265    
3266  static char * getRootSpecifier(char * str) {  static char * getRootSpecifier(char * str) {
3267      char * idx, * rootspec = NULL;      char * idx, * rootspec = NULL;
3268    
# Line 3732  int main(int argc, const char ** argv) { Line 3750  int main(int argc, const char ** argv) {
3750   { "boot-filesystem", 0, POPT_ARG_STRING, &bootPrefix, 0,   { "boot-filesystem", 0, POPT_ARG_STRING, &bootPrefix, 0,
3751      _("filestystem which contains /boot directory (for testing only)"),      _("filestystem which contains /boot directory (for testing only)"),
3752      _("bootfs") },      _("bootfs") },
3753  #if defined(__i386__) || defined(__x86_64__)  #if defined(__i386__) || defined(__x86_64__) || defined (__powerpc64__)
3754   { "bootloader-probe", 0, POPT_ARG_NONE, &bootloaderProbe, 0,   { "bootloader-probe", 0, POPT_ARG_NONE, &bootloaderProbe, 0,
3755      _("check if lilo is installed on lilo.conf boot sector") },      _("check which bootloader is installed on boot sector") },
3756  #endif  #endif
3757   { "config-file", 'c', POPT_ARG_STRING, &grubConfig, 0,   { "config-file", 'c', POPT_ARG_STRING, &grubConfig, 0,
3758      _("path to grub config file to update (\"-\" for stdin)"),      _("path to grub config file to update (\"-\" for stdin)"),
# Line 3974  int main(int argc, const char ** argv) { Line 3992  int main(int argc, const char ** argv) {
3992      }      }
3993    
3994      if (bootloaderProbe) {      if (bootloaderProbe) {
3995   int lrc = 0, grc = 0, gr2c = 0, erc = 0;   int lrc = 0, grc = 0, gr2c = 0, erc = 0, yrc = 0;
3996   struct grubConfig * lconfig, * gconfig;   struct grubConfig * lconfig, * gconfig, * yconfig;
3997    
3998   const char *grub2config = grub2FindConfig(&grub2ConfigType);   const char *grub2config = grub2FindConfig(&grub2ConfigType);
3999   if (grub2config) {   if (grub2config) {
# Line 4011  int main(int argc, const char ** argv) { Line 4029  int main(int argc, const char ** argv) {
4029   erc = checkForExtLinux(lconfig);   erc = checkForExtLinux(lconfig);
4030   }   }
4031    
4032   if (lrc == 1 || grc == 1 || gr2c == 1) return 1;  
4033     if (!access(yabootConfigType.defaultConfig, F_OK)) {
4034        yconfig = readConfig(yabootConfigType.defaultConfig,
4035     &yabootConfigType);
4036        if (!yconfig)
4037     yrc = 1;
4038        else
4039          yrc = checkForYaboot(lconfig);
4040     }
4041    
4042     if (lrc == 1 || grc == 1 || gr2c == 1 || yrc == 1) return 1;
4043    
4044   if (lrc == 2) printf("lilo\n");   if (lrc == 2) printf("lilo\n");
4045   if (gr2c == 2) printf("grub2\n");   if (gr2c == 2) printf("grub2\n");
4046   if (grc == 2) printf("grub\n");   if (grc == 2) printf("grub\n");
4047   if (erc == 2) printf("extlinux\n");   if (erc == 2) printf("extlinux\n");
4048     if (yrc == 2) printf("yaboot\n");
4049    
4050   return 0;   return 0;
4051      }      }

Legend:
Removed from v.1850  
changed lines
  Added in v.1853