]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Don't override more informative errors.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Mon, 26 Dec 2011 11:58:08 +0000 (12:58 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Mon, 26 Dec 2011 11:58:08 +0000 (12:58 +0100)
* grub-core/commands/acpi.c (grub_cmd_acpi): Don't override errors.
* grub-core/font/font.c (open_section): Likewise.
* grub-core/loader/i386/bsd.c (grub_bsd_load_aout): New argument
filename. Don't override errors.
(grub_cmd_openbsd_ramdisk): Don't override errors.
* grub-core/loader/i386/linux.c (grub_cmd_linux): Likewise.
(grub_cmd_initrd): Likewise.
* grub-core/loader/i386/pc/linux.c (grub_cmd_linux): Likewise.
(grub_cmd_initrd): Likewise.
* grub-core/loader/ia64/efi/linux.c (grub_load_elf64): Likewise.
(grub_cmd_linux): Likewise.
(grub_cmd_initrd): Likewise.
(grub_cmd_payload): Likewise.
* grub-core/loader/mips/linux.c (grub_cmd_initrd): Likewise.
* grub-core/loader/multiboot.c (grub_cmd_multiboot): Likewise.
(grub_cmd_module): Likewise.
* grub-core/loader/powerpc/ieee1275/linux.c (grub_cmd_initrd): Likewise.
* grub-core/loader/sparc64/ieee1275/linux.c (grub_cmd_initrd): Likewise.
* grub-core/loader/xnu.c (grub_xnu_load_driver): Likewise.
(grub_cmd_xnu_mkext): Likewise.
(grub_cmd_xnu_ramdisk): Likewise.
(grub_xnu_check_os_bundle_required): Likewise.
(grub_xnu_load_kext_from_dir): Likewise.
(grub_cmd_xnu_kextdir): Likewise.
* grub-core/loader/xnu_resume.c (grub_xnu_resume): Likewise.

13 files changed:
ChangeLog
grub-core/commands/acpi.c
grub-core/font/font.c
grub-core/loader/i386/bsd.c
grub-core/loader/i386/linux.c
grub-core/loader/i386/pc/linux.c
grub-core/loader/ia64/efi/linux.c
grub-core/loader/mips/linux.c
grub-core/loader/multiboot.c
grub-core/loader/powerpc/ieee1275/linux.c
grub-core/loader/sparc64/ieee1275/linux.c
grub-core/loader/xnu.c
grub-core/loader/xnu_resume.c

index 22860352464297a4c86c708b50b7c8e7680e257c..3acd07f972de50cf21c7e4c0ca83d65430a8fdd0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2011-12-26  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Don't override more informative errors.
+
+       * grub-core/commands/acpi.c (grub_cmd_acpi): Don't override errors.
+       * grub-core/font/font.c (open_section): Likewise.
+       * grub-core/loader/i386/bsd.c (grub_bsd_load_aout): New argument
+       filename. Don't override errors.
+       (grub_cmd_openbsd_ramdisk): Don't override errors.
+       * grub-core/loader/i386/linux.c (grub_cmd_linux): Likewise.
+       (grub_cmd_initrd): Likewise.
+       * grub-core/loader/i386/pc/linux.c (grub_cmd_linux): Likewise.
+       (grub_cmd_initrd): Likewise.
+       * grub-core/loader/ia64/efi/linux.c (grub_load_elf64): Likewise.
+       (grub_cmd_linux): Likewise.
+       (grub_cmd_initrd): Likewise.
+       (grub_cmd_payload): Likewise.
+       * grub-core/loader/mips/linux.c (grub_cmd_initrd): Likewise.
+       * grub-core/loader/multiboot.c (grub_cmd_multiboot): Likewise.
+       (grub_cmd_module): Likewise.
+       * grub-core/loader/powerpc/ieee1275/linux.c (grub_cmd_initrd): Likewise.
+       * grub-core/loader/sparc64/ieee1275/linux.c (grub_cmd_initrd): Likewise.
+       * grub-core/loader/xnu.c (grub_xnu_load_driver): Likewise.
+       (grub_cmd_xnu_mkext): Likewise.
+       (grub_cmd_xnu_ramdisk): Likewise.
+       (grub_xnu_check_os_bundle_required): Likewise.
+       (grub_xnu_load_kext_from_dir): Likewise.
+       (grub_cmd_xnu_kextdir): Likewise.
+       * grub-core/loader/xnu_resume.c (grub_xnu_resume): Likewise.
+
 2011-12-25  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/fs/minix.c (grub_minix_mount) [MODE_MINIX3]: Treat 0xffff
index 2531b8e11d49197ea8379294fb40f0b17a529fe1..048f8c0cb10111b8a6293bdf4b4a0f42091f61d1 100644 (file)
@@ -649,15 +649,17 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
        {
          grub_file_close (file);
          free_tables ();
-         return grub_error (GRUB_ERR_OUT_OF_MEMORY,
-                            "couldn't read file %s", args[i]);
+         return grub_errno;
        }
 
       if (grub_file_read (file, buf, size) != (int) size)
        {
          grub_file_close (file);
          free_tables ();
-         return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[i]);
+         if (!grub_errno)
+           grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
+                       args[i]);
+         return grub_errno;
        }
       grub_file_close (file);
 
index 3737480cff816358450102bbbf4d89b22df8e9f8..8d74534ef0a04a173ff70b8eaf874fe9ce2e6cf6 100644 (file)
@@ -250,8 +250,7 @@ open_section (grub_file_t file, struct font_file_section *section)
     }
   else if (retval < 0)
     {
-      grub_error (GRUB_ERR_BAD_FONT,
-                 "font format error: can't read section name");
+      /* Read error.  */
       return 1;
     }
 
@@ -265,8 +264,7 @@ open_section (grub_file_t file, struct font_file_section *section)
     }
   else if (retval < 0)
     {
-      grub_error (GRUB_ERR_BAD_FONT,
-                 "font format error: can't read section length");
+      /* Read error.  */
       return 1;
     }
 
index f9bab21e6f2756058b64738cdee8458940aa2394..835f14695f09e93851d49fe5f37431080f70ab59 100644 (file)
@@ -1159,7 +1159,7 @@ grub_bsd_unload (void)
 }
 
 static grub_err_t
-grub_bsd_load_aout (grub_file_t file)
+grub_bsd_load_aout (grub_file_t file, const char *filename)
 {
   grub_addr_t load_addr, load_end;
   int ofs, align_page;
@@ -1171,7 +1171,12 @@ grub_bsd_load_aout (grub_file_t file)
     return grub_errno;
 
   if (grub_file_read (file, &ah, sizeof (ah)) != sizeof (ah))
-    return grub_error (GRUB_ERR_READ_ERROR, "cannot read the a.out header");
+    {
+      if (!grub_errno)
+       grub_error (GRUB_ERR_READ_ERROR, N_("premature end of file %s"),
+                   filename);
+      return grub_errno;
+    }
 
   if (grub_aout_get_type (&ah) != AOUT_TYPE_AOUT32)
     return grub_error (GRUB_ERR_BAD_OS, "invalid a.out header");
@@ -1426,7 +1431,7 @@ grub_bsd_load (int argc, char *argv[])
     {
       is_elf_kernel = 0;
       grub_errno = 0;
-      grub_bsd_load_aout (file);
+      grub_bsd_load_aout (file, argv[0]);
       grub_file_close (file);
     }
 
@@ -2000,8 +2005,7 @@ grub_cmd_openbsd_ramdisk (grub_command_t cmd __attribute__ ((unused)),
 
   file = grub_file_open (args[0]);
   if (! file)
-    return grub_error (GRUB_ERR_FILE_NOT_FOUND,
-                      "couldn't load ramdisk");
+    return grub_errno;
 
   size = grub_file_size (file);
 
@@ -2017,8 +2021,9 @@ grub_cmd_openbsd_ramdisk (grub_command_t cmd __attribute__ ((unused)),
       != (grub_ssize_t) (size))
     {
       grub_file_close (file);
-      grub_error_push ();
-      return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]);
+      if (!grub_errno)
+       grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
+      return grub_errno;
     }
   grub_memset (openbsd_ramdisk.target + size, 0,
               openbsd_ramdisk.max_size - size);
index 80ad542e3b0813ff5a73ea0a840c6152f12fc8e7..1f89ec5d2dd15f73d41e0ca3f60dd441372a629e 100644 (file)
@@ -649,7 +649,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
   if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
     {
-      grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
       goto fail;
     }
 
@@ -717,7 +719,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   len = 0x400 - sizeof (lh);
   if (grub_file_read (file, (char *) real_mode_mem + sizeof (lh), len) != len)
     {
-      grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
       goto fail;
     }
 
