Simplify disk opening
This commit is contained in:
parent
00542307eb
commit
0044d1db2e
15 changed files with 29 additions and 49 deletions
|
@ -79,7 +79,8 @@ arcdisk_hash_add (char *devpath)
|
|||
|
||||
|
||||
static int
|
||||
grub_arcdisk_iterate (int (*hook_in) (const char *name))
|
||||
grub_arcdisk_iterate (int (*hook_in) (const char *name),
|
||||
grub_disk_pull_t pull)
|
||||
{
|
||||
auto int hook (const char *name, const struct grub_arc_component *comp);
|
||||
int hook (const char *name, const struct grub_arc_component *comp)
|
||||
|
@ -90,6 +91,9 @@ grub_arcdisk_iterate (int (*hook_in) (const char *name))
|
|||
return 0;
|
||||
return hook_in (name);
|
||||
}
|
||||
if (pull != GRUB_DISK_PULL_NONE)
|
||||
return 0;
|
||||
|
||||
return grub_arc_iterate_devs (hook, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -412,8 +412,7 @@ grub_ata_iterate (int (*hook_in) (const char *name),
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ata_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
grub_ata_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
unsigned id, bus;
|
||||
struct grub_ata *ata;
|
||||
|
|
|
@ -454,8 +454,7 @@ get_device (struct grub_efidisk_data *devices, int num)
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_efidisk_open (const char *name, struct grub_disk *disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
grub_efidisk_open (const char *name, struct grub_disk *disk)
|
||||
{
|
||||
int num;
|
||||
struct grub_efidisk_data *d = 0;
|
||||
|
|
|
@ -39,8 +39,7 @@ grub_host_iterate (int (*hook) (const char *name),
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_host_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
grub_host_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
if (grub_strcmp (name, "host"))
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a host disk");
|
||||
|
|
|
@ -328,8 +328,7 @@ grub_biosdisk_iterate (int (*hook) (const char *name),
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_biosdisk_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
grub_biosdisk_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
grub_uint64_t total_sectors = 0;
|
||||
int drive;
|
||||
|
|
|
@ -58,8 +58,7 @@ grub_nand_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
grub_size_t size, char *buf);
|
||||
|
||||
static grub_err_t
|
||||
grub_nand_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
grub_nand_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
grub_ieee1275_ihandle_t dev_ihandle = 0;
|
||||
struct grub_nand_data *data = 0;
|
||||
|
|
|
@ -233,8 +233,7 @@ compute_dev_path (const char *name)
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ofdisk_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
grub_ieee1275_phandle_t dev;
|
||||
char *devpath;
|
||||
|
|
|
@ -148,8 +148,7 @@ grub_loopback_iterate (int (*hook) (const char *name),
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_loopback_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
grub_loopback_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
struct grub_loopback *dev;
|
||||
|
||||
|
|
|
@ -181,8 +181,7 @@ find_lv (const char *name)
|
|||
static const char *scan_for = NULL;
|
||||
|
||||
static grub_err_t
|
||||
grub_lvm_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull)
|
||||
grub_lvm_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
struct grub_lvm_lv *lv = NULL;
|
||||
int explicit = 0;
|
||||
|
@ -192,8 +191,7 @@ grub_lvm_open (const char *name, grub_disk_t disk,
|
|||
|
||||
lv = find_lv (name);
|
||||
|
||||
if (! lv && !scan_depth &&
|
||||
pull == (explicit ? GRUB_DISK_PULL_RESCAN : GRUB_DISK_PULL_RESCAN_UNTYPED))
|
||||
if (! lv && !scan_depth && explicit)
|
||||
{
|
||||
scan_for = name;
|
||||
scan_depth++;
|
||||
|
|
|
@ -40,8 +40,7 @@ grub_memdisk_iterate (int (*hook) (const char *name),
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_memdisk_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
grub_memdisk_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
if (grub_strcmp (name, "memdisk"))
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a memdisk");
|
||||
|
|
|
@ -257,7 +257,7 @@ find_array (const char *name)
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_raid_open (const char *name, grub_disk_t disk, grub_disk_pull_t pull)
|
||||
grub_raid_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
struct grub_raid_array *array;
|
||||
unsigned n;
|
||||
|
@ -268,7 +268,7 @@ grub_raid_open (const char *name, grub_disk_t disk, grub_disk_pull_t pull)
|
|||
|
||||
array = find_array (name);
|
||||
|
||||
if (! array && pull == GRUB_DISK_PULL_RESCAN)
|
||||
if (! array)
|
||||
{
|
||||
scan_devices (name);
|
||||
if (grub_errno)
|
||||
|
|
|
@ -371,8 +371,7 @@ grub_scsi_iterate (int (*hook) (const char *name),
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_scsi_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
grub_scsi_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
grub_scsi_dev_t p;
|
||||
grub_scsi_t scsi;
|
||||
|
|
|
@ -206,13 +206,9 @@ grub_disk_dev_iterate (int (*hook) (const char *name))
|
|||
grub_disk_pull_t pull;
|
||||
|
||||
for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++)
|
||||
{
|
||||
if (pull == GRUB_DISK_PULL_RESCAN_UNTYPED)
|
||||
continue;
|
||||
for (p = grub_disk_dev_list; p; p = p->next)
|
||||
if (p->iterate && (p->iterate) (hook, pull))
|
||||
return 1;
|
||||
}
|
||||
for (p = grub_disk_dev_list; p; p = p->next)
|
||||
if (p->iterate && (p->iterate) (hook, pull))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -243,7 +239,6 @@ grub_disk_open (const char *name)
|
|||
grub_disk_dev_t dev;
|
||||
char *raw = (char *) name;
|
||||
grub_uint64_t current_time;
|
||||
grub_disk_pull_t pull;
|
||||
|
||||
grub_dprintf ("disk", "Opening `%s'...\n", name);
|
||||
|
||||
|
@ -270,19 +265,14 @@ grub_disk_open (const char *name)
|
|||
if (! disk->name)
|
||||
goto fail;
|
||||
|
||||
for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++)
|
||||
for (dev = grub_disk_dev_list; dev; dev = dev->next)
|
||||
{
|
||||
for (dev = grub_disk_dev_list; dev; dev = dev->next)
|
||||
{
|
||||
if ((dev->open) (raw, disk, pull) == GRUB_ERR_NONE)
|
||||
break;
|
||||
else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
else
|
||||
goto fail;
|
||||
}
|
||||
if (dev)
|
||||
if ((dev->open) (raw, disk) == GRUB_ERR_NONE)
|
||||
break;
|
||||
else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
else
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (! dev)
|
||||
|
|
|
@ -227,8 +227,7 @@ grub_util_biosdisk_iterate (int (*hook) (const char *name),
|
|||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_util_biosdisk_open (const char *name, grub_disk_t disk,
|
||||
grub_disk_pull_t pull __attribute__ ((unused)))
|
||||
grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
int drive;
|
||||
struct stat st;
|
||||
|
|
|
@ -56,7 +56,6 @@ typedef enum
|
|||
GRUB_DISK_PULL_NONE,
|
||||
GRUB_DISK_PULL_REMOVABLE,
|
||||
GRUB_DISK_PULL_RESCAN,
|
||||
GRUB_DISK_PULL_RESCAN_UNTYPED,
|
||||
GRUB_DISK_PULL_MAX
|
||||
} grub_disk_pull_t;
|
||||
|
||||
|
@ -74,8 +73,7 @@ struct grub_disk_dev
|
|||
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,
|
||||
grub_disk_pull_t pull);
|
||||
grub_err_t (*open) (const char *name, struct grub_disk *disk);
|
||||
|
||||
/* Close the disk DISK. */
|
||||
void (*close) (struct grub_disk *disk);
|
||||
|
|
Loading…
Reference in a new issue