diff mbox series

[4/7] btrfs-progs: subvol: introduce rowspec definition for json output

Message ID 20230813094555.106052-5-christoph@c8h4.io (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: implement json output for subvolume subcommands | expand

Commit Message

Christoph Heiss Aug. 13, 2023, 9:44 a.m. UTC
Includes all fields that are needed by the various `btrfs subvolume`
subcommands.

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
---
 cmds/subvolume.c | 25 +++++++++++++++++++++++++
 cmds/subvolume.h | 19 +++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 cmds/subvolume.h
diff mbox series

Patch

diff --git a/cmds/subvolume.c b/cmds/subvolume.c
index 65cff24b..cb863ac7 100644
--- a/cmds/subvolume.c
+++ b/cmds/subvolume.c
@@ -41,9 +41,34 @@ 
 #include "common/open-utils.h"
 #include "common/string-utils.h"
 #include "common/units.h"
+#include "common/format-output.h"
 #include "cmds/commands.h"
 #include "cmds/qgroup.h"
 
+const struct rowspec btrfs_subvolume_rowspec[] = {
+	{ .key = "ID", .fmt = "%llu", .out_json = "id" },
+	{ .key = "name", .fmt = "%s", .out_json = "name" },
+	{ .key = "gen", .fmt = "%llu", .out_json = "gen" },
+	{ .key = "cgen", .fmt = "%llu", .out_json = "cgen" },
+	{ .key = "parent", .fmt = "%llu", .out_json = "parent" },
+	{ .key = "top level", .fmt = "%llu", .out_json = "top_level" },
+	{ .key = "otime", .fmt = "time-long", .out_json = "otime" },
+	{ .key = "parent_uuid", .fmt = "uuid", .out_json = "parent_uuid" },
+	{ .key = "received_uuid", .fmt = "uuid", .out_json = "received_uuid" },
+	{ .key = "uuid", .fmt = "uuid", .out_json = "uuid" },
+	{ .key = "path", .fmt = "%s", .out_json = "path" },
+	{ .key = "flag-list-item", .fmt = "%s" },
+	{ .key = "stransid", .fmt = "%llu", .out_json = "stransid" },
+	{ .key = "stime", .fmt = "time-long", .out_json = "stime" },
+	{ .key = "rtransid", .fmt = "%llu", .out_json = "rtransid" },
+	{ .key = "rtime", .fmt = "time-long", .out_json = "rtime" },
+	{ .key = "snapshot-list-item", .fmt = "%s" },
+	{ .key = "quota-group", .fmt = "qgroupid", .out_json = "group" },
+	{ .key = "quota-ref", .fmt = "%llu", .out_json = "referenced" },
+	{ .key = "quota-excl", .fmt = "%llu", .out_json = "exclusive" },
+	ROWSPEC_END
+};
+
 static int wait_for_subvolume_cleaning(int fd, size_t count, uint64_t *ids,
 				       int sleep_interval)
 {
diff --git a/cmds/subvolume.h b/cmds/subvolume.h
new file mode 100644
index 00000000..041ea865
--- /dev/null
+++ b/cmds/subvolume.h
@@ -0,0 +1,19 @@ 
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+struct rowspec;
+
+extern const struct rowspec btrfs_subvolume_rowspec[];