Commit Graph

46 Commits

Author SHA1 Message Date
Colin Watson 62daa27056 util: Detect more I/O errors
Many of GRUB's utilities don't check anywhere near all the possible
write errors.  For example, if grub-install runs out of space when
copying a file, it won't notice.  There were missing checks for the
return values of write, fflush, fsync, and close (or the equivalents on
other OSes), all of which must be checked.

I tried to be consistent with the existing logging practices of the
various hostdisk implementations, but they weren't entirely consistent
to start with so I used my judgement.  The result at least looks
reasonable on GNU/Linux when I provoke a write error:

  Installing for x86_64-efi platform.
  grub-install: error: cannot copy `/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed' to `/boot/efi/EFI/debian/grubx64.efi': No space left on device.

There are more missing checks in other utilities, but this should fix
the most critical ones.

Fixes Debian bug #922741.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Steve McIntyre <93sam@debian.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2019-03-05 10:23:47 +01:00
Vladimir Serbinenko 27d1a67f8a Fix canonicalize_file_name clash.
canonicalize_file_name clashed with gnulib function. Additionally
it was declared in 2 places: emu/misc.h and util/misc.h. Added
grub_ prefix and removed second declaration.
2015-03-04 01:00:19 +01:00
Andrey Borzenkov 5ae584c0b0 fix Mingw W64-32 cross compile failure due to printf redefinition in libintl.h
In file included from util/misc.c:36:0:
./include/grub/emu/misc.h:56:1: error: 'libintl_printf' is an unrecognized format function type [-Werror=format=]
 char * EXPORT_FUNC(xasprintf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))) WARN_UNUSED_RESULT;
 ^
./include/grub/emu/misc.h:58:1: error: 'libintl_printf' is an unrecognized format function type [-Werror=format=]

The reason is libintl.h which redefines printf as libintl_printf. The problem
is not present in native MinGW build which avoids redefinition.  Use
(format (__printf__) instead which is valid replacement in GCC.

v2: add grub-core/lib/libgcrypt/src/g10lib.h
v3: modify g10lib.h during import
2014-01-25 21:49:41 +04:00
Vladimir Serbinenko 18e76955be Use %I64 and not %ll when using OS printf if compiling for windows. 2013-12-17 16:04:47 +01:00
Vladimir Serbinenko 4f9541226c Introduce grub_util_file_sync and use it instead of fsync(fileno(f)).
Fixes build for windows.
2013-11-27 14:13:50 +01:00
Vladimir 'phcoder' Serbinenko fb320faf88 * include/grub/misc.h: Don't use warn_unused_result on gcc < 3.4.
* include/grub/emu/misc.h: Likewise.
2013-10-18 16:34:18 +02:00
Vladimir 'phcoder' Serbinenko 7e45abcef4 Move cpu time retrieval to separate grub_util_get_cpu_time_ms
and remove export.h.
2013-10-15 13:13:53 +02:00
Vladimir 'phcoder' Serbinenko bb338aaf24 Add a wrapper for fopen. On unix-like systems just pass-through. On
windows use unicode version.
2013-10-13 20:36:28 +02:00
Vladimir 'phcoder' Serbinenko 71c1d67a34 Avoid including hostfile.h when not necessarry as it pulls
in OS-specific headers which may redefine generic names
	like "far".
2013-10-10 09:18:06 +02:00
Vladimir 'phcoder' Serbinenko 761c718b52 Move OS-dependent file definitions to include/grub/osdep/hostfile*.h. 2013-10-09 08:20:20 +02:00
Vladimir 'phcoder' Serbinenko 47345010a4 Add AROS hostdisk and getroot routines. 2013-10-04 02:35:03 +02:00
Vladimir 'phcoder' Serbinenko e85a5d5ca6 * include/grub/emu/misc.h: Remove leftover cygwin definitions.
Use windows path for DEFAULT_DIRECTORY.
2013-09-23 11:24:10 +02:00
Vladimir 'phcoder' Serbinenko 984cfd8a79 * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_size): Adapt for
mingw32 as well based on grub_util_get_disk_size.
	* util/misc.c (grub_util_get_disk_size): Removed. all users switched to
	grub_util_get_fd_size.
	(sync): Removed.
	(fsync): Moved to ...
	* grub-core/kern/emu/misc.c (fsync): ... here.
2013-08-22 16:50:12 +02:00
Vladimir 'phcoder' Serbinenko 0f7e980b29 Redirect xasprintf to grub_xvasprintf rather than having #ifdef's
for vasprintf presence.
2013-05-10 20:57:32 +02:00
Vladimir 'phcoder' Serbinenko a6393224c4 Make 'make check' work on emu. 2013-04-27 02:00:16 +02:00
Vladimir 'phcoder' Serbinenko dfdffd0d94 * include/grub/emu/misc.h (grub_util_warn): Add missing format
attribute.
	(grub_util_info): Likewise.
	(grub_util_error): Likewise.
