Changes by: flatcap
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv703/ntfstools
Modified Files:
ntfsundelete.c ntfsundelete.h
Log Message:
filename regex matching works, default to case insensitive matching
Index: ntfsundelete.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsundelete.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -U2 -r1.7 -r1.8
--- ntfsundelete.c 13 Jul 2002 16:33:00 -0000 1.7
+++ ntfsundelete.c 14 Jul 2002 11:20:20 -0000 1.8
@@ -86,5 +86,5 @@
" -p num --percentage num Minimum percentage recoverable\n"
" -m regex --match regex Only work on files with matching names\n"
- " -i --ignore-case Case insensive matching\n"
+ " -C --case Case sensive matching\n"
" -S range --size range Match files of this size\n"
"\n"
@@ -105,52 +105,4 @@
-#if 0
-/**
- * create_regex
- */
-int create_regex (const char *pattern, int case, regex_t *re)
-{
- int result;
- int retval = 1;
- char *arg1, *arg2;
-
- arg1 = create_regex (argv[1]);
- arg2 = argv[2];
- if (!arg1) {
- printf ("create_regex\n");
- goto free;
- }
-
- //printf ("match '%s' = regex '%s'\n", argv[1], arg1);
-
- if (regcomp (&re, arg1, REG_NOSUB)) {
- printf ("regcomp\n");
- goto out;
- }
-
- result = regexec (&re, arg2, 0, NULL, 0);
- if (result < 0) {
- printf ("regexec\n");
- goto rfree;
- }
-
- if (result == REG_NOMATCH) {
- printf ("no match\n");
- goto rfree;
- }
-
- printf ("match\n");
- retval = 0;
-
-rfree:
- regfree (&re);
-free:
- free (arg1);
-out:
- return retval;
-}
-
-#endif
-
/**
* transform
@@ -177,9 +129,11 @@
}
- result = malloc (length + 1);
+ result = malloc (length + 3);
if (!result)
return NULL;
- for (i = 0, j = 0; pattern[i]; i++, j++) {
+ result[0] = '^';
+
+ for (i = 0, j = 1; pattern[i]; i++, j++) {
if (pattern[i] == '*') {
result[j] = '.';
@@ -197,4 +151,6 @@
}
+ result[j] = '$';
+
return result;
}
@@ -274,5 +230,4 @@
}
-
/**
* parse_options - Read and validate the programs command line
@@ -286,10 +241,10 @@
int parse_options (int argc, char *argv[])
{
- static const char *sopt = "-sp:m:iS:u:o:d:b:c:fvVh";
+ static const char *sopt = "-sp:m:CS:u:o:d:b:c:fvVh";
static const struct option lopt[] = {
{ "scan", no_argument, NULL, 's' },
{ "percentage", required_argument, NULL, 'p' },
{ "match", required_argument, NULL, 'm' },
- { "ignore-case", no_argument, NULL, 'i' },
+ { "case", no_argument, NULL, 'C' },
{ "size", required_argument, NULL, 'S' },
{ "undelete", required_argument, NULL, 'u' },
@@ -395,6 +350,6 @@
err++;
break;
- case 'i':
- opts.ignore_case++;
+ case 'C':
+ opts.match_case++;
break;
case 'f':
@@ -446,5 +401,5 @@
break;
case MODE_UNDELETE:
- if ((opts.percent != -1) || opts.match || opts.ignore_case ||
+ if ((opts.percent != -1) || opts.match || opts.match_case ||
(opts.size_begin > 0) || (opts.size_end > 0)) {
printf ("Undelete can only be used with "
@@ -456,5 +411,5 @@
if (opts.dest || (opts.fillbyte != -1) ||
(opts.percent != -1) || opts.match ||
- opts.ignore_case || (opts.size_begin > 0) ||
+ opts.match_case || (opts.size_begin > 0) ||
(opts.size_end > 0)) {
printf ("Copy can only be used with --output\n");
@@ -1133,9 +1088,37 @@
/**
+ * name_match
+ */
+int name_match (regex_t *re, struct ufile *file)
+{
+ struct list_head *item;
+ int result;
+
+ if (!re || !file)
+ return 0;
+
+ list_for_each (item, &file->name) {
+ struct filename *f = list_entry (item, struct filename, list);
+
+ if (!f->name)
+ continue;
+ result = regexec (re, f->name, 0, NULL, 0);
+ if (result < 0) {
+ printf ("regexec\n");
+ return 0;
+ } else if (result == REG_NOERROR) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/**
* scan_disk
*/
int scan_disk (ntfs_volume *vol)
{
- char *buffer;
+ char *buffer = NULL;
int results = 0;
ntfs_attr *attr;
@@ -1145,4 +1128,5 @@
int percent;
struct ufile *file;
+ regex_t re;
if (!vol)
@@ -1155,6 +1139,19 @@
buffer = malloc (vol->mft_record_size);
if (!buffer) {
- ntfs_attr_close (attr);
- return -1;
+ results = -1;
+ goto out;
+ }
+
+ //printf ("match '%s' = regex '%s'\n", argv[1], arg1);
+
+ if (opts.match) {
+ int flags = REG_NOSUB;
+
+ if (!opts.match_case)
+ flags |= REG_ICASE;
+ if (regcomp (&re, opts.match, flags)) {
+ printf ("regcomp\n");
+ goto out;
+ }
}
@@ -1178,4 +1175,7 @@
}
+ if (opts.match && !name_match (&re, file))
+ continue;
+
percent = calc_percentage (file, vol);
@@ -1197,7 +1197,10 @@
}
printf ("\nFiles with potentially recoverable content: %d\n", results);
-
+out:
+ if (opts.match)
+ regfree (&re);
free (buffer);
- ntfs_attr_close (attr);
+ if (attr)
+ ntfs_attr_close (attr);
return results;
}
Index: ntfsundelete.h
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsundelete.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -U2 -r1.4 -r1.5
--- ntfsundelete.h 13 Jul 2002 16:33:00 -0000 1.4
+++ ntfsundelete.h 14 Jul 2002 11:20:20 -0000 1.5
@@ -47,5 +47,5 @@
char fillbyte; /* Use for unrecoverable sections */
char *match; /* Regex for filename matching */
- int ignore_case; /* Case insensitive matching */
+ int match_case; /* Case sensitive matching */
int verbose; /* Extra output */
int force; /* Override common sense */
|