]> git.proxmox.com Git - grub2.git/blobdiff - util/raid.c
Eliminate fixed limit on reed solomon decoder length.
[grub2.git] / util / raid.c
index edf865aa79d8066f318d106628a2a0b8f9d3e204..8de5fbac0c54185d2eaf730a492e0aeead0cde17 100644 (file)
 #ifdef __linux__
 #include <grub/emu/misc.h>
 #include <grub/util/misc.h>
-#include <grub/util/raid.h>
+#include <grub/emu/getroot.h>
 
 #include <string.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <errno.h>
+#include <sys/types.h>
 
 #include <linux/types.h>
 #include <linux/major.h>
 #include <linux/raid/md_p.h>
 #include <linux/raid/md_u.h>
-
-static char *
-grub_util_getdiskname (int major, int minor)
-{
-  char *name = xmalloc (15);
-
-  if (major == LOOP_MAJOR)
-    sprintf (name, "/dev/loop%d", minor);
-  else if (major == IDE0_MAJOR)
-    sprintf (name, "/dev/hd%c", 'a' + minor / 64);
-  else if (major == IDE1_MAJOR)
-    sprintf (name, "/dev/hd%c", 'c' + minor / 64);
-  else if (major == IDE2_MAJOR)
-    sprintf (name, "/dev/hd%c", 'e' + minor / 64);
-  else if (major == IDE3_MAJOR)
-    sprintf (name, "/dev/hd%c", 'g' + minor / 64);
-  else if (major == SCSI_DISK0_MAJOR)
-    sprintf (name, "/dev/sd%c", 'a' + minor / 16);
-  else
-    grub_util_error ("unknown device number: %d, %d", major, minor);
-
-  return name;
-}
+#include <grub/i18n.h>
 
 char **
-grub_util_raid_getmembers (char *name)
+grub_util_raid_getmembers (const char *name, int bootable)
 {
   int fd, ret, i, j;
-  char *devname;
   char **devicelist;
   mdu_version_t version;
   mdu_array_info_t info;
   mdu_disk_info_t disk;
 
-  devname = xmalloc (strlen (name) + 6);
-  strcpy (devname, "/dev/");
-  strcpy (devname+5, name);
-
-  fd = open (devname, O_RDONLY);
+  fd = open (name, O_RDONLY);
 
   if (fd == -1)
-    grub_util_error ("can't open %s: %s", devname, strerror (errno));
-
-  free (devname);
+    grub_util_error (_("can't open %s: %s"), name, strerror (errno));
 
   ret = ioctl (fd, RAID_VERSION, &version);
   if (ret != 0)
-    grub_util_error ("ioctl RAID_VERSION error: %s", strerror (errno));
+    grub_util_error (_("ioctl RAID_VERSION error: %s"), strerror (errno));
+
+  if ((version.major != 0 || version.minor != 90)
+      && (version.major != 1 || version.minor != 0)
+      && (version.major != 1 || version.minor != 1)
+      && (version.major != 1 || version.minor != 2))
+    grub_util_error (_("unsupported RAID version: %d.%d"),
+                    version.major, version.minor);
 
-  if (version.major != 0 || version.minor != 90)
-    grub_util_error ("unsupported RAID version: %d.%d",
+  if (bootable && (version.major != 0 || version.minor != 90))
+    grub_util_error (_("unsupported RAID version: %d.%d"),
                     version.major, version.minor);
 
   ret = ioctl (fd, GET_ARRAY_INFO, &info);
   if (ret != 0)
-    grub_util_error ("ioctl GET_ARRAY_INFO error: %s", strerror (errno));
+    grub_util_error (_("ioctl GET_ARRAY_INFO error: %s"), strerror (errno));
 
   devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *));
 
@@ -96,17 +75,20 @@ grub_util_raid_getmembers (char *name)
       disk.number = i;
       ret = ioctl (fd, GET_DISK_INFO, &disk);
       if (ret != 0)
-       grub_util_error ("ioctl GET_DISK_INFO error: %s", strerror (errno));
+       grub_util_error (_("ioctl GET_DISK_INFO error: %s"), strerror (errno));
 
       if (disk.state & (1 << MD_DISK_ACTIVE))
        {
-         devicelist[j] = grub_util_getdiskname (disk.major, disk.minor);
+         devicelist[j] = grub_find_device (NULL,
+                                           makedev (disk.major, disk.minor));
          j++;
        }
     }
 
   devicelist[j] = NULL;
 
+  close (fd);
+
   return devicelist;
 }