2012-02-10 14:15:14 +01:00
Vladimir 'phcoder' Serbinenko cf5f7ee788 Support install on multi-device filesystems.
* include/grub/emu/getroot.h (grub_guess_root_device): Renamed to ...
	(grub_guess_root_devices): ...this. Return char **. All users updated.
	* include/grub/emu/misc.h (grub_find_root_device_from_mountinfo):
	Removed.
	* util/getroot.c (find_root_device_from_libzfs): Moved pool logic to ...
	(find_root_devices_from_poolname): ... here.
	(grub_find_root_devices_from_mountinfo): Return char **. Make static.
	Support zfs-fuse.
	(grub_guess_root_device): Rename to ...
	(grub_guess_root_devices): ... this. Return char **. All users updated.
	* util/grub-install.in: Handle multi-device filesystems.
	* util/grub-probe.c (probe). Make device_names a char **. Add delim
	argument. All users updated.
	Handle multi-device filesystems.
	Use 'delim' as separator.
	Remove device check to allow filesystems on file.
	(main): Support -0 argument. Handle multi-device.
	* util/grub-setup.c (setup): Remove root argument. Handle multi-device.
	Fix a cross-device check while on it.
	(arguments): Remove root_dev.
	(argp_parser): Remove -r.
	(main): Remove root_dev.
2012-02-03 10:35:28 +01:00
Vladimir 'phcoder' Serbinenko 0d51ee20ee * include/grub/emu/misc.h (xasprintf): Add missing format attribute.
* include/grub/mips/kernel.h (grub_halt): Remove redundant declaration.
	* include/grub/mips/qemu_mips/kernel.h (grub_halt): Likewise.
	* include/grub/misc.h (grub_reboot)
	[GRUB_MACHINE_EMU || GRUB_MACHINE_QEMU_MIPS]: Export.
	(grub_halt) [__mips__]: Likewise.
2011-12-13 14:51:41 +01:00
Vladimir 'phcoder' Serbinenko 544c24876e Move grub_reboot out of the kernel.
* grub-core/Makefile.core.def (reboot): Add platform-specific files.
	* grub-core/kern/efi/efi.c (grub_reboot): Moved to ...
	* grub-core/lib/efi/reboot.c: ... here.
	* grub-core/kern/i386/efi/startup.S: Remove including of realmode.S.
	* grub-core/kern/i386/ieee1275/startup.S: Likewise.
	* grub-core/kern/i386/pc/startup.S (grub_exit): Inline cold_reboot.
	* grub-core/kern/i386/realmode.S (grub_reboot): Moved to...
	* grub-core/lib/i386/reboot_trampoline.S: ... here.
	* grub-core/kern/ieee1275/openfw.c (grub_reboot): Moved to...
	* grub-core/lib/ieee1275/reboot.c: ... here.
	* grub-core/kern/mips/arc/init.c (grub_reboot): Moved to...
	* grub-core/lib/mips/arc/reboot.c: ... here.
	* grub-core/kern/mips/loongson/init.c (grub_reboot): Moved to...
	* grub-core/lib/mips/loongson/reboot.c: ...here.
	* grub-core/kern/mips/qemu_mips/init.c (grub_reboot): Moved to...
	* grub-core/lib/mips/qemu_mips/reboot.c: ... here.
	* include/grub/emu/misc.h (grub_reboot): New function declaration.
	* include/grub/i386/reboot.h: New file.
	* include/grub/mips/loongson/ec.h: Fix includes.
	* include/grub/mips/qemu_mips/kernel.h (grub_reboot): Removed.
	* include/grub/misc.h (grub_reboot): Don't mark as kernel function.
	* grub-core/lib/i386/reboot.c: New file.
2011-10-19 16:53:18 +02:00
Vladimir Serbinenko a2491e235c Improve devmapper support
* grub-core/kern/emu/getroot.c (grub_util_is_dmraid): Removed.
	(grub_util_is_lvm): New function.
	(grub_util_get_dev_abstraction): Assume dmraid if not lvm rather
	than lvm if not dmraid.
	Handle mapped md nodes.
	* grub-core/kern/emu/hostdisk.c (device_is_mapped): Rename to ...
	(grub_util_device_is_mapped): ... this. Make always available. All users
	updated.
	(grub_util_get_dm_node_linear_info) [HAVE_DEVICE_MAPPER]: New function.
	(convert_system_partition_to_system_disk): Handle lvm, mpath and
	dmraid nodes.
	* include/grub/emu/misc.h (grub_util_device_is_mapped): New proto.

	Also-By: Colin Watson <cjwatson@ubuntu.com>
