]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Move OS-specific driver configuration to grub_util_fd_open. This
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Wed, 9 Oct 2013 05:04:25 +0000 (07:04 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Wed, 9 Oct 2013 05:04:25 +0000 (07:04 +0200)
moves OS-dependent parts from kern/emu/hostdisk.c to
grub-core/osdep/*/hostdisk.c.

13 files changed:
ChangeLog
grub-core/kern/emu/hostdisk.c
grub-core/osdep/apple/hostdisk.c
grub-core/osdep/aros/hostdisk.c
grub-core/osdep/basic/hostdisk.c
grub-core/osdep/bsd/getroot.c
grub-core/osdep/bsd/hostdisk.c
grub-core/osdep/freebsd/hostdisk.c
grub-core/osdep/hurd/hostdisk.c
grub-core/osdep/sun/hostdisk.c
grub-core/osdep/unix/hostdisk.c
grub-core/osdep/windows/hostdisk.c
include/grub/emu/hostdisk.h

index b6d3cb37276054e84736e232f77d8dd81ca9e855..2c43dceb69aa838f76f63ad650c63e73de05822f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-10-09  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Move OS-specific driver configuration to grub_util_fd_open. This
+       moves OS-dependent parts from kern/emu/hostdisk.c to
+       grub-core/osdep/*/hostdisk.c.
+
 2013-10-09  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * util/grub-mkimage.c (generate_image): Use size_t instead of
index a29eb5f3ace2bf464099d1d1b391b29dfa273196..fb7d72edcd5e0f2737be726a0d9ac96787f88753 100644 (file)
@@ -232,36 +232,12 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f
 
   *max = ~0ULL;
 
-#ifdef O_LARGEFILE
-  flags |= O_LARGEFILE;
-#endif
 #ifdef O_SYNC
   flags |= O_SYNC;
 #endif
 #ifdef O_FSYNC
   flags |= O_FSYNC;
 #endif
-#ifdef O_BINARY
-  flags |= O_BINARY;
-#endif
-
-#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
-  int sysctl_flags, sysctl_oldflags;
-  size_t sysctl_size = sizeof (sysctl_flags);
-
-  if (sysctlbyname ("kern.geom.debugflags", &sysctl_oldflags, &sysctl_size, NULL, 0))
-    {
-      grub_error (GRUB_ERR_BAD_DEVICE, "cannot get current flags of sysctl kern.geom.debugflags");
-      return GRUB_UTIL_FD_INVALID;
-    }
-  sysctl_flags = sysctl_oldflags | 0x10;
-  if (! (sysctl_oldflags & 0x10)
-      && sysctlbyname ("kern.geom.debugflags", NULL , 0, &sysctl_flags, sysctl_size))
-    {
-      grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags of sysctl kern.geom.debugflags");
-      return GRUB_UTIL_FD_INVALID;
-    }
-#endif
 
   if (data->dev && strcmp (data->dev, map[disk->id].device) == 0 &&
       data->access_mode == (flags & O_ACCMODE))
@@ -290,21 +266,6 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f
        }
     }
 
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-  if (! (sysctl_oldflags & 0x10)
-      && sysctlbyname ("kern.geom.debugflags", NULL , 0, &sysctl_oldflags, sysctl_size))
-    {
-      grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags back to the old value for sysctl kern.geom.debugflags");
-      return GRUB_UTIL_FD_INVALID;
-    }
-#endif
-
-#if defined(__APPLE__)
-  /* If we can't have exclusive access, try shared access */
-  if (fd < 0)
-    fd = open(map[disk->id].device, flags | O_SHLOCK);
-#endif
-
   if (!GRUB_UTIL_FD_IS_VALID(data->fd))
     {
       grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot open `%s': %s"),
@@ -312,8 +273,6 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f
       return GRUB_UTIL_FD_INVALID;
     }
 
-  grub_hostdisk_configure_device_driver (fd);
-
   if (grub_util_fd_seek (fd, map[disk->id].device,
                         sector << disk->log_sector_size))
     {
index ac653bb6a68ad0fe707ce42ca0bd25cdfd6b1482..c9df43e4fe9b40c7b07584d009283521371bc5b6 100644 (file)
@@ -68,7 +68,23 @@ grub_util_get_fd_size (grub_util_fd_t fd, const char *name, unsigned *log_secsiz
   return nr << log_sector_size;
 }
 
-void
-grub_hostdisk_configure_device_driver (grub_util_fd_t fd __attribute__ ((unused)))
+grub_util_fd_t
+grub_util_fd_open (const char *os_dev, int flags)
 {
+  grub_util_fd_t ret;
+
+#ifdef O_LARGEFILE
+  flags |= O_LARGEFILE;
+#endif
+#ifdef O_BINARY
+  flags |= O_BINARY;
+#endif
+
+  ret = open (os_dev, flags);
+
+  /* If we can't have exclusive access, try shared access */
+  if (ret < 0)
+    ret = open (os_dev, flags | O_SHLOCK);
+
+  return ret;
 }
index b6a2de9babfa9ff2996f58612b7a186f69252d2a..75fafe8d06361c56bcf7000ea38910cf6e8eac68 100644 (file)
@@ -169,6 +169,13 @@ grub_util_fd_open (const char *dev, int flg)
   IPTR unit = 0;
   ULONG flags = 0;
 
+#ifdef O_LARGEFILE
+  flg |= O_LARGEFILE;
+#endif
+#ifdef O_BINARY
+  flg |= O_BINARY;
+#endif
+
   ret->off = 0;
 
   if (dev[0] == '\0')
@@ -479,12 +486,6 @@ grub_util_fd_sync (grub_util_fd_t fd)
     }
 }
 
-
-void
-grub_hostdisk_configure_device_driver (grub_util_fd_t fd __attribute__ ((unused)))
-{
-}
-
 void
 grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))
 {
index 7ea079557f51d5a6c9bcbd046f5494cc6f4ff2a0..529bf29f39f061d0444b2088258323441aa5f78b 100644 (file)
@@ -52,11 +52,6 @@ grub_util_get_fd_size_os (grub_util_fd_t fd __attribute__ ((unused)),
   return -1;
 }
 
-void
-grub_hostdisk_configure_device_driver (grub_util_fd_t fd __attribute__ ((unused)))
-{
-}
-
 void
 grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))
 {
index db2fb07d3f712606807e622c28bf256a66c113d3..0cb0da109c15588f8ef3116c8a424668f680e5fc 100644 (file)
@@ -86,7 +86,6 @@ grub_util_part_to_disk (const char *os_dev, struct stat *st,
                      strerror (errno));
          return xstrdup (os_dev);
        }
-      /* We don't call configure_device_driver since this isn't a floppy device name.  */
       if (ioctl (fd, DIOCGWEDGEINFO, &dkw) == -1)
        {
          grub_error (GRUB_ERR_BAD_DEVICE,
@@ -156,7 +155,7 @@ grub_util_find_partition_start_os (const char *dev)
   struct disklabel label;
   int p_index;
 
-  fd = open (dev, O_RDONLY);
+  fd = grub_util_fd_open (dev, O_RDONLY);
   if (fd == -1)
     {
       grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot open `%s': %s"),
@@ -165,7 +164,6 @@ grub_util_find_partition_start_os (const char *dev)
     }
 
 #  if defined(__NetBSD__)
