linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH e2fsprogs] print "mostly-printable" xattr strings in debugfs
@ 2008-01-30  3:30 Eric Sandeen
  2008-02-18 16:35 ` Eric Sandeen
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2008-01-30  3:30 UTC (permalink / raw)
  To: ext4 development

Taking a cue from getfattr... if a string is "mostly"
printable characters, go ahead & print as a string,
and escape what's left over.

so we get:

Extended attributes stored in inode body: 
  selinux = "system_u:object_r:root_t:s0\000" (28)

instead of:

Extended attributes stored in inode body: 
  selinux = "73 79 73 74 65 6d 5f 75 3a 6f 62 6a 65 63 74 5f 72 3a 72 6f 6f 74 5f 74 3a 73 30 00 " (28)

(selinux includes the trailing null in "len" so it
never prints as a string today)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
 
Index: e2fsprogs-1.40.5/debugfs/debugfs.c
===================================================================
--- e2fsprogs-1.40.5.orig/debugfs/debugfs.c
+++ e2fsprogs-1.40.5/debugfs/debugfs.c
@@ -434,19 +434,21 @@ static int list_blocks_proc(ext2_filsys 
 
 static void dump_xattr_string(FILE *out, const char *str, int len)
 {
-	int printable = 1;
+	int printable = 0;
 	int i;
 	
-	/* check is string printable? */
+	/* check: is string "printable enough?" */
 	for (i = 0; i < len; i++)
-		if (!isprint(str[i])) {
-			printable = 0;
-			break;
-		}
+		if (isprint(str[i]))
+			printable++;
+
+	if (printable <= len*7/8)
+		printable = 0;
 
 	for (i = 0; i < len; i++)
 		if (printable)
-			fprintf(out, "%c", (unsigned char)str[i]);
+			fprintf(out, isprint(str[i]) ? "%c" : "\\%03o",
+				(unsigned char)str[i]);
 		else
 			fprintf(out, "%02x ", (unsigned char)str[i]);
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH e2fsprogs] print "mostly-printable" xattr strings in debugfs
  2008-01-30  3:30 [PATCH e2fsprogs] print "mostly-printable" xattr strings in debugfs Eric Sandeen
@ 2008-02-18 16:35 ` Eric Sandeen
  2008-02-19  3:16   ` Theodore Tso
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2008-02-18 16:35 UTC (permalink / raw)
  To: ext4 development

Eric Sandeen wrote:
> Taking a cue from getfattr... if a string is "mostly"
> printable characters, go ahead & print as a string,
> and escape what's left over.

Ted, ping on this?  Since we use selinux a lot, it'd be nice to have
something readable in debugfs output.

If there's anything you don't like about the patch I'll be happy to fix
it up.

Thanks,
-Eric

> so we get:
> 
> Extended attributes stored in inode body: 
>   selinux = "system_u:object_r:root_t:s0\000" (28)
> 
> instead of:
> 
> Extended attributes stored in inode body: 
>   selinux = "73 79 73 74 65 6d 5f 75 3a 6f 62 6a 65 63 74 5f 72 3a 72 6f 6f 74 5f 74 3a 73 30 00 " (28)
> 
> (selinux includes the trailing null in "len" so it
> never prints as a string today)
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
>  
> Index: e2fsprogs-1.40.5/debugfs/debugfs.c
> ===================================================================
> --- e2fsprogs-1.40.5.orig/debugfs/debugfs.c
> +++ e2fsprogs-1.40.5/debugfs/debugfs.c
> @@ -434,19 +434,21 @@ static int list_blocks_proc(ext2_filsys 
>  
>  static void dump_xattr_string(FILE *out, const char *str, int len)
>  {
> -	int printable = 1;
> +	int printable = 0;
>  	int i;
>  	
> -	/* check is string printable? */
> +	/* check: is string "printable enough?" */
>  	for (i = 0; i < len; i++)
> -		if (!isprint(str[i])) {
> -			printable = 0;
> -			break;
> -		}
> +		if (isprint(str[i]))
> +			printable++;
> +
> +	if (printable <= len*7/8)
> +		printable = 0;
>  
>  	for (i = 0; i < len; i++)
>  		if (printable)
> -			fprintf(out, "%c", (unsigned char)str[i]);
> +			fprintf(out, isprint(str[i]) ? "%c" : "\\%03o",
> +				(unsigned char)str[i]);
>  		else
>  			fprintf(out, "%02x ", (unsigned char)str[i]);
>  }
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH e2fsprogs] print "mostly-printable" xattr strings in debugfs
  2008-02-18 16:35 ` Eric Sandeen
@ 2008-02-19  3:16   ` Theodore Tso
  0 siblings, 0 replies; 3+ messages in thread
From: Theodore Tso @ 2008-02-19  3:16 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development

On Mon, Feb 18, 2008 at 10:35:37AM -0600, Eric Sandeen wrote:
> Eric Sandeen wrote:
> > Taking a cue from getfattr... if a string is "mostly"
> > printable characters, go ahead & print as a string,
> > and escape what's left over.
> 
> Ted, ping on this?  Since we use selinux a lot, it'd be nice to have
> something readable in debugfs output.

Thanks for reminding me.  It's been applied into the maint branch.

       	   	     	       	    	    - Ted

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-02-19  3:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-30  3:30 [PATCH e2fsprogs] print "mostly-printable" xattr strings in debugfs Eric Sandeen
2008-02-18 16:35 ` Eric Sandeen
2008-02-19  3:16   ` Theodore Tso

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).