@@ -908,8 +912,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
                              - (sizeof (LINUX_IMAGE) - 1));
 
   len = prot_size;
-  if (grub_file_read (file, prot_mode_mem, len) != len)
-    grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
+  if (grub_file_read (file, prot_mode_mem, len) != len && !grub_errno)
+    grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+               argv[0]);
 
   if (grub_errno == GRUB_ERR_NONE)
     {
@@ -1014,7 +1019,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
 
   if (grub_file_read (file, initrd_mem, size) != size)
     {
-      grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
       goto fail;
     }
 
index c7c0991748a349be526adb72596161b9c7979f17..077b17bb8dd48e1b462ff326f94b38fdb60b0937 100644 (file)
@@ -108,7 +108,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
   if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
     {
-      grub_error (GRUB_ERR_READ_ERROR, "cannot read the Linux header");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
       goto fail;
     }
 
@@ -283,7 +285,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   len = real_size + GRUB_DISK_SECTOR_SIZE - sizeof (lh);
   if (grub_file_read (file, grub_linux_real_chunk + sizeof (lh), len) != len)
     {
-      grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
       goto fail;
     }
 
@@ -321,8 +325,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
   len = grub_linux16_prot_size;
   if (grub_file_read (file, grub_linux_prot_chunk, grub_linux16_prot_size)
-      != (grub_ssize_t) grub_linux16_prot_size)
-    grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
+      != (grub_ssize_t) grub_linux16_prot_size && !grub_errno)
+    grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+               argv[0]);
 
   if (grub_errno == GRUB_ERR_NONE)
     {
@@ -424,7 +429,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
 
   if (grub_file_read (file, initrd_chunk, size) != size)
     {
-      grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
       goto fail;
     }
 
index 247eebae5b725245a7e3da68669598f392a95013..ab28c1dead0be4af0219d420fa256b196d804eea 100644 (file)
@@ -30,6 +30,7 @@
 #include <grub/efi/api.h>
 #include <grub/efi/efi.h>
 #include <grub/elf.h>
+#include <grub/i18n.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -377,7 +378,7 @@ grub_linux_unload (void)
 }
 
 static grub_err_t
-grub_load_elf64 (grub_file_t file, void *buffer)
+grub_load_elf64 (grub_file_t file, void *buffer, const char *filename)
 {
   Elf64_Ehdr *ehdr = (Elf64_Ehdr *) buffer;
   Elf64_Phdr *phdr;
@@ -472,11 +473,15 @@ grub_load_elf64 (grub_file_t file, void *buffer)
            return grub_error (GRUB_ERR_BAD_OS,
                               "invalid offset in program header");
 
-         if (grub_file_read (file, (void *)(phdr->p_paddr + reloc_offset),
+         if (grub_file_read (file, (void *) (phdr->p_paddr + reloc_offset),
                              phdr->p_filesz)
               != (grub_ssize_t) phdr->p_filesz)
-           return grub_error (GRUB_ERR_BAD_OS,
-                              "couldn't read segment from file");
+           {
+             if (!grub_errno)
+               grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
+                           filename);
+             return grub_errno;
+           }
          
           if (phdr->p_filesz < phdr->p_memsz)
            grub_memset
@@ -515,13 +520,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
   file = grub_file_open (argv[0]);
   if (! file)
-    {
-      grub_error (GRUB_ERR_BAD_ARGUMENT, "Couldn't open file");
-      goto fail;
-    }
+    goto fail;
 
   len = grub_file_read (file, buffer, sizeof (buffer));
-  if (len < (grub_ssize_t)sizeof (Elf64_Ehdr))
+  if (len < (grub_ssize_t) sizeof (Elf64_Ehdr))
     {
       grub_error (GRUB_ERR_BAD_OS, "File too small");
       goto fail;
@@ -529,7 +531,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
 
   grub_printf ("Loading linux: %s\n", argv[0]);
 
-  if (grub_load_elf64 (file, buffer))
+  if (grub_load_elf64 (file, buffer, argv[0]))
     goto fail;
 
   len = sizeof("BOOT_IMAGE=") + 8;
@@ -611,9 +613,11 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
               (grub_uint64_t)initrd_mem, initrd_size);
 
   if (grub_file_read (file, initrd_mem, initrd_size) 
-      != (grub_ssize_t)initrd_size)
+      != (grub_ssize_t) initrd_size)
     {
-      grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
       goto fail;
     }
  fail:
@@ -659,7 +663,9 @@ grub_cmd_payload  (grub_command_t cmd __attribute__ ((unused)),
 
   if (grub_file_read (file, base, size) != size)
     {
-      grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
       goto fail;
     }
 
index 17c2656e2b63416f02cc6b9cf6148491a7964dc8..739bc0291d6eed588c861395e3b6dd71e41e7239 100644 (file)
@@ -478,7 +478,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
 
   if (grub_file_read (file, initrd_src, size) != size)
     {
-      grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
       grub_file_close (file);
 
       return grub_errno;
index f76123e6752a2137538291415910b195303e196e..fec1b5bf6174b22d63942993a122864a93fe3fc4 100644 (file)
@@ -226,7 +226,7 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)),
 
   file = grub_file_open (argv[0]);
   if (! file)
-    return grub_error (GRUB_ERR_BAD_ARGUMENT, "couldn't open file");
+    return grub_errno;
 
   grub_dl_ref (my_mod);
 
@@ -322,7 +322,10 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
   if (grub_file_read (file, module, size) != size)
     {
       grub_file_close (file);
-      return grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
+      return grub_errno;
     }
 
   grub_file_close (file);
index 12a3fa9f6afe5cc81c60e71de19ee85e6bb9cad5..c6a5afecfdef24568f9ff040223f054a695694db 100644 (file)
@@ -353,7 +353,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
   if (grub_file_read (file, (void *) addr, size) != size)
     {
       grub_ieee1275_release (addr, size);
-      grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
       goto fail;
     }
 
index 8ed61f8bf9889b6e9c64a7677b1ca83d50f41ea6..273dbd61ec4083b3c5e5526d4ff9a4f206e30894 100644 (file)
@@ -417,7 +417,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
 
   if (grub_file_read (file, (void *) addr, size) != size)
     {
-      grub_error (GRUB_ERR_FILE_READ_ERROR, "couldn't read file");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
+                   argv[0]);
       goto fail;
     }
 
