]> git.proxmox.com Git - grub2.git/commitdiff
Improve and unify messages.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 5 Feb 2012 10:07:33 +0000 (11:07 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 5 Feb 2012 10:07:33 +0000 (11:07 +0100)
* grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors): Add argument
name. All users updated.
Print filename in error.
(read_device_map): Print filename in error.
* util/getroot.c (grub_guess_root_devices): Print filename in error.
(grub_util_get_os_disk): Likewise.
(grub_util_biosdisk_get_grub_dev): Likewise.
(grub_util_check_block_device): Likewise.
(grub_util_check_char_device): Likewise.
(grub_make_system_path_relative_to_its_root): Likewise.
* util/grub-editenv.c (create_envblk_file): Likewise.
(open_envblk_file): Likewise.
(write_envblk): Likewise.
* util/grub-fstest.c (cmd_cp): Likewise.
(cmd_cat): Likewise.
(cmd_cmp): Likewise.
* util/grub-menulst2cfg.c (main): Likewise.
* util/grub-mkfont.c (write_font_ascii_bitmap): Likewise.
(write_font_width_spec): Likewise.
(write_font_pf2): Likewise.
* util/grub-mkimage.c (generate_image): New argument outname.
All users updated.
Remove unreacheable message.
(options): Unify messages.
(help_filter): Likewise.
* util/grub-mklayout.c (usage): Removed (unused).
(main): Print filename in error.
* util/grub-mkrescue.in: Fix wrong quoting.
* util/grub-setup.c (setup): Print filename in error.
* util/ieee1275/ofpath.c (vendor_is_ATA): Likewise.
(check_sas): Likewise.
* util/misc.c (grub_util_get_fp_size): Removed.
(grub_util_get_image_size): Print filename in error.
(grub_util_read_at): Removed.
(grub_util_read_image): Print filename in error.
(grub_util_load_image): Likewise.
(grub_util_write_image_at): New argument filename. All users updated.
Print filename in error.
(grub_util_write_image): New argument filename. All users updated.
Print filename in error.
* util/raid.c (grub_util_raid_getmembers): Print filename in error.
* util/resolve.c (grub_util_resolve_dependencies): Likewise.

19 files changed:
ChangeLog
grub-core/disk/geli.c
grub-core/kern/emu/hostdisk.c
include/grub/emu/hostdisk.h
include/grub/util/misc.h
util/getroot.c
util/grub-editenv.c
util/grub-fstest.c
util/grub-menulst2cfg.c
util/grub-mkfont.c
util/grub-mkimage.c
util/grub-mklayout.c
util/grub-mkrescue.in
util/grub-pe2elf.c
util/grub-setup.c
util/ieee1275/ofpath.c
util/misc.c
util/raid.c
util/resolve.c

index f694788d771cdd88e2824962f928a29bdd72cebd..b0d0e975389e50a7bc7ada28003d3102c235f6f8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,50 @@
+2012-02-05  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Improve and unify messages.
+
+       * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors): Add argument
+       name. All users updated.
+       Print filename in error.
+       (read_device_map): Print filename in error.
+       * util/getroot.c (grub_guess_root_devices): Print filename in error.
+       (grub_util_get_os_disk): Likewise.
+       (grub_util_biosdisk_get_grub_dev): Likewise.
+       (grub_util_check_block_device): Likewise.
+       (grub_util_check_char_device): Likewise.
+       (grub_make_system_path_relative_to_its_root): Likewise.
+       * util/grub-editenv.c (create_envblk_file): Likewise.
+       (open_envblk_file): Likewise.
+       (write_envblk): Likewise.
+       * util/grub-fstest.c (cmd_cp): Likewise.
+       (cmd_cat): Likewise.
+       (cmd_cmp): Likewise.
+       * util/grub-menulst2cfg.c (main): Likewise.
+       * util/grub-mkfont.c (write_font_ascii_bitmap): Likewise.
+       (write_font_width_spec): Likewise.
+       (write_font_pf2): Likewise.
+       * util/grub-mkimage.c (generate_image): New argument outname.
+       All users updated.
+       Remove unreacheable message.
+       (options): Unify messages.
+       (help_filter): Likewise.
+       * util/grub-mklayout.c (usage): Removed (unused).
+       (main): Print filename in error.
+       * util/grub-mkrescue.in: Fix wrong quoting.
+       * util/grub-setup.c (setup): Print filename in error.
+       * util/ieee1275/ofpath.c (vendor_is_ATA): Likewise.
+       (check_sas): Likewise.
+       * util/misc.c (grub_util_get_fp_size): Removed.
+       (grub_util_get_image_size): Print filename in error.
+       (grub_util_read_at): Removed.
+       (grub_util_read_image): Print filename in error.
+       (grub_util_load_image): Likewise.
+       (grub_util_write_image_at): New argument filename. All users updated.
+       Print filename in error.
+       (grub_util_write_image): New argument filename. All users updated.
+       Print filename in error.
+       * util/raid.c (grub_util_raid_getmembers): Print filename in error.
+       * util/resolve.c (grub_util_resolve_dependencies): Likewise.
+
 2012-02-05  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/Makefile.core.def (pxechain): New module.
index 6220fa9aa52945f1b716190b6f013924d8527dfe..1ade44cabca0d7ce4d3c1d8c99bbd0c8a385b914 100644 (file)
@@ -221,7 +221,7 @@ grub_util_get_geli_uuid (const char *dev)
   if (fd < 0)
     return NULL;
 
-  s = grub_util_get_fd_sectors (fd, &log_secsize);
+  s = grub_util_get_fd_sectors (fd, dev, &log_secsize);
   grub_util_fd_seek (fd, dev, (s << log_secsize) - 512);
 
   uuid = xmalloc (GRUB_MD_SHA256->mdlen * 2 + 1);
