grub-install --root-directory=/mnt /dev/sda1 fails
Hello list,
grub-install with some --root-directory option and a partition given as setup device and not a whole disk doestn't work, i.e. blocklists are used.
grub-setup fails that it can't find the core.img.
The problem are these 2 lines in setup():core_path_dev = grub_util_get_path (dir, core_file);
...
file = grub_file_open (core_path_dev);
core_path_dev contains the full path given with the -d' or --directory' option for example /mnt/boot/grub.
This can't work because /mnt is a different filesystem and so GRUB only
sees /boot/grub.
Removing the /mnt part from it works fine:
(gdb) set core_path_dev="/boot/grub/core.img"
(gdb) print *file->device->disk
$13 = {name = 0x640b90 "hd1,1", dev = 0x62f520, total_sectors = 16777216, has_partitions = 1, id = 1, partition = 0x640c10, read_hook = 0, data = 0x0}
The only solution that comes to my mind for this problem is, to introduce a --root-directory' option and making the --directory' option relative to it.
Does anyone have a better idea?
Signature · 1 line
Felix Zielcke
Quoted 23 lines · Felix Zielcke
Hello list,
grub-install with some --root-directory option and a partition given as setup device and not a whole disk doestn't work, i.e. blocklists are used.
grub-setup fails that it can't find the core.img.The problem are these 2 lines in
setup():core_path_dev=grub_util_get_path(dir,core_file);
...
file =grub_file_open(core_path_dev);
core_path_devcontains the full path given with the-d' or--directory' option for example/mnt/boot/grub.This can't work because /mnt is a different filesystem and so GRUB only sees
/boot/grub.
Removing the /mnt part from it works fine:
(gdb) set core_path_dev="/boot/grub/core.img"
(gdb) print*file->device->disk
$13 = {name =0x640b90"hd1,1", dev =0x62f520,total_sectors= 16777216,has_partitions= 1, id = 1, partition =0x640c10,read_hook= 0, data =0x0}
Quoted 5 lines
The only solution that comes to my mind for this problem is, to introduce a
--root-directory' option and making the--directory' option relative to it.Does anyone have a better idea?
Don't we already have a function which transforms host directory into grub directory? AFAIR we have.
Quoted 11 lines
--
Felix Zielcke_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Am Mittwoch, den 06.05.2009, 17:12 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 3 lines
Don't we already have a function which transforms host directory into grub
directory? AFAIR we have.
There's just the shell function in grub-mkconfig_lib.in Here's now a patch wich implements it in util/hostdisk.c and gets used for core_path_dev in setup ().
But it doestn't work with symlinks.
readlink () can only be used if the file pointed to is a symlink, not if a symlink is somewhere in between.
coreutils where the readlink binary is from is GPL 3+ but the function for it uses hash tables and it seems like it would be too much code to copy just for this.
Signature · 1 line
Felix Zielcke
2009-06-01 Felix Zielcke <[email protected]>
* include/grub/util/hostdisk.c (grub_make_system_path_relative_to_its_root): New function prototype.
* util/hostdisk.c (grub_make_system_path_relative_to_its_root):
New function.
* util/i386/pc/grub-setup.c (setup): Use grub_make_system_path_relative_to_its_root to make core_path_dev relative to the partition.
include/grub/util/hostdisk.h +2 -0
@@ -23,5 +23,7 @@void grub_util_biosdisk_init (const char *dev_map);void grub_util_biosdisk_fini (void );char *grub_util_biosdisk_get_grub_dev (const char *os_dev); +char *grub_make_system_path_relative_to_its_root (char *path); +#endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */
util/hostdisk.c +36 -0
@@ -1072,3 +1072,39 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)return make_device_name (drive,-1 ,-1 );#endif } + +char *grub_make_system_path_relative_to_its_root (char *path) +{ + +struct stat st; +char buf[500 ], buf2[500 ]; +dev_t num; +char *p; + +if (stat (path, &st) <0 ) +return path; + + num = st.st_dev; +memset (buf,0 ,sizeof (buf)); +strncpy (buf, path,500 ); +strcpy (buf2, buf); +while (1 ) + { + p =strrchr (buf,'/' ); +if (p != buf) + *p =0 ; +else *++p =0 ; + +if (stat (buf, &st) <0 ) +return path; + +if (st.st_dev != num) +break ; +strcpy (buf2,buf); +if (p -1 == buf) +return path; + } +for (p = buf2; *p !=0 ; p++) + path++; +return path; +}
util/i386/pc/grub-setup.c +1 -0
@@ -405,6 +405,7 @@ unable_to_embed:/* Make sure that GRUB reads the identical image as the OS. */ tmp_img =xmalloc (core_size); core_path_dev =grub_util_get_path (dir, core_file); + core_path_dev =grub_make_system_path_relative_to_its_root (core_path_dev);/* It is a Good Thing to sync two times. */ sync ();
Am Montag, den 01.06.2009, 21:39 +0200 schrieb Felix Zielcke:
Quoted 6 lines
Am Mittwoch, den 06.05.2009, 17:12 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 3 lines
Don't we already have a function which transforms host directory into grub
directory? AFAIR we have.
Quoted 9 lines
There's just the shell function in grub-mkconfig_lib.in Here's now a patch wich implements it in
util/hostdisk.cand gets used forcore_path_devin setup ().
But it doestn't work with symlinks.
readlink () can only be used if the file pointed to is a symlink, not if a symlink is somewhere in between.
coreutils where the readlink binary is from is GPL 3+ but the function for it uses hash tables and it seems like it would be too much code to copy just for this.
Here's a new patch which prints out an error if stat () fails.
Signature · 1 line
Felix Zielcke
2009-06-08 Felix Zielcke <[email protected]>
* include/grub/util/hostdisk.c (grub_make_system_path_relative_to_its_root): New function prototype.
* util/hostdisk.c (grub_make_system_path_relative_to_its_root):
New function.
* util/i386/pc/grub-setup.c (setup): Use grub_make_system_path_relative_to_its_root to make core_path_dev relative to the partition.
util/hostdisk.c +36 -0
@@ -1076,3 +1076,39 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)return make_device_name (drive,-1 ,-1 );#endif } + +char *grub_make_system_path_relative_to_its_root (char *path) +{ + +struct stat st; +char buf[500 ], buf2[500 ]; +dev_t num; +char *p; + +if (stat (path, &st) <0 ) +return NULL ; + + num = st.st_dev; +memset (buf,0 ,sizeof (buf)); +strncpy (buf, path,500 ); +strcpy (buf2, buf); +while (1 ) + { + p =strrchr (buf,'/' ); +if (p != buf) + *p =0 ; +else *++p =0 ; + +if (stat (buf, &st) <0 ) +return NULL ; + +if (st.st_dev != num) +break ; +strcpy (buf2,buf); +if (p -1 == buf) +return path; + } +for (p = buf2; *p !=0 ; p++) + path++; +return path; +}
util/i386/pc/grub-setup.c +3 -0
@@ -405,6 +405,9 @@ unable_to_embed:/* Make sure that GRUB reads the identical image as the OS. */ tmp_img =xmalloc (core_size); core_path_dev =grub_util_get_path (dir, core_file); + core_path_dev =grub_make_system_path_relative_to_its_root (core_path_dev); +if (core_path_dev ==NULL ) +grub_util_error ("failed to make path of core.img relative to its root" );/* It is a Good Thing to sync two times. */ sync ();
2009-06-08 Felix Zielcke <[email protected]>
* include/grub/util/hostdisk.c (grub_make_system_path_relative_to_its_root): New function prototype.
* util/hostdisk.c (grub_make_system_path_relative_to_its_root):
New function.
* util/i386/pc/grub-setup.c (setup): Use grub_make_system_path_relative_to_its_root to make core_path_dev relative to the partition.
util/hostdisk.c +6 -0
@@ -1076,3 +1076,39 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)return make_device_name (drive,-1 ,-1 );#endif } + +char *grub_make_system_path_relative_to_its_root (char *path) +{ + +struct stat st; +char buf[500 ], buf2[500 ];
Use malloc instead of static allocation
+ p = strrchr (buf, '/');
+ if (p != buf)
+ *p = 0;
+ else *++p = 0;
You assume path starts with /. You have to check this. Otherwise you may get sigsegv
+ strcpy(buf2,buf);
Just save (p - buf) instead of copying buf to buf2
Quoted 27 lines · Felix Zielcke
Am Montag, den 01.06.2009, 21:39 +0200 schrieb Felix Zielcke:
Quoted 6 lines
Am Mittwoch, den 06.05.2009, 17:12 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 3 lines
Don't we already have a function which transforms host directory into grub
directory? AFAIR we have.Quoted 9 lines
There's just the shell function in grub-mkconfig_lib.in Here's now a patch wich implements it in
util/hostdisk.cand gets used forcore_path_devin setup ().
But it doestn't work with symlinks.
readlink () can only be used if the file pointed to is a symlink, not if a symlink is somewhere in between.
coreutils where the readlink binary is from is GPL 3+ but the function for it uses hash tables and it seems like it would be too much code to copy just for this.Here's a new patch which prints out an error if stat () fails. --
Felix Zielcke_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Am Dienstag, den 09.06.2009, 23:51 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 7 lines
(quoted diff) +6
-0+ +char *grub_make_system_path_relative_to_its_root (char *path) +{ + + struct stat st; + char buf[500], buf2[500];Use malloc instead of static allocation
Changed.
Quoted 6 lines
(quoted diff) +4
-0+ p = strrchr (buf, '/'); + if (p != buf) + *p = 0; + else *++p = 0;You assume path starts with /. You have to check this. Otherwise you may get sigsegv
Changed.
Quoted 2 lines
+
strcpy(buf2,buf);
Just save (p - buf) instead of copying buf to buf2
I did this now if realpath () isn't avaible.
Now realpath is used in case it's avaible. POSIX specifies it and readlink is actually using it if it's avaible. I didn't read the source correctly.
The problem is just Cygwin. It has it but it returns the cygwin path. So C:\\Windows would get /cygdrive/c/windows, which is easy to handle. But realpath ("/boot/grub") would return /boot/grub which isn't true from Windows/GRUB point of view.
Maybe Christian and Bean can say something about it.
MingW doestn't have it and I don't know what Windows would have, so the MingW users would still use my own way.
Signature · 1 line
Felix Zielcke
2009-06-11 Felix Zielcke <[email protected]>
* configure.ac (AC_CHECK_FUNCS): Add realpath.
* include/grub/util/hostdisk.c (grub_make_system_path_relative_to_its_root): New function prototype.
* util/hostdisk.c: Include <stdint.h>. (grub_make_system_path_relative_to_its_root): New function.
* util/i386/pc/grub-setup.c (setup): Use grub_make_system_path_relative_to_its_root to make core_path_dev relative to the partition.
configure.ac +1 -1
@@ -205,7 +205,7 @@ if test "$target_cpu"-"$platform" = i386-pc; then fi # Check for functions. -AC_CHECK_FUNCS(posix_memalign memalign asprintf) +AC_CHECK_FUNCS(posix_memalign memalign asprintf realpath) # # Check for target programs.
include/grub/util/hostdisk.h +1 -0
@@ -23,5 +23,6 @@void grub_util_biosdisk_init (const char *dev_map);void grub_util_biosdisk_fini (void );char *grub_util_biosdisk_get_grub_dev (const char *os_dev); +char *grub_make_system_path_relative_to_its_root (char *path)#endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */
util/hostdisk.c +92 -0
101 lines not on this page · raw message
util/i386/pc/grub-setup.c +4 -2
@@ -89,7 +89,7 @@ setup (const char *dir, const char *root, const char *dest, int must_embed, int force) { char *boot_path, *core_path, *core_path_dev; -char *boot_img, *core_img; +char *boot_img, *core_img, *p;size_t boot_size, core_size;grub_uint16_t core_sectors;grub_device_t root_dev, dest_dev;
@@ -404,7 +404,9 @@ unable_to_embed:/* Make sure that GRUB reads the identical image as the OS. */ tmp_img =xmalloc (core_size); - core_path_dev =grub_util_get_path (dir, core_file); + p =grub_util_get_path (dir, core_file); + core_path_dev =grub_make_system_path_relative_to_its_root (p); +free (p);/* It is a Good Thing to sync two times. */ sync ();
Am Donnerstag, den 11.06.2009, 01:00 +0200 schrieb Felix Zielcke:
Quoted 24 lines
Am Dienstag, den 09.06.2009, 23:51 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 7 lines
(quoted diff) +6
-0+ +char *grub_make_system_path_relative_to_its_root (char *path) +{ + + struct stat st; + char buf[500], buf2[500];Use malloc instead of static allocation
Changed.
Quoted 6 lines
(quoted diff) +4
-0+ p = strrchr (buf, '/'); + if (p != buf) + *p = 0; + else *++p = 0;You assume path starts with /. You have to check this. Otherwise you may get sigsegv
Changed.
Quoted 2 lines
+
strcpy(buf2,buf);
Just save (p - buf) instead of copying buf to buf2
Quoted 11 lines
I did this now if realpath () isn't avaible.
Now realpath is used in case it's avaible. POSIX specifies it and readlink is actually using it if it's avaible. I didn't read the source correctly.
The problem is just Cygwin. It has it but it returns the cygwin path. So C:\\Windows would get /cygdrive/c/windows, which is easy to handle. But realpath ("/boot/grub") would return/boot/grubwhich isn't true from Windows/GRUB point of view.
Maybe Christian and Bean can say something about it.
MingW doestn't have it and I don't know what Windows would have, so the MingW users would still use my own way.
Here's now a new one which aborts if realpath is avaible but doestn't support (path, NULL)
and the fallback function is changed to dynamically allocate the memory. And now all memory is properly free'd
Signature · 1 line
Felix Zielcke
2009-06-11 Felix Zielcke <[email protected]>
* configure.ac (AC_CHECK_FUNCS): Add realpath.
* include/grub/util/hostdisk.c (grub_make_system_path_relative_to_its_root): New function prototype.
* util/hostdisk.c: Include <stdint.h>. (grub_make_system_path_relative_to_its_root): New function.
* util/i386/pc/grub-setup.c (setup): Use grub_make_system_path_relative_to_its_root to make core_path_dev relative to the partition.
configure.ac +1 -1
@@ -196,7 +196,7 @@ if test "$target_cpu"-"$platform" = i386-pc; then fi # Check for functions. -AC_CHECK_FUNCS(posix_memalign memalign asprintf) +AC_CHECK_FUNCS(posix_memalign memalign asprintf realpath) # # Check for target programs.
include/grub/util/hostdisk.h +1 -0
@@ -23,5 +23,6 @@void grub_util_biosdisk_init (const char *dev_map);void grub_util_biosdisk_fini (void );char *grub_util_biosdisk_get_grub_dev (const char *os_dev); +char *grub_make_system_path_relative_to_its_root (char *path,void **free_ptr);#endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */
util/hostdisk.c +93 -0
102 lines not on this page · raw message
util/i386/pc/grub-setup.c +5 -2
@@ -89,7 +89,7 @@ setup (const char *dir, const char *root, const char *dest, int must_embed, int force) { char *boot_path, *core_path, *core_path_dev; -char *boot_img, *core_img; +char *boot_img, *core_img, *p, *free_ptr;size_t boot_size, core_size;grub_uint16_t core_sectors;grub_device_t root_dev, dest_dev;
@@ -404,7 +404,10 @@ unable_to_embed:/* Make sure that GRUB reads the identical image as the OS. */ tmp_img =xmalloc (core_size); - core_path_dev =grub_util_get_path (dir, core_file); + p =grub_util_get_path (dir, core_file); + core_path_dev =grub_make_system_path_relative_to_its_root (p,&free_ptr); +free (p); +free (free_ptr);/* It is a Good Thing to sync two times. */ sync ();
Am Freitag, den 12.06.2009, 01:21 +0200 schrieb Felix Zielcke:
Quoted 37 lines
Am Donnerstag, den 11.06.2009, 01:00 +0200 schrieb Felix Zielcke:
Quoted 24 lines
Am Dienstag, den 09.06.2009, 23:51 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 7 lines
util/hostdisk.c +6
-0+ +char *grub_make_system_path_relative_to_its_root (char *path) +{ + +struct stat st; +char buf[500 ], buf2[500 ];Use malloc instead of static allocation
Changed.
Quoted 6 lines
util/hostdisk.c +4
-0+ p =strrchr (buf,'/' ); +if (p != buf) + *p =0 ; +else *++p =0 ;You assume path starts with /. You have to check this. Otherwise you may get sigsegv
Changed.
Quoted 2 lines
+
strcpy(buf2,buf);
Just save (p - buf) instead of copying buf to buf2Quoted 11 lines
I did this now if realpath () isn't avaible.
Now realpath is used in case it's avaible. POSIX specifies it and readlink is actually using it if it's avaible. I didn't read the source correctly.
The problem is just Cygwin. It has it but it returns the cygwin path. So C:\\Windows would get /cygdrive/c/windows, which is easy to handle. But realpath ("/boot/grub") would return/boot/grubwhich isn't true from Windows/GRUB point of view.
Maybe Christian and Bean can say something about it.
MingW doestn't have it and I don't know what Windows would have, so the MingW users would still use my own way.
Quoted 4 lines
Here's now a new one which aborts if realpath is avaible but doestn't support (path, NULL)
and the fallback function is changed to dynamically allocate the memory. And now all memory is properly free'd
args just noticed I forgot the *free_ptr = buf2; I'm too lazy now to send an extra patch just for this.
Signature · 1 line
Felix Zielcke
Am Freitag, den 12.06.2009, 01:25 +0200 schrieb Felix Zielcke:
Quoted 38 lines
Am Freitag, den 12.06.2009, 01:21 +0200 schrieb Felix Zielcke:
Quoted 37 lines
Am Donnerstag, den 11.06.2009, 01:00 +0200 schrieb Felix Zielcke:
Quoted 35 lines
Am Dienstag, den 09.06.2009, 23:51 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 7 lines
(quoted diff) +6
-0+ +char *grub_make_system_path_relative_to_its_root (char *path) +{ + + struct stat st; + char buf[500], buf2[500];Use malloc instead of static allocation
Changed.
Quoted 6 lines
(quoted diff) +4
-0+ p = strrchr (buf, '/'); + if (p != buf) + *p = 0; + else *++p = 0;You assume path starts with /. You have to check this. Otherwise you may get sigsegv
Changed.
Quoted 2 lines
+
strcpy(buf2,buf);
Just save (p - buf) instead of copying buf to buf2I did this now if realpath () isn't avaible.
Now realpath is used in case it's avaible. POSIX specifies it and readlink is actually using it if it's avaible. I didn't read the source correctly.
The problem is just Cygwin. It has it but it returns the cygwin path. So C:\\Windows would get /cygdrive/c/windows, which is easy to handle. But realpath ("/boot/grub") would return/boot/grubwhich isn't true from Windows/GRUB point of view.
Maybe Christian and Bean can say something about it.
MingW doestn't have it and I don't know what Windows would have, so the MingW users would still use my own way.
Quoted 7 lines
Quoted 4 lines
Here's now a new one which aborts if realpath is avaible but doestn't support (path, NULL)
and the fallback function is changed to dynamically allocate the memory. And now all memory is properly free'dargs just noticed I forgot the
*free_ptr= buf2; I'm too lazy now to send an extra patch just for this.
Ok here's a new one which compiles without warnings.
Signature · 1 line
Felix Zielcke
2009-06-12 Felix Zielcke <[email protected]>
* configure.ac (AC_CHECK_FUNCS): Add realpath.
* include/grub/util/hostdisk.c (grub_make_system_path_relative_to_its_root): New function prototype.
* util/hostdisk.c: Include <stdint.h>. (grub_make_system_path_relative_to_its_root): New function.
* util/i386/pc/grub-setup.c (setup): Use grub_make_system_path_relative_to_its_root to make core_path_dev relative to the partition.
configure.ac +1 -1
@@ -196,7 +196,7 @@ if test "$target_cpu"-"$platform" = i386-pc; then fi # Check for functions. -AC_CHECK_FUNCS(posix_memalign memalign asprintf) +AC_CHECK_FUNCS(posix_memalign memalign asprintf realpath) # # Check for target programs.
include/grub/util/hostdisk.h +1 -0
@@ -23,5 +23,6 @@void grub_util_biosdisk_init (const char *dev_map);void grub_util_biosdisk_fini (void );char *grub_util_biosdisk_get_grub_dev (const char *os_dev); +char *grub_make_system_path_relative_to_its_root (char *path,char **free_ptr);#endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */
util/hostdisk.c +95 -0
104 lines not on this page · raw message
util/i386/pc/grub-setup.c +5 -2
@@ -89,7 +89,7 @@ setup (const char *dir, const char *root, const char *dest, int must_embed, int force) { char *boot_path, *core_path, *core_path_dev; -char *boot_img, *core_img; +char *boot_img, *core_img, *p, *free_ptr;size_t boot_size, core_size;grub_uint16_t core_sectors;grub_device_t root_dev, dest_dev;
@@ -404,7 +404,10 @@ unable_to_embed:/* Make sure that GRUB reads the identical image as the OS. */ tmp_img =xmalloc (core_size); - core_path_dev =grub_util_get_path (dir, core_file); + p =grub_util_get_path (dir, core_file); + core_path_dev =grub_make_system_path_relative_to_its_root (p, &free_ptr); +free (p); +free (free_ptr);/* It is a Good Thing to sync two times. */ sync ();
Quoted 1 line · Felix Zielcke
Ok here's a new one which compiles without warnings.
I suggest that whenever a patch is published, it comes with a detailed description. Surely, it could be gathered by rereading the thread, but I think it's not sufficient for two reasons.
The first reason is that we want the patches reviewed by more people. Not everybody has time to read the whole discussion.
The second reason is that the description the shows how the author sees the changes, what the potential benefits are, what code is affected. The reviewers would be able to compare the goals to the implementation.
Even if the description was already published, it should not be hard to publish it again, perhaps with some improvements.
Regarding this patch, I don't think we need to add a function to hostdisk.c is it's only used in grub-setup.c. It would be better to have it in grub-setup.c unless it's a generic function or there is a good chance that it will be used elsewhere.
grub_make_system_path_relative_to_its_root is a very long name. There is nothing wrong with a long name per se, but it may be in sign that the function is too specialized and should not be in hostdisk.c.
Following is not good for several reasons:
#warning "The function `grub_make_system_path_relative_to_its_root' might not work on your OS correctly."
The warning will only be seen by those who compile GRUB, but not by the end users who installed a binary. The warning doesn't explain what exactly may not work correctly. Since we are talking about new functionality here, I'd rather omit an unsafe implementation if realpath() is not available.
What is free_ptr? It looks like it's a pointer that the caller should free. I think functions should be self-contained and should not ask the caller to do the cleanup (unless they actually return something useful in the allocated memory).
Signature · 2 lines
Regards, Pavel Roskin
Am Freitag, den 12.06.2009, 12:21 -0400 schrieb Pavel Roskin:
Quoted 11 lines · Felix Zielcke
Quoted 2 lines
Ok here's a new one which compiles without warnings.
I suggest that whenever a patch is published, it comes with a detailed description. Surely, it could be gathered by rereading the thread, but I think it's not sufficient for two reasons.
The first reason is that we want the patches reviewed by more people. Not everybody has time to read the whole discussion.
Quoted 6 lines
The second reason is that the description the shows how the author sees the changes, what the potential benefits are, what code is affected. The reviewers would be able to compare the goals to the implementation.
Even if the description was already published, it should not be hard to publish it again, perhaps with some improvements.
Well it does (well should) exactly do the same as the make_system_path_relative_to_its_root in util/grub-mkconfig_lib except that it's written in C instead of a bash function.
Quoted 20 lines
Regarding this patch, I don't think we need to add a function to
hostdisk.cis it's only used ingrub-setup.c. It would be better to have it ingrub-setup.cunless it's a generic function or there is a good chance that it will be used elsewhere.
grub_make_system_path_relative_to_its_rootis a very long name. There is nothing wrong with a long name per se, but it may be in sign that the function is too specialized and should not be inhostdisk.c.Following is not good for several reasons:
#warning "The function `grub_make_system_path_relative_to_its_root' might not work on your OS correctly."
The warning will only be seen by those who compile GRUB, but not by the end users who installed a binary. The warning doesn't explain what exactly may not work correctly. Since we are talking about new functionality here, I'd rather omit an unsafe implementation if
realpath()is not available.
Quoted 4 lines
What is
free_ptr? It looks like it's a pointer that the caller should free. I think functions should be self-contained and should not ask the caller to do the cleanup (unless they actually return something useful in the allocated memory).
Robert anyway already said that this needs discussing. The function is currently only useful in grub-setup in the case blocklists are used for core.img
I don't think it will be useful for anything else.
About free_ptr,
yeah I could just copy buf2 + offset to a buf3 and then just free buf2 inside the function so that the caller can just free the return value of it.
But I got this idea only after I sent the patch and I already told Vladimir that he doestn't need to look anymore because Robert wants to have the whole design discussed first.
Signature · 1 line
Felix Zielcke
Am Montag, den 01.06.2009, 21:39 +0200 schrieb Felix Zielcke:
Quoted 6 lines
Am Mittwoch, den 06.05.2009, 17:12 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 3 lines
Don't we already have a function which transforms host directory into grub
directory? AFAIR we have.
Quoted 9 lines
There's just the shell function in grub-mkconfig_lib.in Here's now a patch wich implements it in
util/hostdisk.cand gets used forcore_path_devin setup ().
But it doestn't work with symlinks.
readlink () can only be used if the file pointed to is a symlink, not if a symlink is somewhere in between.
coreutils where the readlink binary is from is GPL 3+ but the function for it uses hash tables and it seems like it would be too much code to copy just for this.
So what do we do know about this problem?
We could just assume that the directory given with grub-setup --directory is already the real absolute path and just use the stat magic to make it relative.
Or we use realpath() if avaible to get the real one.
And on systems not having it, like mingw we could just assume that it's already relative and just return the path given.
Or is there some other way this bug can be fixed?
Signature · 1 line
Felix Zielcke
Quoted 17 lines · Felix Zielcke
Am Montag, den 01.06.2009, 21:39 +0200 schrieb Felix Zielcke:
Quoted 6 lines
Am Mittwoch, den 06.05.2009, 17:12 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 3 lines
Don't we already have a function which transforms host directory into grub
directory? AFAIR we have.Quoted 9 lines
There's just the shell function in grub-mkconfig_lib.in Here's now a patch wich implements it in
util/hostdisk.cand gets used forcore_path_devin setup ().
But it doestn't work with symlinks.
readlink () can only be used if the file pointed to is a symlink, not if a symlink is somewhere in between.
coreutils where the readlink binary is from is GPL 3+ but the function for it uses hash tables and it seems like it would be too much code to copy just for this.
Quoted 8 lines
So what do we do know about this problem?
We could just assume that the directory given with grub-setup --directory is already the real absolute path and just use the stat magic to make it relative.
Or we userealpath()if avaible to get the real one.
And on systems not having it, like mingw we could just assume that it's already relative and just return the path given.
Or is there some other way this bug can be fixed?
I just looked into this, and I don't think there's any real problem that needs fixing. The "workaround" is just a red herring, it works for him by pure chance.
See:
http://savannah.gnu.org/bugs/index.php?26924
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."
Am Samstag, den 04.07.2009, 22:09 +0200 schrieb Robert Millan:
Quoted 27 lines · Felix Zielcke
Quoted 17 lines
Am Montag, den 01.06.2009, 21:39 +0200 schrieb Felix Zielcke:
Quoted 6 lines
Am Mittwoch, den 06.05.2009, 17:12 +0200 schrieb Vladimir 'phcoder' Serbinenko:
Quoted 3 lines
Don't we already have a function which transforms host directory into grub
directory? AFAIR we have.Quoted 9 lines
There's just the shell function in grub-mkconfig_lib.in Here's now a patch wich implements it in
util/hostdisk.cand gets used forcore_path_devin setup ().
But it doestn't work with symlinks.
readlink () can only be used if the file pointed to is a symlink, not if a symlink is somewhere in between.
coreutils where the readlink binary is from is GPL 3+ but the function for it uses hash tables and it seems like it would be too much code to copy just for this.Quoted 8 lines
So what do we do know about this problem?
We could just assume that the directory given with grub-setup --directory is already the real absolute path and just use the stat magic to make it relative.
Or we userealpath()if avaible to get the real one.
And on systems not having it, like mingw we could just assume that it's already relative and just return the path given.
Or is there some other way this bug can be fixed?
Quoted 7 lines
I just looked into this, and I don't think there's any real problem that needs fixing. The "workaround" is just a red herring, it works for him by pure chance.
See:
I think I tested this and the root device was set correctly, so it looked at the right device for the core.img
Signature · 1 line
Felix Zielcke