From f4a82d9e6754ad63086315089966b840118bbc1a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 5 Oct 2017 15:25:53 +0200 Subject: [PATCH] btrfs-progs: subvol list: don't list FS_TREE as deleted Adding support for 'btrfs subvol show' for the toplevel subvolume accidentally started to list the toplevel subvolume among the deleted. Since version 4.8.3. Don't panic. The toplevel subvolume (id 5) cannot be deleted. Fixes: d4aa2bc07e ("btrfs-progs: subvol show: print more details about toplevel subvolume") Signed-off-by: David Sterba --- btrfs-list.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/btrfs-list.c b/btrfs-list.c index b050bb6..dd917a3 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -1273,8 +1273,18 @@ static void filter_and_sort_subvol(struct root_lookup *all_subvols, ret = resolve_root(all_subvols, entry, top_id); if (ret == -ENOENT) { - entry->full_path = strdup("DELETED"); - entry->deleted = 1; + if (top_id != BTRFS_FS_TREE_OBJECTID) { + entry->full_path = strdup("DELETED"); + entry->deleted = 1; + } else { + /* + * The full path is not supposed to be printed, + * but we don't want to print an empty string, + * in case it appears somewhere. + */ + entry->full_path = strdup("TOPLEVEL"); + entry->deleted = 0; + } } ret = filter_root(entry, filter_set); if (ret) @@ -1459,6 +1469,11 @@ static void print_all_subvol_info(struct root_lookup *sorted_tree, n = rb_first(&sorted_tree->root); while (n) { entry = rb_entry(n, struct root_info, sort_node); + + /* The toplevel subvolume is not listed by default */ + if (entry->root_id == BTRFS_FS_TREE_OBJECTID) + goto next; + switch (layout) { case BTRFS_LIST_LAYOUT_DEFAULT: print_one_subvol_info_default(entry); @@ -1470,6 +1485,7 @@ static void print_all_subvol_info(struct root_lookup *sorted_tree, print_one_subvol_info_raw(entry, raw_prefix); break; } +next: n = rb_next(n); } } -- 2.7.4