index 1b5374934d8f517a950dfd8e519930de1ea0136c..331e8095a334fcc8cf1dbd0e5b5e796fbd6085cf 100644 (file)
@@ -240,7 +240,7 @@ grub_util_biosdisk_iterate (int (*hook) (const char *name),
 
 #if !defined(__MINGW32__)
 grub_uint64_t
-grub_util_get_fd_sectors (int fd, unsigned *log_secsize)
+grub_util_get_fd_sectors (int fd, const char *name, unsigned *log_secsize)
 {
 # if defined(__NetBSD__)
   struct disklabel label;
@@ -253,7 +253,7 @@ grub_util_get_fd_sectors (int fd, unsigned *log_secsize)
   struct stat st;
 
   if (fstat (fd, &st) < 0)
-    grub_util_error (_("fstat failed"));
+    grub_util_error (_("cannot stat `%s': %s"), name, strerror (errno));
 
 #if defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || \
   defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__) \
@@ -374,7 +374,8 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
     if (fd == -1)
       return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device);
 
-    disk->total_sectors = grub_util_get_fd_sectors (fd, &disk->log_sector_size);
+    disk->total_sectors = grub_util_get_fd_sectors (fd, map[drive].device,
+                                                   &disk->log_sector_size);
 
 # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__)
     if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode))
@@ -1143,14 +1144,14 @@ read_device_map (const char *dev_map)
 
   if (dev_map[0] == '\0')
     {
-      grub_util_info (_("no device.map"));
+      grub_util_info ("no device.map");
       return;
     }
 
   fp = fopen (dev_map, "r");
   if (! fp)
     {
-      grub_util_info (_("cannot open `%s'"), dev_map);
+      grub_util_info (_("cannot open `%s': %s"), dev_map, strerror (errno));
       return;
     }
 
index 950d26c03f49dc187d3033bac9c0ae9b80efcb9c..b3db85902d63967e14cf62127200b5ad58ae5d9f 100644 (file)
@@ -58,7 +58,7 @@ grub_hostdisk_os_dev_to_grub_drive (const char *os_dev, int add);
 
 #if !defined(__MINGW32__)
 grub_uint64_t
-grub_util_get_fd_sectors (int fd, unsigned *log_secsize);
+grub_util_get_fd_sectors (int fd, const char *name, unsigned *log_secsize);
 #endif
 
 char *
index 419c8661cc1e1db16a32a67c9ad8ba336c92508d..073493eedf029de3aa1dd11b2f1958c6bc8328b3 100644 (file)
 #include <grub/emu/misc.h>
 
 char *grub_util_get_path (const char *dir, const char *file);
-size_t grub_util_get_fp_size (FILE *fp);
 size_t grub_util_get_image_size (const char *path);
-void grub_util_read_at (void *img, size_t len, off_t offset, FILE *fp);
 char *grub_util_read_image (const char *path);
 void grub_util_load_image (const char *path, char *buf);
-void grub_util_write_image (const char *img, size_t size, FILE *out);
+void grub_util_write_image (const char *img, size_t size, FILE *out,
+                           const char *name);
 void grub_util_write_image_at (const void *img, size_t size, off_t offset,
-                              FILE *out);
+                              FILE *out, const char *name);
 
 #ifdef __MINGW32__
 
index 120980b904c032ab5f558a63acda16a1f2dec835..f69af89f8bda32714abb229567b52287dd8c76fa 100644 (file)
@@ -868,7 +868,7 @@ grub_guess_root_devices (const char *dir)
     }
 
   if (stat (dir, &st) < 0)
-    grub_util_error (_("cannot stat `%s'"), dir);
+    grub_util_error (_("cannot stat `%s': %s"), dir, strerror (errno));
 
   dev = st.st_dev;
 
@@ -1915,8 +1915,10 @@ grub_util_get_os_disk (const char *os_dev)
 
   if (stat (os_dev, &st) < 0)
     {
-      grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", os_dev);
-      grub_util_info ("cannot stat `%s'", os_dev);
+      const char *errstr = strerror (errno); 
+      grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot stat `%s': %s"),
+                 os_dev, errstr);
+      grub_util_info (_("cannot stat `%s': %s"), os_dev, errstr);
       return 0;
     }
 
@@ -1934,8 +1936,10 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
 
   if (stat (os_dev, &st) < 0)
     {
-      grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", os_dev);
-      grub_util_info ("cannot stat `%s'", os_dev);
+      const char *errstr = strerror (errno); 
+      grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot stat `%s': %s"), os_dev,
+                 errstr);
+      grub_util_info (_("cannot stat `%s': %s"), os_dev, errstr);
       return 0;
     }
 
@@ -2337,7 +2341,8 @@ grub_util_check_block_device (const char *blk_dev)
   struct stat st;
 
   if (stat (blk_dev, &st) < 0)
-    grub_util_error (_("cannot stat `%s'"), blk_dev);
+    grub_util_error (_("cannot stat `%s': %s"), blk_dev,
+                    strerror (errno));
 
   if (S_ISBLK (st.st_mode))
     return (blk_dev);
@@ -2351,7 +2356,7 @@ grub_util_check_char_device (const char *blk_dev)
   struct stat st;
 
   if (stat (blk_dev, &st) < 0)
-    grub_util_error (_("cannot stat `%s'"), blk_dev);
+    grub_util_error (_("cannot stat `%s': %s"), blk_dev, strerror (errno));
 
   if (S_ISCHR (st.st_mode))
     return (blk_dev);
@@ -2493,7 +2498,7 @@ grub_make_system_path_relative_to_its_root (const char *path)
   free (p);
 
   if (stat (buf, &st) < 0)
-    grub_util_error (_("cannot stat %s: %s"), buf, strerror (errno));
+    grub_util_error (_("cannot stat `%s': %s"), buf, strerror (errno));
 
   buf2 = xstrdup (buf);
   num = st.st_dev;
