From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MBDM7-0001xJ-HL for mharc-grub-devel@gnu.org; Mon, 01 Jun 2009 15:39:35 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MBDM6-0001wl-1k for grub-devel@gnu.org; Mon, 01 Jun 2009 15:39:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MBDM1-0001vd-FU for grub-devel@gnu.org; Mon, 01 Jun 2009 15:39:33 -0400 Received: from [199.232.76.173] (port=39074 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MBDM1-0001va-B1 for grub-devel@gnu.org; Mon, 01 Jun 2009 15:39:29 -0400 Received: from moutng.kundenserver.de ([212.227.17.8]:50062) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MBDM0-0000MC-ME for grub-devel@gnu.org; Mon, 01 Jun 2009 15:39:29 -0400 Received: from [85.180.7.157] (e180007157.adsl.alicedsl.de [85.180.7.157]) by mrelayeu.kundenserver.de (node=mrbap1) with ESMTP (Nemesis) id 0MKt2u-1MBDLz2W3h-000558; Mon, 01 Jun 2009 21:39:27 +0200 From: Felix Zielcke To: The development of GRUB 2 In-Reply-To: References: <1241620317.3746.8.camel@fz.local> Content-Type: multipart/mixed; boundary="=-rLiMc2UOhRjvvHUG6JZu" Date: Mon, 01 Jun 2009 21:39:26 +0200 Message-Id: <1243885166.3417.11.camel@fz.local> Mime-Version: 1.0 X-Mailer: Evolution 2.26.2 X-Provags-ID: V01U2FsdGVkX18ylR4sywtWisbLF87/jDb37gshXPS//+2zqQ5 iZgu0fJ81Z02EdbGN2SnFl2P7NRFoIrtGtDy/22MscF7yBMIpj g5AAHyQ4+3NgomGa8GZm8Pq98IDyPei X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: grub-install --root-directory=/mnt /dev/sda1 fails X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Jun 2009 19:39:34 -0000 --=-rLiMc2UOhRjvvHUG6JZu Content-Type: text/plain Content-Transfer-Encoding: 7bit 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. -- Felix Zielcke --=-rLiMc2UOhRjvvHUG6JZu Content-Disposition: attachment; filename="make_sys_path_relative.patch" Content-Type: text/x-patch; name="make_sys_path_relative.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit 2009-06-01 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/include/grub/util/hostdisk.h b/include/grub/util/hostdisk.h index 21efb0d..0fb0219 100644 --- a/include/grub/util/hostdisk.h +++ b/include/grub/util/hostdisk.h @@ -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 */ diff --git a/util/hostdisk.c b/util/hostdisk.c index eaccb73..2b80b48 100644 --- a/util/hostdisk.c +++ b/util/hostdisk.c @@ -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; +} diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index 997811b..57f49d4 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -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 (); --=-rLiMc2UOhRjvvHUG6JZu--