From a121c9648eb09fcc8fcfec3b2a24d2f50375462d Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 29 Feb 2012 15:23:31 +0100 Subject: [PATCH] Use the common size routine in hostfs so we can read disks as well. * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors): Rename to .. (grub_util_get_fd_size): ... this. Return size in bytes. All users updated. * grub-core/kern/emu/hostfs.c (grub_hostfs_open): Use grub_util_get_fd_size. --- ChangeLog | 10 ++++++++++ grub-core/disk/geli.c | 3 ++- grub-core/kern/emu/hostdisk.c | 17 +++++++++-------- grub-core/kern/emu/hostfs.c | 5 ++--- include/grub/emu/hostdisk.h | 2 +- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 12a76b551..d80c7be2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2012-02-29 Vladimir Serbinenko + + Use the common size routine in hostfs so we can read disks as well. + + * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors): Rename to .. + (grub_util_get_fd_size): ... this. Return size in bytes. + All users updated. + * grub-core/kern/emu/hostfs.c (grub_hostfs_open): Use + grub_util_get_fd_size. + 2012-02-29 Vladimir Serbinenko * grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors) [__APPLE__]: diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index 855c12e4c..3a7929bf9 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -221,7 +221,8 @@ grub_util_get_geli_uuid (const char *dev) if (fd < 0) return NULL; - s = grub_util_get_fd_sectors (fd, dev, &log_secsize); + s = grub_util_get_fd_size (fd, dev, &log_secsize); + s >>= log_secsize; grub_util_fd_seek (fd, dev, (s << log_secsize) - 512); uuid = xmalloc (GRUB_MD_SHA256->mdlen * 2 + 1); diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index 5b588a652..f099f57f0 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -240,7 +240,7 @@ grub_util_biosdisk_iterate (int (*hook) (const char *name), #if !defined(__MINGW32__) grub_uint64_t -grub_util_get_fd_sectors (int fd, const char *name, unsigned *log_secsize) +grub_util_get_fd_size (int fd, const char *name, unsigned *log_secsize) { # if defined(__NetBSD__) struct disklabel label; @@ -304,16 +304,16 @@ grub_util_get_fd_sectors (int fd, const char *name, unsigned *log_secsize) *log_secsize = log_sector_size; # if defined (__APPLE__) - return nr; + return nr << log_sector_size; # elif defined(__NetBSD__) - return label.d_secperunit; + return label.d_secperunit << log_sector_size; # elif defined (__sun__) - return minfo.dki_capacity; + return minfo.dki_capacity << log_sector_size; # else if (nr & ((1 << log_sector_size) - 1)) grub_util_error ("%s", _("unaligned device size")); - return (nr >> log_sector_size); + return nr; # endif fail: @@ -329,7 +329,7 @@ grub_util_get_fd_sectors (int fd, const char *name, unsigned *log_secsize) if (log_secsize) *log_secsize = 9; - return st.st_size >> 9; + return st.st_size; } #endif @@ -378,8 +378,9 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("cannot open `%s': %s"), map[drive].device, strerror (errno)); - disk->total_sectors = grub_util_get_fd_sectors (fd, map[drive].device, - &disk->log_sector_size); + 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(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__) if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode)) diff --git a/grub-core/kern/emu/hostfs.c b/grub-core/kern/emu/hostfs.c index 6c819da81..3cb089c3f 100644 --- a/grub-core/kern/emu/hostfs.c +++ b/grub-core/kern/emu/hostfs.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -132,9 +133,7 @@ grub_hostfs_open (struct grub_file *file, const char *name) #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); + file->size = grub_util_get_fd_size (fileno (f), name, NULL); #endif return GRUB_ERR_NONE; diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h index 88c20f5c9..f1bfa6e98 100644 --- a/include/grub/emu/hostdisk.h +++ b/include/grub/emu/hostdisk.h @@ -59,7 +59,7 @@ grub_hostdisk_os_dev_to_grub_drive (const char *os_dev, int add); #if !defined(__MINGW32__) grub_uint64_t -grub_util_get_fd_sectors (int fd, const char *name, unsigned *log_secsize); +grub_util_get_fd_size (int fd, const char *name, unsigned *log_secsize); #endif char * -- 2.39.5