2011-05-18 09:35:47 +02:00
Vladimir 'phcoder' Serbinenko 4b07826647 partitioned mdraid support (untested) 2011-01-08 16:33:49 +01:00
Vladimir 'phcoder' Serbinenko 228cfb40bf support bind and subvolume mount 2010-12-02 14:26:46 +01:00
Vladimir 'phcoder' Serbinenko 4a1a0153c3 * include/grub/emu/misc.h: Don't include grub/util/libzfs.h.
* include/grub/emu/misc.h (grub_get_libzfs_handle): Move from here ...
	* include/grub/util/libzfs.h (grub_get_libzfs_handle): ... here.
2010-11-06 23:52:56 +01:00
Yves Blusseau a4c1d277c1 Keep boot and grub directory names in sync with utils scripts
* configure.ac: Define GRUB_BOOT_DIR_NAME and GRUB_DIR_NAME macros.
    * config.h.in: Add previous macros.
    * include/grub/emu/misc.h (DEFAULT_DIRECTORY): Use previous macros.
    * util/grub-install.in: Use $bootdir and $grubdir variables.
2010-09-21 11:42:30 +02:00
Vladimir 'phcoder' Serbinenko 742f9232e3 Split config.h for util and core.
* acinclude.m4 (HAVE_ASM_USCORE): Transformed into a variable.
	(ADDR32): Likewise.
	(DATA32): Likewise.
	(BSS_START_SYMBOL): Likewise.
	(END_SYMBOL): Likewise.
	(NEED_ENABLE_EXECUTE_STACK): Likewise. All users updated.
	(grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK): Removed.
	* config.h.in: New file.
	* configure.ac: Use config-util.h as config define file.
	Rename MACHINE into GRUB_MACHINE. All users updated.
	(NEED_REGISTER_FRAME_INFO): Transformed into a variable. All users
	updated.
	(NESTED_FUNC_ATTR): Likewise.
	Substitue new variables.
	(COND_HAVE_ASM_USCORE): New conditional.
	* grub-core/Makefile.am (ASM_PREFIX): New variable.
	(kernel_syms.lst): Use ASM_PREFIX.
	* grub-core/kern/emu/console.c: Include config-util.h.
	* grub-core/kern/emu/misc.c: Likewise.
	* grub-core/kern/emu/mm.c: Likewise.
	* include/grub/emu/misc.h: Likewise.
	* include/grub/libgcc.h: Likewise.
2010-09-19 22:22:43 +02:00
Vladimir 'phcoder' Serbinenko 050abaeaa8 Fix emu on mipsel.
* conf/Makefile.common (CFLAGS_PLATFORM): Add -mflush-func
	=grub_cpu_flush_cache on all mips and not only yeeloong.
	* configure.ac (COND_mips): New conditional.
	* grub-core/Makefile.am (KERNEL_HEADER_FILES): Add libgcc on all
	platforms.
	* grub-core/kern/emu/cache.S (__mips__): Use _flush_cache.
	* grub-core/kern/emu/full.c (grub_arch_dl_init_linker)
	[GRUB_LINKER_HAVE_INIT]: New function.
	(grub_emu_post_init): Likewise.
	* grub-core/kern/emu/lite.c (grub_emu_post_init): Likewise.
	* grub-core/kern/emu/main.c: Use grub_emu_post_init.
	* include/grub/cache.h (_mips): Include mips/cache.h.
	* include/grub/disk.h [GRUB_UTIL || GRUB_MACHINE_EMU]: Add missing
	LVM and RAID prototypes.
	* include/grub/emu/misc.h (grub_emu_post_init): New proto.
	* include/grub/mips/time.h (grub_cpu_idle) [GRUB_MACHINE_EMU]: New
	function.
2010-09-11 16:58:06 +02:00
BVK Chaitanya 2be24791dd merge with mainline 2010-08-21 00:49:29 +05:30
Robert Millan 0de22aa997 2010-08-04 Robert Millan <rmh@gnu.org>
* include/grub/emu/misc.h (grub_find_mount_point_from_dir)
	(grub_find_zpool_from_mount_point): Merge into ...
	(grub_find_zpool_from_dir): ... this.
	* kern/emu/misc.c: Likewise.
	
	* kern/emu/misc.c
	(grub_make_system_path_relative_to_its_root): Replace
	grub_find_mount_point_from_dir() / grub_find_zpool_from_mount_point()
	with grub_find_zpool_from_dir().
	* kern/emu/getroot.c (find_root_device_from_libzfs): Likewise.
