summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--configure.ac2
-rw-r--r--src/common.h11
-rw-r--r--src/edit.c6
-rw-r--r--src/ewf.c9
-rw-r--r--src/fat.c19
-rw-r--r--src/fat_adv.c6
-rw-r--r--src/fnctdsk.c62
-rw-r--r--src/geometry.c57
-rw-r--r--src/godmode.c90
-rw-r--r--src/hdaccess.c176
-rw-r--r--src/hdcache.c13
-rw-r--r--src/intrf.c16
-rw-r--r--src/intrface.c3
-rw-r--r--src/msdos.c113
-rw-r--r--src/msdos.h2
-rw-r--r--src/next.c3
-rw-r--r--src/ntfs.c22
-rw-r--r--src/ntfs_adv.c4
-rw-r--r--src/parti386.c124
-rw-r--r--src/partnone.c8
-rw-r--r--src/partsun.c35
-rw-r--r--src/win32.c32
-rw-r--r--src/win32.h2
24 files changed, 448 insertions, 369 deletions
diff --git a/NEWS b/NEWS
index 83d06b2..3880cb7 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,7 @@
Current news
============
+6.11-WIP
+
6.10
TestDisk & PhotoRec 6.10 comes with severals improvements:
- Report disk manufacturer and model under Windows and Linux (Only Linux was
diff --git a/configure.ac b/configure.ac
index 5c3fc86..91dde0e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT([testdisk],[6.10],[grenier@cgsecurity.org])
+AC_INIT([testdisk],[6.11-WIP],[grenier@cgsecurity.org])
TESTDISKDATE="July 2008"
AC_SUBST(TESTDISKDATE)
AC_DEFINE_UNQUOTED([TESTDISKDATE],"$TESTDISKDATE",[Date of release])
diff --git a/src/common.h b/src/common.h
index 65d080a..11e4120 100644
--- a/src/common.h
+++ b/src/common.h
@@ -230,6 +230,13 @@ typedef enum errcode_type errcode_type_t;
typedef struct param_disk_struct disk_t;
typedef struct partition_struct partition_t;
typedef struct CHS_struct CHS_t;
+typedef struct
+{
+ unsigned int cylinders;
+ unsigned int heads_per_cylinder;
+ unsigned int sectors_per_head;
+// unsigned int bytes_per_sector;
+} CHSgeometry_t;
struct CHS_struct
{
@@ -269,7 +276,7 @@ struct arch_fnct_struct
int (*write_part)(disk_t *disk_car, const list_part_t *list_part, const int ro, const int verbose, const int align);
list_part_t *(*init_part_order)(const disk_t *disk_car, list_part_t *list_part);
/* geometry must be initialized to 0,0,0 in get_geometry_from_mbr()*/
- int (*get_geometry_from_mbr)(const unsigned char *buffer, const int verbose, CHS_t *geometry);
+ int (*get_geometry_from_mbr)(const unsigned char *buffer, const int verbose, CHSgeometry_t *geometry);
int (*check_part)(disk_t *disk_car,const int verbose,partition_t *partition, const int saveheader);
int (*write_MBR_code)(disk_t *disk_car);
list_part_t *(*add_partition)(disk_t *disk_car,list_part_t *list_part, const int verbose, char **current_cmd);
@@ -289,7 +296,7 @@ typedef struct arch_fnct_struct arch_fnct_t;
struct param_disk_struct
{
uint64_t disk_size;
- CHS_t CHS; /* logical CHS */
+ CHSgeometry_t geom; /* logical CHS */
int write_used;
int autodetect;
int access_mode;
diff --git a/src/edit.c b/src/edit.c
index 21adbf4..be53ad2 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -149,7 +149,7 @@ static void interface_editor_position(const disk_t *disk_car,uint64_t *lba)
mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of cylinders: ");
if (get_string(response, LINE_LENGTH, def) > 0) {
tmp_val = atoi(response);
- if (tmp_val <= disk_car->CHS.cylinder) {
+ if (tmp_val < disk_car->geom.cylinders) {
position.cylinder = tmp_val;
} else
wprintw(stdscr,"Illegal cylinders value");
@@ -161,7 +161,7 @@ static void interface_editor_position(const disk_t *disk_car,uint64_t *lba)
mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of heads: ");
if (get_string(response, LINE_LENGTH, def) > 0) {
tmp_val = atoi(response);
- if (tmp_val <= disk_car->CHS.head) {
+ if (tmp_val < disk_car->geom.heads_per_cylinder) {
position.head = tmp_val;
} else
wprintw(stdscr,"Illegal heads value");
@@ -173,7 +173,7 @@ static void interface_editor_position(const disk_t *disk_car,uint64_t *lba)
mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of sectors per track: ");
if (get_string(response, LINE_LENGTH, def) > 0) {
tmp_val = atoi(response);
- if (tmp_val > 0 && tmp_val <= disk_car->CHS.sector ) {
+ if (tmp_val > 0 && tmp_val <= disk_car->geom.sectors_per_head ) {
position.sector = tmp_val;
} else
wprintw(stdscr,"Illegal sectors value");
diff --git a/src/ewf.c b/src/ewf.c
index c4498c5..57b6b85 100644
--- a/src/ewf.c
+++ b/src/ewf.c
@@ -149,9 +149,9 @@ disk_t *fewf_init(const char *device, const int verbose, const arch_fnct_t *arch
if(disk_car->sector_size==0)
disk_car->sector_size=DEFAULT_SECTOR_SIZE;
/* Set geometry */
- disk_car->CHS.cylinder=0;
- disk_car->CHS.head=0;
- disk_car->CHS.sector=1;
+ disk_car->geom.cylinders=0;
+ disk_car->geom.heads_per_cylinder=1;
+ disk_car->geom.sectors_per_head=1;
/* Get disk_real_size */
#ifdef LIBEWF_GET_MEDIA_SIZE_HAVE_TWO_ARGUMENTS
{
@@ -178,7 +178,8 @@ static const char *fewf_description(disk_t *disk_car)
char buffer_disk_size[100];
snprintf(disk_car->description_txt, sizeof(disk_car->description_txt),"Image %s - %s - CHS %u %u %u%s",
data->file_name, size_to_unit(disk_car->disk_size,buffer_disk_size),
- disk_car->CHS.cylinder+1, disk_car->CHS.head+1, disk_car->CHS.sector,((data->mode&O_RDWR)==O_RDWR?"":" (RO)"));
+ disk_car->geom.cylinders, disk_car->geom.heads_per_cylinder, disk_car->geom.sectors_per_head,
+ ((data->mode&O_RDWR)==O_RDWR?"":" (RO)"));
return disk_car->description_txt;
}
diff --git a/src/fat.c b/src/fat.c
index b39bf3d..11c0713 100644
--- a/src/fat.c
+++ b/src/fat.c
@@ -761,15 +761,19 @@ int test_FAT(disk_t *disk_car,const struct fat_boot_sector *fat_header, partitio
}
if(fat_header->fats>1)
comp_FAT(disk_car,partition,fat_length,le16(fat_header->reserved));
- if(le16(fat_header->heads)!=disk_car->CHS.head+1)
+ if(le16(fat_header->heads)!=disk_car->geom.heads_per_cylinder)
{
- screen_buffer_add("Warning: Incorrect number of heads/cylinder %u (FAT) != %u (HD)\n",le16(fat_header->heads),disk_car->CHS.head+1);
- log_warning("heads/cylinder %u (FAT) != %u (HD)\n",le16(fat_header->heads),disk_car->CHS.head+1);
+ screen_buffer_add("Warning: Incorrect number of heads/cylinder %u (FAT) != %u (HD)\n",
+ le16(fat_header->heads), disk_car->geom.heads_per_cylinder);
+ log_warning("heads/cylinder %u (FAT) != %u (HD)\n",
+ le16(fat_header->heads), disk_car->geom.heads_per_cylinder);
}
- if(le16(fat_header->secs_track)!=disk_car->CHS.sector)
+ if(le16(fat_header->secs_track)!=disk_car->geom.sectors_per_head)
{
- screen_buffer_add("Warning: Incorrect number of sectors per track %u (FAT) != %u (HD)\n",le16(fat_header->secs_track),disk_car->CHS.sector);
- log_warning("sect/track %u (FAT) != %u (HD)\n",le16(fat_header->secs_track),disk_car->CHS.sector);
+ screen_buffer_add("Warning: Incorrect number of sectors per track %u (FAT) != %u (HD)\n",
+ le16(fat_header->secs_track), disk_car->geom.sectors_per_head);
+ log_warning("sect/track %u (FAT) != %u (HD)\n",
+ le16(fat_header->secs_track), disk_car->geom.sectors_per_head);
}
return 0;
}
@@ -1039,7 +1043,8 @@ int recover_OS2MB(disk_t *disk_car, const struct fat_boot_sector*fat_header, par
{
if(test_OS2MB(disk_car, fat_header, partition, verbose, dump_ind))
return 1;
- partition->part_size=(uint64_t)(disk_car->CHS.head+1) * disk_car->CHS.sector*disk_car->sector_size; /* 1 cylinder */
+ /* 1 cylinder */
+ partition->part_size=(uint64_t)disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size;
partition->part_type_i386=P_OS2MB;
partition->fsname[0]='\0';
partition->info[0]='\0';
diff --git a/src/fat_adv.c b/src/fat_adv.c
index 92944fd..345d901 100644
--- a/src/fat_adv.c
+++ b/src/fat_adv.c
@@ -1068,8 +1068,8 @@ static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, con
fat_header->sector_size[1]=disk_car->sector_size >>8;
fat_header->fats=fats;
fat_header->media=0xF8;
- fat_header->secs_track=le16(disk_car->CHS.sector);
- fat_header->heads=le16(disk_car->CHS.head+1);
+ fat_header->secs_track=le16(disk_car->geom.sectors_per_head);
+ fat_header->heads=le16(disk_car->geom.heads_per_cylinder);
fat_header->marker=le16(0xAA55);
if(!((fat_header->ignored[0]==0xeb&&fat_header->ignored[2]==0x90)||fat_header->ignored[0]==0xe9))
{
@@ -1085,7 +1085,7 @@ static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, con
memcpy(fat_header->system_id,"MSWIN4.1",8);
/* FIXME, need to know where the extended or logical partition start */
if(partition->status==STATUS_LOG)
- fat_header->hidden=le32(disk_car->CHS.sector);
+ fat_header->hidden=le32(disk_car->geom.sectors_per_head);
else
fat_header->hidden=le32((partition->part_offset/disk_car->sector_size));
fat_header->sectors_per_cluster=sectors_per_cluster;
diff --git a/src/fnctdsk.c b/src/fnctdsk.c
index f0185c0..5983d80 100644
--- a/src/fnctdsk.c
+++ b/src/fnctdsk.c
@@ -43,33 +43,44 @@
static unsigned int get_geometry_from_list_part_aux(const disk_t *disk_car, const list_part_t *list_part, const int verbose);
unsigned long int C_H_S2LBA(const disk_t *disk_car,const unsigned int C, const unsigned int H, const unsigned int S)
-{ return ((unsigned long int)C*(disk_car->CHS.head+1)+H)*disk_car->CHS.sector+S-1;
+{
+ return ((unsigned long int)C * disk_car->geom.heads_per_cylinder + H) * disk_car->geom.sectors_per_head + S - 1;
}
uint64_t CHS2offset(const disk_t *disk_car,const CHS_t*CHS)
-{ return (((uint64_t)CHS->cylinder*(disk_car->CHS.head+1)+CHS->head)*disk_car->CHS.sector+CHS->sector-1)*disk_car->sector_size;
+{
+ return (((uint64_t)CHS->cylinder * disk_car->geom.heads_per_cylinder + CHS->head) *
+ disk_car->geom.sectors_per_head + CHS->sector - 1) * disk_car->sector_size;
}
uint64_t C_H_S2offset(const disk_t *disk_car,const unsigned int C, const unsigned int H, const unsigned int S)
-{ return (((uint64_t)C*(disk_car->CHS.head+1)+H)*disk_car->CHS.sector+S-1)*disk_car->sector_size;
+{
+ return (((uint64_t)C * disk_car->geom.heads_per_cylinder + H) *
+ disk_car->geom.sectors_per_head + S - 1) * disk_car->sector_size;
}
unsigned int offset2sector(const disk_t *disk_car, const uint64_t offset)
-{ return ((offset/disk_car->sector_size)%disk_car->CHS.sector)+1; }
+{
+ return ((offset / disk_car->sector_size) % disk_car->geom.sectors_per_head) + 1;
+}
unsigned int offset2head(const disk_t *disk_car, const uint64_t offset)
-{ return ((offset/disk_car->sector_size)/disk_car->CHS.sector)%(disk_car->CHS.head+1); }
+{
+ return ((offset / disk_car->sector_size) / disk_car->geom.sectors_per_head) % disk_car->geom.heads_per_cylinder;
+}
unsigned int offset2cylinder(const disk_t *disk_car, const uint64_t offset)
-{ return ((offset/disk_car->sector_size)/disk_car->CHS.sector)/(disk_car->CHS.head+1); }
+{
+ return ((offset / disk_car->sector_size) / disk_car->geom.sectors_per_head) / disk_car->geom.heads_per_cylinder;
+}
void offset2CHS(const disk_t *disk_car,const uint64_t offset, CHS_t*CHS)
{
uint64_t pos=offset/disk_car->sector_size;
- CHS->sector=(pos%disk_car->CHS.sector)+1;
- pos/=disk_car->CHS.sector;
- CHS->head=pos%(disk_car->CHS.head+1);
- CHS->cylinder=pos/(disk_car->CHS.head+1);
+ CHS->sector=(pos%disk_car->geom.sectors_per_head)+1;
+ pos/=disk_car->geom.sectors_per_head;
+ CHS->head=pos%disk_car->geom.heads_per_cylinder;
+ CHS->cylinder=pos/disk_car->geom.heads_per_cylinder;
}
void dup_CHS(CHS_t * CHS_dst, const CHS_t * CHS_source)
@@ -386,7 +397,7 @@ static unsigned int get_geometry_from_list_part_aux(const disk_t *disk_car, cons
if(start.sector==1 && start.head<=1)
{
nbr++;
- if(end.head==disk_car->CHS.head)
+ if(end.head==disk_car->geom.heads_per_cylinder-1)
{
nbr++;
/* Doesn't check if end.sector==disk_car->CHS.sector */
@@ -395,7 +406,8 @@ static unsigned int get_geometry_from_list_part_aux(const disk_t *disk_car, cons
}
if(nbr>0)
{
- log_info("get_geometry_from_list_part_aux head=%u nbr=%u\n",disk_car->CHS.head+1,nbr);
+ log_info("get_geometry_from_list_part_aux head=%u nbr=%u\n",
+ disk_car->geom.heads_per_cylinder, nbr);
if(verbose>1)
{
for(element=list_part;element!=NULL;element=element->next)
@@ -404,7 +416,7 @@ static unsigned int get_geometry_from_list_part_aux(const disk_t *disk_car, cons
CHS_t end;
offset2CHS(disk_car,element->part->part_offset,&start);
offset2CHS(disk_car,element->part->part_offset+element->part->part_size-1,&end);
- if(start.sector==1 && start.head<=1 && end.head==disk_car->CHS.head)
+ if(start.sector==1 && start.head<=1 && end.head==disk_car->geom.heads_per_cylinder-1)
{
log_partition(disk_car,element->part);
}
@@ -417,25 +429,25 @@ static unsigned int get_geometry_from_list_part_aux(const disk_t *disk_car, cons
unsigned int get_geometry_from_list_part(const disk_t *disk_car, const list_part_t *list_part, const int verbose)
{
const unsigned int head_list[]={8,16,32,64,128,240,255,0};
- unsigned int nbr_max;
- unsigned int nbr;
- unsigned int h_index=0;
- unsigned int head_max=disk_car->CHS.head;
+ unsigned int best_score;
+ unsigned int score;
+ unsigned int i;
+ unsigned int heads_per_cylinder=disk_car->geom.heads_per_cylinder;
disk_t *new_disk_car=(disk_t *)MALLOC(sizeof(*new_disk_car));
memcpy(new_disk_car,disk_car,sizeof(*new_disk_car));
- nbr_max=get_geometry_from_list_part_aux(new_disk_car, list_part, verbose);
- for(h_index=0;head_list[h_index]!=0;h_index++)
+ best_score=get_geometry_from_list_part_aux(new_disk_car, list_part, verbose);
+ for(i=0; head_list[i]!=0; i++)
{
- new_disk_car->CHS.head=head_list[h_index]-1;
- nbr=get_geometry_from_list_part_aux(new_disk_car, list_part, verbose);
- if(nbr>=nbr_max)
+ new_disk_car->geom.heads_per_cylinder=head_list[i];
+ score=get_geometry_from_list_part_aux(new_disk_car, list_part, verbose);
+ if(score >= best_score)
{
- nbr_max=nbr;
- head_max=new_disk_car->CHS.head;
+ best_score=score;
+ heads_per_cylinder=new_disk_car->geom.heads_per_cylinder;
}
}
free(new_disk_car);
- return head_max;
+ return heads_per_cylinder;
}
const char *size_to_unit(uint64_t disk_size, char *buffer)
diff --git a/src/geometry.c b/src/geometry.c
index aa0b766..5017b61 100644
--- a/src/geometry.c
+++ b/src/geometry.c
@@ -42,6 +42,13 @@
#include "log.h"
#include "hdaccess.h"
+static inline void set_cylinders_from_size_up(disk_t *disk_car)
+{
+ disk_car->geom.cylinders=(disk_car->disk_size / disk_car->sector_size +
+ (uint64_t)disk_car->geom.sectors_per_head * disk_car->geom.heads_per_cylinder - 1) /
+ ((uint64_t)disk_car->geom.sectors_per_head * disk_car->geom.heads_per_cylinder);
+}
+
static void change_geometry_cli(disk_t *disk_car, char ** current_cmd)
{
int done = 0;
@@ -61,7 +68,7 @@ static void change_geometry_cli(disk_t *disk_car, char ** current_cmd)
(*current_cmd)++;
if (tmp_val > 0)
{
- disk_car->CHS.cylinder = tmp_val-1;
+ disk_car->geom.cylinders = tmp_val;
cyl_modified=1;
geo_modified=1;
}
@@ -76,12 +83,10 @@ static void change_geometry_cli(disk_t *disk_car, char ** current_cmd)
(*current_cmd)++;
if (tmp_val > 0 && tmp_val <= MAX_HEADS)
{
- disk_car->CHS.head = tmp_val-1;
+ disk_car->geom.heads_per_cylinder = tmp_val;
geo_modified=1;
if(cyl_modified==0)
- { /* Round up */
- disk_car->CHS.cylinder=(((disk_car->disk_size/disk_car->sector_size+disk_car->CHS.head)/(disk_car->CHS.head+1))+disk_car->CHS.sector-1)/disk_car->CHS.sector-1;
- }
+ set_cylinders_from_size_up(disk_car);
}
else
log_error("Illegal heads value\n");
@@ -94,12 +99,10 @@ static void change_geometry_cli(disk_t *disk_car, char ** current_cmd)
(*current_cmd)++;
/* SUN partition can have more than 63 sectors */
if (tmp_val > 0) {
- disk_car->CHS.sector = tmp_val;
+ disk_car->geom.sectors_per_head = tmp_val;
geo_modified=1;
if(cyl_modified==0)
- { /* Round up */
- disk_car->CHS.cylinder=(((disk_car->disk_size/disk_car->sector_size+disk_car->CHS.head)/(disk_car->CHS.head+1))+disk_car->CHS.sector-1)/disk_car->CHS.sector-1;
- }
+ set_cylinders_from_size_up(disk_car);
} else
log_error("Illegal sectors value\n");
}
@@ -115,9 +118,7 @@ static void change_geometry_cli(disk_t *disk_car, char ** current_cmd)
{
disk_car->sector_size = tmp_val;
if(cyl_modified==0)
- { /* Round up */
- disk_car->CHS.cylinder=(((disk_car->disk_size/disk_car->sector_size+disk_car->CHS.head)/(disk_car->CHS.head+1))+disk_car->CHS.sector-1)/disk_car->CHS.sector-1;
- }
+ set_cylinders_from_size_up(disk_car);
}
else
log_error("Illegal sector size\n");
@@ -127,11 +128,11 @@ static void change_geometry_cli(disk_t *disk_car, char ** current_cmd)
done = 1;
}
if(cyl_modified!=0)
- disk_car->disk_size=(uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size;
+ disk_car->disk_size=(uint64_t)disk_car->geom.cylinders*disk_car->geom.heads_per_cylinder*disk_car->geom.sectors_per_head*disk_car->sector_size;
}
if(geo_modified!=0)
{
- disk_car->disk_size=(uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size;
+ disk_car->disk_size=(uint64_t)disk_car->geom.cylinders*disk_car->geom.heads_per_cylinder*disk_car->geom.sectors_per_head*disk_car->sector_size;
#ifdef __APPLE__
/* On MacOSX if HD contains some bad sectors, the disk size may not be correctly detected */
disk_car->disk_real_size=disk_car->disk_size;
@@ -185,12 +186,12 @@ static void change_geometry_ncurses(disk_t *disk_car)
case 'c':
case 'C':
{
- sprintf(def, "%u", disk_car->CHS.cylinder+1);
+ sprintf(def, "%u", disk_car->geom.cylinders);
mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of cylinders: ");
if (get_string(response, LINE_LENGTH, def) > 0) {
tmp_val = atoi(response);
if (tmp_val > 0) {
- disk_car->CHS.cylinder = tmp_val-1;
+ disk_car->geom.cylinders = tmp_val;
cyl_modified=1;
geo_modified=1;
} else
@@ -202,17 +203,15 @@ static void change_geometry_ncurses(disk_t *disk_car)
case 'h':
case 'H':
{
- sprintf(def, "%u", disk_car->CHS.head+1);
+ sprintf(def, "%u", disk_car->geom.heads_per_cylinder);
mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of heads: ");
if (get_string(response, LINE_LENGTH, def) > 0) {
tmp_val = atoi(response);
if (tmp_val > 0 && tmp_val <= MAX_HEADS) {
- disk_car->CHS.head = tmp_val-1;
+ disk_car->geom.heads_per_cylinder = tmp_val;
geo_modified=1;
if(cyl_modified==0)
- { /* Round up */
- disk_car->CHS.cylinder=(((disk_car->disk_size/disk_car->sector_size+disk_car->CHS.head)/(disk_car->CHS.head+1))+disk_car->CHS.sector-1)/disk_car->CHS.sector-1;
- }
+ set_cylinders_from_size_up(disk_car);
} else
wprintw(stdscr,"Illegal heads value");
}
@@ -222,7 +221,7 @@ static void change_geometry_ncurses(disk_t *disk_car)
case 's':
case 'S':
{
- sprintf(def, "%u", disk_car->CHS.sector);
+ sprintf(def, "%u", disk_car->geom.sectors_per_head);
/* FIXME SUN partition can have more than 63 sectors */
mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of sectors per track (1-63): ");
if (get_string(response, LINE_LENGTH, def) > 0)
@@ -230,12 +229,10 @@ static void change_geometry_ncurses(disk_t *disk_car)
tmp_val = atoi(response);
/* TODO Check for the maximum value */
if (tmp_val > 0) {
- disk_car->CHS.sector = tmp_val;
+ disk_car->geom.sectors_per_head = tmp_val;
geo_modified=1;
if(cyl_modified==0)
- { /* Round up */
- disk_car->CHS.cylinder=(((disk_car->disk_size/disk_car->sector_size+disk_car->CHS.head)/(disk_car->CHS.head+1))+disk_car->CHS.sector-1)/disk_car->CHS.sector-1;
- }
+ set_cylinders_from_size_up(disk_car);
} else
wprintw(stdscr,"Illegal sectors value");
}
@@ -255,9 +252,7 @@ static void change_geometry_ncurses(disk_t *disk_car)
if (tmp_val==256 || tmp_val==512 || tmp_val==1024 || tmp_val==2048 || tmp_val==4096 || tmp_val==3*512) {
disk_car->sector_size = tmp_val;
if(cyl_modified==0)
- { /* Round up */
- disk_car->CHS.cylinder=(((disk_car->disk_size/disk_car->sector_size+disk_car->CHS.head)/(disk_car->CHS.head+1))+disk_car->CHS.sector-1)/disk_car->CHS.sector-1;
- }
+ set_cylinders_from_size_up(disk_car);
} else
wprintw(stdscr,"Illegal sector size");
}
@@ -271,11 +266,11 @@ static void change_geometry_ncurses(disk_t *disk_car)
break;
}
if(cyl_modified!=0)
- disk_car->disk_size=(uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size;
+ disk_car->disk_size=(uint64_t)disk_car->geom.cylinders*disk_car->geom.heads_per_cylinder*disk_car->geom.sectors_per_head*disk_car->sector_size;
}
if(geo_modified!=0)
{
- disk_car->disk_size=(uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size;
+ disk_car->disk_size=(uint64_t)disk_car->geom.cylinders*disk_car->geom.heads_per_cylinder*disk_car->geom.sectors_per_head*disk_car->sector_size;
#ifdef __APPLE__
/* On MacOSX if HD contains some bad sectors, the disk size may not be correctly detected */
disk_car->disk_real_size=disk_car->disk_size;
diff --git a/src/godmode.c b/src/godmode.c
index 39120f6..975cbcc 100644
--- a/src/godmode.c
+++ b/src/godmode.c
@@ -76,14 +76,15 @@ static inline void offset2CHS_inline(const disk_t *disk_car,const uint64_t offse
static inline void offset2CHS_inline(const disk_t *disk_car,const uint64_t offset, CHS_t*CHS)
{
uint64_t pos=offset/disk_car->sector_size;
- CHS->sector=(pos%disk_car->CHS.sector)+1;
- pos/=disk_car->CHS.sector;
- CHS->head=pos%(disk_car->CHS.head+1);
- CHS->cylinder=pos/(disk_car->CHS.head+1);
+ CHS->sector=(pos%disk_car->geom.sectors_per_head)+1;
+ pos/=disk_car->geom.sectors_per_head;
+ CHS->head=pos%disk_car->geom.heads_per_cylinder;
+ CHS->cylinder=pos/disk_car->geom.heads_per_cylinder;
}
static inline uint64_t CHS2offset_inline(const disk_t *disk_car,const CHS_t*CHS)
-{ return (((uint64_t)CHS->cylinder*(disk_car->CHS.head+1)+CHS->head)*disk_car->CHS.sector+CHS->sector-1)*disk_car->sector_size;
+{
+ return (((uint64_t)CHS->cylinder*disk_car->geom.heads_per_cylinder+CHS->head)*disk_car->geom.sectors_per_head+CHS->sector-1)*disk_car->sector_size;
}
/* Optimization end */
@@ -304,7 +305,8 @@ static void warning_geometry_ncurses(disk_t *disk_car, const unsigned int recomm
wmove(stdscr,4,0);
wprintw(stdscr,"%s",disk_car->description(disk_car));
wmove(stdscr,6,0);
- wprintw(stdscr,"Warning: the current number of heads per cylinder is %u",disk_car->CHS.head+1);
+ wprintw(stdscr, "Warning: the current number of heads per cylinder is %u",
+ disk_car->geom.heads_per_cylinder);
wmove(stdscr,7,0);
wprintw(stdscr,"but the correct value may be %u.",recommanded_heads_per_cylinder);
wmove(stdscr,8,0);
@@ -387,10 +389,10 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
partition_t *partition;
/* It's not a problem to read a little bit more than necessary */
const uint64_t search_location_max=td_max(disk_car->disk_size +
- (disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size,
+ disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size,
disk_car->disk_real_size);
const uint64_t max_disk_size_for_partition=td_max(disk_car->disk_size,
- (uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size);
+ (uint64_t)disk_car->geom.cylinders*disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size);
partition=partition_new(disk_car->arch);
buffer_disk=(unsigned char*)MALLOC(16*DEFAULT_SECTOR_SIZE);
{
@@ -431,18 +433,18 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
/* 1/[01]/1 CHS x 16 63 */
try_offset_nbr=tab_insert(try_offset, 16 * 63 * disk_car->sector_size, try_offset_nbr);
try_offset_nbr=tab_insert(try_offset, 17 * 63 * disk_car->sector_size, try_offset_nbr);
- try_offset_nbr=tab_insert(try_offset, 16 * disk_car->CHS.sector * disk_car->sector_size, try_offset_nbr);
- try_offset_nbr=tab_insert(try_offset, 17 * disk_car->CHS.sector * disk_car->sector_size, try_offset_nbr);
+ try_offset_nbr=tab_insert(try_offset, 16 * disk_car->geom.sectors_per_head * disk_car->sector_size, try_offset_nbr);
+ try_offset_nbr=tab_insert(try_offset, 17 * disk_car->geom.sectors_per_head * disk_car->sector_size, try_offset_nbr);
/* 1/[01]/1 CHS x 240 63 */
try_offset_nbr=tab_insert(try_offset, 240 * 63 * disk_car->sector_size, try_offset_nbr);
try_offset_nbr=tab_insert(try_offset, 241 * 63 * disk_car->sector_size, try_offset_nbr);
- try_offset_nbr=tab_insert(try_offset, 240 * disk_car->CHS.sector * disk_car->sector_size, try_offset_nbr);
- try_offset_nbr=tab_insert(try_offset, 241 * disk_car->CHS.sector * disk_car->sector_size, try_offset_nbr);
+ try_offset_nbr=tab_insert(try_offset, 240 * disk_car->geom.sectors_per_head * disk_car->sector_size, try_offset_nbr);
+ try_offset_nbr=tab_insert(try_offset, 241 * disk_car->geom.sectors_per_head * disk_car->sector_size, try_offset_nbr);
/* 1/[01]/1 CHS x 255 63 */
try_offset_nbr=tab_insert(try_offset, 255 * 63 * disk_car->sector_size, try_offset_nbr);
try_offset_nbr=tab_insert(try_offset, 256 * 63 * disk_car->sector_size, try_offset_nbr);
- try_offset_nbr=tab_insert(try_offset, 255 * disk_car->CHS.sector * disk_car->sector_size, try_offset_nbr);
- try_offset_nbr=tab_insert(try_offset, 256 * disk_car->CHS.sector * disk_car->sector_size, try_offset_nbr);
+ try_offset_nbr=tab_insert(try_offset, 255 * disk_car->geom.sectors_per_head * disk_car->sector_size, try_offset_nbr);
+ try_offset_nbr=tab_insert(try_offset, 256 * disk_car->geom.sectors_per_head * disk_car->sector_size, try_offset_nbr);
}
else if(disk_car->arch==&arch_mac)
{
@@ -453,8 +455,8 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
}
else if(disk_car->arch==&arch_sun)
{
- min_location=(disk_car->CHS.head+1) * disk_car->CHS.sector * disk_car->sector_size;
- location_boundary=(disk_car->CHS.head+1) * disk_car->CHS.sector * disk_car->sector_size;
+ min_location=disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size;
+ location_boundary=disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size;
}
else if(disk_car->arch==&arch_xbox)
{
@@ -476,12 +478,14 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
static CHS_t start;
offset2CHS_inline(disk_car,search_location,&start);
#ifdef HAVE_NCURSES
- if(old_cylinder!=start.cylinder && interface!=0 && (disk_car->CHS.head!=0 || (start.cylinder & 0xFFF)==0))
+ if(old_cylinder!=start.cylinder && interface!=0 && (disk_car->geom.heads_per_cylinder>0 || (start.cylinder & 0xFFF)==0))
{
old_cylinder=start.cylinder;
wmove(stdscr,ANALYSE_Y,ANALYSE_X);
wclrtoeol(stdscr);
- wprintw(stdscr,"Analyse cylinder %5u/%u: %02u%%",start.cylinder,disk_car->CHS.cylinder,(unsigned int)((uint64_t)start.cylinder*100/(disk_car->CHS.cylinder+1)));
+ wprintw(stdscr,"Analyse cylinder %5u/%u: %02u%%",
+ start.cylinder, disk_car->geom.cylinders-1,
+ (unsigned int)((uint64_t)start.cylinder*100/disk_car->geom.cylinders));
wrefresh(stdscr);
ind_stop|=check_enter_key_or_s(stdscr);
}
@@ -569,7 +573,8 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
if(res<=0 && test_nbr==3)
{
if((disk_car->arch==&arch_i386 &&
- ((start.sector==disk_car->CHS.sector && (start.head==disk_car->CHS.head || fast_mode>1)) ||
+ ((start.sector==disk_car->geom.sectors_per_head &&
+ (start.head==disk_car->geom.heads_per_cylinder-1 || fast_mode>1)) ||
(search_vista_part>0 && search_location%(2048*512)==(2048-1)*512))) ||
(disk_car->arch!=&arch_i386 && search_location%location_boundary==(location_boundary-512) &&
search_location>0))
@@ -579,7 +584,8 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
if(res<=0 && test_nbr==4)
{
if((disk_car->arch==&arch_i386 &&
- ((start.sector==disk_car->CHS.sector && (start.head==disk_car->CHS.head || fast_mode>1)) ||
+ ((start.sector==disk_car->geom.sectors_per_head &&
+ (start.head==disk_car->geom.heads_per_cylinder-1 || fast_mode>1)) ||
(search_vista_part>0 && search_location%(2048*512)==(2048-1)*512))) ||
(disk_car->arch!=&arch_i386 && search_location%location_boundary==(location_boundary-512) &&
search_location>0))
@@ -704,9 +710,9 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
offset2CHS_inline(disk_car,partition->part_offset+partition->part_size-1,&end);
if(align>0)
{
- end.sector=disk_car->CHS.sector;
+ end.sector=disk_car->geom.sectors_per_head;
if(align>1)
- end.head=disk_car->CHS.head;
+ end.head=disk_car->geom.heads_per_cylinder-1;
}
help_factor_max=((uint64_t)CHS2offset_inline(disk_car, &end)-partition->part_offset+disk_car->sector_size-partition->part_size)/MD_RESERVED_BYTES;
if(help_factor_max<3)
@@ -736,7 +742,7 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
}
{
uint64_t next_part_offset=partition->part_offset+partition->part_size-1+1;
- uint64_t head_size=disk_car->CHS.sector*disk_car->sector_size;
+ uint64_t head_size=disk_car->geom.sectors_per_head * disk_car->sector_size;
try_offset_nbr=tab_insert(try_offset,next_part_offset,try_offset_nbr);
try_offset_nbr=tab_insert(try_offset,next_part_offset+head_size,try_offset_nbr);
if(next_part_offset%head_size!=0)
@@ -1062,7 +1068,7 @@ static list_part_t *add_ext_part_i386(disk_t *disk_car, list_part_t *list_part,
offset2CHS_inline(disk_car,deb->prev->part->part_offset+deb->prev->part->part_size-1+1,&start);
start.sector=1;
start.head++;
- if(start.head>=disk_car->CHS.head)
+ if(start.head >= disk_car->geom.heads_per_cylinder)
{
start.cylinder++;
start.head=0;
@@ -1075,25 +1081,25 @@ static list_part_t *add_ext_part_i386(disk_t *disk_car, list_part_t *list_part,
}
if(fin->next==NULL)
{
- end.cylinder=disk_car->CHS.cylinder;
- end.head=disk_car->CHS.head;
- end.sector=disk_car->CHS.sector;
+ end.cylinder=disk_car->geom.cylinders-1;
+ end.head=disk_car->geom.heads_per_cylinder-1;
+ end.sector=disk_car->geom.sectors_per_head;
}
else
{
end.cylinder=offset2cylinder(disk_car,fin->next->part->part_offset)-1; /* 8 october 2002 */
- end.head=disk_car->CHS.head;
- end.sector=disk_car->CHS.sector;
+ end.head=disk_car->geom.heads_per_cylinder-1;
+ end.sector=disk_car->geom.sectors_per_head;
if(CHS2offset_inline(disk_car,&end)<=fin->part->part_offset+fin->part->part_size-1)
{
offset2CHS_inline(disk_car,fin->next->part->part_offset-1,&end);
- end.sector=disk_car->CHS.sector;
+ end.sector=disk_car->geom.sectors_per_head;
if(end.head>0)
end.head--;
else
{
end.cylinder--;
- end.head=disk_car->CHS.head;
+ end.head=disk_car->geom.heads_per_cylinder-1;
}
if(CHS2offset_inline(disk_car,&end)<=fin->part->part_offset+fin->part->part_size-1)
{
@@ -1120,12 +1126,12 @@ static list_part_t *add_ext_part_i386(disk_t *disk_car, list_part_t *list_part,
}
}
offset2CHS_inline(disk_car,fin->part->part_offset+fin->part->part_size-1,&end);
- end.head=disk_car->CHS.head;
- end.sector=disk_car->CHS.sector;
+ end.head=disk_car->geom.heads_per_cylinder-1;
+ end.sector=disk_car->geom.sectors_per_head;
if(fin->next && CHS2offset_inline(disk_car,&end)>=fin->next->part->part_offset)
{
offset2CHS_inline(disk_car,fin->part->part_offset+fin->part->part_size-1,&end);
- end.sector=disk_car->CHS.sector;
+ end.sector=disk_car->geom.sectors_per_head;
}
if(fin->next && CHS2offset_inline(disk_car,&end)>=fin->next->part->part_offset)
{
@@ -1199,16 +1205,16 @@ int interface_recovery(disk_t *disk_car, const list_part_t * list_part_org, cons
list_part=search_part(disk_car, list_part_org, verbose, dump_ind, fast_mode, 1, search_vista_part, current_cmd);
if(list_part!=NULL && (disk_car->arch==&arch_i386 || disk_car->arch==&arch_sun))
{ /* Correct disk geometry is necessary for successfull Intel and Sun partition recovery */
- unsigned int head_max;
- head_max=get_geometry_from_list_part(disk_car, list_part, verbose);
- if(disk_car->CHS.head!=head_max)
+ unsigned int heads_per_cylinder;
+ heads_per_cylinder=get_geometry_from_list_part(disk_car, list_part, verbose);
+ if(disk_car->geom.heads_per_cylinder!=heads_per_cylinder)
{
log_warning("Warning: the current number of heads per cylinder is %u but the correct value may be %u.\n",
- disk_car->CHS.head+1, head_max+1);
+ disk_car->geom.heads_per_cylinder, heads_per_cylinder);
#ifdef HAVE_NCURSES
if(*current_cmd==NULL)
{
- warning_geometry_ncurses(disk_car, head_max+1);
+ warning_geometry_ncurses(disk_car, heads_per_cylinder);
}
#endif
}
@@ -1235,9 +1241,9 @@ int interface_recovery(disk_t *disk_car, const list_part_t * list_part_org, cons
if(align==0)
location_boundary=disk_car->sector_size;
else if(align==1)
- location_boundary=disk_car->CHS.sector * disk_car->sector_size;
+ location_boundary=disk_car->geom.sectors_per_head * disk_car->sector_size;
else
- location_boundary=(disk_car->CHS.head+1) * disk_car->CHS.sector * disk_car->sector_size;
+ location_boundary=disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size;
}
}
else if(disk_car->arch==&arch_mac)
@@ -1246,7 +1252,7 @@ int interface_recovery(disk_t *disk_car, const list_part_t * list_part_org, cons
}
else if(disk_car->arch==&arch_sun)
{
- location_boundary=(disk_car->CHS.head+1) * disk_car->CHS.sector * disk_car->sector_size;
+ location_boundary=disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size;
}
else
{ /* arch_none, arch_xbox, arch_gpt */
diff --git a/src/hdaccess.c b/src/hdaccess.c
index c916e40..fa85709 100644
--- a/src/hdaccess.c
+++ b/src/hdaccess.c
@@ -532,23 +532,24 @@ static unsigned int disk_get_sector_size(const int hd_h, const char *device, con
return DEFAULT_SECTOR_SIZE;
}
-static void disk_get_geometry(CHS_t *CHS, const int hd_h, const char *device, const int verbose)
+static void disk_get_geometry(CHSgeometry_t *geom, const int hd_h, const char *device, const int verbose)
{
if(verbose>1)
log_verbose("disk_get_geometry for %s\n", device);
#ifdef HDIO_GETGEO_BIG
- if(CHS->sector==0)
+ if(geom->sectors_per_head==0)
{
- struct hd_big_geometry geometry_big;
- if (ioctl(hd_h, HDIO_GETGEO_BIG, &geometry_big)>=0)
+ struct hd_big_geometry geometry;
+ if (ioctl(hd_h, HDIO_GETGEO_BIG, &geometry)>=0)
{ /* I can get the geometry */
if(verbose>1)
{
- log_verbose("disk_get_geometry HDIO_GETGEO_BIG %s Ok (%u,%u,%u)\n",device,geometry_big.cylinders,geometry_big.heads,geometry_big.sectors);
+ log_verbose("disk_get_geometry HDIO_GETGEO_BIG %s Ok (%u,%u,%u)\n",
+ device, geometry.cylinders, geometry.heads, geometry.sectors);
}
- CHS->cylinder= geometry_big.cylinders-1;
- CHS->head=geometry_big.heads-1;
- CHS->sector= geometry_big.sectors;
+ geom->cylinders=geometry.cylinders;
+ geom->heads_per_cylinder=geometry.heads;
+ geom->sectors_per_head=geometry.sectors;
}
else
{
@@ -560,29 +561,30 @@ static void disk_get_geometry(CHS_t *CHS, const int hd_h, const char *device, co
}
#endif
#ifdef HDIO_GETGEO
- if(CHS->sector==0)
+ if(geom->sectors_per_head==0)
{
struct hd_geometry geometry;
if(ioctl(hd_h, HDIO_GETGEO, &geometry)>=0)
{ /* I can get the geometry */
if(verbose>1)
{
- log_verbose("disk_get_geometry HDIO_GETGEO %s Ok (%u,%u,%u)\n",device,geometry.cylinders,geometry.heads,geometry.sectors);
+ log_verbose("disk_get_geometry HDIO_GETGEO %s Ok (%u,%u,%u)\n",
+ device, geometry.cylinders, geometry.heads, geometry.sectors);
}
- CHS->cylinder= geometry.cylinders-1;
- CHS->head=geometry.heads-1;
- CHS->sector= geometry.sectors;
+ geom->cylinders=geometry.cylinders;
+ geom->heads_per_cylinder=geometry.heads;
+ geom->sectors_per_head=geometry.sectors;
}
}
#endif
#ifdef DKIOCGGEOM
- if(CHS->sector==0)
+ if(geom->sectors_per_head==0)
{
struct dk_geom dkgeom;
if (ioctl (hd_h, DKIOCGGEOM, &dkgeom)>=0) {
- CHS->cylinder= dkgeom.dkg_ncyl-1;
- CHS->head=dkgeom.dkg_nhead-1;
- CHS->sector=dkgeom.dkg_nsect;
+ geom->cylinders= dkgeom.dkg_ncyl;
+ geom->heads_per_cylinder=dkgeom.dkg_nhead;
+ geom->sectors_per_head=dkgeom.dkg_nsect;
if(verbose>1)
{
log_verbose("disk_get_geometry DKIOCGGEOM %s Ok\n",device);
@@ -591,7 +593,7 @@ static void disk_get_geometry(CHS_t *CHS, const int hd_h, const char *device, co
}
#endif
#ifdef DIOCGDINFO
- if(CHS->sector==0)
+ if(geom->sectors_per_head==0)
{
struct disklabel geometry;
if (ioctl(hd_h, DIOCGDINFO, &geometry)==0)
@@ -600,9 +602,9 @@ static void disk_get_geometry(CHS_t *CHS, const int hd_h, const char *device, co
{
log_verbose("disk_get_geometry DIOCGDINFO %s Ok\n",device);
}
- CHS->cylinder=geometry.d_ncylinders-1;
- CHS->head=geometry.d_ntracks-1;
- CHS->sector=geometry.d_nsectors;
+ geom->cylinders=geometry.d_ncylinders;
+ geom->heads_per_cylinder=geometry.d_ntracks;
+ geom->sectors_per_head=geometry.d_nsectors;
}
else
{
@@ -614,7 +616,7 @@ static void disk_get_geometry(CHS_t *CHS, const int hd_h, const char *device, co
}
#endif
#ifdef DIOCGFWSECTORS
- if(CHS->sector==0)
+ if(geom->sectors_per_head==0)
{
int error;
unsigned int u;
@@ -635,9 +637,9 @@ static void disk_get_geometry(CHS_t *CHS, const int hd_h, const char *device, co
{
log_verbose("disk_get_geometry DIOCGFWHEADS %s Ok\n",device);
}
- CHS->cylinder=0;
- CHS->head=heads-1;
- CHS->sector=sectors;
+ geom->cylinders=0;
+ geom->heads_per_cylinder=heads;
+ geom->sectors_per_head=sectors;
}
}
}
@@ -650,14 +652,14 @@ static void disk_get_geometry(CHS_t *CHS, const int hd_h, const char *device, co
#else
handle=(HANDLE)_get_osfhandle(hd_h);
#endif
- return disk_get_geometry_win32(CHS, handle, device, verbose);
+ return disk_get_geometry_win32(geom, handle, device, verbose);
}
#endif
- if(CHS->sector!=0)
+ if(geom->sectors_per_head>0 && geom->heads_per_cylinder>0)
return ;
- CHS->cylinder=0;
- CHS->head=0;
- CHS->sector=1;
+ geom->cylinders=0;
+ geom->heads_per_cylinder=1;
+ geom->sectors_per_head=1;
if(verbose>1)
{
log_error("disk_get_geometry default geometry for %s\n", device);
@@ -747,28 +749,27 @@ void update_disk_car_fields(disk_t *disk_car)
{
if(disk_car->disk_real_size==0)
{
- if(disk_car->CHS.cylinder>0)
+ if(disk_car->geom.cylinders>0)
{
log_warning("Fix disk size using CHS\n");
- disk_car->disk_real_size=(uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size;
+ disk_car->disk_real_size=(uint64_t)disk_car->geom.cylinders * disk_car->geom.heads_per_cylinder *
+ disk_car->geom.sectors_per_head * disk_car->sector_size;
}
}
else
{
- unsigned int cylinder_num;
- cylinder_num=disk_car->disk_real_size / ((uint64_t)disk_car->CHS.head+1) / (uint64_t)disk_car->CHS.sector/(uint64_t)disk_car->sector_size;
- if(cylinder_num>0 && disk_car->CHS.cylinder+1!= cylinder_num)
+ const unsigned int cylinder_num=disk_car->disk_real_size /
+ (uint64_t)disk_car->geom.heads_per_cylinder /
+ (uint64_t)disk_car->geom.sectors_per_head /
+ (uint64_t)disk_car->sector_size;
+ if(cylinder_num>0 && disk_car->geom.cylinders != cylinder_num)
{
log_debug("Fix cylinder count for %s: number of cylinders %u != %u (calculated)\n",
- disk_car->device, disk_car->CHS.cylinder+1, cylinder_num);
- disk_car->CHS.cylinder= cylinder_num-1;
+ disk_car->device, disk_car->geom.cylinders, cylinder_num);
+ disk_car->geom.cylinders = cylinder_num;
}
}
disk_car->disk_size=disk_car->disk_real_size;
- /*
- disk_car->disk_size=td_max(disk_car->disk_real_size,
- (uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size);
- */
}
#ifdef TARGET_LINUX
@@ -1023,7 +1024,7 @@ static const char *file_description(disk_t *disk_car)
char buffer_disk_size[100];
snprintf(disk_car->description_txt, sizeof(disk_car->description_txt),"Disk %s - %s - CHS %u %u %u%s",
disk_car->device, size_to_unit(disk_car->disk_size,buffer_disk_size),
- disk_car->CHS.cylinder+1, disk_car->CHS.head+1, disk_car->CHS.sector,
+ disk_car->geom.cylinders, disk_car->geom.heads_per_cylinder, disk_car->geom.sectors_per_head,
((data->mode&O_RDWR)==O_RDWR?"":" (RO)"));
return disk_car->description_txt;
}
@@ -1200,29 +1201,27 @@ static void autoset_geometry(disk_t * disk_car, const unsigned char *buffer, con
{
if(disk_car->arch->get_geometry_from_mbr!=NULL)
{
- CHS_t geometry;
- geometry.cylinder=0;
- geometry.head=0;
- geometry.sector=0;
+ CHSgeometry_t geometry;
+ geometry.cylinders=0;
+ geometry.heads_per_cylinder=0;
+ geometry.sectors_per_head=0;
disk_car->arch->get_geometry_from_mbr(buffer, verbose, &geometry);
disk_car->autodetect=1;
- if(geometry.sector>0)
+ if(geometry.sectors_per_head > 0)
{
- disk_car->CHS.head=geometry.head;
- disk_car->CHS.sector=geometry.sector;
+ disk_car->geom.heads_per_cylinder=geometry.heads_per_cylinder;
+ disk_car->geom.sectors_per_head=geometry.sectors_per_head;
}
else
{
- disk_car->CHS.head=255-1;
- disk_car->CHS.sector=63;
+ disk_car->geom.heads_per_cylinder=255;
+ disk_car->geom.sectors_per_head=63;
}
}
/* Round up because file is often truncated. */
- disk_car->CHS.cylinder=(disk_car->disk_size / disk_car->sector_size +
- (uint64_t)disk_car->CHS.sector*(disk_car->CHS.head+1) - 1) /
- disk_car->CHS.sector / (disk_car->CHS.head+1);
- if(disk_car->CHS.cylinder > 0)
- disk_car->CHS.cylinder--;
+ disk_car->geom.cylinders=(disk_car->disk_size / disk_car->sector_size +
+ (uint64_t)disk_car->geom.sectors_per_head * disk_car->geom.heads_per_cylinder - 1) /
+ disk_car->geom.sectors_per_head / disk_car->geom.heads_per_cylinder;
}
disk_t *file_test_availability(const char *device, const int verbose, const arch_fnct_t *arch, int testdisk_mode)
@@ -1376,7 +1375,7 @@ disk_t *file_test_availability(const char *device, const int verbose, const arch
if(verbose>1)
log_info("file_test_availability %s is a device\n", device);
disk_car->sector_size=disk_get_sector_size(hd_h, device, verbose);
- disk_get_geometry(&disk_car->CHS, hd_h, device, verbose);
+ disk_get_geometry(&disk_car->geom, hd_h, device, verbose);
disk_car->disk_real_size=disk_get_size(hd_h, device, verbose, disk_car->sector_size);
#ifdef BLKFLSBUF
/* Little trick from Linux fdisk */
@@ -1405,10 +1404,10 @@ disk_t *file_test_availability(const char *device, const int verbose, const arch
if(memcmp(buffer,"DOSEMU",6)==0 && *(unsigned long*)(buffer+11)>0)
{
log_info("%s DOSEMU\n",device);
- disk_car->CHS.cylinder=*(unsigned long*)(buffer+15)-1;
- disk_car->CHS.head=*(unsigned long*)(buffer+7)-1;
- disk_car->CHS.sector=*(unsigned long*)(buffer+11);
- disk_car->disk_real_size=(uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size;
+ disk_car->geom.cylinders=*(unsigned long*)(buffer+15);
+ disk_car->geom.heads_per_cylinder=*(unsigned long*)(buffer+7);
+ disk_car->geom.sectors_per_head=*(unsigned long*)(buffer+11);
+ disk_car->disk_real_size=(uint64_t)disk_car->geom.cylinders * disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size;
disk_car->offset=*(unsigned long*)(buffer+19);
}
else if(memcmp(buffer, evf_file_signature, 8)==0)
@@ -1427,9 +1426,9 @@ disk_t *file_test_availability(const char *device, const int verbose, const arch
}
else
{
- disk_car->CHS.cylinder=0;
- disk_car->CHS.head=255-1;
- disk_car->CHS.sector=63;
+ disk_car->geom.cylinders=0;
+ disk_car->geom.heads_per_cylinder=255;
+ disk_car->geom.sectors_per_head=63;
if((uint64_t)stat_rec.st_size > disk_car->offset)
{
disk_car->disk_real_size=((uint64_t)stat_rec.st_size-disk_car->offset+disk_car->sector_size-1)/disk_car->sector_size*disk_car->sector_size;
@@ -1465,8 +1464,6 @@ disk_t *file_test_availability(const char *device, const int verbose, const arch
void hd_update_geometry(disk_t *disk_car, const int allow_partial_last_cylinder, const int verbose)
{
unsigned char *buffer;
- uint64_t pos;
- CHS_t pos_CHS;
buffer=(unsigned char *)MALLOC(disk_car->sector_size);
if(disk_car->autodetect!=0)
{
@@ -1479,28 +1476,35 @@ void hd_update_geometry(disk_t *disk_car, const int allow_partial_last_cylinder,
autoset_geometry(disk_car,buffer,1);
}
}
- dup_CHS(&pos_CHS,&disk_car->CHS);
- pos_CHS.cylinder++;
- if(allow_partial_last_cylinder) {
- pos_CHS.head=0;
- pos_CHS.sector=1;
- }
- pos=CHS2offset(disk_car,&pos_CHS);
-#ifdef DJGPP
- if(disk_car->description==disk_description)
+ if((unsigned int)(disk_car->geom.cylinders+1)!=0) /* Avoid to wrap */
{
- struct info_disk_struct*data=disk_car->data;
- data->CHSR.cylinder=0;
- }
+ uint64_t pos;
+ CHS_t pos_CHS;
+ pos_CHS.cylinder=disk_car->geom.cylinders-1+1;
+ if(allow_partial_last_cylinder)
+ {
+ pos_CHS.head=0;
+ pos_CHS.sector=1;
+ }
+ else
+ {
+ pos_CHS.head=disk_car->geom.heads_per_cylinder-1;
+ pos_CHS.sector=disk_car->geom.sectors_per_head;
+ }
+ pos=CHS2offset(disk_car,&pos_CHS);
+#ifdef DJGPP
+ if(disk_car->description==disk_description)
+ {
+ struct info_disk_struct*data=disk_car->data;
+ data->geo_phys.cylinders=0;
+ }
#endif
- if((unsigned int)(disk_car->CHS.cylinder+1)!=0) /* Avoid to wrap */
- {
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, pos)==0)
+ if(disk_car->read(disk_car,disk_car->sector_size, buffer, pos)>=0)
{
- disk_car->CHS.cylinder++;
- if(disk_car->disk_size < (uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size)
+ disk_car->geom.cylinders++;
+ if(disk_car->disk_size < (uint64_t)disk_car->geom.cylinders * disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size)
{
- disk_car->disk_size=(uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size;
+ disk_car->disk_size = (uint64_t)disk_car->geom.cylinders * disk_car->geom.heads_per_cylinder * disk_car->geom.sectors_per_head * disk_car->sector_size;
log_info("Computes LBA from CHS for %s\n",disk_car->description(disk_car));
}
}
@@ -1509,7 +1513,7 @@ void hd_update_geometry(disk_t *disk_car, const int allow_partial_last_cylinder,
if(disk_car->description==disk_description)
{
struct info_disk_struct*data=disk_car->data;
- data->CHSR.cylinder=disk_car->CHS.cylinder;
+ data->geo_phys.cylinders=disk_car->geom.cylinders;
}
#endif
free(buffer);
@@ -1532,7 +1536,7 @@ void autoset_unit(disk_t *disk_car)
return ;
if(disk_car->arch==&arch_mac ||
disk_car->arch==&arch_gpt ||
- (disk_car->CHS.head==0 && disk_car->CHS.sector==1))
+ (disk_car->geom.heads_per_cylinder==1 && disk_car->geom.sectors_per_head==1))
disk_car->unit=UNIT_SECTOR;
else
disk_car->unit=UNIT_CHS;
diff --git a/src/hdcache.c b/src/hdcache.c
index 4e80b50..f17d304 100644
--- a/src/hdcache.c
+++ b/src/hdcache.c
@@ -231,6 +231,13 @@ static int cache_sync(disk_t *disk_car)
return data->disk_car->sync(data->disk_car);
}
+static void dup_geometry(CHSgeometry_t * CHS_dst, const CHSgeometry_t * CHS_source)
+{
+ CHS_dst->cylinders=CHS_source->cylinders;
+ CHS_dst->heads_per_cylinder=CHS_source->heads_per_cylinder;
+ CHS_dst->sectors_per_head=CHS_source->sectors_per_head;
+}
+
disk_t *new_diskcache(disk_t *disk_car, const unsigned int testdisk_mode)
{
unsigned int i;
@@ -249,7 +256,7 @@ disk_t *new_diskcache(disk_t *disk_car, const unsigned int testdisk_mode)
data->cache_size_min=64*512;
else
data->cache_size_min=0;
- dup_CHS(&new_disk_car->CHS,&disk_car->CHS);
+ dup_geometry(&new_disk_car->geom,&disk_car->geom);
new_disk_car->disk_size=disk_car->disk_size;
new_disk_car->disk_real_size=disk_car->disk_real_size;
new_disk_car->write_used=0;
@@ -272,7 +279,7 @@ disk_t *new_diskcache(disk_t *disk_car, const unsigned int testdisk_mode)
static const char *cache_description(disk_t *disk_car)
{
struct cache_struct *data=(struct cache_struct *)disk_car->data;
- dup_CHS(&data->disk_car->CHS,&disk_car->CHS);
+ dup_geometry(&data->disk_car->geom,&disk_car->geom);
data->disk_car->disk_size=disk_car->disk_size;
return data->disk_car->description(data->disk_car);
}
@@ -280,7 +287,7 @@ static const char *cache_description(disk_t *disk_car)
static const char *cache_description_short(disk_t *disk_car)
{
struct cache_struct *data=(struct cache_struct *)disk_car->data;
- dup_CHS(&data->disk_car->CHS,&disk_car->CHS);
+ dup_geometry(&data->disk_car->geom,&disk_car->geom);
data->disk_car->disk_size=disk_car->disk_size;
return data->disk_car->description_short(data->disk_car);
}
diff --git a/src/intrf.c b/src/intrf.c
index 8deb21e..0c4b06b 100644
--- a/src/intrf.c
+++ b/src/intrf.c
@@ -1061,12 +1061,12 @@ void aff_LBA2CHS(const disk_t *disk_car, const unsigned long int pos_LBA)
{
unsigned long int tmp;
unsigned long int cylinder, head, sector;
- tmp=disk_car->CHS.sector;
+ tmp=disk_car->geom.sectors_per_head;
sector=(pos_LBA%tmp)+1;
tmp=pos_LBA/tmp;
- cylinder=tmp/(disk_car->CHS.head+1);
- head=tmp%(disk_car->CHS.head+1);
- wprintw(stdscr,"%lu/%lu/%lu", cylinder,head,sector);
+ cylinder=tmp / disk_car->geom.heads_per_cylinder;
+ head=tmp % disk_car->geom.heads_per_cylinder;
+ wprintw(stdscr, "%lu/%lu/%lu", cylinder, head, sector);
}
int ask_YN(WINDOW *window)
@@ -1963,12 +1963,12 @@ void log_CHS_from_LBA(const disk_t *disk_car, const unsigned long int pos_LBA)
{
unsigned long int tmp;
unsigned long int cylinder, head, sector;
- tmp=disk_car->CHS.sector;
+ tmp=disk_car->geom.sectors_per_head;
sector=(pos_LBA%tmp)+1;
tmp=pos_LBA/tmp;
- cylinder=tmp/(disk_car->CHS.head+1);
- head=tmp%(disk_car->CHS.head+1);
- log_info("%lu/%lu/%lu", cylinder,head,sector);
+ cylinder=tmp / disk_car->geom.heads_per_cylinder;
+ head=tmp % disk_car->geom.heads_per_cylinder;
+ log_info("%lu/%lu/%lu", cylinder, head, sector);
}
int display_message(const char*msg)
diff --git a/src/intrface.c b/src/intrface.c
index 1c9405d..3f718dd 100644
--- a/src/intrface.c
+++ b/src/intrface.c
@@ -612,7 +612,8 @@ static int interface_check_disk_capacity_ncurses(disk_t *disk_car)
static int interface_check_disk_capacity(disk_t *disk_car)
{
/* Test for LBA28 limitation */
- if(disk_car->CHS.sector>0 && (disk_car->CHS.cylinder+1) == (((1<<28)-1) / (disk_car->CHS.head+1) / disk_car->CHS.sector))
+ if(disk_car->geom.sectors_per_head>0 &&
+ disk_car->geom.cylinders == (((1<<28)-1) / disk_car->geom.heads_per_cylinder / disk_car->geom.sectors_per_head))
{
log_warning("LBA28 limitation\n");
log_flush();
diff --git a/src/msdos.c b/src/msdos.c
index 10a33f8..0bc864c 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -100,15 +100,15 @@ static int hd_read(disk_t *disk_car, void *buf, const unsigned int count, const
if(data->mode_enh==0)
{ /* Limite CHS = 1023,255,63 = 8,064Mo ~= 7.8 Go */
int head, track, sector;
- if(data->CHSR.sector==0)
+ if(data->geo_phys.sectors_per_head==0)
{
- log_critical("hd_read: BUG CHSR.sector=0 !\n");
+ log_critical("hd_read: BUG geo_phys.sectors_per_head=0 !\n");
return 1;
}
- sector=(hd_offset%data->CHSR.sector)+1;
- hd_offset/=data->CHSR.sector;
- head=hd_offset%(data->CHSR.head+1);
- track=hd_offset/(data->CHSR.head+1);
+ sector=(hd_offset%data->geo_phys.sectors_per_head)+1;
+ hd_offset/=data->geo_phys.sectors_per_head;
+ head=hd_offset%data->geo_phys.heads_per_cylinder;
+ track=hd_offset/data->geo_phys.heads_per_cylinder;
if(track<1024)
return biosdisk(2, data->disk, head, track, sector, nsects, buf);
return 1;
@@ -149,15 +149,15 @@ static int hd_write(disk_t *disk_car, const void *buf, const unsigned int count,
if(data->mode_enh==0)
{ /* Limite CHS = 1023,255,63 = 8,064Mo ~= 7.8 Go */
int head, track, sector;
- if(data->CHSR.sector==0)
+ if(data->geo_phys.sectors_per_head==0)
{
- log_critical("hd_write: BUG CHSR.sector=0 !\n");
+ log_critical("hd_write: BUG geo_phys.sectors_per_head=0 !\n");
return 1;
}
- sector=(hd_offset%data->CHSR.sector)+1;
- hd_offset/=data->CHSR.sector;
- head=hd_offset%(data->CHSR.head+1);
- track=hd_offset/(data->CHSR.head+1);
+ sector=(hd_offset%data->geo_phys.sectors_per_head)+1;
+ hd_offset/=data->geo_phys.sectors_per_head;
+ head=hd_offset%data->geo_phys.heads_per_cylinder;
+ track=hd_offset/data->geo_phys.heads_per_cylinder;
if(track<1024)
return biosdisk(3, data->disk, head, track, sector, nsects, buf);
return 1;
@@ -229,6 +229,7 @@ static int check_enh_bios(const unsigned int disk, const int verbose)
static int hd_identify_enh_bios(disk_t *disk_car,const int verbose)
{
+ uint64_t computed_size;
int compute_LBA=0;
__dpmi_regs r;
unsigned char buf[0x200]; /* Don't change it! */
@@ -247,13 +248,13 @@ static int hd_identify_enh_bios(disk_t *disk_car,const int verbose)
dosmemget(cmd_dos_segment<<4, HDPARM_BUF_SIZ, &buf);
if(r.h.ah)
return 1;
- disk_car->CHS.cylinder=*(uint16_t*)&buf[0x04];
- disk_car->CHS.head=*(uint16_t*)&buf[0x08];
- disk_car->CHS.sector=*(uint16_t*)&buf[0x0C];
+ disk_car->geom.cylinders=*(uint16_t*)&buf[0x04];
+ disk_car->geom.heads_per_cylinder=*(uint16_t*)&buf[0x08];
+ disk_car->geom.sectors_per_head=*(uint16_t*)&buf[0x0C];
disk_car->disk_size=(*(uint32_t*)&buf[0x10])*(uint64_t)disk_car->sector_size;
if(disk_car->disk_size==0)
{
- if(disk_car->CHS.cylinder==0 || disk_car->CHS.head==0 || disk_car->CHS.sector==0)
+ if(disk_car->geom.cylinders==0 || disk_car->geom.heads_per_cylinder==0 || disk_car->geom.sectors_per_head==0)
{
if(verbose>0)
log_warning("hd_identify_enh_bios: No size returned by BIOS.\n");
@@ -261,24 +262,23 @@ static int hd_identify_enh_bios(disk_t *disk_car,const int verbose)
}
else
{
- disk_car->CHS.cylinder--;
- disk_car->CHS.head--;
compute_LBA=1;
- disk_car->disk_size=(uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size;
+ disk_car->disk_size=(uint64_t)disk_car->geom.cylinders*disk_car->geom.heads_per_cylinder*disk_car->geom.sectors_per_head*disk_car->sector_size;
if(verbose>0)
log_verbose("Computes LBA from CHS\n");
}
}
else
{
- if(disk_car->CHS.cylinder>0 && disk_car->CHS.head>0 && disk_car->CHS.sector>0)
+ if(disk_car->geom.cylinders>0 && disk_car->geom.heads_per_cylinder>0 && disk_car->geom.sectors_per_head>0)
{
- disk_car->CHS.cylinder--;
- disk_car->CHS.head--;
/* Some bios are buggy */
- if(disk_car->disk_size>(uint64_t)(disk_car->CHS.cylinder+2)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size)
+ if(disk_car->disk_size>(uint64_t)(disk_car->geom.cylinders+1)*disk_car->geom.heads_per_cylinder*disk_car->geom.sectors_per_head*disk_car->sector_size)
{
- disk_car->CHS.cylinder=(disk_car->disk_size/(disk_car->CHS.head+1))/disk_car->CHS.sector/disk_car->sector_size-1;
+ disk_car->geom.cylinders=disk_car->disk_size /
+ disk_car->geom.heads_per_cylinder /
+ disk_car->geom.sectors_per_head /
+ disk_car->sector_size;
if(verbose>0)
log_verbose("Computes C from number of sectors\n");
}
@@ -287,43 +287,52 @@ static int hd_identify_enh_bios(disk_t *disk_car,const int verbose)
{
if(verbose>0)
log_verbose("Computes CHS from number of sectors\n");
- disk_car->CHS.head=255-1;
- disk_car->CHS.sector=63;
- disk_car->CHS.cylinder=(disk_car->disk_size/(disk_car->CHS.head+1))/disk_car->CHS.sector/disk_car->sector_size-1;
+ disk_car->geom.heads_per_cylinder=255;
+ disk_car->geom.sectors_per_head=63;
+ disk_car->geom.cylinders=disk_car->disk_size /
+ disk_car->geom.heads_per_cylinder /
+ disk_car->geom.sectors_per_head /
+ disk_car->sector_size;
}
}
- if(disk_car->CHS.sector==0)
+ if(disk_car->geom.sectors_per_head==0)
{
data->bad_geometry=1;
- disk_car->CHS.sector=1;
+ disk_car->geom.sectors_per_head=1;
log_critical("Incorrect number of sector\n");
}
- if(disk_car->CHS.sector>63)
+ if(disk_car->geom.sectors_per_head>63)
{
/* data->bad_geometry=1; */
log_critical("Incorrect number of sector\n");
}
- if(disk_car->CHS.head>255-1)
+ if(disk_car->geom.heads_per_cylinder>255)
{
data->bad_geometry=1;
log_critical("Incorrect number of head\n");
}
+ computed_size=(uint64_t)disk_car->geom.cylinders*disk_car->geom.heads_per_cylinder*disk_car->geom.sectors_per_head*disk_car->sector_size;
if(verbose>0 || data->bad_geometry!=0)
- log_info("LBA %lu, computed %u (CHS=%u,%u,%u)\n",(long unsigned)(disk_car->disk_size/disk_car->sector_size), (disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector,disk_car->CHS.cylinder,disk_car->CHS.head,disk_car->CHS.sector);
+ log_info("LBA %lu, computed %lu (CHS=%u,%u,%u)\n",
+ (long unsigned)(disk_car->disk_size/disk_car->sector_size),
+ (long unsigned)(computed_size/disk_car->sector_size),
+ disk_car->geom.cylinders,
+ disk_car->geom.heads_per_cylinder,
+ disk_car->geom.sectors_per_head);
if(compute_LBA)
- disk_car->disk_size=(uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size;
+ disk_car->disk_size=computed_size;
else
{
- if(disk_car->disk_size < (uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector/disk_car->sector_size)
+ if(disk_car->disk_size < computed_size)
{
log_info("Computes LBA from CHS, previous value may be false.\n");
- disk_car->disk_size=(uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size;
+ disk_car->disk_size=computed_size;
}
}
disk_car->disk_real_size=disk_car->disk_size;
- data->CHSR.cylinder=disk_car->CHS.cylinder;
- data->CHSR.head=disk_car->CHS.head;
- data->CHSR.sector=disk_car->CHS.sector;
+ data->geo_phys.cylinders=disk_car->geom.cylinders;
+ data->geo_phys.heads_per_cylinder=disk_car->geom.heads_per_cylinder;
+ data->geo_phys.sectors_per_head=disk_car->geom.sectors_per_head;
if(verbose>0)
{
log_info("hd_identify_enh_bios\n");
@@ -366,26 +375,26 @@ disk_t *hd_identify(const int verbose, const unsigned int disk, const arch_fnct_
disk_car->access_mode=testdisk_mode;
disk_car->clean=disk_clean;
disk_car->data=data;
- disk_car->CHS.cylinder=((buf[0] & 0x0C0)<<2)|buf[1];
- disk_car->CHS.head=buf[3];
- disk_car->CHS.sector=buf[0] & 0x3F;
- if(disk_car->CHS.head>=255)
+ disk_car->geom.cylinders=1+(((buf[0] & 0x0C0)<<2)|buf[1]);
+ disk_car->geom.heads_per_cylinder=1+buf[3];
+ disk_car->geom.sectors_per_head=buf[0] & 0x3F;
+ if(disk_car->geom.heads_per_cylinder>255)
{ /* Problem found by G Rowe */
log_critical("BIOS reports an invalid heads number\n");
data->bad_geometry=1;
- disk_car->CHS.head=254;
+ disk_car->geom.heads_per_cylinder=255;
}
- if(disk_car->CHS.sector==0)
+ if(disk_car->geom.sectors_per_head==0)
{ /* Problem found by Brian Barrett */
log_critical("BIOS reports an invalid number of sector per head\n");
data->bad_geometry=1;
- disk_car->CHS.sector=1;
+ disk_car->geom.sectors_per_head=1;
}
- disk_car->disk_size=(uint64_t)(disk_car->CHS.cylinder+1)*(disk_car->CHS.head+1)*disk_car->CHS.sector*disk_car->sector_size;
+ disk_car->disk_size=(uint64_t)disk_car->geom.cylinders*disk_car->geom.heads_per_cylinder*disk_car->geom.sectors_per_head*disk_car->sector_size;
disk_car->disk_real_size=disk_car->disk_size;
- data->CHSR.cylinder=disk_car->CHS.cylinder;
- data->CHSR.head=disk_car->CHS.head;
- data->CHSR.sector=disk_car->CHS.sector;
+ data->geo_phys.cylinders=disk_car->geom.cylinders;
+ data->geo_phys.heads_per_cylinder=disk_car->geom.heads_per_cylinder;
+ data->geo_phys.sectors_per_head=disk_car->geom.sectors_per_head;
if(verbose>0)
log_info("%s\n",disk_description(disk_car));
if(check_enh_bios(disk,verbose))
@@ -401,7 +410,7 @@ disk_t *hd_identify(const int verbose, const unsigned int disk, const arch_fnct_
/* standard geometry H,S, compute C from LBA */
disk_car->disk_size=param_disk_enh->disk_size;
disk_car->disk_real_size=disk_car->disk_size;
- disk_car->CHS.cylinder=(disk_car->disk_size/(disk_car->CHS.head+1))/disk_car->CHS.sector/disk_car->sector_size-1;
+ disk_car->geom.cylinders=(disk_car->disk_size/disk_car->geom.heads_per_cylinder)/disk_car->geom.sectors_per_head/disk_car->sector_size;
}
else
data->mode_enh=0;
@@ -418,7 +427,7 @@ const char *disk_description(disk_t *disk_car)
char buffer_disk_size[100];
snprintf(disk_car->description_txt, sizeof(disk_car->description_txt),"Disk %2x - %s - CHS %u %u %u%s",
data->disk, size_to_unit(disk_car->disk_size,buffer_disk_size),
- disk_car->CHS.cylinder+1, disk_car->CHS.head+1, disk_car->CHS.sector,
+ disk_car->geom.cylinders, disk_car->geom.heads_per_cylinder, disk_car->geom.sectors_per_head,
data->bad_geometry!=0?" (Buggy BIOS)":"");
return disk_car->description_txt;
}
@@ -435,7 +444,7 @@ static const char *disk_description_short(disk_t *disk_car)
static int disk_read_aux(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset)
{
struct info_disk_struct*data=disk_car->data;
- if(data->CHSR.cylinder>0 && offset+count>disk_car->disk_size)
+ if(data->geo_phys.cylinders>0 && offset+count>disk_car->disk_size)
{
log_error("disk_read_aux: Don't read after the end of the disk\n");
return -1;
diff --git a/src/msdos.h b/src/msdos.h
index a9bfdc6..f86df72 100644
--- a/src/msdos.h
+++ b/src/msdos.h
@@ -22,7 +22,7 @@
struct info_disk_struct
{
unsigned int disk;
- CHS_t CHSR; /* CHS low level */
+ CHSgeometry_t geo_phys; /* CHS low level */
int mode_enh;
int bad_geometry;
};
diff --git a/src/next.c b/src/next.c
index 47e8437..757f3d7 100644
--- a/src/next.c
+++ b/src/next.c
@@ -50,7 +50,8 @@ static unsigned int search_location_nbr=0;
static search_location_t search_location_info[SEARCH_LOCATION_MAX];
static inline uint64_t CHS_to_offset(const unsigned int C, const int H, const int S,const disk_t *disk_car)
-{ return (((uint64_t)C*(disk_car->CHS.head+1)+H)*disk_car->CHS.sector+(S>0?S-1:S))*disk_car->sector_size;
+{
+ return (((uint64_t)C * disk_car->geom.heads_per_cylinder + H) * disk_car->geom.sectors_per_head +(S>0?S-1:S))*disk_car->sector_size;
}
void search_location_init(const disk_t *disk_car, const unsigned int location_boundary, const int fast_mode, const int search_vista_part)
diff --git a/src/ntfs.c b/src/ntfs.c
index 8f7ded0..2fc893a 100644
--- a/src/ntfs.c
+++ b/src/ntfs.c
@@ -140,20 +140,26 @@ int test_NTFS(const disk_t *disk_car,const struct ntfs_boot_sector*ntfs_header,
{
log_info("NTFS at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
}
- if(le16(ntfs_header->heads)!=disk_car->CHS.head+1)
+ if(le16(ntfs_header->heads)!=disk_car->geom.heads_per_cylinder)
{
- screen_buffer_add("Warning: Incorrect number of heads/cylinder %u (NTFS) != %u (HD)\n",le16(ntfs_header->heads),disk_car->CHS.head+1);
- log_warning("heads/cylinder %u (NTFS) != %u (HD)\n",le16(ntfs_header->heads),disk_car->CHS.head+1);
+ screen_buffer_add("Warning: Incorrect number of heads/cylinder %u (NTFS) != %u (HD)\n",
+ le16(ntfs_header->heads), disk_car->geom.heads_per_cylinder);
+ log_warning("heads/cylinder %u (NTFS) != %u (HD)\n",
+ le16(ntfs_header->heads), disk_car->geom.heads_per_cylinder);
}
- if(le16(ntfs_header->secs_track)!=disk_car->CHS.sector)
+ if(le16(ntfs_header->secs_track)!=disk_car->geom.sectors_per_head)
{
- screen_buffer_add("Warning: Incorrect number of sectors per track %u (NTFS) != %u (HD)\n",le16(ntfs_header->secs_track),disk_car->CHS.sector);
- log_warning("sect/track %u (NTFS) != %u (HD)\n",le16(ntfs_header->secs_track),disk_car->CHS.sector);
+ screen_buffer_add("Warning: Incorrect number of sectors per track %u (NTFS) != %u (HD)\n",
+ le16(ntfs_header->secs_track), disk_car->geom.sectors_per_head);
+ log_warning("sect/track %u (NTFS) != %u (HD)\n",
+ le16(ntfs_header->secs_track), disk_car->geom.sectors_per_head);
}
if(ntfs_sector_size(ntfs_header)!=disk_car->sector_size)
{
- screen_buffer_add("Warning: Incorrect number of bytes per sector %u (NTFS) != %u (HD)\n",ntfs_sector_size(ntfs_header),disk_car->sector_size);
- log_warning("Warning: Incorrect number of bytes per sector %u (NTFS) != %u (HD)\n",ntfs_sector_size(ntfs_header),disk_car->sector_size);
+ screen_buffer_add("Warning: Incorrect number of bytes per sector %u (NTFS) != %u (HD)\n",
+ ntfs_sector_size(ntfs_header), disk_car->sector_size);
+ log_warning("Warning: Incorrect number of bytes per sector %u (NTFS) != %u (HD)\n",
+ ntfs_sector_size(ntfs_header), disk_car->sector_size);
}
if(partition->part_size>0)
diff --git a/src/ntfs_adv.c b/src/ntfs_adv.c
index 9ad80d4..31d9118 100644
--- a/src/ntfs_adv.c
+++ b/src/ntfs_adv.c
@@ -296,8 +296,8 @@ static int create_ntfs_boot_sector(disk_t *disk_car, partition_t *partition, con
ntfs_header->sectors[1]=0;
ntfs_header->media=0xF8;
ntfs_header->fat_length=le16(0);
- ntfs_header->secs_track=le16(disk_car->CHS.sector);
- ntfs_header->heads=le16(disk_car->CHS.head+1);
+ ntfs_header->secs_track=le16(disk_car->geom.sectors_per_head);
+ ntfs_header->heads=le16(disk_car->geom.heads_per_cylinder);
/* absolute sector address from the beginning of the disk (!= FAT) */
ntfs_header->hidden=le32(partition->part_offset/disk_car->sector_size);
ntfs_header->total_sect=le32(0);
diff --git a/src/parti386.c b/src/parti386.c
index 02444ac..17abd52 100644
--- a/src/parti386.c
+++ b/src/parti386.c
@@ -92,7 +92,7 @@ struct partition_dos {
static uint64_t get_start_sect(const struct partition_dos *p);
static uint64_t get_nr_sects(const struct partition_dos *p);
static void log_dos_entry(const disk_t *disk_car, const struct partition_dos*);
-static int get_geometry_from_i386mbr(const unsigned char *buffer, const int verbose, CHS_t *geometry);
+static int get_geometry_from_i386mbr(const unsigned char *buffer, const int verbose, CHSgeometry_t *geometry);
static list_part_t *get_ext_data_i386(disk_t *disk_car, list_part_t *list_part, const int verbose, const int saveheader);
static void test_MBR_data(list_part_t *list_part);
static int test_MBR_over(disk_t *disk_car,list_part_t *list_part);
@@ -277,7 +277,7 @@ static void set_start_sect(struct partition_dos *p, unsigned int start_sect)
}
-int get_geometry_from_i386mbr(const unsigned char *buffer, const int verbose, CHS_t *geometry)
+int get_geometry_from_i386mbr(const unsigned char *buffer, const int verbose, CHSgeometry_t *geometry)
{
unsigned int i;
if(verbose>1)
@@ -293,24 +293,32 @@ int get_geometry_from_i386mbr(const unsigned char *buffer, const int verbose, CH
const struct partition_dos *p=pt_offset_const(buffer,i);
if(p->sys_ind!=0)
{
- if(geometry->cylinder<e_cyl(p))
- geometry->cylinder=e_cyl(p);
- if(geometry->head<e_head(p))
- geometry->head=e_head(p);
- if(geometry->sector<e_sect(p))
- geometry->sector=e_sect(p);
+ if(geometry->cylinders<e_cyl(p)+1)
+ geometry->cylinders=e_cyl(p)+1;
+ if(geometry->heads_per_cylinder<e_head(p)+1)
+ geometry->heads_per_cylinder=e_head(p)+1;
+ if(geometry->sectors_per_head<e_sect(p))
+ geometry->sectors_per_head=e_sect(p);
}
}
- if(geometry->sector==32 ||
- (geometry->sector==63 && (geometry->head==16-1 || geometry->head==32-1 || geometry->head==64-1 || geometry->head==128-1 || geometry->head==240-1 || geometry->head==255-1)))
- log_info("Geometry from i386 MBR: head=%u sector=%u\n",geometry->head+1,geometry->sector);
+ if(geometry->sectors_per_head==32 ||
+ (geometry->sectors_per_head==63 &&
+ ( geometry->heads_per_cylinder==16 ||
+ geometry->heads_per_cylinder==32 ||
+ geometry->heads_per_cylinder==64 ||
+ geometry->heads_per_cylinder==128 ||
+ geometry->heads_per_cylinder==240 ||
+ geometry->heads_per_cylinder==255)))
+ log_info("Geometry from i386 MBR: head=%u sector=%u\n",
+ geometry->heads_per_cylinder, geometry->sectors_per_head);
else
{
- if(geometry->sector>0)
- log_warning("Geometry from i386 MBR: head=%u sector=%u\n",geometry->head+1,geometry->sector);
- geometry->cylinder=0;
- geometry->head=0;
- geometry->sector=0;
+ if(geometry->sectors_per_head>0)
+ log_warning("Geometry from i386 MBR: head=%u sector=%u\n",geometry->heads_per_cylinder, geometry->sectors_per_head);
+ /* Don't trust the geometry */
+ geometry->cylinders=0;
+ geometry->heads_per_cylinder=0;
+ geometry->sectors_per_head=0;
}
return 0;
}
@@ -345,7 +353,7 @@ static list_part_t *read_part_i386(disk_t *disk_car, const int verbose, const in
{
unsigned int i;
int res=0;
- CHS_t geometry;
+ CHSgeometry_t geometry;
list_part_t *new_list_part=NULL;
unsigned char *buffer=(unsigned char *)MALLOC(disk_car->sector_size);
screen_buffer_reset();
@@ -355,9 +363,9 @@ static list_part_t *read_part_i386(disk_t *disk_car, const int verbose, const in
free(buffer);
return NULL;
}
- geometry.cylinder=0;
- geometry.head=0;
- geometry.sector=0;
+ geometry.cylinders=0;
+ geometry.heads_per_cylinder=0;
+ geometry.sectors_per_head=0;
if(get_geometry_from_i386mbr(buffer,verbose,&geometry)!=0)
{
screen_buffer_add(msg_TBL_NMARK);
@@ -793,13 +801,13 @@ static int write_all_log_i386(disk_t *disk_car, const list_part_t *list_part, co
CHS_t nextext_start;
bloc_nextext->part_offset=element->next->part->part_offset-disk_car->sector_size;
offset2CHS(disk_car,bloc_nextext->part_offset,&nextext_start);
- if(nextext_start.sector!=disk_car->CHS.sector)
+ if(nextext_start.sector!=disk_car->geom.sectors_per_head)
{
if(nextext_start.head>0)
nextext_start.head--;
else
{
- nextext_start.head=disk_car->CHS.head;
+ nextext_start.head=disk_car->geom.heads_per_cylinder-1;
nextext_start.cylinder--;
}
}
@@ -963,8 +971,8 @@ static void partition2_i386_entry(const disk_t *disk_car, const uint64_t pos, co
if(start.cylinder>1023)
{ /* Partition Magic 5 uses CHS=(1023,0,1) if extended or last logical *
* Linux fdisk and TestDisk use CHS=(1023,lastH,lastS) */
- p->head=(unsigned char)disk_car->CHS.head;
- p->sector=(unsigned char)(disk_car->CHS.sector|((1023>>8)<<6));
+ p->head=(unsigned char)disk_car->geom.heads_per_cylinder-1;
+ p->sector=(unsigned char)(disk_car->geom.sectors_per_head | ((1023>>8)<<6));
p->cyl=(unsigned char)1023;
}
else
@@ -975,8 +983,8 @@ static void partition2_i386_entry(const disk_t *disk_car, const uint64_t pos, co
}
if(end.cylinder>1023)
{
- p->end_head=(unsigned char)disk_car->CHS.head;
- p->end_sector=(unsigned char)(disk_car->CHS.sector|((1023>>8)<<6));
+ p->end_head=(unsigned char)disk_car->geom.heads_per_cylinder-1;
+ p->end_sector=(unsigned char)(disk_car->geom.sectors_per_head | ((1023>>8)<<6));
p->end_cyl=(unsigned char)1023;
}
else
@@ -1030,32 +1038,32 @@ static int i386_entry2partition(disk_t *disk_car, const uint64_t offset, partiti
break;
}
/* Check CHS */
- if((start.sector==0)||(start.sector>disk_car->CHS.sector))
+ if(start.sector==0 || start.sector > disk_car->geom.sectors_per_head)
{
if(partition->errcode==BAD_NOERR)
partition->errcode=BAD_SS;
}
- if((end.sector==0)||(end.sector>disk_car->CHS.sector))
+ if(end.sector==0 || end.sector > disk_car->geom.sectors_per_head)
{
if(partition->errcode==BAD_NOERR)
partition->errcode=BAD_ES;
}
- if(start.head>disk_car->CHS.head)
+ if(start.head >= disk_car->geom.heads_per_cylinder)
{
if(partition->errcode==BAD_NOERR)
partition->errcode=BAD_SH;
}
- if(start.cylinder>disk_car->CHS.cylinder)
+ if(start.cylinder >= disk_car->geom.cylinders)
{
if(partition->errcode==BAD_NOERR)
partition->errcode=BAD_SC;
}
- if(end.head>disk_car->CHS.head)
+ if(end.head >= disk_car->geom.heads_per_cylinder)
{
if(partition->errcode==BAD_NOERR)
partition->errcode=BAD_EH;
}
- if(end.cylinder>disk_car->CHS.cylinder)
+ if(end.cylinder >= disk_car->geom.cylinders)
{
if(partition->errcode==BAD_NOERR)
partition->errcode=BAD_EC;
@@ -1063,7 +1071,9 @@ static int i386_entry2partition(disk_t *disk_car, const uint64_t offset, partiti
if(((start_calculated.cylinder<=1023)&& (C_H_S2offset(disk_car,start.cylinder,start.head,start.sector)!=partition->part_offset))
|| ((start_calculated.cylinder>1023)&&(start.cylinder!=1023)&&(start.cylinder!=(start_calculated.cylinder&1023))))
{
- log_error("BAD_RS LBA=%lu %lu\n",(long unsigned)(partition->part_offset/disk_car->sector_size),C_H_S2LBA(disk_car,start.cylinder,start.head,start.sector));
+ log_error("BAD_RS LBA=%lu %lu\n",
+ (long unsigned)(partition->part_offset/disk_car->sector_size),
+ C_H_S2LBA(disk_car, start.cylinder, start.head, start.sector));
if(partition->errcode==BAD_NOERR)
partition->errcode=BAD_RS;
}
@@ -1176,9 +1186,9 @@ static list_part_t *add_partition_i386_cli(disk_t *disk_car,list_part_t *list_pa
start.cylinder=0;
start.head=0;
start.sector=1;
- end.cylinder=disk_car->CHS.cylinder;
- end.head=disk_car->CHS.head;
- end.sector=disk_car->CHS.sector;
+ end.cylinder=disk_car->geom.cylinders-1;
+ end.head=disk_car->geom.heads_per_cylinder-1;
+ end.sector=disk_car->geom.sectors_per_head;
while(*current_cmd[0]==',')
(*current_cmd)++;
while(1)
@@ -1186,32 +1196,38 @@ static list_part_t *add_partition_i386_cli(disk_t *disk_car,list_part_t *list_pa
if(strncmp(*current_cmd,"c,",2)==0)
{
(*current_cmd)+=2;
- start.cylinder=ask_number_cli(current_cmd, start.cylinder,0,disk_car->CHS.cylinder,"Enter the starting cylinder ");
+ start.cylinder=ask_number_cli(current_cmd, start.cylinder,
+ 0, disk_car->geom.cylinders-1, "Enter the starting cylinder ");
}
else if(strncmp(*current_cmd,"h,",2)==0)
{
(*current_cmd)+=2;
- start.head=ask_number_cli(current_cmd, start.head,0,disk_car->CHS.head,"Enter the starting head ");
+ start.head=ask_number_cli(current_cmd, start.head,
+ 0, disk_car->geom.heads_per_cylinder-1, "Enter the starting head ");
}
else if(strncmp(*current_cmd,"s,",2)==0)
{
(*current_cmd)+=2;
- start.sector=ask_number_cli(current_cmd, start.sector,1,disk_car->CHS.sector,"Enter the starting sector ");
+ start.sector=ask_number_cli(current_cmd, start.sector,
+ 1, disk_car->geom.sectors_per_head, "Enter the starting sector ");
}
else if(strncmp(*current_cmd,"C,",2)==0)
{
(*current_cmd)+=2;
- end.cylinder=ask_number_cli(current_cmd, end.cylinder,start.cylinder,disk_car->CHS.cylinder,"Enter the ending cylinder ");
+ end.cylinder=ask_number_cli(current_cmd, end.cylinder,
+ start.cylinder, disk_car->geom.cylinders-1, "Enter the ending cylinder ");
}
else if(strncmp(*current_cmd,"H,",2)==0)
{
(*current_cmd)+=2;
- end.head=ask_number_cli(current_cmd, end.head,0,disk_car->CHS.head,"Enter the ending head ");
+ end.head=ask_number_cli(current_cmd, end.head,
+ 0, disk_car->geom.heads_per_cylinder-1, "Enter the ending head ");
}
else if(strncmp(*current_cmd,"S,",2)==0)
{
(*current_cmd)+=2;
- end.sector=ask_number_cli(current_cmd, end.sector,1,disk_car->CHS.sector,"Enter the ending sector ");
+ end.sector=ask_number_cli(current_cmd, end.sector,
+ 1, disk_car->geom.sectors_per_head-1, "Enter the ending sector ");
}
else if(strncmp(*current_cmd,"T,",2)==0)
{
@@ -1264,9 +1280,9 @@ static list_part_t *add_partition_i386_ncurses(disk_t *disk_car,list_part_t *lis
start.cylinder=0;
start.head=0;
start.sector=1;
- end.cylinder=disk_car->CHS.cylinder;
- end.head=disk_car->CHS.head;
- end.sector=disk_car->CHS.sector;
+ end.cylinder=disk_car->geom.cylinders-1;
+ end.head=disk_car->geom.heads_per_cylinder-1;
+ end.sector=disk_car->geom.sectors_per_head;
{
int done = 0;
while (done==0) {
@@ -1298,32 +1314,38 @@ static list_part_t *add_partition_i386_ncurses(disk_t *disk_car,list_part_t *lis
switch (command) {
case 'c':
wmove(stdscr, INTER_GEOM_Y, INTER_GEOM_X);
- start.cylinder=ask_number(start.cylinder,0,disk_car->CHS.cylinder,"Enter the starting cylinder ");
+ start.cylinder=ask_number(start.cylinder,
+ 0, disk_car->geom.cylinders, "Enter the starting cylinder ");
position=1;
break;
case 'h':
wmove(stdscr, INTER_GEOM_Y, INTER_GEOM_X);
- start.head=ask_number(start.head,0,disk_car->CHS.head,"Enter the starting head ");
+ start.head=ask_number(start.head,
+ 0, disk_car->geom.heads_per_cylinder, "Enter the starting head ");
position=2;
break;
case 's':
wmove(stdscr, INTER_GEOM_Y, INTER_GEOM_X);
- start.sector=ask_number(start.sector,1,disk_car->CHS.sector,"Enter the starting sector ");
+ start.sector=ask_number(start.sector,
+ 1, disk_car->geom.sectors_per_head, "Enter the starting sector ");
position=3;
break;
case 'C':
wmove(stdscr, INTER_GEOM_Y, INTER_GEOM_X);
- end.cylinder=ask_number(end.cylinder,start.cylinder,disk_car->CHS.cylinder,"Enter the ending cylinder ");
+ end.cylinder=ask_number(end.cylinder,
+ start.cylinder, disk_car->geom.cylinders-1, "Enter the ending cylinder ");
position=4;
break;
case 'H':
wmove(stdscr, INTER_GEOM_Y, INTER_GEOM_X);
- end.head=ask_number(end.head,0,disk_car->CHS.head,"Enter the ending head ");
+ end.head=ask_number(end.head,
+ 0, disk_car->geom.heads_per_cylinder, "Enter the ending head ");
position=5;
break;
case 'S':
wmove(stdscr, INTER_GEOM_Y, INTER_GEOM_X);
- end.sector=ask_number(end.sector,1,disk_car->CHS.sector,"Enter the ending sector ");
+ end.sector=ask_number(end.sector,
+ 1, disk_car->geom.sectors_per_head, "Enter the ending sector ");
position=6;
break;
case 'T':
diff --git a/src/partnone.c b/src/partnone.c
index a5bb275..060c742 100644
--- a/src/partnone.c
+++ b/src/partnone.c
@@ -65,7 +65,7 @@
#include "partnone.h"
static int check_part_none(disk_t *disk_car, const int verbose,partition_t *partition,const int saveheader);
-static int get_geometry_from_nonembr(const unsigned char *buffer, const int verbose, CHS_t *geometry);
+static int get_geometry_from_nonembr(const unsigned char *buffer, const int verbose, CHSgeometry_t *geometry);
static list_part_t *read_part_none(disk_t *disk_car, const int verbose, const int saveheader);
static list_part_t *init_part_order_none(const disk_t *disk_car, list_part_t *list_part);
static void set_next_status_none(const disk_t *disk_car, partition_t *partition);
@@ -145,7 +145,7 @@ unsigned int get_part_type_none(const partition_t *partition)
return partition->upart_type;
}
-int get_geometry_from_nonembr(const unsigned char *buffer, const int verbose, CHS_t *geometry)
+int get_geometry_from_nonembr(const unsigned char *buffer, const int verbose, CHSgeometry_t *geometry)
{
{
/* Ugly hack to get geometry from FAT and NTFS */
@@ -155,8 +155,8 @@ int get_geometry_from_nonembr(const unsigned char *buffer, const int verbose, CH
if(le16(fat_header->secs_track)>0 && le16(fat_header->secs_track)<=63 &&
le16(fat_header->heads)>0 && le16(fat_header->heads)<=255)
{
- geometry->sector=le16(fat_header->secs_track);
- geometry->head=le16(fat_header->heads)-1;
+ geometry->sectors_per_head=le16(fat_header->secs_track);
+ geometry->heads_per_cylinder=le16(fat_header->heads);
}
}
}
diff --git a/src/partsun.c b/src/partsun.c
index 52f224c..ad701b0 100644
--- a/src/partsun.c
+++ b/src/partsun.c
@@ -59,7 +59,7 @@
#include "log.h"
static int check_part_sun(disk_t *disk_car, const int verbose,partition_t *partition,const int saveheader);
-static int get_geometry_from_sunmbr(const unsigned char *buffer, const int verbose, CHS_t *geometry);
+static int get_geometry_from_sunmbr(const unsigned char *buffer, const int verbose, CHSgeometry_t *geometry);
static list_part_t *read_part_sun(disk_t *disk_car, const int verbose, const int saveheader);
static int write_part_sun(disk_t *disk_car, const list_part_t *list_part, const int ro , const int verbose, const int align);
static list_part_t *init_part_order_sun(const disk_t *disk_car, list_part_t *list_part);
@@ -120,19 +120,20 @@ static unsigned int get_part_type_sun(const partition_t *partition)
return partition->part_type_sun;
}
-int get_geometry_from_sunmbr(const unsigned char *buffer, const int verbose, CHS_t *geometry)
+int get_geometry_from_sunmbr(const unsigned char *buffer, const int verbose, CHSgeometry_t *geometry)
{
const sun_partition *sunlabel=(const sun_partition*)buffer;
if(verbose>1)
{
log_trace("get_geometry_from_sunmbr\n");
}
- geometry->cylinder=0;
- geometry->head=be16(sunlabel->ntrks)-1;
- geometry->sector=be16(sunlabel->nsect);
- if(geometry->sector>0)
+ geometry->cylinders=0;
+ geometry->heads_per_cylinder=be16(sunlabel->ntrks);
+ geometry->sectors_per_head=be16(sunlabel->nsect);
+ if(geometry->sectors_per_head>0)
{
- log_info("Geometry from SUN MBR: head=%u sector=%u\n",geometry->head+1,geometry->sector);
+ log_info("Geometry from SUN MBR: head=%u sector=%u\n",
+ geometry->heads_per_cylinder, geometry->sectors_per_head);
}
return 0;
}
@@ -230,9 +231,9 @@ static list_part_t *add_partition_sun_cli(disk_t *disk_car,list_part_t *list_par
start.cylinder=0;
start.head=0;
start.sector=1;
- end.cylinder=disk_car->CHS.cylinder;
- end.head=disk_car->CHS.head;
- end.sector=disk_car->CHS.sector;
+ end.cylinder=disk_car->geom.cylinders-1;
+ end.head=disk_car->geom.heads_per_cylinder-1;
+ end.sector=disk_car->geom.sectors_per_head;
while(*current_cmd[0]==',')
(*current_cmd)++;
while(1)
@@ -240,12 +241,12 @@ static list_part_t *add_partition_sun_cli(disk_t *disk_car,list_part_t *list_par
if(strncmp(*current_cmd,"c,",2)==0)
{
(*current_cmd)+=2;
- start.cylinder=ask_number_cli(current_cmd, start.cylinder,0,disk_car->CHS.cylinder,"Enter the starting cylinder ");
+ start.cylinder=ask_number_cli(current_cmd, start.cylinder,0,disk_car->geom.cylinders-1,"Enter the starting cylinder ");
}
else if(strncmp(*current_cmd,"C,",2)==0)
{
(*current_cmd)+=2;
- end.cylinder=ask_number_cli(current_cmd, end.cylinder,start.cylinder,disk_car->CHS.cylinder,"Enter the ending cylinder ");
+ end.cylinder=ask_number_cli(current_cmd, end.cylinder,start.cylinder,disk_car->geom.cylinders-1,"Enter the ending cylinder ");
}
else if(strncmp(*current_cmd,"T,",2)==0)
{
@@ -284,9 +285,9 @@ static list_part_t *add_partition_sun_ncurses(disk_t *disk_car,list_part_t *list
start.cylinder=0;
start.head=0;
start.sector=1;
- end.cylinder=disk_car->CHS.cylinder;
- end.head=disk_car->CHS.head;
- end.sector=disk_car->CHS.sector;
+ end.cylinder=disk_car->geom.cylinders-1;
+ end.head=disk_car->geom.heads_per_cylinder-1;
+ end.sector=disk_car->geom.sectors_per_head;
{
int done = FALSE;
while (done==FALSE) {
@@ -314,12 +315,12 @@ static list_part_t *add_partition_sun_ncurses(disk_t *disk_car,list_part_t *list
switch (command) {
case 'c':
wmove(stdscr, INTER_GEOM_Y, INTER_GEOM_X);
- start.cylinder=ask_number(start.cylinder,0,disk_car->CHS.cylinder,"Enter the starting cylinder ");
+ start.cylinder=ask_number(start.cylinder,0,disk_car->geom.cylinders-1,"Enter the starting cylinder ");
position=1;
break;
case 'C':
wmove(stdscr, INTER_GEOM_Y, INTER_GEOM_X);
- end.cylinder=ask_number(end.cylinder,start.cylinder,disk_car->CHS.cylinder,"Enter the ending cylinder ");
+ end.cylinder=ask_number(end.cylinder,start.cylinder,disk_car->geom.cylinders-1,"Enter the ending cylinder ");
position=2;
break;
case 'T':
diff --git a/src/win32.c b/src/win32.c
index 072276e..3fd3c03 100644
--- a/src/win32.c
+++ b/src/win32.c
@@ -141,9 +141,9 @@ uint64_t disk_get_size_win32(HANDLE handle, const char *device, const int verbos
return filewin32_setfilepointer(handle, device);
}
-void disk_get_geometry_win32(CHS_t *CHS, HANDLE handle, const char *device, const int verbose)
+void disk_get_geometry_win32(CHSgeometry_t *geom, HANDLE handle, const char *device, const int verbose)
{
- if(CHS->sector!=0)
+ if(geom->sectors_per_head!=0)
return;
{
DWORD gotbytes;
@@ -151,10 +151,10 @@ void disk_get_geometry_win32(CHS_t *CHS, HANDLE handle, const char *device, cons
if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0,
&geometry_ex, sizeof(geometry_ex), &gotbytes, NULL))
{
- CHS->cylinder= geometry_ex.Geometry.Cylinders.QuadPart-1;
- CHS->head=geometry_ex.Geometry.TracksPerCylinder-1;
- CHS->sector= geometry_ex.Geometry.SectorsPerTrack;
- if(CHS->sector!=0)
+ geom->cylinders= geometry_ex.Geometry.Cylinders.QuadPart;
+ geom->heads_per_cylinder=geometry_ex.Geometry.TracksPerCylinder;
+ geom->sectors_per_head= geometry_ex.Geometry.SectorsPerTrack;
+ if(geom->sectors_per_head!=0)
return ;
}
}
@@ -164,16 +164,16 @@ void disk_get_geometry_win32(CHS_t *CHS, HANDLE handle, const char *device, cons
if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
&geometry, sizeof(geometry), &gotbytes, NULL))
{
- CHS->cylinder= geometry.Cylinders.QuadPart-1;
- CHS->head=geometry.TracksPerCylinder-1;
- CHS->sector= geometry.SectorsPerTrack;
- if(CHS->sector!=0)
+ geom->cylinders= geometry.Cylinders.QuadPart;
+ geom->heads_per_cylinder=geometry.TracksPerCylinder;
+ geom->sectors_per_head= geometry.SectorsPerTrack;
+ if(geom->sectors_per_head!=0)
return ;
}
}
- CHS->cylinder=0;
- CHS->head=0;
- CHS->sector=1;
+ geom->cylinders=0;
+ geom->heads_per_cylinder=1;
+ geom->sectors_per_head=1;
}
// Try to handle cdrom
@@ -322,7 +322,7 @@ disk_t *file_test_availability_win32(const char *device, const int verbose, cons
disk_car->access_mode=testdisk_mode;
disk_car->clean=file_win32_clean;
disk_car->sector_size=disk_get_sector_size_win32(handle, device, verbose);
- disk_get_geometry_win32(&disk_car->CHS, handle, device, verbose);
+ disk_get_geometry_win32(&disk_car->geom, handle, device, verbose);
disk_car->disk_real_size=disk_get_size_win32(handle, device, verbose);
file_win32_disk_get_model(handle, disk_car, verbose);
update_disk_car_fields(disk_car);
@@ -345,12 +345,12 @@ static const char *file_win32_description(disk_t *disk_car)
if(disk_car->device[0]=='\\' && disk_car->device[1]=='\\' && disk_car->device[2]=='.' && disk_car->device[3]=='\\' && disk_car->device[5]==':')
snprintf(disk_car->description_txt, sizeof(disk_car->description_txt),"Drive %c: - %s - CHS %u %u %u%s",
disk_car->device[4], size_to_unit(disk_car->disk_size,buffer_disk_size),
- disk_car->CHS.cylinder+1, disk_car->CHS.head+1, disk_car->CHS.sector,
+ disk_car->geom.cylinders, disk_car->geom.heads_per_cylinder, disk_car->geom.sectors_per_head,
((data->mode&FILE_WRITE_DATA)==FILE_WRITE_DATA?"":" (RO)"));
else
snprintf(disk_car->description_txt, sizeof(disk_car->description_txt),"Disk %s - %s - CHS %u %u %u%s",
disk_car->device, size_to_unit(disk_car->disk_size,buffer_disk_size),
- disk_car->CHS.cylinder+1, disk_car->CHS.head+1, disk_car->CHS.sector,
+ disk_car->geom.cylinders, disk_car->geom.heads_per_cylinder, disk_car->geom.sectors_per_head,
((data->mode&FILE_WRITE_DATA)==FILE_WRITE_DATA?"":" (RO)"));
return disk_car->description_txt;
}
diff --git a/src/win32.h b/src/win32.h
index 3d7c65f..09e4922 100644
--- a/src/win32.h
+++ b/src/win32.h
@@ -25,6 +25,6 @@
disk_t *file_test_availability_win32(const char *device, const int verbose, const arch_fnct_t *arch, const int testdisk_mode);
unsigned int disk_get_sector_size_win32(HANDLE handle, const char *device, const int verbose);
uint64_t disk_get_size_win32(HANDLE handle, const char *device, const int verbose);
-void disk_get_geometry_win32(CHS_t *CHS, HANDLE handle, const char *device, const int verbose);
+void disk_get_geometry_win32(CHSgeometry_t *geom, HANDLE handle, const char *device, const int verbose);
#endif
#endif