Skip to content

Commit

Permalink
btrfs-progs: fi show: remove stray newline in filesystem show
Browse files Browse the repository at this point in the history
Remove last newline in the output of 'btrfs filesystem show', keep the
line between two filesystems so the devices are visually grouped
togehter.

Pull-request: #866
Author: Matt Langford <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
mattlangford authored and kdave committed Aug 19, 2024
1 parent 84c044d commit 48be42f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cmds/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices,
if (devs_found < total) {
pr_verbose(LOG_DEFAULT, "\t*** Some devices missing\n");
}
pr_verbose(LOG_DEFAULT, "\n");
}

/* adds up all the used spaces as reported by the space info ioctl
Expand Down Expand Up @@ -431,7 +430,6 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
free(canonical_path);
}

pr_verbose(LOG_DEFAULT, "\n");
return 0;
}

Expand Down Expand Up @@ -481,6 +479,10 @@ static int btrfs_scan_kernel(void *search, unsigned unit_mode)

fd = open(mnt->mnt_dir, O_RDONLY);
if ((fd != -1) && !get_df(fd, &space_info_arg)) {
/* Put space between filesystem entries for readability. */
if (found != 0)
pr_verbose(LOG_DEFAULT, "\n");

print_one_fs(&fs_info_arg, dev_info_arg,
space_info_arg, label, unit_mode);
free(space_info_arg);
Expand Down Expand Up @@ -757,6 +759,7 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
char uuid_buf[BTRFS_UUID_UNPARSED_SIZE];
unsigned unit_mode;
int found = 0;
bool needs_newline = false;

unit_mode = get_unit_mode_from_arg(&argc, argv, 0);

Expand Down Expand Up @@ -845,6 +848,12 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
goto out;
}

/*
* The above call will return 0 if it found anything, in those cases we
* need an extra newline below.
*/
needs_newline = !ret;

/* shows mounted only */
if (where == BTRFS_SCAN_MOUNTED)
goto out;
Expand Down Expand Up @@ -882,8 +891,14 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
goto out;
}

list_for_each_entry(fs_devices, &all_uuids, fs_list)
list_for_each_entry(fs_devices, &all_uuids, fs_list) {
/* Put space between filesystem entries for readability. */
if (needs_newline)
pr_verbose(LOG_DEFAULT, "\n");

print_one_uuid(fs_devices, unit_mode);
needs_newline = true;
}

if (search && !found) {
error("not a valid btrfs filesystem: %s", search);
Expand Down

0 comments on commit 48be42f

Please sign in to comment.