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

Conversation

brianpow
Copy link

No description provided.

@AltraMayor
Copy link
Owner

Hi @brianpow,

Before we go through code review, could you describe the use case that this pull request intends to help? It doesn't need to be formal or long, I'm just looking for a brief description of the situation in which someone would want to use the parameter --keep. I understood what the parameter does, but I couldn't come up with a situation that I'd use it.

Thank you.

@brianpow
Copy link
Author

Hi @brianpow,

Before we go through code review, could you describe the use case that this pull request intends to help? It doesn't need to be formal or long, I'm just looking for a brief description of the situation in which someone would want to use the parameter --keep. I understood what the parameter does, but I couldn't come up with a situation that I'd use it.

Thank you.

Hi. If the flash memory is overheated, your computer is suspended or the test is interrupted accidentally, we can keep the existing files and continue f3write instead of creating everything from beginning.

@brianpow
Copy link
Author

brianpow commented Jul 20, 2020

now f3read can delete corrupted NUM.h2w. It makes my life easier if corrupted file was found and I want to tested again by recreating only those corrupted file. So I can easily run these command without counting around the start or end number.
f3read -d /dev/XXX ; f3write -k /dev/XXX; f3read /dev/XXX

for f3probe, with --fix parameter, again user doesn't need to mark down the sectors and run f3fix.

Both changes are good for unattended test/fix too

@AltraMayor
Copy link
Owner

Having f3read --delete does add meaning to f3write --keep. I'm going to work with you to review the code and merge it.

Let's start making this pull request coherent. First, create a second pull request and move patch add --fix parameter to run f3fix automatically if counterfeit memory detected. I intend to accept this second pull request as well, but let's get a thing done at a time.

Please add f3read: , f3write: , f3probe: to the title of the patches accordingly. You can find examples in the log of the repository.

Copy link
Owner

@AltraMayor AltraMayor left a comment

Choose a reason for hiding this comment

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

add --keep parameter to keep existing NUM.h2w files

f3write.c Outdated Show resolved Hide resolved
f3write.c Outdated Show resolved Hide resolved
f3write.c Outdated Show resolved Hide resolved
f3write.c Outdated Show resolved Hide resolved
f3write.c Outdated Show resolved Hide resolved
f3write.c Outdated Show resolved Hide resolved
Copy link
Owner

@AltraMayor AltraMayor left a comment

Choose a reason for hiding this comment

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

add --delete parameter to delete corrupted NUM.h2w file

Please add an s to file in the title of this patch.

f3read.c Outdated Show resolved Hide resolved
f3read.c Outdated Show resolved Hide resolved
@@ -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.

f3read.c Outdated Show resolved Hide resolved
f3read.c Outdated Show resolved Hide resolved
@AltraMayor AltraMayor changed the title add --keep parameter to keep existing NUM.h2w files add f3write --keep and f3read --delete parameters Jul 28, 2020
@AltraMayor AltraMayor changed the title add f3write --keep and f3read --delete parameters Add f3write --keep and f3read --delete parameters Jul 28, 2020
Copy link
Owner

@AltraMayor AltraMayor left a comment

Choose a reason for hiding this comment

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

add --fix parameter to run f3fix automatically if counterfeit memory detected

A shorter title: add --fix parameter to run f3fix when needed

f3probe.c Show resolved Hide resolved
f3probe.c Show resolved Hide resolved
f3probe.c Outdated Show resolved Hide resolved
@@ -373,8 +382,8 @@ static int test_device(struct args *args)
uint64_t read_count, read_time_us;
uint64_t write_count, write_time_us;
uint64_t reset_count, reset_time_us;
uint64_t last_good_sector;
Copy link
Owner

@AltraMayor AltraMayor Jul 28, 2020

Choose a reason for hiding this comment

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

Instead of moving the declaration of last_good_sector here, declare char *fix_cmd = NULL;

More details in other comments.

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.

Copy link
Owner

Choose a reason for hiding this comment

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

To clarify, the declaration of last_good_sector should be moved back to the body of the switch..case.

