xref: /dflybsd-src/sbin/hammer2/print_inode.c (revision d0a74117cc5baed46a1514b9ec89c0b7943c91f2)
1 /*
2  * Copyright (c) 2013-2019 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@dragonflybsd.org>
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 "hammer2.h"
36 
37 static void
38 hexdump_inode(const void *data, size_t len)
39 {
40 	const unsigned char *p = data;
41 	size_t i;
42 
43 	if (VerboseOpt <= 0)
44 		return;
45 
46 	for (i = 0; i < len; i++) {
47 		printf("%02X", *p);
48 		if (i != len - 1)
49 			printf(" ");
50 		p++;
51 	}
52 	printf("\n");
53 }
54 
55 void
56 print_inode(const char *path)
57 {
58 	hammer2_ioc_inode_t inode;
59 	hammer2_inode_data_t *ipdata;
60 	hammer2_inode_meta_t *meta;
61 	char *uid_str, *gid_str, *pfs_clid_str, *pfs_fsid_str;
62 	int i, fd, status;
63 
64 	fd = hammer2_ioctl_handle(path);
65 	if (fd == -1)
66 		return;
67 
68 	if (ioctl(fd, HAMMER2IOC_INODE_GET, &inode) == -1) {
69 		printf("ioctl(HAMMER2IOC_INODE_GET) failed\n");
70 		return;
71 	}
72 	ipdata = &inode.ip_data;
73 	meta = &ipdata->meta;
74 
75 	uuid_to_string(&meta->uid, &uid_str, &status);
76 	uuid_to_string(&meta->gid, &gid_str, &status);
77 	uuid_to_string(&meta->pfs_clid, &pfs_clid_str, &status);
78 	uuid_to_string(&meta->pfs_fsid, &pfs_fsid_str, &status);
79 
80 	hexdump_inode(meta, sizeof(*meta));
81 	printf("version = %u\n", meta->version);
82 	printf("pfs_subtype = %u\n", meta->pfs_subtype);
83 	printf("uflags = 0x%x\n", (unsigned int)meta->uflags);
84 	printf("rmajor = %u\n", meta->rmajor);
85 	printf("rminor = %u\n", meta->rminor);
86 	printf("ctime = 0x%jx\n", (uintmax_t)meta->ctime);
87 	printf("mtime = 0x%jx\n", (uintmax_t)meta->mtime);
88 	printf("atime = 0x%jx\n", (uintmax_t)meta->atime);
89 	printf("btime = 0x%jx\n", (uintmax_t)meta->btime);
90 	printf("uid = %s\n", uid_str);
91 	printf("gid = %s\n", gid_str);
92 	printf("type = %u\n", meta->type);
93 	printf("op_flags = 0x%x\n", meta->op_flags);
94 	printf("cap_flags = 0x%x\n", meta->cap_flags);
95 	printf("mode = 0%o\n", meta->mode);
96 	printf("inum = 0x%jx\n", (uintmax_t)meta->inum);
97 	printf("size = %ju\n", (uintmax_t)meta->size);
98 	printf("nlinks = %ju\n", (uintmax_t)meta->nlinks);
99 	printf("iparent = %ju\n", (uintmax_t)meta->iparent);
100 	printf("name_key = 0x%jx\n", (uintmax_t)meta->name_key);
101 	printf("name_len = %u\n", meta->name_len);
102 	printf("ncopies = %u\n", meta->ncopies);
103 	printf("comp_algo = %u\n", meta->comp_algo);
104 	printf("target_type = %u\n", meta->target_type);
105 	printf("check_algo = %u\n", meta->check_algo);
106 	printf("pfs_nmasters = %u\n", meta->pfs_nmasters);
107 	printf("pfs_type = %u\n", meta->pfs_type);
108 	printf("pfs_inum = 0x%jx\n", (uintmax_t)meta->pfs_inum);
109 	printf("pfs_clid = %s\n", pfs_clid_str);
110 	printf("pfs_fsid = %s\n", pfs_fsid_str);
111 	printf("data_quota = 0x%jx\n", (uintmax_t)meta->data_quota);
112 	printf("inode_quota = 0x%jx\n", (uintmax_t)meta->inode_quota);
113 	printf("pfs_lsnap_tid = 0x%jx\n", (uintmax_t)meta->pfs_lsnap_tid);
114 	printf("decrypt_check = 0x%jx\n", (uintmax_t)meta->decrypt_check);
115 	/* XXX HAMMER2IOC_INODE_GET only supports meta part */
116 	return;
117 	printf("\n");
118 
119 	hexdump_inode(ipdata->filename, sizeof(ipdata->filename));
120 	printf("filename = \"%s\"\n", ipdata->filename);
121 	printf("\n");
122 
123 	if (!(meta->op_flags & HAMMER2_OPFLAG_DIRECTDATA)) {
124 		for (i = 0; i < HAMMER2_SET_COUNT; ++i) {
125 			hammer2_blockref_t *bref =
126 			    &ipdata->u.blockset.blockref[i];
127 			hexdump_inode(bref, sizeof(*bref));
128 
129 			if (bref->type == HAMMER2_BREF_TYPE_EMPTY) {
130 				printf("blockref[%d] is empty\n", i);
131 				continue;
132 			}
133 			printf("blockref[%d] type = %u\n", i, bref->type);
134 			printf("blockref[%d] methods = %u\n", i, bref->methods);
135 			printf("blockref[%d] copyid = %u\n", i, bref->copyid);
136 			printf("blockref[%d] keybits = %u\n", i, bref->keybits);
137 			printf("blockref[%d] vradix = %u\n", i, bref->vradix);
138 			printf("blockref[%d] flags = 0x%x\n", i, bref->flags);
139 			printf("blockref[%d] leaf_count = %u\n", i,
140 			    bref->leaf_count);
141 			printf("blockref[%d] key = 0x%jx\n", i,
142 			    (uintmax_t)bref->key);
143 			printf("blockref[%d] mirror_tid = 0x%jx\n", i,
144 			    (uintmax_t)bref->mirror_tid);
145 			printf("blockref[%d] modify_tid = 0x%jx\n", i,
146 			    (uintmax_t)bref->modify_tid);
147 			printf("blockref[%d] data_off = 0x%jx\n", i,
148 			    (uintmax_t)bref->data_off);
149 			printf("blockref[%d] update_tid = 0x%jx\n", i,
150 			    (uintmax_t)bref->update_tid);
151 			if (i != HAMMER2_SET_COUNT - 1)
152 				printf("\n");
153 		}
154 	} else {
155 		hexdump_inode(ipdata->u.data, sizeof(ipdata->u.data));
156 		printf("embedded data\n");
157 	}
158 }
159