@@ -2512,7 +2517,7 @@ grub_make_system_path_relative_to_its_root (const char *path)
        *++p = 0;
 
       if (stat (buf, &st) < 0)
-       grub_util_error (_("cannot stat %s: %s"), buf, strerror (errno));
+       grub_util_error (_("cannot stat `%s': %s"), buf, strerror (errno));
 
       /* buf is another filesystem; we found it.  */
       if (st.st_dev != num)
index 2bff806121c7174ff6b498bc4ae36e5cef0b8c6f..f8b2ef7fea835673eb743ec6b0ff536ca0d11bef 100644 (file)
@@ -120,14 +120,16 @@ create_envblk_file (const char *name)
   namenew = xasprintf ("%s.new", name);
   fp = fopen (namenew, "wb");
   if (! fp)
-    grub_util_error (_("cannot open the file %s"), namenew);
+    grub_util_error (_("cannot open `%s': %s"), namenew,
+                    strerror (errno));
 
   memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
   memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#',
           DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) + 1);
 
   if (fwrite (buf, 1, DEFAULT_ENVBLK_SIZE, fp) != DEFAULT_ENVBLK_SIZE)
-    grub_util_error (_("cannot write to the file %s"), namenew);
+    grub_util_error (_("cannot write to the file `%s': %s"), namenew,
+                    strerror (errno));
 
   fsync (fileno (fp));
   free (buf);
@@ -153,23 +155,27 @@ open_envblk_file (const char *name)
       create_envblk_file (name);
       fp = fopen (name, "rb");
       if (! fp)
-        grub_util_error (_("cannot open the file %s"), name);
+        grub_util_error (_("cannot open `%s': %s"), name,
+                        strerror (errno));
     }
 
   if (fseek (fp, 0, SEEK_END) < 0)
-    grub_util_error (_("cannot seek the file %s"), name);
+    grub_util_error (_("cannot seek the file `%s': %s"), name,
+                    strerror (errno));
 
   size = (size_t) ftell (fp);
 
   if (fseek (fp, 0, SEEK_SET) < 0)
-    grub_util_error (_("cannot seek the file %s"), name);
+    grub_util_error (_("cannot seek the file `%s': %s"), name,
+                    strerror (errno));
 
   buf = malloc (size);
   if (! buf)
     grub_util_error (_("out of memory"));
 
   if (fread (buf, 1, size, fp) != size)
-    grub_util_error (_("cannot read the file %s"), name);
+    grub_util_error (_("cannot read the file `%s': %s"), name,
+                    strerror (errno));
 
   fclose (fp);
 
@@ -204,11 +210,13 @@ write_envblk (const char *name, grub_envblk_t envblk)
 
   fp = fopen (name, "wb");
   if (! fp)
-    grub_util_error (_("cannot open the file %s"), name);
+    grub_util_error (_("cannot open `%s': %s"), name,
+                    strerror (errno));
 
   if (fwrite (grub_envblk_buffer (envblk), 1, grub_envblk_size (envblk), fp)
       != grub_envblk_size (envblk))
-    grub_util_error (_("cannot write to the file %s"), name);
+    grub_util_error (_("cannot write to the file `%s': %s"), name,
+                    strerror (errno));
 
   fsync (fileno (fp));
   fclose (fp);
index c81314e77da6b3b0f64315dc0a06450c44956014..cb7f9a36468305a52f420ccab63ae90a7f9fa3a6 100644 (file)
@@ -173,7 +173,8 @@ cmd_cp (char *src, char *dest)
 
     if ((int) fwrite (buf, 1, len, ff) != len)
       {
-       grub_util_error (_("write error"));
+       grub_util_error (_("cannot write to the file `%s': %s"),
+                        dest, strerror (errno));
        return 1;
       }
 
@@ -201,7 +202,8 @@ cmd_cat (char *src)
 
     if ((int) fwrite (buf, 1, len, stdout) != len)
       {
-       grub_util_error (_("write error"));
+       grub_util_error (_("cannot write to the stdout: %s"),
+                        strerror (errno));
        return 1;
       }
 
@@ -249,7 +251,8 @@ cmd_cmp (char *src, char *dest)
     }
 
   if ((skip) && (fseeko (ff, skip, SEEK_SET)))
-    grub_util_error (_("seek error"));
+    grub_util_error (_("cannot seek the file `%s': %s"), dest,
+                    strerror (errno));
 
   read_file (src, cmp_hook);
 
index aeabad9763aa58c1b39ac2bc3cc1aaab5258923c..1f41ee8f56c7935858d3de0703cf85ea6eca9e8b 100644 (file)
@@ -47,7 +47,7 @@ main (int argc, char **argv)
       in = fopen (argv[1], "r");
       if (!in)
        {
-         fprintf (stderr, _("Couldn't open %s for reading: %s\n"),
+         fprintf (stderr, _("cannot open `%s': %s"),
                   argv[1], strerror (errno));
          return 1;
        }
@@ -62,7 +62,7 @@ main (int argc, char **argv)
        {                                       
          if (in != stdin)
            fclose (in);
-         fprintf (stderr, _("Couldn't open %s for writing: %s\n"),
+         fprintf (stderr, _("cannot open `%s': %s"),
                   argv[2], strerror (errno));
          return 1;
        }
index 58eca093a7d260bb34ef7a8a25ee63679065af11..d809a00068ea53d4b383547105c14a2605fa51cc 100644 (file)
@@ -648,31 +648,33 @@ add_font (struct grub_font_info *font_info, FT_Face face, int nocut)
     }
 }
 
-void
-write_string_section (char *name, char *str, int* offset, FILE* file)
+static void
+write_string_section (char *name, char *str, int* offset, FILE *file,
+                     const char *filename)
 {
   grub_uint32_t leng, leng_be32;
 
   leng = strlen (str) + 1;
   leng_be32 = grub_cpu_to_be32 (leng);
 
-  grub_util_write_image (name, 4, file);
-  grub_util_write_image ((char *) &leng_be32, 4, file);
-  grub_util_write_image (str, leng, file);
+  grub_util_write_image (name, 4, file, filename);
+  grub_util_write_image ((char *) &leng_be32, 4, file, filename);
+  grub_util_write_image (str, leng, file, filename);
 
   *offset += 8 + leng;
 }
 
-void
-write_be16_section (char *name, grub_uint16_t data, int* offset, FILE* file)
+static void
+write_be16_section (char *name, grub_uint16_t data, int* offset, FILE *file,
+                   const char *filename)
 {
   grub_uint32_t leng;
 
   leng = grub_cpu_to_be32 (2);
   data = grub_cpu_to_be16 (data);
-  grub_util_write_image (name, 4, file);
-  grub_util_write_image ((char *) &leng, 4, file);
-  grub_util_write_image ((char *) &data, 2, file);
+  grub_util_write_image (name, 4, file, filename);
+  grub_util_write_image ((char *) &leng, 4, file, filename);
+  grub_util_write_image ((char *) &data, 2, file, filename);
 
   *offset += 10;
 }
@@ -758,7 +760,8 @@ write_font_ascii_bitmap (struct grub_font_info *font_info, char *output_file)
   
   file = fopen (output_file, "wb");
   if (! file)
-    grub_util_error (_("Can\'t write to file %s."), output_file);
+    grub_util_error (_("cannot write to the file `%s': %s"), output_file,
+                    strerror (errno));
 
   int correct_size;
   for (glyph = font_info->glyphs_sorted, num = 0; num < font_info->num_glyphs;
@@ -794,7 +797,8 @@ write_font_width_spec (struct grub_font_info *font_info, char *output_file)
   
   file = fopen (output_file, "wb");
   if (! file)
-    grub_util_error (_("Can\'t write to file %s."), output_file);
+    grub_util_error (_("cannot write to the file `%s': %s"), output_file,
+                    strerror (errno));
 
   for (glyph = font_info->glyphs_sorted;
        glyph < font_info->glyphs_sorted + font_info->num_glyphs; glyph++)
@@ -817,15 +821,17 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
 
   file = fopen (output_file, "wb");
   if (! file)
-    grub_util_error (_("Can\'t write to file %s."), output_file);
+    grub_util_error (_("cannot write to the file `%s': %s"), output_file,
+                    strerror (errno));
 
   offset = 0;
 
   leng = grub_cpu_to_be32 (4);
   grub_util_write_image (FONT_FORMAT_SECTION_NAMES_FILE,
-                        sizeof(FONT_FORMAT_SECTION_NAMES_FILE) - 1, file);
-  grub_util_write_image ((char *) &leng, 4, file);
-  grub_util_write_image (FONT_FORMAT_PFF2_MAGIC, 4, file);
+                        sizeof(FONT_FORMAT_SECTION_NAMES_FILE) - 1, file,
+                        output_file);
+  grub_util_write_image ((char *) &leng, 4, file, output_file);
+  grub_util_write_image (FONT_FORMAT_PFF2_MAGIC, 4, file, output_file);
   offset += 12;
 
   if (! font_info->name)
@@ -848,24 +854,24 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
                         font_info->size);
 
   write_string_section (FONT_FORMAT_SECTION_NAMES_FONT_NAME,
-                       font_name, &offset, file);
+                       font_name, &offset, file, output_file);
   write_string_section (FONT_FORMAT_SECTION_NAMES_FAMILY,
-                       font_info->name, &offset, file);
+                       font_info->name, &offset, file, output_file);
   write_string_section (FONT_FORMAT_SECTION_NAMES_WEIGHT,
                        (font_info->style & FT_STYLE_FLAG_BOLD) ?
                        "bold" : "normal",
-                       &offset, file);
+                       &offset, file, output_file);
   write_string_section (FONT_FORMAT_SECTION_NAMES_SLAN,
                        (font_info->style & FT_STYLE_FLAG_ITALIC) ?
                        "italic" : "normal",
-                       &offset, file);
+                       &offset, file, output_file);
 
   write_be16_section (FONT_FORMAT_SECTION_NAMES_POINT_SIZE,
-                     font_info->size, &offset, file);
+                     font_info->size, &offset, file, output_file);
   write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH,
