2008-08-29 Bean <bean123ch@gmail.com>
* configure.ac: Change host_os to cygwin for mingw. (asprintf): New check for function. * include/grub/symbol.h: Replace #ifndef __CYGWIN__ with #if ! defined (__CYGWIN__) && ! defined (__MINGW32__). * include/grub/util/misc.h: #include <config.h> and <grub/types.h>, declear asprintf if HAVE_ASPRINTF is not set, declear fseeko, ftello, sync, sleep and grub_util_get_disk_size for mingw. * util/biosdisk.c (grub_util_biosdisk_open): Use grub_util_get_disk_size to get size in mingw. (open_device): Use flag O_BINARY if it's defined. (find_root_device): Add dummy code for mingw. * util/grub-mkdevicemap.c (get_floppy_disk_name): Return 0 for mingw. (get_ide_disk_name): Return //./PHYSICALDRIVE%d for mingw. (get_scsi_disk_name): Return 0 for mingw. * util/hostfs.c: #include <grub/util/misc.h>. (grub_hostfs_open): Use "rb" flag to open file, use grub_util_get_disk_size to get disk size for mingw. * util/misc.c: #include <windows.h> and <winioctl.h> in mingw. (asprintf): New function if HAVE_ASPRINTF is not set. (sync): New function for mingw. (sleep): Likewise. (grub_util_get_disk_size): Likewise.
This commit is contained in:
parent
ab3f267329
commit
6e5a42fe9a
11 changed files with 199 additions and 6 deletions
31
ChangeLog
31
ChangeLog
|
@ -1,3 +1,34 @@
|
||||||
|
2008-08-29 Bean <bean123ch@gmail.com>
|
||||||
|
|
||||||
|
* configure.ac: Change host_os to cygwin for mingw.
|
||||||
|
(asprintf): New check for function.
|
||||||
|
|
||||||
|
* include/grub/symbol.h: Replace #ifndef __CYGWIN__ with
|
||||||
|
#if ! defined (__CYGWIN__) && ! defined (__MINGW32__).
|
||||||
|
|
||||||
|
* include/grub/util/misc.h: #include <config.h> and <grub/types.h>,
|
||||||
|
declear asprintf if HAVE_ASPRINTF is not set, declear fseeko, ftello,
|
||||||
|
sync, sleep and grub_util_get_disk_size for mingw.
|
||||||
|
|
||||||
|
* util/biosdisk.c (grub_util_biosdisk_open): Use grub_util_get_disk_size
|
||||||
|
to get size in mingw.
|
||||||
|
(open_device): Use flag O_BINARY if it's defined.
|
||||||
|
(find_root_device): Add dummy code for mingw.
|
||||||
|
|
||||||
|
* util/grub-mkdevicemap.c (get_floppy_disk_name): Return 0 for mingw.
|
||||||
|
(get_ide_disk_name): Return //./PHYSICALDRIVE%d for mingw.
|
||||||
|
(get_scsi_disk_name): Return 0 for mingw.
|
||||||
|
|
||||||
|
* util/hostfs.c: #include <grub/util/misc.h>.
|
||||||
|
(grub_hostfs_open): Use "rb" flag to open file, use
|
||||||
|
grub_util_get_disk_size to get disk size for mingw.
|
||||||
|
|
||||||
|
* util/misc.c: #include <windows.h> and <winioctl.h> in mingw.
|
||||||
|
(asprintf): New function if HAVE_ASPRINTF is not set.
|
||||||
|
(sync): New function for mingw.
|
||||||
|
(sleep): Likewise.
|
||||||
|
(grub_util_get_disk_size): Likewise.
|
||||||
|
|
||||||
2008-08-28 Pavel Roskin <proski@gnu.org>
|
2008-08-28 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
* conf/powerpc-ieee1275.rmk (kernel_elf_SOURCES): Add
|
* conf/powerpc-ieee1275.rmk (kernel_elf_SOURCES): Add
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
/* Define if C symbols get an underscore after compilation */
|
/* Define if C symbols get an underscore after compilation */
|
||||||
#undef HAVE_ASM_USCORE
|
#undef HAVE_ASM_USCORE
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `asprintf' function. */
|
||||||
|
#undef HAVE_ASPRINTF
|
||||||
|
|
||||||
/* Define to 1 if you have the <curses.h> header file. */
|
/* Define to 1 if you have the <curses.h> header file. */
|
||||||
#undef HAVE_CURSES_H
|
#undef HAVE_CURSES_H
|
||||||
|
|
||||||
|
|
11
configure
vendored
11
configure
vendored
|
@ -1993,6 +1993,14 @@ case "$target_cpu" in
|
||||||
x86_64 | sparc64) target_m64=1 ;;
|
x86_64 | sparc64) target_m64=1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
case "$host_os" in
|
||||||
|
mingw32) host_os=cygwin ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$target_os" in
|
||||||
|
mingw32) target_os=cygwin ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -5786,7 +5794,8 @@ fi
|
||||||
# Check for functions.
|
# Check for functions.
|
||||||
|
|
||||||
|
|
||||||
for ac_func in posix_memalign memalign
|
|
||||||
|
for ac_func in posix_memalign memalign asprintf
|
||||||
do
|
do
|
||||||
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||||
{ echo "$as_me:$LINENO: checking for $ac_func" >&5
|
{ echo "$as_me:$LINENO: checking for $ac_func" >&5
|
||||||
|
|
10
configure.ac
10
configure.ac
|
@ -99,6 +99,14 @@ case "$target_cpu" in
|
||||||
x86_64 | sparc64) target_m64=1 ;;
|
x86_64 | sparc64) target_m64=1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
case "$host_os" in
|
||||||
|
mingw32) host_os=cygwin ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$target_os" in
|
||||||
|
mingw32) target_os=cygwin ;;
|
||||||
|
esac
|
||||||
|
|
||||||
AC_SUBST(target_cpu)
|
AC_SUBST(target_cpu)
|
||||||
AC_SUBST(target_os)
|
AC_SUBST(target_os)
|
||||||
AC_SUBST(platform)
|
AC_SUBST(platform)
|
||||||
|
@ -183,7 +191,7 @@ if test "$target_cpu"-"$platform" = i386-pc; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for functions.
|
# Check for functions.
|
||||||
AC_CHECK_FUNCS(posix_memalign memalign)
|
AC_CHECK_FUNCS(posix_memalign memalign asprintf)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check for target programs.
|
# Check for target programs.
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
# define EXT_C(sym) sym
|
# define EXT_C(sym) sym
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __CYGWIN__
|
#if ! defined (__CYGWIN__) && ! defined (__MINGW32__)
|
||||||
#define FUNCTION(x) .globl EXT_C(x) ; .type EXT_C(x), "function" ; EXT_C(x):
|
#define FUNCTION(x) .globl EXT_C(x) ; .type EXT_C(x), "function" ; EXT_C(x):
|
||||||
#define VARIABLE(x) .globl EXT_C(x) ; .type EXT_C(x), "object" ; EXT_C(x):
|
#define VARIABLE(x) .globl EXT_C(x) ; .type EXT_C(x), "object" ; EXT_C(x):
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <grub/types.h>
|
||||||
|
|
||||||
#ifdef __NetBSD__
|
#ifdef __NetBSD__
|
||||||
/* NetBSD uses /boot for its boot block. */
|
/* NetBSD uses /boot for its boot block. */
|
||||||
# define DEFAULT_DIRECTORY "/grub"
|
# define DEFAULT_DIRECTORY "/grub"
|
||||||
|
@ -55,4 +58,22 @@ void grub_util_write_image_at (const void *img, size_t size, off_t offset,
|
||||||
FILE *out);
|
FILE *out);
|
||||||
char *grub_util_get_disk_name (int disk, char *name);
|
char *grub_util_get_disk_name (int disk, char *name);
|
||||||
|
|
||||||
|
#ifndef HAVE_ASPRINTF
|
||||||
|
|
||||||
|
int asprintf (char **buf, const char *fmt, ...);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
|
||||||
|
#define fseeko fseeko64
|
||||||
|
#define ftello ftello64
|
||||||
|
|
||||||
|
void sync (void);
|
||||||
|
void sleep(int s);
|
||||||
|
|
||||||
|
grub_int64_t grub_util_get_disk_size (char *name);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* ! GRUB_UTIL_MISC_HEADER */
|
#endif /* ! GRUB_UTIL_MISC_HEADER */
|
||||||
|
|
|
@ -163,7 +163,22 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
||||||
disk->id = drive;
|
disk->id = drive;
|
||||||
|
|
||||||
/* Get the size. */
|
/* Get the size. */
|
||||||
#if defined(__linux__) || defined(__CYGWIN__)
|
#if defined(__MINGW32__)
|
||||||
|
{
|
||||||
|
grub_uint64_t size;
|
||||||
|
|
||||||
|
size = grub_util_get_disk_size (map[drive].device);
|
||||||
|
|
||||||
|
if (size % 512)
|
||||||
|
grub_util_error ("unaligned device size");
|
||||||
|
|
||||||
|
disk->total_sectors = size >> 9;
|
||||||
|
|
||||||
|
grub_util_info ("the size of %s is %llu", name, disk->total_sectors);
|
||||||
|
|
||||||
|
return GRUB_ERR_NONE;
|
||||||
|
}
|
||||||
|
#elif defined(__linux__) || defined(__CYGWIN__)
|
||||||
{
|
{
|
||||||
unsigned long long nr;
|
unsigned long long nr;
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -281,6 +296,9 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
|
||||||
#ifdef O_FSYNC
|
#ifdef O_FSYNC
|
||||||
flags |= O_FSYNC;
|
flags |= O_FSYNC;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef O_BINARY
|
||||||
|
flags |= O_BINARY;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
/* Linux has a bug that the disk cache for a whole disk is not consistent
|
/* Linux has a bug that the disk cache for a whole disk is not consistent
|
||||||
|
|
|
@ -169,7 +169,16 @@ grub_get_prefix (const char *dir)
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __CYGWIN__
|
#ifdef __MINGW32__
|
||||||
|
|
||||||
|
static char *
|
||||||
|
find_root_device (const char *dir __attribute__ ((unused)),
|
||||||
|
dev_t dev __attribute__ ((unused)))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif ! defined(__CYGWIN__)
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
find_root_device (const char *dir, dev_t dev)
|
find_root_device (const char *dir, dev_t dev)
|
||||||
|
|
|
@ -169,6 +169,9 @@ get_floppy_disk_name (char *name, int unit)
|
||||||
#elif defined(__CYGWIN__)
|
#elif defined(__CYGWIN__)
|
||||||
/* Cygwin */
|
/* Cygwin */
|
||||||
sprintf (name, "/dev/fd%d", unit);
|
sprintf (name, "/dev/fd%d", unit);
|
||||||
|
#elif defined(__MINGW32__)
|
||||||
|
(void) unit;
|
||||||
|
*name = 0;
|
||||||
#else
|
#else
|
||||||
# warning "BIOS floppy drives cannot be guessed in your operating system."
|
# warning "BIOS floppy drives cannot be guessed in your operating system."
|
||||||
/* Set NAME to a bogus string. */
|
/* Set NAME to a bogus string. */
|
||||||
|
@ -214,6 +217,8 @@ get_ide_disk_name (char *name, int unit)
|
||||||
/* Cygwin emulates all disks as /dev/sdX. */
|
/* Cygwin emulates all disks as /dev/sdX. */
|
||||||
(void) unit;
|
(void) unit;
|
||||||
*name = 0;
|
*name = 0;
|
||||||
|
#elif defined(__MINGW32__)
|
||||||
|
sprintf (name, "//./PHYSICALDRIVE%d", unit);
|
||||||
#else
|
#else
|
||||||
# warning "BIOS IDE drives cannot be guessed in your operating system."
|
# warning "BIOS IDE drives cannot be guessed in your operating system."
|
||||||
/* Set NAME to a bogus string. */
|
/* Set NAME to a bogus string. */
|
||||||
|
@ -258,6 +263,9 @@ get_scsi_disk_name (char *name, int unit)
|
||||||
#elif defined(__CYGWIN__)
|
#elif defined(__CYGWIN__)
|
||||||
/* Cygwin emulates all disks as /dev/sdX. */
|
/* Cygwin emulates all disks as /dev/sdX. */
|
||||||
sprintf (name, "/dev/sd%c", unit + 'a');
|
sprintf (name, "/dev/sd%c", unit + 'a');
|
||||||
|
#elif defined(__MINGW32__)
|
||||||
|
(void) unit;
|
||||||
|
*name = 0;
|
||||||
#else
|
#else
|
||||||
# warning "BIOS SCSI drives cannot be guessed in your operating system."
|
# warning "BIOS SCSI drives cannot be guessed in your operating system."
|
||||||
/* Set NAME to a bogus string. */
|
/* Set NAME to a bogus string. */
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <grub/disk.h>
|
#include <grub/disk.h>
|
||||||
#include <grub/misc.h>
|
#include <grub/misc.h>
|
||||||
#include <grub/dl.h>
|
#include <grub/dl.h>
|
||||||
|
#include <grub/util/misc.h>
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -95,15 +96,19 @@ grub_hostfs_open (struct grub_file *file, const char *name)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
f = fopen (name, "r");
|
f = fopen (name, "rb");
|
||||||
if (! f)
|
if (! f)
|
||||||
return grub_error (GRUB_ERR_BAD_FILENAME,
|
return grub_error (GRUB_ERR_BAD_FILENAME,
|
||||||
"can't open `%s'", name);
|
"can't open `%s'", name);
|
||||||
file->data = f;
|
file->data = f;
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
file->size = grub_util_get_disk_size (name);
|
||||||
|
#else
|
||||||
fseeko (f, 0, SEEK_END);
|
fseeko (f, 0, SEEK_END);
|
||||||
file->size = ftello (f);
|
file->size = ftello (f);
|
||||||
fseeko (f, 0, SEEK_SET);
|
fseeko (f, 0, SEEK_SET);
|
||||||
|
#endif
|
||||||
|
|
||||||
return GRUB_ERR_NONE;
|
return GRUB_ERR_NONE;
|
||||||
}
|
}
|
||||||
|
|
81
util/misc.c
81
util/misc.c
|
@ -259,6 +259,8 @@ grub_memalign (grub_size_t align, grub_size_t size)
|
||||||
#elif defined(HAVE_MEMALIGN)
|
#elif defined(HAVE_MEMALIGN)
|
||||||
p = memalign (align, size);
|
p = memalign (align, size);
|
||||||
#else
|
#else
|
||||||
|
(void) align;
|
||||||
|
(void) size;
|
||||||
grub_util_error ("grub_memalign is not supported");
|
grub_util_error ("grub_memalign is not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -313,3 +315,82 @@ grub_arch_sync_caches (void *address __attribute__ ((unused)),
|
||||||
grub_size_t len __attribute__ ((unused)))
|
grub_size_t len __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_ASPRINTF
|
||||||
|
|
||||||
|
int
|
||||||
|
asprintf (char **buf, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
/* Should be large enough. */
|
||||||
|
*buf = xmalloc (512);
|
||||||
|
|
||||||
|
va_start (ap, fmt);
|
||||||
|
status = vsprintf (*buf, fmt, ap);
|
||||||
|
va_end (ap);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <winioctl.h>
|
||||||
|
|
||||||
|
void sync (void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void sleep (int s)
|
||||||
|
{
|
||||||
|
Sleep (s * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
grub_int64_t
|
||||||
|
grub_util_get_disk_size (char *name)
|
||||||
|
{
|
||||||
|
HANDLE hd;
|
||||||
|
grub_int64_t size = -1LL;
|
||||||
|
|
||||||
|
hd = CreateFile (name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
|
0, OPEN_EXISTING, 0, 0);
|
||||||
|
|
||||||
|
if (hd == INVALID_HANDLE_VALUE)
|
||||||
|
return size;
|
||||||
|
|
||||||
|
if (((name[0] == '/') || (name[0] == '\\')) &&
|
||||||
|
((name[1] == '/') || (name[1] == '\\')) &&
|
||||||
|
(name[2] == '.') &&
|
||||||
|
((name[3] == '/') || (name[3] == '\\')) &&
|
||||||
|
(! strncasecmp (name + 4, "PHYSICALDRIVE", 13)))
|
||||||
|
{
|
||||||
|
DWORD nr;
|
||||||
|
DISK_GEOMETRY g;
|
||||||
|
|
||||||
|
if (! DeviceIoControl (hd, IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
||||||
|
0, 0, &g, sizeof (g), &nr, 0))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
size = g.Cylinders.QuadPart;
|
||||||
|
size *= g.TracksPerCylinder * g.SectorsPerTrack * g.BytesPerSector;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LARGE_INTEGER s;
|
||||||
|
|
||||||
|
s.LowPart = GetFileSize (hd, &s.HighPart);
|
||||||
|
size = s.QuadPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
fail:
|
||||||
|
|
||||||
|
CloseHandle (hd);
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue