linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@dilger.ca>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org, Andreas Dilger <adilger@dilger.ca>
Subject: [PATCH 2/4] filefrag: improve extent flags printing
Date: Mon, 16 Dec 2013 18:05:29 -0700	[thread overview]
Message-ID: <1387242331-29227-2-git-send-email-adilger@dilger.ca> (raw)
In-Reply-To: <1387242331-29227-1-git-send-email-adilger@dilger.ca>

Improve the handling of printing extent flags in verbose mode.
For unknown flags, print out the flag value in hexadecimal.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
---
 misc/filefrag.c |   60 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/misc/filefrag.c b/misc/filefrag.c
index 18dc1e5..6289899 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -120,6 +120,15 @@ static void print_extent_header(void)
 	       "expected:");
 }
 
+static void print_flag(__u32 *flags, __u32 mask, char *buf, const char *name)
+{
+	if ((*flags & mask) == 0)
+		return;
+
+	strcat(buf, name);
+	*flags &= ~mask;
+}
+
 static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex,
 			      unsigned long long expected, int blk_shift,
 			      ext2fs_struct_stat *st)
@@ -128,10 +137,12 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex,
 	unsigned long long logical_blk;
 	unsigned long long ext_len;
 	unsigned long long ext_blks;
-	char flags[256] = "";
+	__u32 flags, mask;
+	char buf[256] = "";
 
+	flags = fm_extent->fe_flags;
 	/* For inline data all offsets should be in bytes, not blocks */
-	if (fm_extent->fe_flags & FIEMAP_EXTENT_DATA_INLINE)
+	if (flags & FIEMAP_EXTENT_DATA_INLINE)
 		blk_shift = 0;
 
 	ext_len = fm_extent->fe_length >> blk_shift;
@@ -140,34 +151,35 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex,
 	physical_blk = fm_extent->fe_physical >> blk_shift;
 
 	if (expected)
-		sprintf(flags, ext_fmt == hex_fmt ? "%*llx: " : "%*llu: ",
+		sprintf(buf, ext_fmt == hex_fmt ? "%*llx: " : "%*llu: ",
 			physical_width, expected >> blk_shift);
 	else
-		sprintf(flags, "%.*s  ", physical_width, "                   ");
-
-	if (fm_extent->fe_flags & FIEMAP_EXTENT_UNKNOWN)
-		strcat(flags, "unknown,");
-	if (fm_extent->fe_flags & FIEMAP_EXTENT_DELALLOC)
-		strcat(flags, "delalloc,");
-	if (fm_extent->fe_flags & FIEMAP_EXTENT_DATA_ENCRYPTED)
-		strcat(flags, "encrypted,");
-	if (fm_extent->fe_flags & FIEMAP_EXTENT_NOT_ALIGNED)
-		strcat(flags, "not_aligned,");
-	if (fm_extent->fe_flags & FIEMAP_EXTENT_DATA_INLINE)
-		strcat(flags, "inline,");
-	if (fm_extent->fe_flags & FIEMAP_EXTENT_DATA_TAIL)
-		strcat(flags, "tail_packed,");
-	if (fm_extent->fe_flags & FIEMAP_EXTENT_UNWRITTEN)
-		strcat(flags, "unwritten,");
-	if (fm_extent->fe_flags & FIEMAP_EXTENT_MERGED)
-		strcat(flags, "merged,");
+		sprintf(buf, "%.*s  ", physical_width, "                   ");
+
+	print_flag(&flags, FIEMAP_EXTENT_UNKNOWN, buf, "unknown,");
+	print_flag(&flags, FIEMAP_EXTENT_DELALLOC, buf, "delalloc,");
+	print_flag(&flags, FIEMAP_EXTENT_DATA_ENCRYPTED, buf, "encrypted,");
+	print_flag(&flags, FIEMAP_EXTENT_NOT_ALIGNED, buf, "not_aligned,");
+	print_flag(&flags, FIEMAP_EXTENT_DATA_INLINE, buf, "inline,");
+	print_flag(&flags, FIEMAP_EXTENT_DATA_TAIL, buf, "tail_packed,");
+	print_flag(&flags, FIEMAP_EXTENT_UNWRITTEN, buf, "unwritten,");
+	print_flag(&flags, FIEMAP_EXTENT_MERGED, buf, "merged,");
+	print_flag(&flags, FIEMAP_EXTENT_LAST, buf, "last,");
+	/* Print unknown flags in hex format.  Known flags are already printed
+	 * above and will have their bit cleared from "flags". */
+	for (mask = 1; flags != 0 && mask != 0; mask <<= 1) {
+		char hex[6];
+
+		sprintf(hex, "%04x,", mask);
+		print_flag(&flags, mask, buf, hex);
+	}
 
 	if (fm_extent->fe_logical + fm_extent->fe_length >= (__u64) st->st_size)
-		strcat(flags, "eof,");
+		strcat(buf, "eof,");
 
 	/* Remove trailing comma, if any */
-	if (flags[0])
-		flags[strlen(flags) - 1] = '\0';
+	if (buf[0])
+		buf[strlen(buf) - 1] = '\0';
 
 	printf(ext_fmt, cur_ex, logical_width, logical_blk,
 	       logical_width, logical_blk + ext_blks,
-- 
1.7.3.4


  reply	other threads:[~2013-12-17  1:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-17  1:05 [PATCH 1/4] filefrag: exit with error code on failure Andreas Dilger
2013-12-17  1:05 ` Andreas Dilger [this message]
2013-12-17  1:05 ` [PATCH 3/4] filefrag: reserve fields and new extent flags Andreas Dilger
2013-12-17  1:05 ` [PATCH 4/4] filefrag: print out physical extent length if set Andreas Dilger

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=1387242331-29227-2-git-send-email-adilger@dilger.ca \
    --to=adilger@dilger.ca \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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).