2 * Copyright (c) 2011-2012 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@dragonflybsd.org>
6 * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 static void shell_msghandler(dmsg_msg_t
*msg
, int unmanaged
);
41 static void shell_ttymsg(dmsg_iocom_t
*iocom
);
42 static void CountFreeBlocks(hammer2_bmap_data_t
*bmap
,
43 hammer2_off_t
*accum16
, hammer2_off_t
*accum64
);
45 /************************************************************************
47 ************************************************************************/
50 cmd_shell(const char *hostname
)
52 dmsg_master_service_info_t
*info
;
56 fd
= dmsg_connect(hostname
);
60 info
= malloc(sizeof(*info
));
61 bzero(info
, sizeof(*info
));
64 info
->usrmsg_callback
= shell_msghandler
;
65 info
->altmsg_callback
= shell_ttymsg
;
66 info
->label
= strdup("debug");
67 pthread_create(&thread
, NULL
, dmsg_master_service
, info
);
68 pthread_join(thread
, NULL
);
75 cmd_shell(const char *hostname
)
77 struct dmsg_iocom iocom
;
82 * Connect to the target
84 fd
= dmsg_connect(hostname
);
89 * Initialize the session and transmit an empty DMSG_DBG_SHELL
90 * to cause the remote end to generate a prompt.
92 dmsg_iocom_init(&iocom
, fd
, 0,
97 fcntl(0, F_SETFL
, O_NONBLOCK
);
98 printf("debug: connected\n");
100 msg
= dmsg_msg_alloc(&iocom
.state0
, 0, DMSG_DBG_SHELL
, NULL
, NULL
);
102 dmsg_iocom_core(&iocom
);
103 fprintf(stderr
, "debug: disconnected\n");
110 * Debug session front-end
112 * Callback from dmsg_iocom_core() when messages might be present
117 shell_msghandler(dmsg_msg_t
*msg
, int unmanaged
)
124 case DMSG_LNK_ERROR
| DMSGF_REPLY
:
126 * One-way non-transactional LNK_ERROR messages typically
127 * indicate a connection failure. Error code 0 is used by
128 * the debug shell to indicate no more results from last cmd.
130 if (msg
->any
.head
.error
) {
131 fprintf(stderr
, "Stream failure: %s\n",
134 write(1, "debug> ", 7);
137 case DMSG_LNK_ERROR
| DMSGF_DELETE
:
138 /* ignore termination of LNK_CONN */
143 * We send the commands, not accept them.
144 * (one-way message, not transactional)
147 dmsg_msg_reply(msg
, DMSG_ERR_NOSUPP
);
149 case DMSG_DBG_SHELL
| DMSGF_REPLY
:
151 * A reply from the remote is data we copy to stdout.
152 * (one-way message, not transactional)
155 msg
->aux_data
[msg
->aux_size
- 1] = 0;
156 write(1, msg
->aux_data
, strlen(msg
->aux_data
));
160 case DMSG_LNK_CONN
| DMSGF_CREATE
:
161 fprintf(stderr
, "Debug Shell received LNK_CONN\n");
162 nmsg
= dmsg_msg_alloc(&msg
->state
->iocom
->state0
, 0,
165 dmsg_msg_write(nmsg
);
166 dmsg_msg_reply(msg
, DMSG_ERR_NOSUPP
);
168 case DMSG_LNK_CONN
| DMSGF_DELETE
:
173 * Ignore any unknown messages, Terminate any unknown
174 * transactions with an error.
176 fprintf(stderr
, "Unknown message: %s\n", dmsg_msg_str(msg
));
178 if (msg
->any
.head
.cmd
& DMSGF_CREATE
)
179 dmsg_msg_reply(msg
, DMSG_ERR_NOSUPP
);
180 if (msg
->any
.head
.cmd
& DMSGF_DELETE
)
181 dmsg_msg_reply(msg
, DMSG_ERR_NOSUPP
);
188 * Debug session front-end
192 shell_ttymsg(dmsg_iocom_t
*iocom
)
194 dmsg_state_t
*pstate
;
200 if (fgets(buf
, sizeof(buf
), stdin
) != NULL
) {
202 pstate
= dmsg_findspan(strtok(buf
+ 1, " \t\n"));
203 cmd
= strtok(NULL
, "\n");
205 pstate
= &iocom
->state0
;
206 cmd
= strtok(buf
, "\n");
209 len
= strlen(cmd
) + 1;
210 msg
= dmsg_msg_alloc(pstate
, len
, DMSG_DBG_SHELL
,
212 bcopy(cmd
, msg
->aux_data
, len
);
215 fprintf(stderr
, "@msgid not found\n");
218 * This should cause the remote end to generate
219 * a debug> prompt (and thus shows that there is
222 msg
= dmsg_msg_alloc(pstate
, 0, DMSG_DBG_SHELL
,
226 } else if (feof(stdin
)) {
228 * Set EOF flag without setting any error code for normal
231 iocom
->flags
|= DMSG_IOCOMF_EOF
;
238 * Debug session back-end (on remote side)
240 static void shell_span(dmsg_msg_t
*msg
, char *cmdbuf
);
241 static void shell_ping(dmsg_msg_t
*msg
, char *cmdbuf
);
244 hammer2_shell_parse(dmsg_msg_t
*msg
, int unmanaged
)
246 dmsg_iocom_t
*iocom
= msg
->state
->iocom
;
252 * Filter on debug shell commands and ping responses only
254 cmd
= msg
->any
.head
.cmd
;
255 if ((cmd
& DMSGF_CMDSWMASK
) == (DMSG_LNK_PING
| DMSGF_REPLY
)) {
256 dmsg_printf(iocom
, "ping reply\n");
260 if ((cmd
& DMSGF_PROTOS
) != DMSG_PROTO_DBG
) {
262 dmsg_msg_reply(msg
, DMSG_ERR_NOSUPP
);
265 if ((cmd
& DMSGF_CMDSWMASK
) != DMSG_DBG_SHELL
) {
267 dmsg_msg_reply(msg
, DMSG_ERR_NOSUPP
);
272 * Debug shell command
274 cmdbuf
= msg
->aux_data
;
275 cmdp
= strsep(&cmdbuf
, " \t");
277 if (cmdp
== NULL
|| *cmdp
== 0) {
279 } else if (strcmp(cmdp
, "ping") == 0) {
280 shell_ping(msg
, cmdbuf
);
281 } else if (strcmp(cmdp
, "span") == 0) {
282 shell_span(msg
, cmdbuf
);
283 } else if (strcmp(cmdp
, "tree") == 0) {
284 dmsg_shell_tree(iocom
, cmdbuf
); /* dump spanning tree */
285 } else if (strcmp(cmdp
, "help") == 0 || strcmp(cmdp
, "?") == 0) {
286 dmsg_printf(iocom
, "help Command help\n");
287 dmsg_printf(iocom
, "span <host> Span to target host\n");
288 dmsg_printf(iocom
, "tree Dump spanning tree\n");
289 dmsg_printf(iocom
, "@span <cmd> Issue via circuit\n");
291 dmsg_printf(iocom
, "Unrecognized command: %s\n", cmdp
);
293 dmsg_printf(iocom
, "debug> ");
297 shell_ping(dmsg_msg_t
*msg
, char *cmdbuf __unused
)
299 dmsg_iocom_t
*iocom
= msg
->state
->iocom
;
302 dmsg_printf(iocom
, "sending ping\n");
303 m2
= dmsg_msg_alloc(msg
->state
, 0, DMSG_LNK_PING
, NULL
, NULL
);
308 shell_span(dmsg_msg_t
*msg
, char *cmdbuf
)
310 dmsg_iocom_t
*iocom
= msg
->state
->iocom
;
311 dmsg_master_service_info_t
*info
;
312 const char *hostname
= strsep(&cmdbuf
, " \t");
317 * Connect to the target
319 if (hostname
== NULL
) {
322 fd
= dmsg_connect(hostname
);
326 * Start master service
329 dmsg_printf(iocom
, "Connection to %s failed\n", hostname
);
331 dmsg_printf(iocom
, "Connected to %s\n", hostname
);
333 info
= malloc(sizeof(*info
));
334 bzero(info
, sizeof(*info
));
337 info
->usrmsg_callback
= hammer2_shell_parse
;
338 info
->label
= strdup("client");
340 pthread_create(&thread
, NULL
, dmsg_master_service
, info
);
341 /*pthread_join(thread, &res);*/
345 /************************************************************************
347 ************************************************************************
349 * Connect to the target manually (not via the cluster list embedded in
350 * a hammer2 filesystem) and initiate the SPAN protocol.
353 cmd_debugspan(const char *hostname
)
360 * Connect to the target
362 fd
= dmsg_connect(hostname
);
366 printf("debugspan: connected to %s, starting CONN/SPAN\n", hostname
);
367 pthread_create(&thread
, NULL
,
368 dmsg_master_service
, (void *)(intptr_t)fd
);
369 pthread_join(thread
, &res
);
373 /************************************************************************
375 ************************************************************************/
377 static void show_bref(hammer2_volume_data_t
*voldata
, int fd
, int tab
,
378 int bi
, hammer2_blockref_t
*bref
,
379 int dofreemap
, int norecurse
);
380 static void tabprintf(int tab
, const char *ctl
, ...);
382 int64_t TotalFreeAccum16
;
383 int64_t TotalFreeAccum64
;
386 cmd_show(const char *devpath
, int dofreemap
)
388 hammer2_blockref_t broot
;
389 hammer2_blockref_t best
;
390 hammer2_media_data_t media
;
395 TotalFreeAccum16
= 0; /* includes TotalFreeAccum64 */
396 TotalFreeAccum64
= 0;
397 fd
= open(devpath
, O_RDONLY
);
404 * Show the tree using the best volume header.
405 * -vvv will show the tree for all four volume headers.
408 bzero(&best
, sizeof(best
));
409 for (i
= 0; i
< 4; ++i
) {
410 bzero(&broot
, sizeof(broot
));
411 broot
.type
= HAMMER2_BREF_TYPE_VOLUME
;
412 broot
.data_off
= (i
* HAMMER2_ZONE_BYTES64
) |
414 lseek(fd
, broot
.data_off
& ~HAMMER2_OFF_MASK_RADIX
, 0);
415 if (read(fd
, &media
, HAMMER2_PBUFSIZE
) ==
416 (ssize_t
)HAMMER2_PBUFSIZE
) {
417 broot
.mirror_tid
= media
.voldata
.mirror_tid
;
418 if (best_i
< 0 || best
.mirror_tid
< broot
.mirror_tid
) {
423 show_bref(&media
.voldata
, fd
, 0, i
, &broot
, dofreemap
, 0);
427 show_bref(&media
.voldata
, fd
, 0, best_i
, &best
, dofreemap
, 0);
430 if (dofreemap
&& VerboseOpt
< 3) {
431 printf("Total free storage: %6.3fGB (%6.3fGB in 64KB chunks)\n",
432 (double)TotalFreeAccum16
/ (1024.0 * 1024.0 * 1024.0),
433 (double)TotalFreeAccum64
/ (1024.0 * 1024.0 * 1024.0));
439 extern uint32_t iscsi_crc32(const void *buf
, size_t size
);
441 show_bref(hammer2_volume_data_t
*voldata
, int fd
, int tab
,
442 int bi
, hammer2_blockref_t
*bref
, int dofreemap
, int norecurse
)
444 hammer2_media_data_t media
;
445 hammer2_blockref_t
*bscan
;
453 const char *type_str
;
459 case HAMMER2_BREF_TYPE_EMPTY
:
462 case HAMMER2_BREF_TYPE_DIRENT
:
465 case HAMMER2_BREF_TYPE_INODE
:
468 case HAMMER2_BREF_TYPE_INDIRECT
:
471 case HAMMER2_BREF_TYPE_DATA
:
474 case HAMMER2_BREF_TYPE_VOLUME
:
477 case HAMMER2_BREF_TYPE_FREEMAP
:
478 type_str
= "freemap";
480 case HAMMER2_BREF_TYPE_FREEMAP_NODE
:
481 type_str
= "fmapnode";
483 case HAMMER2_BREF_TYPE_FREEMAP_LEAF
:
484 type_str
= "fbitmap";
487 type_str
= "unknown";
492 "%s.%-3d %016jx %016jx/%-2d "
493 "mir=%016jx mod=%016jx leafcnt=%d ",
494 type_str
, bi
, (intmax_t)bref
->data_off
,
495 (intmax_t)bref
->key
, (intmax_t)bref
->keybits
,
496 (intmax_t)bref
->mirror_tid
, (intmax_t)bref
->modify_tid
,
500 printf("flags=%02x ", bref
->flags
);
501 if (bref
->type
== HAMMER2_BREF_TYPE_FREEMAP_NODE
||
502 bref
->type
== HAMMER2_BREF_TYPE_FREEMAP_LEAF
) {
503 printf("bigmask=%08x avail=%ld ",
504 bref
->check
.freemap
.bigmask
, bref
->check
.freemap
.avail
);
507 bytes
= (bref
->data_off
& HAMMER2_OFF_MASK_RADIX
);
509 bytes
= (size_t)1 << bytes
;
511 hammer2_off_t io_off
;
512 hammer2_off_t io_base
;
516 io_off
= bref
->data_off
& ~HAMMER2_OFF_MASK_RADIX
;
517 io_base
= io_off
& ~(hammer2_off_t
)(HAMMER2_MINIOSIZE
- 1);
519 boff
= io_off
- io_base
;
521 io_bytes
= HAMMER2_MINIOSIZE
;
522 while (io_bytes
+ boff
< bytes
)
525 if (io_bytes
> sizeof(media
)) {
526 printf("(bad block size %zd)\n", bytes
);
529 if (bref
->type
!= HAMMER2_BREF_TYPE_DATA
|| VerboseOpt
>= 1) {
530 lseek(fd
, io_base
, 0);
531 if (read(fd
, &media
, io_bytes
) != (ssize_t
)io_bytes
) {
532 printf("(media read failed)\n");
536 bcopy((char *)&media
+ boff
, &media
, bytes
);
547 * Check data integrity in verbose mode, otherwise we are just doing
548 * a quick meta-data scan. Meta-data integrity is always checked.
549 * (Also see the check above that ensures the media data is loaded,
550 * otherwise there's no data to check!).
552 * WARNING! bref->check state may be used for other things when
553 * bref has no data (bytes == 0).
556 (bref
->type
!= HAMMER2_BREF_TYPE_DATA
|| VerboseOpt
>= 1)) {
557 switch(HAMMER2_DEC_CHECK(bref
->methods
)) {
558 case HAMMER2_CHECK_NONE
:
559 printf("(meth %02x) ", bref
->methods
);
561 case HAMMER2_CHECK_DISABLED
:
562 printf("(meth %02x) ", bref
->methods
);
564 case HAMMER2_CHECK_ISCSI32
:
565 cv
= hammer2_icrc32(&media
, bytes
);
566 if (bref
->check
.iscsi32
.value
!= cv
) {
567 printf("(icrc %02x:%08x/%08x failed) ",
569 bref
->check
.iscsi32
.value
,
573 printf("(meth %02x, iscsi32=%08x) ",
577 case HAMMER2_CHECK_XXHASH64
:
578 cv64
= XXH64(&media
, bytes
, XXH_HAMMER2_SEED
);
579 if (bref
->check
.xxhash64
.value
!= cv64
) {
580 printf("(xxhash64 %02x:%016jx/%016jx failed) ",
582 bref
->check
.xxhash64
.value
,
586 printf("(meth %02x, xxh=%016jx) ",
587 bref
->methods
, cv64
);
590 case HAMMER2_CHECK_SHA192
:
591 printf("(meth %02x) ", bref
->methods
);
593 case HAMMER2_CHECK_FREEMAP
:
594 cv
= hammer2_icrc32(&media
, bytes
);
595 if (bref
->check
.freemap
.icrc32
!= cv
) {
596 printf("(fcrc %02x:%08x/%08x failed) ",
598 bref
->check
.freemap
.icrc32
,
602 printf("(meth %02x, fcrc=%08x) ",
610 case HAMMER2_BREF_TYPE_EMPTY
:
613 case HAMMER2_BREF_TYPE_DIRENT
:
615 if (bref
->embed
.dirent
.namlen
<= sizeof(bref
->check
.buf
)) {
616 tabprintf(tab
, "filename \"%*.*s\"\n",
617 bref
->embed
.dirent
.namlen
,
618 bref
->embed
.dirent
.namlen
,
621 tabprintf(tab
, "filename \"%*.*s\"\n",
622 bref
->embed
.dirent
.namlen
,
623 bref
->embed
.dirent
.namlen
,
626 tabprintf(tab
, "inum 0x%016jx\n",
627 (uintmax_t)bref
->embed
.dirent
.inum
);
628 tabprintf(tab
, "type %s\n",
629 hammer2_iptype_to_str(bref
->embed
.dirent
.type
));
631 case HAMMER2_BREF_TYPE_INODE
:
633 if (media
.ipdata
.meta
.op_flags
& HAMMER2_OPFLAG_DIRECTDATA
) {
636 bscan
= &media
.ipdata
.u
.blockset
.blockref
[0];
637 bcount
= HAMMER2_SET_COUNT
;
639 namelen
= media
.ipdata
.meta
.name_len
;
640 if (namelen
> HAMMER2_INODE_MAXNAME
)
642 tabprintf(tab
, "filename \"%*.*s\"\n",
643 namelen
, namelen
, media
.ipdata
.filename
);
644 tabprintf(tab
, "version %d\n", media
.ipdata
.meta
.version
);
645 tabprintf(tab
, "uflags 0x%08x\n",
646 media
.ipdata
.meta
.uflags
);
647 if (media
.ipdata
.meta
.rmajor
|| media
.ipdata
.meta
.rminor
) {
648 tabprintf(tab
, "rmajor %d\n",
649 media
.ipdata
.meta
.rmajor
);
650 tabprintf(tab
, "rminor %d\n",
651 media
.ipdata
.meta
.rminor
);
653 tabprintf(tab
, "ctime %s\n",
654 hammer2_time64_to_str(media
.ipdata
.meta
.ctime
, &str
));
655 tabprintf(tab
, "mtime %s\n",
656 hammer2_time64_to_str(media
.ipdata
.meta
.mtime
, &str
));
657 tabprintf(tab
, "atime %s\n",
658 hammer2_time64_to_str(media
.ipdata
.meta
.atime
, &str
));
659 tabprintf(tab
, "btime %s\n",
660 hammer2_time64_to_str(media
.ipdata
.meta
.btime
, &str
));
661 tabprintf(tab
, "uid %s\n",
662 hammer2_uuid_to_str(&media
.ipdata
.meta
.uid
, &str
));
663 tabprintf(tab
, "gid %s\n",
664 hammer2_uuid_to_str(&media
.ipdata
.meta
.gid
, &str
));
665 tabprintf(tab
, "type %s\n",
666 hammer2_iptype_to_str(media
.ipdata
.meta
.type
));
667 tabprintf(tab
, "opflgs 0x%02x\n",
668 media
.ipdata
.meta
.op_flags
);
669 tabprintf(tab
, "capflgs 0x%04x\n",
670 media
.ipdata
.meta
.cap_flags
);
671 tabprintf(tab
, "mode %-7o\n",
672 media
.ipdata
.meta
.mode
);
673 tabprintf(tab
, "inum 0x%016jx\n",
674 media
.ipdata
.meta
.inum
);
675 tabprintf(tab
, "size %ju\n",
676 (uintmax_t)media
.ipdata
.meta
.size
);
677 tabprintf(tab
, "nlinks %ju\n",
678 (uintmax_t)media
.ipdata
.meta
.nlinks
);
679 tabprintf(tab
, "iparent 0x%016jx\n",
680 (uintmax_t)media
.ipdata
.meta
.iparent
);
681 tabprintf(tab
, "name_key 0x%016jx\n",
682 (uintmax_t)media
.ipdata
.meta
.name_key
);
683 tabprintf(tab
, "name_len %u\n",
684 media
.ipdata
.meta
.name_len
);
685 tabprintf(tab
, "ncopies %u\n",
686 media
.ipdata
.meta
.ncopies
);
687 tabprintf(tab
, "compalg %u\n",
688 media
.ipdata
.meta
.comp_algo
);
689 tabprintf(tab
, "checkalg %u\n",
690 media
.ipdata
.meta
.check_algo
);
691 if ((media
.ipdata
.meta
.op_flags
& HAMMER2_OPFLAG_PFSROOT
) ||
692 media
.ipdata
.meta
.pfs_type
== HAMMER2_PFSTYPE_SUPROOT
) {
693 tabprintf(tab
, "pfs_type %u (%s)\n",
694 media
.ipdata
.meta
.pfs_type
,
695 hammer2_pfstype_to_str(media
.ipdata
.meta
.pfs_type
));
696 tabprintf(tab
, "pfs_inum 0x%016jx\n",
697 (uintmax_t)media
.ipdata
.meta
.pfs_inum
);
698 tabprintf(tab
, "pfs_clid %s\n",
699 hammer2_uuid_to_str(&media
.ipdata
.meta
.pfs_clid
,
701 tabprintf(tab
, "pfs_fsid %s\n",
702 hammer2_uuid_to_str(&media
.ipdata
.meta
.pfs_fsid
,
704 tabprintf(tab
, "pfs_lsnap_tid 0x%016jx\n",
705 (uintmax_t)media
.ipdata
.meta
.pfs_lsnap_tid
);
707 tabprintf(tab
, "data_quota %ju\n",
708 (uintmax_t)media
.ipdata
.meta
.data_quota
);
709 tabprintf(tab
, "data_count %ju\n",
710 (uintmax_t)bref
->embed
.stats
.data_count
);
711 tabprintf(tab
, "inode_quota %ju\n",
712 (uintmax_t)media
.ipdata
.meta
.inode_quota
);
713 tabprintf(tab
, "inode_count %ju\n",
714 (uintmax_t)bref
->embed
.stats
.inode_count
);
716 case HAMMER2_BREF_TYPE_INDIRECT
:
717 bscan
= &media
.npdata
[0];
718 bcount
= bytes
/ sizeof(hammer2_blockref_t
);
722 case HAMMER2_BREF_TYPE_DATA
:
724 if (VerboseOpt
>= 2) {
733 case HAMMER2_BREF_TYPE_VOLUME
:
734 printf("mirror_tid=%016jx freemap_tid=%016jx ",
735 media
.voldata
.mirror_tid
,
736 media
.voldata
.freemap_tid
);
738 bscan
= &media
.voldata
.freemap_blockset
.blockref
[0];
739 bcount
= HAMMER2_SET_COUNT
;
741 bscan
= &media
.voldata
.sroot_blockset
.blockref
[0];
742 bcount
= HAMMER2_SET_COUNT
;
746 case HAMMER2_BREF_TYPE_FREEMAP_LEAF
:
748 for (i
= 0; i
< HAMMER2_FREEMAP_COUNT
; ++i
) {
749 hammer2_off_t data_off
;
751 data_off
= bref
->key
+
752 i
* 256 * HAMMER2_FREEMAP_BLOCK_SIZE
;
754 if (media.bmdata[i].class == 0 &&
755 media.bmdata[i].avail == 0) {
759 #if HAMMER2_BMAP_ELEMENTS != 8
760 #error "cmd_debug.c: HAMMER2_BMAP_ELEMENTS expected to be 8"
763 tabprintf(tab
+ 4, "%016jx %04d.%04x (avail=%7d) "
764 "%016jx %016jx %016jx %016jx "
765 "%016jx %016jx %016jx %016jx\n",
767 i
, media
.bmdata
[i
].class,
768 media
.bmdata
[i
].avail
,
769 media
.bmdata
[i
].bitmapq
[0],
770 media
.bmdata
[i
].bitmapq
[1],
771 media
.bmdata
[i
].bitmapq
[2],
772 media
.bmdata
[i
].bitmapq
[3],
773 media
.bmdata
[i
].bitmapq
[4],
774 media
.bmdata
[i
].bitmapq
[5],
775 media
.bmdata
[i
].bitmapq
[6],
776 media
.bmdata
[i
].bitmapq
[7]);
777 if (data_off
>= voldata
->aux_end
&&
778 data_off
< voldata
->volu_size
) {
779 CountFreeBlocks(&media
.bmdata
[i
],
784 tabprintf(tab
, "}\n");
786 case HAMMER2_BREF_TYPE_FREEMAP_NODE
:
788 bscan
= &media
.npdata
[0];
789 bcount
= bytes
/ sizeof(hammer2_blockref_t
);
800 * Recurse if norecurse == 0. If the CRC failed, pass norecurse = 1.
801 * That is, if an indirect or inode fails we still try to list its
802 * direct children to help with debugging, but go no further than
803 * that because they are probably garbage.
805 for (i
= 0; norecurse
== 0 && i
< bcount
; ++i
) {
806 if (bscan
[i
].type
!= HAMMER2_BREF_TYPE_EMPTY
) {
811 show_bref(voldata
, fd
, tab
,
812 i
, &bscan
[i
], dofreemap
, failed
);
817 if (bref
->type
== HAMMER2_BREF_TYPE_INODE
)
818 tabprintf(tab
, "} (%s.%d, \"%*.*s\")\n",
820 namelen
, namelen
, media
.ipdata
.filename
);
822 tabprintf(tab
, "} (%s.%d)\n", type_str
,bi
);
828 CountFreeBlocks(hammer2_bmap_data_t
*bmap
,
829 hammer2_off_t
*accum16
, hammer2_off_t
*accum64
)
834 for (i
= 0; i
< 8; ++i
) {
835 uint64_t bm
= bmap
->bitmapq
[i
];
839 for (j
= 0; j
< 64; j
+= 2) {
840 if ((bm
& mask
) == 0)
844 for (j
= 0; j
< 64; j
+= 8) {
845 if ((bm
& mask
) == 0)
852 cmd_hash(int ac
, const char **av
)
856 for (i
= 0; i
< ac
; ++i
) {
857 printf("%016jx %s\n", dirhash(av
[i
], strlen(av
[i
])), av
[i
]);
863 cmd_dumpchain(const char *path
, u_int flags
)
865 int dummy
= (int)flags
;
868 fd
= open(path
, O_RDONLY
);
870 ioctl(fd
, HAMMER2IOC_DEBUG_DUMP
, &dummy
);
873 fprintf(stderr
, "unable to open %s\n", path
);
881 tabprintf(int tab
, const char *ctl
, ...)
885 printf("%*.*s", tab
, tab
, "");