Hi there,
I'm afraid the patch I sent some days ago was wrong, and it didn't do
what my mail described. This is because I made a mistake when sending
it and I sent a preliminary, incomplete patch instead of the correct one.
I'm attaching the correct patch, which corresponds to the message I sent:
> Hello!
>
> This patch fixes lib/device.c to use dynamic allocation for the
> device names obtained in get_*_name () functions:
>
> - the name variable is returned by the functions instead of
> passing by reference, so that they can allocate it themselves.
> - the get_*_name functions use asprintf() to allocate the device
> name dynamicaly.
> - for NetBSD, it still uses static allocation since the "opendisk"
> call is unable (that i know of) to deal with dynamic buffers.
>
> This fix is needed to work for kernels that have device names longer than
> 16 chars, and for GCS compliance (section 4.1).
--
Robert Millan
diff -ur grub.old/lib/device.c grub/lib/device.c
--- grub.old/lib/device.c 2003-02-17 12:35:30.000000000 +0000
+++ grub/lib/device.c 2003-07-20 00:25:20.000000000 +0000
@@ -186,58 +186,62 @@
#endif /* __linux__ */
/* These three functions are quite different among OSes. */
-static void
-get_floppy_disk_name (char *name, int unit)
+static char *
+get_floppy_disk_name (int unit)
{
+ char *name;;
#if defined(__linux__)
/* GNU/Linux */
if (have_devfs ())
- sprintf (name, "/dev/floppy/%d", unit);
+ asprintf (&name, "/dev/floppy/%d", unit);
else
- sprintf (name, "/dev/fd%d", unit);
+ asprintf (&name, "/dev/fd%d", unit);
#elif defined(__GNU__)
/* GNU/Hurd */
- sprintf (name, "/dev/fd%d", unit);
+ asprintf (&name, "/dev/fd%d", unit);
#elif defined(__FreeBSD__)
/* FreeBSD */
- sprintf (name, "/dev/rfd%d", unit);
+ asprintf (&name, "/dev/rfd%d", unit);
#elif defined(__NetBSD__)
/* NetBSD */
/* opendisk() doesn't work for floppies. */
- sprintf (name, "/dev/rfd%da", unit);
+ asprintf (&name, "/dev/rfd%da", unit);
#elif defined(__OpenBSD__)
/* OpenBSD */
- sprintf (name, "/dev/rfd%dc", unit);
+ asprintf (&name, "/dev/rfd%dc", unit);
#elif defined(__QNXNTO__)
/* QNX RTP */
- sprintf (name, "/dev/fd%d", unit);
+ asprintf (&name, "/dev/fd%d", unit);
#else
# warning "BIOS floppy drives cannot be guessed in your operating system."
/* Set NAME to a bogus string. */
*name = 0;
#endif
+ return name;
}
-static void
-get_ide_disk_name (char *name, int unit)
+static char *
+get_ide_disk_name (int unit)
{
+ char *name;
#if defined(__linux__)
/* GNU/Linux */
- sprintf (name, "/dev/hd%c", unit + 'a');
+ asprintf (&name, "/dev/hd%c", unit + 'a');
#elif defined(__GNU__)
/* GNU/Hurd */
- sprintf (name, "/dev/hd%d", unit);
+ asprintf (&name, "/dev/hd%d", unit);
#elif defined(__FreeBSD__)
/* FreeBSD */
# if __FreeBSD__ >= 4
- sprintf (name, "/dev/rad%d", unit);
+ asprintf (&name, "/dev/rad%d", unit);
# else /* __FreeBSD__ <= 3 */
- sprintf (name, "/dev/rwd%d", unit);
+ asprintf (&name, "/dev/rwd%d", unit);
# endif /* __FreeBSD__ <= 3 */
#elif defined(__NetBSD__) && defined(HAVE_OPENDISK)
/* NetBSD */
char shortname[16];
int fd;
+ name = malloc (16); // FIXME: can opendisk deal with dynamic buffers?
sprintf (shortname, "wd%d", unit);
fd = opendisk (shortname, O_RDONLY, name,
@@ -247,35 +251,38 @@
close (fd);
#elif defined(__OpenBSD__)
/* OpenBSD */
- sprintf (name, "/dev/rwd%dc", unit);
+ asprintf (&name, "/dev/rwd%dc", unit);
#elif defined(__QNXNTO__)
/* QNX RTP */
/* Actually, QNX RTP doesn't distinguish IDE from SCSI, so this could
contain SCSI disks. */
- sprintf (name, "/dev/hd%d", unit);
+ asprintf (&name, "/dev/hd%d", unit);
#else
# warning "BIOS IDE drives cannot be guessed in your operating system."
/* Set NAME to a bogus string. */
*name = 0;
#endif
+ return name;
}
-static void
-get_scsi_disk_name (char *name, int unit)
+static char *
+get_scsi_disk_name (int unit)
{
+ char *name;
#if defined(__linux__)
/* GNU/Linux */
- sprintf (name, "/dev/sd%c", unit + 'a');
+ asprintf (&name, "/dev/sd%c", unit + 'a');
#elif defined(__GNU__)
/* GNU/Hurd */
- sprintf (name, "/dev/sd%d", unit);
+ asprintf (&name, "/dev/sd%d", unit);
#elif defined(__FreeBSD__)
/* FreeBSD */
- sprintf (name, "/dev/rda%d", unit);
+ asprintf (&name, "/dev/rda%d", unit);
#elif defined(__NetBSD__) && defined(HAVE_OPENDISK)
/* NetBSD */
char shortname[16];
int fd;
+ name = malloc (16); // FIXME: can opendisk deal with dynamic buffers?
sprintf (shortname, "sd%d", unit);
fd = opendisk (shortname, O_RDONLY, name,
@@ -285,7 +292,7 @@
close (fd);
#elif defined(__OpenBSD__)
/* OpenBSD */
- sprintf (name, "/dev/rsd%dc", unit);
+ asprintf (&name, "/dev/rsd%dc", unit);
#elif defined(__QNXNTO__)
/* QNX RTP */
/* QNX RTP doesn't distinguish SCSI from IDE, so it is better to
@@ -296,13 +303,16 @@
/* Set NAME to a bogus string. */
*name = 0;
#endif
+ return name;
}
#ifdef __linux__
-static void
-get_dac960_disk_name (char *name, int controller, int drive)
+static char *
+get_dac960_disk_name (int controller, int drive)
{
- sprintf (name, "/dev/rd/c%dd%d", controller, drive);
+ char *name;
+ asprintf (&name, "/dev/rd/c%dd%d", controller, drive);
+ return name;
}
#endif
@@ -537,9 +547,9 @@
/* Floppies. */
for (i = 0; i < floppy_disks; i++)
{
- char name[16];
-
- get_floppy_disk_name (name, i);
+ char *name;
+
+ name = get_floppy_disk_name (i);
/* In floppies, write the map, whether check_device succeeds
or not, because the user just does not insert floppies. */
if (fp)
@@ -550,6 +560,7 @@
(*map)[i] = strdup (name);
assert ((*map)[i]);
}
+ free (name);
}
#ifdef __linux__
@@ -592,9 +603,9 @@
/* IDE disks. */
for (i = 0; i < 8; i++)
{
- char name[16];
+ char *name;
- get_ide_disk_name (name, i);
+ name = get_ide_disk_name (i);
if (check_device (name))
{
(*map)[num_hd + 0x80] = strdup (name);
@@ -606,14 +617,15 @@
num_hd++;
}
+ free (name);
}
/* The rest is SCSI disks. */
for (i = 0; i < 16; i++)
{
- char name[16];
+ char *name;
- get_scsi_disk_name (name, i);
+ name = get_scsi_disk_name (i);
if (check_device (name))
{
(*map)[num_hd + 0x80] = strdup (name);
@@ -625,6 +637,7 @@
num_hd++;
}
+ free (name);
}
#ifdef __linux__
@@ -640,9 +653,9 @@
{
for (drive = 0; drive < 15; drive++)
{
- char name[24];
+ char *name;
- get_dac960_disk_name (name, controller, drive);
+ name = get_dac960_disk_name (controller, drive);
if (check_device (name))
{
(*map)[num_hd + 0x80] = strdup (name);
@@ -654,6 +667,7 @@
num_hd++;
}
+ free (name);
}
}
}
_______________________________________________
Bug-grub mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-grub