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.
21 #include <sys/ioctl.h>
22 #include <sys/mount.h>
28 #include <sys/types.h>
33 #include <uuid/uuid.h>
34 #include "kerncompat.h"
36 #include "transaction.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)
54 static void print_one_uuid(struct btrfs_fs_devices
*fs_devices
)
57 struct list_head
*cur
;
58 struct btrfs_device
*device
;
59 char *super_bytes_used
;
63 uuid_unparse(fs_devices
->fsid
, uuidbuf
);
64 device
= list_entry(fs_devices
->devices
.next
, struct btrfs_device
,
66 if (device
->label
&& device
->label
[0])
67 printf("Label: %s ", device
->label
);
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
) {
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
);
92 if (devs_found
< total
) {
93 printf("\t*** Some devices missing\n");
98 static void print_usage(void)
100 fprintf(stderr
, "usage: btrfs-show [search label or device]\n");
104 static struct option long_options
[] = {
105 /* { "byte-count", 1, NULL, 'b' }, */
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
;
116 int option_index
= 0;
120 c
= getopt_long(ac
, av
, "", long_options
,
134 ret
= btrfs_scan_one_dir("/dev", 0);
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
,
142 if (search
&& uuid_search(fs_devices
, search
) == 0)
144 print_one_uuid(fs_devices
);