* 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> 2013-08-22 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/mm.h (grub_extend_alloc): Remove. * include/grub/mm.h (grub_extend_alloc): Remove.

View file

@ -43,6 +43,12 @@
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#ifdef __MINGW32__
#include <windows.h>
#include <winioctl.h>
#include "dirname.h"
#endif
#ifdef __linux__ #ifdef __linux__
# include <sys/ioctl.h> /* ioctl */ # include <sys/ioctl.h> /* ioctl */
# include <sys/mount.h> # include <sys/mount.h>
@ -245,6 +251,73 @@ grub_util_biosdisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
return 0; 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__) #if !defined(__MINGW32__)
grub_uint64_t grub_uint64_t
grub_util_get_fd_size (int fd, const char *name, unsigned *log_secsize) 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; data->device_map = map[drive].device_map;
/* Get the size. */ /* 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; int fd;
#if defined(__MINGW32__)
fd = -1;
#else
fd = open (map[drive].device, O_RDONLY); fd = open (map[drive].device, O_RDONLY);
if (fd == -1) if (fd == -1)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("cannot open `%s': %s"), return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("cannot open `%s': %s"),
map[drive].device, strerror (errno)); map[drive].device, strerror (errno));
#endif
disk->total_sectors = grub_util_get_fd_size (fd, map[drive].device, disk->total_sectors = grub_util_get_fd_size (fd, map[drive].device,
&disk->log_sector_size); &disk->log_sector_size);
disk->total_sectors >>= 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 defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__)
if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode)) if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode))
# else # else
@ -402,13 +465,13 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
data->is_disk = 1; data->is_disk = 1;
close (fd); close (fd);
#endif
grub_util_info ("the size of %s is %" PRIuGRUB_UINT64_T, grub_util_info ("the size of %s is %" PRIuGRUB_UINT64_T,
name, disk->total_sectors); name, disk->total_sectors);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
#endif
} }
#ifdef HAVE_DEVICE_MAPPER #ifdef HAVE_DEVICE_MAPPER
@ -1359,7 +1422,7 @@ read_device_map (const char *dev_map)
#ifdef __MINGW32__ #ifdef __MINGW32__
(void) st; (void) st;
if (grub_util_get_disk_size (p) == -1LL) if (grub_util_get_fd_size (-1, p, NULL) == -1LL)
#else #else
if (stat (p, &st) == -1) if (stat (p, &st) == -1)
#endif #endif

View file

@ -132,11 +132,7 @@ grub_hostfs_open (struct grub_file *file, const char *name)
file->data = data; 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); file->size = grub_util_get_fd_size (fileno (f), name, NULL);
#endif
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }

View file

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

View file

@ -57,10 +57,8 @@ grub_hostdisk_find_partition_start (const char *dev);
const char * const char *
grub_hostdisk_os_dev_to_grub_drive (const char *os_dev, int add); grub_hostdisk_os_dev_to_grub_drive (const char *os_dev, int add);
#if !defined(__MINGW32__)
grub_uint64_t grub_uint64_t
grub_util_get_fd_size (int fd, const char *name, unsigned *log_secsize); grub_util_get_fd_size (int fd, const char *name, unsigned *log_secsize);
#endif
char * char *
grub_util_get_os_disk (const char *os_dev); 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); extern char * canonicalize_file_name (const char *path);
#ifdef __MINGW32__
int fsync (int fno);
#endif
#ifdef HAVE_DEVICE_MAPPER #ifdef HAVE_DEVICE_MAPPER
int grub_device_mapper_supported (void); int grub_device_mapper_supported (void);
#endif #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 fseeko fseeko64
#define ftello ftello64 #define ftello ftello64
void sync (void);
int fsync (int fno);
grub_int64_t grub_util_get_disk_size (char *name);
#endif #endif

View file

@ -281,63 +281,6 @@ grub_millisleep (grub_uint32_t ms)
#endif #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 #ifdef GRUB_UTIL
void void
grub_util_init_nls (void) grub_util_init_nls (void)