-                     font_info->max_width, &offset, file);
+                     font_info->max_width, &offset, file, output_file);
   write_be16_section (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT,
-                     font_info->max_height, &offset, file);
+                     font_info->max_height, &offset, file, output_file);
 
   if (! font_info->desc)
     {
@@ -884,9 +890,9 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
     }
 
   write_be16_section (FONT_FORMAT_SECTION_NAMES_ASCENT,
-                     font_info->asce, &offset, file);
+                     font_info->asce, &offset, file, output_file);
   write_be16_section (FONT_FORMAT_SECTION_NAMES_DESCENT,
-                     font_info->desc, &offset, file);
+                     font_info->desc, &offset, file, output_file);
 
   if (font_verbosity > 0)
     {
@@ -903,8 +909,8 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
   leng = grub_cpu_to_be32 (font_info->num_glyphs * 9);
   grub_util_write_image (FONT_FORMAT_SECTION_NAMES_CHAR_INDEX,
                         sizeof(FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) - 1,
-                        file);
-  grub_util_write_image ((char *) &leng, 4, file);
+                        file, output_file);
+  grub_util_write_image ((char *) &leng, 4, file, output_file);
   offset += 8 + font_info->num_glyphs * 9 + 8;
 
   for (cur = font_info->glyphs_sorted;
@@ -913,41 +919,43 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
       grub_uint32_t data32;
       grub_uint8_t data8;
       data32 = grub_cpu_to_be32 (cur->char_code);
-      grub_util_write_image ((char *) &data32, 4, file);
+      grub_util_write_image ((char *) &data32, 4, file, output_file);
       data8 = 0;
-      grub_util_write_image ((char *) &data8, 1, file);
+      grub_util_write_image ((char *) &data8, 1, file, output_file);
       data32 = grub_cpu_to_be32 (offset);
-      grub_util_write_image ((char *) &data32, 4, file);
+      grub_util_write_image ((char *) &data32, 4, file, output_file);
       offset += 10 + cur->bitmap_size;
     }
 
   leng = 0xffffffff;
   grub_util_write_image (FONT_FORMAT_SECTION_NAMES_DATA,
-                        sizeof(FONT_FORMAT_SECTION_NAMES_DATA) - 1, file);
-  grub_util_write_image ((char *) &leng, 4, file);
+                        sizeof(FONT_FORMAT_SECTION_NAMES_DATA) - 1,
+                        file, output_file);
+  grub_util_write_image ((char *) &leng, 4, file, output_file);
 
   for (cur = font_info->glyphs_sorted;
        cur < font_info->glyphs_sorted + font_info->num_glyphs; cur++)
     {
       grub_uint16_t data;
       data = grub_cpu_to_be16 (cur->width);
-      grub_util_write_image ((char *) &data, 2, file);
+      grub_util_write_image ((char *) &data, 2, file, output_file);
       data = grub_cpu_to_be16 (cur->height);
-      grub_util_write_image ((char *) &data, 2, file);
+      grub_util_write_image ((char *) &data, 2, file, output_file);
       data = grub_cpu_to_be16 (cur->x_ofs);
-      grub_util_write_image ((char *) &data, 2, file);
+      grub_util_write_image ((char *) &data, 2, file, output_file);
       data = grub_cpu_to_be16 (cur->y_ofs);
-      grub_util_write_image ((char *) &data, 2, file);
+      grub_util_write_image ((char *) &data, 2, file, output_file);
       data = grub_cpu_to_be16 (cur->device_width);
-      grub_util_write_image ((char *) &data, 2, file);
-      grub_util_write_image ((char *) &cur->bitmap[0], cur->bitmap_size, file);
+      grub_util_write_image ((char *) &data, 2, file, output_file);
+      grub_util_write_image ((char *) &cur->bitmap[0], cur->bitmap_size,
+                            file, output_file);
     }
 
   fclose (file);
 }
 
 static struct argp_option options[] = {
-  {"output",  'o', N_("FILE"), 0, N_("set output file"), 0},
+  {"output",  'o', N_("FILE"), 0, N_("save output in FILE [required]"), 0},
   {"ascii-bitmaps",  0x102, 0, 0, N_("save only the ASCII bitmaps"), 0},
   {"width-spec",  0x103, 0, 0, N_("create width summary file"), 0},
   {"index",  'i', N_("NUM"), 0, N_("set face index"), 0},
index 72ddb529640cc69bc2cfc2b4ce9d663c6c614047..3884acb0a20472fba78b1509bd098a72870cbb94 100644 (file)
@@ -695,7 +695,8 @@ struct fixup_block_list
 #undef MKIMAGE_ELF64
 
 static void
-generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
+generate_image (const char *dir, char *prefix, FILE *out, const char *outname,
+               char *mods[],
                char *memdisk_path, char *config_path,
                struct image_target_desc *image_target, int note,
                grub_compression_t comp)
@@ -959,15 +960,13 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
        char *boot_path, *boot_img;
        size_t boot_size;
 
-       if (GRUB_KERNEL_I386_PC_LINK_ADDR + core_size > 0x78000)
+       if (GRUB_KERNEL_I386_PC_LINK_ADDR + core_size > 0x78000
+           || (core_size > (0xffff << GRUB_DISK_SECTOR_BITS)))
          grub_util_error (_("core image is too big (0x%x > 0x%x)"),
                           GRUB_KERNEL_I386_PC_LINK_ADDR + core_size,
                           0x78000);
 
        num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
-       if (num > 0xffff)
-         grub_util_error (_("the core image is too big"));
-
        if (image_target->id == IMAGE_I386_PC_PXE)
          {
            char *pxeboot_path, *pxeboot_img;
@@ -978,7 +977,8 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
            pxeboot_size = grub_util_get_image_size (pxeboot_path);
            pxeboot_img = grub_util_read_image (pxeboot_path);
            
-           grub_util_write_image (pxeboot_img, pxeboot_size, out);
+           grub_util_write_image (pxeboot_img, pxeboot_size, out,
+                                  outname);
            free (pxeboot_img);
            free (pxeboot_path);
 
@@ -1016,7 +1016,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
                                            + (GRUB_DISK_SECTOR_SIZE >> 4)));
        }
 
-       grub_util_write_image (boot_img, boot_size, out);
+       grub_util_write_image (boot_img, boot_size, out, outname);
        free (boot_img);
        free (boot_path);
       }
@@ -1290,7 +1290,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
                             - GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE + 8))
          = grub_host_to_target32 (num);
 
-       grub_util_write_image (boot_img, boot_size, out);
+       grub_util_write_image (boot_img, boot_size, out, outname);
        free (boot_img);
        free (boot_path);
       }
@@ -1616,7 +1616,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
       break;
     }
 
-  grub_util_write_image (core_img, core_size, out);
+  grub_util_write_image (core_img, core_size, out, outname);
   free (core_img);
   free (kernel_path);
 
