@@ -55,6 +55,7 @@
#include "common/parse-utils.h"
#include "common/filesystem-utils.h"
#include "common/format-output.h"
+#include "common/btrfs-info.h"
#include "cmds/commands.h"
#include "cmds/filesystem-usage.h"
@@ -1503,6 +1504,48 @@ static int cmd_filesystem_label(const struct cmd_struct *cmd,
}
static DEFINE_SIMPLE_COMMAND(filesystem_label, "label");
+static const char * const cmd_filesystem_info_usage[] = {
+ "btrfs filesystem info [UUID=<uuid>|UUID_SUB=<subuuid>|PARTUUID=<partuuid>|LABEL=<label>|<device>|<mount_point>] ...",
+ "Show the information of a btrfs filesystem.",
+ NULL
+};
+
+static int cmd_filesystem_info(const struct cmd_struct *cmd,
+ int argc, char **argv)
+{
+ clean_args_no_options(cmd, argc, argv);
+
+ if (argc - optind == 0) {
+ const struct btrfs_info *bi;
+ int r = btrfs_info_get(&bi);
+ if (r < 0) {
+ error("Cannot get info: %d - %s\n", -r, strerror(-r));
+ return 2;
+ }
+ btrfs_info_dump(bi, stdout);
+ } else {
+ for (int i = 1 ; i < argc ; i++) {
+ printf("Target: %s\n", argv[i]);
+
+ const struct btrfs_info *bi;
+ int r = btrfs_info_find(argv[i], &bi);
+ if (r < 0) {
+ error("Cannot get info for '%s': %d - %s\n",
+ argv[i], -r, strerror(-r));
+ return 2;
+ }
+
+ btrfs_info_dump_single_entry(bi, stdout);
+
+ if (i < argc - 1)
+ printf("\n");
+ }
+ }
+
+ return 0;
+}
+static DEFINE_SIMPLE_COMMAND(filesystem_info, "info");
+
static const char * const cmd_filesystem_balance_usage[] = {
"btrfs filesystem balance [args...] (alias of \"btrfs balance\")",
"Please see \"btrfs balance --help\" for more information.",
@@ -1707,6 +1750,7 @@ static const struct cmd_group filesystem_cmd_group = {
&cmd_struct_filesystem_balance,
&cmd_struct_filesystem_resize,
&cmd_struct_filesystem_label,
+ &cmd_struct_filesystem_info,
&cmd_struct_filesystem_usage,
&cmd_struct_filesystem_mkswapfile,
NULL