From: Robert Millan <rmh@aybabtu.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: proposed solution using "ofpathname -a" (Re: OF disk naming scheme)
Date: Sun, 12 Aug 2007 16:56:00 +0200 [thread overview]
Message-ID: <20070812145600.GA2815@aragorn> (raw)
In-Reply-To: <20070722202505.GA9408@aragorn>
[-- Attachment #1: Type: text/plain, Size: 782 bytes --]
On Sun, Jul 22, 2007 at 10:25:05PM +0200, Robert Millan wrote:
>
> AFAIK we can only read the full OF path from /proc (with helper tools like
> ofpath / ofpathname), but not the short alias which grub uses. These can only
> be obtained when grub is running.
>
> If the proposed solution is not good, maybe we could instead remap all disks
> to "standard" grub device names (hd0, hd1..), which grub-mkdevicemap already
> knows how to guess reasonably well.
Ok, I think I finally managed to make it work the way you wanted. Please see
attached patch.
You will also need alias.diff for ofpathname (I've sent it to the author
already).
--
Robert Millan
<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
[-- Attachment #2: mkdevicemap.diff --]
[-- Type: text/x-diff, Size: 8351 bytes --]
2007-08-12 Robert Millan <rmh@aybabtu.com>
* util/i386/get_disk_name.c: New. Implement grub_util_get_disk_name()
to tell grub-mkdevicemap how to name devices.
* util/ieee1275/get_disk_name.c: Likewise (using "ofpathname -a"
feature).
* conf/i386-efi.rmk (grub_mkdevicemap_SOURCES): Add
util/i386/get_disk_name.c.
* conf/i386-pc.rmk (grub_mkdevicemap_SOURCES): Likewise.
* conf/powerpc-ieee1275.rmk (grub_mkdevicemap_SOURCES): Add
util/ieee1275/get_disk_name.c.
* include/grub/util/misc.h: grub_util_get_disk_name() declaration.
* DISTLIST: Add util/i386/get_disk_name.c and
util/ieee1275/get_disk_name.c.
* util/grub-mkdevicemap.c: Replace device naming logic with
grub_util_get_disk_name() calls.
diff -Nur grub2/conf/i386-efi.rmk grub2.mkdevicemap/conf/i386-efi.rmk
--- grub2/conf/i386-efi.rmk 2007-08-02 22:42:19.000000000 +0200
+++ grub2.mkdevicemap/conf/i386-efi.rmk 2007-08-12 15:26:42.000000000 +0200
@@ -24,7 +24,8 @@
# kern/fs.c kern/env.c fs/fshelp.c
# For grub-mkdevicemap.
-grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c
+grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c \
+ util/i386/get_disk_name.c
# For grub-probe.
grub_probe_DEPENDENCIES = grub_probe_init.h
diff -Nur grub2/conf/i386-pc.rmk grub2.mkdevicemap/conf/i386-pc.rmk
--- grub2/conf/i386-pc.rmk 2007-08-02 22:42:19.000000000 +0200
+++ grub2.mkdevicemap/conf/i386-pc.rmk 2007-08-12 15:26:42.000000000 +0200
@@ -72,7 +72,8 @@
util/raid.c util/lvm.c grub_setup_init.c
# For grub-mkdevicemap.
-grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c
+grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c \
+ util/i386/get_disk_name.c
# For grub-probe.
grub_probe_DEPENDENCIES = grub_probe_init.h
diff -Nur grub2/conf/powerpc-ieee1275.rmk grub2.mkdevicemap/conf/powerpc-ieee1275.rmk
--- grub2/conf/powerpc-ieee1275.rmk 2007-08-02 22:42:19.000000000 +0200
+++ grub2.mkdevicemap/conf/powerpc-ieee1275.rmk 2007-08-12 15:26:42.000000000 +0200
@@ -36,7 +36,8 @@
util/resolve.c
# For grub-mkdevicemap.
-grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c
+grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/misc.c \
+ util/ieee1275/get_disk_name.c
# For grub-probe.
grub_probe_DEPENDENCIES = grub_probe_init.h
diff -Nur grub2/include/grub/util/misc.h grub2.mkdevicemap/include/grub/util/misc.h
--- grub2/include/grub/util/misc.h 2007-07-22 01:32:25.000000000 +0200
+++ grub2.mkdevicemap/include/grub/util/misc.h 2007-08-12 15:26:42.000000000 +0200
@@ -53,5 +53,6 @@
void grub_util_write_image (const char *img, size_t size, FILE *out);
void grub_util_write_image_at (const void *img, size_t size, off_t offset,
FILE *out);
+char *grub_util_get_disk_name (int disk, char *name);
#endif /* ! GRUB_UTIL_MISC_HEADER */
diff -Nur grub2/util/grub-mkdevicemap.c grub2.mkdevicemap/util/grub-mkdevicemap.c
--- grub2/util/grub-mkdevicemap.c 2007-07-22 01:32:31.000000000 +0200
+++ grub2.mkdevicemap/util/grub-mkdevicemap.c 2007-08-12 15:26:42.000000000 +0200
@@ -402,8 +402,11 @@
if (realpath (discn, name))
{
+ char *p;
strcat (name, "/disc");
- fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+ p = grub_util_get_disk_name (num_hd, name);
+ fprintf (fp, "(%s)\t%s\n", p, name);
+ free (p);
}
num_hd++;
@@ -421,7 +424,10 @@
get_ide_disk_name (name, i);
if (check_device (name))
{
- fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+ char *p;
+ p = grub_util_get_disk_name (num_hd, name);
+ fprintf (fp, "(%s)\t%s\n", p, name);
+ free (p);
num_hd++;
}
}
@@ -435,7 +441,10 @@
get_ataraid_disk_name (name, i);
if (check_device (name))
{
- fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+ char *p;
+ p = grub_util_get_disk_name (num_hd, name);
+ fprintf (fp, "(%s)\t%s\n", p, name);
+ free (p);
num_hd++;
}
}
@@ -449,7 +458,10 @@
get_scsi_disk_name (name, i);
if (check_device (name))
{
- fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+ char *p;
+ p = grub_util_get_disk_name (num_hd, name);
+ fprintf (fp, "(%s)\t%s\n", p, name);
+ free (p);
num_hd++;
}
}
@@ -472,7 +484,10 @@
get_dac960_disk_name (name, controller, drive);
if (check_device (name))
{
- fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+ char *p;
+ p = grub_util_get_disk_name (num_hd, name);
+ fprintf (fp, "(%s)\t%s\n", p, name);
+ free (p);
num_hd++;
}
}
@@ -490,7 +505,10 @@
get_i2o_disk_name (name, unit);
if (check_device (name))
{
- fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
+ char *p;
+ p = grub_util_get_disk_name (num_hd, name);
+ fprintf (fp, "(%s)\t%s\n", p, name);
+ free (p);
num_hd++;
}
}
diff -Nur grub2/util/i386/get_disk_name.c grub2.mkdevicemap/util/i386/get_disk_name.c
--- grub2/util/i386/get_disk_name.c 1970-01-01 01:00:00.000000000 +0100
+++ grub2.mkdevicemap/util/i386/get_disk_name.c 2007-08-12 15:26:42.000000000 +0200
@@ -0,0 +1,31 @@
+/* get_disk_name.c */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/util/misc.h>
+
+char *
+grub_util_get_disk_name (int disk, char *name)
+{
+ char *p;
+
+ p = xmalloc (16);
+ sprintf (p, "hd%d", disk);
+
+ return p;
+}
diff -Nur grub2/util/ieee1275/get_disk_name.c grub2.mkdevicemap/util/ieee1275/get_disk_name.c
--- grub2/util/ieee1275/get_disk_name.c 1970-01-01 01:00:00.000000000 +0100
+++ grub2.mkdevicemap/util/ieee1275/get_disk_name.c 2007-08-12 16:16:56.000000000 +0200
@@ -0,0 +1,60 @@
+/* get_disk_name.c */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <grub/util/misc.h>
+
+char *
+grub_util_get_disk_name (int disk, char *name)
+{
+ int p[2];
+
+ char *line = NULL;
+ int zero = 0;
+ int len;
+
+ pipe (p);
+
+ switch (fork ())
+ {
+ case -1:
+ perror ("fork");
+ exit (1);
+ case 0:
+ close (1);
+ dup (p[1]);
+ close (p[0]);
+ close (p[1]);
+ execlp ("ofpathname", "ofpathname", "-a", name, NULL);
+ perror ("execlp");
+ default:
+ close (0);
+ dup (p[0]);
+ close (p[0]);
+ close (p[1]);
+ }
+
+ len = getline (&line, &zero, stdin);
+ if (len < 2)
+ grub_util_error ("ofpathname didn't print a meaningful alias name");
+
+ line[len - 1] = '\0';
+
+ return line;
+}
--- grub2/DISTLIST 2007-08-02 22:42:19.000000000 +0200
+++ grub2.mkdevicemap/DISTLIST 2007-08-12 16:33:22.000000000 +0200
@@ -285,11 +285,13 @@
util/grub.d/README
util/i386/efi/grub-install.in
util/i386/efi/grub-mkimage.c
+util/i386/get_disk_name.c
util/i386/pc/grub-install.in
util/i386/pc/grub-mkimage.c
util/i386/pc/grub-setup.c
util/i386/pc/misc.c
util/i386/pc/grub-mkrescue.in
+util/ieee1275/get_disk_name.c
util/powerpc/ieee1275/grub-install.in
util/powerpc/ieee1275/grub-mkimage.c
util/powerpc/ieee1275/misc.c
[-- Attachment #3: alias.diff --]
[-- Type: text/x-diff, Size: 1315 bytes --]
--- ofpathname.orig 2007-07-17 16:10:47.000000000 +0200
+++ ofpathname 2007-08-12 13:00:21.000000000 +0200
@@ -27,6 +33,7 @@
echo "Optional arguments."
echo " -l Convert Open Firmware device pathname to"
echo " logical device name."
+ echo " -a Find matching Open Firmware device alias[es]."
echo " -q, --quiet do not report failures, exit quietly"
echo " -V, --version display version information and exit"
echo " -h, --help display this help information and exit"
@@ -226,7 +234,16 @@
OF_PATH=$OFPATH:1\\ppc\\bootinfo.txt
fi
- echo $OF_PATH
+ if [[ $do_alias = "0" ]]; then
+ echo $OF_PATH
+ else
+ (shopt -s nullglob
+ for i in /proc/device-tree/aliases/* ; do
+ if sed -e "s/\x00$//g" $i | grep -qx "$OF_PATH" ; then
+ basename $i
+ fi
+ done)
+ fi
}
#
@@ -613,10 +638,14 @@
# default: convert logical => OFpath
do_of2l=0
+# default: do not alias-ize
+do_alias=0
getopt -o "l:Vqh" -l "help,version,quiet" $@ > /dev/null 2>&1
while [[ -n $1 ]]; do
case "$1" in
+ -a) do_alias=1 ;;
+
-l) do_of2l=1
DEVNAME_ARG=$2
shift ;;
next prev parent reply other threads:[~2007-08-12 14:52 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-02 18:16 another regression on Efika Robert Millan
2007-07-02 21:14 ` Robert Millan
2007-07-04 16:18 ` Hollis Blanchard
2007-07-10 10:04 ` Jordi Mallach
2007-07-10 14:08 ` memory management issue (Re: another regression on Efika) Robert Millan
2007-07-10 20:32 ` Hollis Blanchard
2007-07-13 22:08 ` Robert Millan
2007-07-24 19:59 ` Robert Millan
2007-07-25 17:51 ` Hollis Blanchard
2007-07-25 20:08 ` Robert Millan
2007-07-25 23:25 ` Hollis Blanchard
2007-07-27 8:05 ` Robert Millan
[not found] ` <20070727103310.GA1539@powerlinux.fr>
2007-07-27 19:15 ` Robert Millan
2007-07-29 19:30 ` Robert Millan
2007-07-30 20:11 ` [PATCH] efika memory issues Robert Millan
2007-07-30 22:35 ` Hollis Blanchard
2007-07-31 14:38 ` Robert Millan
2007-07-31 15:55 ` Hollis Blanchard
2007-07-31 19:42 ` Robert Millan
2007-08-01 17:34 ` Hollis Blanchard
2007-08-01 18:27 ` Robert Millan
2007-09-30 20:10 ` [PATCH] fix memory management on efika/pegasos Robert Millan
2007-10-01 18:18 ` Marcin Kurek
2007-10-01 22:25 ` Marcin Kurek
2007-10-02 19:42 ` Robert Millan
2007-10-03 23:38 ` Marcin Kurek
2007-10-04 20:47 ` Robert Millan
2007-07-10 14:10 ` OF disk naming scheme (Re: another regression on Efika) Robert Millan
2007-07-10 19:26 ` Jordi Mallach
2007-07-13 22:16 ` Robert Millan
2007-07-22 9:33 ` Robert Millan
2007-07-22 14:37 ` Marco Gerards
2007-07-22 20:25 ` Robert Millan
2007-08-12 14:56 ` Robert Millan [this message]
2007-08-05 10:03 ` updated regression diff " Robert Millan
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=20070812145600.GA2815@aragorn \
--to=rmh@aybabtu.com \
--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.