changes from v1: add *label NULL check

This patch modifies grub_lib.c to add fs label as fourth return value
to grub.enum_device. This can be used on osdetect.lua to create OS
description that is easier to understand, as well as providing pool
names for root-on-zfs setup.

Patch inline and attached. Indentation might look weird do to mixed
use of tab and space (mostly copied from current fs uuid code). Is
there a preference for either style? Should I convert all tabs to
spaces at least for this patch?

diff -Naru grub-extras-master.orig/lua/grub_lib.c
grub-extras-master/lua/grub_lib.c
--- grub-extras-master.orig/lua/grub_lib.c 2013-12-25 01:06:47.000000000 +0700
+++ grub-extras-master/lua/grub_lib.c 2015-03-02 15:10:14.007284753 +0700
@@ -183,7 +183,34 @@
  }
     }

-  lua_call (state, 3, 1);
+  if (! fs->label)
+    lua_pushnil (state);
+  else
+    {
+      int err;
+      char *label;
+
+      err = fs->label (dev, &label);
+      if (err)
+ {
+  grub_errno = 0;
+  lua_pushnil (state);
+ }
+      else
+ {
+  if (label == NULL)
+    {
+      lua_pushnil (state);
+    }
+  else
+    {
+      lua_pushstring (state, label);
+    }
+  grub_free (label);
+ }
+    }
+
+  lua_call (state, 4, 1);
   result = lua_tointeger (state, -1);
   lua_pop (state, 1);
  }
diff -Naru grub-extras-master.orig/lua/grub_lib.c grub-extras-master/lua/grub_lib.c
--- grub-extras-master.orig/lua/grub_lib.c	2013-12-25 01:06:47.000000000 +0700
+++ grub-extras-master/lua/grub_lib.c	2015-03-02 15:10:14.007284753 +0700
@@ -183,7 +183,34 @@
 		}
 	    }
 
-	  lua_call (state, 3, 1);
+	  if (! fs->label)
+	    lua_pushnil (state);
+	  else
+	    {
+	      int err;
+	      char *label;
+
+	      err = fs->label (dev, &label);
+	      if (err)
+		{
+		  grub_errno = 0;
+		  lua_pushnil (state);
+		}
+	      else
+		{
+		  if (label == NULL)
+		    {
+		      lua_pushnil (state);
+		    }
+		  else
+		    {
+		      lua_pushstring (state, label);
+		    }
+		  grub_free (label);
+		}
+	    }
+
+	  lua_call (state, 4, 1);
 	  result = lua_tointeger (state, -1);
 	  lua_pop (state, 1);
 	}
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to