Make grub_util_fd_seek match behaviour of other grub_util_fd_* and
fseeko.
This commit is contained in:
parent
dac86b182c
commit
b73249d260
9 changed files with 39 additions and 32 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2013-10-14 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
Make grub_util_fd_seek match behaviour of other grub_util_fd_* and
|
||||||
|
fseeko.
|
||||||
|
|
||||||
2013-10-14 qwertial <qwertial>
|
2013-10-14 qwertial <qwertial>
|
||||||
|
|
||||||
* grub-core/gdb_grub.in: Fix overflow and wrong field.
|
* grub-core/gdb_grub.in: Fix overflow and wrong field.
|
||||||
|
|
|
@ -560,10 +560,11 @@ grub_cryptodisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
||||||
#ifdef GRUB_UTIL
|
#ifdef GRUB_UTIL
|
||||||
if (dev->cheat)
|
if (dev->cheat)
|
||||||
{
|
{
|
||||||
err = grub_util_fd_seek (dev->cheat_fd, dev->cheat,
|
int r;
|
||||||
sector << disk->log_sector_size);
|
r = grub_util_fd_seek (dev->cheat_fd, sector << disk->log_sector_size);
|
||||||
if (err)
|
if (r)
|
||||||
return err;
|
return grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot seek `%s': %s"),
|
||||||
|
dev->cheat, grub_util_fd_strerror ());
|
||||||
if (grub_util_fd_read (dev->cheat_fd, buf, size << disk->log_sector_size)
|
if (grub_util_fd_read (dev->cheat_fd, buf, size << disk->log_sector_size)
|
||||||
!= (ssize_t) (size << disk->log_sector_size))
|
!= (ssize_t) (size << disk->log_sector_size))
|
||||||
return grub_error (GRUB_ERR_READ_ERROR, N_("cannot read `%s': %s"),
|
return grub_error (GRUB_ERR_READ_ERROR, N_("cannot read `%s': %s"),
|
||||||
|
@ -604,10 +605,11 @@ grub_cryptodisk_write (grub_disk_t disk, grub_disk_addr_t sector,
|
||||||
#ifdef GRUB_UTIL
|
#ifdef GRUB_UTIL
|
||||||
if (dev->cheat)
|
if (dev->cheat)
|
||||||
{
|
{
|
||||||
err = grub_util_fd_seek (dev->cheat_fd, dev->cheat,
|
int r;
|
||||||
sector << disk->log_sector_size);
|
r = grub_util_fd_seek (dev->cheat_fd, sector << disk->log_sector_size);
|
||||||
if (err)
|
if (r)
|
||||||
return err;
|
return grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot seek `%s': %s"),
|
||||||
|
dev->cheat, grub_util_fd_strerror ());
|
||||||
if (grub_util_fd_write (dev->cheat_fd, buf, size << disk->log_sector_size)
|
if (grub_util_fd_write (dev->cheat_fd, buf, size << disk->log_sector_size)
|
||||||
!= (ssize_t) (size << disk->log_sector_size))
|
!= (ssize_t) (size << disk->log_sector_size))
|
||||||
return grub_error (GRUB_ERR_READ_ERROR, N_("cannot read `%s': %s"),
|
return grub_error (GRUB_ERR_READ_ERROR, N_("cannot read `%s': %s"),
|
||||||
|
|
|
@ -223,7 +223,7 @@ grub_util_get_geli_uuid (const char *dev)
|
||||||
|
|
||||||
s = grub_util_get_fd_size (fd, dev, &log_secsize);
|
s = grub_util_get_fd_size (fd, dev, &log_secsize);
|
||||||
s >>= log_secsize;
|
s >>= log_secsize;
|
||||||
grub_util_fd_seek (fd, dev, (s << log_secsize) - 512);
|
grub_util_fd_seek (fd, (s << log_secsize) - 512);
|
||||||
|
|
||||||
uuid = xmalloc (GRUB_MD_SHA256->mdlen * 2 + 1);
|
uuid = xmalloc (GRUB_MD_SHA256->mdlen * 2 + 1);
|
||||||
if (grub_util_fd_read (fd, (void *) &hdr, 512) < 0)
|
if (grub_util_fd_read (fd, (void *) &hdr, 512) < 0)
|
||||||
|
|
|
@ -268,10 +268,12 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f
|
||||||
return GRUB_UTIL_FD_INVALID;
|
return GRUB_UTIL_FD_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grub_util_fd_seek (fd, map[disk->id].device,
|
if (grub_util_fd_seek (fd, sector << disk->log_sector_size))
|
||||||
sector << disk->log_sector_size))
|
|
||||||
{
|
{
|
||||||
grub_util_fd_close (fd);
|
grub_util_fd_close (fd);
|
||||||
|
grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot seek `%s': %s"),
|
||||||
|
map[disk->id].device, grub_util_fd_strerror ());
|
||||||
|
|
||||||
return GRUB_UTIL_FD_INVALID;
|
return GRUB_UTIL_FD_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,15 +139,14 @@ grub_util_get_fd_size_file (grub_util_fd_t fd,
|
||||||
return ro;
|
return ro;
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_err_t
|
int
|
||||||
grub_util_fd_seek (grub_util_fd_t fd, const char *name, grub_uint64_t off)
|
grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
|
||||||
{
|
{
|
||||||
switch (fd->type)
|
switch (fd->type)
|
||||||
{
|
{
|
||||||
case GRUB_UTIL_FD_FILE:
|
case GRUB_UTIL_FD_FILE:
|
||||||
if (lseek (fd->fd, 0, SEEK_SET) == (off_t) -1)
|
if (lseek (fd->fd, 0, SEEK_SET) == (off_t) -1)
|
||||||
return grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot seek `%s': %s"),
|
return -1;
|
||||||
name, strerror (errno));
|
|
||||||
fd->off = off;
|
fd->off = off;
|
||||||
return 0;
|
return 0;
|
||||||
case GRUB_UTIL_FD_DISK:
|
case GRUB_UTIL_FD_DISK:
|
||||||
|
@ -155,7 +154,7 @@ grub_util_fd_seek (grub_util_fd_t fd, const char *name, grub_uint64_t off)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_util_fd_t
|
grub_util_fd_t
|
||||||
|
|
|
@ -351,10 +351,11 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grub_util_fd_seek (fd, grub_util_biosdisk_get_osdev (disk),
|
if (grub_util_fd_seek (fd, sector << disk->log_sector_size))
|
||||||
sector << disk->log_sector_size))
|
|
||||||
{
|
{
|
||||||
close (fd);
|
close (fd);
|
||||||
|
grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot seek `%s': %s"),
|
||||||
|
grub_util_biosdisk_get_osdev (disk), strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,8 +82,8 @@ grub_util_get_fd_size (grub_util_fd_t fd, const char *name, unsigned *log_secsiz
|
||||||
#if defined(__linux__) && (!defined(__GLIBC__) || \
|
#if defined(__linux__) && (!defined(__GLIBC__) || \
|
||||||
((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1))))
|
((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1))))
|
||||||
/* Maybe libc doesn't have large file support. */
|
/* Maybe libc doesn't have large file support. */
|
||||||
grub_err_t
|
int
|
||||||
grub_util_fd_seek (grub_util_fd_t fd, const char *name, grub_uint64_t off)
|
grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
|
||||||
{
|
{
|
||||||
loff_t offset, result;
|
loff_t offset, result;
|
||||||
static int _llseek (uint filedes, ulong hi, ulong lo,
|
static int _llseek (uint filedes, ulong hi, ulong lo,
|
||||||
|
@ -93,19 +93,18 @@ grub_util_fd_seek (grub_util_fd_t fd, const char *name, grub_uint64_t off)
|
||||||
|
|
||||||
offset = (loff_t) off;
|
offset = (loff_t) off;
|
||||||
if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET))
|
if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET))
|
||||||
return grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot seek `%s': %s"),
|
return -1;
|
||||||
name, strerror (errno));
|
|
||||||
return GRUB_ERR_NONE;
|
return GRUB_ERR_NONE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
grub_err_t
|
int
|
||||||
grub_util_fd_seek (grub_util_fd_t fd, const char *name, grub_uint64_t off)
|
grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
|
||||||
{
|
{
|
||||||
off_t offset = (off_t) off;
|
off_t offset = (off_t) off;
|
||||||
|
|
||||||
if (lseek (fd, offset, SEEK_SET) != offset)
|
if (lseek (fd, offset, SEEK_SET) != offset)
|
||||||
return grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot seek `%s': %s"),
|
return -1;
|
||||||
name, strerror (errno));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -179,15 +179,14 @@ grub_hostdisk_flush_initial_buffer (const char *os_dev __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_err_t
|
int
|
||||||
grub_util_fd_seek (grub_util_fd_t fd, const char *name, grub_uint64_t off)
|
grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER offset;
|
LARGE_INTEGER offset;
|
||||||
offset.QuadPart = off;
|
offset.QuadPart = off;
|
||||||
|
|
||||||
if (!SetFilePointerEx (fd, offset, NULL, FILE_BEGIN))
|
if (!SetFilePointerEx (fd, offset, NULL, FILE_BEGIN))
|
||||||
return grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot seek `%s': %s"),
|
return -1;
|
||||||
name, strerror (errno));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,8 @@ int grub_util_biosdisk_is_floppy (grub_disk_t disk);
|
||||||
const char *
|
const char *
|
||||||
grub_util_biosdisk_get_compatibility_hint (grub_disk_t disk);
|
grub_util_biosdisk_get_compatibility_hint (grub_disk_t disk);
|
||||||
grub_err_t grub_util_biosdisk_flush (struct grub_disk *disk);
|
grub_err_t grub_util_biosdisk_flush (struct grub_disk *disk);
|
||||||
grub_err_t
|
int
|
||||||
grub_util_fd_seek (grub_util_fd_t fd, const char *name, grub_uint64_t sector);
|
grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t offset);
|
||||||
ssize_t grub_util_fd_read (grub_util_fd_t fd, char *buf, size_t len);
|
ssize_t grub_util_fd_read (grub_util_fd_t fd, char *buf, size_t len);
|
||||||
ssize_t grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len);
|
ssize_t grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len);
|
||||||
grub_err_t
|
grub_err_t
|
||||||
|
|
Loading…
Reference in a new issue