public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <aelder@sgi.com>
To: xfs@oss.sgi.com
Subject: [PATCH 09/11] xfstests: randholes: clean up readblks()
Date: Thu, 14 Oct 2010 09:50:51 -0500	[thread overview]
Message-ID: <1287067851.2362.224.camel@doink> (raw)

Make readblks() a bit more readable by computing a few things
into local variables, and pulling out a few of the comma-separated
expressions that were previously in the for loop headers.

Signed-off-by: Alex Elder <aelder@sgi.com>

---
 src/randholes.c |   55 +++++++++++++++++++++++++++----------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

Index: b/src/randholes.c
===================================================================
--- a/src/randholes.c
+++ b/src/randholes.c
@@ -188,7 +188,7 @@ writeblks(char *fname, int fd, size_t al
 int
 readblks(int fd, size_t alignment)
 {
-	unsigned long offset;
+	__uint64_t offset;
 	char *buffer, *tmp;
 	unsigned int xfer, block, i;
         int err=0;
@@ -208,49 +208,48 @@ readblks(int fd, size_t alignment)
 		perror("lseek");
 		exit(1);
 	}
-	for (offset = 0, block = 0; offset < filesize; offset += xfer) {
+	block = 0;
+	offset = 0;
+	while (offset < filesize) {
 		if ((i = read(fd, buffer, xfer) < xfer)) {
 			if (i < 2)
 				break;
 			perror("read");
 			exit(1);
 		}
-		for (tmp = buffer, i = 0; i < READ_XFER; i++, block++, tmp += blocksize) {
+		tmp = buffer;
+		for (i = 0; i < READ_XFER; i++) {
+			__uint64_t want;
+			__uint64_t first;
+			__uint64_t second;
+
 			if (verbose && ((block % 100) == 0)) {
 				printf("+");
 				fflush(stdout);
 			}
-			if (BITVAL(valid, block) == 0) {
-				if ((*(__uint64_t *)tmp != 0LL) ||
-				    (*(__uint64_t *)(tmp+256) != 0LL)) {
-					printf("mismatched data at offset=%llx, expected 0x%llx, got 0x%llx and 0x%llx\n",
-					       (unsigned long long)fileoffset + block * blocksize,
-					       0LL,
-					       *(unsigned long long *)tmp,
-					       *(unsigned long long *)(tmp+256));
-                                        err++;
-				}
-			} else {
-				if ( (*(__uint64_t *)tmp !=
-				      fileoffset + block * blocksize) ||
-				     (*(__uint64_t *)(tmp+256) !=
-				      fileoffset + block * blocksize) ) {
-					printf("mismatched data at offset=%llx, "
-					       "expected 0x%llx, got 0x%llx and 0x%llx\n",
-					       (unsigned long long)fileoffset + block * blocksize,
-					       (unsigned long long)fileoffset + block * blocksize,
-					       *(unsigned long long *)tmp,
-					       *(unsigned long long *)(tmp+256));
-                                        err++;
-				}
+
+			want = BITVAL(valid, block) ? offset : 0;
+			first = *(__uint64_t *) tmp;
+			second = *(__uint64_t *) (tmp + 256);
+			if (first != want || second != want) {
+				printf("mismatched data at offset=0x%" PRIx64
+					", expected 0x%" PRIx64
+					", got 0x%" PRIx64
+					" and 0x%" PRIx64 "\n",
+					 fileoffset + offset, want,
+					 first, second);
+				err++;
 			}
 			if (verbose > 2) {
 				printf("block %d blocksize %d\n", block,
 				       blocksize);
-				dumpblock((int *)tmp,
-					  fileoffset + block * blocksize,
+				dumpblock((int *)tmp, fileoffset + offset,
 					  blocksize);
 			}
+
+			block++;
+			offset += blocksize;
+			tmp += blocksize;
 		}
 	}
 	if (verbose)


_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

                 reply	other threads:[~2010-10-14 14:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1287067851.2362.224.camel@doink \
    --to=aelder@sgi.com \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox