2N/A/* raid.c - RAID support for GRUB utils. */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A/* We only support RAID on Linux. */
2N/A#ifdef __linux__
2N/A#include <grub/emu/misc.h>
2N/A#include <grub/util/misc.h>
2N/A#include <grub/emu/getroot.h>
2N/A
2N/A#include <string.h>
2N/A#include <fcntl.h>
2N/A#include <sys/ioctl.h>
2N/A#include <errno.h>
2N/A#include <sys/types.h>
2N/A
2N/A#include <linux/types.h>
2N/A#include <linux/major.h>
2N/A#include <linux/raid/md_p.h>
2N/A#include <linux/raid/md_u.h>
2N/A#include <grub/i18n.h>
2N/A
2N/Achar **
2N/Agrub_util_raid_getmembers (const char *name, int bootable)
2N/A{
2N/A int fd, ret, i, j;
2N/A char **devicelist;
2N/A mdu_version_t version;
2N/A mdu_array_info_t info;
2N/A mdu_disk_info_t disk;
2N/A
2N/A fd = open (name, O_RDONLY);
2N/A
2N/A if (fd == -1)
2N/A grub_util_error (_("can't open %s: %s"), name, strerror (errno));
2N/A
2N/A ret = ioctl (fd, RAID_VERSION, &version);
2N/A if (ret != 0)
2N/A grub_util_error (_("ioctl RAID_VERSION error: %s"), strerror (errno));
2N/A
2N/A if ((version.major != 0 || version.minor != 90)
2N/A && (version.major != 1 || version.minor != 0)
2N/A && (version.major != 1 || version.minor != 1)
2N/A && (version.major != 1 || version.minor != 2))
2N/A grub_util_error (_("unsupported RAID version: %d.%d"),
2N/A version.major, version.minor);
2N/A
2N/A if (bootable && (version.major != 0 || version.minor != 90))
2N/A grub_util_error (_("unsupported RAID version: %d.%d"),
2N/A version.major, version.minor);
2N/A
2N/A ret = ioctl (fd, GET_ARRAY_INFO, &info);
2N/A if (ret != 0)
2N/A grub_util_error (_("ioctl GET_ARRAY_INFO error: %s"), strerror (errno));
2N/A
2N/A devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *));
2N/A
2N/A for (i = 0, j = 0; i <info.nr_disks; i++)
2N/A {
2N/A disk.number = i;
2N/A ret = ioctl (fd, GET_DISK_INFO, &disk);
2N/A if (ret != 0)
2N/A grub_util_error (_("ioctl GET_DISK_INFO error: %s"), strerror (errno));
2N/A
2N/A if (disk.state & (1 << MD_DISK_ACTIVE))
2N/A {
2N/A devicelist[j] = grub_find_device (NULL,
2N/A makedev (disk.major, disk.minor));
2N/A j++;
2N/A }
2N/A }
2N/A
2N/A devicelist[j] = NULL;
2N/A
2N/A close (fd);
2N/A
2N/A return devicelist;
2N/A}
2N/A
2N/A#endif /* ! __linux__ */