Description: provides source code enhancements and add the -i option.
             (Closes: #789806, LP: #1067817)
Author: doug Springer <gpib@rickyrockrat.net>
Reviewed-by: Joao Eriberto Mota Filho <eriberto@debian.org>
Last-Update: 2015-06-24
Index: scrounge-ntfs-0.9/src/compat.h
===================================================================
--- scrounge-ntfs-0.9.orig/src/compat.h
+++ scrounge-ntfs-0.9/src/compat.h
@@ -158,7 +158,10 @@ typedef unsigned int uint;
     #endif
   #endif
 #endif
-  
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
Index: scrounge-ntfs-0.9/src/drive.h
===================================================================
--- scrounge-ntfs-0.9.orig/src/drive.h
+++ scrounge-ntfs-0.9/src/drive.h
@@ -34,6 +34,7 @@
 struct _ntfsx_mftmap;
 struct _drivelocks;
 
+#define OP_FLAG_IGNORE 0x0001  /**Do not copy files that already exist in output.  */
 typedef struct _partitioninfo
 {
 	uint32 first;		/* The first sector (in sectors) */
@@ -41,6 +42,9 @@ typedef struct _partitioninfo
 	uint32 mft;			/* Offset into the MFT (in sectors) */
 	byte cluster;		/* Cluster size (in sectors) */
   int device;     /* A handle to an open device */
+	uint32 flags;		/**flags for operation. Ignore, for one  */
+	char *logfile;	/**Log file for err_set_file */
+	void *fp;       /**FILE * for filename, above  */
 
   /* Some other context stuff about the drive */
   struct _drivelocks* locks;
Index: scrounge-ntfs-0.9/src/main.c
===================================================================
--- scrounge-ntfs-0.9.orig/src/main.c
+++ scrounge-ntfs-0.9/src/main.c
@@ -21,48 +21,6 @@
 #include "scrounge.h"
 #include "compat.h"
 
-#ifdef _WIN32
-
-const char kPrintHelp[]       = "\
-usage: scrounge-ntfs -l                                                   \n\
-  List all drive partition information.                              \n\
-                                                                     \n\
-usage: scrounge-ntfs [-d drive] -s                                        \n\
-  Search drive for NTFS partitions.                                  \n\
-                                                                     \n\
-usage: scrounge-ntfs [-d drive] [-m mftoffset] [-c clustersize] [-o outdir] start end  \n\
-  Scrounge data from a partition                                     \n\
-  -d         Drive number                                            \n\
-  -m         Offset to mft (in sectors)                              \n\
-  -c         Cluster size (in sectors, default of 8)                 \n\
-  -o         Directory to put scrounged files in                     \n\
-  start      First sector of partition                               \n\
-  end        Last sector of partition                                \n\
-                                                                     \n\
-";
-
-#else /* Not WIN32 */
-
-const char kPrintHelp[]       = "\
-usage: scrounge-ntfs -l disk                                              \n\
-  List all drive partition information.                              \n\
-                                                                     \n\
-usage: scrounge-ntfs -s disk                                              \n\
-  Search drive for NTFS partitions.                                  \n\
-                                                                     \n\
-usage: scrounge-ntfs [-m mftoffset] [-c clustersize] [-o outdir] disk start end  \n\
-  Scrounge data from a partition                                     \n\
-  -m         Offset to mft (in sectors)                              \n\
-  -c         Cluster size (in sectors, default of 8)                 \n\
-  -o         Directory to put scrounged files in                     \n\
-  disk       The raw disk partitios (ie: /dev/hda)                   \n\
-  start      First sector of partition                               \n\
-  end        Last sector of partition                                \n\
-                                                                     \n\
-";
-
-#endif
-
 #define MODE_SCROUNGE 1
 #define MODE_LIST     2
 #define MODE_SEARCH   3 
@@ -82,6 +40,7 @@ int main(int argc, char* argv[])
   int raw = 0;
   partitioninfo pi;
   char driveName[MAX_PATH + 1];
+	FILE *f=NULL;
 #ifdef _WIN32
   int drive = 0;
 #endif
@@ -91,11 +50,7 @@ int main(int argc, char* argv[])
   /* TODO: We need to be able to autodetect the cluster size */
   pi.cluster = 8;
 
-#ifdef _WIN32
-  while((ch = getopt(argc, argv, "c:d:hlm:o:sv")) != -1)
-#else
-  while((ch = getopt(argc, argv, "c:hlm:o:sv")) != -1)
-#endif
+  while((ch = getopt(argc, argv, "c:d:e:hilm:o:sv")) != -1)
   {
     switch(ch)
     {
@@ -114,9 +69,9 @@ int main(int argc, char* argv[])
       }
       break;
 
-#ifdef _WIN32
     /* drive number */
     case 'd':
+#ifdef _WIN32
       {
         temp = atol(optarg);
 
@@ -126,8 +81,19 @@ int main(int argc, char* argv[])
 
         drive = temp;
       }
-      break;
-#endif
+#else
+			strncpy(driveName, optarg, MAX_PATH);
+  		driveName[MAX_PATH] = 0;
+#endif
+      break;
+    /* Log file  */
+		case 'e':
+			pi.logfile=strdup(optarg);
+			break;
+		/* ignore files that already exist in output  */
+		case 'i':
+			pi.flags|=OP_FLAG_IGNORE;
+			break;
 
     /* list mode */
     case 'l':
@@ -193,17 +159,6 @@ int main(int argc, char* argv[])
 #ifdef _WIN32
   /* Under windows we format the drive number */
   makeDriveName(driveName, drive);
-
-#else
-  /* Now when not under Windows, it's the drive name */
-  if(argc < 1)
-    errx(2, "must specify drive name");
-
-  strncpy(driveName, argv[0], MAX_PATH);
-  driveName[MAX_PATH] = 0;
-
-  argv++;
-  argc--;
 #endif
 
 
@@ -271,6 +226,36 @@ int main(int argc, char* argv[])
 
 void usage()
 {
-  fprintf(stderr, "%s", kPrintHelp);
+#ifdef _WIN32
+#define D_OPT "drive"
+#define D_DESC "Drive number"
+	fprintf(stderr,"\
+usage: scrounge-ntfs -l                                                   \n\
+  List all drive partition information.                              \n\
+                                                                     \n\
+usage: scrounge-ntfs [-d drive] -s                                        \n\
+  Search drive for NTFS partitions.                                  \n"
+#else /* Not WIN32 */
+#define D_OPT "disk"
+#define D_DESC "The raw disk partitios (ie: /dev/hda)"
+		fprintf(stderr,"\
+usage: scrounge-ntfs -l -d disk                                           \n\
+  List all drive partition information.                              \n\
+                                                                     \n\
+usage: scrounge-ntfs -s -d disk                                           \n\
+  Search drive for NTFS partitions.                                  \n"
+#endif
+"usage: scrounge-ntfs [-d %s] [-m mftoffset] [-c clustersize] [-o outdir] [-e errfile] [-i]  start end  \n\
+Scrounge data from a partition                                       \n\
+  -d         %s                                                      \n\
+  -m         Offset to mft (in sectors)                              \n\
+  -c         Cluster size (in sectors, default of 8)                 \n\
+  -l         List sectors/MFT                                        \n\
+  -o         Directory to put scrounged files in                     \n\
+  -i         Ignore files that exist in output                       \n\
+  start      First sector of partition                               \n\
+  end        Last sector of partition                                \n\
+                                                                     \n\
+",D_OPT,D_DESC);
   exit(2);
 }
Index: scrounge-ntfs-0.9/src/scrounge.c
===================================================================
--- scrounge-ntfs-0.9.orig/src/scrounge.c
+++ scrounge-ntfs-0.9/src/scrounge.c
@@ -202,8 +202,7 @@ void processMFTRecord(partitioninfo* pi,
       }
     }
 
-    printf(flags & PROCESS_MFT_FLAG_SUB ? 
-            "\\" FC_PRINTF : "\\" FC_PRINTF "\n", basics.filename);
++	  printf("\\" FC_PRINTF,basics.filename);
 
     /* Directory handling: */
     if(header->flags & kNTFS_RecFlagDir)
@@ -251,6 +250,13 @@ void processMFTRecord(partitioninfo* pi,
     else
 #endif
     {
+			if(pi->flags & OP_FLAG_IGNORE){
+				struct stat buf;
+				if(stat(basics.filename,&buf) == 0) {/* if the file exists, just ignore it  */
+					printf(" - Already exists, Not duplicating.\n");
+					goto cleanup;
+				}	else printf("\n");
+		  }
       ofile = fc_open(basics.filename, O_BINARY | O_CREAT | O_EXCL | O_WRONLY, DEF_FILE_MODE);
   
       fcsncpy(filename2, basics.filename, MAX_PATH);
