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
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)
|
||||
p = memalign (align, size);
|
||||
#else
|
||||
(void) align;
|
||||
(void) size;
|
||||
grub_util_error ("grub_memalign is not supported");
|
||||
#endif
|
||||
|
||||
|
@ -313,3 +315,82 @@ grub_arch_sync_caches (void *address __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
Add a link
Reference in a new issue