-  configure_device_driver (fd);
   /* First handle the case of disk wedges.  */
   if (ioctl (fd, DIOCGWEDGEINFO, &dkw) == 0)
     {
index a5dadf19559d46d5bf000f319125f5e7b381412b..dc845b11f1a3ce8b75639116fe6191f946466f72 100644 (file)
@@ -60,8 +60,8 @@
    after successfully opening the device.  For now, it simply prevents the
    floppy driver from retrying operations on failure, as otherwise the
    driver takes a while to abort when there is no floppy in the drive.  */
-void
-grub_hostdisk_configure_device_driver (grub_util_fd_t fd)
+static void
+configure_device_driver (grub_util_fd_t fd)
 {
   struct stat st;
 
@@ -78,11 +78,24 @@ grub_hostdisk_configure_device_driver (grub_util_fd_t fd)
        return;
     }
 }
-#else
-void
-grub_hostdisk_configure_device_driver (grub_util_fd_t fd __attribute__ ((unused)))
+grub_util_fd_t
+grub_util_fd_open (const char *os_dev, int flags)
 {
+  grub_util_fd_t ret;
+
+#ifdef O_LARGEFILE
+  flags |= O_LARGEFILE;
+#endif
+#ifdef O_BINARY
+  flags |= O_BINARY;
+#endif
+
+  ret = open (os_dev, flags);
+  if (ret >= 0)
+    configure_device_driver (fd);
+  return ret;
 }
+
 #endif
 
 grub_int64_t
index 86d876c445386733db651f059fbb230f0a3101b8..bf864b0e4f1734251e715c62b4d67e6d3de98305 100644 (file)
 # include <sys/mount.h>
 # include <libgeom.h>
 
-void
-grub_hostdisk_configure_device_driver (grub_util_fd_t fd __attribute__ ((unused)))
-{
-}
-
 grub_int64_t
 grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_secsize)
 {
@@ -83,3 +78,45 @@ void
 grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))
 {
 }
