summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2011-03-05 18:59:26 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2011-03-05 18:59:26 +0100
commit1554ea46e8846a4e9e061aa992be36764a6d1117 (patch)
tree9bbc4bd9e827116a77469a8dbf292cb8da782121
parent0718628ebaf1d05961aa804a91a0ecc4cd27a010 (diff)
Fix for HPA and DCO detection (again)
-rw-r--r--src/hdaccess.c3
-rw-r--r--src/hidden.c20
-rw-r--r--src/hiddenn.c11
-rw-r--r--src/hiddenn.h2
-rw-r--r--src/hpa_dco.c12
-rw-r--r--src/pdisksel.c3
-rw-r--r--src/tdisksel.c3
7 files changed, 32 insertions, 22 deletions
diff --git a/src/hdaccess.c b/src/hdaccess.c
index b117e96..8a58b87 100644
--- a/src/hdaccess.c
+++ b/src/hdaccess.c
@@ -1602,9 +1602,6 @@ void init_disk(disk_t *disk)
{
disk->autodetect=0;
disk->disk_size=0;
- disk->user_max=0;
- disk->native_max=0;
- disk->dco=0;
/* Note, some Raid reserve the first 1024 512-sectors */
disk->offset=0;
disk->rbuffer=NULL;
diff --git a/src/hidden.c b/src/hidden.c
index c167005..919ec1f 100644
--- a/src/hidden.c
+++ b/src/hidden.c
@@ -32,18 +32,26 @@
int is_hpa_or_dco(const disk_t *disk)
{
int res=0;
- if(disk->user_max > 0 && disk->user_max < disk->native_max+1)
+ if(disk->native_max> 0 && disk->user_max < disk->native_max+1)
{
- log_warning("%s: Host Protected Area (HPA) present.\n", disk->device);
res=1;
+ if(disk->native_max < disk->dco)
+ res|=2;
}
- if((disk->native_max > 0 && disk->user_max < disk->native_max+1 && disk->native_max < disk->dco) ||
- (disk->user_max > 0 && disk->user_max < disk->dco+1))
+ else if(disk->dco > 0 && disk->user_max < disk->dco+1)
{
- log_warning("%s: Device Configuration Overlay (DCO) present.\n", disk->device);
- res=1;
+ log_info("user_max=%llu dco=%llu\n",
+ (long long unsigned) disk->user_max,
+ (long long unsigned) disk->dco);
+ res|=2;
}
if(res>0)
+ {
+ if(res&1)
+ log_warning("%s: Host Protected Area (HPA) present.\n", disk->device);
+ if(res&2)
+ log_warning("%s: Device Configuration Overlay (DCO) present.\n", disk->device);
log_flush();
+ }
return res;
}
diff --git a/src/hiddenn.c b/src/hiddenn.c
index 5931fc0..066c9fb 100644
--- a/src/hiddenn.c
+++ b/src/hiddenn.c
@@ -34,7 +34,7 @@
#define INTER_DISK_X 0
#define INTER_DISK_Y 18
-int interface_check_hidden_ncurses(disk_t *disk)
+int interface_check_hidden_ncurses(disk_t *disk, const int hpa_dco)
{
static const struct MenuItem menuHidden[]=
{
@@ -69,13 +69,12 @@ int interface_check_hidden_ncurses(disk_t *disk)
wmove(stdscr,line++,0);
wprintw(stdscr, "dco %llu sectors\n", (long long unsigned)(disk->dco+1));
}
- if(disk->user_max > 0 && disk->user_max < disk->native_max+1)
+ if(hpa_dco&1)
{
- wmove(stdscr,line++,0);
- wprintw(stdscr, "Host Protected Area (HPA) present.\n");
+ wmove(stdscr,line++,0);
+ wprintw(stdscr, "Host Protected Area (HPA) present.\n");
}
- if((disk->native_max > 0 && disk->user_max < disk->native_max+1 && disk->native_max < disk->dco) ||
- (disk->user_max > 0 && disk->user_max < disk->dco+1))
+ if(hpa_dco&2)
{
wmove(stdscr,line,0);
wprintw(stdscr, "Device Configuration Overlay (DCO) present.\n");
diff --git a/src/hiddenn.h b/src/hiddenn.h
index 23f8316..5bf1573 100644
--- a/src/hiddenn.h
+++ b/src/hiddenn.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-int interface_check_hidden_ncurses(disk_t *disk);
+int interface_check_hidden_ncurses(disk_t *disk, const int hpa_dco);
#ifdef __cplusplus
} /* closing brace for extern "C" */
diff --git a/src/hpa_dco.c b/src/hpa_dco.c
index c679757..61d4804 100644
--- a/src/hpa_dco.c
+++ b/src/hpa_dco.c
@@ -327,10 +327,13 @@ void disk_get_hpa_dco(const int fd, disk_t *disk)
disk->user_max = (uint64_t) id_val[61] << 16 | id_val[60];
}
disk->dco=sg_device_configuration_identify(fd);
- if((flags & DISK_HAS_48_SUPPORT)!=0)
- disk->native_max=sg_read_native_max_ext(fd);
- else
- disk->native_max=read_native_max(fd);
+ if(flags & DISK_HAS_HPA_SUPPORT)
+ {
+ if((flags & DISK_HAS_48_SUPPORT)!=0)
+ disk->native_max=sg_read_native_max_ext(fd);
+ else
+ disk->native_max=read_native_max(fd);
+ }
if(disk->sector_size!=0)
log_info("%s: size %llu sectors\n", disk->device, (long long unsigned)(disk->disk_real_size/disk->sector_size));
if(disk->user_max!=0)
@@ -341,6 +344,7 @@ void disk_get_hpa_dco(const int fd, disk_t *disk)
log_info("%s: dco %llu sectors\n", disk->device, (long long unsigned)(disk->dco+1));
#endif
}
+
#else
void disk_get_hpa_dco(const int fd, disk_t *disk)
{
diff --git a/src/pdisksel.c b/src/pdisksel.c
index 8e9f20b..ea3da29 100644
--- a/src/pdisksel.c
+++ b/src/pdisksel.c
@@ -265,8 +265,9 @@ static int photorec_disk_selection_ncurses(int verbose, const char *recup_dir, c
case 'O':
{
disk_t *disk=current_disk->disk;
+ const int hpa_dco=is_hpa_or_dco(disk);
autodetect_arch(disk);
- if((!is_hpa_or_dco(disk) || interface_check_hidden_ncurses(disk)==0) &&
+ if((hpa_dco==0 || interface_check_hidden_ncurses(disk, hpa_dco)==0) &&
interface_partition_type(disk, verbose, &current_cmd)==0)
menu_photorec(disk, verbose, recup_dir, file_enable, &current_cmd, list_search_space);
}
diff --git a/src/tdisksel.c b/src/tdisksel.c
index 2cece52..e0e8da4 100644
--- a/src/tdisksel.c
+++ b/src/tdisksel.c
@@ -189,11 +189,12 @@ static int testdisk_disk_selection_ncurses(int verbose,int dump_ind, const list_
case 'O':
{
disk_t *disk=current_disk->disk;
+ const int hpa_dco=is_hpa_or_dco(disk);
autodetect_arch(disk);
autoset_unit(disk);
if(interface_check_disk_capacity(disk)==0 &&
interface_check_disk_access(disk, current_cmd)==0 &&
- (!is_hpa_or_dco(disk) || interface_check_hidden_ncurses(disk)==0) &&
+ (hpa_dco==0 || interface_check_hidden_ncurses(disk, hpa_dco)==0) &&
interface_partition_type(disk, verbose, current_cmd)==0)
{
if(menu_disk(disk, verbose, dump_ind, saveheader, current_cmd))