]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Use shifts in squash4.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 28 Oct 2011 14:05:16 +0000 (16:05 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 28 Oct 2011 14:05:16 +0000 (16:05 +0200)
* grub-core/fs/squash4.c (grub_squash_data): New field log2_blksz.
(squash_mount): Check block size and take logarithm.
(direct_read): Use shifts.

ChangeLog
grub-core/fs/squash4.c

index 64ae05ef497d5fe178c438e0c3b056d6e5f6bde3..6d0cfde930f117df1c0a9011bf9282f2d53ffb3a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-10-28  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Use shifts in squash4.
+
+       * grub-core/fs/squash4.c (grub_squash_data): New field log2_blksz.
+       (squash_mount): Check block size and take logarithm.
+       (direct_read): Use shifts.
+
 2011-10-28  Vladimir Serbinenko  <phcoder@gmail.com>
 
        Correct befs block counting logic.
index d45732c16a2d09c249fc2d72ecf935eb5e76ae7c..a3832b6be532e5b8c580241b4c198b2131f5b1fa 100644 (file)
@@ -173,6 +173,7 @@ struct grub_squash_data
   struct grub_squash_super sb;
   struct grub_squash_cache_inode ino;
   grub_uint64_t fragments;
+  int log2_blksz;
 };
 
 struct grub_fshelp_node
@@ -267,7 +268,10 @@ squash_mount (grub_disk_t disk)
     grub_error (GRUB_ERR_BAD_FS, "not a squash4");
   if (err)
     return NULL;
-  if (grub_le_to_cpu32 (sb.magic) != SQUASH_MAGIC)
+  if (grub_le_to_cpu32 (sb.magic) != SQUASH_MAGIC
+      || grub_le_to_cpu32 (sb.block_size) == 0
+      || ((grub_le_to_cpu32 (sb.block_size) - 1)
+         & grub_le_to_cpu32 (sb.block_size)))
     {
       grub_error (GRUB_ERR_BAD_FS, "not squash4");
       return NULL;
@@ -290,6 +294,10 @@ squash_mount (grub_disk_t disk)
   data->disk = disk;
   data->fragments = grub_le_to_cpu64 (frag);
 
+  for (data->log2_blksz = 0; 
+       (1U << data->log2_blksz) < grub_le_to_cpu32 (data->sb.block_size);
+       data->log2_blksz++);
+
   return data;
 }
 
@@ -528,10 +536,9 @@ direct_read (struct grub_squash_data *data,
          block_offset = ((char *) &ino->ino.file.block_size
                          - (char *) &ino->ino);
        }
-      total_blocks = grub_divmod64 (total_size
-                                   + grub_le_to_cpu32 (data->sb.block_size) - 1,
-                                   grub_le_to_cpu32 (data->sb.block_size),
-                                   0);
+      total_blocks = ((total_size
+                     + grub_le_to_cpu32 (data->sb.block_size) - 1)
+                     >> data->log2_blksz);
       ino->block_sizes = grub_malloc (total_blocks
                                      * sizeof (ino->block_sizes[0]));
       ino->cumulated_block_sizes = grub_malloc (total_blocks
@@ -565,7 +572,7 @@ direct_read (struct grub_squash_data *data,
 
   if (a == 0)
     a = sizeof (struct grub_squash_super);
-  i = grub_divmod64 (off, grub_le_to_cpu32 (data->sb.block_size), 0);
+  i = off >> data->log2_blksz;
   cumulated_uncompressed_size = grub_le_to_cpu32 (data->sb.block_size)
     * (grub_disk_addr_t) i;
   while (cumulated_uncompressed_size < off + len)