grub/util/raid.c
Vladimir 'phcoder' Serbinenko 0ae70393ba Improve and unify messages.
* grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors): Add argument
	name. All users updated.
	Print filename in error.
	(read_device_map): Print filename in error.
	* util/getroot.c (grub_guess_root_devices): Print filename in error.
	(grub_util_get_os_disk): Likewise.
	(grub_util_biosdisk_get_grub_dev): Likewise.
	(grub_util_check_block_device): Likewise.
	(grub_util_check_char_device): Likewise.
	(grub_make_system_path_relative_to_its_root): Likewise.
	* util/grub-editenv.c (create_envblk_file): Likewise.
	(open_envblk_file): Likewise.
	(write_envblk): Likewise.
	* util/grub-fstest.c (cmd_cp): Likewise.
	(cmd_cat): Likewise.
	(cmd_cmp): Likewise.
	* util/grub-menulst2cfg.c (main): Likewise.
	* util/grub-mkfont.c (write_font_ascii_bitmap): Likewise.
	(write_font_width_spec): Likewise.
	(write_font_pf2): Likewise.
	* util/grub-mkimage.c (generate_image): New argument outname.
	All users updated.
	Remove unreacheable message.
	(options): Unify messages.
	(help_filter): Likewise.
	* util/grub-mklayout.c (usage): Removed (unused).
	(main): Print filename in error.
	* util/grub-mkrescue.in: Fix wrong quoting.
	* util/grub-setup.c (setup): Print filename in error.
	* util/ieee1275/ofpath.c (vendor_is_ATA): Likewise.
	(check_sas): Likewise.
	* util/misc.c (grub_util_get_fp_size): Removed.
	(grub_util_get_image_size): Print filename in error.
	(grub_util_read_at): Removed.
	(grub_util_read_image): Print filename in error.
	(grub_util_load_image): Likewise.
	(grub_util_write_image_at): New argument filename. All users updated.
	Print filename in error.
	(grub_util_write_image): New argument filename. All users updated.
	Print filename in error.
	* util/raid.c (grub_util_raid_getmembers): Print filename in error.
	* util/resolve.c (grub_util_resolve_dependencies): Likewise.
2012-02-05 11:07:33 +01:00

95 lines
2.7 KiB
C

/* 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 <http://www.gnu.org/licenses/>.
*/
/* We only support RAID on Linux. */
#ifdef __linux__
#include <grub/emu/misc.h>
#include <grub/util/misc.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>
#include <grub/i18n.h>
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; i <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_ACTIVE))
{
devicelist[j] = grub_find_device (NULL,
makedev (disk.major, disk.minor));
j++;
}
}
devicelist[j] = NULL;
close (fd);
return devicelist;
}
#endif /* ! __linux__ */