add linux devfs support into the grub shell.

This commit is contained in:
okuji 2000-10-15 16:39:04 +00:00
parent 0f8fdcc8b2
commit 84cd6e2879
3 changed files with 88 additions and 4 deletions

View file

@ -1,3 +1,17 @@
2000-10-16 OKUJI Yoshinori <okuji@gnu.org>
From Roderich Schupp:
* lib/device.c: Include <limits.h>.
[__linux__] (have_devfs): New function.
(get_floppy_disk_name) [__linux__]: If devfs is supported, use
the name "/dev/floppy/N" instead.
(init_device_map) [__linux__]: If devfs is supported, use
"/dev/discs/discN" instead.
[__linux__] (write_to_partition): Change the size of DEV to
PATH_MAX instead of 64.
If devfs is supported, replace "/disc" in the device name with
"/part".
2000-10-15 OKUJI Yoshinori <okuji@gnu.org> 2000-10-15 OKUJI Yoshinori <okuji@gnu.org>
From Roderich Schupp <rsch@ExperTeam.de>: From Roderich Schupp <rsch@ExperTeam.de>:

1
NEWS
View file

@ -3,6 +3,7 @@ NEWS - list of user-visible changes between releases of GRUB
New in 1.0 - XXXX-XX-XX: New in 1.0 - XXXX-XX-XX:
* The command "setkey" resets key mappings, when no argument is * The command "setkey" resets key mappings, when no argument is
specified. specified.
* Linux devfs support is added.
New in 0.5.96 - 2000-10-04: New in 0.5.96 - 2000-10-04:
* New commands, "reboot" and "halt". * New commands, "reboot" and "halt".

View file

@ -33,6 +33,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <limits.h>
#ifdef __linux__ #ifdef __linux__
# if !defined(__GLIBC__) || \ # if !defined(__GLIBC__) || \
@ -148,12 +149,36 @@ partially. This is not fatal."
close (fd); close (fd);
} }
#ifdef __linux__
/* Check if we have devfs support. */
static int
have_devfs (void)
{
static int dev_devfsd_exists = -1;
if (dev_devfsd_exists < 0)
{
struct stat st;
dev_devfsd_exists = stat ("/dev/.devfsd", &st) == 0;
}
return dev_devfsd_exists;
}
#endif /* __linux__ */
/* These three functions are quite different among OSes. */ /* These three functions are quite different among OSes. */
static void static void
get_floppy_disk_name (char *name, int unit) get_floppy_disk_name (char *name, int unit)
{ {
#if defined(__linux__) || defined(__GNU__) #if defined(__linux__)
/* GNU/Linux and GNU/Hurd */ /* GNU/Linux */
if (have_devfs ())
sprintf (name, "/dev/floppy/%d", unit);
else
sprintf (name, "/dev/fd%d", unit);
#elif defined(__GNU__)
/* GNU/Hurd */
sprintf (name, "/dev/fd%d", unit); sprintf (name, "/dev/fd%d", unit);
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
/* FreeBSD */ /* FreeBSD */
@ -469,6 +494,43 @@ init_device_map (char ***map, const char *map_file, int floppy_disks)
} }
} }
#ifdef __linux__
if (have_devfs ())
{
while (1)
{
char discn[32];
char name[PATH_MAX];
struct stat st;
/* Linux creates symlinks "/dev/discs/discN" for convenience.
The way to number disks is the same as GRUB's. */
sprintf (discn, "/dev/discs/disc%d", num_hd);
if (stat (discn, &st) < 0)
break;
if (realpath (discn, name))
{
strcat (name, "/disc");
(*map)[num_hd + 0x80] = strdup (name);
assert ((*map)[num_hd + 0x80]);
/* If the device map file is opened, write the map. */
if (fp)
fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
}
num_hd++;
}
/* OK, close the device map file if opened. */
if (fp)
fclose (fp);
return 1;
}
#endif /* __linux__ */
/* IDE disks. */ /* IDE disks. */
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
@ -535,7 +597,7 @@ int
write_to_partition (char **map, int drive, int partition, write_to_partition (char **map, int drive, int partition,
int sector, int size, const char *buf) int sector, int size, const char *buf)
{ {
char dev[64]; /* XXX */ char dev[PATH_MAX]; /* XXX */
int fd; int fd;
if ((partition & 0x00FF00) != 0x00FF00) if ((partition & 0x00FF00) != 0x00FF00)
@ -547,7 +609,14 @@ write_to_partition (char **map, int drive, int partition,
} }
assert (map[drive] != 0); assert (map[drive] != 0);
sprintf (dev, "%s%d", map[drive], ((partition >> 16) & 0xFF) + 1);
strcpy (dev, map[drive]);
if (have_devfs ())
{
if (strcmp (dev + strlen(dev) - 5, "/disc") == 0)
strcat (dev + strlen(dev) - 5, "/part");
}
sprintf (dev + strlen(dev), "%d", ((partition >> 16) & 0xFF) + 1);
/* Open the partition. */ /* Open the partition. */
fd = open (dev, O_RDWR); fd = open (dev, O_RDWR);