From 34e3152b64368d4a3672084ebae565d55f320f5d Mon Sep 17 00:00:00 2001
From: Lucas Meneghel Rodrigues <lmr@redhat.com>
Date: Tue, 18 May 2010 10:40:15 -0300
Subject: [PATCH 1/2] Minor fixes to PAGE_SIZE handling

Signed-off-by: Suzuki <suzuki@in.ibm.com>
---
 fsx-linux.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/fsx-linux.c b/fsx-linux.c
index a1642d2..33eb770 100644
--- a/fsx-linux.c
+++ b/fsx-linux.c
@@ -10,6 +10,8 @@
  *
  *	Small changes to work under Linux -- davej@suse.de
  *
+ *	Minor fixes to PAGE_SIZE handling -- Suzuki <suzuki@in.ibm.com>.
+ *
  */
 
 #undef _XOPEN_SOURCE
@@ -74,7 +76,7 @@ int			logcount = 0;	/* total ops */
 #define OP_SKIPPED	7
 
 #ifndef PAGE_SIZE
-#define PAGE_SIZE       4096
+#define PAGE_SIZE       pagesize
 #endif
 #define PAGE_MASK       (PAGE_SIZE - 1)
 
@@ -129,6 +131,7 @@ int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset);
 FILE *	fsxlogf = NULL;
 int badoff = -1;
 int closeopen = 0;
+int pagesize = 0;
 
 static void *round_up(void *ptr, unsigned long align, unsigned long offset)
 {
@@ -493,7 +496,7 @@ domapread(unsigned offset, unsigned size)
 		    offset, offset + size - 1, size);
 
 	pg_offset = offset & PAGE_MASK;
-	map_size  = pg_offset + size;
+	map_size  = (pg_offset + size + PAGE_MASK) & ~PAGE_MASK;
 
 #ifdef linux
 	if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_SHARED, fd,
@@ -638,7 +641,7 @@ domapwrite(unsigned offset, unsigned size)
 		}
 	}
 	pg_offset = offset & PAGE_MASK;
-	map_size  = pg_offset + size;
+	map_size  = (pg_offset + size + PAGE_MASK) & ~PAGE_MASK;
 
 	if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
 			      MAP_FILE | MAP_SHARED, fd,
@@ -1106,6 +1109,7 @@ main(int argc, char **argv)
 	if (argc != 1)
 		usage();
 	fname = argv[0];
+	pagesize = getpagesize();
 
 	signal(SIGHUP,	cleanup);
 	signal(SIGINT,	cleanup);
-- 
1.7.0.1