Print this page
grub patch
*** 182,206 ****
return GRUB_ERR_NONE;
}
static grub_err_t
! get_bootpath (char *nvlist, char **bootpath, char **devid)
{
char *type = 0;
type = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_TYPE);
if (!type)
return grub_errno;
if (grub_strcmp (type, VDEV_TYPE_DISK) == 0)
{
*bootpath = grub_zfs_nvlist_lookup_string (nvlist,
ZPOOL_CONFIG_PHYS_PATH);
*devid = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_DEVID);
! if (!*bootpath || !*devid)
{
grub_free (*bootpath);
grub_free (*devid);
*bootpath = 0;
*devid = 0;
--- 182,208 ----
return GRUB_ERR_NONE;
}
static grub_err_t
! get_bootpath (char *nvlist, char **bootpath, char **devid, grub_uint64_t inguid)
{
char *type = 0;
+ grub_uint64_t diskguid = 0;
type = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_TYPE);
if (!type)
return grub_errno;
if (grub_strcmp (type, VDEV_TYPE_DISK) == 0)
{
+ grub_zfs_nvlist_lookup_uint64 (nvlist, "guid", &diskguid);
*bootpath = grub_zfs_nvlist_lookup_string (nvlist,
ZPOOL_CONFIG_PHYS_PATH);
*devid = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_DEVID);
! if (!*bootpath || !*devid || (diskguid != inguid))
{
grub_free (*bootpath);
grub_free (*devid);
*bootpath = 0;
*devid = 0;
*** 221,231 ****
child = grub_zfs_nvlist_lookup_nvlist_array (nvlist,
ZPOOL_CONFIG_CHILDREN,
i);
! get_bootpath (child, bootpath, devid);
grub_free (child);
if (*bootpath && *devid)
return GRUB_ERR_NONE;
--- 223,233 ----
child = grub_zfs_nvlist_lookup_nvlist_array (nvlist,
ZPOOL_CONFIG_CHILDREN,
i);
! get_bootpath (child, bootpath, devid, inguid);
grub_free (child);
if (*bootpath && *devid)
return GRUB_ERR_NONE;
*** 338,353 ****
char *nv = 0;
char *bootpath = 0, *devid = 0;
char *fsname;
char *bootfs;
char *poolname;
! grub_uint64_t mdnobj;
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
devname = grub_file_get_device_name (args[0]);
if (grub_errno)
return grub_errno;
dev = grub_device_open (devname);
grub_free (devname);
--- 340,359 ----
char *nv = 0;
char *bootpath = 0, *devid = 0;
char *fsname;
char *bootfs;
char *poolname;
! char def_path[512];
! struct grub_zfs_data * data;
! grub_uint64_t mdnobj, guid;
! int def = 0;
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
devname = grub_file_get_device_name (args[0]);
+
if (grub_errno)
return grub_errno;
dev = grub_device_open (devname);
grub_free (devname);
*** 360,371 ****
if (fsname)
fsname++;
else
fsname = args[0];
! if (!err)
err = grub_zfs_getmdnobj (dev, fsname, &mdnobj);
grub_device_close (dev);
if (err)
return err;
--- 366,383 ----
if (fsname)
fsname++;
else
fsname = args[0];
! if (grub_strcmp(fsname, "default") == 0)
! ++def;
!
! if (! def) {
err = grub_zfs_getmdnobj (dev, fsname, &mdnobj);
+ } else {
+ err = get_default_bootfs_obj(dev, def_path, &mdnobj);
+ }
grub_device_close (dev);
if (err)
return err;
*** 377,389 ****
grub_error (GRUB_ERR_BAD_FS, "No poolname found");
return grub_errno;
}
nv = grub_zfs_nvlist_lookup_nvlist (nvlist, ZPOOL_CONFIG_VDEV_TREE);
! if (nv)
! get_bootpath (nv, &bootpath, &devid);
grub_free (nv);
grub_free (nvlist);
bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu%s%s%s%s%s%s",
--- 389,402 ----
grub_error (GRUB_ERR_BAD_FS, "No poolname found");
return grub_errno;
}
nv = grub_zfs_nvlist_lookup_nvlist (nvlist, ZPOOL_CONFIG_VDEV_TREE);
+ grub_zfs_nvlist_lookup_uint64 (nvlist, "guid", &guid);
! if (nv && guid)
! get_bootpath (nv, &bootpath, &devid, guid);
grub_free (nv);
grub_free (nvlist);
bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu%s%s%s%s%s%s",
*** 399,408 ****
--- 412,426 ----
if (argc >= 2)
grub_env_set (args[1], bootfs);
else
grub_printf ("%s\n", bootfs);
+ if ((def) && (argc >= 3))
+ grub_env_set(args[2], def_path);
+ else if (def)
+ grub_printf("%s\n", def_path);
+
grub_free (bootfs);
grub_free (poolname);
grub_free (bootpath);
grub_free (devid);