2009-06-08 Felix Zielcke * 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]; + 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; +} diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 997811b..9446fd5 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -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 ();