Use full 64-bit division.
* grub-core/kern/misc.c (grub_divmod64_full): Renamed to ... (grub_divmod64): ... this. * include/grub/misc.h (grub_divmod64): Removed. All users switch to full version.
This commit is contained in:
parent
b84f26c549
commit
bf947d36e3
15 changed files with 46 additions and 44 deletions
|
@ -1,3 +1,12 @@
|
|||
2011-05-18 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
Use full 64-bit division.
|
||||
|
||||
* grub-core/kern/misc.c (grub_divmod64_full): Renamed to ...
|
||||
(grub_divmod64): ... this.
|
||||
* include/grub/misc.h (grub_divmod64): Removed. All users switch to full
|
||||
version.
|
||||
|
||||
2011-05-18 Colin Watson <cjwatson@ubuntu.com>
|
||||
|
||||
* util/grub-mkrescue.in: Use portable `.' rather than non-portable
|
||||
|
|
|
@ -134,11 +134,12 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
|
|||
|
||||
if (units)
|
||||
{
|
||||
grub_uint32_t whole, fraction;
|
||||
grub_uint64_t whole, fraction;
|
||||
|
||||
whole = grub_divmod64 (fsize, 100, &fraction);
|
||||
grub_snprintf (buf, sizeof (buf),
|
||||
"%u.%02u%c", whole, fraction,
|
||||
"%" PRIuGRUB_UINT64_T
|
||||
".%02" PRIuGRUB_UINT64_T "%c", whole, fraction,
|
||||
grub_human_sizes[units]);
|
||||
grub_printf ("%-12s", buf);
|
||||
}
|
||||
|
|
|
@ -506,7 +506,7 @@ static grub_size_t
|
|||
get_safe_sectors (grub_disk_addr_t sector, grub_uint32_t sectors)
|
||||
{
|
||||
grub_size_t size;
|
||||
grub_uint32_t offset;
|
||||
grub_uint64_t offset;
|
||||
|
||||
/* OFFSET = SECTOR % SECTORS */
|
||||
grub_divmod64 (sector, sectors, &offset);
|
||||
|
|
|
@ -247,9 +247,9 @@ read_lv (struct grub_lvm_lv *lv, grub_disk_addr_t sector,
|
|||
/* This is a striped segment. We have to find the right PV
|
||||
similar to RAID0. */
|
||||
struct grub_lvm_node *stripe = seg->nodes;
|
||||
grub_uint32_t a, b;
|
||||
grub_uint64_t a, b;
|
||||
grub_uint64_t seg_offset; /* Offset of the segment in PV device. */
|
||||
unsigned int stripenr;
|
||||
grub_uint64_t stripenr;
|
||||
|
||||
offset = sector - ((grub_uint64_t) seg->start_extent
|
||||
* (grub_uint64_t) vg->extent_size);
|
||||
|
|
|
@ -245,7 +245,7 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
case 10:
|
||||
{
|
||||
grub_disk_addr_t read_sector, far_ofs;
|
||||
grub_uint32_t disknr, b, near, far, ofs;
|
||||
grub_uint64_t disknr, b, near, far, ofs;
|
||||
|
||||
read_sector = grub_divmod64 (sector, array->chunk_size, &b);
|
||||
far = ofs = near = 1;
|
||||
|
@ -351,7 +351,7 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
case 6:
|
||||
{
|
||||
grub_disk_addr_t read_sector;
|
||||
grub_uint32_t b, p, n, disknr, e;
|
||||
grub_uint64_t b, p, n, disknr, e;
|
||||
|
||||
/* n = 1 for level 4 and 5, 2 for level 6. */
|
||||
n = array->level / 3;
|
||||
|
|
|
@ -512,7 +512,7 @@ grub_scsi_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"unsupported SCSI block size");
|
||||
|
||||
grub_uint32_t sector_mod = 0;
|
||||
grub_uint64_t sector_mod = 0;
|
||||
sector = grub_divmod64 (sector, spb, §or_mod);
|
||||
|
||||
if (! (sector_mod == 0 && size % spb == 0))
|
||||
|
|
|
@ -125,7 +125,7 @@ grub_affs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
|
|||
int block = node->block;
|
||||
struct grub_affs_file file;
|
||||
struct grub_affs_data *data = node->data;
|
||||
grub_uint32_t mod;
|
||||
grub_uint64_t mod;
|
||||
|
||||
/* Find the block that points to the fileblock we are looking up by
|
||||
following the chain until the right table is reached. */
|
||||
|
|
|
@ -649,7 +649,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
|
||||
chunk_found:
|
||||
{
|
||||
grub_uint32_t stripen;
|
||||
grub_uint64_t stripen;
|
||||
grub_uint64_t stripe_offset;
|
||||
grub_uint64_t off = addr - grub_le_to_cpu64 (key->offset);
|
||||
unsigned redundancy = 1;
|
||||
|
@ -679,10 +679,10 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
{
|
||||
grub_uint64_t stripe_length;
|
||||
grub_dprintf ("btrfs", "single\n");
|
||||
stripe_length = grub_divmod64_full (grub_le_to_cpu64 (chunk->size),
|
||||
grub_le_to_cpu16 (chunk->nstripes),
|
||||
NULL);
|
||||
stripen = grub_divmod64_full (off, stripe_length, &stripe_offset);
|
||||
stripe_length = grub_divmod64 (grub_le_to_cpu64 (chunk->size),
|
||||
grub_le_to_cpu16 (chunk->nstripes),
|
||||
NULL);
|
||||
stripen = grub_divmod64 (off, stripe_length, &stripe_offset);
|
||||
csize = (stripen + 1) * stripe_length - off;
|
||||
break;
|
||||
}
|
||||
|
@ -699,7 +699,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
case GRUB_BTRFS_CHUNK_TYPE_RAID0:
|
||||
{
|
||||
grub_uint64_t middle, high;
|
||||
grub_uint32_t low;
|
||||
grub_uint64_t low;
|
||||
grub_dprintf ("btrfs", "RAID0\n");
|
||||
middle = grub_divmod64 (off,
|
||||
grub_le_to_cpu64 (chunk->stripe_length),
|
||||
|
@ -715,7 +715,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
case GRUB_BTRFS_CHUNK_TYPE_RAID10:
|
||||
{
|
||||
grub_uint64_t middle, high;
|
||||
grub_uint32_t low;
|
||||
grub_uint64_t low;
|
||||
middle = grub_divmod64 (off,
|
||||
grub_le_to_cpu64 (chunk->stripe_length),
|
||||
&low);
|
||||
|
@ -760,7 +760,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
|||
|
||||
grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
|
||||
"+0x%" PRIxGRUB_UINT64_T " (%d stripes (%d substripes) of %"
|
||||
PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT32_T
|
||||
PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT64_T
|
||||
" maps to 0x%" PRIxGRUB_UINT64_T "\n",
|
||||
grub_le_to_cpu64 (key->offset),
|
||||
grub_le_to_cpu64 (chunk->size),
|
||||
|
|
|
@ -306,7 +306,8 @@ grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len)
|
|||
struct grub_pxenv_tftp_read c;
|
||||
struct grub_pxe_data *data;
|
||||
struct grub_pxe_disk_data *disk_data = file->device->disk->data;
|
||||
grub_uint32_t pn, r;
|
||||
grub_uint32_t pn;
|
||||
grub_uint64_t r;
|
||||
|
||||
data = file->data;
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ grub_minix_read_file (struct grub_minix_data *data,
|
|||
grub_disk_addr_t i;
|
||||
grub_disk_addr_t blockcnt;
|
||||
grub_uint64_t posblock;
|
||||
grub_uint32_t blockoff;
|
||||
grub_uint64_t blockoff;
|
||||
|
||||
/* Adjust len so it we can't read past the end of the file. */
|
||||
if (len + pos > GRUB_MINIX_INODE_SIZE (data))
|
||||
|
@ -242,7 +242,7 @@ grub_minix_read_file (struct grub_minix_data *data,
|
|||
for (i = posblock; i < blockcnt; i++)
|
||||
{
|
||||
grub_disk_addr_t blknr;
|
||||
grub_uint32_t blockend = data->block_size;
|
||||
grub_uint64_t blockend = data->block_size;
|
||||
grub_off_t skipfirst = 0;
|
||||
|
||||
blknr = grub_minix_get_file_block (data, i);
|
||||
|
|
|
@ -303,7 +303,7 @@ grub_nilfs2_palloc_entries_per_group (struct grub_nilfs2_data *data)
|
|||
|
||||
static inline grub_uint64_t
|
||||
grub_nilfs2_palloc_group (struct grub_nilfs2_data *data,
|
||||
grub_uint64_t nr, grub_uint32_t * offset)
|
||||
grub_uint64_t nr, grub_uint64_t * offset)
|
||||
{
|
||||
return grub_divmod64 (nr, grub_nilfs2_palloc_entries_per_group (data),
|
||||
offset);
|
||||
|
@ -368,13 +368,15 @@ grub_nilfs2_palloc_entry_offset (struct grub_nilfs2_data *data,
|
|||
grub_uint64_t nr, unsigned long entry_size)
|
||||
{
|
||||
unsigned long group;
|
||||
grub_uint32_t group_offset;
|
||||
grub_uint64_t group_offset;
|
||||
|
||||
group = grub_nilfs2_palloc_group (data, nr, &group_offset);
|
||||
|
||||
return grub_nilfs2_palloc_bitmap_block_offset (data, group,
|
||||
entry_size) + 1 +
|
||||
group_offset / grub_nilfs2_entries_per_block (data, entry_size);
|
||||
grub_divmod64 (group_offset, grub_nilfs2_entries_per_block (data,
|
||||
entry_size),
|
||||
NULL);
|
||||
|
||||
}
|
||||
|
||||
|
@ -577,7 +579,7 @@ grub_nilfs2_dat_translate (struct grub_nilfs2_data *data, grub_uint64_t key)
|
|||
struct grub_nilfs2_dat_entry entry;
|
||||
grub_disk_t disk = data->disk;
|
||||
grub_uint64_t pptr;
|
||||
grub_uint32_t blockno, offset;
|
||||
grub_uint64_t blockno, offset;
|
||||
unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data));
|
||||
|
||||
blockno = grub_nilfs2_palloc_entry_offset (data, key,
|
||||
|
@ -641,7 +643,7 @@ grub_nilfs2_read_checkpoint (struct grub_nilfs2_data *data,
|
|||
struct grub_nilfs2_checkpoint *cpp)
|
||||
{
|
||||
grub_uint64_t blockno;
|
||||
grub_uint32_t offset;
|
||||
grub_uint64_t offset;
|
||||
grub_uint64_t pptr;
|
||||
grub_disk_t disk = data->disk;
|
||||
unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data));
|
||||
|
@ -679,7 +681,7 @@ grub_nilfs2_read_inode (struct grub_nilfs2_data *data,
|
|||
grub_uint64_t ino, struct grub_nilfs2_inode *inodep)
|
||||
{
|
||||
grub_uint64_t blockno;
|
||||
unsigned int offset;
|
||||
grub_uint64_t offset;
|
||||
grub_uint64_t pptr;
|
||||
grub_disk_t disk = data->disk;
|
||||
unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data));
|
||||
|
|
|
@ -431,7 +431,7 @@ read_data (struct grub_ntfs_attr *at, char *pa, char *dest,
|
|||
if (at->flags & AF_GPOS)
|
||||
{
|
||||
grub_disk_addr_t st0, st1;
|
||||
grub_uint32_t m;
|
||||
grub_uint64_t m;
|
||||
|
||||
grub_divmod64 (ofs >> BLK_SHR, ctx->comp.spc, &m);
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ grub_bufio_read (grub_file_t file, char *buf, grub_size_t len)
|
|||
{
|
||||
grub_size_t res = len;
|
||||
grub_bufio_t bufio = file->data;
|
||||
grub_uint32_t pos;
|
||||
grub_uint64_t pos;
|
||||
|
||||
if ((file->offset >= bufio->file->offset) &&
|
||||
(file->offset < bufio->file->offset + bufio->buffer_len))
|
||||
|
|
|
@ -597,7 +597,7 @@ grub_reverse (char *str)
|
|||
|
||||
/* Divide N by D, return the quotient, and store the remainder in *R. */
|
||||
grub_uint64_t
|
||||
grub_divmod64_full (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r)
|
||||
grub_divmod64 (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r)
|
||||
{
|
||||
/* This algorithm is typically implemented by hardware. The idea
|
||||
is to get the highest bit in N, 64 times, by keeping
|
||||
|
@ -666,7 +666,7 @@ grub_lltoa (char *str, int c, unsigned long long n)
|
|||
/* BASE == 10 */
|
||||
do
|
||||
{
|
||||
unsigned m;
|
||||
grub_uint64_t m;
|
||||
|
||||
n = grub_divmod64 (n, 10, &m);
|
||||
*p++ = m + '0';
|
||||
|
|
|
@ -287,20 +287,9 @@ char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
|
|||
char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) __attribute__ ((warn_unused_result));
|
||||
void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
|
||||
void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn));
|
||||
grub_uint64_t EXPORT_FUNC(grub_divmod64_full) (grub_uint64_t n,
|
||||
grub_uint64_t d,
|
||||
grub_uint64_t *r);
|
||||
static inline grub_uint64_t grub_divmod64 (grub_uint64_t n,
|
||||
grub_uint32_t d,
|
||||
grub_uint32_t *r)
|
||||
{
|
||||
grub_uint64_t ret, rr;
|
||||
|
||||
ret = grub_divmod64_full (n, d, &rr);
|
||||
if (r)
|
||||
*r = rr;
|
||||
return ret;
|
||||
}
|
||||
grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
|
||||
grub_uint64_t d,
|
||||
grub_uint64_t *r);
|
||||
|
||||
#if NEED_ENABLE_EXECUTE_STACK && !defined(GRUB_UTIL)
|
||||
void EXPORT_FUNC(__enable_execute_stack) (void *addr);
|
||||
|
|
Loading…
Reference in a new issue