sbin/hammer: Make hammer show properly print '*' for elements that match directive
[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         int             normal;  /* normal iteration */
48 } *btree_search_t;
49
50 static void print_btree_node(hammer_off_t node_offset, btree_search_t search,
51                         int depth, hammer_tid_t mirror_tid,
52                         hammer_base_elm_t left_bound,
53                         hammer_base_elm_t right_bound);
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                 search.normal = 0;
102                 searchp = &search;
103                 printf("show %016jx lo %08x obj_id %016jx depth %d\n",
104                         (uintmax_t)node_offset, lo, (uintmax_t)obj_id, depth);
105         }
106         print_btree_node(node_offset, searchp, depth, HAMMER_MAX_TID,
107                          left_bound, right_bound);
108
109         AssertOnFailure = 1;
110 }
111
112 static void
113 print_btree_node(hammer_off_t node_offset, btree_search_t search,
114                 int depth, hammer_tid_t mirror_tid,
115                 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
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         if (node->mirror_tid <= mirror_tid) {
141                 badm = ' ';
142         } else {
143                 badm = 'M';
144                 badc = 'B';
145         }
146
147         printf("%c%c   NODE %016jx cnt=%02d p=%016jx "
148                "type=%c depth=%d",
149                badc,
150                badm,
151                (uintmax_t)node_offset, node->count,
152                (uintmax_t)node->parent,
153                (node->type ? node->type : '?'), depth);
154         printf(" mirror %016jx", (uintmax_t)node->mirror_tid);
155         if (QuietOpt < 3) {
156                 printf(" fill=");
157                 print_bigblock_fill(node_offset);
158         }
159         printf(" {\n");
160
161         maxcount = (node->type == HAMMER_BTREE_TYPE_INTERNAL) ?
162                    HAMMER_BTREE_INT_ELMS : HAMMER_BTREE_LEAF_ELMS;
163
164         for (i = 0; i < node->count && i < maxcount; ++i) {
165                 elm = &node->elms[i];
166
167                 if (node->type != HAMMER_BTREE_TYPE_INTERNAL) {
168                         ext = NULL;
169                         if (search &&
170                             elm->base.localization == search->lo &&
171                              elm->base.obj_id == search->obj_id) {
172                                 ext = " *";
173                         }
174                 } else if (search) {
175                         ext = " *";
176                         if (elm->base.localization > search->lo ||
177                             (elm->base.localization == search->lo &&
178                              elm->base.obj_id > search->obj_id)) {
179                                 ext = NULL;
180                         }
181                         if (elm[1].base.localization < search->lo ||
182                             (elm[1].base.localization == search->lo &&
183                              elm[1].base.obj_id < search->obj_id)) {
184                                 ext = NULL;
185                         }
186                 } else {
187                         ext = NULL;
188                 }
189
190                 flags = get_elm_flags(node, node_offset,
191                                         elm, elm->base.btype,
192                                         left_bound, right_bound);
193                 print_btree_elm(elm, i, node->type, flags, "ELM", ext);
194         }
195         if (node->type == HAMMER_BTREE_TYPE_INTERNAL) {
196                 elm = &node->elms[i];
197
198                 flags = get_elm_flags(node, node_offset,
199                                         elm, 'I',
200                                         left_bound, right_bound);
201                 print_btree_elm(elm, i, node->type, flags, "RBN", NULL);
202         }
203         printf("     }\n");
204
205         for (i = 0; i < node->count; ++i) {
206                 elm = &node->elms[i];
207
208                 switch(node->type) {
209                 case HAMMER_BTREE_TYPE_INTERNAL:
210                         if (search->normal == 0) {
211                                 if (elm->base.localization > search->lo ||
212                                     (elm->base.localization == search->lo &&
213                                      elm->base.obj_id > search->obj_id)) {
214                                         break;
215                                 }
216                                 if (elm[1].base.localization < search->lo ||
217                                     (elm[1].base.localization == search->lo &&
218                                      elm[1].base.obj_id < search->obj_id)) {
219                                         break;
220                                 }
221                         }
222                         if (elm->internal.subtree_offset) {
223                                 print_btree_node(elm->internal.subtree_offset,
224                                                  search, depth + 1,
225                                                  elm->internal.mirror_tid,
226                                                  &elm[0].base, &elm[1].base);
227                                 /*
228                                  * Cause show to do normal iteration after
229                                  * seeking to the lo:objid
230                                  */
231                                 search->normal = 1;
232                         }
233                         break;
234                 default:
235                         break;
236                 }
237         }
238         rel_buffer(buffer);
239 }
240
241 static __inline
242 int
243 is_root_btree_beg(u_int8_t type, int i, hammer_btree_elm_t elm)
244 {
245         return (type == HAMMER_BTREE_TYPE_INTERNAL &&
246                 i == 0 &&
247                 elm->base.localization == 0 &&
248                 elm->base.obj_id == (int64_t)-0x8000000000000000LL &&
249                 elm->base.key == (int64_t)-0x8000000000000000LL &&
250                 elm->base.create_tid == 1 &&
251                 elm->base.delete_tid == 1 &&
252                 elm->base.rec_type == 0 &&
253                 elm->base.obj_type == 0 &&
254                 elm->base.btype != 0);  /* depends on the original node */
255 }
256
257 static __inline
258 int
259 is_root_btree_end(u_int8_t type, int i, hammer_btree_elm_t elm)
260 {
261         return (type == HAMMER_BTREE_TYPE_INTERNAL &&
262                 i != 0 &&
263                 elm->base.localization == 0xFFFFFFFFU &&
264                 elm->base.obj_id == 0x7FFFFFFFFFFFFFFFLL &&
265                 elm->base.key == 0x7FFFFFFFFFFFFFFFLL &&
266                 elm->base.create_tid == 0xFFFFFFFFFFFFFFFFULL &&
267                 elm->base.delete_tid == 0 &&
268                 elm->base.rec_type == 0xFFFFU &&
269                 elm->base.obj_type == 0 &&
270                 elm->base.btype == 0);  /* not initialized */
271 }
272
273 static
274 void
275 print_btree_elm(hammer_btree_elm_t elm, int i, u_int8_t type,
276                 int flags, const char *label, const char *ext)
277 {
278         char flagstr[8] = { 0, '-', '-', '-', '-', '-', '-', 0 };
279         char deleted;
280         char rootelm;
281
282         flagstr[0] = flags ? 'B' : 'G';
283         if (flags & FLAG_TOOFARLEFT)
284                 flagstr[2] = 'L';
285         if (flags & FLAG_TOOFARRIGHT)
286                 flagstr[3] = 'R';
287         if (flags & FLAG_BADTYPE)
288                 flagstr[4] = 'T';
289         if (flags & FLAG_BADCHILDPARENT)
290                 flagstr[5] = 'C';
291         if (flags & FLAG_BADMIRRORTID)
292                 flagstr[6] = 'M';
293
294         /*
295          * Check if elm is derived from root split
296          */
297         if (is_root_btree_beg(type, i, elm))
298                 rootelm = '>';
299         else if (is_root_btree_end(type, i, elm))
300                 rootelm = '<';
301         else
302                 rootelm = ' ';
303
304         if (elm->base.delete_tid)
305                 deleted = 'd';
306         else
307                 deleted = ' ';
308
309         printf("%s\t%s %2d %c ",
310                flagstr, label, i,
311                (elm->base.btype ? elm->base.btype : '?'));
312         printf("lo=%08x obj=%016jx rt=%02x key=%016jx ot=%02x\n",
313                elm->base.localization,
314                (uintmax_t)elm->base.obj_id,
315                elm->base.rec_type,
316                (uintmax_t)elm->base.key,
317                elm->base.obj_type);
318         printf("\t       %c tids %016jx:%016jx ",
319                (rootelm == ' ' ? deleted : rootelm),
320                (uintmax_t)elm->base.create_tid,
321                (uintmax_t)elm->base.delete_tid);
322
323         switch(type) {
324         case HAMMER_BTREE_TYPE_INTERNAL:
325                 printf("suboff=%016jx",
326                        (uintmax_t)elm->internal.subtree_offset);
327                 if (QuietOpt < 3) {
328                         printf(" mirror %016jx",
329                                (uintmax_t)elm->internal.mirror_tid);
330                 }
331                 if (ext)
332                         printf(" %s", ext);
333                 break;
334         case HAMMER_BTREE_TYPE_LEAF:
335                 if (ext)
336                         printf(" %s", ext);
337                 switch(elm->base.btype) {
338                 case HAMMER_BTREE_TYPE_RECORD:
339                         if (QuietOpt < 3)
340                                 printf("\n%s\t         ", check_data_crc(elm));
341                         else
342                                 printf("\n\t         ");
343                         printf("dataoff=%016jx/%d",
344                                (uintmax_t)elm->leaf.data_offset,
345                                elm->leaf.data_len);
346                         if (QuietOpt < 3) {
347                                 printf(" crc=%04x", elm->leaf.data_crc);
348                                 printf("\n\t         fills=");
349                                 print_bigblock_fill(elm->leaf.data_offset);
350                         }
351                         if (QuietOpt < 2)
352                                 print_record(elm);
353                         break;
354                 }
355                 break;
356         default:
357                 break;
358         }
359         printf("\n");
360 }
361
362 static
363 int
364 get_elm_flags(hammer_node_ondisk_t node, hammer_off_t node_offset,
365                 hammer_btree_elm_t elm, u_int8_t btype,
366                 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
367 {
368         int flags = 0;
369
370         switch(node->type) {
371         case HAMMER_BTREE_TYPE_INTERNAL:
372                 if (elm->internal.subtree_offset) {
373                         struct buffer_info *buffer = NULL;
374                         hammer_node_ondisk_t subnode;
375
376                         subnode = get_node(elm->internal.subtree_offset,
377                                            &buffer);
378                         if (subnode == NULL)
379                                 flags |= FLAG_BADCHILDPARENT;
380                         else if (subnode->parent != node_offset)
381                                 flags |= FLAG_BADCHILDPARENT;
382                         rel_buffer(buffer);
383                 }
384                 if (elm->internal.mirror_tid > node->mirror_tid)
385                         flags |= FLAG_BADMIRRORTID;
386
387                 switch(btype) {
388                 case HAMMER_BTREE_TYPE_INTERNAL:
389                         if (left_bound == NULL || right_bound == NULL)
390                                 break;
391                         if (hammer_btree_cmp(&elm->base, left_bound) < 0)
392                                 flags |= FLAG_TOOFARLEFT;
393                         if (hammer_btree_cmp(&elm->base, right_bound) > 0)
394                                 flags |= FLAG_TOOFARRIGHT;
395                         break;
396                 case HAMMER_BTREE_TYPE_LEAF:
397                         if (left_bound == NULL || right_bound == NULL)
398                                 break;
399                         if (hammer_btree_cmp(&elm->base, left_bound) < 0)
400                                 flags |= FLAG_TOOFARLEFT;
401                         if (hammer_btree_cmp(&elm->base, right_bound) >= 0)
402                                 flags |= FLAG_TOOFARRIGHT;
403                         break;
404                 default:
405                         flags |= FLAG_BADTYPE;
406                         break;
407                 }
408                 break;
409         case HAMMER_BTREE_TYPE_LEAF:
410                 if (node->mirror_tid == 0 &&
411                     !(node->parent == 0 && node->count == 2)) {
412                         flags |= FLAG_BADMIRRORTID;
413                 }
414                 if (elm->base.create_tid && node->mirror_tid &&
415                     elm->base.create_tid > node->mirror_tid) {
416                         flags |= FLAG_BADMIRRORTID;
417                 }
418                 if (elm->base.delete_tid && node->mirror_tid &&
419                     elm->base.delete_tid > node->mirror_tid) {
420                         flags |= FLAG_BADMIRRORTID;
421                 }
422                 switch(btype) {
423                 case HAMMER_BTREE_TYPE_RECORD:
424                         if (left_bound == NULL || right_bound == NULL)
425                                 break;
426                         if (hammer_btree_cmp(&elm->base, left_bound) < 0)
427                                 flags |= FLAG_TOOFARLEFT;
428                         if (hammer_btree_cmp(&elm->base, right_bound) >= 0)
429                                 flags |= FLAG_TOOFARRIGHT;
430                         break;
431                 default:
432                         flags |= FLAG_BADTYPE;
433                         break;
434                 }
435                 break;
436         default:
437                 flags |= FLAG_BADTYPE;
438                 break;
439         }
440         return(flags);
441 }
442
443 static
444 void
445 print_bigblock_fill(hammer_off_t offset)
446 {
447         struct hammer_blockmap_layer1 layer1;
448         struct hammer_blockmap_layer2 layer2;
449         int fill;
450         int error;
451
452         blockmap_lookup(offset, &layer1, &layer2, &error);
453         if (error) {
454                 printf("z%d:%lld=BADZ",
455                         HAMMER_ZONE_DECODE(offset),
456                         (offset & ~HAMMER_OFF_ZONE_MASK) /
457                             HAMMER_BIGBLOCK_SIZE
458                 );
459         } else {
460                 fill = layer2.bytes_free * 100 / HAMMER_BIGBLOCK_SIZE;
461                 fill = 100 - fill;
462
463                 printf("z%d:%lld=%d%%",
464                         HAMMER_ZONE_DECODE(offset),
465                         (offset & ~HAMMER_OFF_ZONE_MASK) /
466                             HAMMER_BIGBLOCK_SIZE,
467                         fill
468                 );
469         }
470 }
471
472 /*
473  * Check the generic crc on a data element.  Inodes record types are
474  * special in that some of their fields are not CRCed.
475  *
476  * Also check that the zone is valid.
477  */
478 static
479 const char *
480 check_data_crc(hammer_btree_elm_t elm)
481 {
482         struct buffer_info *data_buffer;
483         hammer_off_t data_offset;
484         int32_t data_len;
485         int32_t len;
486         u_int32_t crc;
487         int error;
488         char *ptr;
489
490         data_offset = elm->leaf.data_offset;
491         data_len = elm->leaf.data_len;
492         data_buffer = NULL;
493         if (data_offset == 0 || data_len == 0)
494                 return("Z");
495
496         crc = 0;
497         error = 0;
498         while (data_len) {
499                 blockmap_lookup(data_offset, NULL, NULL, &error);
500                 if (error)
501                         break;
502
503                 ptr = get_buffer_data(data_offset, &data_buffer, 0);
504                 len = HAMMER_BUFSIZE - ((int)data_offset & HAMMER_BUFMASK);
505                 if (len > data_len)
506                         len = (int)data_len;
507                 if (elm->leaf.base.rec_type == HAMMER_RECTYPE_INODE &&
508                     data_len == sizeof(struct hammer_inode_data)) {
509                         crc = crc32_ext(ptr, HAMMER_INODE_CRCSIZE, crc);
510                 } else {
511                         crc = crc32_ext(ptr, len, crc);
512                 }
513                 data_len -= len;
514                 data_offset += len;
515         }
516         if (data_buffer)
517                 rel_buffer(data_buffer);
518         if (error) {
519                 switch (error) {        /* bad offset */
520                 case -1:
521                         return("BO-ZL");
522                 case -2:
523                         return("BO-ZG");
524                 case -3:
525                         return("BO-RV");
526                 case -4:
527                         return("BO-AO");
528                 case -5:
529                         return("BO-DE");
530                 case -6:
531                         return("BO-L1");
532                 case -7:
533                         return("BO-LU");
534                 case -8:
535                         return("BO-L2");
536                 case -9:
537                         return("BO-LZ");
538                 default:
539                         return("BO-??");
540                 }
541         }
542         if (crc == elm->leaf.data_crc)
543                 return("");
544         return("BX");                   /* bad crc */
545 }
546
547 static
548 void
549 print_config(char *cfgtxt)
550 {
551         char *token;
552
553         printf("\n%17stext=\"\n", "");
554         while((token = strsep(&cfgtxt, "\r\n")) != NULL) {
555                 printf("%17s  %s\n", "", token);
556         }
557         printf("%17s\"", "");
558 }
559
560 static
561 void
562 print_record(hammer_btree_elm_t elm)
563 {
564         struct buffer_info *data_buffer;
565         hammer_off_t data_offset;
566         int32_t data_len;
567         hammer_data_ondisk_t data;
568         u_int32_t status;
569         char *str1 = NULL;
570         char *str2 = NULL;
571
572         data_offset = elm->leaf.data_offset;
573         data_len = elm->leaf.data_len;
574         data_buffer = NULL;
575
576         if (data_offset)
577                 data = get_buffer_data(data_offset, &data_buffer, 0);
578         else
579                 data = NULL;
580
581         switch(elm->leaf.base.rec_type) {
582         case HAMMER_RECTYPE_UNKNOWN:
583                 printf("\n%17s", "");
584                 printf("unknown");
585                 break;
586         case HAMMER_RECTYPE_INODE:
587                 printf("\n%17s", "");
588                 printf("size=%jd nlinks=%jd",
589                        (intmax_t)data->inode.size,
590                        (intmax_t)data->inode.nlinks);
591                 if (QuietOpt < 1) {
592                         printf(" mode=%05o uflags=%08x\n",
593                                 data->inode.mode,
594                                 data->inode.uflags);
595                         printf("%17s", "");
596                         printf("ctime=%016jx pobjid=%016jx obj_type=%d\n",
597                                 (uintmax_t)data->inode.ctime,
598                                 (uintmax_t)data->inode.parent_obj_id,
599                                 data->inode.obj_type);
600                         printf("%17s", "");
601                         printf("mtime=%016jx", (uintmax_t)data->inode.mtime);
602                         printf(" caps=%02x", data->inode.cap_flags);
603                 }
604                 break;
605         case HAMMER_RECTYPE_DIRENTRY:
606                 printf("\n%17s", "");
607                 data_len -= HAMMER_ENTRY_NAME_OFF;
608                 printf("dir-entry ino=%016jx lo=%08x name=\"%*.*s\"",
609                        (uintmax_t)data->entry.obj_id,
610                        data->entry.localization,
611                        data_len, data_len, data->entry.name);
612                 break;
613         case HAMMER_RECTYPE_FIX:
614                 switch(elm->leaf.base.key) {
615                 case HAMMER_FIXKEY_SYMLINK:
616                         data_len -= HAMMER_SYMLINK_NAME_OFF;
617                         printf("\n%17s", "");
618                         printf("symlink=\"%*.*s\"", data_len, data_len,
619                                 data->symlink.name);
620                         break;
621                 default:
622                         break;
623                 }
624                 break;
625         case HAMMER_RECTYPE_PFS:
626                 printf("\n%17s", "");
627                 printf("sync_beg_tid=%016jx sync_end_tid=%016jx\n",
628                         (intmax_t)data->pfsd.sync_beg_tid,
629                         (intmax_t)data->pfsd.sync_end_tid);
630                 uuid_to_string(&data->pfsd.shared_uuid, &str1, &status);
631                 uuid_to_string(&data->pfsd.unique_uuid, &str2, &status);
632                 printf("%17s", "");
633                 printf("shared_uuid=%s\n", str1);
634                 printf("%17s", "");
635                 printf("unique_uuid=%s\n", str2);
636                 printf("%17s", "");
637                 printf("mirror_flags=%08x label=\"%s\"",
638                         data->pfsd.mirror_flags, data->pfsd.label);
639                 if (data->pfsd.snapshots[0])
640                         printf(" snapshots=\"%s\"", data->pfsd.snapshots);
641                 free(str1);
642                 free(str2);
643                 break;
644         case HAMMER_RECTYPE_SNAPSHOT:
645                 printf("\n%17s", "");
646                 printf("tid=%016jx label=\"%s\"",
647                         (intmax_t)data->snap.tid, data->snap.label);
648                 break;
649         case HAMMER_RECTYPE_CONFIG:
650                 if (VerboseOpt > 2) {
651                         print_config(data->config.text);
652                 }
653                 break;
654         case HAMMER_RECTYPE_DATA:
655                 if (VerboseOpt > 3) {
656                         printf("\n");
657                         hexdump(data, data_len, "\t\t  ", 0);
658                 }
659                 break;
660         case HAMMER_RECTYPE_EXT:
661         case HAMMER_RECTYPE_DB:
662                 if (VerboseOpt > 2) {
663                         printf("\n");
664                         hexdump(data, data_len, "\t\t  ", 0);
665                 }
666                 break;
667         default:
668                 break;
669         }
670         if (data_buffer)
671                 rel_buffer(data_buffer);
672 }
673
674 /*
675  * Dump the UNDO FIFO
676  */
677 void
678 hammer_cmd_show_undo(void)
679 {
680         struct volume_info *volume;
681         hammer_blockmap_t rootmap;
682         hammer_off_t scan_offset;
683         hammer_fifo_any_t head;
684         struct buffer_info *data_buffer = NULL;
685
686         volume = get_volume(RootVolNo);
687         rootmap = &volume->ondisk->vol0_blockmap[HAMMER_ZONE_UNDO_INDEX];
688         printf("Volume header UNDO %016jx-%016jx/%016jx\n",
689                 (intmax_t)rootmap->first_offset,
690                 (intmax_t)rootmap->next_offset,
691                 (intmax_t)rootmap->alloc_offset);
692         printf("Undo map is %jdMB\n",
693                 (intmax_t)((rootmap->alloc_offset & HAMMER_OFF_LONG_MASK) /
694                            (1024 * 1024)));
695         scan_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
696         while (scan_offset < rootmap->alloc_offset) {
697                 head = get_buffer_data(scan_offset, &data_buffer, 0);
698                 printf("%016jx ", scan_offset);
699
700                 switch(head->head.hdr_type) {
701                 case HAMMER_HEAD_TYPE_PAD:
702                         printf("PAD(%04x)\n", head->head.hdr_size);
703                         break;
704                 case HAMMER_HEAD_TYPE_DUMMY:
705                         printf("DUMMY(%04x) seq=%08x\n",
706                                 head->head.hdr_size, head->head.hdr_seq);
707                         break;
708                 case HAMMER_HEAD_TYPE_UNDO:
709                         printf("UNDO(%04x) seq=%08x "
710                                "dataoff=%016jx bytes=%d\n",
711                                 head->head.hdr_size, head->head.hdr_seq,
712                                 (intmax_t)head->undo.undo_offset,
713                                 head->undo.undo_data_bytes);
714                         break;
715                 case HAMMER_HEAD_TYPE_REDO:
716                         printf("REDO(%04x) seq=%08x flags=%08x "
717                                "objid=%016jx logoff=%016jx bytes=%d\n",
718                                 head->head.hdr_size, head->head.hdr_seq,
719                                 head->redo.redo_flags,
720                                 (intmax_t)head->redo.redo_objid,
721                                 (intmax_t)head->redo.redo_offset,
722                                 head->redo.redo_data_bytes);
723                         break;
724                 default:
725                         printf("UNKNOWN(%04x,%04x) seq=%08x\n",
726                                 head->head.hdr_type,
727                                 head->head.hdr_size,
728                                 head->head.hdr_seq);
729                         break;
730                 }
731                 if ((head->head.hdr_size & HAMMER_HEAD_ALIGN_MASK) ||
732                     head->head.hdr_size == 0 ||
733                     head->head.hdr_size > HAMMER_UNDO_ALIGN -
734                                     ((u_int)scan_offset & HAMMER_UNDO_MASK)) {
735                         printf("Illegal size field, skipping to "
736                                "next boundary\n");
737                         scan_offset = (scan_offset + HAMMER_UNDO_MASK) &
738                                         ~HAMMER_UNDO_MASK64;
739                 } else {
740                         scan_offset += head->head.hdr_size;
741                 }
742         }
743         if (data_buffer)
744                 rel_buffer(data_buffer);
745 }