summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2011-04-06 09:08:26 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2011-04-06 09:08:26 +0200
commit3babfb3deb5a81213f9b64517e1e7db1cf5f9ce0 (patch)
tree0efc15958222442c7e80c0213a7a1b37366f85f4 /src
parent39b6eb0e154bac7333e88ee68ea7f126a06ab829 (diff)
Support for ntfs-3g_ntfsprogs
Diffstat (limited to 'src')
-rw-r--r--src/ntfs_dir.c22
-rw-r--r--src/ntfs_inc.h2
-rw-r--r--src/ntfs_io.c27
-rw-r--r--src/ntfs_udl.c40
-rw-r--r--src/ntfs_utl.c8
-rw-r--r--src/ntfs_utl.h2
-rw-r--r--src/ntfsp.c7
-rw-r--r--src/pfree_whole.c4
-rw-r--r--src/photorec.c2
9 files changed, 90 insertions, 24 deletions
diff --git a/src/ntfs_dir.c b/src/ntfs_dir.c
index 02e6727..6037512 100644
--- a/src/ntfs_dir.c
+++ b/src/ntfs_dir.c
@@ -63,6 +63,10 @@
#include <ntfs/version.h>
#endif
#endif
+#ifdef HAVE_LIBNTFS3G
+#include <ntfs-3g/volume.h>
+#include <ntfs-3g/attrib.h>
+#endif
#include "common.h"
#include "intrf.h"
@@ -74,7 +78,7 @@
#include "log.h"
#include "setdate.h"
-#ifdef HAVE_LIBNTFS
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
#define MAX_PATH 1024
#define PATH_SEP '/'
#define NTFS_DT_DIR 4
@@ -98,7 +102,7 @@ extern struct ntfs_device_operations ntfs_device_testdisk_io_ops;
extern int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos,
void *dirent, ntfs_filldir_t filldir);
-static time_t ntfs2utc (s64 ntfstime);
+static time_t td_ntfs2utc (s64 ntfstime);
static int ntfs_td_list_entry( struct ntfs_dir_struct *ls, const ntfschar *name,
const int name_len, const int name_type, const s64 pos,
const MFT_REF mref, const unsigned dt_type);
@@ -130,7 +134,7 @@ static int index_get_size(ntfs_inode *inode)
}
/**
- * ntfs2utc - Convert an NTFS time to Unix time
+ * td_ntfs2utc - Convert an NTFS time to Unix time
* @time: An NTFS time in 100ns units since 1601
*
* NTFS stores times as the number of 100ns intervals since January 1st 1601 at
@@ -138,7 +142,7 @@ static int index_get_size(ntfs_inode *inode)
*
* Return: n A Unix time (number of seconds since 1970)
*/
-static time_t ntfs2utc (s64 ntfstime)
+static time_t td_ntfs2utc (s64 ntfstime)
{
return (ntfstime - (NTFS_TIME_OFFSET)) / 10000000;
}
@@ -259,9 +263,9 @@ static int ntfs_td_list_entry( struct ntfs_dir_struct *ls, const ntfschar *name
new_file->stat.st_blocks=(new_file->stat.st_size+new_file->stat.st_blksize-1)/new_file->stat.st_blksize;
}
#endif
- new_file->stat.st_atime=ntfs2utc(sle64_to_cpu(si->last_access_time));
- new_file->stat.st_mtime=ntfs2utc(sle64_to_cpu(si->last_data_change_time));
- new_file->stat.st_ctime=ntfs2utc(sle64_to_cpu(si->creation_time));
+ new_file->stat.st_atime=td_ntfs2utc(sle64_to_cpu(si->last_access_time));
+ new_file->stat.st_mtime=td_ntfs2utc(sle64_to_cpu(si->last_data_change_time));
+ new_file->stat.st_ctime=td_ntfs2utc(sle64_to_cpu(si->creation_time));
new_file->prev=ls->current_file;
new_file->next=NULL;
/* log_debug("fat: new file %s de=%p size=%u\n",new_file->name,de,de->size); */
@@ -420,7 +424,7 @@ static void dir_partition_ntfs_close(dir_data_t *dir_data)
int dir_partition_ntfs_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose)
{
-#ifdef HAVE_LIBNTFS
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
struct ntfs_device *dev;
my_data_t *my_data=NULL;
ntfs_volume *vol=NULL;
@@ -502,6 +506,8 @@ const char*td_ntfs_version(void)
#else
return "available";
#endif
+#elif defined(HAVE_LIBNTFS3G)
+ return "libntfs-3g";
#else
return "none";
#endif
diff --git a/src/ntfs_inc.h b/src/ntfs_inc.h
index 72e720e..177b372 100644
--- a/src/ntfs_inc.h
+++ b/src/ntfs_inc.h
@@ -19,7 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifdef HAVE_LIBNTFS
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
struct ntfs_dir_struct {
file_data_t *dir_list;
file_data_t *current_file;
diff --git a/src/ntfs_io.c b/src/ntfs_io.c
index fb1be2a..96f30af 100644
--- a/src/ntfs_io.c
+++ b/src/ntfs_io.c
@@ -26,7 +26,7 @@
#include <config.h>
#endif
-#ifdef HAVE_LIBNTFS
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
@@ -44,7 +44,12 @@
#include <sys/ioctl.h>
#endif
#include <stdarg.h>
+#ifdef HAVE_LIBNTFS
#include <ntfs/device.h>
+#endif
+#ifdef HAVE_LIBNTFS3G
+#include <ntfs-3g/device.h>
+#endif
#include <stdio.h>
#include "types.h"
#include "common.h"
@@ -117,6 +122,22 @@ static s64 ntfs_device_testdisk_io_write(struct ntfs_device *dev, const void *bu
return count;
}
+static s64 ntfs_device_testdisk_io_pread(struct ntfs_device *dev, void *buf,
+ s64 count, s64 offset)
+{
+ my_data_t *my_data=(my_data_t*)dev->d_private;
+ return my_data->disk_car->pread(my_data->disk_car, buf, count,
+ my_data->partition->part_offset + offset);
+}
+
+static s64 ntfs_device_testdisk_io_pwrite(struct ntfs_device *dev, const void *buf,
+ s64 count, s64 offset)
+{
+ my_data_t *my_data=(my_data_t*)dev->d_private;
+ return my_data->disk_car->pwrite(my_data->disk_car, buf, count,
+ my_data->partition->part_offset + offset);
+}
+
static int ntfs_device_testdisk_io_sync(struct ntfs_device *dev)
{
my_data_t *my_data=(my_data_t*)dev->d_private;
@@ -147,8 +168,8 @@ struct ntfs_device_operations ntfs_device_testdisk_io_ops = {
.seek = ntfs_device_testdisk_io_seek,
.read = ntfs_device_testdisk_io_read,
.write = ntfs_device_testdisk_io_write,
- .pread = NULL,
- .pwrite = NULL,
+ .pread = ntfs_device_testdisk_io_pread,
+ .pwrite = ntfs_device_testdisk_io_pwrite,
.sync = ntfs_device_testdisk_io_sync,
.stat = ntfs_device_testdisk_io_stat,
.ioctl = ntfs_device_testdisk_io_ioctl,
diff --git a/src/ntfs_udl.c b/src/ntfs_udl.c
index 08267ce..1823ba8 100644
--- a/src/ntfs_udl.c
+++ b/src/ntfs_udl.c
@@ -85,6 +85,20 @@
#ifdef HAVE_NTFS_VERSION_H
#include <ntfs/version.h>
#endif
+#endif
+
+#ifdef HAVE_LIBNTFS3G
+#include <ntfs-3g/bootsect.h>
+#include <ntfs-3g/mft.h>
+#include <ntfs-3g/attrib.h>
+#include <ntfs-3g/layout.h>
+#include <ntfs-3g/inode.h>
+#include <ntfs-3g/device.h>
+#include <ntfs-3g/debug.h>
+#include <ntfs-3g/ntfstime.h>
+#endif
+
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
#ifdef HAVE_ICONV_H
#include <iconv.h>
#endif
@@ -151,6 +165,20 @@ struct ufile {
char padding[4]; /* Unused: padding to 64 bit. */
};
+/**
+ * td_ntfs2utc - Convert an NTFS time to Unix time
+ * @time: An NTFS time in 100ns units since 1601
+ *
+ * NTFS stores times as the number of 100ns intervals since January 1st 1601 at
+ * 00:00 UTC. This system will not suffer from Y2K problems until ~57000AD.
+ *
+ * Return: n A Unix time (number of seconds since 1970)
+ */
+static time_t td_ntfs2utc (s64 ntfstime)
+{
+ return (ntfstime - (NTFS_TIME_OFFSET)) / 10000000;
+}
+
static const char *UNKNOWN = "unknown";
static struct options opts;
@@ -227,7 +255,7 @@ static FILE_NAME_ATTR* verify_parent(struct filename* name, MFT_RECORD* rec)
filename_attr = (FILE_NAME_ATTR*)((char*)attr30 + le16_to_cpu(attr30->value_offset));
/* if name is older than this dir -> can't determine */
- if (ntfs2utc(filename_attr->creation_time) > name->date_c) {
+ if (td_ntfs2utc(filename_attr->creation_time) > name->date_c) {
return NULL;
}
if (filename_attr->file_name_type != name->name_space) {
@@ -388,10 +416,10 @@ static int get_filenames(struct ufile *file, ntfs_volume* vol)
name->size_data = sle64_to_cpu(attr->data_size);
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);
+ name->date_c = td_ntfs2utc(attr->creation_time);
+ name->date_a = td_ntfs2utc(attr->last_data_change_time);
+ name->date_m = td_ntfs2utc(attr->last_mft_change_time);
+ name->date_r = td_ntfs2utc(attr->last_access_time);
if (ntfs_ucstombs(name->uname, name->uname_len, &name->name,
0) < 0) {
@@ -557,7 +585,7 @@ static struct ufile * read_record(ntfs_volume *vol, long long record)
if (attr10) {
STANDARD_INFORMATION *si;
si = (STANDARD_INFORMATION *) ((char *) attr10 + le16_to_cpu(attr10->value_offset));
- file->date = ntfs2utc(si->last_data_change_time);
+ file->date = td_ntfs2utc(si->last_data_change_time);
}
if (attr20 || !attr10)
diff --git a/src/ntfs_utl.c b/src/ntfs_utl.c
index 23e7b79..e18848c 100644
--- a/src/ntfs_utl.c
+++ b/src/ntfs_utl.c
@@ -26,7 +26,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
-#ifdef HAVE_LIBNTFS
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
@@ -50,7 +50,13 @@
#include <stdarg.h>
#include "types.h"
+#ifdef HAVE_LIBNTFS
#include <ntfs/attrib.h>
+#endif
+#ifdef HAVE_LIBNTFS3G
+#include <ntfs-3g/attrib.h>
+#endif
+
#include "ntfs_utl.h"
#include "common.h"
#include "log.h"
diff --git a/src/ntfs_utl.h b/src/ntfs_utl.h
index e02a00a..e19c927 100644
--- a/src/ntfs_utl.h
+++ b/src/ntfs_utl.h
@@ -19,7 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifdef HAVE_LIBNTFS
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/src/ntfsp.c b/src/ntfsp.c
index b86310f..199a5d8 100644
--- a/src/ntfsp.c
+++ b/src/ntfsp.c
@@ -39,6 +39,11 @@
#include "filegen.h"
#ifdef HAVE_LIBNTFS
#include <ntfs/attrib.h>
+#endif
+#ifdef HAVE_LIBNTFS3G
+#include <ntfs-3g/attrib.h>
+#endif
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
#include "ntfsp.h"
#endif
#include "intrf.h"
@@ -49,7 +54,7 @@
#include "log.h"
#include "log_part.h"
-#ifdef HAVE_LIBNTFS
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
#define SIZEOF_BUFFER ((const unsigned int)512)
unsigned int ntfs_remove_used_space(disk_t *disk_car,const partition_t *partition, alloc_data_t *list_search_space)
diff --git a/src/pfree_whole.c b/src/pfree_whole.c
index 0c600ea..1e49cbb 100644
--- a/src/pfree_whole.c
+++ b/src/pfree_whole.c
@@ -67,7 +67,7 @@ int ask_mode_ext2(const disk_t *disk_car, const partition_t *partition, unsigned
{'W',"Whole","Extract files from whole partition"},
{0,NULL,NULL}
};
-#ifdef HAVE_LIBNTFS
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
static const struct MenuItem menuNTFS[]=
{
{'F',"Free", "Scan for file from NTFS unallocated space only"},
@@ -128,7 +128,7 @@ int ask_mode_ext2(const disk_t *disk_car, const partition_t *partition, unsigned
else if(partition->upart_type==UP_FAT32)
command = wmenuSelect_ext(window, 23, 8, 0, menuFAT32, 11,
options, MENU_VERT | MENU_VERT_WARN | MENU_BUTTON, &menu,NULL);
-#ifdef HAVE_LIBNTFS
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
else if(partition->upart_type==UP_NTFS)
command = wmenuSelect_ext(window, 23, 8, 0, menuNTFS, 11,
options, MENU_VERT | MENU_VERT_WARN | MENU_BUTTON, &menu,NULL);
diff --git a/src/photorec.c b/src/photorec.c
index 6d2a30f..80ec3a5 100644
--- a/src/photorec.c
+++ b/src/photorec.c
@@ -393,7 +393,7 @@ unsigned int remove_used_space(disk_t *disk_car, const partition_t *partition, a
return fat_remove_used_space(disk_car, partition, list_search_space);
else if(partition->upart_type==UP_EXFAT)
return exfat_remove_used_space(disk_car, partition, list_search_space);
-#ifdef HAVE_LIBNTFS
+#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
else if(partition->upart_type==UP_NTFS)
return ntfs_remove_used_space(disk_car, partition, list_search_space);
#endif