Simplify disk opening

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-07-07 21:46:25 +02:00
parent 00542307eb
commit 0044d1db2e
15 changed files with 29 additions and 49 deletions

View file

@ -79,7 +79,8 @@ arcdisk_hash_add (char *devpath)
static int 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); auto int hook (const char *name, const struct grub_arc_component *comp);
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 0;
return hook_in (name); return hook_in (name);
} }
if (pull != GRUB_DISK_PULL_NONE)
return 0;
return grub_arc_iterate_devs (hook, 1); return grub_arc_iterate_devs (hook, 1);
} }

View file

@ -412,8 +412,7 @@ grub_ata_iterate (int (*hook_in) (const char *name),
} }
static grub_err_t static grub_err_t
grub_ata_open (const char *name, grub_disk_t disk, grub_ata_open (const char *name, grub_disk_t disk)
grub_disk_pull_t pull __attribute__ ((unused)))
{ {
unsigned id, bus; unsigned id, bus;
struct grub_ata *ata; struct grub_ata *ata;

View file

@ -454,8 +454,7 @@ get_device (struct grub_efidisk_data *devices, int num)
} }
static grub_err_t static grub_err_t
grub_efidisk_open (const char *name, struct grub_disk *disk, grub_efidisk_open (const char *name, struct grub_disk *disk)
grub_disk_pull_t pull __attribute__ ((unused)))
{ {
int num; int num;
struct grub_efidisk_data *d = 0; struct grub_efidisk_data *d = 0;

View file

@ -39,8 +39,7 @@ grub_host_iterate (int (*hook) (const char *name),
} }
static grub_err_t static grub_err_t
grub_host_open (const char *name, grub_disk_t disk, grub_host_open (const char *name, grub_disk_t disk)
grub_disk_pull_t pull __attribute__ ((unused)))
{ {
if (grub_strcmp (name, "host")) if (grub_strcmp (name, "host"))
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a host disk"); return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a host disk");

View file

@ -328,8 +328,7 @@ grub_biosdisk_iterate (int (*hook) (const char *name),
} }
static grub_err_t static grub_err_t
grub_biosdisk_open (const char *name, grub_disk_t disk, grub_biosdisk_open (const char *name, grub_disk_t disk)
grub_disk_pull_t pull __attribute__ ((unused)))
{ {
grub_uint64_t total_sectors = 0; grub_uint64_t total_sectors = 0;
int drive; int drive;

View file

@ -58,8 +58,7 @@ grub_nand_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_size_t size, char *buf); grub_size_t size, char *buf);
static grub_err_t static grub_err_t
grub_nand_open (const char *name, grub_disk_t disk, grub_nand_open (const char *name, grub_disk_t disk)
grub_disk_pull_t pull __attribute__ ((unused)))
{ {
grub_ieee1275_ihandle_t dev_ihandle = 0; grub_ieee1275_ihandle_t dev_ihandle = 0;
struct grub_nand_data *data = 0; struct grub_nand_data *data = 0;

View file

@ -233,8 +233,7 @@ compute_dev_path (const char *name)
} }
static grub_err_t static grub_err_t
grub_ofdisk_open (const char *name, grub_disk_t disk, grub_ofdisk_open (const char *name, grub_disk_t disk)
grub_disk_pull_t pull __attribute__ ((unused)))
{ {
grub_ieee1275_phandle_t dev; grub_ieee1275_phandle_t dev;
char *devpath; char *devpath;

View file

@ -148,8 +148,7 @@ grub_loopback_iterate (int (*hook) (const char *name),
} }
static grub_err_t static grub_err_t
grub_loopback_open (const char *name, grub_disk_t disk, grub_loopback_open (const char *name, grub_disk_t disk)
grub_disk_pull_t pull __attribute__ ((unused)))
{ {
struct grub_loopback *dev; struct grub_loopback *dev;

View file

@ -181,8 +181,7 @@ find_lv (const char *name)
static const char *scan_for = NULL; static const char *scan_for = NULL;
static grub_err_t static grub_err_t
grub_lvm_open (const char *name, grub_disk_t disk, grub_lvm_open (const char *name, grub_disk_t disk)
grub_disk_pull_t pull)
{ {
struct grub_lvm_lv *lv = NULL; struct grub_lvm_lv *lv = NULL;
int explicit = 0; int explicit = 0;
@ -192,8 +191,7 @@ grub_lvm_open (const char *name, grub_disk_t disk,
lv = find_lv (name); lv = find_lv (name);
if (! lv && !scan_depth && if (! lv && !scan_depth && explicit)
pull == (explicit ? GRUB_DISK_PULL_RESCAN : GRUB_DISK_PULL_RESCAN_UNTYPED))
{ {
scan_for = name; scan_for = name;
scan_depth++; scan_depth++;

View file

@ -40,8 +40,7 @@ grub_memdisk_iterate (int (*hook) (const char *name),
} }
static grub_err_t static grub_err_t
grub_memdisk_open (const char *name, grub_disk_t disk, grub_memdisk_open (const char *name, grub_disk_t disk)
grub_disk_pull_t pull __attribute__ ((unused)))
{ {
if (grub_strcmp (name, "memdisk")) if (grub_strcmp (name, "memdisk"))
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a memdisk"); return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a memdisk");

View file

@ -257,7 +257,7 @@ find_array (const char *name)
} }
static grub_err_t 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; struct grub_raid_array *array;
unsigned n; 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); array = find_array (name);
if (! array && pull == GRUB_DISK_PULL_RESCAN) if (! array)
{ {
scan_devices (name); scan_devices (name);
if (grub_errno) if (grub_errno)

View file

@ -371,8 +371,7 @@ grub_scsi_iterate (int (*hook) (const char *name),
} }
static grub_err_t static grub_err_t
grub_scsi_open (const char *name, grub_disk_t disk, grub_scsi_open (const char *name, grub_disk_t disk)
grub_disk_pull_t pull __attribute__ ((unused)))
{ {
grub_scsi_dev_t p; grub_scsi_dev_t p;
grub_scsi_t scsi; grub_scsi_t scsi;

View file

@ -206,13 +206,9 @@ grub_disk_dev_iterate (int (*hook) (const char *name))
grub_disk_pull_t pull; grub_disk_pull_t pull;
for (pull = 0; pull < GRUB_DISK_PULL_MAX; 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) for (p = grub_disk_dev_list; p; p = p->next)
if (p->iterate && (p->iterate) (hook, pull)) if (p->iterate && (p->iterate) (hook, pull))
return 1; return 1;
}
return 0; return 0;
} }
@ -243,7 +239,6 @@ grub_disk_open (const char *name)
grub_disk_dev_t dev; grub_disk_dev_t dev;
char *raw = (char *) name; char *raw = (char *) name;
grub_uint64_t current_time; grub_uint64_t current_time;
grub_disk_pull_t pull;
grub_dprintf ("disk", "Opening `%s'...\n", name); grub_dprintf ("disk", "Opening `%s'...\n", name);
@ -270,20 +265,15 @@ grub_disk_open (const char *name)
if (! disk->name) if (! disk->name)
goto fail; 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) if ((dev->open) (raw, disk) == GRUB_ERR_NONE)
break; break;
else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE) else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE)
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
else else
goto fail; goto fail;
} }
if (dev)
break;
}
if (! dev) if (! dev)
{ {

View file

@ -227,8 +227,7 @@ grub_util_biosdisk_iterate (int (*hook) (const char *name),
} }
static grub_err_t static grub_err_t
grub_util_biosdisk_open (const char *name, grub_disk_t disk, grub_util_biosdisk_open (const char *name, grub_disk_t disk)
grub_disk_pull_t pull __attribute__ ((unused)))
{ {
int drive; int drive;
struct stat st; struct stat st;

View file

@ -56,7 +56,6 @@ typedef enum
GRUB_DISK_PULL_NONE, GRUB_DISK_PULL_NONE,
GRUB_DISK_PULL_REMOVABLE, GRUB_DISK_PULL_REMOVABLE,
GRUB_DISK_PULL_RESCAN, GRUB_DISK_PULL_RESCAN,
GRUB_DISK_PULL_RESCAN_UNTYPED,
GRUB_DISK_PULL_MAX GRUB_DISK_PULL_MAX
} grub_disk_pull_t; } grub_disk_pull_t;
@ -74,8 +73,7 @@ struct grub_disk_dev
grub_disk_pull_t pull); grub_disk_pull_t pull);
/* Open the device named NAME, and set up DISK. */ /* Open the device named NAME, and set up DISK. */
grub_err_t (*open) (const char *name, struct grub_disk *disk, grub_err_t (*open) (const char *name, struct grub_disk *disk);
grub_disk_pull_t pull);
/* Close the disk DISK. */ /* Close the disk DISK. */
void (*close) (struct grub_disk *disk); void (*close) (struct grub_disk *disk);