+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
*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))
}
}
-#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"),
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))
{
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;
}
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')
}
}
-
-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)))
{
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)))
{
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,
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"),
}
# if defined(__NetBSD__)
- configure_device_driver (fd);
/* First handle the case of disk wedges. */
if (ioctl (fd, DIOCGWEDGEINFO, &dkw) == 0)
{
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;
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
# 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)
{
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;
+}
#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)
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)))
{
/* 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
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)
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)))
{
/* 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);