2009-06-08 Felix Zielcke <fziel...@z-51.de> * 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.
diff --git a/util/hostdisk.c b/util/hostdisk.c index a7262dd..0a786ba 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -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 On Mon, Jun 8, 2009 at 11:20 PM, Felix Zielcke<fziel...@z-51.de> wrote: > Am Montag, den 01.06.2009, 21:39 +0200 schrieb Felix Zielcke: >> Am Mittwoch, den 06.05.2009, 17:12 +0200 schrieb Vladimir 'phcoder' >> Serbinenko: >> > 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. > > Here's a new patch which prints out an error if stat () fails. > -- > Felix Zielcke > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel > > -- Regards Vladimir 'phcoder' Serbinenko _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel