Beispiel #1
0
/*
 * nh_dump_nodes - dump info about nodes to stdout
 */
void nh_dump_nodes()
{
	print_node_info(0);
	print_node_info(NH_MEMS);
	print_node_info(NH_CPUS);
	print_node_info(NH_MEMS | NH_CPUS);
}
int main(int argc, char **argv) {
	if(argc != 3) {
		fprintf(stderr, "Usage: filepath print_chilren?");
	}
	if(atoi(argv[2]) > 0) {
		print_node_info(argv[1], true, "");
	} else {
		print_node_info(argv[1], false, "");
	}
	return 0;
}
int dump_node(struct f2fs_sb_info *sbi, nid_t nid)
{
	struct node_info ni;
	struct f2fs_node *node_blk;
	int ret;

	ret = get_node_info(sbi, nid, &ni);
	ASSERT(ret >= 0);

	node_blk = calloc(BLOCK_SZ, 1);
	dev_read_block(node_blk, ni.blk_addr);

	DBG(1, "Node ID               [0x%x]\n", nid);
	DBG(1, "nat_entry.block_addr  [0x%x]\n", ni.blk_addr);
	DBG(1, "nat_entry.version     [0x%x]\n", ni.version);
	DBG(1, "nat_entry.ino         [0x%x]\n", ni.ino);

	if (ni.blk_addr == 0x0) {
		MSG(0, "Invalid nat entry\n\n");
	}

	DBG(1, "node_blk.footer.ino [0x%x]\n", le32_to_cpu(node_blk->footer.ino));
	DBG(1, "node_blk.footer.nid [0x%x]\n", le32_to_cpu(node_blk->footer.nid));

	if (le32_to_cpu(node_blk->footer.ino) == ni.ino &&
			le32_to_cpu(node_blk->footer.nid) == ni.nid) {
		print_node_info(node_blk);
	} else {
		MSG(0, "Invalid node block\n\n");
	}

	free(node_blk);
	return 0;
}
Beispiel #4
0
static void print_tree_recurse(FILE * stream,
                               utree_t * tree, 
                               int indend_level, 
                               int * active_node_order)
{
  int i,j;

  if (!tree) return;

  for (i = 0; i < indend_level; ++i)
  {
    if (active_node_order[i])
      fprintf(stream,"|");
    else
      fprintf(stream," ");

    for (j = 0; j < indend_space-1; ++j)
      fprintf(stream," ");
  }
  fprintf(stream,"\n");

  for (i = 0; i < indend_level-1; ++i)
  {
    if (active_node_order[i])
      fprintf(stream,"|");
    else
      fprintf(stream," ");

    for (j = 0; j < indend_space-1; ++j)
      fprintf(stream," ");
  }

  fprintf(stream,"+");
  for (j = 0; j < indend_space-1; ++j)
    fprintf (stream,"-");
  if (tree->next) fprintf(stream,"+");

  print_node_info(stream,tree);

  if (active_node_order[indend_level-1] == 2) 
    active_node_order[indend_level-1] = 0;

  if (tree->next)
  {
    active_node_order[indend_level] = 1;
    print_tree_recurse(stream,
                       tree->next->back,
                       indend_level+1,
                       active_node_order);
    active_node_order[indend_level] = 2;
    print_tree_recurse(stream,
                       tree->next->next->back, 
                       indend_level+1,
                       active_node_order);
  }

}
Beispiel #5
0
static void print_tree_recurse(const snode_t * root,
                               int indent_level,
                               int * active_node_order,
                               int options)
{
  int i,j;

  if (!root) return;

  for (i = 0; i < indent_level; ++i)
  {
    if (active_node_order[i])
      printf("|");
    else
      printf(" ");

    for (j = 0; j < indent_space-1; ++j)
      printf(" ");
  }
  printf("\n");

  for (i = 0; i < indent_level-1; ++i)
  {
    if (active_node_order[i])
      printf("|");
    else
      printf(" ");

    for (j = 0; j < indent_space-1; ++j)
      printf(" ");
  }

  printf("+");
  for (j = 0; j < indent_space-1; ++j)
    printf ("-");
  if (root->left || root->right) printf("+");

  print_node_info(root, options);

  if (active_node_order[indent_level-1] == 2)
    active_node_order[indent_level-1] = 0;

  active_node_order[indent_level] = 1;
  print_tree_recurse(root->left,
                     indent_level+1,
                     active_node_order,
                     options);
  active_node_order[indent_level] = 2;
  print_tree_recurse(root->right,
                     indent_level+1,
                     active_node_order,
                     options);

}
void print_node_info(char* filename, bool print_children, char* parent){
	//char *filename = "node_000001_root.dat";
	node_t *node = read_node(filename);
	printf("Node ID: %i\nNode filepath: %s\nParent: %s\nNode fanout: %i\nNode child_num: %i\n\n", node->id, node->filepath, parent, node->fanout, node->child_num );
	int i;
	

	if(print_children && !node->is_leaf) {
		for (i = 0; i < node->child_num; i++){
			print_node_info(node->children[i], true, node->filepath);
		}
	}
}
Beispiel #7
0
void stree_show_ascii(const snode_t * root, int options)
{

  unsigned int indent_max = tree_indent_level(root,0);

  int * active_node_order = (int *)xmalloc((indent_max+1) * sizeof(int));
  active_node_order[0] = 1;
  active_node_order[1] = 1;

  print_node_info(root, options);
  print_tree_recurse(root->left,  1, active_node_order, options);
  print_tree_recurse(root->right, 1, active_node_order, options);
  free(active_node_order);
}
static void dump_node_from_blkaddr(u32 blk_addr)
{
	struct f2fs_node *node_blk;
	int ret;

	node_blk = calloc(BLOCK_SZ, 1);
	ASSERT(node_blk);

	ret = dev_read_block(node_blk, blk_addr);
	ASSERT(ret >= 0);

	if (config.dbg_lv > 0)
		print_node_info(node_blk);
	else
		print_inode_info(&node_blk->i, 1);

	free(node_blk);
}
int dump_inode_from_blkaddr(struct f2fs_sb_info *sbi, u32 blk_addr)
{
	nid_t ino, nid;
	int type, ret;
	struct f2fs_summary sum_entry;
	struct node_info ni;
	struct f2fs_node *node_blk;

	type = get_sum_entry(sbi, blk_addr, &sum_entry);
	nid = le32_to_cpu(sum_entry.nid);

	ret = get_node_info(sbi, nid, &ni);
	ASSERT(ret >= 0);

	DBG(1, "Note: blkaddr = main_blkaddr + segno * 512 + offset\n");
	DBG(1, "Block_addr            [0x%x]\n", blk_addr);
	DBG(1, " - Segno              [0x%x]\n", GET_SEGNO(sbi, blk_addr));
	DBG(1, " - Offset             [0x%x]\n", OFFSET_IN_SEG(sbi, blk_addr));
	DBG(1, "SUM.nid               [0x%x]\n", nid);
	DBG(1, "SUM.type              [%s]\n", seg_type_name[type]);
	DBG(1, "SUM.version           [%d]\n", sum_entry.version);
	DBG(1, "SUM.ofs_in_node       [%d]\n", sum_entry.ofs_in_node);
	DBG(1, "NAT.blkaddr           [0x%x]\n", ni.blk_addr);
	DBG(1, "NAT.ino               [0x%x]\n", ni.ino);

	node_blk = calloc(BLOCK_SZ, 1);

read_node_blk:
	dev_read_block(node_blk, blk_addr);

	ino = le32_to_cpu(node_blk->footer.ino);
	nid = le32_to_cpu(node_blk->footer.nid);

	if (ino == nid) {
		print_node_info(node_blk);
	} else {
		ret = get_node_info(sbi, ino, &ni);
		goto read_node_blk;
	}

	free(node_blk);
	return ino;
}
Beispiel #10
0
/*
 * speedmap()
 *    is used to print node information (speed map, node number, GUID, etc.)
 *    about the 1394 devices currently attached to the 1394 bus.
 */
static int
speedmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	s1394_hal_t	hal;
	int		ret;

	if (flags & DCMD_ADDRSPEC) {
		if (mdb_vread(&hal, sizeof (s1394_hal_t), addr) == -1) {
			mdb_warn("failed to read the HAL structure");
			return (DCMD_ERR);
		}

		ret = print_node_info(&hal);
		if (ret == DCMD_ERR)
		    return (DCMD_ERR);
	} else {
		(void) mdb_walk_dcmd("speedmap", "speedmap", argc, argv);
	}

	return (DCMD_OK);
}
Beispiel #11
0
/**
 * Displays all connected nodes
 */
enum shell_reply
shell_exec_nodes(struct gnutella_shell *sh, int argc, const char *argv[])
{
	const GSList *sl;

	shell_check(sh);
	g_assert(argv);
	g_assert(argc > 0);

	shell_set_msg(sh, "");

	shell_write(sh,
	  "100~ \n"
	  "Node                  Port  Flags       CC Since  Uptime User-Agent\n");

	for (sl = node_all_nodes(); sl; sl = g_slist_next(sl)) {
		const struct gnutella_node *n = sl->data;
		print_node_info(sh, n);
	}
	shell_write(sh, ".\n");	/* Terminate message body */

	return REPLY_READY;
}
Beispiel #12
0
/**
 * Displays all connected nodes
 */
enum shell_reply
shell_exec_nodes(struct gnutella_shell *sh, int argc, const char *argv[])
{
	const pslist_t *sl;

	shell_check(sh);
	g_assert(argv);
	g_assert(argc > 0);

	shell_set_msg(sh, "");

	shell_write(sh,
	  "100~ \n"
	  "Node                  Flags       CC Since  Uptime User-Agent\n");

	PSLIST_FOREACH(node_all_nodes(), sl) {
		const gnutella_node_t *n = sl->data;
		print_node_info(sh, n);
	}
	shell_write(sh, ".\n");	/* Terminate message body */

	return REPLY_READY;
}
Beispiel #13
0
int fsck_chk_inode_blk(struct f2fs_sb_info *sbi,
		u32 nid,
		enum FILE_TYPE ftype,
		struct f2fs_node *node_blk,
		u32 *blk_cnt,
		struct node_info *ni)
{
	struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
	u32 child_cnt = 0, child_files = 0;
	enum NODE_TYPE ntype;
	u32 i_links = le32_to_cpu(node_blk->i.i_links);
	u64 i_blocks = le64_to_cpu(node_blk->i.i_blocks);
	int idx = 0;
	int ret = 0;

	ASSERT(node_blk->footer.nid == node_blk->footer.ino);
	ASSERT(le32_to_cpu(node_blk->footer.nid) == nid);

	if (f2fs_test_bit(BLKOFF_FROM_MAIN(sbi, ni->blk_addr), fsck->main_area_bitmap) == 0x0)
		fsck->chk.valid_inode_cnt++;

	/* Orphan node. i_links should be 0 */
	if (ftype == F2FS_FT_ORPHAN) {
		ASSERT(i_links == 0);
	} else {
		ASSERT(i_links > 0);
	}

	if (ftype == F2FS_FT_DIR) {

		/* not included '.' & '..' */
		if (f2fs_test_bit(BLKOFF_FROM_MAIN(sbi, ni->blk_addr), fsck->main_area_bitmap) != 0) {
			DBG(0, "Duplicated inode blk. ino[0x%x][0x%x]\n", nid, ni->blk_addr);
			ASSERT(0);
		}
		f2fs_set_bit(BLKOFF_FROM_MAIN(sbi, ni->blk_addr), fsck->main_area_bitmap);

	} else {

		if (f2fs_test_bit(BLKOFF_FROM_MAIN(sbi, ni->blk_addr), fsck->main_area_bitmap) == 0x0) {
			f2fs_set_bit(BLKOFF_FROM_MAIN(sbi, ni->blk_addr), fsck->main_area_bitmap);
			if (i_links > 1) {
				/* First time. Create new hard link node */
				add_into_hard_link_list(sbi, nid, i_links);
				fsck->chk.multi_hard_link_files++;
			}
		} else {
			if (i_links <= 1) {
				DBG(0, "Error. Node ID [0x%x]."
						" There are one more hard links."
						" But i_links is [0x%x]\n",
						nid, i_links);
				ASSERT(0);
			}

			DBG(3, "ino[0x%x] has hard links [0x%x]\n", nid, i_links);
			ret = find_and_dec_hard_link_list(sbi, nid);
			ASSERT(ret >= 0);

			/* No need to go deep into the node */
			goto out;
		}
	}

	fsck_chk_xattr_blk(sbi, nid, le32_to_cpu(node_blk->i.i_xattr_nid), blk_cnt);

	if (ftype == F2FS_FT_CHRDEV || ftype == F2FS_FT_BLKDEV ||
			ftype == F2FS_FT_FIFO || ftype == F2FS_FT_SOCK)
		goto check;
	if((node_blk->i.i_inline & F2FS_INLINE_DATA)){
		DBG(3, "ino[0x%x] has inline data!\n", nid);
		goto check;
	}

	/* check data blocks in inode */
	for (idx = 0; idx < ADDRS_PER_INODE(&node_blk->i); idx++) {
		if (le32_to_cpu(node_blk->i.i_addr[idx]) != 0) {
			*blk_cnt = *blk_cnt + 1;
			ret = fsck_chk_data_blk(sbi,
					&node_blk->i,
					le32_to_cpu(node_blk->i.i_addr[idx]),
					&child_cnt,
					&child_files,
					(i_blocks == *blk_cnt),
					ftype,
					nid,
					idx,
					ni->version);
			ASSERT(ret >= 0);
		}
	}

	/* check node blocks in inode */
	for (idx = 0; idx < 5; idx++) {
		if (idx == 0 || idx == 1)
			ntype = TYPE_DIRECT_NODE;
		else if (idx == 2 || idx == 3)
			ntype = TYPE_INDIRECT_NODE;
		else if (idx == 4)
			ntype = TYPE_DOUBLE_INDIRECT_NODE;
		else
			ASSERT(0);

		if (le32_to_cpu(node_blk->i.i_nid[idx]) != 0) {
			*blk_cnt = *blk_cnt + 1;
			ret = fsck_chk_node_blk(sbi,
					&node_blk->i,
					le32_to_cpu(node_blk->i.i_nid[idx]),
					ftype,
					ntype,
					blk_cnt);
			ASSERT(ret >= 0);
		}
	}
check:
	if (ftype == F2FS_FT_DIR)
		DBG(1, "Directory Inode: ino: %x name: %s depth: %d child files: %d\n\n",
				le32_to_cpu(node_blk->footer.ino), node_blk->i.i_name,
				le32_to_cpu(node_blk->i.i_current_depth), child_files);
	if (ftype == F2FS_FT_ORPHAN)
		DBG(1, "Orphan Inode: ino: %x name: %s i_blocks: %lu\n\n",
				le32_to_cpu(node_blk->footer.ino), node_blk->i.i_name,
				i_blocks);
	if ((ftype == F2FS_FT_DIR && i_links != child_cnt) ||
			(i_blocks != *blk_cnt)) {
		print_node_info(node_blk);
		DBG(1, "blk   cnt [0x%x]\n", *blk_cnt);
		DBG(1, "child cnt [0x%x]\n", child_cnt);
	}

