File access library for lua
PATCH 1/1 File access library for lua
Hi,
I've added a few function in the lua grub library to access files:
enum_device - enumerate devicesenum_file - enumerate filesfile_open - open filefile_close - close filefile_seek - seek filefile_read - read n bytesfile_getline - read a linefile_getsize - get file sizefile_getpos - get current read position
Here is an example:
#!lua
function enum_device (name)
print (name)
return 0
end
function enum_file (name, is_dir)
print (is_dir, name)
return 0
end
grub.enum_device (enum_device)
grub.enum_file ("/boot/grub", enum_file)
f = grub.file_open ("/boot/grub/grub.cfg")
print (grub.file_getsize (f))
print (grub.file_getline (f))
print (grub.file_getline (f))
print (grub.file_seek (f, 0))
print (grub.file_read (f, 10))
print (grub.file_getpos (f))
grub.file_close (f);
And now after file operation, the result is saved in global variable grub_errno and grub_errmsg (lua variable), for example:
f = grub.file_open ("/abcde")
if (f == nil) then
print (grub_errno, grub_errmsg)
fi
I also enable the string library from lua.
Signature · 1 line
Bean
conf/common.rmk +2 -3
@@ -519,15 +519,14 @@ lua_mod_SOURCES = script/lua/lapi.c script/lua/lcode.c script/lua/ldebug.c \ script/lua/lstate.c script/lua/lstring.c script/lua/ltable.c \ script/lua/ltm.c script/lua/lundump.c script/lua/lvm.c \ script/lua/lzio.c script/lua/lauxlib.c script/lua/lbaselib.c \ - script/lua/linit.c script/lua/ltablib.c \ + script/lua/linit.c script/lua/ltablib.c script/lua/lstrlib.c \ script/lua/grub_main.c script/lua/grub_lib.c lua_mod_CFLAGS = $(COMMON_CFLAGS) lua_mod_LDFLAGS = $(COMMON_LDFLAGS) # Extra libraries for lua # script/lua/lmathlib.c script/lua/loslib.c script/lua/liolib.c -# script/lua/lstrlib.c script/lua/ldblib.c script/lua/ltablib.c -# script/lua/loadlib.c +# script/lua/ldblib.c script/lua/loadlib.c # Common Video Subsystem specific modules. pkglib_MODULES += video.mod videotest.mod bitmap.mod tga.mod jpeg.mod \
script/lua/grub_lib.c +258 -10
296 lines not on this page · raw message
script/lua/grub_lua.h +22 -16
@@ -77,26 +77,28 @@ iscntrl (int c) }static inline int -strcspn (const char *s1,const char *s2) +isupper (int c) { -int size =0 ; - -while (*s1) - { -const char *p = s2; +return ((c >='A' ) && (c <='Z' )); +} -while (*p) - { -if (*s1 == *p) -return size; - p++; - } +static inline int +islower (int c) +{ +return ((c >='a' ) && (c <='z' )); +} - s1++; - size++; - } +static inline int +ispunct (int c) +{ +return ((!isspace (c)) && (!isalnum (c))); +} -return size; +static inline int +isxdigit (int c) +{ +return (isdigit (c) || ((c >='a' ) && (c <='f' )) || + ((c >='A' ) && (c <='F' ))); } static inline int
@@ -105,4 +107,8 @@ abs (int c) return (c >= 0) ? : -c; } +int strcspn (const char *s1,const char *s2); +char *strpbrk (const char *s1,const char *s2); +void *memchr (const void *s,int c,size_t n); +#endif
script/lua/grub_main.c +55 -0
61 lines not on this page · raw message
script/lua/linit.c +1 -1
@@ -20,7 +20,7 @@ static const luaL_Reg lualibs[] = { {LUA_TABLIBNAME, luaopen_table},// {LUA_IOLIBNAME, luaopen_io}, // {LUA_OSLIBNAME, luaopen_os}, -// {LUA_STRLIBNAME, luaopen_string}, + {LUA_STRLIBNAME, luaopen_string},// {LUA_MATHLIBNAME, luaopen_math}, // {LUA_DBLIBNAME, luaopen_debug}, {NULL, NULL}
Quoted 1 line · Bean
I've added a few function in the lua grub library to access files:
...
Quoted 1 line
I also enable the string library from lua.
The patch doesn't introduce any compiler warnings, and that's good.
It makes lua.mod bigger by about 10%, but it's very little compared to the added functionality.
Please don't add trailing whitespace. STGit detects it in two places.
There are several cases of missing spaces before parentheses.
We probably need NESTED_FUNC_ATTR in the dir definition in struct grub_fs, as it takes two arguments. But is a separate issue.
I'm feeling uneasy about having a parser in GRUB that is not used by default, but it's not related to the quality of the patch.
Signature · 2 lines
Regards, Pavel Roskin
Hi,
Quoted 10 lines · Pavel Roskin
Quoted 1 line · Bean
I've added a few function in the lua grub library to access files:
...
Quoted 1 line
I also enable the string library from lua.
The patch doesn't introduce any compiler warnings, and that's good.
It makes lua.mod bigger by about 10%, but it's very little compared to the added functionality.
This is probably due to the enable of string library, the file access function itself should be quite small.
Quoted 10 lines
Please don't add trailing whitespace. STGit detects it in two places.
There are several cases of missing spaces before parentheses.
We probably need
NESTED_FUNC_ATTRin the dir definition in structgrub_fs, as it takes two arguments. But is a separate issue.I'm feeling uneasy about having a parser in GRUB that is not used by default, but it's not related to the quality of the patch.
Actually, this is about to change. The file function here can be used in a script osdetect.lua to generate menu items at runtime, and I also plans to integrate lua with menu viewer.
Quoted 11 lines
--
Regards,
Pavel Roskin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Bean
Quoted 3 lines · Bean
Actually, this is about to change. The file function here can be used in a script osdetect.lua to generate menu items at runtime, and I also plans to integrate lua with menu viewer.
OK, that sounds interesting!
Signature · 2 lines
Regards, Pavel Roskin
Quoted 5 lines · Bean
Quoted 3 lines
I'm feeling uneasy about having a parser in GRUB that is not used by default, but it's not related to the quality of the patch.
Actually, this is about to change.
I don't mind LUA being supported if it's useful for some users, but I'm not satisfied with ditching GRUB scripting engine with something external.
We really should discuss it with Marco or Okuji before changing the default parser to something else.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 5 lines · Robert Millan
Quoted 4 lines · Bean
Quoted 3 lines
I'm feeling uneasy about having a parser in GRUB that is not used by default, but it's not related to the quality of the patch.
Quoted 7 lines
Quoted 1 line
Actually, this is about to change.
I don't mind LUA being supported if it's useful for some users, but I'm not satisfied with ditching GRUB scripting engine with something external.
We really should discuss it with Marco or Okuji before changing the default parser to something else.
Hi,
No need to change the default parser, with the #! syntax, we can call the lua script from main grub.cfg, and the parser will switch back to sh on return, something like this:
grub.cfg:
source osdetect.lua
...
osdetect.lua:
#!lua
...
Quoted 14 lines
--
Robert MillanThe DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Bean
Quoted 11 lines · Bean
Quoted 10 lines · Robert Millan
Quoted 5 lines · Bean
Quoted 3 lines
I'm feeling uneasy about having a parser in GRUB that is not used by default, but it's not related to the quality of the patch.
Actually, this is about to change.
I don't mind LUA being supported if it's useful for some users, but I'm not satisfied with ditching GRUB scripting engine with something external.
Quoted 8 lines
Quoted 2 lines
We really should discuss it with Marco or Okuji before changing the default parser to something else.
Hi,
No need to change the default parser, with the #! syntax, we can call the lua script from main grub.cfg, and the parser will switch back to sh on return, something like this:
Ok, that's nice. I was more thinking about our grub.cfg-generation scripts though. I think those should stay with the current parser.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Hi,
Update for this patch:
1, enum_device now pass fs and uuid as well
2, enum_file change parameter order, now the callback function is the first, path is the second
3, add parameter checking for library function
4, add three function
file_eof - test if eof is encounter for a filefile_exist - test if a file existsadd_menu - add menu item
I also add a script osdetect.lua which can detect Windows 2K/NT/XP/Vista and linux at runtime, to use it, add this in grub.cfg:
source osdetect.lua
Signature · 1 line
Bean
conf/common.rmk +2 -3
@@ -519,15 +519,14 @@ lua_mod_SOURCES = script/lua/lapi.c script/lua/lcode.c script/lua/ldebug.c \ script/lua/lstate.c script/lua/lstring.c script/lua/ltable.c \ script/lua/ltm.c script/lua/lundump.c script/lua/lvm.c \ script/lua/lzio.c script/lua/lauxlib.c script/lua/lbaselib.c \ - script/lua/linit.c script/lua/ltablib.c \ + script/lua/linit.c script/lua/ltablib.c script/lua/lstrlib.c \ script/lua/grub_main.c script/lua/grub_lib.c lua_mod_CFLAGS = $(COMMON_CFLAGS) lua_mod_LDFLAGS = $(COMMON_LDFLAGS) # Extra libraries for lua # script/lua/lmathlib.c script/lua/loslib.c script/lua/liolib.c -# script/lua/lstrlib.c script/lua/ldblib.c script/lua/ltablib.c -# script/lua/loadlib.c +# script/lua/ldblib.c script/lua/loadlib.c # Common Video Subsystem specific modules. pkglib_MODULES += video.mod videotest.mod bitmap.mod tga.mod jpeg.mod \
script/lua/grub_lib.c +351 -21
417 lines not on this page · raw message
script/lua/grub_lua.h +22 -16
@@ -77,26 +77,28 @@ iscntrl (int c) }static inline int -strcspn (const char *s1,const char *s2) +isupper (int c) { -int size =0 ; - -while (*s1) - { -const char *p = s2; +return ((c >='A' ) && (c <='Z' )); +} -while (*p) - { -if (*s1 == *p) -return size; - p++; - } +static inline int +islower (int c) +{ +return ((c >='a' ) && (c <='z' )); +} - s1++; - size++; - } +static inline int +ispunct (int c) +{ +return ((!isspace (c)) && (!isalnum (c))); +} -return size; +static inline int +isxdigit (int c) +{ +return (isdigit (c) || ((c >='a' ) && (c <='f' )) || + ((c >='A' ) && (c <='F' ))); } static inline int
@@ -105,4 +107,8 @@ abs (int c) return (c >= 0) ? : -c; } +int strcspn (const char *s1,const char *s2); +char *strpbrk (const char *s1,const char *s2); +void *memchr (const void *s,int c,size_t n); +#endif
script/lua/grub_main.c +55 -0
61 lines not on this page · raw message
script/lua/linit.c +1 -1
@@ -20,7 +20,7 @@ static const luaL_Reg lualibs[] = { {LUA_TABLIBNAME, luaopen_table},// {LUA_IOLIBNAME, luaopen_io}, // {LUA_OSLIBNAME, luaopen_os}, -// {LUA_STRLIBNAME, luaopen_string}, + {LUA_STRLIBNAME, luaopen_string},// {LUA_MATHLIBNAME, luaopen_math}, // {LUA_DBLIBNAME, luaopen_debug}, {NULL, NULL}
util/osdetect.lua new file +84 -0
84 lines not on this page · raw message
Quoted 10 lines · Bean
Hi,
Update for this patch:
1,
enum_devicenow pass fs and uuid as well
2,enum_filechange parameter order, now the callback function is the first, path is the second
3, add parameter checking for library function
4, add three function
Quoted 3 lines
file_eof- test if eof is encounter for a filefile_exist- test if a file existsadd_menu- add menu item
The new patch introduces a warning:
script/lua/grub_lib.c: In function 'grub_lua_add_menu':script/lua/grub_lib.c:394: warning: pointer targets in passing argument 3 of 'luaL_checklstring' differ in signedness script/lua/lauxlib.h:51: note: expected 'size_t *' but argument is of type 'int *'
Fix:
script/lua/grub_lib.c +2 -1
@@ -388,7 +388,8 @@ grub_lua_file_exist (lua_State *state)static int grub_lua_add_menu (lua_State *state) { -int len, n; +int n; +size_t len;const char *source; source =luaL_checklstring (state,1 , &len);
Quoted 4 lines
I also add a script osdetect.lua which can detect Windows 2K/NT/XP/Vista and linux at runtime, to use it, add this in grub.cfg:
source osdetect.lua
It didn't find Linux for me, but it found the "Other OS", which is actually FreeDOS.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 40 lines · Pavel Roskin
Quoted 10 lines · Bean
Hi,
Update for this patch:
1,
enum_devicenow pass fs and uuid as well
2,enum_filechange parameter order, now the callback function is the first, path is the second
3, add parameter checking for library function
4, add three functionQuoted 3 lines
file_eof- test if eof is encounter for a filefile_exist- test if a file existsadd_menu- add menu itemThe new patch introduces a warning:
script/lua/grub_lib.c: In function 'grub_lua_add_menu':script/lua/grub_lib.c:394: warning: pointer targets in passing argument 3 of 'luaL_checklstring' differ in signednessscript/lua/lauxlib.h:51: note: expected 'size_t*' but argument is of type 'int *'Fix:
script/lua/grub_lib.c +0
-0@@ -388,7 +388,8 @@ grub_lua_file_exist (lua_State *state)static int
grub_lua_add_menu (lua_State*state)
{
- int len, n;
+ int n;
+ size_t len;
const char *source;source =
luaL_checklstring(state, 1, &len);
Quoted 7 lines
Quoted 4 lines
I also add a script osdetect.lua which can detect Windows 2K/NT/XP/Vista and linux at runtime, to use it, add this in grub.cfg:
source osdetect.lua
It didn't find Linux for me, but it found the "Other OS", which is actually FreeDOS.
What's the name of kernel and initrd.img ?
Quoted 11 lines
--
Regards,
Pavel Roskin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Bean
Quoted 1 line · Bean
What's the name of kernel and initrd.img ?
vmlinuz-2.6.30-wl and initrd-2.6.30-wl.img
Signature · 2 lines
Regards, Pavel Roskin
Quoted 5 lines · Pavel Roskin
Quoted 1 line · Bean
What's the name of kernel and initrd.img ?
vmlinuz-2.6.30-wl and initrd-2.6.30-wl.img
Hi,
Oh, find the bug now, try this one.
Quoted 11 lines
--
Regards,
Pavel Roskin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Bean
conf/common.rmk +2 -3
@@ -519,15 +519,14 @@ lua_mod_SOURCES = script/lua/lapi.c script/lua/lcode.c script/lua/ldebug.c \ script/lua/lstate.c script/lua/lstring.c script/lua/ltable.c \ script/lua/ltm.c script/lua/lundump.c script/lua/lvm.c \ script/lua/lzio.c script/lua/lauxlib.c script/lua/lbaselib.c \ - script/lua/linit.c script/lua/ltablib.c \ + script/lua/linit.c script/lua/ltablib.c script/lua/lstrlib.c \ script/lua/grub_main.c script/lua/grub_lib.c lua_mod_CFLAGS = $(COMMON_CFLAGS) lua_mod_LDFLAGS = $(COMMON_LDFLAGS) # Extra libraries for lua # script/lua/lmathlib.c script/lua/loslib.c script/lua/liolib.c -# script/lua/lstrlib.c script/lua/ldblib.c script/lua/ltablib.c -# script/lua/loadlib.c +# script/lua/ldblib.c script/lua/loadlib.c # Common Video Subsystem specific modules. pkglib_MODULES += video.mod videotest.mod bitmap.mod tga.mod jpeg.mod \
script/lua/grub_lib.c +353 -21
419 lines not on this page · raw message
script/lua/grub_lua.h +22 -16
@@ -77,26 +77,28 @@ iscntrl (int c) }static inline int -strcspn (const char *s1,const char *s2) +isupper (int c) { -int size =0 ; - -while (*s1) - { -const char *p = s2; +return ((c >='A' ) && (c <='Z' )); +} -while (*p) - { -if (*s1 == *p) -return size; - p++; - } +static inline int +islower (int c) +{ +return ((c >='a' ) && (c <='z' )); +} - s1++; - size++; - } +static inline int +ispunct (int c) +{ +return ((!isspace (c)) && (!isalnum (c))); +} -return size; +static inline int +isxdigit (int c) +{ +return (isdigit (c) || ((c >='a' ) && (c <='f' )) || + ((c >='A' ) && (c <='F' ))); } static inline int
@@ -105,4 +107,8 @@ abs (int c) return (c >= 0) ? : -c; } +int strcspn (const char *s1,const char *s2); +char *strpbrk (const char *s1,const char *s2); +void *memchr (const void *s,int c,size_t n); +#endif
script/lua/grub_main.c +55 -0
61 lines not on this page · raw message
script/lua/linit.c +1 -1
@@ -20,7 +20,7 @@ static const luaL_Reg lualibs[] = { {LUA_TABLIBNAME, luaopen_table},// {LUA_IOLIBNAME, luaopen_io}, // {LUA_OSLIBNAME, luaopen_os}, -// {LUA_STRLIBNAME, luaopen_string}, + {LUA_STRLIBNAME, luaopen_string},// {LUA_MATHLIBNAME, luaopen_math}, // {LUA_DBLIBNAME, luaopen_debug}, {NULL, NULL}
util/osdetect.lua new file +94 -0
94 lines not on this page · raw message
Quoted 1 line · Bean
Oh, find the bug now, try this one.
This one fails to find anything:
sh:grub> source /boot/grub/osdetect.lua
error: Lua: grub:1: attempt to call field 'enum_device' (a nil value) sh:grub>
Signature · 2 lines
Regards, Pavel Roskin
Quoted 9 lines · Pavel Roskin
Quoted 1 line · Bean
Oh, find the bug now, try this one.
This one fails to find anything:
sh:grub> source
/boot/grub/osdetect.lua
error: Lua: grub:1: attempt to call field 'enum_device' (a nil value) sh:grub>
Hi,
strange, it's working here, what's the device list ?
Quoted 11 lines
--
Regards,
Pavel Roskin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Bean
Quoted 1 line · Bean
strange, it's working here, what's the device list ?
My mistake. I installed an unpatched GRUB.
The entries are created now. However, the initrd is not picked up. The old kernel (vmlinuz-2.6.30-wl.old) goes before the new one (vmlinuz-2.6.30-wl). And most importantly, the syntax for the root command is wrong.
"root hd0,3" has not effect. "root (hd0,3)" and "root=hd0,3" work. Yes, that's a bug in the root command.
Signature · 2 lines
Regards, Pavel Roskin
Hi,
Some bug fix for osdetect.lua, it also detect windows 98/me, freedos, msdos and freebsd.
Extend the function of grub.file_exist to allow testing multiple names at the same time, this simplify osdetect.lua.
Quoted 24 lines · Pavel Roskin
Quoted 1 line · Bean
strange, it's working here, what's the device list ?
My mistake. I installed an unpatched GRUB.
The entries are created now. However, the initrd is not picked up. The old kernel (vmlinuz-2.6.30-wl.old) goes before the new one (vmlinuz-2.6.30-wl). And most importantly, the syntax for the root command is wrong.
"root hd0,3" has not effect. "root (hd0,3)" and "root=hd0,3" work. Yes, that's a bug in the root command.
--
Regards,
Pavel Roskin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Bean
conf/common.rmk +2 -3
@@ -519,15 +519,14 @@ lua_mod_SOURCES = script/lua/lapi.c script/lua/lcode.c script/lua/ldebug.c \ script/lua/lstate.c script/lua/lstring.c script/lua/ltable.c \ script/lua/ltm.c script/lua/lundump.c script/lua/lvm.c \ script/lua/lzio.c script/lua/lauxlib.c script/lua/lbaselib.c \ - script/lua/linit.c script/lua/ltablib.c \ + script/lua/linit.c script/lua/ltablib.c script/lua/lstrlib.c \ script/lua/grub_main.c script/lua/grub_lib.c lua_mod_CFLAGS = $(COMMON_CFLAGS) lua_mod_LDFLAGS = $(COMMON_LDFLAGS) # Extra libraries for lua # script/lua/lmathlib.c script/lua/loslib.c script/lua/liolib.c -# script/lua/lstrlib.c script/lua/ldblib.c script/lua/ltablib.c -# script/lua/loadlib.c +# script/lua/ldblib.c script/lua/loadlib.c # Common Video Subsystem specific modules. pkglib_MODULES += video.mod videotest.mod bitmap.mod tga.mod jpeg.mod \
script/lua/grub_lib.c +359 -21
425 lines not on this page · raw message
script/lua/grub_lua.h +22 -16
@@ -77,26 +77,28 @@ iscntrl (int c) }static inline int -strcspn (const char *s1,const char *s2) +isupper (int c) { -int size =0 ; - -while (*s1) - { -const char *p = s2; +return ((c >='A' ) && (c <='Z' )); +} -while (*p) - { -if (*s1 == *p) -return size; - p++; - } +static inline int +islower (int c) +{ +return ((c >='a' ) && (c <='z' )); +} - s1++; - size++; - } +static inline int +ispunct (int c) +{ +return ((!isspace (c)) && (!isalnum (c))); +} -return size; +static inline int +isxdigit (int c) +{ +return (isdigit (c) || ((c >='a' ) && (c <='f' )) || + ((c >='A' ) && (c <='F' ))); } static inline int
@@ -105,4 +107,8 @@ abs (int c) return (c >= 0) ? : -c; } +int strcspn (const char *s1,const char *s2); +char *strpbrk (const char *s1,const char *s2); +void *memchr (const void *s,int c,size_t n); +#endif
script/lua/grub_main.c +55 -0
61 lines not on this page · raw message
script/lua/linit.c +1 -1
@@ -20,7 +20,7 @@ static const luaL_Reg lualibs[] = { {LUA_TABLIBNAME, luaopen_table},// {LUA_IOLIBNAME, luaopen_io}, // {LUA_OSLIBNAME, luaopen_os}, -// {LUA_STRLIBNAME, luaopen_string}, + {LUA_STRLIBNAME, luaopen_string},// {LUA_MATHLIBNAME, luaopen_math}, // {LUA_DBLIBNAME, luaopen_debug}, {NULL, NULL}
util/osdetect.lua new file +105 -0
105 lines not on this page · raw message
Quoted 4 lines · Bean
Hi,
Some bug fix for osdetect.lua, it also detect windows 98/me, freedos, msdos and freebsd.
Why FressDOS and FressBSD? I assume it's typos. Why isn't Linux capitalized? MS-DOS is written with a dash. "Windows Vista bootmgr" should be "Windows Vista" and "Windows NT/2000/XP loader" should be "Windows NT/2000/XP". It's not like we are just booting the loaders.
inird should be initrd. Please add check for the Fedora style names for initrd, namely "initrd-KVER.img". Or maybe you just missed ".img" in the second check?
Quoted 2 lines
Extend the function of grub.file_exist to allow testing multiple names at the same time, this simplify osdetect.lua.
The change to grub_lua_file_exist() is dubious. It's not clear why the requirement is that all files exist. Maybe I don't know the style of lua, but I think it's wrong to hardcode the AND logic just because one script would benefit from it.
If we consider e.g. the wildcard expansion in make, it will return a non-empty value if any file exists, i.e. the OR logic is used.
I suggest that you split the lua.mod changes and osdetect.lua. The later is obviously a bikeshed issue that can be discussed for a long time. The former needs a more technical consideration.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 10 lines · Pavel Roskin
Quoted 4 lines · Bean
Hi,
Some bug fix for osdetect.lua, it also detect windows 98/me, freedos, msdos and freebsd.
Why FressDOS and FressBSD? I assume it's typos. Why isn't Linux capitalized? MS-DOS is written with a dash. "Windows Vista bootmgr" should be "Windows Vista" and "Windows NT/2000/XP loader" should be "Windows NT/2000/XP". It's not like we are just booting the loaders.
But when we're booting a kernel (Linux) we just say that. Shouldn't we be consistent and say "bootmgr" and "ntldr" too?
Btw, to make this even more interesting, there's also freeldr, which can be used to boot either Windows NT/2000/XP or ReactOS.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 7 lines · Robert Millan
Quoted 6 lines · Pavel Roskin
Quoted 4 lines · Bean
Hi,
Some bug fix for osdetect.lua, it also detect windows 98/me, freedos, msdos and freebsd.
Quoted 7 lines
Quoted 4 lines
Why FressDOS and FressBSD? I assume it's typos. Why isn't Linux capitalized? MS-DOS is written with a dash. "Windows Vista bootmgr" should be "Windows Vista" and "Windows NT/2000/XP loader" should be "Windows NT/2000/XP". It's not like we are just booting the loaders.
But when we're booting a kernel (Linux) we just say that. Shouldn't we be consistent and say "bootmgr" and "ntldr" too?
The difference is that we are using chainloader to boot Windows, so we treat is as one system. If we were loading ntldr from GRUB, then it would be appropriate to mention it.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 11 lines · Pavel Roskin
Quoted 4 lines · Bean
Hi,
Some bug fix for osdetect.lua, it also detect windows 98/me, freedos, msdos and freebsd.
Why FressDOS and FressBSD? I assume it's typos. Why isn't Linux capitalized? MS-DOS is written with a dash. "Windows Vista bootmgr" should be "Windows Vista" and "Windows NT/2000/XP loader" should be "Windows NT/2000/XP". It's not like we are just booting the loaders.
Oh, fixed typos now. As for "Windows Vista bootmgr" and "Windows NT/2000/XP loader", I just copy them from 10_windows.in, I guess there is a reason for it there.
Quoted 4 lines
inird should be initrd. Please add check for the Fedora style names for initrd, namely "initrd-KVER.img". Or maybe you just missed ".img" in the second check?
Add the test for initrd-KVER.img. Is there any distro that uses initrd-KVER ? if not, I can just remove the second test.
Quoted 7 lines
Quoted 2 lines
Extend the function of grub.file_exist to allow testing multiple names at the same time, this simplify osdetect.lua.
The change to
grub_lua_file_exist()is dubious. It's not clear why the requirement is that all files exist. Maybe I don't know the style of lua, but I think it's wrong to hardcode the AND logic just because one script would benefit from it.
As lua can detect the number of parameter quite easily, I just think it'd be a waste not to utilize it. If you always call it with one parameter, then it's equivalent to the previous file_exist. It's just a little more code in c, but it can reduce the number of calls between c and lua.
Quoted 4 lines
If we consider e.g. the wildcard expansion in make, it will return a non-empty value if any file exists, i.e. the OR logic is used.
We can add a new function that uses OR logic instead of AND, for example, grub.file_exist_any, and the current AND version can be called grub.file_exist_all.
Quoted 3 lines
I suggest that you split the lua.mod changes and osdetect.lua. The later is obviously a bikeshed issue that can be discussed for a long time. The former needs a more technical consideration.
Ok.
Quoted 11 lines
--
Regards,
Pavel Roskin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Bean
conf/common.rmk +2 -3
@@ -519,15 +519,14 @@ lua_mod_SOURCES = script/lua/lapi.c script/lua/lcode.c script/lua/ldebug.c \ script/lua/lstate.c script/lua/lstring.c script/lua/ltable.c \ script/lua/ltm.c script/lua/lundump.c script/lua/lvm.c \ script/lua/lzio.c script/lua/lauxlib.c script/lua/lbaselib.c \ - script/lua/linit.c script/lua/ltablib.c \ + script/lua/linit.c script/lua/ltablib.c script/lua/lstrlib.c \ script/lua/grub_main.c script/lua/grub_lib.c lua_mod_CFLAGS = $(COMMON_CFLAGS) lua_mod_LDFLAGS = $(COMMON_LDFLAGS) # Extra libraries for lua # script/lua/lmathlib.c script/lua/loslib.c script/lua/liolib.c -# script/lua/lstrlib.c script/lua/ldblib.c script/lua/ltablib.c -# script/lua/loadlib.c +# script/lua/ldblib.c script/lua/loadlib.c # Common Video Subsystem specific modules. pkglib_MODULES += video.mod videotest.mod bitmap.mod tga.mod jpeg.mod \
script/lua/grub_lib.c +359 -21
425 lines not on this page · raw message
script/lua/grub_lua.h +22 -16
@@ -77,26 +77,28 @@ iscntrl (int c) }static inline int -strcspn (const char *s1,const char *s2) +isupper (int c) { -int size =0 ; - -while (*s1) - { -const char *p = s2; +return ((c >='A' ) && (c <='Z' )); +} -while (*p) - { -if (*s1 == *p) -return size; - p++; - } +static inline int +islower (int c) +{ +return ((c >='a' ) && (c <='z' )); +} - s1++; - size++; - } +static inline int +ispunct (int c) +{ +return ((!isspace (c)) && (!isalnum (c))); +} -return size; +static inline int +isxdigit (int c) +{ +return (isdigit (c) || ((c >='a' ) && (c <='f' )) || + ((c >='A' ) && (c <='F' ))); } static inline int
@@ -105,4 +107,8 @@ abs (int c) return (c >= 0) ? : -c; } +int strcspn (const char *s1,const char *s2); +char *strpbrk (const char *s1,const char *s2); +void *memchr (const void *s,int c,size_t n); +#endif
script/lua/grub_main.c +55 -0
61 lines not on this page · raw message
script/lua/linit.c +1 -1
@@ -20,7 +20,7 @@ static const luaL_Reg lualibs[] = { {LUA_TABLIBNAME, luaopen_table},// {LUA_IOLIBNAME, luaopen_io}, // {LUA_OSLIBNAME, luaopen_os}, -// {LUA_STRLIBNAME, luaopen_string}, + {LUA_STRLIBNAME, luaopen_string},// {LUA_MATHLIBNAME, luaopen_math}, // {LUA_DBLIBNAME, luaopen_debug}, {NULL, NULL}
Hi,
Oh, found a small bug in the previous osdetect.lua, here is an updated version.
Signature · 1 line
Bean
Quoted 3 lines · Bean
Oh, fixed typos now. As for "Windows Vista bootmgr" and "Windows NT/2000/XP loader", I just copy them from 10_windows.in, I guess there is a reason for it there.
I don't think so.
Quoted 7 lines
Quoted 4 lines
inird should be initrd. Please add check for the Fedora style names for initrd, namely "initrd-KVER.img". Or maybe you just missed ".img" in the second check?
Add the test for initrd-KVER.img. Is there any distro that uses initrd-KVER ? if not, I can just remove the second test.
Actually, I think SUSE uses initrd-KVER (no SUSE around, but Google seems to confirm it), Fedora uses initrd-KVER.img and Debian uses initrd.img-KVER, so we need to support all three.
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Extend the function of grub.file_exist to allow testing multiple names at the same time, this simplify osdetect.lua.
The change to
grub_lua_file_exist()is dubious. It's not clear why the requirement is that all files exist. Maybe I don't know the style of lua, but I think it's wrong to hardcode the AND logic just because one script would benefit from it.
Quoted 5 lines
As lua can detect the number of parameter quite easily, I just think it'd be a waste not to utilize it. If you always call it with one parameter, then it's equivalent to the previous
file_exist. It's just a little more code in c, but it can reduce the number of calls between c and lua.
I think it's not nice to add bells and whistles to a basic function checking existence of a file. Imagine if libc did is, and stat() would take a list of files.
Quoted 7 lines
Quoted 3 lines
If we consider e.g. the wildcard expansion in make, it will return a non-empty value if any file exists, i.e. the OR logic is used.
We can add a new function that uses OR logic instead of AND, for example, grub.file_exist_any, and the current AND version can be called grub.file_exist_all.
Can we implement them in lua? I think it would be better than to implement them in C.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 7 lines · Pavel Roskin
Quoted 3 lines · Bean
Oh, fixed typos now. As for "Windows Vista bootmgr" and "Windows NT/2000/XP loader", I just copy them from 10_windows.in, I guess there is a reason for it there.
I don't think so.
Fine with me.
Quoted 2 lines
Can we implement them in lua? I think it would be better than to implement them in C.
Yes, actually it's just a bunch of file_exist AND or OR together, but I think if we use this kind of test often enough, implement it in c would be more efficient.
Signature · 1 line
Bean
Quoted 3 lines · Bean
Yes, actually it's just a bunch of
file_existAND or OR together, but I think if we use this kind of test often enough, implement it in c would be more efficient.
So far, we only have one file.
I checked the Lua reference manual, and no file related functions take lists of filenames:
http://www.lua.org/manual/5.1/
If it was ineffective, I think Lua developers would have designed the file access differently.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 8 lines · Pavel Roskin
Quoted 3 lines · Bean
Yes, actually it's just a bunch of
file_existAND or OR together, but I think if we use this kind of test often enough, implement it in c would be more efficient.So far, we only have one file.
Quoted 7 lines
I checked the Lua reference manual, and no file related functions take lists of filenames:
http://www.lua.org/manual/5.1/
If it was ineffective, I think Lua developers would have designed the file access differently.
All right then, I'd change it back to single parameter. Actually it's not a big deal, but I just hate long lines, :)
Signature · 1 line
Bean
Committed.
Quoted 23 lines · Bean
Quoted 8 lines · Pavel Roskin
Quoted 3 lines · Bean
Yes, actually it's just a bunch of
file_existAND or OR together, but I think if we use this kind of test often enough, implement it in c would be more efficient.So far, we only have one file.
Quoted 7 lines
I checked the Lua reference manual, and no file related functions take lists of filenames:
http://www.lua.org/manual/5.1/
If it was ineffective, I think Lua developers would have designed the file access differently.
All right then, I'd change it back to single parameter. Actually it's not a big deal, but I just hate long lines, :)
--
Bean
Signature · 1 line
Bean
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I was reading the code and now I have a question. You are creating a
grub librairy writen in C including useful functions such as 'grub.file_open'. But in your implementation, you removed base libraries such as 'os' and 'io'. So why don't you just rewrite 'io.open' instead of creating 'grub.file_open'?
Thomas.
Quoted 27 lines · Bean
Committed.
Quoted 21 lines · Bean
Quoted 7 lines · Pavel Roskin
Quoted 3 lines · Bean
Yes, actually it's just a bunch of
file_existAND or OR together, but I think if we use this kind of test often enough, implement it in c would be more efficient.So far, we only have one file.
Quoted 7 lines
I checked the Lua reference manual, and no file related functions take lists of filenames:
http://www.lua.org/manual/5.1/
If it was ineffective, I think Lua developers would have designed the file access differently.
All right then, I'd change it back to single parameter. Actually it's not a big deal, but I just hate long lines, :)
--
Bean
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkpQpmcACgkQBV7eXqefhqjZkgCfdigjl2N7DFu3xxNCLDbyMerP AyEAoKzDcOW6ebJtdEIUcNSB9q57q64G
=fJix
-----END PGP SIGNATURE-----
Quoted 8 lines · Duboucher Thomas
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1I was reading the code and now I have a question. You are creating a grub librairy writen in C including useful functions such as 'grub.file_open'. But in your implementation, you removed base libraries such as 'os' and 'io'. So why don't you just rewrite 'io.open' instead of creating 'grub.file_open'?
Hi,
The io library uses many stdio function, such as fopen, which doesn't exist in grub.
Signature · 1 line
Bean
Quoted 6 lines · Pavel Roskin
Quoted 1 line · Bean
strange, it's working here, what's the device list ?
My mistake. I installed an unpatched GRUB.
Quoted 7 lines
The entries are created now. However, the initrd is not picked up. The old kernel (vmlinuz-2.6.30-wl.old) goes before the new one (vmlinuz-2.6.30-wl). And most importantly, the syntax for the root command is wrong.
"root hd0,3" has not effect. "root (hd0,3)" and "root=hd0,3" work. Yes, that's a bug in the root command.
Can't root command be ditched altogether? It sounds like completely redundant to me and just taking precious kernel space
Quoted 11 lines
--
Regards,
Pavel Roskin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
Quoted 6 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines · Pavel Roskin
"root hd0,3" has not effect. "root (hd0,3)" and "root=hd0,3" work. Yes, that's a bug in the root command.
Can't root command be ditched altogether? It sounds like completely redundant to me and just taking precious kernel space
Fine with me.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 10 lines · Bean
Hi,
Update for this patch:
1,
enum_devicenow pass fs and uuid as well
2,enum_filechange parameter order, now the callback function is the first, path is the second
3, add parameter checking for library function
4, add three function
Quoted 8 lines
file_eof- test if eof is encounter for a filefile_exist- test if a file existsadd_menu- add menu itemI also add a script osdetect.lua which can detect Windows 2K/NT/XP/Vista and linux at runtime, to use it, add this in grub.cfg:
source osdetect.lua
Can you please comment on what Robert said?
Personally, I do not mind supporting lua. But I prefer that scripts included with GRUB are written using the default scripting language. Some good reasons for this:
- I do not know lua, I assume Okuji doesn't either.
- Only using one script already requires the user to use lua: slowdown
- Personally, I hope people improve on the default scripting language
--
Marco