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"
41 static int uuid_search(struct btrfs_fs_devices
*fs_devices
, char *search
)
43 struct list_head
*cur
;
44 struct btrfs_device
*device
;
46 list_for_each(cur
, &fs_devices
->devices
) {
47 device
= list_entry(cur
, struct btrfs_device
, dev_list
);
48 if ((device
->label
&& strcmp(device
->label
, search
) == 0) ||
49 strcmp(device
->name
, search
) == 0)
55 static void print_one_uuid(struct btrfs_fs_devices
*fs_devices
)
58 struct list_head
*cur
;
59 struct btrfs_device
*device
;
60 char *super_bytes_used
;
64 uuid_unparse(fs_devices
->fsid
, uuidbuf
);
65 device
= list_entry(fs_devices
->devices
.next
, struct btrfs_device
,
67 if (device
->label
&& device
->label
[0])
68 printf("Label: %s ", device
->label
);
70 printf("Label: none ");
72 super_bytes_used
= pretty_sizes(device
->super_bytes_used
);
74 total
= device
->total_devs
;
75 printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n", uuidbuf
,
76 (unsigned long long)total
, super_bytes_used
);
78 free(super_bytes_used
);
80 list_for_each(cur
, &fs_devices
->devices
) {
83 device
= list_entry(cur
, struct btrfs_device
, dev_list
);
84 total_bytes
= pretty_sizes(device
->total_bytes
);
85 bytes_used
= pretty_sizes(device
->bytes_used
);
86 printf("\tdevid %4llu size %s used %s path %s\n",
87 (unsigned long long)device
->devid
,
88 total_bytes
, bytes_used
, device
->name
);
93 if (devs_found
< total
) {
94 printf("\t*** Some devices missing\n");
99 static void print_usage(void)
101 fprintf(stderr
, "usage: btrfs-show [search label or device]\n");
102 fprintf(stderr
, "%s\n", BTRFS_BUILD_VERSION
);
106 static struct option long_options
[] = {
107 /* { "byte-count", 1, NULL, 'b' }, */
111 int main(int ac
, char **av
)
113 struct list_head
*all_uuids
;
114 struct btrfs_fs_devices
*fs_devices
;
115 struct list_head
*cur_uuid
;
118 int option_index
= 0;
122 c
= getopt_long(ac
, av
, "", long_options
,
136 ret
= btrfs_scan_one_dir("/dev", 0);
138 fprintf(stderr
, "error %d while scanning\n", ret
);
140 all_uuids
= btrfs_scanned_uuids();
141 list_for_each(cur_uuid
, all_uuids
) {
142 fs_devices
= list_entry(cur_uuid
, struct btrfs_fs_devices
,
144 if (search
&& uuid_search(fs_devices
, search
) == 0)
146 print_one_uuid(fs_devices
);
148 printf("%s\n", BTRFS_BUILD_VERSION
);