Magellan Linux

Diff of /trunk/grubby/grubby.c

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

revision 3021 by niro, Tue Jun 27 14:39:37 2017 UTC revision 3031 by niro, Tue Jun 27 14:48:09 2017 UTC
# Line 1712  static void writeDefault(FILE * out, cha Line 1712  static void writeDefault(FILE * out, cha
1712   fprintf(out, "%sset default=\"${saved_entry}\"\n", indent);   fprintf(out, "%sset default=\"${saved_entry}\"\n", indent);
1713   if (cfg->defaultImage >= FIRST_ENTRY_INDEX && cfg->cfi->setEnv) {   if (cfg->defaultImage >= FIRST_ENTRY_INDEX && cfg->cfi->setEnv) {
1714   char *title;   char *title;
1715   entry = findEntryByIndex(cfg, cfg->defaultImage);   int trueIndex, currentIndex;
1716    
1717     trueIndex = 0;
1718     currentIndex = 0;
1719    
1720     while ((entry = findEntryByIndex(cfg, currentIndex))) {
1721     if (!entry->skip) {
1722     if (trueIndex == cfg->defaultImage) {
1723     break;
1724     }
1725     trueIndex++;
1726     }
1727     currentIndex++;
1728     }
1729   line = getLineByType(LT_MENUENTRY, entry->lines);   line = getLineByType(LT_MENUENTRY, entry->lines);
1730   if (!line)   if (!line)
1731   line = getLineByType(LT_TITLE, entry->lines);   line = getLineByType(LT_TITLE, entry->lines);
# Line 2439  struct singleEntry *findTemplate(struct Line 2452  struct singleEntry *findTemplate(struct
2452   index = 0;   index = 0;
2453   while ((entry = findEntryByIndex(cfg, index))) {   while ((entry = findEntryByIndex(cfg, index))) {
2454   if (suitableImage(entry, prefix, skipRemoved, flags)) {   if (suitableImage(entry, prefix, skipRemoved, flags)) {
2455   int j;   int j, unmodifiedIndex;
2456   for (j = 0; j < index; j++) {  
2457     unmodifiedIndex = index;
2458    
2459     for (j = 0; j < unmodifiedIndex; j++) {
2460   entry2 = findEntryByIndex(cfg, j);   entry2 = findEntryByIndex(cfg, j);
2461   if (entry2->skip)   if (entry2->skip)
2462   index--;   index--;
# Line 2509  void setDefaultImage(struct grubConfig * Line 2525  void setDefaultImage(struct grubConfig *
2525   struct singleEntry *bootEntry, *newDefault;   struct singleEntry *bootEntry, *newDefault;
2526   int indexToVerify, firstKernelEntryIndex, currentLookupIndex;   int indexToVerify, firstKernelEntryIndex, currentLookupIndex;
2527    
2528            /* initialize */
2529            currentLookupIndex = FIRST_ENTRY_INDEX;
2530    
2531   /* handle the two cases where the user explictly picks the default   /* handle the two cases where the user explictly picks the default
2532   * boot entry index as it would exist post-modification */   * boot entry index as it would exist post-modification */
2533    
# Line 2519  void setDefaultImage(struct grubConfig * Line 2538  void setDefaultImage(struct grubConfig *
2538   }   }
2539    
2540   /* Case 2: user picked an arbitrary index as the default boot entry */   /* Case 2: user picked an arbitrary index as the default boot entry */
2541   if (newDefaultBootEntryIndex >= FIRST_ENTRY_INDEX   if (newDefaultBootEntryIndex >= FIRST_ENTRY_INDEX) {
     && config->cfi->defaultIsIndex) {  
2542   indexToVerify = newDefaultBootEntryIndex;   indexToVerify = newDefaultBootEntryIndex;
2543    
2544   /* user chose to make latest boot entry the default */   /* user chose to make latest boot entry the default */
# Line 2553  void setDefaultImage(struct grubConfig * Line 2571  void setDefaultImage(struct grubConfig *
2571   /* check validity of existing default or first-entry-found   /* check validity of existing default or first-entry-found
2572     selection */     selection */
2573   if (defaultKernelPath) {   if (defaultKernelPath) {
2574                    /* we must initialize this */
2575                    firstKernelEntryIndex = 0;
2576   /* user requested first-entry-found */   /* user requested first-entry-found */
2577   if (!findEntryByPath(config, defaultKernelPath,   if (!findEntryByPath(config, defaultKernelPath,
2578       prefix, &firstKernelEntryIndex)) {       prefix, &firstKernelEntryIndex)) {
# Line 2572  void setDefaultImage(struct grubConfig * Line 2592  void setDefaultImage(struct grubConfig *
2592   config->defaultImage++;   config->defaultImage++;
2593   }   }
2594   } else {   } else {
2595   /* use pre-existing default entry */                  /* check to see if the default is stored in the environment */
2596   currentLookupIndex = config->defaultImage;                  if (config->defaultImage < FIRST_ENTRY_INDEX) {
2597                        if (config->defaultImage == DEFAULT_SAVED || config->defaultImage == DEFAULT_SAVED_GRUB2)
2598                        {
2599                            if (config->cfi->defaultIsSaved) {
2600                                if (config->cfi->getEnv) {
2601                                    char *defaultTitle = config->cfi->getEnv(config->cfi, "saved_entry");
2602    
2603                                    if (defaultTitle) {
2604                                        if (isnumber(defaultTitle)) {
2605                                            currentLookupIndex = atoi(defaultTitle);
2606                                        } else {
2607                                            findEntryByTitle(config, defaultTitle, &currentLookupIndex);
2608                                        }
2609                                        /* set the default Image to an actual index */
2610                                        config->defaultImage = currentLookupIndex;
2611                                    }
2612                                }
2613                             }
2614                        }
2615                    } else {
2616                            /* use pre-existing default entry from the file*/
2617                            currentLookupIndex = config->defaultImage;
2618                    }
2619    
2620   if (isAddingBootEntry   if (isAddingBootEntry
2621      && (newBootEntryIndex <= config->defaultImage)) {      && (newBootEntryIndex <= config->defaultImage)) {
# Line 2644  void setFallbackImage(struct grubConfig Line 2686  void setFallbackImage(struct grubConfig
2686   }   }
2687  }  }
2688    
2689  void displayEntry(struct singleEntry *entry, const char *prefix, int index)  void displayEntry(struct grubConfig *config, struct singleEntry *entry, const char *prefix, int index)
2690  {  {
2691   struct singleLine *line;   struct singleLine *line;
2692   char *root = NULL;   char *root = NULL;
# Line 2740  void displayEntry(struct singleEntry *en Line 2782  void displayEntry(struct singleEntry *en
2782    
2783   line = getLineByType(LT_TITLE, entry->lines);   line = getLineByType(LT_TITLE, entry->lines);
2784   if (line) {   if (line) {
2785   printf("title=%s\n", line->elements[1].item);                  char *entryTitle;
2786                    /* if we can extractTitle, then it's a zipl config and
2787                     * if not then we go ahead with what's existed prior */
2788                    entryTitle = extractTitle(config, line);
2789                    if (!entryTitle) {
2790                        entryTitle=line->elements[1].item;
2791                    }
2792     printf("title=%s\n", entryTitle);
2793   } else {   } else {
2794   char *title;   char *title;
2795   line = getLineByType(LT_MENUENTRY, entry->lines);   line = getLineByType(LT_MENUENTRY, entry->lines);
# Line 3156  int displayInfo(struct grubConfig *confi Line 3205  int displayInfo(struct grubConfig *confi
3205   printf("lba\n");   printf("lba\n");
3206   }   }
3207    
3208   displayEntry(entry, prefix, i);   displayEntry(config, entry, prefix, i);
3209    
3210   i++;   i++;
3211   while ((entry = findEntryByPath(config, kernel, prefix, &i))) {   while ((entry = findEntryByPath(config, kernel, prefix, &i))) {
3212   displayEntry(entry, prefix, i);   displayEntry(config, entry, prefix, i);
3213   i++;   i++;
3214   }   }
3215    

Legend:
Removed from v.3021  
changed lines
  Added in v.3031