Changes by: flatcap
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv16216/ntfstools
Modified Files:
ntfsundelete.c ntfsundelete.h
Log Message:
open vol read-only, filter by last mod time
Index: ntfsundelete.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsundelete.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -U2 -r1.8 -r1.9
--- ntfsundelete.c 14 Jul 2002 11:20:20 -0000 1.8
+++ ntfsundelete.c 14 Jul 2002 14:49:22 -0000 1.9
@@ -39,4 +39,5 @@
#include <regex.h>
#include <libintl.h>
+#include <time.h>
#include "ntfsundelete.h"
@@ -86,6 +87,7 @@
" -p num --percentage num Minimum percentage recoverable\n"
" -m regex --match regex Only work on files with matching names\n"
- " -C --case Case sensive matching\n"
+ " -C --case Case sensitive matching\n"
" -S range --size range Match files of this size\n"
+ " -t time --time Last referenced since this time"
"\n"
" -u num --undelete num Undelete inode\n"
@@ -157,4 +159,47 @@
/**
+ * parse_time
+ */
+int parse_time (const char *string, time_t *since)
+{
+ time_t result;
+ char mult = 0;
+
+ if (!string || !since) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ for (result = 0; *string; string++) {
+ if ((*string >= '0') && (*string <= '9')) {
+ result *= 10;
+ result += *string - '0';
+ } else {
+ mult = *string;
+ break;
+ }
+ }
+
+ switch (mult) {
+ case 'y': case 'Y': result *= 12;
+ case 'm': case 'M': result *= 4;
+ case 'w': case 'W': result *= 7;
+ case 'd': case 'D': result *= 24;
+ case 'h': case 'H': result *= 3600;
+ case 's': case 'S':
+ case 0:
+ break;
+
+ default:
+ printf ("invalid time\n");
+ return 0;
+ }
+
+ //printf ("now = %d, since = %d\n", time(NULL), result);
+ *since = time(NULL) - result;
+ return 1;
+}
+
+/**
* parse_size
*/
@@ -241,5 +286,5 @@
int parse_options (int argc, char *argv[])
{
- static const char *sopt = "-sp:m:CS:u:o:d:b:c:fvVh";
+ static const char *sopt = "-sp:m:CS:t:u:o:d:b:c:fvVh";
static const struct option lopt[] = {
{ "scan", no_argument, NULL, 's' },
@@ -248,4 +293,5 @@
{ "case", no_argument, NULL, 'C' },
{ "size", required_argument, NULL, 'S' },
+ { "time", required_argument, NULL, 't' },
{ "undelete", required_argument, NULL, 'u' },
{ "output", required_argument, NULL, 'o' },
@@ -313,4 +359,12 @@
}
break;
+ case 't':
+ if (opts.since == 0) {
+ if (!parse_time (argv[optind-1], &opts.since))
+ err++;
+ } else {
+ err++;
+ }
+ break;
case 'o':
if (!opts.output) {
@@ -638,4 +692,14 @@
name->flags = attr->file_attributes;
+ name->date_c = ntfs2utc (attr->creation_time);
+ name->date_a = ntfs2utc (attr->last_data_change_time);
+ name->date_m = ntfs2utc (attr->last_mft_change_time);
+ name->date_r = ntfs2utc (attr->last_access_time);
+
+ file->date = max (file->date, name->date_c);
+ file->date = max (file->date, name->date_a);
+ file->date = max (file->date, name->date_m);
+ file->date = max (file->date, name->date_r);
+
if (ntfs_ucstombs (name->uname, name->uname_len, &name->name,
name->uname_len) < 0) {
@@ -782,5 +846,5 @@
STANDARD_INFORMATION *si;
si = (STANDARD_INFORMATION *) ((char *) attr10 + le16_to_cpu (attr10->value_offset));
- file->date = ntfs2utc (si->last_data_change_time);
+ file->date = max (file->date, ntfs2utc (si->last_data_change_time));
}
@@ -970,4 +1034,13 @@
printf ("Size alloc: %lld\n", f->size_alloc);
printf ("Size data: %lld\n", f->size_data);
+
+ strftime (buffer, sizeof (buffer), "%F %R", localtime (&f->date_c));
+ printf ("Date C: %s\n", buffer);
+ strftime (buffer, sizeof (buffer), "%F %R", localtime (&f->date_a));
+ printf ("Date A: %s\n", buffer);
+ strftime (buffer, sizeof (buffer), "%F %R", localtime (&f->date_m));
+ printf ("Date M: %s\n", buffer);
+ strftime (buffer, sizeof (buffer), "%F %R", localtime (&f->date_r));
+ printf ("Date R: %s\n", buffer);
}
@@ -1175,6 +1248,8 @@
}
+ if ((opts.since > 0) && (file->date <= opts.since))
+ continue;
if (opts.match && !name_match (&re, file))
- continue;
+ continue;
percent = calc_percentage (file, vol);
@@ -1456,5 +1531,5 @@
}
- vol = ntfs_mount (opts.device, 0);
+ vol = ntfs_mount (opts.device, MS_RDONLY);
if (opts.uinode >= 0)
Index: ntfsundelete.h
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsundelete.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -U2 -r1.5 -r1.6
--- ntfsundelete.h 14 Jul 2002 11:20:20 -0000 1.5
+++ ntfsundelete.h 14 Jul 2002 14:49:22 -0000 1.6
@@ -50,4 +50,5 @@
int verbose; /* Extra output */
int force; /* Override common sense */
+ time_t since; /* Since this time */
long long size_begin; /* Range for file size */
long long size_end;
@@ -65,4 +66,8 @@
long long size_data; /* Actual size of data */
FILE_ATTR_FLAGS flags;
+ time_t date_c;
+ time_t date_a;
+ time_t date_m;
+ time_t date_r;
};
|