All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] grub-extras/lua: add fs label to grub.enum_device
@ 2015-02-27 11:47 Fajar A. Nugraha
  2015-02-27 11:56 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 11+ messages in thread
From: Fajar A. Nugraha @ 2015-02-27 11:47 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 2016 bytes --]

The original mail, in case it didn't get through (because I used the
wrong sender address):

On Fri, Feb 27, 2015 at 3:41 PM, Fajar A. Nugraha <work@fajar.net> wrote:
>
> Hi,
>
> Is this the right place to ask about possible enhancement to grub-lua?
>
> I'm looking to modify osdetect.lua with the ability to boot
> ubuntu-on-zfs setup. Most of the needed capabilities are already
> there. However I can't find how to get pool name from a device. Grub
> is already able to detect the pool name as label, and it shows up
> correctly when I use "probe -l". Would you be open to modifying
> grub_lib.c so that grub.enum_device will also pass fs label to the
> callback function (currently it pass device, fs, and uuid)?
>
> Or alternatively, in case I missed something obvious, is there a way
> capture the output of "probe -l" and use it on lua? grub.run only
> returns error code and error message.
>


And now for the patch. It's inline below (also attached, in case my
mail client mess this up), created against grub-extras master
(5d12c95d), tested on grub master (66b0e664). The new lua module was
tested by loading both the original osdetect.lua (enum_device (device,
fs, uuid)) and my modified version (function enum_device (device, fs,
uuid, label)), both run fine and the fs label was correctly populated
on my modified version.

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-02-27 18:15:33.002264978 +0700
@@ -183,7 +183,27 @@
  }
     }

-  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
+ {
+  lua_pushstring (state, label);
+  grub_free (label);
+ }
+    }
+
+  lua_call (state, 4, 1);
   result = lua_tointeger (state, -1);
   lua_pop (state, 1);
  }

[-- Attachment #2: lua_enum_device.patch --]
[-- Type: text/x-patch, Size: 708 bytes --]

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-02-27 18:15:33.002264978 +0700
@@ -183,7 +183,27 @@
 		}
 	    }
 
-	  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
+		{
+		  lua_pushstring (state, label);
+		  grub_free (label);
+		}
+	    }
+
+	  lua_call (state, 4, 1);
 	  result = lua_tointeger (state, -1);
 	  lua_pop (state, 1);
 	}

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] grub-extras/lua: add fs label to grub.enum_device
  2015-02-27 11:47 [PATCH] grub-extras/lua: add fs label to grub.enum_device Fajar A. Nugraha
@ 2015-02-27 11:56 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-02-27 12:04   ` Fajar A. Nugraha
  2015-02-27 12:06   ` Andrei Borzenkov
  0 siblings, 2 replies; 11+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-02-27 11:56 UTC (permalink / raw)
  To: The development of GNU GRUB

On 27.02.2015 12:47, Fajar A. Nugraha wrote:
> +  lua_pushstring (state, label);
What happens if label is NULL?


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] grub-extras/lua: add fs label to grub.enum_device
  2015-02-27 11:56 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-02-27 12:04   ` Fajar A. Nugraha
  2015-02-27 12:06   ` Andrei Borzenkov
  1 sibling, 0 replies; 11+ messages in thread
From: Fajar A. Nugraha @ 2015-02-27 12:04 UTC (permalink / raw)
  To: The development of GNU GRUB

On Fri, Feb 27, 2015 at 6:56 PM, Vladimir 'φ-coder/phcoder' Serbinenko
<phcoder@gmail.com> wrote:
> On 27.02.2015 12:47, Fajar A. Nugraha wrote:
>>
>> +  lua_pushstring (state, label);
>
> What happens if label is NULL?

On my test it doesn't throw any errors.

Note that the new code was mostly copy-paste from the original fs->uuid code

