* grub-core/kern/emu/hostdisk.c (grub_util_get_fd_size): Adapt for

mingw32 as well based on grub_util_get_disk_size.
	* util/misc.c (grub_util_get_disk_size): Removed. all users switched to
	grub_util_get_fd_size.
	(sync): Removed.
	(fsync): Moved to ...
	* grub-core/kern/emu/misc.c (fsync): ... here.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-08-22 16:50:12 +02:00
parent f82d79c984
commit 984cfd8a79
8 changed files with 106 additions and 94 deletions

View File

@ -1,3 +1,13 @@
2013-08-22 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/emu/hostdisk.c (grub_util_get_fd_size): Adapt for
mingw32 as well based on grub_util_get_disk_size.
* util/misc.c (grub_util_get_disk_size): Removed. all users switched to
grub_util_get_fd_size.
(sync): Removed.
(fsync): Moved to ...
* grub-core/kern/emu/misc.c (fsync): ... here.
2013-08-22 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/mm.h (grub_extend_alloc): Remove.

View File

@ -43,6 +43,12 @@
#include <errno.h>
#include <limits.h>
#ifdef __MINGW32__
#include <windows.h>
#include <winioctl.h>
#include "dirname.h"
#endif
#ifdef __linux__
# include <sys/ioctl.h> /* ioctl */
# include <sys/mount.h>
@ -245,6 +251,73 @@ grub_util_biosdisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
return 0;
}
#ifdef __MINGW32__
grub_uint64_t
grub_util_get_fd_size (int fd __attribute__ ((unused)), const char *name_in,
unsigned *log_secsize)
{
HANDLE hd;
grub_int64_t size = -1LL;
int log_sector_size = 9;
char *name = xstrdup (name_in);
if (log_secsize)
*log_secsize = log_sector_size;
strip_trailing_slashes(name);
hd = CreateFile (name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
0, OPEN_EXISTING, 0, 0);
if (hd == INVALID_HANDLE_VALUE)
{
free (name);
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;
for (log_sector_size = 0;
(1 << log_sector_size) < g.BytesPerSector;
log_sector_size++);
}
else
{
ULARGE_INTEGER s;
s.LowPart = GetFileSize (hd, &s.HighPart);
size = s.QuadPart;
}
fail:
if (log_secsize)
*log_secsize = log_sector_size;
free (name);
CloseHandle (hd);
return size;
}
#endif
#if !defined(__MINGW32__)
grub_uint64_t
grub_util_get_fd_size (int fd, const char *name, unsigned *log_secsize)
@ -366,34 +439,24 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
data->device_map = map[drive].device_map;
/* Get the size. */
#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;
}
#else
{
int fd;
#if defined(__MINGW32__)
fd = -1;
#else
fd = open (map[drive].device, O_RDONLY);
if (fd == -1)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("cannot open `%s': %s"),
map[drive].device, strerror (errno));
#endif
disk->total_sectors = grub_util_get_fd_size (fd, map[drive].device,
&disk->log_sector_size);
disk->total_sectors >>= disk->log_sector_size;
#if !defined(__MINGW32__)
# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__)
if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode))
# else
@ -402,13 +465,13 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
data->is_disk = 1;
close (fd);
#endif
grub_util_info ("the size of %s is %" PRIuGRUB_UINT64_T,
name, disk->total_sectors);
return GRUB_ERR_NONE;
}
#endif
}
#ifdef HAVE_DEVICE_MAPPER
@ -1359,7 +1422,7 @@ read_device_map (const char *dev_map)
#ifdef __MINGW32__
(void) st;
if (grub_util_get_disk_size (p) == -1LL)
if (grub_util_get_fd_size (-1, p, NULL) == -1LL)
#else
if (stat (p, &st) == -1)
#endif

View File

@ -132,11 +132,7 @@ grub_hostfs_open (struct grub_file *file, const char *name)
file->data = data;
#ifdef __MINGW32__
file->size = grub_util_get_disk_size (name);
#else
file->size = grub_util_get_fd_size (fileno (f), name, NULL);
#endif
return GRUB_ERR_NONE;
}

View File

@ -42,10 +42,6 @@
#include <grub/time.h>
#include <grub/emu/misc.h>
#ifdef HAVE_DEVICE_MAPPER
# include <libdevmapper.h>
#endif
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
@ -59,10 +55,6 @@
# include <sys/mnttab.h>
#endif
#ifdef HAVE_SYS_MKDEV_H
# include <sys/mkdev.h> /* makedev */
#endif
int verbosity;
void
@ -189,6 +181,15 @@ grub_get_rtc (void)
* GRUB_TICKS_PER_SECOND / 1000000));
}
#ifdef __MINGW32__
int fsync (int fno __attribute__ ((unused)))
{
return 0;
}
#endif
char *
canonicalize_file_name (const char *path)
{

View File

@ -57,10 +57,8 @@ grub_hostdisk_find_partition_start (const char *dev);
const char *
grub_hostdisk_os_dev_to_grub_drive (const char *os_dev, int add);
#if !defined(__MINGW32__)
grub_uint64_t
grub_util_get_fd_size (int fd, const char *name, unsigned *log_secsize);
#endif
char *
grub_util_get_os_disk (const char *os_dev);

View File

@ -66,6 +66,12 @@ void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((format
extern char * canonicalize_file_name (const char *path);
#ifdef __MINGW32__
int fsync (int fno);
#endif
#ifdef HAVE_DEVICE_MAPPER
int grub_device_mapper_supported (void);
#endif

View File

@ -44,11 +44,6 @@ void grub_util_write_image_at (const void *img, size_t size, off_t offset,
#define fseeko fseeko64
#define ftello ftello64
void sync (void);
int fsync (int fno);
grub_int64_t grub_util_get_disk_size (char *name);
#endif

View File

@ -281,63 +281,6 @@ grub_millisleep (grub_uint32_t ms)
#endif
#ifdef __MINGW32__
void sync (void)
{
}
int fsync (int fno __attribute__ ((unused)))
{
return 0;
}
grub_int64_t
grub_util_get_disk_size (char *name)
{
HANDLE hd;
grub_int64_t size = -1LL;
strip_trailing_slashes(name);
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 /* __MINGW32__ */
#ifdef GRUB_UTIL
void
grub_util_init_nls (void)