mirror of
https://git.proxmox.com/git/grub2
synced 2025-05-21 07:09:01 +00:00

Add LDM support using the same framework. * Makefile.util.def (libgrubkern): Add grub-core/disk/ldm.c, grub-core/disk/diskfilter.c and grub-core/partmap/gpt.c. (libgrubmods): Remove grub-core/disk/raid.c and grub-core/partmap/gpt.c. * grub-core/Makefile.core.def (ldm): New module. (raid): Renamed to diskfilter. All users updated. * grub-core/disk/raid.c: Moved to ... * grub-core/disk/diskfilter.c: ... here. * grub-core/disk/diskfilter.c: Rename grub_raid_ to grub_diskfilter_. (lv_num): New var. (find_array): Renamed to ... (find_lv): ... this. Support multi-LV. Skip nameless LVs (grub_is_array_readable): Renamed to ... (grub_is_lv_readable): ... this. Support multinode hierarchy. (insert_array): New argument id. (is_node_readable): New function. (scan_device): Rename to ... (scan_disk): .. this. Restrict to one disk. (scan_devices): New function. (grub_diskfilter_iterate): Support multi-LV. Skip invisible and nameless LVs. (grub_diskfilter_memberlist): Support multi-LV. (grub_diskfilter_read_node): New function. (grub_raid_read): Most of logic moved to ... (read_segment): ... here (read_lv): New function. (grub_diskfilter_get_vg_by_uuid): New function. (grub_diskfilter_make_raid): Likewise. * grub-core/disk/ldm.c: New file. * grub-core/disk/lvm.c (vg_list): Removed. (lv_count): Likewise. (scan_depth): Likewise. (is_lv_readable): Likewise. (grub_lvm_getvalue): Advance pointer past the number. (find_lv): Removed. (do_lvm_scan): Refactored into ... (grub_lvm_detect): ... this. Support raid. (grub_lvm_iterate): Removed. (grub_lvm_memberlist): Likewise. (grub_lvm_open): Likewise. (grub_lvm_close): Likewise. (read_lv): Likewise. (read_node): Likewise. (is_node_readable): Likewise. (is_lv_readable): Likewise. (grub_lvm_read): Likewise. (grub_lvm_write): Likewise. (grub_lvm_dev): Use diskfilter (GRUB_MOD_INIT): Likewise. (GRUB_MOD_FINI): Likewise. * grub-core/disk/dmraid_nvidia.c (grub_dmraid_nv_detect): Use new interface. * grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Likewise. * grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Likewise. * grub-core/disk/raid5_recover.c (grub_raid5_recover): Use grub_diskfilter_read_node. Fix a bug with xor. * grub-core/disk/raid6_recover.c (grub_raid6_recover): Use grub_diskfilter_read_node. Support GRUB_RAID_LAYOUT_MUL_FROM_POS. * grub-core/kern/disk.c (grub_disk_dev_list): Make global. (grub_disk_dev_iterate): Move from here... * include/grub/disk.h (grub_disk_dev_iterate): ... to here. Inlined. * grub-core/kern/emu/hostdisk.c (grub_hostdisk_find_partition_start): Make global. (grub_hostdisk_find_partition_start): Likewise. (grub_hostdisk_os_dev_to_grub_drive): New function. (grub_util_biosdisk_get_osdev): Check that disk is biosdisk. * grub-core/kern/emu/hostdisk.c (make_device_name): Move to ... * util/getroot.c (make_device_name): ... here. * grub-core/kern/emu/hostdisk.c (grub_util_get_dm_node_linear_info): Move to ... * util/getroot.c (grub_util_get_dm_node_linear_info): ...here. * grub-core/kern/emu/hostdisk.c (convert_system_partition_to_system_disk): Move to ... * util/getroot.c (convert_system_partition_to_system_disk): ...here. * grub-core/kern/emu/hostdisk.c (device_is_wholedisk): Move to ... * util/getroot.c (device_is_wholedisk): ... here. * grub-core/kern/emu/hostdisk.c (find_system_device): Move to ... * util/getroot.c (find_system_device): ... here. * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_present): Move to ... * util/getroot.c (grub_util_biosdisk_is_present): ...here. * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_get_grub_dev): Move to ... * util/getroot.c (grub_util_biosdisk_get_grub_dev): ... here. Handle LDM. * grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_is_floppy): Move to ... * util/getroot.c (grub_util_biosdisk_is_floppy): ... here. * grub-core/partmap/gpt.c (grub_gpt_partition_map_iterate): Made global. * include/grub/disk.h (grub_disk_dev_id): Replaced RAID and LVM with DISKFILTER. * include/grub/raid.h: Renamed to ... * include/grub/diskfilter.h: ... this. * include/grub/diskfilter.h: Rename grub_raid_* to grub_diskfilter_* (GRUB_RAID_LAYOUT_*): Make into array. (GRUB_RAID_LAYOUT_MUL_FROM_POS): New value. (grub_diskfilter_vg): New struct. (grub_diskfilter_pv_id): Likewise. (grub_raid_member): Removed. (grub_raid_array): Likewise. (grub_diskfilter_pv): New struct. (grub_diskfilter_lv): Likewise. (grub_diskfilter_segment): Likewise. (grub_diskfilter_node): Likewise. (grub_diskfilter_get_vg_by_uuid): New proto. (grub_raid_register): Inline. (grub_diskfilter_unregister): Likewise. (grub_diskfilter_make_raid): New proto. (grub_diskfilter_vg_register): Likewise. (grub_diskfilter_read_node): Likewise. (grub_diskfilter_get_pv_from_disk) [GRUB_UTIL]: Likewise. * include/grub/emu/hostdisk.h (grub_util_get_ldm): New proto. (grub_util_is_ldm): Likewise. (grub_util_ldm_embed) [GRUB_UTIL]: Likewise. (grub_hostdisk_find_partition_start): Likewise. (grub_hostdisk_os_dev_to_grub_drive): Likewise. * include/grub/gpt_partition.h (GRUB_GPT_PARTITION_TYPE_LDM): New definition. (grub_gpt_partition_map_iterate): New proto. * include/grub/lvm.h (grub_lvm_vg): Removed. (grub_lvm_pv): Likewise. (grub_lvm_lv): Likewise. (grub_lvm_segment): Likewise. (grub_lvm_node): Likewise. * util/getroot.c [...] * util/grub-probe.c (probe_raid_level): Handle diskfilter. (probe_abstraction): Likewise. * util/grub-setup.c (setup): Remove must_embed. Support LDM. (main): Remove dead logic.
213 lines
6.0 KiB
C
213 lines
6.0 KiB
C
/*
|
|
* GRUB -- GRand Unified Bootloader
|
|
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 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/>.
|
|
*/
|
|
|
|
#ifndef GRUB_DISK_HEADER
|
|
#define GRUB_DISK_HEADER 1
|
|
|
|
#include <grub/symbol.h>
|
|
#include <grub/err.h>
|
|
#include <grub/types.h>
|
|
#include <grub/device.h>
|
|
|
|
/* These are used to set a device id. When you add a new disk device,
|
|
you must define a new id for it here. */
|
|
enum grub_disk_dev_id
|
|
{
|
|
GRUB_DISK_DEVICE_BIOSDISK_ID,
|
|
GRUB_DISK_DEVICE_OFDISK_ID,
|
|
GRUB_DISK_DEVICE_LOOPBACK_ID,
|
|
GRUB_DISK_DEVICE_EFIDISK_ID,
|
|
GRUB_DISK_DEVICE_DISKFILTER_ID,
|
|
GRUB_DISK_DEVICE_HOST_ID,
|
|
GRUB_DISK_DEVICE_ATA_ID,
|
|
GRUB_DISK_DEVICE_MEMDISK_ID,
|
|
GRUB_DISK_DEVICE_NAND_ID,
|
|
GRUB_DISK_DEVICE_UUID_ID,
|
|
GRUB_DISK_DEVICE_PXE_ID,
|
|
GRUB_DISK_DEVICE_SCSI_ID,
|
|
GRUB_DISK_DEVICE_FILE_ID,
|
|
GRUB_DISK_DEVICE_CRYPTODISK_ID,
|
|
GRUB_DISK_DEVICE_ARCDISK_ID,
|
|
};
|
|
|
|
struct grub_disk;
|
|
#ifdef GRUB_UTIL
|
|
struct grub_disk_memberlist;
|
|
#endif
|
|
|
|
typedef enum
|
|
{
|
|
GRUB_DISK_PULL_NONE,
|
|
GRUB_DISK_PULL_REMOVABLE,
|
|
GRUB_DISK_PULL_RESCAN,
|
|
GRUB_DISK_PULL_MAX
|
|
} grub_disk_pull_t;
|
|
|
|
/* Disk device. */
|
|
struct grub_disk_dev
|
|
{
|
|
/* The device name. */
|
|
const char *name;
|
|
|
|
/* The device id used by the cache manager. */
|
|
enum grub_disk_dev_id id;
|
|
|
|
/* Call HOOK with each device name, until HOOK returns non-zero. */
|
|
int (*iterate) (int (*hook) (const char *name),
|
|
grub_disk_pull_t pull);
|
|
|
|
/* Open the device named NAME, and set up DISK. */
|
|
grub_err_t (*open) (const char *name, struct grub_disk *disk);
|
|
|
|
/* Close the disk DISK. */
|
|
void (*close) (struct grub_disk *disk);
|
|
|
|
/* Read SIZE sectors from the sector SECTOR of the disk DISK into BUF. */
|
|
grub_err_t (*read) (struct grub_disk *disk, grub_disk_addr_t sector,
|
|
grub_size_t size, char *buf);
|
|
|
|
/* Write SIZE sectors from BUF into the sector SECTOR of the disk DISK. */
|
|
grub_err_t (*write) (struct grub_disk *disk, grub_disk_addr_t sector,
|
|
grub_size_t size, const char *buf);
|
|
|
|
#ifdef GRUB_UTIL
|
|
struct grub_disk_memberlist *(*memberlist) (struct grub_disk *disk);
|
|
const char * (*raidname) (struct grub_disk *disk);
|
|
#endif
|
|
|
|
/* The next disk device. */
|
|
struct grub_disk_dev *next;
|
|
};
|
|
typedef struct grub_disk_dev *grub_disk_dev_t;
|
|
|
|
extern grub_disk_dev_t EXPORT_VAR (grub_disk_dev_list);
|
|
|
|
struct grub_partition;
|
|
|
|
/* Disk. */
|
|
struct grub_disk
|
|
{
|
|
/* The disk name. */
|
|
const char *name;
|
|
|
|
/* The underlying disk device. */
|
|
grub_disk_dev_t dev;
|
|
|
|
/* The total number of sectors. */
|
|
grub_uint64_t total_sectors;
|
|
|
|
/* Logarithm of sector size. */
|
|
unsigned int log_sector_size;
|
|
|
|
/* The id used by the disk cache manager. */
|
|
unsigned long id;
|
|
|
|
/* The partition information. This is machine-specific. */
|
|
struct grub_partition *partition;
|
|
|
|
/* Called when a sector was read. OFFSET is between 0 and
|
|
the sector size minus 1, and LENGTH is between 0 and the sector size. */
|
|
void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
|
|
unsigned offset, unsigned length);
|
|
|
|
/* Device-specific data. */
|
|
void *data;
|
|
};
|
|
typedef struct grub_disk *grub_disk_t;
|
|
|
|
#ifdef GRUB_UTIL
|
|
struct grub_disk_memberlist
|
|
{
|
|
grub_disk_t disk;
|
|
struct grub_disk_memberlist *next;
|
|
};
|
|
typedef struct grub_disk_memberlist *grub_disk_memberlist_t;
|
|
#endif
|
|
|
|
/* The sector size. */
|
|
#define GRUB_DISK_SECTOR_SIZE 0x200
|
|
#define GRUB_DISK_SECTOR_BITS 9
|
|
|
|
/* The maximum number of disk caches. */
|
|
#define GRUB_DISK_CACHE_NUM 1021
|
|
|
|
/* The size of a disk cache in 512B units. Must be at least as big as the
|
|
largest supported sector size, currently 16K. */
|
|
#define GRUB_DISK_CACHE_BITS 6
|
|
#define GRUB_DISK_CACHE_SIZE (1 << GRUB_DISK_CACHE_BITS)
|
|
|
|
/* Return value of grub_disk_get_size() in case disk size is unknown. */
|
|
#define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL
|
|
|
|
/* This is called from the memory manager. */
|
|
void grub_disk_cache_invalidate_all (void);
|
|
|
|
void EXPORT_FUNC(grub_disk_dev_register) (grub_disk_dev_t dev);
|
|
void EXPORT_FUNC(grub_disk_dev_unregister) (grub_disk_dev_t dev);
|
|
static inline int
|
|
grub_disk_dev_iterate (int (*hook) (const char *name))
|
|
{
|
|
grub_disk_dev_t p;
|
|
grub_disk_pull_t pull;
|
|
|
|
for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++)
|
|
for (p = grub_disk_dev_list; p; p = p->next)
|
|
if (p->iterate && (p->iterate) (hook, pull))
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
grub_disk_t EXPORT_FUNC(grub_disk_open) (const char *name);
|
|
void EXPORT_FUNC(grub_disk_close) (grub_disk_t disk);
|
|
grub_err_t EXPORT_FUNC(grub_disk_read) (grub_disk_t disk,
|
|
grub_disk_addr_t sector,
|
|
grub_off_t offset,
|
|
grub_size_t size,
|
|
void *buf);
|
|
grub_err_t EXPORT_FUNC(grub_disk_write) (grub_disk_t disk,
|
|
grub_disk_addr_t sector,
|
|
grub_off_t offset,
|
|
grub_size_t size,
|
|
const void *buf);
|
|
|
|
grub_uint64_t EXPORT_FUNC(grub_disk_get_size) (grub_disk_t disk);
|
|
|
|
#if DISK_CACHE_STATS
|
|
void
|
|
EXPORT_FUNC(grub_disk_cache_get_performance) (unsigned long *hits, unsigned long *misses);
|
|
#endif
|
|
|
|
extern void (* EXPORT_VAR(grub_disk_firmware_fini)) (void);
|
|
extern int EXPORT_VAR(grub_disk_firmware_is_tainted);
|
|
|
|
#if defined (GRUB_UTIL) || defined (GRUB_MACHINE_EMU)
|
|
void grub_lvm_init (void);
|
|
void grub_ldm_init (void);
|
|
void grub_mdraid09_init (void);
|
|
void grub_mdraid1x_init (void);
|
|
void grub_diskfilter_init (void);
|
|
void grub_lvm_fini (void);
|
|
void grub_ldm_fini (void);
|
|
void grub_mdraid09_fini (void);
|
|
void grub_mdraid1x_fini (void);
|
|
void grub_diskfilter_fini (void);
|
|
#endif
|
|
|
|
#endif /* ! GRUB_DISK_HEADER */
|