dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0202-grub-core-fs-hfs.c-grub_hfs_read_file-Avoid-divmod64.patch

f96e0b
From 816fd37ee87127911c61b5464dfdd25145b36e1c Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Sun, 10 Mar 2013 18:27:53 +0100
f96e0b
Subject: [PATCH 202/482] 	* grub-core/fs/hfs.c (grub_hfs_read_file):
f96e0b
 Avoid divmod64 since the 	maximum size is 4G - 1 on hfs
f96e0b
f96e0b
---
f96e0b
 ChangeLog          |  5 +++++
f96e0b
 grub-core/fs/hfs.c | 15 ++++++++-------
f96e0b
 2 files changed, 13 insertions(+), 7 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index bc51ae9..931ae8e 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,5 +1,10 @@
f96e0b
 2013-03-10  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
+	* grub-core/fs/hfs.c (grub_hfs_read_file): Avoid divmod64 since the
f96e0b
+	maximum size is 4G - 1 on hfs
f96e0b
+
f96e0b
+2013-03-10  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
 	Avoid costly 64-bit division in grub_get_time_ms on most platforms.
f96e0b
 
f96e0b
 2013-03-10  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c
f96e0b
index 73ac7f9..14520c0 100644
f96e0b
--- a/grub-core/fs/hfs.c
f96e0b
+++ b/grub-core/fs/hfs.c
f96e0b
@@ -244,15 +244,16 @@ grub_hfs_block (struct grub_hfs_data *data, grub_hfs_datarecord_t dat,
f96e0b
 static grub_ssize_t
f96e0b
 grub_hfs_read_file (struct grub_hfs_data *data,
f96e0b
 		    grub_disk_read_hook_t read_hook, void *read_hook_data,
f96e0b
-		    grub_off_t pos, grub_size_t len, char *buf)
f96e0b
+		    grub_uint32_t pos, grub_size_t len, char *buf)
f96e0b
 {
f96e0b
   grub_off_t i;
f96e0b
   grub_off_t blockcnt;
f96e0b
 
f96e0b
-  blockcnt = grub_divmod64 (((len + pos)
f96e0b
-			     + data->blksz - 1), data->blksz, 0);
f96e0b
+  /* Files are at most 2G/4G - 1 bytes on hfs. Avoid 64-bit division.
f96e0b
+     Moreover len > 0 as checked in upper layer.  */
f96e0b
+  blockcnt = (len + pos - 1) / data->blksz + 1;
f96e0b
 
f96e0b
-  for (i = grub_divmod64 (pos, data->blksz, 0); i < blockcnt; i++)
f96e0b
+  for (i = pos / data->blksz; i < blockcnt; i++)
f96e0b
     {
f96e0b
       grub_disk_addr_t blknr;
f96e0b
       grub_off_t blockoff;
f96e0b
@@ -260,7 +261,7 @@ grub_hfs_read_file (struct grub_hfs_data *data,
f96e0b
 
f96e0b
       int skipfirst = 0;
f96e0b
 
f96e0b
-      grub_divmod64 (pos, data->blksz, &blockoff);
f96e0b
+      blockoff = pos % data->blksz;
f96e0b
 
f96e0b
       blknr = grub_hfs_block (data, data->extents, data->fileid, i, 1);
f96e0b
       if (grub_errno)
f96e0b
@@ -269,7 +270,7 @@ grub_hfs_read_file (struct grub_hfs_data *data,
f96e0b
       /* Last block.  */
f96e0b
       if (i == blockcnt - 1)
f96e0b
 	{
f96e0b
-	  grub_divmod64 ((len + pos), data->blksz, &blockend);
f96e0b
+	  blockend = (len + pos) % data->blksz;
f96e0b
 
f96e0b
 	  /* The last portion is exactly EXT2_BLOCK_SIZE (data).  */
f96e0b
 	  if (! blockend)
f96e0b
@@ -277,7 +278,7 @@ grub_hfs_read_file (struct grub_hfs_data *data,
f96e0b
 	}
f96e0b
 
f96e0b
       /* First block.  */
f96e0b
-      if (i == grub_divmod64 (pos, data->blksz, 0))
f96e0b
+      if (i == pos / data->blksz)
f96e0b
 	{
f96e0b
 	  skipfirst = blockoff;
f96e0b
 	  blockend -= skipfirst;
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b