From 549e9e2a1f4d655cf186e1206ee9298e0aba6854 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <phcoder@gmail.com>
Date: Sat, 15 Jul 2023 23:10:12 +0200
Subject: [PATCH] grub-fstest: Add a new command zfs-bootfs.

This is useful to check zfs-bootfs command.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
---
 util/grub-fstest.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/util/grub-fstest.c b/util/grub-fstest.c
index 25ae52ab6..06ca6a4cf 100644
--- a/util/grub-fstest.c
+++ b/util/grub-fstest.c
@@ -69,7 +69,8 @@ enum {
   CMD_BLOCKLIST,
   CMD_TESTLOAD,
   CMD_ZFSINFO,
-  CMD_XNU_UUID
+  CMD_XNU_UUID,
+  CMD_ZFS_BOOTFS
 };
 #define BUF_SIZE  32256
 
@@ -441,6 +442,9 @@ fstest (int n)
     case CMD_ZFSINFO:
       execute_command ("zfsinfo", n, args);
       break;
+    case CMD_ZFS_BOOTFS:
+      execute_command ("zfs-bootfs", n, args);
+      break;
     case CMD_CP:
       cmd_cp (args[0], args[1]);
       break;
@@ -518,6 +522,7 @@ static struct argp_option options[] = {
   {N_("crc FILE"), 0, 0     , OPTION_DOC, N_("Get crc32 checksum of FILE."), 1},
   {N_("blocklist FILE"), 0, 0, OPTION_DOC, N_("Display blocklist of FILE."), 1},
   {N_("xnu_uuid DEVICE"), 0, 0, OPTION_DOC, N_("Compute XNU UUID of the device."), 1},
+  {N_("zfs-bootfs ZFS_DATASET"), 0, 0, OPTION_DOC, N_("Compute zfs dataset bootpath."), 1},
 
   {"root",      'r', N_("DEVICE_NAME"), 0, N_("Set root device."),                 2},
   {"skip",      's', N_("NUM"),           0, N_("Skip N bytes from output file."),   2},
@@ -712,6 +717,11 @@ argp_parser (int key, char *arg, struct argp_state *state)
 	  cmd = CMD_XNU_UUID;
 	  nparm = 0;
 	}
+      else if (grub_strcmp (arg, "zfs-bootfs") == 0)
+	{
+	  cmd = CMD_ZFS_BOOTFS;
+	  nparm = 0;
+	}
       else
 	{
 	  fprintf (stderr, _("Invalid command %s.\n"), arg);
-- 
2.39.2

