* grub-core/tests/video_checksum.c: Use grub_util_fd_* rather than
open/read/write.
This commit is contained in:
parent
69ca587652
commit
25ac643a54
11 changed files with 67 additions and 42 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2013-10-15 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* grub-core/tests/video_checksum.c: Use grub_util_fd_* rather than
|
||||||
|
open/read/write.
|
||||||
|
|
||||||
2013-10-14 Vladimir Serbinenko <phcoder@gmail.com>
|
2013-10-14 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* grub-core/osdep/windows/emuconsole.c: New file.
|
* grub-core/osdep/windows/emuconsole.c: New file.
|
||||||
|
|
|
@ -60,6 +60,6 @@
|
||||||
|
|
||||||
#define RE_ENABLE_I18N 1
|
#define RE_ENABLE_I18N 1
|
||||||
|
|
||||||
#define __USE_GNU 1
|
#define _GNU_SOURCE 1
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -218,6 +218,7 @@ if COND_emu
|
||||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h
|
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/misc.h
|
||||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/export.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
|
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
|
||||||
if COND_GRUB_EMU_SDL
|
if COND_GRUB_EMU_SDL
|
||||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h
|
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h
|
||||||
|
|
|
@ -80,11 +80,11 @@ grub_util_fd_open (const char *os_dev, int flags)
|
||||||
flags |= O_BINARY;
|
flags |= O_BINARY;
|
||||||
#endif
|
#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 we can't have exclusive access, try shared access */
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
ret = open (os_dev, flags | O_SHLOCK);
|
ret = open (os_dev, flags | O_SHLOCK, S_IRUSR | S_IWUSR);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ grub_util_fd_open (const char *dev, int flg)
|
||||||
if (dev[0] != '/' || dev[1] != '/' || dev[2] != ':')
|
if (dev[0] != '/' || dev[1] != '/' || dev[2] != ':')
|
||||||
{
|
{
|
||||||
ret->type = GRUB_UTIL_FD_FILE;
|
ret->type = GRUB_UTIL_FD_FILE;
|
||||||
ret->fd = open (dev, flg);
|
ret->fd = open (dev, flg, S_IRUSR | S_IWUSR);
|
||||||
if (ret->fd < 0)
|
if (ret->fd < 0)
|
||||||
{
|
{
|
||||||
free (ret);
|
free (ret);
|
||||||
|
|
|
@ -90,7 +90,7 @@ grub_util_fd_open (const char *os_dev, int flags)
|
||||||
flags |= O_BINARY;
|
flags |= O_BINARY;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = open (os_dev, flags);
|
ret = open (os_dev, flags, S_IRUSR | S_IWUSR);
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
configure_device_driver (fd);
|
configure_device_driver (fd);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -106,7 +106,7 @@ grub_util_fd_open (const char *os_dev, int flags)
|
||||||
return GRUB_UTIL_FD_INVALID;
|
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 defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
if (! (sysctl_oldflags & 0x10)
|
if (! (sysctl_oldflags & 0x10)
|
||||||
|
|
|
@ -173,7 +173,7 @@ grub_util_fd_open (const char *os_dev, int flags)
|
||||||
flags |= O_BINARY;
|
flags |= O_BINARY;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return open (os_dev, flags);
|
return open (os_dev, flags, S_IRUSR | S_IWUSR);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,19 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* All tests need to include test.h for GRUB testing framework. */
|
/* All tests need to include test.h for GRUB testing framework. */
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
#include <grub/test.h>
|
#include <grub/test.h>
|
||||||
#include <grub/dl.h>
|
#include <grub/dl.h>
|
||||||
#include <grub/video.h>
|
#include <grub/video.h>
|
||||||
#include <grub/lib/crc.h>
|
#include <grub/lib/crc.h>
|
||||||
#include <grub/mm.h>
|
#include <grub/mm.h>
|
||||||
#include <grub/term.h>
|
#include <grub/term.h>
|
||||||
|
#ifdef GRUB_MACHINE_EMU
|
||||||
|
#include <grub/emu/hostdisk.h>
|
||||||
|
#include <grub/emu/misc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
GRUB_MOD_LICENSE ("GPLv3+");
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
|
@ -239,13 +246,11 @@ struct grub_video_mode_info grub_test_video_modes[30] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef GRUB_MACHINE_EMU
|
#ifdef GRUB_MACHINE_EMU
|
||||||
#include <grub/emu/misc.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
struct bmp_header
|
struct bmp_header
|
||||||
|
@ -266,13 +271,13 @@ grub_video_capture_write_bmp (const char *fname,
|
||||||
void *ptr,
|
void *ptr,
|
||||||
const struct grub_video_mode_info *mode_info)
|
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;
|
struct bmp_header head;
|
||||||
|
|
||||||
if (fd < 0)
|
if (!GRUB_UTIL_FD_IS_VALID (fd))
|
||||||
{
|
{
|
||||||
grub_printf (_("cannot open `%s': %s"),
|
grub_printf (_("cannot open `%s': %s"),
|
||||||
fname, strerror (errno));
|
fname, grub_util_fd_strerror ());
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_memset (&head, 0, sizeof (head));
|
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.width = grub_cpu_to_le16 (mode_info->width);
|
||||||
head.height = grub_cpu_to_le16 (mode_info->height);
|
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))
|
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;
|
g = palette_data[i].g;
|
||||||
b = palette_data[i].b;
|
b = palette_data[i].b;
|
||||||
|
|
||||||
write (fd, &b, 1);
|
grub_util_fd_write (fd, (char *) &b, 1);
|
||||||
write (fd, &g, 1);
|
grub_util_fd_write (fd, (char *) &g, 1);
|
||||||
write (fd, &r, 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 >> gshift) & gmask) << mulgshift;
|
||||||
*optr++ = ((val >> rshift) & rmask) << mulrshift;
|
*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);
|
grub_free (buffer);
|
||||||
break;
|
break;
|
||||||
|
@ -395,7 +400,7 @@ grub_video_capture_write_bmp (const char *fname,
|
||||||
*optr++ = ((val >> gshift) & gmask) << mulgshift;
|
*optr++ = ((val >> gshift) & gmask) << mulgshift;
|
||||||
*optr++ = ((val >> rshift) & rmask) << mulrshift;
|
*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);
|
grub_free (buffer);
|
||||||
break;
|
break;
|
||||||
|
@ -426,7 +431,7 @@ grub_video_capture_write_bmp (const char *fname,
|
||||||
*optr++ = ((val >> gshift) & gmask) << mulgshift;
|
*optr++ = ((val >> gshift) & gmask) << mulgshift;
|
||||||
*optr++ = ((val >> rshift) & rmask) << mulrshift;
|
*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);
|
grub_free (buffer);
|
||||||
break;
|
break;
|
||||||
|
@ -436,11 +441,12 @@ grub_video_capture_write_bmp (const char *fname,
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
for (y = mode_info->height - 1; y >= 0; 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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close (fd);
|
grub_util_fd_close (fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -474,7 +480,7 @@ grub_video_checksum_get_modename (void)
|
||||||
//#define COLLECT_TIME_STATISTICS 1
|
//#define COLLECT_TIME_STATISTICS 1
|
||||||
|
|
||||||
#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
||||||
int genfd = -1;
|
grub_util_fd_t genfd = GRUB_UTIL_FD_INVALID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <grub/time.h>
|
#include <grub/time.h>
|
||||||
|
@ -491,10 +497,11 @@ write_time (void)
|
||||||
char buf[60];
|
char buf[60];
|
||||||
static grub_uint64_t prev;
|
static grub_uint64_t prev;
|
||||||
grub_uint64_t cur;
|
grub_uint64_t cur;
|
||||||
static int tmrfd = -1;
|
static grub_util_fd_t tmrfd = GRUB_UTIL_FD_INVALID;
|
||||||
struct tms tm;
|
struct tms tm;
|
||||||
if (tmrfd < 0)
|
if (!GRUB_UTIL_FD_IS_VALID (tmrfd))
|
||||||
tmrfd = open ("time.txt", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
tmrfd = grub_util_fd_open ("time.txt", GRUB_UTIL_FD_O_WRONLY
|
||||||
|
| GRUB_UTIL_FD_O_CREATTRUNC);
|
||||||
|
|
||||||
times (&tm);
|
times (&tm);
|
||||||
cur = (tm.tms_utime * 1000ULL) / sysconf(_SC_CLK_TCK);
|
cur = (tm.tms_utime * 1000ULL) / sysconf(_SC_CLK_TCK);
|
||||||
|
@ -505,8 +512,8 @@ write_time (void)
|
||||||
grub_video_checksum_get_modename (), ctr,
|
grub_video_checksum_get_modename (), ctr,
|
||||||
cur - prev);
|
cur - prev);
|
||||||
prev = cur;
|
prev = cur;
|
||||||
if (tmrfd >= 0)
|
if (GRUB_UTIL_FD_IS_VALID (tmrfd))
|
||||||
write (tmrfd, buf, grub_strlen (buf));
|
grub_util_fd_write (tmrfd, buf, grub_strlen (buf));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,11 +601,11 @@ checksum (void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
||||||
if (genfd >= 0)
|
if (GRUB_UTIL_FD_IS_VALID (genfd))
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
grub_snprintf (buf, sizeof (buf), "0x%x, ", crc);
|
grub_snprintf (buf, sizeof (buf), "0x%x, ", crc);
|
||||||
write (genfd, buf, grub_strlen (buf));
|
grub_util_fd_write (genfd, buf, grub_strlen (buf));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -675,9 +682,10 @@ grub_video_checksum (const char *basename_in)
|
||||||
grub_video_get_info (&capt_mode_info);
|
grub_video_get_info (&capt_mode_info);
|
||||||
|
|
||||||
#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
||||||
if (genfd < 0)
|
if (!GRUB_UTIL_FD_IS_VALID (genfd))
|
||||||
genfd = open ("checksums.h", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
genfd = grub_util_fd_open ("checksums.h", GRUB_UTIL_FD_O_WRONLY
|
||||||
if (genfd >= 0)
|
| GRUB_UTIL_FD_O_CREATTRUNC);
|
||||||
|
if (GRUB_UTIL_FD_IS_VALID (genfd))
|
||||||
{
|
{
|
||||||
char buf[400];
|
char buf[400];
|
||||||
|
|
||||||
|
@ -700,9 +708,9 @@ grub_video_checksum (const char *basename_in)
|
||||||
capt_mode_info.height,
|
capt_mode_info.height,
|
||||||
grub_video_checksum_get_modename ());
|
grub_video_checksum_get_modename ());
|
||||||
|
|
||||||
write (genfd, " { \"", 5);
|
grub_util_fd_write (genfd, " { \"", 5);
|
||||||
write (genfd, basename_in, grub_strlen (basename_in));
|
grub_util_fd_write (genfd, basename_in, grub_strlen (basename_in));
|
||||||
write (genfd, buf, grub_strlen (buf));
|
grub_util_fd_write (genfd, buf, grub_strlen (buf));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -740,11 +748,11 @@ void
|
||||||
grub_video_checksum_end (void)
|
grub_video_checksum_end (void)
|
||||||
{
|
{
|
||||||
#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
#if defined (GENERATE_MODE) && defined (GRUB_MACHINE_EMU)
|
||||||
if (genfd >= 0)
|
if (GRUB_UTIL_FD_IS_VALID (genfd))
|
||||||
{
|
{
|
||||||
char buf[40];
|
char buf[40];
|
||||||
grub_snprintf (buf, sizeof (buf), "}, %d },\n", ctr);
|
grub_snprintf (buf, sizeof (buf), "}, %d },\n", ctr);
|
||||||
write (genfd, buf, grub_strlen (buf));
|
grub_util_fd_write (genfd, buf, grub_strlen (buf));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
grub_test_assert (ctr == nchk, "Not enough checksums %s_%dx%dx%s: %d vs %d",
|
grub_test_assert (ctr == nchk, "Not enough checksums %s_%dx%dx%s: %d vs %d",
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#ifdef GRUB_SYMBOL_GENERATOR
|
||||||
void EXPORT_FUNC (open64) (void);
|
void EXPORT_FUNC (open64) (void);
|
||||||
void EXPORT_FUNC (close) (void);
|
void EXPORT_FUNC (close) (void);
|
||||||
void EXPORT_FUNC (read) (void);
|
void EXPORT_FUNC (read) (void);
|
||||||
|
@ -7,3 +8,13 @@ void EXPORT_FUNC (__errno_location) (void);
|
||||||
void EXPORT_FUNC (strerror) (void);
|
void EXPORT_FUNC (strerror) (void);
|
||||||
void EXPORT_FUNC (sysconf) (void);
|
void EXPORT_FUNC (sysconf) (void);
|
||||||
void EXPORT_FUNC (times) (void);
|
void EXPORT_FUNC (times) (void);
|
||||||
|
#else
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/times.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
|
|
|
@ -26,13 +26,13 @@
|
||||||
#include <grub/osdep/hostfile.h>
|
#include <grub/osdep/hostfile.h>
|
||||||
|
|
||||||
grub_util_fd_t
|
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 *
|
const char *
|
||||||
grub_util_fd_strerror (void);
|
EXPORT_FUNC(grub_util_fd_strerror) (void);
|
||||||
void
|
void
|
||||||
grub_util_fd_sync (grub_util_fd_t fd);
|
grub_util_fd_sync (grub_util_fd_t fd);
|
||||||
void
|
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_t
|
||||||
grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags,
|
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);
|
grub_err_t grub_util_biosdisk_flush (struct grub_disk *disk);
|
||||||
int
|
int
|
||||||
grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t offset);
|
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 EXPORT_FUNC(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_write) (grub_util_fd_t fd, const char *buf, size_t len);
|
||||||
grub_err_t
|
grub_err_t
|
||||||
grub_cryptodisk_cheat_mount (const char *sourcedev, const char *cheat);
|
grub_cryptodisk_cheat_mount (const char *sourcedev, const char *cheat);
|
||||||
const char *
|
const char *
|
||||||
|
|
Loading…
Reference in a new issue