@@ -1632,15 +1632,15 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
 \f
 
 static struct argp_option options[] = {
-  {"directory",  'd', N_("DIR"), 0, N_("use images and modules under DIR [default=%s/@platform@]"), 0},
+  {"directory",  'd', N_("DIR"), 0, N_("use images and modules under DIR [default=%s/<platform>]"), 0},
   {"prefix",  'p', N_("DIR"), 0, N_("set grub_prefix directory [default=%s]"), 0},
   {"memdisk",  'm', N_("FILE"), 0, N_("embed FILE as a memdisk image"), 0},
   {"config",   'c', N_("FILE"), 0, N_("embed FILE as boot config"), 0},
   {"note",   'n', 0, 0, N_("add NOTE segment for CHRP Open Firmware"), 0},
   {"output",  'o', N_("FILE"), 0, N_("output a generated image to FILE [default=stdout]"), 0},
-  {"format",  'O', N_("FORMAT"), 0, N_("generate an image in format.\navailable formats: %s"), 0},
+  {"format",  'O', N_("FORMAT"), 0, 0, 0},
   {"compression",  'C', "(xz|none|auto)", 0, N_("choose the compression to use"), 0},
-  {"verbose",     'v', 0,      0, N_("Print verbose messages."), 0},
+  {"verbose",     'v', 0,      0, N_("print verbose messages."), 0},
   { 0, 0, 0, 0, 0, 0 }
 };
 
@@ -1671,7 +1671,8 @@ help_filter (int key, const char *text, void *input __attribute__ ((unused)))
            *ptr++ = ' ';
          }
        ptr[-2] = 0;
-       ret = xasprintf (text, formats);
+       ret = xasprintf ("%s\n%s %s", _("generate an image in format"),
+                        _("available formats:"), formats);
        free (formats);
        return ret;
       }
@@ -1829,7 +1830,7 @@ main (int argc, char *argv[])
   if (!arguments.image_target)
     {
       char *program = xstrdup(program_name);
-      printf ("%s", _("Target format not specified (use the -O option).\n"));
+      printf ("%s\n", _("Target format not specified (use the -O option)."));
       argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
       free (program);
       exit(1);
@@ -1839,7 +1840,8 @@ main (int argc, char *argv[])
     {
       fp = fopen (arguments.output, "wb");
       if (! fp)
-       grub_util_error (_("cannot open %s"), arguments.output);
+       grub_util_error (_("cannot open `%s': %s"), arguments.output,
+                        strerror (errno));
       free (arguments.output);
     }
 
@@ -1856,6 +1858,7 @@ main (int argc, char *argv[])
     }
 
   generate_image (arguments.dir, arguments.prefix ? : DEFAULT_DIRECTORY, fp,
+                 arguments.output,
                  arguments.modules, arguments.memdisk, arguments.config,
                  arguments.image_target, arguments.note, arguments.comp);
 
index f31b660a9da394758843e01415f41293880ac404..6b85ef87f293d1c5b0510b11299992ab57ec6e93 100644 (file)
@@ -264,20 +264,6 @@ static grub_uint8_t linux_to_usb_map[128] = {
   /* 0x6e */ GRUB_KEYBOARD_KEY_INSERT,      GRUB_KEYBOARD_KEY_DELETE
 }; 
 
-static void
-usage (int status)
-{
-  if (status)
-    fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name);
-  else
-    printf (_("\
-Usage: %s [OPTIONS]\n\
-\n\
-Report bugs to <%s>.\n"), program_name, PACKAGE_BUGREPORT);
-
-  exit (status);
-}
-
 static void
 add_special_keys (struct grub_keyboard_layout *layout)
 {
@@ -484,7 +470,8 @@ main (int argc, char *argv[])
     in = stdin;
 
   if (!in)
-    grub_util_error (_("Couldn't open input file: %s\n"), strerror (errno));
+    grub_util_error (_("cannot open `%s': %s"), arguments.input ? : "stdin",
+                    strerror (errno));
 
   if (arguments.output)
     out = fopen (arguments.output, "wb");
@@ -495,7 +482,8 @@ main (int argc, char *argv[])
     {
       if (in != stdin)
        fclose (in);
-      grub_util_error (_("Couldn't open output file: %s\n"), strerror (errno));
+      grub_util_error (_("cannot open `%s': %s"), arguments.output ? : "stdout",
+                      strerror (errno));
     }
 
   write_keymaps (in, out);
index e0800648f2f5d64d74fb0b833360bcf6c059da83..22d43f6eb9e930b52705a54efbb591d02f5c141a 100644 (file)
@@ -270,7 +270,7 @@ if test -e "${pc_dir}" ; then
     embed_img="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
     cat "${pc_dir}/boot.img" "${core_img}" > "${embed_img}"
 
-    rm -f $"{core_img}"
+    rm -f "${core_img}"
 
     grub_mkisofs_arguments="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-info-table \
                --embedded-boot ${embed_img}"
index 730b9c12f160246358e8d32a270d89e983a16cc1..d63e8d78e3d30b31a8c3b80b9bfbf5d6a251cc88 100644 (file)
@@ -123,7 +123,7 @@ insert_string (const char *name)
 }
 
 static int *
