+2013-03-10 Vladimir Serbinenko <phcoder@gmail.com>
+
+ * grub-core/fs/hfs.c (grub_hfs_read_file): Avoid divmod64 since the
+ maximum size is 4G - 1 on hfs
+
2013-03-10 Vladimir Serbinenko <phcoder@gmail.com>
Avoid costly 64-bit division in grub_get_time_ms on most platforms.
static grub_ssize_t
grub_hfs_read_file (struct grub_hfs_data *data,
grub_disk_read_hook_t read_hook, void *read_hook_data,
- grub_off_t pos, grub_size_t len, char *buf)
+ grub_uint32_t pos, grub_size_t len, char *buf)
{
grub_off_t i;
grub_off_t blockcnt;
- blockcnt = grub_divmod64 (((len + pos)
- + data->blksz - 1), data->blksz, 0);
+ /* Files are at most 2G/4G - 1 bytes on hfs. Avoid 64-bit division.
+ Moreover len > 0 as checked in upper layer. */
+ blockcnt = (len + pos - 1) / data->blksz + 1;
- for (i = grub_divmod64 (pos, data->blksz, 0); i < blockcnt; i++)
+ for (i = pos / data->blksz; i < blockcnt; i++)
{
grub_disk_addr_t blknr;
grub_off_t blockoff;
int skipfirst = 0;
- grub_divmod64 (pos, data->blksz, &blockoff);
+ blockoff = pos % data->blksz;
blknr = grub_hfs_block (data, data->extents, data->fileid, i, 1);
if (grub_errno)
/* Last block. */
if (i == blockcnt - 1)
{
- grub_divmod64 ((len + pos), data->blksz, &blockend);
+ blockend = (len + pos) % data->blksz;
/* The last portion is exactly EXT2_BLOCK_SIZE (data). */
if (! blockend)
}
/* First block. */
- if (i == grub_divmod64 (pos, data->blksz, 0))
+ if (i == pos / data->blksz)
{
skipfirst = blockoff;
blockend -= skipfirst;