]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Use full 64-bit division.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Wed, 18 May 2011 13:35:19 +0000 (15:35 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Wed, 18 May 2011 13:35:19 +0000 (15:35 +0200)
* 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.

15 files changed:
ChangeLog
grub-core/commands/ls.c
grub-core/disk/i386/pc/biosdisk.c
grub-core/disk/lvm.c
grub-core/disk/raid.c
grub-core/disk/scsi.c
grub-core/fs/affs.c
grub-core/fs/btrfs.c
grub-core/fs/i386/pc/pxe.c
grub-core/fs/minix.c
grub-core/fs/nilfs2.c
grub-core/fs/ntfs.c
grub-core/io/bufio.c
grub-core/kern/misc.c
include/grub/misc.h

index 7b44c32fcf90d2057ab559699f750df3808c2706..cd49e296e08eb84b526185d99b2e5b91b015869c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index 5fc648a9b6fa3f79faf04498696ce4dc28336b0a..4c4051a226273b7066a4b50579ff67f43d8e60ad 100644 (file)
@@ -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);
                }
index 1d47dc727c96816f722c8e10a535a1ecbe0d79a2..3baf20717e646c2c5431d95b6fa00453d2ee24c7 100644 (file)
@@ -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);
index 206e3e22095a6db816566fc1d9ff684c5feac39e..563b49b49f32b452efc46df7b9f7bfcbcf3f3b2c 100644 (file)
@@ -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);
index 946e6d2c2a1510aa6d96a3691c047f79e9217933..c6be3efde6183a34b4c8f057a83509a561342748 100644 (file)
@@ -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;
index 25f0e3aea25a6b9a1c428b3e225ba5f9a8a9ebf2..d683cbfe78116c9f9632cb0f65e13a1f9ef5d9aa 100644 (file)
@@ -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, &sector_mod);
 
       if (! (sector_mod == 0 && size % spb == 0))
index 7c2099410aa6761effdfc256745959f4b60fc5a2..e17540e2f5211b5b1f35346ba57419f68fb49cfe 100644 (file)
@@ -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.  */
index 59e91b5528e680de38a5b6f0dd0e76117b3da85a..533529e3f22edebaa042c3a77c874afa943ce55e 100644 (file)
@@ -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),
index 4304881fa47b9c6849436494ce9af002774849b4..7d86b78bf15d00e10d9757a091223d3b343347a7 100644 (file)
@@ -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;
 
index 91659b0f6c89e7cb7721ff2f9986db0ba373cb58..64a64cca03539c44f5e8a7effcfbc7b169abf0b7 100644 (file)
@@ -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);
index 4c8d7633cdb7fff4d7fe8a5bd34987a8458053cb..44fb213bd61077bdb90a7a804bd167e3047fb7d0 100644 (file)
@@ -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));
index 1a8d3f17f00a5cc6df9cc54e143d42a74f696317..5d128bcc0b2de15492ac42bee64ed253fcbf9c84 100644 (file)
@@ -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);
 
index 3b456c1d27def6153569090e5ff44164eb1a3a9b..adb38af5617bb4ecc7b1e2c48db82f3c2038f21b 100644 (file)
@@ -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))
index 1b4cdec66f12f8a103e75630a1e2b11145b054cc..a3dfabf82a98673519e704bb895d722c6692fab8 100644 (file)
@@ -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';
index 80588be33ab9c276c0606bde828a63068ad2429a..da4bd4a7e43cb809fdc6e9419c5c123dcf9545e8 100644 (file)
@@ -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);