linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-xfs@vger.kernel.org
Cc: sandeen@redhat.com, Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 5/6] fiemap: Factor out common code used for printing holes
Date: Thu, 24 Aug 2017 14:47:51 +0300	[thread overview]
Message-ID: <1503575272-28263-6-git-send-email-nborisov@suse.com> (raw)
In-Reply-To: <1503575272-28263-1-git-send-email-nborisov@suse.com>

The code responsible for printing holes is scattered across 3 places:
plain print function, verbose print function and in the block handling EOF hole.
Introduce a new function factoring out the common code and replace the 3 sites
where the code is used with it. This reduces duplication and makes it apparent
when we are printing holes. No functional changes.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 io/fiemap.c | 66 +++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 36 insertions(+), 30 deletions(-)

diff --git a/io/fiemap.c b/io/fiemap.c
index 0f04b874fd5f..44a64870d711 100644
--- a/io/fiemap.c
+++ b/io/fiemap.c
@@ -52,6 +52,36 @@ fiemap_help(void)
 "\n"));
 }
 
+static void
+print_hole(
+	   int		foff_w,
+	   int		boff_w,
+	   int		tot_w,
+	   int		cur_extent,
+	   int		lflag,
+	   bool		plain,
+	   __u64	llast,
+	   __u64	lstart)
+{
+	   char		lbuf[48];
+
+	   if (plain) {
+		printf("\t%d: [%llu..%llu]: hole", cur_extent,
+		       llast, lstart - 1ULL);
+		if (lflag)
+			printf(_(" %llu blocks\n"), lstart - llast);
+		else
+			printf("\n");
+	   } else {
+		snprintf(lbuf, sizeof(lbuf), "[%llu..%llu]:", llast,
+			 lstart - 1ULL);
+		printf("%4d: %-*s %-*s %*llu\n", cur_extent, foff_w, lbuf,
+		       boff_w, _("hole"), tot_w, lstart - llast);
+	   }
+
+
+}
+
 static int
 print_verbose(
 	struct fiemap_extent	*extent,
@@ -87,11 +117,8 @@ print_verbose(
 	}
 
 	if (lstart != llast) {
-		snprintf(lbuf, sizeof(lbuf), "[%llu..%llu]:", llast,
-			 lstart - 1ULL);
-		printf("%4d: %-*s %-*s %*llu\n", cur_extent, foff_w, lbuf,
-		       boff_w, _("hole"), tot_w, lstart - llast);
-		memset(lbuf, 0, sizeof(lbuf));
+		print_hole(foff_w, boff_w, tot_w, cur_extent, 0, false, llast,
+			   lstart);
 		cur_extent++;
 	}
 
@@ -126,12 +153,7 @@ print_plain(
 	block = BTOBBT(extent->fe_physical);
 
 	if (lstart != llast) {
-		printf("\t%d: [%llu..%llu]: hole", cur_extent,
-		       llast, lstart - 1ULL);
-		if (lflag)
-			printf(_(" %llu blocks\n"), lstart - llast);
-		else
-			printf("\n");
+		print_hole(0, 0, 0, cur_extent, lflag, true, llast, lstart);
 		cur_extent++;
 	}
 
@@ -309,25 +331,9 @@ fiemap_f(
 		return 0;
 	}
 
-	if (cur_extent && last_logical < st.st_size) {
-		char	lbuf[32];
-
-		snprintf(lbuf, sizeof(lbuf), "[%llu..%llu]:",
-			 BTOBBT(last_logical), BTOBBT(st.st_size) - 1);
-		if (vflag) {
-			printf("%4d: %-*s %-*s %*llu\n", cur_extent,
-			       foff_w, lbuf, boff_w, _("hole"), tot_w,
-			       BTOBBT(st.st_size - last_logical));
-		} else {
-			printf("\t%d: %s %s", cur_extent, lbuf,
-			       _("hole"));
-			if (lflag)
-				printf(_(" %llu blocks\n"),
-				       BTOBBT(st.st_size - last_logical));
-			else
-				printf("\n");
-		}
-	}
+	if (cur_extent && last_logical < st.st_size)
+		print_hole(foff_w, boff_w, tot_w, cur_extent, lflag, !vflag,
+			   BTOBBT(last_logical), BTOBBT(st.st_size));
 
 out:
 	free(fiemap);
-- 
2.7.4


  parent reply	other threads:[~2017-08-24 11:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24 11:47 [PATCH 0/6] Fiemap refactoring Nikolay Borisov
2017-08-24 11:47 ` [PATCH 1/6] fiemap: Remove blocksize variable Nikolay Borisov
2017-08-24 11:47 ` [PATCH 2/6] fiemap: Make max_extents a global var Nikolay Borisov
2017-08-24 11:47 ` [PATCH 3/6] fiemap: Eliminate num_extents Nikolay Borisov
2017-08-24 11:47 ` [PATCH 4/6] fiemap: De-obfuscate last_logical and cur_extent manipulation Nikolay Borisov
2017-08-24 11:47 ` Nikolay Borisov [this message]
2017-08-24 11:47 ` [PATCH 6/6] fiemap: Fix semantics of max_extents (-n arguments) Nikolay Borisov
2017-08-24 16:03   ` Eric Sandeen
2017-08-24 16:06     ` Nikolay Borisov
2017-08-24 16:07       ` Eric Sandeen
2017-08-24 17:51   ` Darrick J. Wong
2017-08-24 18:43     ` Eric Sandeen
2017-08-24 20:09 ` [PATCH 7/6] xfs_bmap: fix -n documentation in manpage Eric Sandeen
2017-08-24 20:56   ` Darrick J. Wong

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=1503575272-28263-6-git-send-email-nborisov@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.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;
as well as URLs for NNTP newsgroup(s).