f3probe.c Outdated Show resolved Hide resolved
f3probe.c Outdated Show resolved Hide resolved
f3probe.c Outdated Show resolved Hide resolved
Copy link
Owner

@AltraMayor AltraMayor left a comment

Choose a reason for hiding this comment

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

f3write: code cleanup

f3write.c Show resolved Hide resolved
printf("Skipping file %s\n", filename);
return false;
}

Copy link
Owner

Choose a reason for hiding this comment

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

Style: drop this new blank line.

free(full_fn);
return false;
}
err(errno, "Unexpectedly found file %s, but option --keep is not in use", full_fn);
Copy link
Owner

Choose a reason for hiding this comment

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

Could replace the but with and? My fault, sorry.

Copy link
Owner

@AltraMayor AltraMayor left a comment

Choose a reason for hiding this comment

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

f3read: code cleanup

@@ -386,11 +386,13 @@ 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) {
if (delete && (stats.secs_corrupted || tot_changed || tot_overwritten)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Please replace tot_changed with stats.secs_changed and tot_overwritten with stats.secs_overwritten. My fault, again.

Break the line as needed to fit within the 80-column limit.

@@ -485,6 +486,7 @@ static int test_device(struct args *args)
case FKTY_CHAIN: {
last_good_sector = (real_size_byte >> 9) - 1;
assert(block_order >= 9);
assert(asprintf(&fix_cmd, "f3fix --last-sec=%" PRIu64 " %s", last_good_sector, final_dev_filename) > 0);
Copy link
Owner

Choose a reason for hiding this comment

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

Break line to fit within the 80-column limit.

@@ -485,6 +486,7 @@ static int test_device(struct args *args)
case FKTY_CHAIN: {
last_good_sector = (real_size_byte >> 9) - 1;
assert(block_order >= 9);
assert(asprintf(&fix_cmd, "f3fix --last-sec=%" PRIu64 " %s", last_good_sector, final_dev_filename) > 0);
printf("Bad news: The device `%s' is a counterfeit of type %s\n\n"
"You can \"fix\" this device using the following command:\n"
"f3fix --last-sec=%" PRIu64 " %s\n",
Copy link
Owner

Choose a reason for hiding this comment

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

  1. Replace the line "f3fix --last-sec=%" PRIu64 " %s\n", with "%s\n",.
  2. Replace the line last_good_sector, final_dev_filename); below with fix_cmd);.

Comment on lines +521 to +523
if (args->fix && fix_cmd) {
system(fix_cmd);
}
Copy link
Owner

Choose a reason for hiding this comment

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

Style: drop the braces since the body of this if statement is a single line.

@@ -373,8 +382,8 @@ static int test_device(struct args *args)
uint64_t read_count, read_time_us;
uint64_t write_count, write_time_us;
uint64_t reset_count, reset_time_us;
uint64_t last_good_sector;
Copy link
Owner

Choose a reason for hiding this comment

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

To clarify, the declaration of last_good_sector should be moved back to the body of the switch..case.

Copy link
Owner

@AltraMayor AltraMayor left a comment

Choose a reason for hiding this comment

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

f3probe: code cleanup

Copy link
Owner

@AltraMayor AltraMayor left a comment

Choose a reason for hiding this comment

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

f3write: code cleanup

@@ -39,8 +39,8 @@ static struct argp_option options[] = {
"Maximum write rate", 0},
{"show-progress", 'p', "NUM", 0,
"Show progress if NUM is not zero", 0},
{"keep", 'k', 0, 0,
"Keep existing NUM.h2w file, otherwise all NUM.h2w files will be removed in each run", 0},
{"keep", 'k', 0, 0,
Copy link
Owner

Choose a reason for hiding this comment

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

Replace the first 0 after 'k' with NULL.

@brianpow
Copy link
Author

brianpow commented Sep 1, 2020

@AltraMayor
Thank you for your comments and guidance. Sorry that I just started a big project. For those glitches, I guess majorities of them won't break the program and hope someone will fix them. Sorry again for my poor programming habit.

@AltraMayor
Copy link
Owner

I'm going to leave this pull request open, so someone else can pick it up if the need for it comes. Good luck on your new project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants