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.
This commit is contained in:
parent
c66d641020
commit
a121c9648e
5 changed files with 24 additions and 13 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2012-02-29 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
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 <phcoder@gmail.com>
|
||||
|
||||
* grub-core/kern/emu/hostdisk.c (grub_util_get_fd_sectors) [__APPLE__]:
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <grub/mm.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/emu/hostdisk.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
#include <dirent.h>
|
||||
|
@ -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;
|
||||
|
|
|
@ -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 *
|
||||
|
|
Loading…
Reference in a new issue