-write_section_data (FILE* fp, char *image,
+write_section_data (FILE* fp, const char *name, char *image,
                     struct grub_pe32_coff_header *pe_chdr,
                     struct grub_pe32_section_table *pe_shdr)
 {
@@ -192,7 +192,8 @@ write_section_data (FILE* fp, char *image,
         {
           shdr[idx].sh_offset = offset;
           grub_util_write_image_at (image + pe_shdr->raw_data_offset,
-                                    pe_shdr->raw_data_size, offset, fp);
+                                    pe_shdr->raw_data_size, offset, fp,
+                                   name);
 
           offset += pe_shdr->raw_data_size;
         }
@@ -222,7 +223,7 @@ write_section_data (FILE* fp, char *image,
 }
 
 static void
-write_reloc_section (FILE* fp, char *image,
+write_reloc_section (FILE* fp, const char *name, char *image,
                      struct grub_pe32_coff_header *pe_chdr,
                      struct grub_pe32_section_table *pe_shdr,
                      Elf32_Sym *symtab,
@@ -296,7 +297,7 @@ write_reloc_section (FILE* fp, char *image,
         grub_util_write_image_at (image + pe_sec->raw_data_offset,
                                   shdr[shdr[i].sh_info].sh_size,
                                   shdr[shdr[i].sh_info].sh_offset,
-                                  fp);
+                                  fp, name);
 
       shdr[i].sh_type = SHT_REL;
       shdr[i].sh_offset = offset;
@@ -305,14 +306,14 @@ write_reloc_section (FILE* fp, char *image,
       shdr[i].sh_entsize = sizeof (Elf32_Rel);
       shdr[i].sh_size = num_rels * sizeof (Elf32_Rel);
 
-      grub_util_write_image_at (rel, shdr[i].sh_size, offset, fp);
+      grub_util_write_image_at (rel, shdr[i].sh_size, offset, fp, name);
       offset += shdr[i].sh_size;
       free (rel);
     }
 }
 
 static void
-write_symbol_table (FILE* fp, char *image,
+write_symbol_table (FILE* fp, const char *name, char *image,
                     struct grub_pe32_coff_header *pe_chdr,
                     struct grub_pe32_section_table *pe_shdr,
                     int *section_map)
@@ -403,7 +404,7 @@ write_symbol_table (FILE* fp, char *image,
   shdr[SYMTAB_SECTION].sh_addralign = 4;
 
   grub_util_write_image_at (symtab, shdr[SYMTAB_SECTION].sh_size,
-                            offset, fp);
+                            offset, fp, name);
   offset += shdr[SYMTAB_SECTION].sh_size;
 
   free (symtab);
@@ -411,21 +412,22 @@ write_symbol_table (FILE* fp, char *image,
 }
 
 static void
-write_string_table (FILE* fp)
+write_string_table (FILE *fp, const char *name)
 {
   shdr[STRTAB_SECTION].sh_name = insert_string (".strtab");
   shdr[STRTAB_SECTION].sh_type = SHT_STRTAB;
   shdr[STRTAB_SECTION].sh_offset = offset;
   shdr[STRTAB_SECTION].sh_size = strtab_len;
   shdr[STRTAB_SECTION].sh_addralign = 1;
-  grub_util_write_image_at (strtab, strtab_len, offset, fp);
+  grub_util_write_image_at (strtab, strtab_len, offset, fp,
+                           name);
   offset += strtab_len;
 
   free (strtab);
 }
 
 static void
-write_section_header (FILE* fp)
+write_section_header (FILE *fp, const char *name)
 {
   ehdr.e_ident[EI_MAG0] = ELFMAG0;
   ehdr.e_ident[EI_MAG1] = ELFMAG1;
@@ -446,13 +448,13 @@ write_section_header (FILE* fp)
   ehdr.e_shoff = offset;
   ehdr.e_shnum = num_sections;
   grub_util_write_image_at (&shdr, sizeof (Elf32_Shdr) * num_sections,
-                            offset, fp);
+                            offset, fp, name);
 
-  grub_util_write_image_at (&ehdr, sizeof (Elf32_Ehdr), 0, fp);
+  grub_util_write_image_at (&ehdr, sizeof (Elf32_Ehdr), 0, fp, name);
 }
 
 static void
-convert_pe (FILE* fp, char *image)
+convert_pe (FILE* fp, const char *name, char *image)
 {
   struct grub_pe32_coff_header *pe_chdr;
   struct grub_pe32_section_table *pe_shdr;
@@ -471,14 +473,14 @@ convert_pe (FILE* fp, char *image)
   pe_shdr = (struct grub_pe32_section_table *) (pe_chdr + 1);
   num_sections = REL_SECTION;
 
-  section_map = write_section_data (fp, image, pe_chdr, pe_shdr);
+  section_map = write_section_data (fp, name, image, pe_chdr, pe_shdr);
 
-  write_symbol_table (fp, image, pe_chdr, pe_shdr, section_map);
+  write_symbol_table (fp, name, image, pe_chdr, pe_shdr, section_map);
   free (section_map);
 
-  write_string_table (fp);
+  write_string_table (fp, name);
 
-  write_section_header (fp);
+  write_section_header (fp, name);
 }
 
 int
@@ -533,7 +535,7 @@ main (int argc, char *argv[])
   if (! fp)
     grub_util_error ("cannot open %s", argv[optind]);
 
-  convert_pe (fp, image);
+  convert_pe (fp, argv[optind], image);
 
   fclose (fp);
 
index e5a8ced9577d2ad00a6a51e6ec60258b47dde2c2..cdc7284332e50136f644e97fb6f20afee19c1350 100644 (file)
@@ -709,9 +709,10 @@ unable_to_embed:
   grub_util_info ("opening the core image `%s'", core_path);
   fp = fopen (core_path, "r+b");
   if (! fp)
-    grub_util_error (_("cannot open `%s'"), core_path);
+    grub_util_error (_("cannot open `%s': %s"), core_path,
+                    strerror (errno));
 
-  grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp);
+  grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp, core_path);
   fclose (fp);
 
  finish:
index 9b3825fc27468b5a81c6a2234633ba664dcb517b..932b79809efa2bee7c44464fa63eeb0ed60f4e0d 100644 (file)
@@ -294,15 +294,15 @@ vendor_is_ATA(const char *path)
 
   bufname = xmalloc (path_size);
 
-  snprintf(bufname, path_size, "%s/vendor", path);
-  fd = open(bufname, O_RDONLY);
+  snprintf (bufname, path_size, "%s/vendor", path);
+  fd = open (bufname, O_RDONLY);
   if (fd < 0)
-    grub_util_error (_("cannot open 'vendor' node of `%s'"), path);
+    grub_util_error (_("cannot open `%s': %s"), bufname, strerror (errno));
 
   memset(bufcont, 0, sizeof (bufcont));
   err = read(fd, bufcont, sizeof (bufcont));
   if (err < 0)
-    grub_util_error (_("cannot read 'vendor' node of `%s'"), path);
+    grub_util_error (_("cannot open `%s': %s"), bufname, strerror (errno));
 
   close(fd);
   free (bufname);
@@ -336,9 +336,9 @@ check_sas (char *sysfs_path, int *tgt)
   path = xmalloc (path_size);
   snprintf (path, path_size, "%s/sas_device:%s/phy_identifier", p, ed);
 
-  fd = open(path, O_RDONLY);
+  fd = open (path, O_RDONLY);
   if (fd < 0)
-    grub_util_error(_("cannot open SAS PHY ID `%s'\n"), path);
+    grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
 
   memset (phy, 0, sizeof (phy));
   read (fd, phy, sizeof (phy));
index 6ebaf30bc78b76c5464dec5f368f568997ad3d3e..a0f022a5f6ed8454561a73d743d05955ff345837 100644 (file)
@@ -83,20 +83,6 @@ grub_util_get_path (const char *dir, const char *file)
   return path;
 }
 
-size_t
-grub_util_get_fp_size (FILE *fp)
-{
-  struct stat st;
-
-  if (fflush (fp) == EOF)
-    grub_util_error (_("fflush failed"));
-
-  if (fstat (fileno (fp), &st) == -1)
-    grub_util_error (_("fstat failed"));
-
-  return st.st_size;
-}
-
 size_t
 grub_util_get_image_size (const char *path)
 {
@@ -105,21 +91,11 @@ grub_util_get_image_size (const char *path)
   grub_util_info ("getting the size of %s", path);
 
   if (stat (path, &st) == -1)
-    grub_util_error (_("cannot stat %s"), path);
+    grub_util_error (_("cannot stat `%s': %s"), path, strerror (errno));
 
   return st.st_size;
 }
 
-void
-grub_util_read_at (void *img, size_t size, off_t offset, FILE *fp)
-{
-  if (fseeko (fp, offset, SEEK_SET) == -1)
-    grub_util_error (_("seek failed"));
-
-  if (fread (img, 1, size, fp) != size)
-    grub_util_error (_("read failed"));
-}
-
 char *
 grub_util_read_image (const char *path)
 {
@@ -134,9 +110,12 @@ grub_util_read_image (const char *path)
 
   fp = fopen (path, "rb");
   if (! fp)
-    grub_util_error (_("cannot open %s"), path);
+    grub_util_error (_("cannot open `%s': %s"), path,
+                    strerror (errno));
 
-  grub_util_read_at (img, size, 0, fp);
+  if (fread (img, 1, size, fp) != size)
+    grub_util_error (_("cannot read the file `%s': %s"), path,
+                    strerror (errno));
 
   fclose (fp);
 
@@ -155,30 +134,41 @@ grub_util_load_image (const char *path, char *buf)
 
   fp = fopen (path, "rb");
   if (! fp)
-    grub_util_error (_("cannot open %s"), path);
+    grub_util_error (_("cannot open `%s': %s"), path,
+                    strerror (errno));
 
   if (fread (buf, 1, size, fp) != size)
-    grub_util_error (_("cannot read %s"), path);
+    grub_util_error (_("cannot read the file `%s': %s"), path,
+                    strerror (errno));
 
   fclose (fp);
 }
 
 void
-grub_util_write_image_at (const void *img, size_t size, off_t offset, FILE *out)
+grub_util_write_image_at (const void *img, size_t size, off_t offset, FILE *out,
+                         const char *name)
 {
   grub_util_info ("writing 0x%x bytes at offset 0x%x", size, offset);
   if (fseeko (out, offset, SEEK_SET) == -1)
-    grub_util_error (_("seek failed"));
+    grub_util_error (_("cannot seek the file `%s': %s"),
+                    name, strerror (errno));
   if (fwrite (img, 1, size, out) != size)
-    grub_util_error (_("write failed"));
+    grub_util_error (_("cannot write to the file `%s': %s"),
+                    name, strerror (errno));
 }
 
 void
-grub_util_write_image (const char *img, size_t size, FILE *out)
+grub_util_write_image (const char *img, size_t size, FILE *out,
+                      const char *name)
 {
   grub_util_info ("writing 0x%x bytes", size);
   if (fwrite (img, 1, size, out) != size)
-    grub_util_error (_("write failed"));
+    if (!name)
+      grub_util_error (_("cannot write to the stdout: %s"),
+                      strerror (errno));
+    else
+      grub_util_error (_("cannot write to the file `%s': %s"),
+                      name, strerror (errno));
 }
 
 char *
index 8de5fbac0c54185d2eaf730a492e0aeead0cde17..0851bff96b73280684e188b85903be0617619c00 100644 (file)
@@ -47,7 +47,7 @@ grub_util_raid_getmembers (const char *name, int bootable)
   fd = open (name, O_RDONLY);
 
   if (fd == -1)
-    grub_util_error (_("can't open %s: %s"), name, strerror (errno));
+    grub_util_error (_("cannot open `%s': %s"), name, strerror (errno));
 
   ret = ioctl (fd, RAID_VERSION, &version);
   if (ret != 0)
index 3eb8bfb149ae4481a606380195552c908c311832..a07c454b96af386312b4790b41ffe6a6e48eba7a 100644 (file)
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <ctype.h>
+#include <errno.h>
 
 #include <grub/emu/misc.h>
 #include <grub/util/misc.h>
@@ -241,7 +242,7 @@ grub_util_resolve_dependencies (const char *prefix,
   path = grub_util_get_path (prefix, dep_list_file);
   fp = fopen (path, "r");
   if (! fp)
-    grub_util_error (_("cannot open %s"), path);
+    grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
 
   free (path);
   dep_list = read_dep_list (fp);