]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
efidisk: prevent errors from diskfilter scan of removable drives
authorAndrei Borzenkov <arvidjaar@gmail.com>
Fri, 26 Feb 2016 18:44:37 +0000 (21:44 +0300)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Fri, 26 Feb 2016 18:44:37 +0000 (21:44 +0300)
Map EFI_NO_MEDIA to GRUB_ERR_OUT_OF_RANGE that is ignored by diskfilter. This
actually matches pretty close (we obviously attempt to read outside of media)
and avoids adding more error codes.

This affects only internally initiated scans. If read/write from removable is
explicitly requested, we still return an error and text explanation is more
clear for user than generic error.

Reported and tested by Andreas Loew <Andreas.Loew@gmx.net>

grub-core/disk/efi/efidisk.c

index 1c00e3ec8f702e1cf12d383ab6099bb710e4d79a..ea753446dde5ab3f3bd5e2453e25fdba9de36a05 100644 (file)
@@ -547,7 +547,9 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
 
   status = grub_efidisk_readwrite (disk, sector, size, buf, 0);
 
-  if (status != GRUB_EFI_SUCCESS)
+  if (status == GRUB_EFI_NO_MEDIA)
+    return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'", disk->name));
+  else if (status != GRUB_EFI_SUCCESS)
     return grub_error (GRUB_ERR_READ_ERROR,
                       N_("failure reading sector 0x%llx from `%s'"),
                       (unsigned long long) sector,
@@ -568,7 +570,9 @@ grub_efidisk_write (struct grub_disk *disk, grub_disk_addr_t sector,
 
   status = grub_efidisk_readwrite (disk, sector, size, (char *) buf, 1);
 
-  if (status != GRUB_EFI_SUCCESS)
+  if (status == GRUB_EFI_NO_MEDIA)
+    return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("no media in `%s'", disk->name));
+  else if (status != GRUB_EFI_SUCCESS)
     return grub_error (GRUB_ERR_WRITE_ERROR,
                       N_("failure writing sector 0x%llx to `%s'"),
                       (unsigned long long) sector, disk->name);