sbin/hammer: Fix workaround made in 2f8c6a59
[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                         deleted = ' ';  /* could use unique mark */
277                 else
278                         deleted = 'd';
279         } else {
280                 deleted = ' ';
281         }
282
283         printf("%s\t%s %2d %c ",
284                flagstr, label, i,
285                (elm->base.btype ? elm->base.btype : '?'));
286         printf("lo=%08x obj=%016jx rt=%02x key=%016jx ot=%02x\n",
287                elm->base.localization,
288                (uintmax_t)elm->base.obj_id,
289                elm->base.rec_type,
290                (uintmax_t)elm->base.key,
291                elm->base.obj_type);
292         printf("\t       %c tids %016jx:%016jx ",
293                deleted,
294                (uintmax_t)elm->base.create_tid,
295                (uintmax_t)elm->base.delete_tid);
296
297         switch(type) {
298         case HAMMER_BTREE_TYPE_INTERNAL:
299                 printf("suboff=%016jx",
300                        (uintmax_t)elm->internal.subtree_offset);
301                 if (QuietOpt < 3) {
302                         printf(" mirror %016jx",
303                                (uintmax_t)elm->internal.mirror_tid);
304                 }
305                 if (ext)
306                         printf(" %s", ext);
307                 break;
308         case HAMMER_BTREE_TYPE_LEAF:
309                 if (ext)
310                         printf(" %s", ext);
311                 switch(elm->base.btype) {
312                 case HAMMER_BTREE_TYPE_RECORD:
313                         if (QuietOpt < 3)
314                                 printf("\n%s\t         ", check_data_crc(elm));
315                         else
316                                 printf("\n\t         ");
317                         printf("dataoff=%016jx/%d",
318                                (uintmax_t)elm->leaf.data_offset,
319                                elm->leaf.data_len);
320                         if (QuietOpt < 3) {
321                                 printf(" crc=%04x", elm->leaf.data_crc);
322                                 printf("\n\t         fills=");
323                                 print_bigblock_fill(elm->leaf.data_offset);
324                         }
325                         if (QuietOpt < 2)
326                                 print_record(elm);
327                         break;
328                 }
329                 break;
330         default:
331                 break;
332         }
333         printf("\n");
334 }
335
336 static
337 int
338 get_elm_flags(hammer_node_ondisk_t node, hammer_off_t node_offset,
339                 hammer_btree_elm_t elm, u_int8_t btype,
340                 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
341 {
342         int flags = 0;
343
344         switch(node->type) {
345         case HAMMER_BTREE_TYPE_INTERNAL:
346                 if (elm->internal.subtree_offset) {
347                         struct buffer_info *buffer = NULL;
348                         hammer_node_ondisk_t subnode;
349
350                         subnode = get_node(elm->internal.subtree_offset,
351                                            &buffer);
352                         if (subnode == NULL)
353                                 flags |= FLAG_BADCHILDPARENT;
354                         else if (subnode->parent != node_offset)
355                                 flags |= FLAG_BADCHILDPARENT;
356                         rel_buffer(buffer);
357                 }
358                 if (elm->internal.mirror_tid > node->mirror_tid)
359                         flags |= FLAG_BADMIRRORTID;
360
361                 switch(btype) {
362                 case HAMMER_BTREE_TYPE_INTERNAL:
363                         if (left_bound == NULL || right_bound == NULL)
364                                 break;
365                         if (hammer_btree_cmp(&elm->base, left_bound) < 0)
366                                 flags |= FLAG_TOOFARLEFT;
367                         if (hammer_btree_cmp(&elm->base, right_bound) > 0)
368                                 flags |= FLAG_TOOFARRIGHT;
369                         break;
370                 case HAMMER_BTREE_TYPE_LEAF:
371                         if (left_bound == NULL || right_bound == NULL)
372                                 break;
373                         if (hammer_btree_cmp(&elm->base, left_bound) < 0)
374                                 flags |= FLAG_TOOFARLEFT;
375                         if (hammer_btree_cmp(&elm->base, right_bound) >= 0)
376                                 flags |= FLAG_TOOFARRIGHT;
377                         break;
378                 default:
379                         flags |= FLAG_BADTYPE;
380                         break;
381                 }
382                 break;
383         case HAMMER_BTREE_TYPE_LEAF:
384                 if (node->mirror_tid == 0 &&
385                     !(node->parent == 0 && node->count == 2)) {
386                         flags |= FLAG_BADMIRRORTID;
387                 }
388                 if (elm->base.create_tid && node->mirror_tid &&
389                     elm->base.create_tid > node->mirror_tid) {
390                         flags |= FLAG_BADMIRRORTID;
391                 }
392                 if (elm->base.delete_tid && node->mirror_tid &&
393                     elm->base.delete_tid > node->mirror_tid) {
394                         flags |= FLAG_BADMIRRORTID;
395                 }
396                 switch(btype) {
397                 case HAMMER_BTREE_TYPE_RECORD:
398                         if (left_bound == NULL || right_bound == NULL)
399                                 break;
400                         if (hammer_btree_cmp(&elm->base, left_bound) < 0)
401                                 flags |= FLAG_TOOFARLEFT;
402                         if (hammer_btree_cmp(&elm->base, right_bound) >= 0)
403                                 flags |= FLAG_TOOFARRIGHT;
404                         break;
405                 default:
406                         flags |= FLAG_BADTYPE;
407                         break;
408                 }
409                 break;
410         default:
411                 flags |= FLAG_BADTYPE;
412                 break;
413         }
414         return(flags);
415 }
416
417 static
418 void
419 print_bigblock_fill(hammer_off_t offset)
420 {
421         struct hammer_blockmap_layer1 layer1;
422         struct hammer_blockmap_layer2 layer2;
423         int fill;
424         int error;
425
426         blockmap_lookup(offset, &layer1, &layer2, &error);
427         if (error) {
428                 printf("z%d:%lld=BADZ",
429                         HAMMER_ZONE_DECODE(offset),
430                         (offset & ~HAMMER_OFF_ZONE_MASK) /
431                             HAMMER_BIGBLOCK_SIZE
432                 );
433         } else {
434                 fill = layer2.bytes_free * 100 / HAMMER_BIGBLOCK_SIZE;
435                 fill = 100 - fill;
436
437                 printf("z%d:%lld=%d%%",
438                         HAMMER_ZONE_DECODE(offset),
439                         (offset & ~HAMMER_OFF_ZONE_MASK) /
440                             HAMMER_BIGBLOCK_SIZE,
441                         fill
442                 );
443         }
444 }
445
446 /*
447  * Check the generic crc on a data element.  Inodes record types are
448  * special in that some of their fields are not CRCed.
449  *
450  * Also check that the zone is valid.
451  */
452 static
453 const char *
454 check_data_crc(hammer_btree_elm_t elm)
455 {
456         struct buffer_info *data_buffer;
457         hammer_off_t data_offset;
458         int32_t data_len;
459         int32_t len;
460         u_int32_t crc;
461         int error;
462         char *ptr;
463
464         data_offset = elm->leaf.data_offset;
465         data_len = elm->leaf.data_len;
466         data_buffer = NULL;
467         if (data_offset == 0 || data_len == 0)
468                 return("Z");
469
470         crc = 0;
471         error = 0;
472         while (data_len) {
473                 blockmap_lookup(data_offset, NULL, NULL, &error);
474                 if (error)
475                         break;
476
477                 ptr = get_buffer_data(data_offset, &data_buffer, 0);
478                 len = HAMMER_BUFSIZE - ((int)data_offset & HAMMER_BUFMASK);
479                 if (len > data_len)
480                         len = (int)data_len;
481                 if (elm->leaf.base.rec_type == HAMMER_RECTYPE_INODE &&
482                     data_len == sizeof(struct hammer_inode_data)) {
483                         crc = crc32_ext(ptr, HAMMER_INODE_CRCSIZE, crc);
484                 } else {
485                         crc = crc32_ext(ptr, len, crc);
486                 }
487                 data_len -= len;
488                 data_offset += len;
489         }
490         if (data_buffer)
491                 rel_buffer(data_buffer);
492         if (error)
493                 return("BO");           /* bad offset */
494         if (crc == elm->leaf.data_crc)
495                 return("");
496         return("BX");                   /* bad crc */
497 }
498
499 static
500 void
501 print_config(char *cfgtxt)
502 {
503         char *token;
504
505         printf("\n%17stext=\"\n", "");
506         while((token = strsep(&cfgtxt, "\r\n")) != NULL) {
507                 printf("%17s  %s\n", "", token);
508         }
509         printf("%17s\"", "");
510 }
511
512 static
513 void
514 print_record(hammer_btree_elm_t elm)
515 {
516         struct buffer_info *data_buffer;
517         hammer_off_t data_offset;
518         int32_t data_len;
519         hammer_data_ondisk_t data;
520         u_int32_t status;
521         char *str1 = NULL;
522         char *str2 = NULL;
523
524         data_offset = elm->leaf.data_offset;
525         data_len = elm->leaf.data_len;
526         data_buffer = NULL;
527
528         if (data_offset)
529                 data = get_buffer_data(data_offset, &data_buffer, 0);
530         else
531                 data = NULL;
532
533         switch(elm->leaf.base.rec_type) {
534         case HAMMER_RECTYPE_UNKNOWN:
535                 printf("\n%17s", "");
536                 printf("unknown");
537                 break;
538         case HAMMER_RECTYPE_INODE:
539                 printf("\n%17s", "");
540                 printf("size=%jd nlinks=%jd",
541                        (intmax_t)data->inode.size,
542                        (intmax_t)data->inode.nlinks);
543                 if (QuietOpt < 1) {
544                         printf(" mode=%05o uflags=%08x\n",
545                                 data->inode.mode,
546                                 data->inode.uflags);
547                         printf("%17s", "");
548                         printf("ctime=%016jx pobjid=%016jx obj_type=%d\n",
549                                 (uintmax_t)data->inode.ctime,
550                                 (uintmax_t)data->inode.parent_obj_id,
551                                 data->inode.obj_type);
552                         printf("%17s", "");
553                         printf("mtime=%016jx", (uintmax_t)data->inode.mtime);
554                         printf(" caps=%02x", data->inode.cap_flags);
555                 }
556                 break;
557         case HAMMER_RECTYPE_DIRENTRY:
558                 printf("\n%17s", "");
559                 data_len -= HAMMER_ENTRY_NAME_OFF;
560                 printf("dir-entry ino=%016jx lo=%08x name=\"%*.*s\"",
561                        (uintmax_t)data->entry.obj_id,
562                        data->entry.localization,
563                        data_len, data_len, data->entry.name);
564                 break;
565         case HAMMER_RECTYPE_FIX:
566                 switch(elm->leaf.base.key) {
567                 case HAMMER_FIXKEY_SYMLINK:
568                         data_len -= HAMMER_SYMLINK_NAME_OFF;
569                         printf("\n%17s", "");
570                         printf("symlink=\"%*.*s\"", data_len, data_len,
571                                 data->symlink.name);
572                         break;
573                 default:
574                         break;
575                 }
576                 break;
577         case HAMMER_RECTYPE_PFS:
578                 printf("\n%17s", "");
579                 printf("sync_beg_tid=%016jx sync_end_tid=%016jx\n",
580                         (intmax_t)data->pfsd.sync_beg_tid,
581                         (intmax_t)data->pfsd.sync_end_tid);
582                 uuid_to_string(&data->pfsd.shared_uuid, &str1, &status);
583                 uuid_to_string(&data->pfsd.unique_uuid, &str2, &status);
584                 printf("%17s", "");
585                 printf("shared_uuid=%s\n", str1);
586                 printf("%17s", "");
587                 printf("unique_uuid=%s\n", str2);
588                 printf("%17s", "");
589                 printf("mirror_flags=%08x label=\"%s\"",
590                         data->pfsd.mirror_flags, data->pfsd.label);
591                 if (data->pfsd.snapshots[0])
592                         printf(" snapshots=\"%s\"", data->pfsd.snapshots);
593                 free(str1);
594                 free(str2);
595                 break;
596         case HAMMER_RECTYPE_SNAPSHOT:
597                 printf("\n%17s", "");
598                 printf("tid=%016jx label=\"%s\"",
599                         (intmax_t)data->snap.tid, data->snap.label);
600                 break;
601         case HAMMER_RECTYPE_CONFIG:
602                 if (VerboseOpt > 2) {
603                         print_config(data->config.text);
604                 }
605                 break;
606         case HAMMER_RECTYPE_DATA:
607                 if (VerboseOpt > 3) {
608                         printf("\n");
609                         hexdump(data, data_len, "\t\t  ", 0);
610                 }
611                 break;
612         case HAMMER_RECTYPE_EXT:
613         case HAMMER_RECTYPE_DB:
614                 if (VerboseOpt > 2) {
615                         printf("\n");
616                         hexdump(data, data_len, "\t\t  ", 0);
617                 }
618                 break;
619         default:
620                 break;
621         }
622         if (data_buffer)
623                 rel_buffer(data_buffer);
624 }
625
626 /*
627  * Dump the UNDO FIFO
628  */
629 void
630 hammer_cmd_show_undo(void)
631 {
632         struct volume_info *volume;
633         hammer_blockmap_t rootmap;
634         hammer_off_t scan_offset;
635         hammer_fifo_any_t head;
636         struct buffer_info *data_buffer = NULL;
637
638         volume = get_volume(RootVolNo);
639         rootmap = &volume->ondisk->vol0_blockmap[HAMMER_ZONE_UNDO_INDEX];
640         printf("Volume header UNDO %016jx-%016jx/%016jx\n",
641                 (intmax_t)rootmap->first_offset,
642                 (intmax_t)rootmap->next_offset,
643                 (intmax_t)rootmap->alloc_offset);
644         printf("Undo map is %jdMB\n",
645                 (intmax_t)((rootmap->alloc_offset & HAMMER_OFF_LONG_MASK) /
646                            (1024 * 1024)));
647         scan_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
648         while (scan_offset < rootmap->alloc_offset) {
649                 head = get_buffer_data(scan_offset, &data_buffer, 0);
650                 printf("%016jx ", scan_offset);
651
652                 switch(head->head.hdr_type) {
653                 case HAMMER_HEAD_TYPE_PAD:
654                         printf("PAD(%04x)\n", head->head.hdr_size);
655                         break;
656                 case HAMMER_HEAD_TYPE_DUMMY:
657                         printf("DUMMY(%04x) seq=%08x\n",
658                                 head->head.hdr_size, head->head.hdr_seq);
659                         break;
660                 case HAMMER_HEAD_TYPE_UNDO:
661                         printf("UNDO(%04x) seq=%08x "
662                                "dataoff=%016jx bytes=%d\n",
663                                 head->head.hdr_size, head->head.hdr_seq,
664                                 (intmax_t)head->undo.undo_offset,
665                                 head->undo.undo_data_bytes);
666                         break;
667                 case HAMMER_HEAD_TYPE_REDO:
668                         printf("REDO(%04x) seq=%08x flags=%08x "
669                                "objid=%016jx logoff=%016jx bytes=%d\n",
670                                 head->head.hdr_size, head->head.hdr_seq,
671                                 head->redo.redo_flags,
672                                 (intmax_t)head->redo.redo_objid,
673                                 (intmax_t)head->redo.redo_offset,
674                                 head->redo.redo_data_bytes);
675                         break;
676                 default:
677                         printf("UNKNOWN(%04x,%04x) seq=%08x\n",
678                                 head->head.hdr_type,
679                                 head->head.hdr_size,
680                                 head->head.hdr_seq);
681                         break;
682                 }
683                 if ((head->head.hdr_size & HAMMER_HEAD_ALIGN_MASK) ||
684                     head->head.hdr_size == 0 ||
685                     head->head.hdr_size > HAMMER_UNDO_ALIGN -
686                                     ((u_int)scan_offset & HAMMER_UNDO_MASK)) {
687                         printf("Illegal size field, skipping to "
688                                "next boundary\n");
689                         scan_offset = (scan_offset + HAMMER_UNDO_MASK) &
690                                         ~HAMMER_UNDO_MASK64;
691                 } else {
692                         scan_offset += head->head.hdr_size;
693                 }
694         }
695         if (data_buffer)
696                 rel_buffer(data_buffer);
697 }