Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not print filename if only one file #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions misc/filefrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern int optind;
#include <ext2fs/fiemap.h>
#include "../version.h"

int one_arg_only = 0;
int verbose = 0;
unsigned int blocksize; /* Use specified blocksize (default 1kB) */
int sync_file = 0; /* fsync file before getting the mapping */
Expand Down Expand Up @@ -502,8 +503,13 @@ static int frag_report(const char *filename)
if (verbose) {
__u32 state;

printf("File size of %s is %llu (%llu block%s of %d bytes)",
filename, (unsigned long long) st.st_size,
if (one_arg_only)
printf("File size ");
else
printf("File size of %s ", filename);

printf("is %llu (%llu block%s of %d bytes)",
(unsigned long long) st.st_size,
(unsigned long long) (numblocks * blksize >> blk_shift),
numblocks == 1 ? "" : "s", 1 << blk_shift);
if (use_extent_cache &&
Expand Down Expand Up @@ -551,10 +557,12 @@ static int frag_report(const char *filename)
expected = expected / data_blocks_per_cyl + 1;
}

if (!one_arg_only)
printf("%s: ", filename);
if (num_extents == 1)
printf("%s: 1 extent found", filename);
printf("1 extent found");
else
printf("%s: %d extents found", filename, num_extents);
printf("%d extents found", num_extents);
/* count, and thus expected, only set for indirect FIBMAP'd files */
if (is_ext2 && expected && expected < num_extents)
printf(", perfection would be %d extent%s\n", expected,
Expand Down Expand Up @@ -683,6 +691,9 @@ int main(int argc, char**argv)
if (optind == argc)
usage(argv[0]);

if (optind + 1 == argc)
one_arg_only = 1;

for (cpp = argv + optind; *cpp != NULL; cpp++) {
int rc2 = frag_report(*cpp);

Expand Down