mirror of
https://gitee.com/openharmony/third_party_f2fs-tools
synced 2024-11-23 10:10:00 +00:00
fsck.f2fs: introduce new option --dry-run
With --dry-run enabled, fsck.f2fs will do all checks and "fixes" except that all fixes will not be written to storage at last. Signed-off-by: Sheng Yong <shengyong1@huawei.com> Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
2d1a62ee75
commit
f2f1341ffe
14
fsck/main.c
14
fsck/main.c
@ -18,6 +18,7 @@
|
||||
#include "fsck.h"
|
||||
#include <libgen.h>
|
||||
#include <ctype.h>
|
||||
#include <getopt.h>
|
||||
#include "quotaio.h"
|
||||
|
||||
struct f2fs_fsck gfsck;
|
||||
@ -31,6 +32,7 @@ void fsck_usage()
|
||||
MSG(0, " -f check/fix entire partition\n");
|
||||
MSG(0, " -p preen mode [default:0 the same as -a [0|1]]\n");
|
||||
MSG(0, " -t show directory tree\n");
|
||||
MSG(0, " --dry-run do not really fix corruptions\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -118,10 +120,20 @@ void f2fs_parse_options(int argc, char *argv[])
|
||||
|
||||
if (!strcmp("fsck.f2fs", prog)) {
|
||||
const char *option_string = ":ad:fp:t";
|
||||
int opt = 0;
|
||||
struct option long_opt[] = {
|
||||
{"dry-run", no_argument, 0, 1},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c.func = FSCK;
|
||||
while ((option = getopt(argc, argv, option_string)) != EOF) {
|
||||
while ((option = getopt_long(argc, argv, option_string,
|
||||
long_opt, &opt)) != EOF) {
|
||||
switch (option) {
|
||||
case 1:
|
||||
c.dry_run = 1;
|
||||
MSG(0, "Info: Dry run\n");
|
||||
break;
|
||||
case 'a':
|
||||
c.auto_fix = 1;
|
||||
MSG(0, "Info: Fix the reported corruption.\n");
|
||||
|
@ -309,6 +309,7 @@ struct f2fs_configuration {
|
||||
int trimmed;
|
||||
int func;
|
||||
void *private;
|
||||
int dry_run;
|
||||
int fix_on;
|
||||
int bug_on;
|
||||
int auto_fix;
|
||||
|
@ -598,6 +598,7 @@ void f2fs_init_configuration(void)
|
||||
c.trimmed = 0;
|
||||
c.ro = 0;
|
||||
c.kd = -1;
|
||||
c.dry_run = 0;
|
||||
}
|
||||
|
||||
static int is_mounted(const char *mpt, const char *device)
|
||||
|
@ -129,6 +129,9 @@ int dev_write(void *buf, __u64 offset, size_t len)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (c.dry_run)
|
||||
return 0;
|
||||
|
||||
if (c.sparse_mode)
|
||||
return dev_write_sparse(buf, offset, len);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user