diff --git a/ChangeLog b/ChangeLog index f694788d7..b0d0e9753 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,50 @@ +2012-02-05 Vladimir Serbinenko + + 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 * grub-core/Makefile.core.def (pxechain): New module. diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 6220fa9aa..1ade44cab 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -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); diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 1b5374934..331e8095a 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -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; } diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index 950d26c03..b3db85902 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -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 * diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h index 419c8661c..073493eed 100644 --- a/include/grub/util/misc.h +++ b/include/grub/util/misc.h @@ -31,14 +31,13 @@ #include 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__ diff --git a/util/getroot.c b/util/getroot.c index 120980b90..f69af89f8 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -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) diff --git a/util/grub-editenv.c b/util/grub-editenv.c index 2bff80612..f8b2ef7fe 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -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); diff --git a/util/grub-fstest.c b/util/grub-fstest.c index c81314e77..cb7f9a364 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -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); diff --git a/util/grub-menulst2cfg.c b/util/grub-menulst2cfg.c index aeabad976..1f41ee8f5 100644 --- a/util/grub-menulst2cfg.c +++ b/util/grub-menulst2cfg.c @@ -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; } diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index 58eca093a..d809a0006 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -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}, diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 72ddb5296..3884acb0a 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -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[], 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/]"), 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); diff --git a/util/grub-mklayout.c b/util/grub-mklayout.c index f31b660a9..6b85ef87f 100644 --- a/util/grub-mklayout.c +++ b/util/grub-mklayout.c @@ -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); diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index e0800648f..22d43f6eb 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -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}" diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c index 730b9c12f..d63e8d78e 100644 --- a/util/grub-pe2elf.c +++ b/util/grub-pe2elf.c @@ -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); diff --git a/util/grub-setup.c b/util/grub-setup.c index e5a8ced95..cdc728433 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -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: diff --git a/util/ieee1275/ofpath.c b/util/ieee1275/ofpath.c index 9b3825fc2..932b79809 100644 --- a/util/ieee1275/ofpath.c +++ b/util/ieee1275/ofpath.c @@ -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)); diff --git a/util/misc.c b/util/misc.c index 6ebaf30bc..a0f022a5f 100644 --- a/util/misc.c +++ b/util/misc.c @@ -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 * diff --git a/util/raid.c b/util/raid.c index 8de5fbac0..0851bff96 100644 --- a/util/raid.c +++ b/util/raid.c @@ -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) diff --git a/util/resolve.c b/util/resolve.c index 3eb8bfb14..a07c454b9 100644 --- a/util/resolve.c +++ b/util/resolve.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -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);