index f96bc2b75a78e5c274d9b2e4f900195da7e1a8ff..7da3551836102a0aa8ac4344730ec369af113b45 100644 (file)
@@ -738,9 +738,10 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
          != (grub_ssize_t) (infoplistsize))
        {
          grub_file_close (infoplist);
-         grub_error_push ();
-         return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s: ",
-                            infoplistname);
+         if (!grub_errno)
+           grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s: "),
+                       infoplistname);
+         return grub_errno;
        }
       grub_file_close (infoplist);
       buf[infoplistsize] = 0;
@@ -782,8 +783,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
 
   file = grub_file_open (args[0]);
   if (! file)
-    return grub_error (GRUB_ERR_FILE_NOT_FOUND,
-                      "couldn't load driver package");
+    return grub_errno;
 
   /* Sometimes caches are fat binary. Errgh. */
   if (grub_file_read (file, &head, sizeof (head))
@@ -792,8 +792,9 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
       /* I don't know the internal structure of package but
         can hardly imagine a valid package shorter than 20 bytes. */
       grub_file_close (file);
-      grub_error_push ();
-      return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]);
+      if (!grub_errno)
+       grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
+      return grub_errno;
     }
 
   /* Find the corresponding architecture. */
@@ -804,9 +805,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
       if (! archs)
        {
          grub_file_close (file);
-         grub_error_push ();
-         return grub_error (GRUB_ERR_OUT_OF_MEMORY,
-                            "couldn't read file %s", args[0]);
+         return grub_errno;
 
        }
       if (grub_file_read (file, archs,
@@ -814,8 +813,10 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
          != (grub_ssize_t) sizeof(struct grub_macho_fat_arch) * narchs)
        {
          grub_free (archs);
-         grub_error_push ();
-         return grub_error (GRUB_ERR_READ_ERROR, "cannot read fat header");
+         if (!grub_errno)
+           grub_error (GRUB_ERR_READ_ERROR, N_("premature end of file %s"),
+                       args[0]);
+         return grub_errno;
        }
       for (i = 0; i < narchs; i++)
        {
@@ -867,8 +868,9 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
   if (grub_file_read (file, loadto, readlen) != (grub_ssize_t) (readlen))
     {
       grub_file_close (file);
-      grub_error_push ();
-      return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]);
+      if (!grub_errno)
+       grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
+      return grub_errno;
     }
   grub_file_close (file);
 
@@ -895,8 +897,7 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)),
 
   file = grub_file_open (args[0]);
   if (! file)
