Changes by: flatcap
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv8997
Modified Files:
ntfsundelete.8.in ntfsundelete.c
Log Message:
docs updated. mem leak fixed.
Index: ntfsundelete.8.in
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsundelete.8.in,v
retrieving revision 1.6
retrieving revision 1.7
diff -U2 -r1.6 -r1.7
--- ntfsundelete.8.in 17 Jul 2002 10:51:15 -0000 1.6
+++ ntfsundelete.8.in 17 Jul 2002 23:36:31 -0000 1.7
@@ -186,6 +186,6 @@
.TP
.BI \-\-quiet
-Reduce the amount of output to a minimum. Naturally, it doesn't make sense to combine
-this option with
+Reduce the amount of output to a minimum. Naturally, it doesn't make sense to
+combine this option with
.BR \-\-scan .
.TP
@@ -206,5 +206,32 @@
.B \-\-time
options, respectively.
+.sp
+The output to scan will be:
+.sp
+.br
+Inode Flags %age Date Size Filename
+.br
+----------------------------------------------
+.br
+6038 FN.. 93% 2002-07-17 26629 thesis.doc
+.br
+.RS
.TP
+The flags field can display:
+F/D \- File/Directory
+.br
+N/R \- (Non-)Resident data stream
+.br
+C/E \- Compressed/Encrypted data stream
+.br
+! \- Missing attributes
+.sp
+.RE
+.RS
+The percentage field shows how much of the file can potentially be recovered.
+.sp
+.br
+.RE
+.RE
.BI "\-S " range
.br
@@ -258,47 +285,52 @@
.BR ntfsundelete .
.SH EXAMPLES
-.TP
Look for deleted files on /dev/hda1.
-.RS 4
-.TP
+.RS
+.sp
.B ntfsundelete /dev/hda1
+.sp
.RE
-.TP
Look for deleted documents on /dev/hda1.
-.RS 4
-.TP
+.RS
+.sp
.B ntfsundelete /dev/hda1 -s \-m '*.doc'
+.sp
.RE
-.TP
-Look for deleted files between 5000 and 6000000 bytes, with at least 90% of the data recoverable, on /dev/hda1.
-.RS 4
-.TP
+Look for deleted files between 5000 and 6000000 bytes, with at least 90% of the
+data recoverable, on /dev/hda1.
+.RS
+.sp
.B ntfsundelete /dev/hda1 \-S 5k\-6m \-p 90
+.sp
.RE
-.TP
Look for deleted files altered in the last two days
-.RS 4
-.TP
+.RS
+.sp
.B ntfsundelete /dev/hda1 \-t 2d
+.sp
.RE
-.TP
-Undelete inode number 3689, call the file 'work.doc' and put it in the user's home directory.
-.RS 4
-.TP
+Undelete inode number 3689, call the file 'work.doc' and put it in the user's
+home directory.
+.RS
+.sp
.B ntfsundelete /dev/hda1 \-u 3689 \-o work.doc \-d ~
+.sp
.RE
-.TP
Save MFT Records 3689 to 3690 to a file 'debug'
-.RS 4
-.TP
+.RS
+.sp
.B ntfsundelete /dev/hda1 \-c 3689\-3690 \-o debug
+.RE
.SH BUGS
There are some small limitations to this program, but currently no known bugs.
-If you find one, please email the author and let him know.
+If you find one, please send an email to
+.nh
+<lin...@li...>
+.hy
.SH AUTHOR
.B ntfsundelete
was written by Richard Russon (FlatCap) <nt...@fl...>
.br
-If you find this tool useful, please send him an email :\-)
+If you find this tool useful, make FlatCap happy and send him an email.
.SH AVAILABILITY
.B ntfsundelete
Index: ntfsundelete.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsundelete.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -U2 -r1.17 -r1.18
--- ntfsundelete.c 17 Jul 2002 12:27:27 -0000 1.17
+++ ntfsundelete.c 17 Jul 2002 23:36:31 -0000 1.18
@@ -50,4 +50,6 @@
#include "disk_io.h"
+#include <dmalloc.h>
+
static const char *AUTHOR = "Richard Russon (FlatCap)";
static const char *EXEC_NAME = "ntfsundelete";
@@ -164,5 +166,5 @@
" -h --help Print this help\n\n",
EXEC_NAME);
- Iprintf ("Please report bugs to: lin...@li...\n\n");
+ Iprintf ("Please report bugs to: lin...@li...\n\n");
}
@@ -353,8 +355,9 @@
}
- if (strlen (suffix) > 1) {
+
+ /*if (strlen (suffix) > 1) {
Eprintf ("Invalid size suffix '%s'. Use T, G, M, or K.\n", suffix);
return 0;
- }
+ } Can't do this because of ranges*/
switch (suffix[0]) {
@@ -680,5 +683,6 @@
struct filename *f = list_entry (item, struct filename, list);
Dprintf ("freeing filename '%s'\n", f->name ? f->name : NONE);
- free (f->name);
+ if (f->name)
+ free (f->name);
free (f);
}
@@ -687,8 +691,12 @@
struct data *d = list_entry (item, struct data, list);
Dprintf ("freeing data stream '%s'\n", d->name ? d->name : UNNAMED);
- free (d->name);
- free (d->run_list);
+ if (d->name)
+ free (d->name);
+ if (d->run_list)
+ free (d->run_list);
free (d);
}
+
+ free (file);
}
@@ -785,5 +793,6 @@
* object.
*
- * XXX pref_name
+ * One of the filenames is picked (the one with the lowest numbered namespace)
+ * and its locale friendly name is put in pref_name.
*
* Return: n The number of $FILENAME attributes found
@@ -1328,5 +1337,5 @@
int percent = 0;
- char flagd = '.', flagr = '.', flagc = '.', flage = '.', flagx = '.';
+ char flagd = '.', flagr = '.', flagc = '.', flagx = '.';
strftime (buffer, sizeof (buffer), "%F", localtime (&file->date));
@@ -1346,6 +1355,6 @@
if (d->resident) flagr = 'R';
else flagr = 'N';
- if (d->compressed) flagc = 'C';
- if (d->encrypted) flage = 'E';
+ if (d->compressed) flagc = 'C'; /* These two are mutually exclusive */
+ if (d->encrypted) flagc = 'E';
percent = max (percent, d->percent);
@@ -1361,6 +1370,6 @@
name = NONE;
- Iprintf ("%-8lld %c%c%c%c%c %3d%% %s %9lld %s\n",
- file->inode, flagd, flagr, flagc, flage, flagx,
+ Iprintf ("%-8lld %c%c%c%c %3d%% %s %9lld %s\n",
+ file->inode, flagd, flagr, flagc, flagx,
percent, buffer, size, name);
}
@@ -1405,4 +1414,83 @@
/**
+ * write_data - Write out a block of data
+ * @fd: File descriptor to write to
+ * @buffer: Data to write
+ * @bufsize: Amount of data to write
+ *
+ * Write a block of data to a file descriptor.
+ *
+ * Return: -1 Error, something went wrong
+ * 0 Success, all the data was written
+ */
+int write_data (int fd, const char *buffer, int bufsize)
+{
+ ssize_t result1, result2;
+
+ if (!buffer) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ result1 = write (fd, buffer, bufsize);
+ if ((result1 == bufsize) || (result1 < 0))
+ return result1;
+
+ /* Try again with the rest of the buffer */
+ buffer += result1;
+ bufsize -= result1;
+
+ result2 = write (fd, buffer, bufsize);
+ if (result2 < 0)
+ return result1;
+
+ return result1 + result2;
+}
+
+/**
+ * open_file - Create a file based on the dir, name and stream supplied
+ * @dir: Directory in which to create the file (optional)
+ * @name: Filename to give the file (optional)
+ * @stream: Name of the stream (optional)
+ *
+ * Create a file and return the file descriptor. All the components are
+ * optional. If the name is missing, "unknown" will be used. If the directory
+ * is missing the file will be created in the current directory. If the stream
+ * name is present it will be appended to the filename, delimited by a colon.
+ *
+ * Return: -1 Error, failed to create the file
+ * n Success, this is the file descriptor
+ */
+int open_file (const char *dir, const char *name, const char *stream)
+{
+ char buf[256];
+ int flags;
+
+ if (!name)
+ name = UNKNOWN;
+
+ if (dir)
+ if (stream)
+ snprintf (buf, sizeof (buf), "%s/%s:%s", dir, name, stream);
+ else
+ snprintf (buf, sizeof (buf), "%s/%s", dir, name);
+ else
+ if (stream)
+ snprintf (buf, sizeof (buf), "%s:%s", name, stream);
+ else
+ snprintf (buf, sizeof (buf), "%s", name);
+
+ Vprintf ("Creating file: %s\n", buf);
+
+ if (opts.force)
+ flags = O_RDWR | O_CREAT | O_TRUNC;
+ else
+ flags = O_RDWR | O_CREAT | O_EXCL;
+
+ return open (buf, flags, S_IRUSR | S_IWUSR);
+}
+
+
+/**
* scan_disk - Search an NTFS volume for files that could be undeleted
* @vol: An ntfs volume obtained from ntfs_mount
@@ -1480,11 +1568,11 @@
if ((opts.since > 0) && (file->date <= opts.since))
- continue;
+ goto skip;
if (opts.match && !name_match (&re, file))
- continue;
+ goto skip;
if (opts.size_begin && (opts.size_begin > file->max_size))
- continue;
+ goto skip;
if (opts.size_end && (opts.size_end < file->max_size))
- continue;
+ goto skip;
percent = calc_percentage (file, vol);
@@ -1501,5 +1589,5 @@
results++;
}
-
+skip:
free_file (file);
}
@@ -1518,76 +1606,4 @@
/**
- * write_data - Write out a block of data
- * @fd: File descriptor to write to
- * @buffer: Data to write
- * @bufsize: Amount of data to write
- *
- * Write a block of data to a file descriptor.
- *
- * Return: -1 Error, something went wrong
- * 0 Success, all the data was written
- */
-int write_data (int fd, const char *buffer, int bufsize)
-{
- ssize_t result1, result2;
-
- if (!buffer) {
- errno = EINVAL;
- return -1;
- }
-
- result1 = write (fd, buffer, bufsize);
- if ((result1 == bufsize) || (result1 < 0))
- return result1;
-
- /* Try again with the rest of the buffer */
- buffer += result1;
- bufsize -= result1;
-
- result2 = write (fd, buffer, bufsize);
- if (result2 < 0)
- return result1;
-
- return result1 + result2;
-}
-
-/**
- * open_file - Create a file based on the dir, name and stream supplied
- * @dir: Directory in which to create the file (optional)
- * @name: Filename to give the file (optional)
- * @stream: Name of the stream (optional)
- *
- * Create a file and return the file descriptor. All the components are
- * optional. If the name is missing, "unknown" will be used. If the directory
- * is missing the file will be created in the current directory. If the stream
- * name is present it will be appended to the filename, delimited by a colon.
- *
- * Return: -1 Error, failed to create the file
- * n Success, this is the file descriptor
- */
-int open_file (const char *dir, const char *name, const char *stream)
-{
- char buf[256];
-
- if (!name)
- name = UNKNOWN;
-
- if (dir)
- if (stream)
- snprintf (buf, sizeof (buf), "%s/%s:%s", dir, name, stream);
- else
- snprintf (buf, sizeof (buf), "%s/%s", dir, name);
- else
- if (stream)
- snprintf (buf, sizeof (buf), "%s:%s", name, stream);
- else
- snprintf (buf, sizeof (buf), "%s", name);
-
- Vprintf ("Creating file: %s\n", buf);
-
- return open (buf, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
-}
-
-/**
* undelete_file - Recover a deleted file from an NTFS volume
* @vol: An ntfs volume obtained from ntfs_mount
@@ -1613,5 +1629,5 @@
int undelete_file (ntfs_volume *vol, long long inode)
{
- char buffer[1024]; // XXX hard-coded to the size of an MFT record
+ char *buffer = NULL;
struct ufile *file;
int i, j;
@@ -1621,4 +1637,8 @@
int fd = -1;
long long k;
+ int result = 0;
+
+ if (!vol)
+ return 0;
file = read_record (vol, inode);
@@ -1628,4 +1648,8 @@
}
+ buffer = malloc (vol->mft_record_size);
+ if (!buffer)
+ goto free;
+
if (opts.verbose) {
dump_record (file);
@@ -1639,6 +1663,8 @@
if (file->mft->flags & MFT_RECORD_IN_USE) {
Eprintf ("Record is in use by the mft\n");
- if (!opts.force)
+ if (!opts.force) {
+ free_file (file);
return 0;
+ }
Vprintf ("Forced to continue.\n");
}
@@ -1646,10 +1672,10 @@
if (calc_percentage (file, vol) == 0) {
Iprintf ("File has no recoverable data.\n");
- return 0;
+ goto free;
}
if (list_empty (&file->data)) {
Iprintf ("File has no data. There is nothing to recover.\n");
- return 0;
+ goto free;
}
@@ -1661,5 +1687,5 @@
if (fd < 0) {
Eprintf ("Couldn't create file: %s\n", strerror (errno));
- return 0;
+ goto free;
}
@@ -1668,5 +1694,5 @@
Eprintf ("Write failed: %s\n", strerror (errno));
close (fd);
- return 0;
+ goto free;
}
@@ -1690,5 +1716,5 @@
if (fd < 0) {
Eprintf ("Couldn't create output file: %s\n", strerror (errno));
- return 0;
+ goto free;
}
@@ -1700,5 +1726,5 @@
Eprintf ("Write failed: %s\n", strerror (errno));
close (fd);
- return 0;
+ goto free;
}
}
@@ -1714,5 +1740,5 @@
Eprintf ("Write failed: %s\n", strerror (errno));
close (fd);
- return 0;
+ goto free;
}
}
@@ -1727,5 +1753,5 @@
Eprintf ("Write failed: %s\n", strerror (errno));
close (fd);
- return 0;
+ goto free;
}
}
@@ -1742,5 +1768,5 @@
Eprintf ("Write failed: %s\n", strerror (errno));
close (fd);
- return 0;
+ goto free;
}
} else {
@@ -1748,10 +1774,10 @@
Eprintf ("Read failed: %s\n", strerror (errno));
close (fd);
- return 0;
+ goto free;
}
if (write_data (fd, buffer, sizeof (buffer)) < sizeof (buffer)) {
Eprintf ("Write failed: %s\n", strerror (errno));
close (fd);
- return 0;
+ goto free;
}
}
@@ -1765,8 +1791,15 @@
}
+ if (d->name)
+ Iprintf ("Undeleted '%s:%s' successfully.\n", file->pref_name, d->name);
+ else
+ Iprintf ("Undeleted '%s' successfully.\n", file->pref_name);
}
-
+ result = 1;
+free:
+ if (buffer)
+ free (buffer);
free_file (file);
- return 0;
+ return result;
}
@@ -1852,5 +1885,4 @@
return result;
}
-
/**
|