xref: /dragonfly/sbin/hammer2/print_inode.c (revision 335b9e93)
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 *str = NULL;
62 	int i, fd;
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 	hexdump_inode(meta, sizeof(*meta));
76 	printf("version = %u\n", meta->version);
77 	printf("pfs_subtype = %u\n", meta->pfs_subtype);
78 	printf("uflags = 0x%x\n", (unsigned int)meta->uflags);
79 	printf("rmajor = %u\n", meta->rmajor);
80 	printf("rminor = %u\n", meta->rminor);
81 	printf("ctime = %s\n", hammer2_time64_to_str(meta->ctime, &str));
82 	printf("mtime = %s\n", hammer2_time64_to_str(meta->mtime, &str));
83 	printf("atime = %s\n", hammer2_time64_to_str(meta->atime, &str));
84 	printf("btime = %s\n", hammer2_time64_to_str(meta->btime, &str));
85 	printf("uid = %s\n", hammer2_uuid_to_str(&meta->uid, &str));
86 	printf("gid = %s\n", hammer2_uuid_to_str(&meta->gid, &str));
87 	printf("type = %u\n", meta->type);
88 	printf("op_flags = 0x%x\n", meta->op_flags);
89 	printf("cap_flags = 0x%x\n", meta->cap_flags);
90 	printf("mode = 0%o\n", meta->mode);
91 	printf("inum = 0x%jx\n", (uintmax_t)meta->inum);
92 	printf("size = %ju\n", (uintmax_t)meta->size);
93 	printf("nlinks = %ju\n", (uintmax_t)meta->nlinks);
94 	printf("iparent = %ju\n", (uintmax_t)meta->iparent);
95 	printf("name_key = 0x%jx\n", (uintmax_t)meta->name_key);
96 	printf("name_len = %u\n", meta->name_len);
97 	printf("ncopies = %u\n", meta->ncopies);
98 	printf("comp_algo = %u\n", meta->comp_algo);
99 	printf("target_type = %u\n", meta->target_type);
100 	printf("check_algo = %u\n", meta->check_algo);
101 	printf("pfs_nmasters = %u\n", meta->pfs_nmasters);
102 	printf("pfs_type = %u\n", meta->pfs_type);
103 	printf("pfs_inum = 0x%jx\n", (uintmax_t)meta->pfs_inum);
104 	printf("pfs_clid = %s\n",
105 	    hammer2_uuid_to_str(&meta->pfs_clid, &str));
106 	printf("pfs_fsid = %s\n",
107 	    hammer2_uuid_to_str(&meta->pfs_fsid, &str));
108 	printf("data_quota = 0x%jx\n", (uintmax_t)meta->data_quota);
109 	printf("inode_quota = 0x%jx\n", (uintmax_t)meta->inode_quota);
110 	printf("pfs_lsnap_tid = 0x%jx\n", (uintmax_t)meta->pfs_lsnap_tid);
111 	printf("decrypt_check = 0x%jx\n", (uintmax_t)meta->decrypt_check);
112 
113 	free(str);
114 	/* XXX HAMMER2IOC_INODE_GET only supports meta part */
115 	return;
116 	printf("\n");
117 
118 	hexdump_inode(ipdata->filename, sizeof(ipdata->filename));
119 	printf("filename = \"%s\"\n", ipdata->filename);
120 	printf("\n");
121 
122 	if (!(meta->op_flags & HAMMER2_OPFLAG_DIRECTDATA)) {
123 		for (i = 0; i < HAMMER2_SET_COUNT; ++i) {
124 			hammer2_blockref_t *bref =
125 			    &ipdata->u.blockset.blockref[i];
126 			hexdump_inode(bref, sizeof(*bref));
127 
128 			if (bref->type == HAMMER2_BREF_TYPE_EMPTY) {
129 				printf("blockref[%d] is empty\n", i);
130 				continue;
131 			}
132 			printf("blockref[%d] type = %u\n", i, bref->type);
133 			printf("blockref[%d] methods = %u\n", i, bref->methods);
134 			printf("blockref[%d] copyid = %u\n", i, bref->copyid);
135 			printf("blockref[%d] keybits = %u\n", i, bref->keybits);
136 			printf("blockref[%d] vradix = %u\n", i, bref->vradix);
137 			printf("blockref[%d] flags = 0x%x\n", i, bref->flags);
138 			printf("blockref[%d] leaf_count = %u\n", i,
139 			    bref->leaf_count);
140 			printf("blockref[%d] key = 0x%jx\n", i,
141 			    (uintmax_t)bref->key);
142 			printf("blockref[%d] mirror_tid = 0x%jx\n", i,
143 			    (uintmax_t)bref->mirror_tid);
144 			printf("blockref[%d] modify_tid = 0x%jx\n", i,
145 			    (uintmax_t)bref->modify_tid);
146 			printf("blockref[%d] data_off = 0x%jx\n", i,
147 			    (uintmax_t)bref->data_off);
148 			printf("blockref[%d] update_tid = 0x%jx\n", i,
149 			    (uintmax_t)bref->update_tid);
150 			if (i != HAMMER2_SET_COUNT - 1)
151 				printf("\n");
152 		}
153 	} else {
154 		hexdump_inode(ipdata->u.data, sizeof(ipdata->u.data));
155 		printf("embedded data\n");
156 	}
157 }
158