	ASSERT(i_blocks == *blk_cnt);
	if (ftype == F2FS_FT_DIR)
		ASSERT(i_links == child_cnt);
out:
	return 0;
}
Beispiel #14
0
static int
dump_art_node_callback(void *data,
	const unsigned char *key, uint32_t key_len,
	const unsigned char *val, uint32_t val_len)
{
	cb_data *cbd;
	const art_node *an;
	TOID(art_node4) an4;
	TOID(art_node16) an16;
	TOID(art_node48) an48;
	TOID(art_node256) an256;
	TOID(art_leaf) al;
	TOID(art_node_u) child;
	TOID(var_string) oid_key;
	TOID(var_string) oid_value;

	if (data != NULL) {
		cbd = (cb_data *)data;
		switch (D_RO(cbd->node)->art_node_type) {
		case NODE4:
			an4 = D_RO(cbd->node)->u.an4;
			an = &(D_RO(an4)->n);
			child = D_RO(an4)->children[cbd->child_idx];
			if (!TOID_IS_NULL(child)) {
				print_node_info("node4",
				    cbd->node.oid.off, an);
				printf("N%lx -> N%lx [label=\"%c\"];\n",
				    cbd->node.oid.off,
				    child.oid.off,
				    D_RO(an4)->keys[cbd->child_idx]);
			}
			break;
		case NODE16:
			an16 = D_RO(cbd->node)->u.an16;
			an = &(D_RO(an16)->n);
			child = D_RO(an16)->children[cbd->child_idx];
			if (!TOID_IS_NULL(child)) {
				print_node_info("node16",
				    cbd->node.oid.off, an);
				printf("N%lx -> N%lx [label=\"%c\"];\n",
				    cbd->node.oid.off,
				    child.oid.off,
				    D_RO(an16)->keys[cbd->child_idx]);
			}
			break;
		case NODE48:
			an48 = D_RO(cbd->node)->u.an48;
			an = &(D_RO(an48)->n);
			child = D_RO(an48)->children[cbd->child_idx];
			if (!TOID_IS_NULL(child)) {
				print_node_info("node48",
				    cbd->node.oid.off, an);
				printf("N%lx -> N%lx [label=\"%c\"];\n",
				    cbd->node.oid.off,
				    child.oid.off,
				    D_RO(an48)->keys[cbd->child_idx]);
			}
			break;
		case NODE256:
			an256 = D_RO(cbd->node)->u.an256;
			an = &(D_RO(an256)->n);
			child = D_RO(an256)->children[cbd->child_idx];
			if (!TOID_IS_NULL(child)) {
				print_node_info("node256",
				    cbd->node.oid.off, an);
				printf("N%lx -> N%lx [label=\"0x%x\"];\n",
				    cbd->node.oid.off,
				    child.oid.off,
				    (char)((cbd->child_idx) & 0xff));
			}
			break;
		case art_leaf_t:
			al = D_RO(cbd->node)->u.al;
			oid_key = D_RO(al)->key;
			oid_value = D_RO(al)->value;
			printf("N%lx [shape=box,"
				"label=\"leaf at\\n0x%lx\"];\n",
			    cbd->node.oid.off, cbd->node.oid.off);
			printf("N%lx [shape=box,"
				"label=\"key at 0x%lx: %s\"];\n",
			    oid_key.oid.off, oid_key.oid.off,
			    D_RO(oid_key)->s);
			printf("N%lx [shape=box,"
				"label=\"value at 0x%lx: %s\"];\n",
			    oid_value.oid.off, oid_value.oid.off,
			    D_RO(oid_value)->s);
			printf("N%lx -> N%lx;\n",
			    cbd->node.oid.off, oid_key.oid.off);
			printf("N%lx -> N%lx;\n",
			    cbd->node.oid.off, oid_value.oid.off);
			break;
		default:
			break;
		}
	} else {
		printf("leaf: key len %d = [%s], value len %d = [%s]\n",
		    key_len, key, val_len, val);
	}
	return 0;
}