Update the Ext3 converter
[btrfs-progs-unstable.git] / btrfs-show.c
blob5c370f1e176f69795eda450fedde0763b046a97d
1 /*
2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
19 #define _GNU_SOURCE
20 #ifndef __CHECKER__
21 #include <sys/ioctl.h>
22 #include <sys/mount.h>
23 #include "ioctl.h"
24 #endif
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <getopt.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <unistd.h>
32 #include <dirent.h>
33 #include <uuid/uuid.h>
34 #include "kerncompat.h"
35 #include "ctree.h"
36 #include "transaction.h"
37 #include "utils.h"
38 #include "volumes.h"
40 static int uuid_search(struct btrfs_fs_devices *fs_devices, char *search)
42 struct list_head *cur;
43 struct btrfs_device *device;
45 list_for_each(cur, &fs_devices->devices) {
46 device = list_entry(cur, struct btrfs_device, dev_list);
47 if ((device->label && strcmp(device->label, search) == 0) ||
48 strcmp(device->name, search) == 0)
49 return 1;
51 return 0;
54 static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
56 char uuidbuf[37];
57 struct list_head *cur;
58 struct btrfs_device *device;
59 char *super_bytes_used;
60 u64 devs_found = 0;
61 u64 total;
63 uuid_unparse(fs_devices->fsid, uuidbuf);
64 device = list_entry(fs_devices->devices.next, struct btrfs_device,
65 dev_list);
66 if (device->label && device->label[0])
67 printf("Label: %s ", device->label);
68 else
69 printf("Label: none ");
71 super_bytes_used = pretty_sizes(device->super_bytes_used);
73 total = device->total_devs;
74 printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n", uuidbuf,
75 (unsigned long long)total, super_bytes_used);
77 free(super_bytes_used);
79 list_for_each(cur, &fs_devices->devices) {
80 char *total_bytes;
81 char *bytes_used;
82 device = list_entry(cur, struct btrfs_device, dev_list);
83 total_bytes = pretty_sizes(device->total_bytes);
84 bytes_used = pretty_sizes(device->bytes_used);
85 printf("\tdevid %4llu size %s used %s path %s\n",
86 (unsigned long long)device->devid,
87 total_bytes, bytes_used, device->name);
88 free(total_bytes);
89 free(bytes_used);
90 devs_found++;
92 if (devs_found < total) {
93 printf("\t*** Some devices missing\n");
95 printf("\n");
98 static void print_usage(void)
100 fprintf(stderr, "usage: btrfs-show [search label or device]\n");
101 exit(1);
104 static struct option long_options[] = {
105 /* { "byte-count", 1, NULL, 'b' }, */
106 { 0, 0, 0, 0}
109 int main(int ac, char **av)
111 struct list_head *all_uuids;
112 struct btrfs_fs_devices *fs_devices;
113 struct list_head *cur_uuid;
114 char *search = NULL;
115 int ret;
116 int option_index = 0;
118 while(1) {
119 int c;
120 c = getopt_long(ac, av, "", long_options,
121 &option_index);
122 if (c < 0)
123 break;
124 switch(c) {
125 default:
126 print_usage();
129 ac = ac - optind;
130 if (ac != 0) {
131 search = av[optind];
134 ret = btrfs_scan_one_dir("/dev", 0);
135 if (ret)
136 fprintf(stderr, "error %d while scanning\n", ret);
138 all_uuids = btrfs_scanned_uuids();
139 list_for_each(cur_uuid, all_uuids) {
140 fs_devices = list_entry(cur_uuid, struct btrfs_fs_devices,
141 list);
142 if (search && uuid_search(fs_devices, search) == 0)
143 continue;
144 print_one_uuid(fs_devices);
146 return 0;