From 0044d1db2e43943112aac3f3482e97d66584e645 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 7 Jul 2011 21:46:25 +0200 Subject: [PATCH] Simplify disk opening --- grub-core/disk/arc/arcdisk.c | 6 +++++- grub-core/disk/ata.c | 3 +-- grub-core/disk/efi/efidisk.c | 3 +-- grub-core/disk/host.c | 3 +-- grub-core/disk/i386/pc/biosdisk.c | 3 +-- grub-core/disk/ieee1275/nand.c | 3 +-- grub-core/disk/ieee1275/ofdisk.c | 3 +-- grub-core/disk/loopback.c | 3 +-- grub-core/disk/lvm.c | 6 ++---- grub-core/disk/memdisk.c | 3 +-- grub-core/disk/raid.c | 4 ++-- grub-core/disk/scsi.c | 3 +-- grub-core/kern/disk.c | 28 +++++++++------------------- grub-core/kern/emu/hostdisk.c | 3 +-- include/grub/disk.h | 4 +--- 15 files changed, 29 insertions(+), 49 deletions(-) diff --git a/grub-core/disk/arc/arcdisk.c b/grub-core/disk/arc/arcdisk.c index 7dff30931..170bf521d 100644 --- a/grub-core/disk/arc/arcdisk.c +++ b/grub-core/disk/arc/arcdisk.c @@ -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); } diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c index 9a09ee158..8add7f4de 100644 --- a/grub-core/disk/ata.c +++ b/grub-core/disk/ata.c @@ -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; diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index 4ae1d7bb9..85969cc1d 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -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; diff --git a/grub-core/disk/host.c b/grub-core/disk/host.c index 5376cc6ce..5ee0d2e56 100644 --- a/grub-core/disk/host.c +++ b/grub-core/disk/host.c @@ -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"); diff --git a/grub-core/disk/i386/pc/biosdisk.c b/grub-core/disk/i386/pc/biosdisk.c index 1198d4305..e152b9d89 100644 --- a/grub-core/disk/i386/pc/biosdisk.c +++ b/grub-core/disk/i386/pc/biosdisk.c @@ -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; diff --git a/grub-core/disk/ieee1275/nand.c b/grub-core/disk/ieee1275/nand.c index 4be5b5641..94d62bc4f 100644 --- a/grub-core/disk/ieee1275/nand.c +++ b/grub-core/disk/ieee1275/nand.c @@ -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; diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index 7b7db3a08..2cd43d80a 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -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; diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c index 21345af57..dca83b7c6 100644 --- a/grub-core/disk/loopback.c +++ b/grub-core/disk/loopback.c @@ -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; diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 9e304c001..06e9f6d6a 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -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++; diff --git a/grub-core/disk/memdisk.c b/grub-core/disk/memdisk.c index 775234055..ed570c6a0 100644 --- a/grub-core/disk/memdisk.c +++ b/grub-core/disk/memdisk.c @@ -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"); diff --git a/grub-core/disk/raid.c b/grub-core/disk/raid.c index a7d36bfb2..5d8326daf 100644 --- a/grub-core/disk/raid.c +++ b/grub-core/disk/raid.c @@ -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) diff --git a/grub-core/disk/scsi.c b/grub-core/disk/scsi.c index 5ab5177e9..610cc4dc5 100644 --- a/grub-core/disk/scsi.c +++ b/grub-core/disk/scsi.c @@ -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; diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 022157434..5584030bd 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -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) diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index a2f9ce084..59d7a4a2c 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -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; diff --git a/include/grub/disk.h b/include/grub/disk.h index efa27a4d2..2b6d02972 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -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);