From 25ac643a5464c38b6d0bb903b90dd6b87b0c2143 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 15 Oct 2013 11:06:57 +0200 Subject: [PATCH] * grub-core/tests/video_checksum.c: Use grub_util_fd_* rather than open/read/write. --- ChangeLog | 5 +++ config.h.in | 2 +- grub-core/Makefile.am | 1 + grub-core/osdep/apple/hostdisk.c | 4 +- grub-core/osdep/aros/hostdisk.c | 2 +- grub-core/osdep/bsd/hostdisk.c | 2 +- grub-core/osdep/freebsd/hostdisk.c | 2 +- grub-core/osdep/unix/hostdisk.c | 2 +- grub-core/tests/video_checksum.c | 68 +++++++++++++++++------------- include/grub/emu/export.h | 11 +++++ include/grub/emu/hostdisk.h | 10 ++--- 11 files changed, 67 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9852f06e3..75331f9f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-10-15 Vladimir Serbinenko + + * grub-core/tests/video_checksum.c: Use grub_util_fd_* rather than + open/read/write. + 2013-10-14 Vladimir Serbinenko * grub-core/osdep/windows/emuconsole.c: New file. diff --git a/config.h.in b/config.h.in index 3d2fd6778..efc9c4ca0 100644 --- a/config.h.in +++ b/config.h.in @@ -60,6 +60,6 @@ #define RE_ENABLE_I18N 1 -#define __USE_GNU 1 +#define _GNU_SOURCE 1 #endif diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 86f335f0f..d9ec7ca31 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -218,6 +218,7 @@ if COND_emu KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/export.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostdisk.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h if COND_GRUB_EMU_SDL KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h diff --git a/grub-core/osdep/apple/hostdisk.c b/grub-core/osdep/apple/hostdisk.c index c9df43e4f..5006a57d5 100644 --- a/grub-core/osdep/apple/hostdisk.c +++ b/grub-core/osdep/apple/hostdisk.c @@ -80,11 +80,11 @@ grub_util_fd_open (const char *os_dev, int flags) flags |= O_BINARY; #endif - ret = open (os_dev, flags); + ret = open (os_dev, flags, S_IRUSR | S_IWUSR); /* If we can't have exclusive access, try shared access */ if (ret < 0) - ret = open (os_dev, flags | O_SHLOCK); + ret = open (os_dev, flags | O_SHLOCK, S_IRUSR | S_IWUSR); return ret; } diff --git a/grub-core/osdep/aros/hostdisk.c b/grub-core/osdep/aros/hostdisk.c index a9fa9d06b..c42264b9f 100644 --- a/grub-core/osdep/aros/hostdisk.c +++ b/grub-core/osdep/aros/hostdisk.c @@ -179,7 +179,7 @@ grub_util_fd_open (const char *dev, int flg) if (dev[0] != '/' || dev[1] != '/' || dev[2] != ':') { ret->type = GRUB_UTIL_FD_FILE; - ret->fd = open (dev, flg); + ret->fd = open (dev, flg, S_IRUSR | S_IWUSR); if (ret->fd < 0) { free (ret); diff --git a/grub-core/osdep/bsd/hostdisk.c b/grub-core/osdep/bsd/hostdisk.c index dc845b11f..0e32b9822 100644 --- a/grub-core/osdep/bsd/hostdisk.c +++ b/grub-core/osdep/bsd/hostdisk.c @@ -90,7 +90,7 @@ grub_util_fd_open (const char *os_dev, int flags) flags |= O_BINARY; #endif - ret = open (os_dev, flags); + ret = open (os_dev, flags, S_IRUSR | S_IWUSR); if (ret >= 0) configure_device_driver (fd); return ret; diff --git a/grub-core/osdep/freebsd/hostdisk.c b/grub-core/osdep/freebsd/hostdisk.c index bf864b0e4..944e4be02 100644 --- a/grub-core/osdep/freebsd/hostdisk.c +++ b/grub-core/osdep/freebsd/hostdisk.c @@ -106,7 +106,7 @@ grub_util_fd_open (const char *os_dev, int flags) return GRUB_UTIL_FD_INVALID; } - ret = open (os_dev, flags); + ret = open (os_dev, flags, S_IRUSR | S_IWUSR); #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) if (! (sysctl_oldflags & 0x10) diff --git a/grub-core/osdep/unix/hostdisk.c b/grub-core/osdep/unix/hostdisk.c index b222629d2..3ef379742 100644 --- a/grub-core/osdep/unix/hostdisk.c +++ b/grub-core/osdep/unix/hostdisk.c @@ -173,7 +173,7 @@ grub_util_fd_open (const char *os_dev, int flags) flags |= O_BINARY; #endif - return open (os_dev, flags); + return open (os_dev, flags, S_IRUSR | S_IWUSR); } #endif diff --git a/grub-core/tests/video_checksum.c b/grub-core/tests/video_checksum.c index d898529cd..33b32c051 100644 --- a/grub-core/tests/video_checksum.c +++ b/grub-core/tests/video_checksum.c @@ -17,12 +17,19 @@ */ /* All tests need to include test.h for GRUB testing framework. */ + +#include + #include #include #include #include #include #include +#ifdef GRUB_MACHINE_EMU +#include +#include +#endif GRUB_MOD_LICENSE ("GPLv3+"); @@ -239,13 +246,11 @@ struct grub_video_mode_info grub_test_video_modes[30] = { }; #ifdef GRUB_MACHINE_EMU -#include #include #include #include #include #include -#include #include struct bmp_header @@ -266,13 +271,13 @@ grub_video_capture_write_bmp (const char *fname, void *ptr, const struct grub_video_mode_info *mode_info) { - int fd = open (fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + grub_util_fd_t fd = grub_util_fd_open (fname, O_WRONLY | O_CREAT | O_TRUNC); struct bmp_header head; - if (fd < 0) + if (!GRUB_UTIL_FD_IS_VALID (fd)) { grub_printf (_("cannot open `%s': %s"), - fname, strerror (errno)); + fname, grub_util_fd_strerror ()); } grub_memset (&head, 0, sizeof (head)); @@ -300,7 +305,7 @@ grub_video_capture_write_bmp (const char *fname, head.width = grub_cpu_to_le16 (mode_info->width); head.height = grub_cpu_to_le16 (mode_info->height); - write (fd, &head, sizeof (head)); + grub_util_fd_write (fd, (char *) &head, sizeof (head)); if (!(mode_info->mode_type & GRUB_VIDEO_MODE_TYPE_RGB)) { @@ -318,9 +323,9 @@ grub_video_capture_write_bmp (const char *fname, g = palette_data[i].g; b = palette_data[i].b; - write (fd, &b, 1); - write (fd, &g, 1); - write (fd, &r, 1); + grub_util_fd_write (fd, (char *) &b, 1); + grub_util_fd_write (fd, (char *) &g, 1); + grub_util_fd_write (fd, (char *) &r, 1); } } @@ -355,7 +360,7 @@ grub_video_capture_write_bmp (const char *fname, *optr++ = ((val >> gshift) & gmask) << mulgshift; *optr++ = ((val >> rshift) & rmask) << mulrshift; } - write (fd, buffer, mode_info->width * 3); + grub_util_fd_write (fd, (char *) buffer, mode_info->width * 3); } grub_free (buffer); break; @@ -395,7 +400,7 @@ grub_video_capture_write_bmp (const char *fname, *optr++ = ((val >> gshift) & gmask) << mulgshift; *optr++ = ((val >> rshift) & rmask) << mulrshift; } - write (fd, buffer, mode_info->width * 3); + grub_util_fd_write (fd, (char *) buffer, mode_info->width * 3); } grub_free (buffer); break; @@ -426,7 +431,7 @@ grub_video_capture_write_bmp (const char *fname, *optr++ = ((val >> gshift) & gmask) << mulgshift; *optr++ = ((val >> rshift) & rmask) << mulrshift; } - write (fd, buffer, mode_info->width * 3); + grub_util_fd_write (fd, (char *) buffer, mode_info->width * 3); } grub_free (buffer); break; @@ -436,11 +441,12 @@ grub_video_capture_write_bmp (const char *fname, int y; for (y = mode_info->height - 1; y >= 0; y--) - write (fd, ((grub_uint8_t *) ptr + mode_info->pitch * y), mode_info->width); + grub_util_fd_write (fd, ((char *) ptr + mode_info->pitch * y), + mode_info->width); break; } } - close (fd); + grub_util_fd_close (fd); } #endif @@ -474,7 +480,7 @@ grub_video_checksum_get_modename (void) //#define COLLECT_TIME_STATISTICS 1 #if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU) -int genfd = -1; +grub_util_fd_t genfd = GRUB_UTIL_FD_INVALID; #endif #include @@ -491,10 +497,11 @@ write_time (void) char buf[60]; static grub_uint64_t prev; grub_uint64_t cur; - static int tmrfd = -1; + static grub_util_fd_t tmrfd = GRUB_UTIL_FD_INVALID; struct tms tm; - if (tmrfd < 0) - tmrfd = open ("time.txt", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + if (!GRUB_UTIL_FD_IS_VALID (tmrfd)) + tmrfd = grub_util_fd_open ("time.txt", GRUB_UTIL_FD_O_WRONLY + | GRUB_UTIL_FD_O_CREATTRUNC); times (&tm); cur = (tm.tms_utime * 1000ULL) / sysconf(_SC_CLK_TCK); @@ -505,8 +512,8 @@ write_time (void) grub_video_checksum_get_modename (), ctr, cur - prev); prev = cur; - if (tmrfd >= 0) - write (tmrfd, buf, grub_strlen (buf)); + if (GRUB_UTIL_FD_IS_VALID (tmrfd)) + grub_util_fd_write (tmrfd, buf, grub_strlen (buf)); #endif } @@ -594,11 +601,11 @@ checksum (void) #endif #if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU) - if (genfd >= 0) + if (GRUB_UTIL_FD_IS_VALID (genfd)) { char buf[20]; grub_snprintf (buf, sizeof (buf), "0x%x, ", crc); - write (genfd, buf, grub_strlen (buf)); + grub_util_fd_write (genfd, buf, grub_strlen (buf)); } #endif @@ -675,9 +682,10 @@ grub_video_checksum (const char *basename_in) grub_video_get_info (&capt_mode_info); #if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU) - if (genfd < 0) - genfd = open ("checksums.h", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - if (genfd >= 0) + if (!GRUB_UTIL_FD_IS_VALID (genfd)) + genfd = grub_util_fd_open ("checksums.h", GRUB_UTIL_FD_O_WRONLY + | GRUB_UTIL_FD_O_CREATTRUNC); + if (GRUB_UTIL_FD_IS_VALID (genfd)) { char buf[400]; @@ -700,9 +708,9 @@ grub_video_checksum (const char *basename_in) capt_mode_info.height, grub_video_checksum_get_modename ()); - write (genfd, " { \"", 5); - write (genfd, basename_in, grub_strlen (basename_in)); - write (genfd, buf, grub_strlen (buf)); + grub_util_fd_write (genfd, " { \"", 5); + grub_util_fd_write (genfd, basename_in, grub_strlen (basename_in)); + grub_util_fd_write (genfd, buf, grub_strlen (buf)); } #endif @@ -740,11 +748,11 @@ void grub_video_checksum_end (void) { #if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU) - if (genfd >= 0) + if (GRUB_UTIL_FD_IS_VALID (genfd)) { char buf[40]; grub_snprintf (buf, sizeof (buf), "}, %d },\n", ctr); - write (genfd, buf, grub_strlen (buf)); + grub_util_fd_write (genfd, buf, grub_strlen (buf)); } #endif grub_test_assert (ctr == nchk, "Not enough checksums %s_%dx%dx%s: %d vs %d", diff --git a/include/grub/emu/export.h b/include/grub/emu/export.h index 4da9c4758..03fea2c91 100644 --- a/include/grub/emu/export.h +++ b/include/grub/emu/export.h @@ -1,3 +1,4 @@ +#ifdef GRUB_SYMBOL_GENERATOR void EXPORT_FUNC (open64) (void); void EXPORT_FUNC (close) (void); void EXPORT_FUNC (read) (void); @@ -7,3 +8,13 @@ void EXPORT_FUNC (__errno_location) (void); void EXPORT_FUNC (strerror) (void); void EXPORT_FUNC (sysconf) (void); void EXPORT_FUNC (times) (void); +#else +#include +#include +#include +#include +#include +#include +#include +#include +#endif diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index fd319b0d1..b15abcbca 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -26,13 +26,13 @@ #include grub_util_fd_t -grub_util_fd_open (const char *os_dev, int flags); +EXPORT_FUNC(grub_util_fd_open) (const char *os_dev, int flags); const char * -grub_util_fd_strerror (void); +EXPORT_FUNC(grub_util_fd_strerror) (void); void grub_util_fd_sync (grub_util_fd_t fd); void -grub_util_fd_close (grub_util_fd_t fd); +EXPORT_FUNC(grub_util_fd_close) (grub_util_fd_t fd); grub_util_fd_t grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags, @@ -49,8 +49,8 @@ grub_util_biosdisk_get_compatibility_hint (grub_disk_t disk); grub_err_t grub_util_biosdisk_flush (struct grub_disk *disk); int grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t offset); -ssize_t grub_util_fd_read (grub_util_fd_t fd, char *buf, size_t len); -ssize_t grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len); +ssize_t EXPORT_FUNC(grub_util_fd_read) (grub_util_fd_t fd, char *buf, size_t len); +ssize_t EXPORT_FUNC(grub_util_fd_write) (grub_util_fd_t fd, const char *buf, size_t len); grub_err_t grub_cryptodisk_cheat_mount (const char *sourcedev, const char *cheat); const char *