-    return grub_error (GRUB_ERR_FILE_NOT_FOUND,
-                      "couldn't load ramdisk");
+    return grub_errno;
 
   err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
   if (err)
@@ -907,12 +908,12 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)),
   err = grub_xnu_heap_malloc (size, &loadto, &loadto_target);
   if (err)
     return err;
-  if (grub_file_read (file, loadto, size)
-      != (grub_ssize_t) (size))
+  if (grub_file_read (file, loadto, size) != (grub_ssize_t) (size))
     {
       grub_file_close (file);
-      grub_error_push ();
-      return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]);
+      if (!grub_errno)
+       grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
+      return grub_errno;
     }
   return grub_xnu_register_memory ("RAMDisk", 0, loadto_target, size);
 }
@@ -936,27 +937,20 @@ grub_xnu_check_os_bundle_required (char *plistname,
 
   file = grub_file_open (plistname);
   if (! file)
-    {
-      grub_file_close (file);
-      grub_error_push ();
-      grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", plistname);
-      return 0;
-    }
+    return 0;
 
   size = grub_file_size (file);
   buf = grub_malloc (size);
   if (! buf)
     {
       grub_file_close (file);
-      grub_error_push ();
-      grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't read file %s", plistname);
       return 0;
     }
   if (grub_file_read (file, buf, size) != (grub_ssize_t) (size))
     {
       grub_file_close (file);
-      grub_error_push ();
-      grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", plistname);
+      if (!grub_errno)
+       grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), plistname);
       return 0;
     }
   grub_file_close (file);
@@ -1150,7 +1144,7 @@ grub_xnu_load_kext_from_dir (char *dirname, const char *osbundlerequired,
 
   newdirname = grub_malloc (grub_strlen (dirname) + 20);
   if (! newdirname)
-    return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't allocate buffer");
+    return grub_errno;
   grub_strcpy (newdirname, dirname);
   newdirname[grub_strlen (dirname)] = '/';
   newdirname[grub_strlen (dirname) + 1] = 0;
@@ -1271,8 +1265,7 @@ grub_cmd_xnu_kextdir (grub_command_t cmd __attribute__ ((unused)),
       char *osbundlerequired = grub_strdup (args[1]), *ptr;
       grub_err_t err;
       if (! osbundlerequired)
-       return grub_error (GRUB_ERR_OUT_OF_MEMORY,
-                          "couldn't allocate string temporary space");
+       return grub_errno;
       for (ptr = osbundlerequired; *ptr; ptr++)
        *ptr = grub_tolower (*ptr);
       err = grub_xnu_scan_dir_for_kexts (args[0], osbundlerequired, 10);
index 8f0e2448399ed09c22442a1a5ae638b12d6b89d5..d7f9adaafb0252baf2746fc027e6e880c32fc843 100644 (file)
@@ -25,6 +25,7 @@
 #include <grub/cpu/xnu.h>
 #include <grub/mm.h>
 #include <grub/loader.h>
+#include <grub/i18n.h>
 
 static void *grub_xnu_hibernate_image;
 
@@ -59,11 +60,13 @@ grub_xnu_resume (char *imagename)
 
   /* Read the header. */
   if (grub_file_read (file, &hibhead, sizeof (hibhead))
-      !=sizeof (hibhead))
+      != sizeof (hibhead))
     {
       grub_file_close (file);
-      return grub_error (GRUB_ERR_READ_ERROR,
-                        "cannot read the hibernate header");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_READ_ERROR,
+                   N_("premature end of file %s"), imagename);
+      return grub_errno;
     }
 
   /* Check the header. */
@@ -138,7 +141,10 @@ grub_xnu_resume (char *imagename)
       != (grub_ssize_t) codesize)
     {
       grub_file_close (file);
-      return grub_error (GRUB_ERR_READ_ERROR, "cannot read resume image");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_READ_ERROR,
+                   N_("premature end of file %s"), imagename);
+      return grub_errno;
     }
 
   /* Read image. */
@@ -147,7 +153,10 @@ grub_xnu_resume (char *imagename)
       != (grub_ssize_t) hibhead.image_size)
     {
       grub_file_close (file);
-      return grub_error (GRUB_ERR_READ_ERROR, "cannot read resume image");
+      if (!grub_errno)
+       grub_error (GRUB_ERR_READ_ERROR,
+                   N_("premature end of file %s"), imagename);
+      return grub_errno;
     }
   grub_file_close (file);