Changes by: flatcap
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv31192
Modified Files:
ntfsundelete.c ntfsundelete.h
Log Message:
perform some checks on the device we're opening
Index: ntfsundelete.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsundelete.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -U2 -r1.9 -r1.10
--- ntfsundelete.c 14 Jul 2002 14:49:22 -0000 1.9
+++ ntfsundelete.c 14 Jul 2002 15:53:03 -0000 1.10
@@ -89,5 +89,5 @@
" -C --case Case sensitive matching\n"
" -S range --size range Match files of this size\n"
- " -t time --time Last referenced since this time"
+ " -t time --time time Last referenced since this time\n"
"\n"
" -u num --undelete num Undelete inode\n"
@@ -196,6 +196,6 @@
}
- //printf ("now = %d, since = %d\n", time(NULL), result);
- *since = time(NULL) - result;
+ //printf ("now = %d, since = %d\n", time (NULL), result);
+ *since = time (NULL) - result;
return 1;
}
@@ -768,5 +768,5 @@
if (data->resident) {
data->size_data = rec->value_length;
- data->data = ((char*)(rec)) + rec->value_offset;
+ data->data = ((char*) (rec)) + rec->value_offset;
} else {
data->size_alloc = rec->allocated_size;
@@ -1514,4 +1514,57 @@
/**
+ * copy_mft
+ */
+int copy_mft (ntfs_volume *vol)
+{
+ return 0;
+}
+
+
+/**
+ * valid_device
+ */
+int valid_device (const char *name, int force)
+{
+ unsigned long mnt_flags = 0;
+ struct stat st;
+
+ if (stat (name, &st) == -1) {
+ if (errno == ENOENT) {
+ printf ("The device %s doesn't exist\n", name);
+ } else {
+ printf ("Error getting information about %s: %s\n", name, strerror (errno));
+ }
+ return 0;
+ }
+
+ if (!S_ISBLK (st.st_mode)) {
+ printf ("not a block device.\n");
+ if (!force) {
+ printf ("bailing out\n");
+ return 0;
+ }
+ }
+
+ /* Make sure the file system is not mounted. */
+ if (ntfs_check_if_mounted (name, &mnt_flags)) {
+ printf ("Failed to determine whether %s is mounted: %s\n", name, strerror (errno));
+ if (!force) {
+ printf ("bailing out\n");
+ return 0;
+ }
+ } else if (mnt_flags & NTFS_MF_MOUNTED) {
+ //printf ("%s is mounted.\n", name);
+ if (!force) {
+ printf ("Refusing to work with a mounted filesystem.\n");
+ return 0;
+ }
+ //printf ("forced\n");
+ }
+
+ return 1;
+}
+
+/**
* main
*/
@@ -1519,9 +1572,6 @@
{
const char *locale;
-
ntfs_volume *vol;
-
- if (!parse_options (argc, argv))
- return 1;
+ int result = 1;
locale = setlocale (LC_ALL, "");
@@ -1529,17 +1579,38 @@
locale = setlocale (LC_ALL, NULL);
printf ("Failed to set locale, using default '%s'.\n", locale);
+ } else {
+ //printf ("using locale...
+ }
+
+ if (!parse_options (argc, argv))
+ return 1;
+
+ if (!valid_device (opts.device, opts.force)) {
+ return 1;
}
vol = ntfs_mount (opts.device, MS_RDONLY);
+ if (!vol) {
+ printf ("mount failed\n");
+ return 1;
+ }
- if (opts.uinode >= 0)
- undelete_file (vol, opts.uinode);
- else
- scan_disk (vol);
+ switch (opts.mode) {
+ case MODE_SCAN:
+ result = scan_disk (vol);
+ break;
+ case MODE_UNDELETE:
+ result = undelete_file (vol, opts.uinode);
+ break;
+ case MODE_COPY:
+ result = copy_mft (vol);
+ break;
+ default:
+ /* Cannot happen */
+ }
ntfs_umount (vol, FALSE);
- return 0;
+ return result;
}
-
Index: ntfsundelete.h
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsundelete.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -U2 -r1.6 -r1.7
--- ntfsundelete.h 14 Jul 2002 14:49:22 -0000 1.6
+++ ntfsundelete.h 14 Jul 2002 15:53:03 -0000 1.7
@@ -37,5 +37,4 @@
};
-
struct options {
char *device; /* Device/File to work with */
|