###
 if (! fs->uuid)
   lua_pushnil (state);
 else
   {
...
###

New code on my patch:
###
+  if (! fs->label)
+    lua_pushnil (state);
+  else
+    {
...
###

so if label is NULL then it should not reach lua_pushstring (state,
label), but rather run lua_pushnil (state).

-- 
Fajar


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] grub-extras/lua: add fs label to grub.enum_device
  2015-02-27 11:56 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-02-27 12:04   ` Fajar A. Nugraha
@ 2015-02-27 12:06   ` Andrei Borzenkov
  2015-02-27 12:28     ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 1 reply; 11+ messages in thread
From: Andrei Borzenkov @ 2015-02-27 12:06 UTC (permalink / raw)
  To: The development of GNU GRUB

On Fri, Feb 27, 2015 at 2:56 PM, Vladimir 'φ-coder/phcoder' Serbinenko
<phcoder@gmail.com> wrote:
> On 27.02.2015 12:47, Fajar A. Nugraha wrote:
>>
>> +  lua_pushstring (state, label);
>
> What happens if label is NULL?
>

In all cases if grub could mount filesystem it returns strdup(label).
Is it possible that mount fails without setting grub_errno? If yes, it
is probably a bug.

> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] grub-extras/lua: add fs label to grub.enum_device
  2015-02-27 12:06   ` Andrei Borzenkov
@ 2015-02-27 12:28     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-02-27 12:40       ` Fajar A. Nugraha
  2015-02-27 14:15       ` Andrei Borzenkov
  0 siblings, 2 replies; 11+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-02-27 12:28 UTC (permalink / raw)
  To: grub-devel

On 27.02.2015 13:06, Andrei Borzenkov wrote:
> On Fri, Feb 27, 2015 at 2:56 PM, Vladimir 'φ-coder/phcoder' Serbinenko
> <phcoder@gmail.com> wrote:
>> On 27.02.2015 12:47, Fajar A. Nugraha wrote:
>>>
>>> +  lua_pushstring (state, label);
>>
>> What happens if label is NULL?
>>
>
> In all cases if grub could mount filesystem it returns strdup(label).
> Is it possible that mount fails without setting grub_errno? If yes, it
> is probably a bug.
>
Nope. If filesystem has no label (rather than just empty label), it will 
have *label == NULL and return no error which is correct. Same for UUID. 
So unless lua_pushstring has special handling for NULL, this code needs 
to be fixed.
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] grub-extras/lua: add fs label to grub.enum_device
  2015-02-27 12:28     ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2015-02-27 12:40       ` Fajar A. Nugraha
  2015-02-27 12:42         ` Vladimir 'phcoder' Serbinenko
  2015-02-27 14:15       ` Andrei Borzenkov
  1 sibling, 1 reply; 11+ messages in thread
From: Fajar A. Nugraha @ 2015-02-27 12:40 UTC (permalink / raw)
  To: The development of GNU GRUB

On Fri, Feb 27, 2015 at 7:28 PM, Vladimir 'φ-coder/phcoder' Serbinenko
<phcoder@gmail.com> wrote:
> On 27.02.2015 13:06, Andrei Borzenkov wrote:
>>
>> On Fri, Feb 27, 2015 at 2:56 PM, Vladimir 'φ-coder/phcoder' Serbinenko
>> <phcoder@gmail.com> wrote:
>>>
>>> On 27.02.2015 12:47, Fajar A. Nugraha wrote:
>>>>
>>>>
>>>> +  lua_pushstring (state, label);
>>>
>>>
>>> What happens if label is NULL?
>>>
>>
>> In all cases if grub could mount filesystem it returns strdup(label).
>> Is it possible that mount fails without setting grub_errno? If yes, it
>> is probably a bug.
>>
> Nope. If filesystem has no label (rather than just empty label), it will
> have *label == NULL and return no error which is correct. Same for UUID. So
> unless lua_pushstring has special handling for NULL, this code needs to be
> fixed.


