From cef86fefda32531828cf0aaeeb9cc7051f21bf23 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 8 Oct 2013 16:59:50 +0200 Subject: [PATCH] * util/raid.c: Fold into ... * util/getroot_linux.c: ... here. Make all functions static. --- ChangeLog | 5 ++ Makefile.util.def | 1 - include/grub/emu/getroot.h | 3 -- util/getroot_linux.c | 66 +++++++++++++++++++++++++ util/raid.c | 98 -------------------------------------- 5 files changed, 71 insertions(+), 102 deletions(-) delete mode 100644 util/raid.c diff --git a/ChangeLog b/ChangeLog index faea7a5a6..32dc7b5b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-10-08 Vladimir Serbinenko + + * util/raid.c: Fold into ... + * util/getroot_linux.c: ... here. Make all functions static. + 2013-10-08 Vladimir Serbinenko * grub-core/fs/zfs/zfs_lz4.c: Switch from ad-hoc endiannes and width diff --git a/Makefile.util.def b/Makefile.util.def index cfd94d2c4..710be2f28 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -13,7 +13,6 @@ library = { common = util/getroot_unix.c; common = util/getroot_os.c; common = util/getroot_devmapper.c; - common = util/raid.c; common = grub-core/kern/emu/hostdisk.c; common = grub-core/kern/emu/hostdisk_devmapper.c; common = grub-core/kern/emu/hostdisk_os.c; diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h index 8762788b7..96ec40e60 100644 --- a/include/grub/emu/getroot.h +++ b/include/grub/emu/getroot.h @@ -39,9 +39,6 @@ char *grub_make_system_path_relative_to_its_root (const char *path); const char *grub_util_check_block_device (const char *blk_dev); const char *grub_util_check_char_device (const char *blk_dev); char *grub_util_get_grub_dev (const char *os_dev); -#ifdef __linux__ -char **grub_util_raid_getmembers (const char *name, int bootable); -#endif #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) void grub_util_follow_gpart_up (const char *name, grub_disk_addr_t *off_out, char **name_out); diff --git a/util/getroot_linux.c b/util/getroot_linux.c index 13b78e5a3..b1fede8f6 100644 --- a/util/getroot_linux.c +++ b/util/getroot_linux.c @@ -49,6 +49,12 @@ #include +#include +#include +#include +#include +#include + /* Defines taken from btrfs/ioctl.h. */ @@ -88,6 +94,66 @@ struct mountinfo_entry char fstype[ESCAPED_PATH_MAX + 1], device[ESCAPED_PATH_MAX + 1]; }; +static char ** +grub_util_raid_getmembers (const char *name, int bootable) +{ + int fd, ret, i, j; + char **devicelist; + mdu_version_t version; + mdu_array_info_t info; + mdu_disk_info_t disk; + + fd = open (name, O_RDONLY); + + if (fd == -1) + grub_util_error (_("cannot 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)); + + 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 (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)); + + devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *)); + + for (i = 0, j = 0; j < info.nr_disks; i++) + { + disk.number = i; + ret = ioctl (fd, GET_DISK_INFO, &disk); + if (ret != 0) + grub_util_error (_("ioctl GET_DISK_INFO error: %s"), strerror (errno)); + + if (disk.state & (1 << MD_DISK_REMOVED)) + continue; + + if (disk.state & (1 << MD_DISK_ACTIVE)) + devicelist[j] = grub_find_device (NULL, + makedev (disk.major, disk.minor)); + else + devicelist[j] = NULL; + j++; + } + + devicelist[j] = NULL; + + close (fd); + + return devicelist; +} + /* Statting something on a btrfs filesystem always returns a virtual device major/minor pair rather than the real underlying device, because btrfs can span multiple underlying devices (and even if it's currently only diff --git a/util/raid.c b/util/raid.c deleted file mode 100644 index f73ae76c2..000000000 --- a/util/raid.c +++ /dev/null @@ -1,98 +0,0 @@ -/* raid.c - RAID support for GRUB utils. */ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -/* We only support RAID on Linux. */ -#ifdef __linux__ -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -char ** -grub_util_raid_getmembers (const char *name, int bootable) -{ - int fd, ret, i, j; - char **devicelist; - mdu_version_t version; - mdu_array_info_t info; - mdu_disk_info_t disk; - - fd = open (name, O_RDONLY); - - if (fd == -1) - grub_util_error (_("cannot 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)); - - 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 (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)); - - devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *)); - - for (i = 0, j = 0; j < info.nr_disks; i++) - { - disk.number = i; - ret = ioctl (fd, GET_DISK_INFO, &disk); - if (ret != 0) - grub_util_error (_("ioctl GET_DISK_INFO error: %s"), strerror (errno)); - - if (disk.state & (1 << MD_DISK_REMOVED)) - continue; - - if (disk.state & (1 << MD_DISK_ACTIVE)) - devicelist[j] = grub_find_device (NULL, - makedev (disk.major, disk.minor)); - else - devicelist[j] = NULL; - j++; - } - - devicelist[j] = NULL; - - close (fd); - - return devicelist; -} - -#endif /* ! __linux__ */