summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-05-19 16:13:20 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2013-05-19 16:13:20 +0200
commit4699591268012128de457f172963a51ae1c681d6 (patch)
tree6553606fd73ff8b11ea2e17e7d4296548db418a1 /src
parentea952b0cc9d7a732916fc37db13383a0ae31faf7 (diff)
TestDisk, Advanced, List will now always display files or a warning message
Diffstat (limited to 'src')
-rw-r--r--src/dir.h1
-rw-r--r--src/dirpart.c104
-rw-r--r--src/dirpart.h3
-rw-r--r--src/exfat_dir.c8
-rw-r--r--src/exfat_dir.h2
-rw-r--r--src/ext2_dir.c8
-rw-r--r--src/ext2_dir.h2
-rw-r--r--src/fat_dir.c6
-rw-r--r--src/fat_dir.h2
-rw-r--r--src/ntfs_dir.c8
-rw-r--r--src/ntfs_dir.h2
-rw-r--r--src/rfs_dir.c10
-rw-r--r--src/rfs_dir.h2
13 files changed, 80 insertions, 78 deletions
diff --git a/src/dir.h b/src/dir.h
index a21ae1e..2a58c24 100644
--- a/src/dir.h
+++ b/src/dir.h
@@ -38,6 +38,7 @@ extern "C" {
#define CAPA_LIST_DELETED 1
#define CAPA_LIST_ADS 2
+typedef enum { DIR_PART_ENOSYS=-2, DIR_PART_EIO=-1, DIR_PART_OK=0} dir_partition_t;
typedef struct dir_data dir_data_t;
typedef struct
{
diff --git a/src/dirpart.c b/src/dirpart.c
index aa302e7..7dabfa4 100644
--- a/src/dirpart.c
+++ b/src/dirpart.c
@@ -50,58 +50,58 @@
#include "log.h"
#include "log_part.h"
-int dir_partition(disk_t *disk_car, const partition_t *partition, const int verbose, char **current_cmd)
+static dir_partition_t dir_partition_init(disk_t *disk, const partition_t *partition, const int verbose, dir_data_t *dir_data)
{
- dir_data_t dir_data;
-#ifdef HAVE_NCURSES
- WINDOW *window;
-#endif
- int res=-3;
- fflush(stderr);
- dir_data.local_dir=NULL;
+ dir_partition_t res=DIR_PART_ENOSYS;
if(is_part_fat(partition))
- res=dir_partition_fat_init(disk_car,partition,&dir_data,verbose);
+ res=dir_partition_fat_init(disk, partition, dir_data, verbose);
else if(is_part_ntfs(partition))
{
- res=dir_partition_ntfs_init(disk_car,partition,&dir_data,verbose);
- if(res!=0)
- res=dir_partition_exfat_init(disk_car, partition, &dir_data, verbose);
+ res=dir_partition_ntfs_init(disk, partition, dir_data, verbose);
+ if(res!=DIR_PART_OK)
+ res=dir_partition_exfat_init(disk, partition, dir_data, verbose);
}
else if(is_part_linux(partition))
{
- res=dir_partition_ext2_init(disk_car,partition,&dir_data,verbose);
- if(res!=0)
- res=dir_partition_reiser_init(disk_car,partition,&dir_data,verbose);
+ res=dir_partition_ext2_init(disk, partition, dir_data, verbose);
+ if(res!=DIR_PART_OK)
+ res=dir_partition_reiser_init(disk, partition, dir_data, verbose);
}
- if(res!=0)
+ if(res==DIR_PART_OK)
+ return DIR_PART_OK;
+ switch(partition->upart_type)
{
- switch(partition->upart_type)
- {
- case UP_FAT12:
- case UP_FAT16:
- case UP_FAT32:
- res=dir_partition_fat_init(disk_car,partition,&dir_data,verbose);
- break;
- case UP_EXT4:
- case UP_EXT3:
- case UP_EXT2:
- res=dir_partition_ext2_init(disk_car,partition,&dir_data,verbose);
- break;
- case UP_RFS:
- case UP_RFS2:
- case UP_RFS3:
- res=dir_partition_reiser_init(disk_car,partition,&dir_data,verbose);
- break;
- case UP_NTFS:
- res=dir_partition_ntfs_init(disk_car,partition,&dir_data,verbose);
- break;
- case UP_EXFAT:
- res=dir_partition_exfat_init(disk_car, partition, &dir_data, verbose);
- break;
- default:
- return res;
- }
+ case UP_FAT12:
+ case UP_FAT16:
+ case UP_FAT32:
+ return dir_partition_fat_init(disk, partition, dir_data, verbose);
+ case UP_EXT4:
+ case UP_EXT3:
+ case UP_EXT2:
+ return dir_partition_ext2_init(disk, partition, dir_data, verbose);
+ case UP_RFS:
+ case UP_RFS2:
+ case UP_RFS3:
+ return dir_partition_reiser_init(disk, partition, dir_data, verbose);
+ case UP_NTFS:
+ return dir_partition_ntfs_init(disk, partition, dir_data, verbose);
+ case UP_EXFAT:
+ return dir_partition_exfat_init(disk, partition, dir_data, verbose);
+ default:
+ return DIR_PART_ENOSYS;
}
+}
+
+dir_partition_t dir_partition(disk_t *disk, const partition_t *partition, const int verbose, char **current_cmd)
+{
+ dir_data_t dir_data;
+#ifdef HAVE_NCURSES
+ WINDOW *window;
+#endif
+ dir_partition_t res;
+ fflush(stderr);
+ dir_data.local_dir=NULL;
+ res=dir_partition_init(disk, partition, verbose, &dir_data);
#ifdef HAVE_NCURSES
window=newwin(LINES, COLS, 0, 0); /* full screen */
dir_data.display=window;
@@ -112,14 +112,14 @@ int dir_partition(disk_t *disk_car, const partition_t *partition, const int verb
log_info("\n");
switch(res)
{
- case -2:
+ case DIR_PART_ENOSYS:
screen_buffer_reset();
#ifdef HAVE_NCURSES
aff_copy(window);
wmove(window,4,0);
- aff_part(window,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition);
+ aff_part(window,AFF_PART_ORDER|AFF_PART_STATUS,disk,partition);
#endif
- log_partition(disk_car,partition);
+ log_partition(disk,partition);
screen_buffer_add("Support for this filesystem hasn't been enable during compilation.\n");
screen_buffer_to_log();
if(*current_cmd==NULL)
@@ -129,14 +129,14 @@ int dir_partition(disk_t *disk_car, const partition_t *partition, const int verb
#endif
}
break;
- case -1:
+ case DIR_PART_EIO:
screen_buffer_reset();
#ifdef HAVE_NCURSES
aff_copy(window);
wmove(window,4,0);
- aff_part(window,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition);
+ aff_part(window,AFF_PART_ORDER|AFF_PART_STATUS,disk,partition);
#endif
- log_partition(disk_car,partition);
+ log_partition(disk,partition);
screen_buffer_add("Can't open filesystem. Filesystem seems damaged.\n");
screen_buffer_to_log();
if(*current_cmd==NULL)
@@ -146,7 +146,7 @@ int dir_partition(disk_t *disk_car, const partition_t *partition, const int verb
#endif
}
break;
- default:
+ case DIR_PART_OK:
{
int recursive=0;
if(*current_cmd!=NULL)
@@ -172,18 +172,18 @@ int dir_partition(disk_t *disk_car, const partition_t *partition, const int verb
} while(do_continue==1);
}
if(recursive>0)
- dir_whole_partition_log(disk_car,partition,&dir_data,dir_data.current_inode);
+ dir_whole_partition_log(disk,partition,&dir_data,dir_data.current_inode);
else
{
#ifdef HAVE_NCURSES
- dir_partition_aff(disk_car, partition, &dir_data, dir_data.current_inode, current_cmd);
+ dir_partition_aff(disk, partition, &dir_data, dir_data.current_inode, current_cmd);
#else
{
file_info_t dir_list = {
.list = TD_LIST_HEAD_INIT(dir_list.list),
.name = NULL
};
- dir_data.get_dir(disk_car, partition, &dir_data, dir_data.current_inode, &dir_list);
+ dir_data.get_dir(disk, partition, &dir_data, dir_data.current_inode, &dir_list);
dir_aff_log(&dir_data, &dir_list);
delete_list_file(&dir_list);
}
diff --git a/src/dirpart.h b/src/dirpart.h
index 38445c6..f78573c 100644
--- a/src/dirpart.h
+++ b/src/dirpart.h
@@ -22,7 +22,8 @@
#ifdef __cplusplus
extern "C" {
#endif
-int dir_partition(disk_t *disk_car, const partition_t *partition, const int verbose, char **current_cmd);
+#include "dir.h"
+dir_partition_t dir_partition(disk_t *disk_car, const partition_t *partition, const int verbose, char **current_cmd);
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/exfat_dir.c b/src/exfat_dir.c
index e012f08..a4fee56 100644
--- a/src/exfat_dir.c
+++ b/src/exfat_dir.c
@@ -228,7 +228,7 @@ static int exfat_dir(disk_t *disk, const partition_t *partition, dir_data_t *dir
return 0;
}
-int dir_partition_exfat_init(disk_t *disk, const partition_t *partition, dir_data_t *dir_data, const int verbose)
+dir_partition_t dir_partition_exfat_init(disk_t *disk, const partition_t *partition, dir_data_t *dir_data, const int verbose)
{
static struct exfat_dir_struct *ls;
struct exfat_super_block *exfat_header;
@@ -239,14 +239,14 @@ int dir_partition_exfat_init(disk_t *disk, const partition_t *partition, dir_dat
{
log_error("Can't read exFAT boot sector.\n");
free(exfat_header);
- return -1;
+ return DIR_PART_EIO;
}
if(le16(exfat_header->signature)!=0xAA55 ||
memcmp(exfat_header->oem_id, "EXFAT ", sizeof(exfat_header->oem_id))!=0)
{
log_error("Not an exFAT boot sector.\n");
free(exfat_header);
- return -1;
+ return DIR_PART_EIO;
}
ls=(struct exfat_dir_struct *)MALLOC(sizeof(*ls));
ls->boot_sector=exfat_header;
@@ -266,7 +266,7 @@ int dir_partition_exfat_init(disk_t *disk, const partition_t *partition, dir_dat
dir_data->local_dir=NULL;
dir_data->private_dir_data=ls;
dir_data->get_dir=exfat_dir;
- return 0;
+ return DIR_PART_OK;
}
static void dir_partition_exfat_close(dir_data_t *dir_data)
diff --git a/src/exfat_dir.h b/src/exfat_dir.h
index fd7afff..2e57f39 100644
--- a/src/exfat_dir.h
+++ b/src/exfat_dir.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-int dir_partition_exfat_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose);
+dir_partition_t dir_partition_exfat_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose);
#ifdef __cplusplus
} /* closing brace for extern "C" */
diff --git a/src/ext2_dir.c b/src/ext2_dir.c
index ac15a20..9f48a2d 100644
--- a/src/ext2_dir.c
+++ b/src/ext2_dir.c
@@ -336,7 +336,7 @@ static int ext2_copy(disk_t *disk_car, const partition_t *partition, dir_data_t
}
#endif
-int dir_partition_ext2_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose)
+dir_partition_t dir_partition_ext2_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose)
{
#if defined(HAVE_LIBEXT2FS)
struct ext2_dir_struct *ls=(struct ext2_dir_struct *)MALLOC(sizeof(*ls));
@@ -356,7 +356,7 @@ int dir_partition_ext2_init(disk_t *disk_car, const partition_t *partition, dir_
{
// free(my_data);
free(ls);
- return -1;
+ return DIR_PART_EIO;
}
strncpy(dir_data->current_directory,"/",sizeof(dir_data->current_directory));
dir_data->current_inode=EXT2_ROOT_INO;
@@ -368,9 +368,9 @@ int dir_partition_ext2_init(disk_t *disk_car, const partition_t *partition, dir_
dir_data->close=&dir_partition_ext2_close;
dir_data->local_dir=NULL;
dir_data->private_dir_data=ls;
- return 0;
+ return DIR_PART_OK;
#else
- return -2;
+ return DIR_PART_ENOSYS;
#endif
}
diff --git a/src/ext2_dir.h b/src/ext2_dir.h
index 33258c8..cfb2cf5 100644
--- a/src/ext2_dir.h
+++ b/src/ext2_dir.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-int dir_partition_ext2_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose);
+dir_partition_t dir_partition_ext2_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose);
const char*td_ext2fs_version(void);
#ifdef __cplusplus
diff --git a/src/fat_dir.c b/src/fat_dir.c
index bdd7376..5619e62 100644
--- a/src/fat_dir.c
+++ b/src/fat_dir.c
@@ -439,7 +439,7 @@ static int fat1x_rootdir(disk_t *disk_car, const partition_t *partition, const d
}
-int dir_partition_fat_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose)
+dir_partition_t dir_partition_fat_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose)
{
static unsigned char *buffer;
static struct fat_dir_struct *ls;
@@ -448,7 +448,7 @@ int dir_partition_fat_init(disk_t *disk_car, const partition_t *partition, dir_d
{
log_error("Can't read FAT boot sector.\n");
free(buffer);
- return -1;
+ return DIR_PART_EIO;
}
set_secwest();
ls=(struct fat_dir_struct *)MALLOC(sizeof(*ls));
@@ -467,7 +467,7 @@ int dir_partition_fat_init(disk_t *disk_car, const partition_t *partition, dir_d
dir_data->local_dir=NULL;
dir_data->private_dir_data=ls;
dir_data->get_dir=fat_dir;
- return 0;
+ return DIR_PART_OK;
}
static void dir_partition_fat_close(dir_data_t *dir_data)
diff --git a/src/fat_dir.h b/src/fat_dir.h
index 4b3c384..2e2290e 100644
--- a/src/fat_dir.h
+++ b/src/fat_dir.h
@@ -24,7 +24,7 @@ extern "C" {
#endif
int dir_fat_aux(const unsigned char*buffer, const unsigned int size, const unsigned int cluster_size, const unsigned int param, file_info_t *dir_list);
-int dir_partition_fat_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose);
+dir_partition_t dir_partition_fat_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose);
#ifdef __cplusplus
} /* closing brace for extern "C" */
diff --git a/src/ntfs_dir.c b/src/ntfs_dir.c
index c5e87aa..d416cea 100644
--- a/src/ntfs_dir.c
+++ b/src/ntfs_dir.c
@@ -458,7 +458,7 @@ static void dir_partition_ntfs_close(dir_data_t *dir_data)
}
#endif
-int dir_partition_ntfs_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose)
+dir_partition_t dir_partition_ntfs_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose)
{
#if defined(HAVE_LIBNTFS) || defined(HAVE_LIBNTFS3G)
struct ntfs_device *dev;
@@ -500,7 +500,7 @@ int dir_partition_ntfs_init(disk_t *disk_car, const partition_t *partition, dir_
if (!vol) {
free(my_data);
ntfs_device_free(dev);
- return -1;
+ return DIR_PART_EIO;
}
if (vol->flags & VOLUME_IS_DIRTY) {
log_warning("NTFS Volume is dirty.\n");
@@ -528,9 +528,9 @@ int dir_partition_ntfs_init(disk_t *disk_car, const partition_t *partition, dir_
dir_data->local_dir=NULL;
dir_data->private_dir_data=ls;
}
- return 0;
+ return DIR_PART_OK;
#else
- return -2;
+ return DIR_PART_ENOSYS;
#endif
}
diff --git a/src/ntfs_dir.h b/src/ntfs_dir.h
index 4722724..da888e8 100644
--- a/src/ntfs_dir.h
+++ b/src/ntfs_dir.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-int dir_partition_ntfs_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose);
+dir_partition_t dir_partition_ntfs_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose);
const char*td_ntfs_version(void);
#ifdef __cplusplus
diff --git a/src/rfs_dir.c b/src/rfs_dir.c
index e845717..5207437 100644
--- a/src/rfs_dir.c
+++ b/src/rfs_dir.c
@@ -545,7 +545,7 @@ static int reiser_copy(disk_t *disk_car, const partition_t *partition, dir_data_
}
#endif
-int dir_partition_reiser_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose)
+dir_partition_t dir_partition_reiser_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose)
{
#ifdef HAVE_LIBREISERFS
dal_t *dal;
@@ -564,7 +564,7 @@ int dir_partition_reiser_init(disk_t *disk_car, const partition_t *partition, di
{
log_error("Couldn't open device\n");
free(my_data);
- return -1;
+ return DIR_PART_EIO;
}
/* log_debug("file_open ok\n"); */
@@ -577,7 +577,7 @@ int dir_partition_reiser_init(disk_t *disk_car, const partition_t *partition, di
log_error("Couldn't open reiser filesystem %s\n",dal_error(dal));
/* file_close call free(my_data) */
file_close(dal);
- return -1;
+ return DIR_PART_EIO;
}
/* log_debug("reiserfs_fs_open_fast ok\n"); */
{
@@ -597,9 +597,9 @@ int dir_partition_reiser_init(disk_t *disk_car, const partition_t *partition, di
dir_data->local_dir=NULL;
dir_data->private_dir_data=ls;
}
- return 0;
+ return DIR_PART_OK;
#else
- return -2;
+ return DIR_PART_ENOSYS;
#endif
}
diff --git a/src/rfs_dir.h b/src/rfs_dir.h
index 37455d4..0df0bcd 100644
--- a/src/rfs_dir.h
+++ b/src/rfs_dir.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-int dir_partition_reiser_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose);
+dir_partition_t dir_partition_reiser_init(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const int verbose);
const char*td_reiserfs_version(void);
#ifdef __cplusplus