diff --git a/ntfsprogs/ntfsundelete.c b/ntfsprogs/ntfsundelete.c index 5d479b57..96e37373 100644 --- a/ntfsprogs/ntfsundelete.c +++ b/ntfsprogs/ntfsundelete.c @@ -221,6 +221,7 @@ static void usage (void) "\n" " -u nums --undelete nums Undelete inodes\n" " -o file --output file Save with this filename\n" + " -O --optimistic Undelete in-use clusters as well\n" " -d dir --destination dir Destination directory\n" " -b num --byte num Fill missing parts with this byte\n" " -T --truncate Truncate 100%% recoverable file to exact size.\n" @@ -390,7 +391,7 @@ static int parse_time (const char *value, time_t *since) */ static int parse_options (int argc, char *argv[]) { - static const char *sopt = "-b:Cc:d:fh?m:o:p:sS:t:Tu:qvV"; + static const char *sopt = "-b:Cc:d:fh?m:o:Op:sS:t:Tu:qvV"; static const struct option lopt[] = { { "byte", required_argument, NULL, 'b' }, { "case", no_argument, NULL, 'C' }, @@ -400,6 +401,7 @@ static int parse_options (int argc, char *argv[]) { "help", no_argument, NULL, 'h' }, { "match", required_argument, NULL, 'm' }, { "output", required_argument, NULL, 'o' }, + { "optimistic", no_argument, NULL, 'O' }, { "percentage", required_argument, NULL, 'p' }, { "scan", no_argument, NULL, 's' }, { "size", required_argument, NULL, 'S' }, @@ -486,6 +488,13 @@ static int parse_options (int argc, char *argv[]) err++; } break; + case 'O': + if (!opts.optimistic) { + opts.optimistic++; + } else { + err++; + } + break; case 'p': if (opts.percent == -1) { end = NULL; @@ -1666,7 +1675,7 @@ static int undelete_file (ntfs_volume *vol, long long inode) end = rl[i].lcn + rl[i].length; for (j = start; j < end; j++) { - if (utils_cluster_in_use (vol, j)) { + if (utils_cluster_in_use (vol, j) && !opts.optimistic) { memset (buffer, opts.fillbyte, bufsize); if (write_data (fd, buffer, bufsize) < bufsize) { Eprintf ("Write failed: %s\n", strerror (errno)); diff --git a/ntfsprogs/ntfsundelete.h b/ntfsprogs/ntfsundelete.h index 2e0a2189..4a25af98 100644 --- a/ntfsprogs/ntfsundelete.h +++ b/ntfsprogs/ntfsundelete.h @@ -50,6 +50,7 @@ struct options { int quiet; /* Less output */ int verbose; /* Extra output */ int force; /* Override common sense */ + int optimistic; /* Undelete in-use clusters as well */ time_t since; /* Since this time */ s64 size_begin; /* Range for file size */ s64 size_end;