xref: /dragonfly/sbin/hammer2/print_inode.c (revision 2b7dbe20)
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 && !((i + 1) % 16))
49 			printf("\n");
50 		else if (i != len - 1)
51 			printf(" ");
52 		p++;
53 	}
54 	printf("\n");
55 }
56 
57 void
58 print_inode(const char *path)
59 {
60 	hammer2_ioc_inode_t inode;
61 	hammer2_inode_data_t *ipdata;
62 	hammer2_inode_meta_t *meta;
63 	char *str = NULL;
64 	int fd;
65 
66 	fd = hammer2_ioctl_handle(path);
67 	if (fd == -1)
68 		return;
69 
70 	if (ioctl(fd, HAMMER2IOC_INODE_GET, &inode) == -1) {
71 		printf("ioctl(HAMMER2IOC_INODE_GET) failed\n");
72 		return;
73 	}
74 	ipdata = &inode.ip_data;
75 	meta = &ipdata->meta;
76 
77 	hexdump_inode(meta, sizeof(*meta));
78 
79 	printf("version = %u\n", meta->version);
80 	printf("pfs_subtype = %u (%s)\n", meta->pfs_subtype,
81 	    hammer2_pfssubtype_to_str(meta->pfs_subtype));
82 	printf("uflags = 0x%x\n", (unsigned int)meta->uflags);
83 	printf("rmajor = %u\n", meta->rmajor);
84 	printf("rminor = %u\n", meta->rminor);
85 	printf("ctime = %s\n", hammer2_time64_to_str(meta->ctime, &str));
86 	printf("mtime = %s\n", hammer2_time64_to_str(meta->mtime, &str));
87 	printf("atime = %s\n", hammer2_time64_to_str(meta->atime, &str));
88 	printf("btime = %s\n", hammer2_time64_to_str(meta->btime, &str));
89 	printf("uid = %s\n", hammer2_uuid_to_str(&meta->uid, &str));
90 	printf("gid = %s\n", hammer2_uuid_to_str(&meta->gid, &str));
91 	printf("type = %u (%s)\n", meta->type,
92 	    hammer2_iptype_to_str(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 = 0x%jx\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 (%s)\n", meta->pfs_type,
108 	    hammer2_pfstype_to_str(meta->pfs_type));
109 	printf("pfs_inum = 0x%jx\n", (uintmax_t)meta->pfs_inum);
110 	printf("pfs_clid = %s\n",
111 	    hammer2_uuid_to_str(&meta->pfs_clid, &str));
112 	printf("pfs_fsid = %s\n",
113 	    hammer2_uuid_to_str(&meta->pfs_fsid, &str));
114 	printf("data_quota = 0x%jx\n", (uintmax_t)meta->data_quota);
115 	printf("inode_quota = 0x%jx\n", (uintmax_t)meta->inode_quota);
116 	printf("pfs_lsnap_tid = 0x%jx\n", (uintmax_t)meta->pfs_lsnap_tid);
117 	printf("decrypt_check = 0x%jx\n", (uintmax_t)meta->decrypt_check);
118 
119 	free(str);
120 }
121