source: mainline/uspace/app/ext2info/ext2info.c@ 3949e8a0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3949e8a0 was f6fa2c2, checked in by Martin Sucha <sucha14@…>, 15 years ago

Added read support and code in ext2info for more superblock entries

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Sucha
3 * Copyright (c) 2010 Jiri Svoboda
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup fs
31 * @{
32 */
33
34/**
35 * @file ext2info.c
36 * @brief Tool for displaying information about ext2 filesystem
37 *
38 */
39
40#include <stdio.h>
41#include <stdlib.h>
42#include <libblock.h>
43#include <mem.h>
44#include <devmap.h>
45#include <byteorder.h>
46#include <sys/types.h>
47#include <sys/typefmt.h>
48#include <inttypes.h>
49#include <errno.h>
50#include <libext2.h>
51
52#define NAME "ext2info"
53
54static void syntax_print(void);
55static void print_superblock(ext2_superblock_t *sb);
56
57int main(int argc, char **argv)
58{
59
60 int rc;
61 char *dev_path;
62 devmap_handle_t handle;
63 ext2_filesystem_t filesystem;
64
65 if (argc < 2) {
66 printf(NAME ": Error, argument missing.\n");
67 syntax_print();
68 return 1;
69 }
70
71 --argc; ++argv;
72
73 if (argc != 1) {
74 printf(NAME ": Error, unexpected argument.\n");
75 syntax_print();
76 return 1;
77 }
78
79 dev_path = *argv;
80
81 rc = devmap_device_get_handle(dev_path, &handle, 0);
82 if (rc != EOK) {
83 printf(NAME ": Error resolving device `%s'.\n", dev_path);
84 return 2;
85 }
86
87 rc = ext2_filesystem_init(&filesystem, handle);
88 if (rc != EOK) {
89 printf(NAME ": Error initializing libext2.\n");
90 return 3;
91 }
92
93 print_superblock(filesystem.superblock);
94
95 ext2_filesystem_fini(&filesystem);
96
97 return 0;
98}
99
100
101static void syntax_print(void)
102{
103 printf("syntax: ext2info <device_name>\n");
104}
105
106static void print_superblock(ext2_superblock_t *superblock)
107{
108 uint16_t magic;
109 uint32_t first_block;
110 uint32_t block_size;
111 uint32_t fragment_size;
112 uint32_t blocks_per_group;
113 uint32_t fragments_per_group;
114 uint32_t rev_major;
115 uint16_t rev_minor;
116 uint16_t state;
117 uint32_t first_inode;
118 uint16_t inode_size;
119 uint32_t total_blocks;
120 uint32_t reserved_blocks;
121 uint32_t free_blocks;
122 uint32_t total_inodes;
123 uint32_t free_inodes;
124 uint32_t os;
125
126 int pos;
127 unsigned char c;
128
129 magic = ext2_superblock_get_magic(superblock);
130 first_block = ext2_superblock_get_first_block(superblock);
131 block_size = ext2_superblock_get_block_size(superblock);
132 fragment_size = ext2_superblock_get_fragment_size(superblock);
133 blocks_per_group = ext2_superblock_get_blocks_per_group(superblock);
134 fragments_per_group = ext2_superblock_get_fragments_per_group(superblock);
135 rev_major = ext2_superblock_get_rev_major(superblock);
136 rev_minor = ext2_superblock_get_rev_minor(superblock);
137 state = ext2_superblock_get_state(superblock);
138 first_inode = ext2_superblock_get_first_inode(superblock);
139 inode_size = ext2_superblock_get_inode_size(superblock);
140 total_blocks = ext2_superblock_get_total_block_count(superblock);
141 reserved_blocks = ext2_superblock_get_reserved_block_count(superblock);
142 free_blocks = ext2_superblock_get_free_block_count(superblock);
143 total_inodes = ext2_superblock_get_total_inode_count(superblock);
144 free_inodes = ext2_superblock_get_free_inode_count(superblock);
145 os = ext2_superblock_get_os(superblock);
146
147 printf("Superblock:\n");
148
149 if (magic == EXT2_SUPERBLOCK_MAGIC) {
150 printf(" Magic value: %X (correct)\n", magic);
151 }
152 else {
153 printf(" Magic value: %X (incorrect)\n", magic);
154 }
155
156 printf(" Revision: %u.%hu\n", rev_major, rev_minor);
157 printf(" State: %hu\n", state);
158 printf(" Creator OS: %u\n", os);
159 printf(" First block: %u\n", first_block);
160 printf(" Block size: %u bytes (%u KiB)\n", block_size, block_size/1024);
161 printf(" Blocks per group: %u\n", blocks_per_group);
162 printf(" Total blocks: %u\n", total_blocks);
163 printf(" Reserved blocks: %u\n", reserved_blocks);
164 printf(" Free blocks: %u\n", free_blocks);
165 printf(" Fragment size: %u bytes (%u KiB)\n", fragment_size,
166 fragment_size/1024);
167 printf(" Fragments per group: %u\n", fragments_per_group);
168 printf(" First inode: %u\n", first_inode);
169 printf(" Inode size: %hu bytes\n", inode_size);
170 printf(" Total inodes: %u\n", total_inodes);
171 printf(" Free inodes: %u\n", free_inodes);
172
173
174 if (rev_major == 1) {
175 printf(" UUID: ");
176 for (pos = 0; pos < 16; pos++) {
177 printf("%02x", superblock->uuid[pos]);
178 }
179 printf("\n");
180
181 printf(" Volume label: ");
182 for (pos = 0; pos < 16; pos++) {
183 c = superblock->volume_name[pos];
184 if (c >= 32 && c < 128) {
185 putchar(c);
186 }
187 else {
188 putchar(' ');
189 }
190 }
191 printf("\n");
192 }
193
194}
195
196/**
197 * @}
198 */
Note: See TracBrowser for help on using the repository browser.