Print this page
fixes + mirror

Split Close
Expand all
Collapse all
          --- old/grub/grub-core/commands/search.c
          +++ new/grub/grub-core/commands/search.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   *
  16   16   *  You should have received a copy of the GNU General Public License
  17   17   *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  18   18   */
  19   19  
  20   20  #include <grub/types.h>
  21   21  #include <grub/misc.h>
  22   22  #include <grub/mm.h>
  23   23  #include <grub/err.h>
  24   24  #include <grub/dl.h>
       25 +#include <grub/zfs/zfs.h>
  25   26  #include <grub/device.h>
  26   27  #include <grub/file.h>
  27   28  #include <grub/env.h>
  28   29  #include <grub/command.h>
  29   30  #include <grub/search.h>
  30   31  #include <grub/i18n.h>
  31   32  #include <grub/disk.h>
  32   33  #include <grub/partition.h>
  33   34  
  34   35  GRUB_MOD_LICENSE ("GPLv3+");
↓ open down ↓ 2 lines elided ↑ open up ↑
  37   38  {
  38   39    struct cache_entry *next;
  39   40    char *key;
  40   41    char *value;
  41   42  };
  42   43  
  43   44  static struct cache_entry *cache;
  44   45  
  45   46  void
  46   47  FUNC_NAME (const char *key, const char *var, int no_floppy,
  47      -           char **hints, unsigned nhints)
       48 +           char **hints, unsigned nhints, int mirror)
  48   49  {
  49   50    int count = 0;
  50   51    int is_cache = 0;
       52 +  grub_uint64_t txg = 0;
  51   53    grub_fs_autoload_hook_t saved_autoload;
  52   54  
  53   55    auto int iterate_device (const char *name);
  54   56    int iterate_device (const char *name)
  55   57    {
  56   58      int found = 0;
  57   59  
  58   60      /* Skip floppy drives when requested.  */
  59   61      if (no_floppy &&
  60   62          name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
↓ open down ↓ 80 lines elided ↑ open up ↑
 141  143                  grub_errno = GRUB_ERR_NONE;
 142  144                }
 143  145            }
 144  146          else
 145  147            grub_errno = GRUB_ERR_NONE;
 146  148        }
 147  149  
 148  150      if (found)
 149  151        {
 150  152          count++;
 151      -        if (var)
 152      -          grub_env_set (var, name);
 153      -        else
      153 +        if (var) {
      154 +          if (! mirror) {
      155 +            grub_env_set (var, name);
      156 +          } else {
      157 +            grub_uint64_t tmp_txg = 0;
      158 +            char * nvlist = NULL;
      159 +            grub_device_t dev = grub_device_open (name);
      160 +            if (! dev) {
      161 +              grub_errno = GRUB_ERR_BAD_DEVICE;
      162 +              return 0;
      163 +            }
      164 +            grub_errno = grub_zfs_fetch_nvlist (dev, &nvlist);
      165 +            grub_device_close (dev);
      166 +            if (grub_errno)
      167 +              return 0;
      168 +            grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_TXG, &tmp_txg);
      169 +            if (tmp_txg > txg) {
      170 +              grub_env_set (var, name);
      171 +              txg = tmp_txg;
      172 +            }
      173 +            grub_free (nvlist);
      174 +          }
      175 +        } else {
 154  176            grub_printf (" %s", name);
      177 +        }
 155  178        }
 156  179  
 157  180      grub_errno = GRUB_ERR_NONE;
 158      -    return (found && var);
      181 +    return (found && var && !mirror);
 159  182    }
 160  183  
 161  184    auto int part_hook (grub_disk_t disk, const grub_partition_t partition);
 162  185    int part_hook (grub_disk_t disk, const grub_partition_t partition)
 163  186    {
 164  187      char *partition_name, *devname;
 165  188      int ret;
 166  189  
 167  190      partition_name = grub_partition_get_name (partition);
 168  191      if (! partition_name)
↓ open down ↓ 104 lines elided ↑ open up ↑
 273  296  }
 274  297  
 275  298  static grub_err_t
 276  299  grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc,
 277  300                      char **args)
 278  301  {
 279  302    if (argc == 0)
 280  303      return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
 281  304  
 282  305    FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0, (args + 2),
 283      -             argc > 2 ? argc - 2 : 0);
      306 +             argc > 2 ? argc - 2 : 0, 0);
 284  307  
 285  308    return grub_errno;
 286  309  }
 287  310  
 288  311  static grub_command_t cmd;
 289  312  
 290  313  #ifdef DO_SEARCH_FILE
 291  314  GRUB_MOD_INIT(search_fs_file)
 292  315  #elif defined (DO_SEARCH_FS_UUID)
 293  316  GRUB_MOD_INIT(search_fs_uuid)
↓ open down ↓ 20 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX