]>
git.proxmox.com Git - grub2.git/blob - util/raid.c
1 /* raid.c - RAID support for GRUB utils. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2006,2007,2008 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. */
22 #include <grub/emu/misc.h>
23 #include <grub/util/misc.h>
24 #include <grub/util/raid.h>
25 #include <grub/emu/getroot.h>
29 #include <sys/ioctl.h>
31 #include <sys/types.h>
33 #include <linux/types.h>
34 #include <linux/major.h>
35 #include <linux/raid/md_p.h>
36 #include <linux/raid/md_u.h>
39 grub_util_raid_getmembers (char *name
)
44 mdu_version_t version
;
45 mdu_array_info_t info
;
48 devname
= xmalloc (strlen (name
) + 6);
49 strcpy (devname
, "/dev/");
50 strcpy (devname
+5, name
);
52 fd
= open (devname
, O_RDONLY
);
55 grub_util_error ("can't open %s: %s", devname
, strerror (errno
));
59 ret
= ioctl (fd
, RAID_VERSION
, &version
);
61 grub_util_error ("ioctl RAID_VERSION error: %s", strerror (errno
));
63 if (version
.major
!= 0 || version
.minor
!= 90)
64 grub_util_error ("unsupported RAID version: %d.%d",
65 version
.major
, version
.minor
);
67 ret
= ioctl (fd
, GET_ARRAY_INFO
, &info
);
69 grub_util_error ("ioctl GET_ARRAY_INFO error: %s", strerror (errno
));
71 devicelist
= xmalloc ((info
.nr_disks
+ 1) * sizeof (char *));
73 for (i
= 0, j
= 0; i
<info
.nr_disks
; i
++)
76 ret
= ioctl (fd
, GET_DISK_INFO
, &disk
);
78 grub_util_error ("ioctl GET_DISK_INFO error: %s", strerror (errno
));
80 if (disk
.state
& (1 << MD_DISK_ACTIVE
))
82 devicelist
[j
] = grub_find_device (NULL
,
83 makedev (disk
.major
, disk
.minor
));
93 #endif /* ! __linux__ */