2010-08-04 13:29:13 +02:00
Robert Millan 9dd6fd50b4 2010-08-03 Robert Millan <rmh@gnu.org>
Fix grub-emu build.
	
	* include/grub/util/misc.h: Move `<grub/util/libzfs.h>' to ...
	* include/grub/emu/misc.h: ... here.
	
	* include/grub/util/misc.h (grub_get_libzfs_handle): Move function ...
	* include/grub/emu/misc.h (grub_get_libzfs_handle): ... here.
	
	* util/misc.c: Remove `<grub/util/libzfs.h>'.
	[HAVE_LIBZFS] (libzfs_handle, fini_libzfs)
	(grub_get_libzfs_handle): Move to ...
	* kern/emu/misc.c [HAVE_LIBZFS] (__libzfs_handle, fini_libzfs)
	(grub_get_libzfs_handle): ... here.
2010-08-03 23:51:48 +02:00
Robert Millan c882acc031 2010-08-01 Robert Millan <rmh@gnu.org>
* include/grub/emu/misc.h (grub_find_mount_point_from_dir)
	(grub_find_zpool_from_mount_point): New function prototypes.
	
	* kern/emu/getroot.c [HAVE_GETFSSTAT]: Move `<sys/mount.h>' to ...
	* kern/emu/misc.c [HAVE_GETFSSTAT]: ... here.
	
	* kern/emu/getroot.c (find_mount_point_from_dir): Move to ...
	* kern/emu/misc.c (grub_find_mount_point_from_dir): ... this.  Remove
	`static' attribute.
	
	* kern/emu/getroot.c (find_root_device_from_libzfs): Split code for
	finding zpool from mount point into ...
	* kern/emu/misc.c (grub_find_zpool_from_mount_point): ... this.
	
	* kern/emu/misc.c (grub_make_system_path_relative_to_its_root): When
	requested path is part of a ZFS pool, use
	grub_find_zpool_from_mount_point() to detect its filesystem name,
	and generate a path with `/fsname@path' syntax.
2010-08-01 22:59:02 +02:00
Robert Millan c9a00aeeaa 2010-07-30 Robert Millan <rmh@gnu.org>
* include/grub/emu/misc.h: Add missing license header.
2010-07-30 22:01:10 +02:00
Robert Millan f7790cdd5d 2010-07-30 Robert Millan <rmh@gnu.org>
* include/grub/emu/misc.h (grub_make_system_path_relative_to_its_root)
	(xmalloc, xrealloc, xstrdup, xasprintf): Add
	`warn_unused_result' attribute.
	* include/grub/misc.h (grub_strdup, grub_strndup, grub_strlen)
	(grub_xasprintf, grub_xvasprintf): Likewise.
	* include/grub/emu/misc.h (xasprintf): Remove duplicate prototype.
2010-07-30 11:27:02 +02:00
BVK Chaitanya e57a453ad1 merge with mainline 2010-07-11 17:55:26 +05:30
Colin Watson e0f4c43882 * kern/emu/misc.c (device_mapper_null_log): New function.
(grub_device_mapper_supported): New function.
* include/grub/emu/misc.h (grub_device_mapper_supported): Add
prototype.
* kern/emu/hostdisk.c (find_partition_start): Check whether
device-mapper is supported before trying to use it.
* util/deviceiter.c (grub_util_iterate_devices): Likewise.
2010-06-07 22:41:55 +01:00
BVK Chaitanya 6d6f139349 review fixes 2010-06-02 14:45:07 +05:30
BVK Chaitanya e508977630 review fixes 2010-06-02 13:51:05 +05:30
BVK Chaitanya 13d7b4b0de merge with mainline 2010-06-02 09:12:52 +05:30
BVK Chaitanya fa4b84900a Fix grub-emu issues on NetBSD, with gcc 4.1.3.
* conf/any-emu.rmk: Remove unnecessary COMMON_CFLAGS.
	* include/grub/emu/misc.h (canonicalize_file_name): New Prototype.
	* kern/misc.c (__enable_execute_stack): Disable on
	GRUB_MACHINE_EMU.
2010-05-28 19:18:45 +05:30
BVK Chaitanya 066e9dd87e pull-in emu-fixes branch 2010-05-26 09:58:23 +05:30
BVK Chaitanya 5f02926bbc emu build fixes for sparc64 and freebsd 2010-05-26 09:56:59 +05:30
BVK Chaitanya 1828cb6098 merge with emu-reorg 2010-05-06 13:06:51 +05:30
BVK Chaitanya da6e6f17f3 cygwin emu build fixes 2010-05-06 08:45:39 +05:30
BVK Chaitanya 725396942e replace --enable-grub-emu-modules with grub-emu-lite 2010-05-04 09:47:48 +05:30
BVK Chaitanya 81827e248c merge with mainline 2010-05-04 09:09:03 +05:30
BVK Chaitanya f07ccea799 removed some duplicate code 2010-04-27 20:55:12 +05:30
BVK Chaitanya 840b61d8f0 reorganized grub-emu sources to suite upcoming automake build system 2010-04-27 10:50:28 +05:30