+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.
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);
#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;
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__) \
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))
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;
}
#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 *
#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__
}
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;
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;
}
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;
}
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);
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);
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;
*++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)
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);
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);
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);
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;
}
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;
}
}
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);
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;
}
{
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;
}
}
}
-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;
}
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;
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++)
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)
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)
{
}
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)
{
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;
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},
#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)
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;
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);
+ (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);
}
- 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);
}
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);
\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 }
};
*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;
}
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);
{
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);
}
}
generate_image (arguments.dir, arguments.prefix ? : DEFAULT_DIRECTORY, fp,
+ arguments.output,
arguments.modules, arguments.memdisk, arguments.config,
arguments.image_target, arguments.note, arguments.comp);
/* 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)
{
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");
{
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);
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}"
}
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)
{
{
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;
}
}
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,
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;
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)
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);
}
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;
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;
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
if (! fp)
grub_util_error ("cannot open %s", argv[optind]);
- convert_pe (fp, image);
+ convert_pe (fp, argv[optind], image);
fclose (fp);
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:
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);
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));
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)
{
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)
{
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);
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 *
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)
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
+#include <errno.h>
#include <grub/emu/misc.h>
#include <grub/util/misc.h>
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);