From: Felix Zielcke <fzielcke@z-51.de>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: grub-install --root-directory=/mnt /dev/sda1 fails
Date: Mon, 01 Jun 2009 21:39:26 +0200 [thread overview]
Message-ID: <1243885166.3417.11.camel@fz.local> (raw)
In-Reply-To: <d7ead6de0905060812n3a5ff52fj26d8339a8166eb37@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 670 bytes --]
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
[-- Attachment #2: make_sys_path_relative.patch --]
[-- Type: text/x-patch, Size: 2244 bytes --]
2009-06-01 Felix Zielcke <fzielcke@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/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 ();
next prev parent reply other threads:[~2009-06-01 19:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-06 14:31 grub-install --root-directory=/mnt /dev/sda1 fails Felix Zielcke
2009-05-06 15:12 ` Vladimir 'phcoder' Serbinenko
2009-06-01 19:39 ` Felix Zielcke [this message]
2009-06-08 21:20 ` [PATCH] " Felix Zielcke
2009-06-09 21:51 ` Vladimir 'phcoder' Serbinenko
2009-06-10 23:00 ` Felix Zielcke
2009-06-11 23:21 ` Felix Zielcke
2009-06-11 23:25 ` Felix Zielcke
2009-06-12 10:28 ` Felix Zielcke
2009-06-12 16:21 ` Pavel Roskin
2009-06-12 16:33 ` Felix Zielcke
2009-07-01 14:33 ` Felix Zielcke
2009-07-04 20:09 ` Robert Millan
2009-07-08 14:16 ` Felix Zielcke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1243885166.3417.11.camel@fz.local \
--to=fzielcke@z-51.de \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.