Doesn't

if (! fs->label)
    lua_pushnil (state);

do the correct handling? Or is there something I missed, and NULL does
not always evaluate to FALSE?

-- 
Fajar


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] grub-extras/lua: add fs label to grub.enum_device
  2015-02-27 12:40       ` Fajar A. Nugraha
@ 2015-02-27 12:42         ` Vladimir 'phcoder' Serbinenko
  2015-02-27 12:48           ` Fajar A. Nugraha
  0 siblings, 1 reply; 11+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2015-02-27 12:42 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 1355 bytes --]

Le 2015-02-27 13:40, "Fajar A. Nugraha" <list@fajar.net> a écrit :
>
> On Fri, Feb 27, 2015 at 7:28 PM, Vladimir 'φ-coder/phcoder' Serbinenko
> <phcoder@gmail.com> wrote:
> > On 27.02.2015 13:06, Andrei Borzenkov wrote:
> >>
> >> On Fri, Feb 27, 2015 at 2:56 PM, Vladimir 'φ-coder/phcoder' Serbinenko
> >> <phcoder@gmail.com> wrote:
> >>>
> >>> On 27.02.2015 12:47, Fajar A. Nugraha wrote:
> >>>>
> >>>>
> >>>> +  lua_pushstring (state, label);
> >>>
> >>>
> >>> What happens if label is NULL?
> >>>
> >>
> >> In all cases if grub could mount filesystem it returns strdup(label).
> >> Is it possible that mount fails without setting grub_errno? If yes, it
> >> is probably a bug.
> >>
> > Nope. If filesystem has no label (rather than just empty label), it will
> > have *label == NULL and return no error which is correct. Same for
UUID. So
> > unless lua_pushstring has special handling for NULL, this code needs to
be
> > fixed.
>
>
> Doesn't
>
> if (! fs->label)
>     lua_pushnil (state);
>
> do the correct handling? Or is there something I missed, and NULL does
> not always evaluate to FALSE?
>
I was speaking of label, not fs->label
> --
> Fajar
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

[-- Attachment #2: Type: text/html, Size: 2108 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] grub-extras/lua: add fs label to grub.enum_device
  2015-02-27 12:42         ` Vladimir 'phcoder' Serbinenko
@ 2015-02-27 12:48           ` Fajar A. Nugraha
  2015-02-27 12:50             ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 11+ messages in thread
From: Fajar A. Nugraha @ 2015-02-27 12:48 UTC (permalink / raw)
  To: The development of GNU GRUB

On Fri, Feb 27, 2015 at 7:42 PM, Vladimir 'phcoder' Serbinenko
<phcoder@gmail.com> wrote:
>
> Le 2015-02-27 13:40, "Fajar A. Nugraha" <list@fajar.net> a écrit :
>
>
>>
>> On Fri, Feb 27, 2015 at 7:28 PM, Vladimir 'φ-coder/phcoder' Serbinenko
>> <phcoder@gmail.com> wrote:
>> > On 27.02.2015 13:06, Andrei Borzenkov wrote:
>> >>
>> >> On Fri, Feb 27, 2015 at 2:56 PM, Vladimir 'φ-coder/phcoder' Serbinenko
>> >> <phcoder@gmail.com> wrote:
>> >>>
>> >>> On 27.02.2015 12:47, Fajar A. Nugraha wrote:
>> >>>>
>> >>>>
>> >>>> +  lua_pushstring (state, label);
>> >>>
>> >>>
>> >>> What happens if label is NULL?
>> >>>
>> >>
>> >> In all cases if grub could mount filesystem it returns strdup(label).
>> >> Is it possible that mount fails without setting grub_errno? If yes, it
>> >> is probably a bug.
>> >>
>> > Nope. If filesystem has no label (rather than just empty label), it will
>> > have *label == NULL and return no error which is correct. Same for UUID.
>> > So
>> > unless lua_pushstring has special handling for NULL, this code needs to
>> > be
>> > fixed.
>>
>>
>> Doesn't
>>
>> if (! fs->label)
>>     lua_pushnil (state);
>>
>> do the correct handling? Or is there something I missed, and NULL does
>> not always evaluate to FALSE?
>>
> I was speaking of label, not fs->label


Ah, OK.

In that case, won't fs->label be FALSE, and *label (in grub_lib.c,
please correct me if you mean *label in other parts of grub) would
never be defined, and  lua_pushstring(state, label) will never get
called?

-- 
Fajar


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] grub-extras/lua: add fs label to grub.enum_device
  2015-02-27 12:48           ` Fajar A. Nugraha
