make the linux-ppc packags be in synch with other platforms
[tangerine.git] / arch / common / boot / grub2 / util / raid.c
blobe1ccff4efae77d18419eae561eacf3cb98bc2043
1 /* raid.c - RAID support for GRUB utils. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2006,2007 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 /* We only support RAID on Linux. */
21 #ifdef __linux__
22 #include <grub/util/misc.h>
24 #include <string.h>
25 #include <fcntl.h>
26 #include <sys/ioctl.h>
27 #include <errno.h>
29 #include <linux/types.h>
30 #include <linux/major.h>
31 #include <linux/raid/md_p.h>
32 #include <linux/raid/md_u.h>
34 char *
35 grub_util_getdiskname (int major, int minor)
37 char *name = xmalloc (15);
39 if (major == LOOP_MAJOR)
40 sprintf (name, "/dev/loop%d", minor);
41 else if (major == IDE0_MAJOR)
42 sprintf (name, "/dev/hd%c", 'a' + minor / 64);
43 else if (major == IDE1_MAJOR)
44 sprintf (name, "/dev/hd%c", 'c' + minor / 64);
45 else if (major == IDE2_MAJOR)
46 sprintf (name, "/dev/hd%c", 'e' + minor / 64);
47 else if (major == IDE3_MAJOR)
48 sprintf (name, "/dev/hd%c", 'g' + minor / 64);
49 else if (major == SCSI_DISK0_MAJOR)
50 sprintf (name, "/dev/sd%c", 'a' + minor / 16);
51 else
52 grub_util_error ("Unknown device number: %d, %d", major, minor);
54 return name;
57 char **
58 grub_util_raid_getmembers (char *name)
60 int fd, ret, i, j;
61 char *devname;
62 char **devicelist;
63 mdu_version_t version;
64 mdu_array_info_t info;
65 mdu_disk_info_t disk;
67 devname = xmalloc (strlen (name) + 6);
68 strcpy (devname, "/dev/");
69 strcpy (devname+5, name);
71 fd = open (devname, O_RDONLY);
73 if (fd == -1)
74 grub_util_error ("Can't open %s: %s", devname, strerror (errno));
76 free (devname);
78 ret = ioctl (fd, RAID_VERSION, &version);
79 if (ret != 0)
80 grub_util_error ("ioctl RAID_VERSION error: %s", strerror (errno));
82 if (version.major != 0 || version.minor != 90)
83 grub_util_error ("Unsupported RAID version: %d.%d",
84 version.major, version.minor);
86 ret = ioctl (fd, GET_ARRAY_INFO, &info);
87 if (ret != 0)
88 grub_util_error ("ioctl GET_ARRAY_INFO error: %s", strerror (errno));
90 devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *));
92 for (i = 0, j = 0; i <info.nr_disks; i++)
94 disk.number = i;
95 ret = ioctl (fd, GET_DISK_INFO, &disk);
96 if (ret != 0)
97 grub_util_error ("ioctl GET_DISK_INFO error: %s", strerror (errno));
99 if (disk.state & (1 << MD_DISK_ACTIVE))
101 devicelist[j] = grub_util_getdiskname (disk.major, disk.minor);
102 j++;
106 devicelist[j] = NULL;
108 return devicelist;
111 #endif /* ! __linux__ */