Skip to content

Commit 48be42f

Browse files
mattlangfordkdave
authored andcommittedAug 19, 2024
btrfs-progs: fi show: remove stray newline in filesystem show
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 <github@matt.boats> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 84c044d commit 48be42f

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed
 

‎cmds/filesystem.c

+18-3
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices,
365365
if (devs_found < total) {
366366
pr_verbose(LOG_DEFAULT, "\t*** Some devices missing\n");
367367
}
368-
pr_verbose(LOG_DEFAULT, "\n");
369368
}
370369

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

434-
pr_verbose(LOG_DEFAULT, "\n");
435433
return 0;
436434
}
437435

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

482480
fd = open(mnt->mnt_dir, O_RDONLY);
483481
if ((fd != -1) && !get_df(fd, &space_info_arg)) {
482+
/* Put space between filesystem entries for readability. */
483+
if (found != 0)
484+
pr_verbose(LOG_DEFAULT, "\n");
485+
484486
print_one_fs(&fs_info_arg, dev_info_arg,
485487
space_info_arg, label, unit_mode);
486488
free(space_info_arg);
@@ -757,6 +759,7 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
757759
char uuid_buf[BTRFS_UUID_UNPARSED_SIZE];
758760
unsigned unit_mode;
759761
int found = 0;
762+
bool needs_newline = false;
760763

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

@@ -845,6 +848,12 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
845848
goto out;
846849
}
847850

851+
/*
852+
* The above call will return 0 if it found anything, in those cases we
853+
* need an extra newline below.
854+
*/
855+
needs_newline = !ret;
856+
848857
/* shows mounted only */
849858
if (where == BTRFS_SCAN_MOUNTED)
850859
goto out;
@@ -882,8 +891,14 @@ static int cmd_filesystem_show(const struct cmd_struct *cmd,
882891
goto out;
883892
}
884893

885-
list_for_each_entry(fs_devices, &all_uuids, fs_list)
894+
list_for_each_entry(fs_devices, &all_uuids, fs_list) {
895+
/* Put space between filesystem entries for readability. */
896+
if (needs_newline)
897+
pr_verbose(LOG_DEFAULT, "\n");
898+
886899
print_one_uuid(fs_devices, unit_mode);
900+
needs_newline = true;
901+
}
887902

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

0 commit comments

Comments
 (0)