+
+grub_util_fd_t
+grub_util_fd_open (const char *os_dev, int flags)
+{
+  grub_util_fd_t ret;
+  int sysctl_flags, sysctl_oldflags;
+  size_t sysctl_size = sizeof (sysctl_flags);
+
+#ifdef O_LARGEFILE
+  flags |= O_LARGEFILE;
+#endif
+#ifdef O_BINARY
+  flags |= O_BINARY;
+#endif
+
+  if (sysctlbyname ("kern.geom.debugflags", &sysctl_oldflags, &sysctl_size, NULL, 0))
+    {
+      grub_error (GRUB_ERR_BAD_DEVICE, "cannot get current flags of sysctl kern.geom.debugflags");
+      return GRUB_UTIL_FD_INVALID;
+    }
+  sysctl_flags = sysctl_oldflags | 0x10;
+  if (! (sysctl_oldflags & 0x10)
+      && sysctlbyname ("kern.geom.debugflags", NULL , 0, &sysctl_flags, sysctl_size))
+    {
+      grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags of sysctl kern.geom.debugflags");
+      return GRUB_UTIL_FD_INVALID;
+    }
+
+  ret = open (os_dev, flags);
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+  if (! (sysctl_oldflags & 0x10)
+      && sysctlbyname ("kern.geom.debugflags", NULL , 0, &sysctl_oldflags, sysctl_size))
+    {
+      grub_error (GRUB_ERR_BAD_DEVICE, "cannot set flags back to the old value for sysctl kern.geom.debugflags");
+      close (ret);
+      return GRUB_UTIL_FD_INVALID;
+    }
+#endif
+
+  return ret;
+}
index 36ce09a0cceb60a4a251744752966d239ff99610..57560e1e240f741a9c7db3f7a3c401d5c8d05313 100644 (file)
 #include <hurd/fs.h>
 #include <sys/mman.h>
 
-void
-grub_hostdisk_configure_device_driver (grub_util_fd_t fd __attribute__ ((unused)))
-{
-}
-
 int
 grub_util_hurd_get_disk_info (const char *dev, grub_uint32_t *secsize, grub_disk_addr_t *offset,
                              grub_disk_addr_t *size, char **parent)
index fa691a0c99b5c8eac79681b606068a63ffa9a5b8..dab96dcffdd2f918744981b837ae025a12127742 100644 (file)
@@ -67,11 +67,6 @@ grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_sec
   return minfo.dki_capacity << log_sector_size;
 }
 
-void
-grub_hostdisk_configure_device_driver (grub_util_fd_t fd __attribute__ ((unused)))
-{
-}
-
 void
 grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))
 {
index 52572498b168c386b728044ff87bdd5db6b8b05a..bb0e49f9c6cd4e086dda9fab8de869ee5c255fb5 100644 (file)
@@ -53,9 +53,6 @@
 /* Maybe libc doesn't have large file support.  */
 #  include <linux/unistd.h>     /* _llseek */
 # endif /* (GLIBC < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR < 1)) */
-# ifndef BLKFLSBUF
-#  define BLKFLSBUF     _IO (0x12,97)   /* flush buffer cache */
-# endif /* ! BLKFLSBUF */
 #endif /* __linux__ */
 
 grub_uint64_t
@@ -166,11 +163,20 @@ grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len)
   return size;
 }
 
+#if !defined (__NetBSD__) && !defined (__APPLE__) && !defined (__FreeBSD__) && !defined(__FreeBSD_kernel__)
 grub_util_fd_t
 grub_util_fd_open (const char *os_dev, int flags)
 {
+#ifdef O_LARGEFILE
+  flags |= O_LARGEFILE;
+#endif
+#ifdef O_BINARY
+  flags |= O_BINARY;
+#endif
+
   return open (os_dev, flags);
 }
+#endif
 
 const char *
 grub_util_fd_strerror (void)
index 10ae6fd53d67165e1a37d3f182f976b1e6b75202..5f0fc542534cbbf56a541b5443573ac8615ad84a 100644 (file)
@@ -137,11 +137,6 @@ grub_util_get_fd_size (grub_util_fd_t hd, const char *name_in,
   return size;
 }
 
-void
-grub_hostdisk_configure_device_driver (grub_util_fd_t fd __attribute__ ((unused)))
-{
-}
-
 void
 grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))
 {
index 28038e6d22eeb84ecc42238166d0cf551819a98c..3c621a843add4a54fbd624bd2b4203504fff2ada 100644 (file)
@@ -126,14 +126,6 @@ grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_sec
 /* REturns partition offset in 512B blocks.  */
 grub_disk_addr_t
 grub_hostdisk_find_partition_start_os (const char *dev);
-/* Adjust device driver parameters.  This function should be called just
-   after successfully opening the device.  For now, it simply prevents the
-   floppy driver from retrying operations on failure, as otherwise the
-   driver takes a while to abort when there is no floppy in the drive.
-   For now it's non-nop only on NetBSD.
-*/
-void
-grub_hostdisk_configure_device_driver (grub_util_fd_t fd);
 void
 grub_hostdisk_flush_initial_buffer (const char *os_dev);