From ed9ba06dd011b1e66bcb757f4cb5e4a4db54ecbc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 28 Oct 2011 16:05:16 +0200 Subject: [PATCH] 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. --- ChangeLog | 8 ++++++++ grub-core/fs/squash4.c | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 64ae05ef4..6d0cfde93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-10-28 Vladimir Serbinenko + + 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 Correct befs block counting logic. diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c index d45732c16..a3832b6be 100644 --- a/grub-core/fs/squash4.c +++ b/grub-core/fs/squash4.c @@ -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)