[1834] 2008-08-29 Bean <[email protected]>

Bean <[email protected]>
Newsgroups gmane.comp.boot-loaders.grub.cvs
Message-ID <[email protected]>
Revision: 1834
          http://svn.sv.gnu.org/viewvc/?view=rev&root=grub&revision=1834
Author:   bean
Date:     2008-08-29 19:55:23 +0000 (Fri, 29 Aug 2008)

Log Message:
-----------
2008-08-29  Bean  <[email protected]>

	* 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.

Modified Paths:
--------------
    trunk/grub2/ChangeLog
    trunk/grub2/config.h.in
    trunk/grub2/configure
    trunk/grub2/configure.ac
    trunk/grub2/include/grub/symbol.h
    trunk/grub2/include/grub/util/misc.h
    trunk/grub2/util/biosdisk.c
    trunk/grub2/util/getroot.c
    trunk/grub2/util/grub-mkdevicemap.c
    trunk/grub2/util/hostfs.c
    trunk/grub2/util/misc.c

Modified: trunk/grub2/ChangeLog
===================================================================
--- trunk/grub2/ChangeLog	2008-08-29 01:08:05 UTC (rev 1833)
+++ trunk/grub2/ChangeLog	2008-08-29 19:55:23 UTC (rev 1834)
@@ -1,3 +1,34 @@
+2008-08-29  Bean  <[email protected]>
+
+	* 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  <[email protected]>
 
 	* conf/powerpc-ieee1275.rmk (kernel_elf_SOURCES): Add

Modified: trunk/grub2/config.h.in
===================================================================
--- trunk/grub2/config.h.in	2008-08-29 01:08:05 UTC (rev 1833)
+++ trunk/grub2/config.h.in	2008-08-29 19:55:23 UTC (rev 1834)
@@ -25,6 +25,9 @@
 /* Define if C symbols get an underscore after compilation */
 #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. */
 #undef HAVE_CURSES_H
 

Modified: trunk/grub2/configure
===================================================================
--- trunk/grub2/configure	2008-08-29 01:08:05 UTC (rev 1833)
+++ trunk/grub2/configure	2008-08-29 19:55:23 UTC (rev 1834)
@@ -1993,10 +1993,18 @@
   x86_64 | sparc64) target_m64=1 ;;
 esac
 
+case "$host_os" in
+  mingw32) host_os=cygwin ;;
+esac
 
+case "$target_os" in
+  mingw32) target_os=cygwin ;;
+esac
 
 
 
+
+
 #
 # Checks for build programs.
 #
@@ -5786,7 +5794,8 @@
 # Check for functions.
 
 
-for ac_func in posix_memalign memalign
+
+for ac_func in posix_memalign memalign asprintf
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 { echo "$as_me:$LINENO: checking for $ac_func" >&5

Modified: trunk/grub2/configure.ac
===================================================================
--- trunk/grub2/configure.ac	2008-08-29 01:08:05 UTC (rev 1833)
+++ trunk/grub2/configure.ac	2008-08-29 19:55:23 UTC (rev 1834)
@@ -99,6 +99,14 @@
   x86_64 | sparc64) target_m64=1 ;;
 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_os)
 AC_SUBST(platform)
@@ -183,7 +191,7 @@
 fi
 
 # Check for functions.
-AC_CHECK_FUNCS(posix_memalign memalign)
+AC_CHECK_FUNCS(posix_memalign memalign asprintf)
 
 #
 # Check for target programs.

Modified: trunk/grub2/include/grub/symbol.h
===================================================================
--- trunk/grub2/include/grub/symbol.h	2008-08-29 01:08:05 UTC (rev 1833)
+++ trunk/grub2/include/grub/symbol.h	2008-08-29 19:55:23 UTC (rev 1834)
@@ -28,7 +28,7 @@
 # define EXT_C(sym)	sym
 #endif
 
-#ifndef __CYGWIN__
+#if ! defined (__CYGWIN__) && ! defined (__MINGW32__)
 #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):
 #else

Modified: trunk/grub2/include/grub/util/misc.h
===================================================================
--- trunk/grub2/include/grub/util/misc.h	2008-08-29 01:08:05 UTC (rev 1833)
+++ trunk/grub2/include/grub/util/misc.h	2008-08-29 19:55:23 UTC (rev 1834)
@@ -24,6 +24,9 @@
 #include <setjmp.h>
 #include <unistd.h>
 