@ 2015-02-27 12:50             ` Vladimir 'phcoder' Serbinenko
  0 siblings, 0 replies; 11+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2015-02-27 12:50 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 1964 bytes --]

Le 2015-02-27 13:48, "Fajar A. Nugraha" <list@fajar.net> a écrit :
>
> On Fri, Feb 27, 2015 at 7:42 PM, Vladimir 'phcoder' Serbinenko
> <phcoder@gmail.com> wrote:
> >
> > Le 2015-02-27 13:40, "Fajar A. Nugraha" <list@fajar.net> a écrit :
> >
> >
> >>
> >> On Fri, Feb 27, 2015 at 7:28 PM, Vladimir 'φ-coder/phcoder' Serbinenko
> >> <phcoder@gmail.com> wrote:
> >> > On 27.02.2015 13:06, Andrei Borzenkov wrote:
> >> >>
> >> >> On Fri, Feb 27, 2015 at 2:56 PM, Vladimir 'φ-coder/phcoder'
Serbinenko
> >> >> <phcoder@gmail.com> wrote:
> >> >>>
> >> >>> On 27.02.2015 12:47, Fajar A. Nugraha wrote:
> >> >>>>
> >> >>>>
> >> >>>> +  lua_pushstring (state, label);
> >> >>>
> >> >>>
> >> >>> What happens if label is NULL?
> >> >>>
> >> >>
> >> >> In all cases if grub could mount filesystem it returns
strdup(label).
> >> >> Is it possible that mount fails without setting grub_errno? If yes,
it
> >> >> is probably a bug.
> >> >>
> >> > Nope. If filesystem has no label (rather than just empty label), it
will
> >> > have *label == NULL and return no error which is correct. Same for
UUID.
> >> > So
> >> > unless lua_pushstring has special handling for NULL, this code needs
to
> >> > be
> >> > fixed.
> >>
> >>
> >> Doesn't
> >>
> >> if (! fs->label)
> >>     lua_pushnil (state);
> >>
> >> do the correct handling? Or is there something I missed, and NULL does
> >> not always evaluate to FALSE?
> >>
> > I was speaking of label, not fs->label
>
>
> Ah, OK.
>
> In that case, won't fs->label be FALSE, and *label (in grub_lib.c,
> please correct me if you mean *label in other parts of grub) would
> never be defined, and  lua_pushstring(state, label) will never get
> called?
>
fs->label only checks for function availability
> --
> Fajar
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel

[-- Attachment #2: Type: text/html, Size: 3206 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] grub-extras/lua: add fs label to grub.enum_device
  2015-02-27 12:28     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2015-02-27 12:40       ` Fajar A. Nugraha
@ 2015-02-27 14:15       ` Andrei Borzenkov
  2015-02-27 14:33         ` Vladimir 'φ-coder/phcoder' Serbinenko
  1 sibling, 1 reply; 11+ messages in thread
From: Andrei Borzenkov @ 2015-02-27 14:15 UTC (permalink / raw)
  To: The development of GNU GRUB

On Fri, Feb 27, 2015 at 3:28 PM, Vladimir 'φ-coder/phcoder' Serbinenko
<phcoder@gmail.com> wrote:
> On 27.02.2015 13:06, Andrei Borzenkov wrote:
>>
>> On Fri, Feb 27, 2015 at 2:56 PM, Vladimir 'φ-coder/phcoder' Serbinenko
>> <phcoder@gmail.com> wrote:
>>>
>>> On 27.02.2015 12:47, Fajar A. Nugraha wrote:
>>>>
>>>>
>>>> +  lua_pushstring (state, label);
>>>
>>>
>>> What happens if label is NULL?
>>>
>>
>> In all cases if grub could mount filesystem it returns strdup(label).
>> Is it possible that mount fails without setting grub_errno? If yes, it
>> is probably a bug.
>>
> Nope. If filesystem has no label (rather than just empty label), it will
> have *label == NULL and return no error which is correct.

If filesystem has no label it should not define fs->label. Which
filesystem defines fs->label but returns NULL label?

>                                                                                      Same for UUID. So
> unless lua_pushstring has special handling for NULL, this code needs to be
> fixed.
>
>>> _______________________________________________
>>> Grub-devel mailing list
>>> Grub-devel@gnu.org
>>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] grub-extras/lua: add fs label to grub.enum_device
  2015-02-27 14:15       ` Andrei Borzenkov
@ 2015-02-27 14:33         ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 11+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2015-02-27 14:33 UTC (permalink / raw)
  To: The development of GNU GRUB

On 27.02.2015 15:15, Andrei Borzenkov wrote:
> On Fri, Feb 27, 2015 at 3:28 PM, Vladimir 'φ-coder/phcoder' Serbinenko
> <phcoder@gmail.com> wrote:
>> On 27.02.2015 13:06, Andrei Borzenkov wrote:
>>>
>>> On Fri, Feb 27, 2015 at 2:56 PM, Vladimir 'φ-coder/phcoder' Serbinenko
>>> <phcoder@gmail.com> wrote:
>>>>
>>>> On 27.02.2015 12:47, Fajar A. Nugraha wrote:
>>>>>
>>>>>
>>>>> +  lua_pushstring (state, label);
>>>>
>>>>
>>>> What happens if label is NULL?
>>>>
>>>
>>> In all cases if grub could mount filesystem it returns strdup(label).
>>> Is it possible that mount fails without setting grub_errno? If yes, it
>>> is probably a bug.
>>>
>> Nope. If filesystem has no label (rather than just empty label), it will
>> have *label == NULL and return no error which is correct.
>
> If filesystem has no label it should not define fs->label. Which
> filesystem defines fs->label but returns NULL label?
>
HFS+. Filesystem in general has labels but a given instance may not have 
a label.
>>                                                                                       Same for UUID. So
>> unless lua_pushstring has special handling for NULL, this code needs to be
>> fixed.
>>
>>>> _______________________________________________
>>>> Grub-devel mailing list
>>>> Grub-devel@gnu.org
>>>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>>
>>>
>>> _______________________________________________
>>> Grub-devel mailing list
>>> Grub-devel@gnu.org
>>> https://lists.gnu.org/mailman/listinfo/grub-devel
>>>
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-02-27 14:33 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-27 11:47 [PATCH] grub-extras/lua: add fs label to grub.enum_device Fajar A. Nugraha
2015-02-27 11:56 ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-02-27 12:04   ` Fajar A. Nugraha
2015-02-27 12:06   ` Andrei Borzenkov
2015-02-27 12:28     ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-02-27 12:40       ` Fajar A. Nugraha
2015-02-27 12:42         ` Vladimir 'phcoder' Serbinenko
2015-02-27 12:48           ` Fajar A. Nugraha
2015-02-27 12:50             ` Vladimir 'phcoder' Serbinenko
2015-02-27 14:15       ` Andrei Borzenkov
2015-02-27 14:33         ` Vladimir 'φ-coder/phcoder' Serbinenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.