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