[klibc] fancy dump_fs for nfsmount

Erik van Konijnenburg ekonijn at xs4all.nl
Sun Jun 5 05:14:48 PDT 2005


The dump_fh() function in nfsmount can be misleading: always
mentions NFS_FHSIZE as size, but can print more,
can print nothing if passed less than 8 bytes.

This is a more robust implementation also suitable
for printing datastructures other than the file handle,
with ASCII rendering as bonus; output like so:

stuff: 0xbfffe41c, length 30
0000: 53 75 6e 20  4a 75 6e 20  20 35 20 31  34 3a 31 32  Sun  Jun   5 1 4:12
0010: 3a 35 33 20  43 45 53 54  20 32 30 30  35 0a        :53  CEST 200 5.


Signed-off-by: Erik van Konijnenburg <ekonijn at xs4all.nl>

Index: klibc-1.0.14/nfsmount/mount.c
===================================================================
--- klibc-1.0.14.orig/nfsmount/mount.c	2005-06-04 13:50:02.000000000 +0200
+++ klibc-1.0.14/nfsmount/mount.c	2005-06-04 15:07:52.000000000 +0200
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "nfsmount.h"
 #include "sunrpc.h"
@@ -92,6 +93,32 @@
 	return (len + 3) & ~3;
 }
 
+
+#ifdef NFS_DEBUG
+void hex_dump (const char *msg, const char *buf, int len) {
+	int i, done = 0;
+	printf ("%s: %p, length %d\n", msg, buf, len);
+	while (done < len) {
+		printf ("%04x: ", done);
+		for (i = done; i < done + 16; i++) {
+			if (i < len) 
+				printf ("%02x ", buf[i] & 0xff);
+			else
+				printf ("   ");
+			if (i % 4 == 3) printf (" ");
+		}
+		for (i = done; i < done + 16; i++) {
+			if (i < len) 
+				printf ("%c", isprint(buf[i]) ? buf[i] : '.');
+			if (i % 4 == 3) printf (" ");
+		}
+		printf ("\n");
+		done += 16;
+	}
+}
+#endif NFS_DEBUG
+
+
 static inline void dump_params(__u32 server,
 			       const char *path,
 			       const struct nfs_mount_data *data)
@@ -122,23 +149,7 @@
 static inline void dump_fh(const char *data, int len)
 {
 #ifdef NFS_DEBUG
-	int i = 0;
-	int max = len - (len % 8);
-
-	printf("Root file handle: %d bytes\n", NFS2_FHSIZE);
-
-	while (i < max) {
-		int j;
-
-		printf("  %4d:  ", i);
-		for (j = 0; j < 4; j++) {
-			printf("%02x %02x %02x %02x  ",
-			       data[i] & 0xff, data[i + 1] & 0xff,
-			       data[i + 2] & 0xff, data[i + 3] & 0xff);
-		}
-		i += j;
-		printf("\n");
-	}
+	hex_dump ("Root file handle", data, len);
 #endif
 }
 



More information about the klibc mailing list