Re: [PATCH v2] lib/hexdump update on feedback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Randy Dunlap <[email protected]>

Rename hex_dumper() to hex_dump_to_buffer().
Rename hextoasc() macro to hex_asc()
	[remove conflicts with sky/skfp/skge drivers].
Change output format to remove '-' in middle of ASCII output and
	add space between hex and ASCII output.

Signed-off-by: Randy Dunlap <[email protected]>
---
 include/linux/kernel.h |    4 ++--
 lib/hexdump.c          |   40 ++++++++++++++++++++--------------------
 2 files changed, 22 insertions(+), 22 deletions(-)

--- linux-2.6.21-git4.orig/include/linux/kernel.h
+++ linux-2.6.21-git4/include/linux/kernel.h
@@ -207,11 +207,11 @@ enum {
 	DUMP_PREFIX_ADDRESS,
 	DUMP_PREFIX_OFFSET
 };
-extern void hex_dumper(const void *buf, size_t len, char *linebuf,
+extern void hex_dump_to_buffer(const void *buf, size_t len, char *linebuf,
 				size_t linebuflen);
 extern void print_hex_dump(const char *level, int prefix_type,
 				void *buf, size_t len);
-#define hextoasc(x)	"0123456789abcdef"[x]
+#define hex_asc(x)	"0123456789abcdef"[x]
 
 #ifdef DEBUG
 /* If you are writing a driver, please use dev_dbg instead */
--- linux-2.6.21-git4.orig/lib/hexdump.c
+++ linux-2.6.21-git4/lib/hexdump.c
@@ -13,26 +13,27 @@
 #include <linux/module.h>
 
 /**
- * hex_dumper - convert a blob of data to "hex ASCII" in memory
+ * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
  * @buf: data blob to dump
  * @len: number of bytes in the @buf
  * @linebuf: where to put the converted data
  * @linebuflen: total size of @linebuf, including space for terminating NUL
  *
- * hex_dumper() works on one "line" of output at a time, i.e.,
+ * hex_dump_to_buffer() works on one "line" of output at a time, i.e.,
  * 16 bytes of input data converted to hex + ASCII output.
  *
- * Given a buffer of u8 data, hex_dumper() converts the input data to a
- * hex + ASCII dump at the supplied memory location.
+ * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data
+ * to a hex + ASCII dump at the supplied memory location.
  * The converted output is always NUL-terminated.
  *
  * E.g.:
- *	hex_dumper(frame->data, frame->len, linebuf, sizeof(linebuf));
+ *	hex_dump_to_buffer(frame->data, frame->len, linebuf, sizeof(linebuf));
  *
- * Prints the offsets of the block of memory, not addresses:
- * 0009ab42: 40414243 44454647 48494a4b 4c4d4e4f-@ABCDEFG HIJKLMNO
+ * example output buffer:
+ * 40414243 44454647 48494a4b 4c4d4e4f  @ABCDEFGHIJKLMNO
  */
-void hex_dumper(const void *buf, size_t len, char *linebuf, size_t linebuflen)
+void hex_dump_to_buffer(const void *buf, size_t len, char *linebuf,
+			size_t linebuflen)
 {
 	const u8 *ptr = buf;
 	u8 ch;
@@ -42,19 +43,18 @@ void hex_dumper(const void *buf, size_t 
 		if (j && !(j % 4))
 			linebuf[lx++] = ' ';
 		ch = ptr[j];
-		linebuf[lx++] = hextoasc(ch >> 4);
-		linebuf[lx++] = hextoasc(ch & 0x0f);
+		linebuf[lx++] = hex_asc(ch >> 4);
+		linebuf[lx++] = hex_asc(ch & 0x0f);
 	}
-	if (lx < linebuflen)
-		linebuf[lx++] = '-';
-	for (j = 0; (j < 16) && (j < len) && (lx + 2) < linebuflen; j++) {
-		linebuf[lx++] = isprint(ptr[j]) ?  ptr[j] : '.';
-		if (j == 7)
-			linebuf[lx++] = ' ';
+	if ((lx + 2) < linebuflen) {
+		linebuf[lx++] = ' ';
+		linebuf[lx++] = ' ';
 	}
+	for (j = 0; (j < 16) && (j < len) && (lx + 2) < linebuflen; j++)
+		linebuf[lx++] = isprint(ptr[j]) ? ptr[j] : '.';
 	linebuf[lx++] = '\0';
 }
-EXPORT_SYMBOL(hex_dumper);
+EXPORT_SYMBOL(hex_dump_to_buffer);
 
 /**
  * print_hex_dump - print a text hex dump to syslog for a binary blob of data
@@ -72,9 +72,9 @@ EXPORT_SYMBOL(hex_dumper);
  *   print_hex_dump(KERN_DEBUG, DUMP_PREFIX_ADDRESS, frame->data, frame->len);
  *
  * Example output using %DUMP_PREFIX_OFFSET:
- * 0009ab42: 40414243 44454647 48494a4b 4c4d4e4f-@ABCDEFG HIJKLMNO
+ * 0009ab42: 40414243 44454647 48494a4b 4c4d4e4f  @ABCDEFGHIJKLMNO
  * Example output using %DUMP_PREFIX_ADDRESS:
- * ffffffff88089af0: 70717273 74757677 78797a7b 7c7d7e7f-pqrstuvw xyz{|}~.
+ * ffffffff88089af0: 70717273 74757677 78797a7b 7c7d7e7f  pqrstuvwxyz{|}~.
  */
 void print_hex_dump(const char *level, int prefix_type, void *buf, size_t len)
 {
@@ -85,7 +85,7 @@ void print_hex_dump(const char *level, i
 	for (i = 0; i < len; i += 16) {
 		linelen = min(remaining, 16);
 		remaining -= 16;
-		hex_dumper(ptr + i, linelen, linebuf, sizeof(linebuf));
+		hex_dump_to_buffer(ptr + i, linelen, linebuf, sizeof(linebuf));
 
 		switch (prefix_type) {
 		case DUMP_PREFIX_ADDRESS:
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux