]> granicus.if.org Git - zfs/commitdiff
Fix zdb_dump_block on little endian systems
authorChunwei Chen <david.chen@osnexus.com>
Fri, 20 Nov 2015 23:47:37 +0000 (15:47 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 3 Dec 2015 01:02:28 +0000 (17:02 -0800)
When dumping a block on a little endian system the data must be
byte swapped to display correctly.  Example incorrect output:

$ echo 0123456789abcdef > aaa
$ zdb -eR pp 3:1ee00:200
3:1ee00:200
          0 1 2 3 4 5 6 7   8 9 a b c d e f  0123456789abcdef
000000:  3736353433323130  6665646362613938  0123456789abcdef
000010:  000000000000000a  0000000000000000  ................

Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4020

cmd/zdb/zdb.c

index 18378c4e6b6d48cb4c330b8f48dc4ee5677b8344..f050f36e21fb3f8ea087cbdcfa46f88be52399dd 100644 (file)
@@ -3212,6 +3212,10 @@ zdb_dump_block(char *label, void *buf, uint64_t size, int flags)
 
        (void) printf("\n%s\n%6s   %s  0123456789abcdef\n", label, "", hdr);
 
+#ifdef _LITTLE_ENDIAN
+       /* correct the endianess */
+       do_bswap = !do_bswap;
+#endif
        for (i = 0; i < nwords; i += 2) {
                (void) printf("%06llx:  %016llx  %016llx  ",
                    (u_longlong_t)(i * sizeof (uint64_t)),