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

Add f3write --keep and f3read --delete parameters #140

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
18 changes: 16 additions & 2 deletions f3read.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ static struct argp_option options[] = {
"Maximum read rate", 0},
{"show-progress", 'p', "NUM", 0,
"Show progress if NUM is not zero", 0},
{"delete", 'd', NULL, 0,
brianpow marked this conversation as resolved.
Show resolved Hide resolved
"delete corrupted NUM.h2w file", 0},
AltraMayor marked this conversation as resolved.
Show resolved Hide resolved
{ 0 }
};

Expand All @@ -48,6 +50,7 @@ struct args {
long end_at;
long max_read_rate;
int show_progress;
bool delete;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align indentation with other fields.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've missed this item.

const char *dev_path;
};

Expand Down Expand Up @@ -85,6 +88,10 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
args->show_progress = !!arg_to_long(state, arg);
break;

case 'd':
args->delete = true;
break;

case ARGP_KEY_INIT:
args->dev_path = NULL;
break;
Expand Down Expand Up @@ -340,7 +347,7 @@ static inline void pr_avg_speed(double speed)
}

static void iterate_files(const char *path, const long *files,
long start_at, long end_at, long max_read_rate, int progress)
long start_at, long end_at, long max_read_rate, int progress, bool delete)
{
uint64_t tot_ok, tot_corrupted, tot_changed, tot_overwritten, tot_size;
int and_read_all = 1;
Expand Down Expand Up @@ -379,6 +386,12 @@ static void iterate_files(const char *path, const long *files,
tot_overwritten += stats.secs_overwritten;
tot_size += stats.bytes_read;
and_read_all = and_read_all && stats.read_all;
if (stats.secs_corrupted && delete) {
AltraMayor marked this conversation as resolved.
Show resolved Hide resolved
const char *filename;
char *full_fn = full_fn_from_number(&filename, path, *files);
if (unlink(full_fn))
err(errno, "Can't remove file %s\n", full_fn);
}
AltraMayor marked this conversation as resolved.
Show resolved Hide resolved
files++;
}
assert(!gettimeofday(&t2, NULL));
Expand Down Expand Up @@ -428,6 +441,7 @@ int main(int argc, char **argv)
.max_read_rate = 0,
/* If stdout isn't a terminal, supress progress. */
.show_progress = isatty(STDOUT_FILENO),
.delete = false,
};

/* Read parameters. */
Expand All @@ -437,7 +451,7 @@ int main(int argc, char **argv)
files = ls_my_files(args.dev_path, args.start_at, args.end_at);

iterate_files(args.dev_path, files, args.start_at, args.end_at,
args.max_read_rate, args.show_progress);
args.max_read_rate, args.show_progress, args.delete);
free((void *)files);
return 0;
}