|
39 | 39 | #include "common/help.h" |
40 | 40 | #include "common/device-scan.h" |
41 | 41 | #include "common/string-utils.h" |
| 42 | +#include "common/parse-utils.h" |
42 | 43 | #include "cmds/commands.h" |
43 | 44 |
|
44 | 45 | static void print_extents(struct extent_buffer *eb) |
@@ -137,81 +138,6 @@ static void print_old_roots(struct btrfs_super_block *super) |
137 | 138 | } |
138 | 139 | } |
139 | 140 |
|
140 | | -/* |
141 | | - * Convert a tree name from various forms to the numerical id if possible |
142 | | - * Accepted forms: |
143 | | - * - case does not matter |
144 | | - * - same as the key name, BTRFS_ROOT_TREE_OBJECTID |
145 | | - * - dtto shortened, BTRFS_ROOT_TREE |
146 | | - * - dtto without prefix, ROOT_TREE |
147 | | - * - common name, ROOT, CHUNK, EXTENT, ... |
148 | | - * - dtto alias, DEVICE for DEV, CHECKSUM for CSUM |
149 | | - * |
150 | | - * Returns 0 if the tree id was not recognized. |
151 | | - */ |
152 | | -static u64 treeid_from_string(const char *str, const char **end) |
153 | | -{ |
154 | | - int match = 0; |
155 | | - int i; |
156 | | - u64 id; |
157 | | - static struct treename { |
158 | | - const char *name; |
159 | | - u64 id; |
160 | | - } tn[] = { |
161 | | - { "ROOT", BTRFS_ROOT_TREE_OBJECTID }, |
162 | | - { "EXTENT", BTRFS_EXTENT_TREE_OBJECTID }, |
163 | | - { "CHUNK", BTRFS_CHUNK_TREE_OBJECTID }, |
164 | | - { "DEVICE", BTRFS_DEV_TREE_OBJECTID }, |
165 | | - { "DEV", BTRFS_DEV_TREE_OBJECTID }, |
166 | | - { "FS", BTRFS_FS_TREE_OBJECTID }, |
167 | | - { "CSUM", BTRFS_CSUM_TREE_OBJECTID }, |
168 | | - { "CHECKSUM", BTRFS_CSUM_TREE_OBJECTID }, |
169 | | - { "QUOTA", BTRFS_QUOTA_TREE_OBJECTID }, |
170 | | - { "UUID", BTRFS_UUID_TREE_OBJECTID }, |
171 | | - { "FREE_SPACE", BTRFS_FREE_SPACE_TREE_OBJECTID }, |
172 | | - { "FREE-SPACE", BTRFS_FREE_SPACE_TREE_OBJECTID }, |
173 | | - { "TREE_LOG_FIXUP", BTRFS_TREE_LOG_FIXUP_OBJECTID }, |
174 | | - { "TREE-LOG-FIXUP", BTRFS_TREE_LOG_FIXUP_OBJECTID }, |
175 | | - { "TREE_LOG", BTRFS_TREE_LOG_OBJECTID }, |
176 | | - { "TREE-LOG", BTRFS_TREE_LOG_OBJECTID }, |
177 | | - { "TREE_RELOC", BTRFS_TREE_RELOC_OBJECTID }, |
178 | | - { "TREE-RELOC", BTRFS_TREE_RELOC_OBJECTID }, |
179 | | - { "DATA_RELOC", BTRFS_DATA_RELOC_TREE_OBJECTID }, |
180 | | - { "DATA-RELOC", BTRFS_DATA_RELOC_TREE_OBJECTID }, |
181 | | - { "BLOCK_GROUP", BTRFS_BLOCK_GROUP_TREE_OBJECTID }, |
182 | | - { "BLOCK-GROUP", BTRFS_BLOCK_GROUP_TREE_OBJECTID }, |
183 | | - { "RAID_STRIPE", BTRFS_RAID_STRIPE_TREE_OBJECTID }, |
184 | | - { "RAID-STRIPE", BTRFS_RAID_STRIPE_TREE_OBJECTID }, |
185 | | - }; |
186 | | - |
187 | | - if (strncasecmp("BTRFS_", str, strlen("BTRFS_")) == 0) |
188 | | - str += strlen("BTRFS_"); |
189 | | - |
190 | | - for (i = 0; i < ARRAY_SIZE(tn); i++) { |
191 | | - int len = strlen(tn[i].name); |
192 | | - |
193 | | - if (strncasecmp(tn[i].name, str, len) == 0) { |
194 | | - id = tn[i].id; |
195 | | - match = 1; |
196 | | - str += len; |
197 | | - break; |
198 | | - } |
199 | | - } |
200 | | - |
201 | | - if (!match) |
202 | | - return 0; |
203 | | - |
204 | | - if (strncasecmp("_TREE", str, strlen("_TREE")) == 0) |
205 | | - str += strlen("_TREE"); |
206 | | - |
207 | | - if (strncasecmp("_OBJECTID", str, strlen("_OBJECTID")) == 0) |
208 | | - str += strlen("_OBJECTID"); |
209 | | - |
210 | | - *end = str; |
211 | | - |
212 | | - return id; |
213 | | -} |
214 | | - |
215 | 141 | static const char * const cmd_inspect_dump_tree_usage[] = { |
216 | 142 | "btrfs inspect-internal dump-tree [options] <device> [<device> ..]", |
217 | 143 | "Dump tree structures from a given device", |
@@ -417,27 +343,9 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd, |
417 | 343 | if (ret < 0) |
418 | 344 | goto out; |
419 | 345 | break; |
420 | | - case 't': { |
421 | | - const char *end = NULL; |
422 | | - |
423 | | - if (string_is_numerical(optarg)) |
424 | | - tree_id = arg_strtou64(optarg); |
425 | | - else |
426 | | - tree_id = treeid_from_string(optarg, &end); |
427 | | - |
428 | | - if (!tree_id) { |
429 | | - error("unrecognized tree id: %s", |
430 | | - optarg); |
431 | | - exit(1); |
432 | | - } |
433 | | - |
434 | | - if (end && *end) { |
435 | | - error("unexpected tree id suffix of '%s': %s", |
436 | | - optarg, end); |
437 | | - exit(1); |
438 | | - } |
| 346 | + case 't': |
| 347 | + tree_id = parse_tree_id(optarg); |
439 | 348 | break; |
440 | | - } |
441 | 349 | case GETOPT_VAL_FOLLOW: |
442 | 350 | follow = BTRFS_PRINT_TREE_FOLLOW; |
443 | 351 | break; |
|
0 commit comments