sbin/hammer: Don't show irrelevant "BM" and "d" after root split
[dragonfly.git] / sbin / hammer / cmd_show.c
1 /*
2  * Copyright (c) 2008 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34
35 #include "hammer.h"
36 #include <libutil.h>
37
38 #define FLAG_TOOFARLEFT         0x0001
39 #define FLAG_TOOFARRIGHT        0x0002
40 #define FLAG_BADTYPE            0x0004
41 #define FLAG_BADCHILDPARENT     0x0008
42 #define FLAG_BADMIRRORTID       0x0010
43
44 typedef struct btree_search {
45         u_int32_t       lo;
46         int64_t         obj_id;
47 } *btree_search_t;
48
49 static void print_btree_node(hammer_off_t node_offset, btree_search_t search,
50                         int depth, hammer_tid_t mirror_tid,
51                         hammer_base_elm_t left_bound,
52                         hammer_base_elm_t right_bound,
53                         int this_index);
54 static const char *check_data_crc(hammer_btree_elm_t elm);
55 static void print_record(hammer_btree_elm_t elm);
56 static void print_btree_elm(hammer_btree_elm_t elm, int i, u_int8_t type,
57                         int flags, const char *label, const char *ext);
58 static int get_elm_flags(hammer_node_ondisk_t node, hammer_off_t node_offset,
59                         hammer_btree_elm_t elm, u_int8_t btype,
60                         hammer_base_elm_t left_bound,
61                         hammer_base_elm_t right_bound);
62 static void print_bigblock_fill(hammer_off_t offset);
63
64 void
65 hammer_cmd_show(hammer_off_t node_offset, u_int32_t lo, int64_t obj_id,
66                 int depth,
67                 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
68 {
69         struct volume_info *volume;
70         struct btree_search search;
71         btree_search_t searchp;
72         int zone;
73
74         AssertOnFailure = 0;
75
76         if (node_offset == (hammer_off_t)-1) {
77                 volume = get_volume(RootVolNo);
78                 node_offset = volume->ondisk->vol0_btree_root;
79                 if (QuietOpt < 3) {
80                         printf("Volume header\trecords=%jd next_tid=%016jx\n",
81                                (intmax_t)volume->ondisk->vol0_stat_records,
82                                (uintmax_t)volume->ondisk->vol0_next_tid);
83                         printf("\t\tbufoffset=%016jx\n",
84                                (uintmax_t)volume->ondisk->vol_buf_beg);
85                         for (zone = 0; zone < HAMMER_MAX_ZONES; ++zone) {
86                                 printf("\t\tzone %d\tnext_offset=%016jx\n",
87                                         zone,
88                                         (uintmax_t)volume->ondisk->vol0_blockmap[zone].next_offset
89                                 );
90                         }
91                 }
92                 rel_volume(volume);
93         }
94
95         if (lo == 0 && obj_id == (int64_t)HAMMER_MIN_OBJID) {
96                 searchp = NULL;
97                 printf("show %016jx depth %d\n", (uintmax_t)node_offset, depth);
98         } else {
99                 search.lo = lo;
100                 search.obj_id = obj_id;
101                 searchp = &search;
102                 printf("show %016jx lo %08x obj_id %016jx depth %d\n",
103                         (uintmax_t)node_offset, lo, (uintmax_t)obj_id, depth);
104         }
105         print_btree_node(node_offset, searchp, depth, HAMMER_MAX_TID,
106                          left_bound, right_bound, -1);
107
108         AssertOnFailure = 1;
109 }
110
111 static void
112 print_btree_node(hammer_off_t node_offset, btree_search_t search,
113                 int depth, hammer_tid_t mirror_tid,
114                 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound,
115                 int this_index)
116 {
117         struct buffer_info *buffer = NULL;
118         hammer_node_ondisk_t node;
119         hammer_btree_elm_t elm;
120         int i;
121         int flags;
122         int maxcount;
123         char badc;
124         char badm;
125         const char *ext;
126
127         node = get_node(node_offset, &buffer);
128
129         if (node == NULL) {
130                 printf("BI   NODE %016jx (IO ERROR)\n",
131                        (uintmax_t)node_offset);
132                 return;
133         }
134
135         if (crc32(&node->crc + 1, HAMMER_BTREE_CRCSIZE) == node->crc)
136                 badc = ' ';
137         else
138                 badc = 'B';
139
140         /*
141          * Workaround for the root split that is not an error
142          */
143         if (this_index == 0 && depth == 1 && mirror_tid == 0) {
144                 badm = ' ';  /* could use unique mark */
145         } else {
146                 if (node->mirror_tid <= mirror_tid) {
147                         badm = ' ';
148                 } else {
149                         badm = 'M';
150                         badc = 'B';
151                 }
152         }
153
154         printf("%c%c   NODE %016jx cnt=%02d p=%016jx "
155                "type=%c depth=%d",
156                badc,
157                badm,
158                (uintmax_t)node_offset, node->count,
159                (uintmax_t)node->parent,
160                (node->type ? node->type : '?'), depth);
161         printf(" mirror %016jx", (uintmax_t)node->mirror_tid);
162         if (QuietOpt < 3) {
163                 printf(" fill=");
164                 print_bigblock_fill(node_offset);
165         }
166         printf(" {\n");
167
168         maxcount = (node->type == HAMMER_BTREE_TYPE_INTERNAL) ?
169                    HAMMER_BTREE_INT_ELMS : HAMMER_BTREE_LEAF_ELMS;
170
171         for (i = 0; i < node->count && i < maxcount; ++i) {
172                 elm = &node->elms[i];
173
174                 if (node->type != HAMMER_BTREE_TYPE_INTERNAL) {
175                         ext = NULL;
176                         if (search &&
177                             elm->base.localization == search->lo &&
178                              elm->base.obj_id == search->obj_id) {
179                                 ext = " *";
180                         }
181                 } else if (search) {
182                         ext = " *";
183                         if (elm->base.localization > search->lo ||
184                             (elm->base.localization == search->lo &&
185                              elm->base.obj_id > search->obj_id)) {
186                                 ext = NULL;
187                         }
188                         if (elm[1].base.localization < search->lo ||
189                             (elm[1].base.localization == search->lo &&
190                              elm[1].base.obj_id < search->obj_id)) {
191                                 ext = NULL;
192                         }
193                 } else {
194                         ext = NULL;
195                 }
196
197                 flags = get_elm_flags(node, node_offset,
198                                         elm, elm->base.btype,
199                                         left_bound, right_bound);
200                 print_btree_elm(elm, i, node->type, flags, "ELM", ext);
201         }
202         if (node->type == HAMMER_BTREE_TYPE_INTERNAL) {
203                 elm = &node->elms[i];
204
205                 flags = get_elm_flags(node, node_offset,
206                                         elm, 'I',
207                                         left_bound, right_bound);
208                 print_btree_elm(elm, i, node->type, flags, "RBN", NULL);
209         }
210         printf("     }\n");
211
212         for (i = 0; i < node->count; ++i) {
213                 elm = &node->elms[i];
214
215                 switch(node->type) {
216                 case HAMMER_BTREE_TYPE_INTERNAL:
217                         if (search) {
218                                 if (elm->base.localization > search->lo ||
219                                     (elm->base.localization == search->lo &&
220                                      elm->base.obj_id > search->obj_id)) {
221                                         break;
222                                 }
223                                 if (elm[1].base.localization < search->lo ||
224                                     (elm[1].base.localization == search->lo &&
225                                      elm[1].base.obj_id < search->obj_id)) {
226                                         break;
227                                 }
228                         }
229                         if (elm->internal.subtree_offset) {
230                                 print_btree_node(elm->internal.subtree_offset,
231                                                  search, depth + 1,
232                                                  elm->internal.mirror_tid,
233                                                  &elm[0].base, &elm[1].base, i);
234                                 /*
235                                  * Cause show to iterate after seeking to
236                                  * the lo:objid
237                                  */
238                                 search = NULL;
239                         }
240                         break;
241                 default:
242                         break;
243                 }
244         }
245         rel_buffer(buffer);
246 }
247
248 static
249 void
250 print_btree_elm(hammer_btree_elm_t elm, int i, u_int8_t type,
251                 int flags, const char *label, const char *ext)
252 {
253         char flagstr[8] = { 0, '-', '-', '-', '-', '-', '-', 0 };
254         char deleted;
255
256         flagstr[0] = flags ? 'B' : 'G';
257         if (flags & FLAG_TOOFARLEFT)
258                 flagstr[2] = 'L';
259         if (flags & FLAG_TOOFARRIGHT)
260                 flagstr[3] = 'R';
261         if (flags & FLAG_BADTYPE)
262                 flagstr[4] = 'T';
263         if (flags & FLAG_BADCHILDPARENT)
264                 flagstr[5] = 'C';
265         if (flags & FLAG_BADMIRRORTID)
266                 flagstr[6] = 'M';
267
268         /*
269          * Workaround for the root split that is not actual delete
270          */
271         if (elm->base.delete_tid) {
272                 if (type == HAMMER_BTREE_TYPE_INTERNAL &&
273                     i == 0 &&
274                     elm->base.create_tid == 1 &&
275                     elm->base.delete_tid == 1 &&
276                     elm->internal.mirror_tid == 0)
277                         deleted = ' ';  /* could use unique mark */
278                 else
279                         deleted = 'd';
280         } else {
281                 deleted = ' ';
282         }
283
284         printf("%s\t%s %2d %c ",
285                flagstr, label, i,
286                (elm->base.btype ? elm->base.btype : '?'));
287         printf("lo=%08x obj=%016jx rt=%02x key=%016jx ot=%02x\n",
288                elm->base.localization,
289                (uintmax_t)elm->base.obj_id,
290                elm->base.rec_type,
291                (uintmax_t)elm->base.key,
292                elm->base.obj_type);
293         printf("\t       %c tids %016jx:%016jx ",
294                deleted,
295                (uintmax_t)elm->base.create_tid,
296                (uintmax_t)elm->base.delete_tid);
297
298         switch(type) {
299         case HAMMER_BTREE_TYPE_INTERNAL:
300                 printf("suboff=%016jx",
301                        (uintmax_t)elm->internal.subtree_offset);
302                 if (QuietOpt < 3) {
303                         printf(" mirror %016jx",
304                                (uintmax_t)elm->internal.mirror_tid);
305                 }
306                 if (ext)
307                         printf(" %s", ext);
308                 break;
309         case HAMMER_BTREE_TYPE_LEAF:
310                 if (ext)
311                         printf(" %s", ext);
312                 switch(elm->base.btype) {
313                 case HAMMER_BTREE_TYPE_RECORD:
314                         if (QuietOpt < 3)
315                                 printf("\n%s\t         ", check_data_crc(elm));
316                         else
317                                 printf("\n\t         ");
318                         printf("dataoff=%016jx/%d",
319                                (uintmax_t)elm->leaf.data_offset,
320                                elm->leaf.data_len);
321                         if (QuietOpt < 3) {
322                                 printf(" crc=%04x", elm->leaf.data_crc);
323                                 printf("\n\t         fills=");
324                                 print_bigblock_fill(elm->leaf.data_offset);
325                         }
326                         if (QuietOpt < 2)
327                                 print_record(elm);
328                         break;
329                 }
330                 break;
331         default:
332                 break;
333         }
334         printf("\n");
335 }
336
337 static
338 int
339 get_elm_flags(hammer_node_ondisk_t node, hammer_off_t node_offset,
340                 hammer_btree_elm_t elm, u_int8_t btype,
341                 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
342 {
343         int flags = 0;
344
345         switch(node->type) {
346         case HAMMER_BTREE_TYPE_INTERNAL:
347                 if (elm->internal.subtree_offset) {
348                         struct buffer_info *buffer = NULL;
349                         hammer_node_ondisk_t subnode;
350
351                         subnode = get_node(elm->internal.subtree_offset,
352                                            &buffer);
353                         if (subnode == NULL)
354                                 flags |= FLAG_BADCHILDPARENT;
355                         else if (subnode->parent != node_offset)
356                                 flags |= FLAG_BADCHILDPARENT;
357                         rel_buffer(buffer);
358                 }
359                 if (elm->internal.mirror_tid > node->mirror_tid)
360                         flags |= FLAG_BADMIRRORTID;
361
362                 switch(btype) {
363                 case HAMMER_BTREE_TYPE_INTERNAL:
364                         if (left_bound == NULL || right_bound == NULL)
365                                 break;
366                         if (hammer_btree_cmp(&elm->base, left_bound) < 0)
367                                 flags |= FLAG_TOOFARLEFT;
368                         if (hammer_btree_cmp(&elm->base, right_bound) > 0)
369                                 flags |= FLAG_TOOFARRIGHT;
370                         break;
371                 case HAMMER_BTREE_TYPE_LEAF:
372                         if (left_bound == NULL || right_bound == NULL)
373                                 break;
374                         if (hammer_btree_cmp(&elm->base, left_bound) < 0)
375                                 flags |= FLAG_TOOFARLEFT;
376                         if (hammer_btree_cmp(&elm->base, right_bound) >= 0)
377                                 flags |= FLAG_TOOFARRIGHT;
378                         break;
379                 default:
380                         flags |= FLAG_BADTYPE;
381                         break;
382                 }
383                 break;
384         case HAMMER_BTREE_TYPE_LEAF:
385                 if (node->mirror_tid == 0 &&
386                     !(node->parent == 0 && node->count == 2)) {
387                         flags |= FLAG_BADMIRRORTID;
388                 }
389                 if (elm->base.create_tid && node->mirror_tid &&
390                     elm->base.create_tid > node->mirror_tid) {
391                         flags |= FLAG_BADMIRRORTID;
392                 }
393                 if (elm->base.delete_tid && node->mirror_tid &&
394                     elm->base.delete_tid > node->mirror_tid) {
395                         flags |= FLAG_BADMIRRORTID;
396                 }
397                 switch(btype) {
398                 case HAMMER_BTREE_TYPE_RECORD:
399                         if (left_bound == NULL || right_bound == NULL)
400                                 break;
401                         if (hammer_btree_cmp(&elm->base, left_bound) < 0)
402                                 flags |= FLAG_TOOFARLEFT;
403                         if (hammer_btree_cmp(&elm->base, right_bound) >= 0)
404                                 flags |= FLAG_TOOFARRIGHT;
405                         break;
406                 default:
407                         flags |= FLAG_BADTYPE;
408                         break;
409                 }
410                 break;
411         default:
412                 flags |= FLAG_BADTYPE;
413                 break;
414         }
415         return(flags);
416 }
417
418 static
419 void
420 print_bigblock_fill(hammer_off_t offset)
421 {
422         struct hammer_blockmap_layer1 layer1;
423         struct hammer_blockmap_layer2 layer2;
424         int fill;
425         int error;
426
427         blockmap_lookup(offset, &layer1, &layer2, &error);
428         if (error) {
429                 printf("z%d:%lld=BADZ",
430                         HAMMER_ZONE_DECODE(offset),
431                         (offset & ~HAMMER_OFF_ZONE_MASK) /
432                             HAMMER_BIGBLOCK_SIZE
433                 );
434         } else {
435                 fill = layer2.bytes_free * 100 / HAMMER_BIGBLOCK_SIZE;
436                 fill = 100 - fill;
437
438                 printf("z%d:%lld=%d%%",
439                         HAMMER_ZONE_DECODE(offset),
440                         (offset & ~HAMMER_OFF_ZONE_MASK) /
441                             HAMMER_BIGBLOCK_SIZE,
442                         fill
443                 );
444         }
445 }
446
447 /*
448  * Check the generic crc on a data element.  Inodes record types are
449  * special in that some of their fields are not CRCed.
450  *
451  * Also check that the zone is valid.
452  */
453 static
454 const char *
455 check_data_crc(hammer_btree_elm_t elm)
456 {
457         struct buffer_info *data_buffer;
458         hammer_off_t data_offset;
459         int32_t data_len;
460         int32_t len;
461         u_int32_t crc;
462         int error;
463         char *ptr;
464
465         data_offset = elm->leaf.data_offset;
466         data_len = elm->leaf.data_len;
467         data_buffer = NULL;
468         if (data_offset == 0 || data_len == 0)
469                 return("Z");
470
471         crc = 0;
472         error = 0;
473         while (data_len) {
474                 blockmap_lookup(data_offset, NULL, NULL, &error);
475                 if (error)
476                         break;
477
478                 ptr = get_buffer_data(data_offset, &data_buffer, 0);
479                 len = HAMMER_BUFSIZE - ((int)data_offset & HAMMER_BUFMASK);
480                 if (len > data_len)
481                         len = (int)data_len;
482                 if (elm->leaf.base.rec_type == HAMMER_RECTYPE_INODE &&
483                     data_len == sizeof(struct hammer_inode_data)) {
484                         crc = crc32_ext(ptr, HAMMER_INODE_CRCSIZE, crc);
485                 } else {
486                         crc = crc32_ext(ptr, len, crc);
487                 }
488                 data_len -= len;
489                 data_offset += len;
490         }
491         if (data_buffer)
492                 rel_buffer(data_buffer);
493         if (error)
494                 return("BO");           /* bad offset */
495         if (crc == elm->leaf.data_crc)
496                 return("");
497         return("BX");                   /* bad crc */
498 }
499
500 static
501 void
502 print_config(char *cfgtxt)
503 {
504         char *token;
505
506         printf("\n%17stext=\"\n", "");
507         while((token = strsep(&cfgtxt, "\r\n")) != NULL) {
508                 printf("%17s  %s\n", "", token);
509         }
510         printf("%17s\"", "");
511 }
512
513 static
514 void
515 print_record(hammer_btree_elm_t elm)
516 {
517         struct buffer_info *data_buffer;
518         hammer_off_t data_offset;
519         int32_t data_len;
520         hammer_data_ondisk_t data;
521         u_int32_t status;
522         char *str1 = NULL;
523         char *str2 = NULL;
524
525         data_offset = elm->leaf.data_offset;
526         data_len = elm->leaf.data_len;
527         data_buffer = NULL;
528
529         if (data_offset)
530                 data = get_buffer_data(data_offset, &data_buffer, 0);
531         else
532                 data = NULL;
533
534         switch(elm->leaf.base.rec_type) {
535         case HAMMER_RECTYPE_UNKNOWN:
536                 printf("\n%17s", "");
537                 printf("unknown");
538                 break;
539         case HAMMER_RECTYPE_INODE:
540                 printf("\n%17s", "");
541                 printf("size=%jd nlinks=%jd",
542                        (intmax_t)data->inode.size,
543                        (intmax_t)data->inode.nlinks);
544                 if (QuietOpt < 1) {
545                         printf(" mode=%05o uflags=%08x\n",
546                                 data->inode.mode,
547                                 data->inode.uflags);
548                         printf("%17s", "");
549                         printf("ctime=%016jx pobjid=%016jx obj_type=%d\n",
550                                 (uintmax_t)data->inode.ctime,
551                                 (uintmax_t)data->inode.parent_obj_id,
552                                 data->inode.obj_type);
553                         printf("%17s", "");
554                         printf("mtime=%016jx", (uintmax_t)data->inode.mtime);
555                         printf(" caps=%02x", data->inode.cap_flags);
556                 }
557                 break;
558         case HAMMER_RECTYPE_DIRENTRY:
559                 printf("\n%17s", "");
560                 data_len -= HAMMER_ENTRY_NAME_OFF;
561                 printf("dir-entry ino=%016jx lo=%08x name=\"%*.*s\"",
562                        (uintmax_t)data->entry.obj_id,
563                        data->entry.localization,
564                        data_len, data_len, data->entry.name);
565                 break;
566         case HAMMER_RECTYPE_FIX:
567                 switch(elm->leaf.base.key) {
568                 case HAMMER_FIXKEY_SYMLINK:
569                         data_len -= HAMMER_SYMLINK_NAME_OFF;
570                         printf("\n%17s", "");
571                         printf("symlink=\"%*.*s\"", data_len, data_len,
572                                 data->symlink.name);
573                         break;
574                 default:
575                         break;
576                 }
577                 break;
578         case HAMMER_RECTYPE_PFS:
579                 printf("\n%17s", "");
580                 printf("sync_beg_tid=%016jx sync_end_tid=%016jx\n",
581                         (intmax_t)data->pfsd.sync_beg_tid,
582                         (intmax_t)data->pfsd.sync_end_tid);
583                 uuid_to_string(&data->pfsd.shared_uuid, &str1, &status);
584                 uuid_to_string(&data->pfsd.unique_uuid, &str2, &status);
585                 printf("%17s", "");
586                 printf("shared_uuid=%s\n", str1);
587                 printf("%17s", "");
588                 printf("unique_uuid=%s\n", str2);
589                 printf("%17s", "");
590                 printf("mirror_flags=%08x label=\"%s\"",
591                         data->pfsd.mirror_flags, data->pfsd.label);
592                 if (data->pfsd.snapshots[0])
593                         printf(" snapshots=\"%s\"", data->pfsd.snapshots);
594                 free(str1);
595                 free(str2);
596                 break;
597         case HAMMER_RECTYPE_SNAPSHOT:
598                 printf("\n%17s", "");
599                 printf("tid=%016jx label=\"%s\"",
600                         (intmax_t)data->snap.tid, data->snap.label);
601                 break;
602         case HAMMER_RECTYPE_CONFIG:
603                 if (VerboseOpt > 2) {
604                         print_config(data->config.text);
605                 }
606                 break;
607         case HAMMER_RECTYPE_DATA:
608                 if (VerboseOpt > 3) {
609                         printf("\n");
610                         hexdump(data, data_len, "\t\t  ", 0);
611                 }
612                 break;
613         case HAMMER_RECTYPE_EXT:
614         case HAMMER_RECTYPE_DB:
615                 if (VerboseOpt > 2) {
616                         printf("\n");
617                         hexdump(data, data_len, "\t\t  ", 0);
618                 }
619                 break;
620         default:
621                 break;
622         }
623         if (data_buffer)
624                 rel_buffer(data_buffer);
625 }
626
627 /*
628  * Dump the UNDO FIFO
629  */
630 void
631 hammer_cmd_show_undo(void)
632 {
633         struct volume_info *volume;
634         hammer_blockmap_t rootmap;
635         hammer_off_t scan_offset;
636         hammer_fifo_any_t head;
637         struct buffer_info *data_buffer = NULL;
638
639         volume = get_volume(RootVolNo);
640         rootmap = &volume->ondisk->vol0_blockmap[HAMMER_ZONE_UNDO_INDEX];
641         printf("Volume header UNDO %016jx-%016jx/%016jx\n",
642                 (intmax_t)rootmap->first_offset,
643                 (intmax_t)rootmap->next_offset,
644                 (intmax_t)rootmap->alloc_offset);
645         printf("Undo map is %jdMB\n",
646                 (intmax_t)((rootmap->alloc_offset & HAMMER_OFF_LONG_MASK) /
647                            (1024 * 1024)));
648         scan_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
649         while (scan_offset < rootmap->alloc_offset) {
650                 head = get_buffer_data(scan_offset, &data_buffer, 0);
651                 printf("%016jx ", scan_offset);
652
653                 switch(head->head.hdr_type) {
654                 case HAMMER_HEAD_TYPE_PAD:
655                         printf("PAD(%04x)\n", head->head.hdr_size);
656                         break;
657                 case HAMMER_HEAD_TYPE_DUMMY:
658                         printf("DUMMY(%04x) seq=%08x\n",
659                                 head->head.hdr_size, head->head.hdr_seq);
660                         break;
661                 case HAMMER_HEAD_TYPE_UNDO:
662                         printf("UNDO(%04x) seq=%08x "
663                                "dataoff=%016jx bytes=%d\n",
664                                 head->head.hdr_size, head->head.hdr_seq,
665                                 (intmax_t)head->undo.undo_offset,
666                                 head->undo.undo_data_bytes);
667                         break;
668                 case HAMMER_HEAD_TYPE_REDO:
669                         printf("REDO(%04x) seq=%08x flags=%08x "
670                                "objid=%016jx logoff=%016jx bytes=%d\n",
671                                 head->head.hdr_size, head->head.hdr_seq,
672                                 head->redo.redo_flags,
673                                 (intmax_t)head->redo.redo_objid,
674                                 (intmax_t)head->redo.redo_offset,
675                                 head->redo.redo_data_bytes);
676                         break;
677                 default:
678                         printf("UNKNOWN(%04x,%04x) seq=%08x\n",
679                                 head->head.hdr_type,
680                                 head->head.hdr_size,
681                                 head->head.hdr_seq);
682                         break;
683                 }
684                 if ((head->head.hdr_size & HAMMER_HEAD_ALIGN_MASK) ||
685                     head->head.hdr_size == 0 ||
686                     head->head.hdr_size > HAMMER_UNDO_ALIGN -
687                                     ((u_int)scan_offset & HAMMER_UNDO_MASK)) {
688                         printf("Illegal size field, skipping to "
689                                "next boundary\n");
690                         scan_offset = (scan_offset + HAMMER_UNDO_MASK) &
691                                         ~HAMMER_UNDO_MASK64;
692                 } else {
693                         scan_offset += head->head.hdr_size;
694                 }
695         }
696         if (data_buffer)
697                 rel_buffer(data_buffer);
698 }