+#include <config.h>
+#include <grub/types.h>
+
 #ifdef __NetBSD__
 /* NetBSD uses /boot for its boot block.  */
 # define DEFAULT_DIRECTORY	"/grub"
@@ -55,4 +58,22 @@
 			       FILE *out);
 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 */

Modified: trunk/grub2/util/biosdisk.c
===================================================================
--- trunk/grub2/util/biosdisk.c	2008-08-29 01:08:05 UTC (rev 1833)
+++ trunk/grub2/util/biosdisk.c	2008-08-29 19:55:23 UTC (rev 1834)
@@ -163,8 +163,23 @@
   disk->id = drive;
 
   /* 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;
     int fd;
 
@@ -281,6 +296,9 @@
 #ifdef O_FSYNC
   flags |= O_FSYNC;
 #endif
+#ifdef O_BINARY
+  flags |= O_BINARY;
+#endif
   
 #ifdef __linux__
   /* Linux has a bug that the disk cache for a whole disk is not consistent

Modified: trunk/grub2/util/getroot.c
===================================================================
--- trunk/grub2/util/getroot.c	2008-08-29 01:08:05 UTC (rev 1833)
+++ trunk/grub2/util/getroot.c	2008-08-29 19:55:23 UTC (rev 1834)
@@ -169,9 +169,18 @@
   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 *
 find_root_device (const char *dir, dev_t dev)
 {
   DIR *dp;

Modified: trunk/grub2/util/grub-mkdevicemap.c
===================================================================
--- trunk/grub2/util/grub-mkdevicemap.c	2008-08-29 01:08:05 UTC (rev 1833)
+++ trunk/grub2/util/grub-mkdevicemap.c	2008-08-29 19:55:23 UTC (rev 1834)
@@ -169,6 +169,9 @@
 #elif defined(__CYGWIN__)
   /* Cygwin */
   sprintf (name, "/dev/fd%d", unit);
+#elif defined(__MINGW32__)
+  (void) unit;
+  *name = 0;
 #else
 # warning "BIOS floppy drives cannot be guessed in your operating system."
   /* Set NAME to a bogus string.  */
@@ -214,6 +217,8 @@
   /* Cygwin emulates all disks as /dev/sdX.  */
   (void) unit;
   *name = 0;
+#elif defined(__MINGW32__)
+  sprintf (name, "//./PHYSICALDRIVE%d", unit);
 #else
 # warning "BIOS IDE drives cannot be guessed in your operating system."
   /* Set NAME to a bogus string.  */
@@ -258,6 +263,9 @@
 #elif defined(__CYGWIN__)
   /* Cygwin emulates all disks as /dev/sdX.  */
   sprintf (name, "/dev/sd%c", unit + 'a');
+#elif defined(__MINGW32__)
+  (void) unit;
+  *name = 0;
 #else
 # warning "BIOS SCSI drives cannot be guessed in your operating system."
   /* Set NAME to a bogus string.  */

Modified: trunk/grub2/util/hostfs.c
===================================================================
--- trunk/grub2/util/hostfs.c	2008-08-29 01:08:05 UTC (rev 1833)
+++ trunk/grub2/util/hostfs.c	2008-08-29 19:55:23 UTC (rev 1834)
@@ -22,6 +22,7 @@
 #include <grub/disk.h>
 #include <grub/misc.h>
 #include <grub/dl.h>
+#include <grub/util/misc.h>
 
 #include <dirent.h>
 #include <stdio.h>
@@ -95,15 +96,19 @@
 {
   FILE *f;
 
-  f = fopen (name, "r");
+  f = fopen (name, "rb");
   if (! f)
     return grub_error (GRUB_ERR_BAD_FILENAME,
 		       "can't open `%s'", name);
   file->data = f;
 
+#ifdef __MINGW32__
+  file->size = grub_util_get_disk_size (name);
+#else
   fseeko (f, 0, SEEK_END);
   file->size = ftello (f);
   fseeko (f, 0, SEEK_SET);
+#endif
 
   return GRUB_ERR_NONE;
 }

Modified: trunk/grub2/util/misc.c
===================================================================
--- trunk/grub2/util/misc.c	2008-08-29 01:08:05 UTC (rev 1833)
+++ trunk/grub2/util/misc.c	2008-08-29 19:55:23 UTC (rev 1834)
@@ -259,6 +259,8 @@
 #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_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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.