summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2017-04-14 18:28:30 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2017-04-14 18:28:30 +0200
commitf2f2d6b71a63a6cbfa30c8a8f72b260d58036842 (patch)
treeb2a75146b4a06b34de006a149f1f3ffe2ca297e5 /src
parentf7a840127cd5e741c29528542e02267c95df693e (diff)
Remove interface from rebuild_FAT_BS()
Diffstat (limited to 'src')
-rw-r--r--src/fat1x.c2
-rw-r--r--src/fat32.c2
-rw-r--r--src/fat_adv.c158
-rw-r--r--src/fat_adv.h2
-rw-r--r--src/fat_cluster.c15
-rw-r--r--src/fat_cluster.h2
-rw-r--r--src/tntfs.c269
7 files changed, 220 insertions, 230 deletions
diff --git a/src/fat1x.c b/src/fat1x.c
index d48372f..ce7d553 100644
--- a/src/fat1x.c
+++ b/src/fat1x.c
@@ -184,7 +184,7 @@ int fat1x_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos
free(buffer_bs);
return 0;
case 'R': /* R : rebuild boot sector */
- rebuild_FAT_BS(disk_car,partition,verbose,dump_ind,1,expert,current_cmd);
+ rebuild_FAT_BS(disk_car, partition, verbose, dump_ind, expert, current_cmd);
break;
case 'D':
dump_fat1x(disk_car, partition, buffer_bs, current_cmd);
diff --git a/src/fat32.c b/src/fat32.c
index 8593299..f6aca69 100644
--- a/src/fat32.c
+++ b/src/fat32.c
@@ -309,7 +309,7 @@ int fat32_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos
dir_partition(disk_car, partition, 0,current_cmd);
break;
case 'R': /* R : rebuild boot sector */
- rebuild_FAT_BS(disk_car,partition,verbose,dump_ind,1,expert,current_cmd);
+ rebuild_FAT_BS(disk_car, partition, verbose, dump_ind, expert, current_cmd);
break;
}
}
diff --git a/src/fat_adv.c b/src/fat_adv.c
index b5f3452..aef17ec 100644
--- a/src/fat_adv.c
+++ b/src/fat_adv.c
@@ -73,13 +73,13 @@ struct info_offset_struct
unsigned int fat_type;
};
-static upart_type_t fat_find_info(disk_t *disk_car,unsigned int*reserved, unsigned int*fat_length, const partition_t *partition,const uint64_t max_offset,const int p_fat12,const int p_fat16,const int p_fat32,const int verbose,const int dump_ind,const int interface, const unsigned int expert, unsigned int *fats);
-static int fat_find_type(disk_t *disk_car,const partition_t *partition,const uint64_t max_offset,const int p_fat12,const int p_fat16,const int p_fat32,const int verbose,const int dump_ind,const int interface,unsigned int *nbr_offset,info_offset_t *info_offset, const unsigned int max_nbr_offset);
+static upart_type_t fat_find_info(disk_t *disk_car,unsigned int*reserved, unsigned int*fat_length, const partition_t *partition, const uint64_t max_offset, const int p_fat12, const int p_fat16, const int p_fat32, const int verbose, const int dump_ind, const unsigned int expert, unsigned int *fats);
+static int fat_find_type(disk_t *disk_car, const partition_t *partition, const uint64_t max_offset, const int p_fat12, const int p_fat16, const int p_fat32, const int verbose, const int dump_ind, unsigned int *nbr_offset, info_offset_t *info_offset, const unsigned int max_nbr_offset);
static unsigned int fat_find_fat_start(const unsigned char *buffer,const int p_fat12, const int p_fat16, const int p_fat32,unsigned long int*fat_offset, const unsigned int sector_size);
-static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, const unsigned int reserved, const int verbose, const unsigned int dir_entries, const unsigned long int root_cluster, const unsigned int sectors_per_cluster, const unsigned int fat_length,const int interface, const upart_type_t upart_type, const unsigned int fats, char **current_cmd);
-static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *partition,const unsigned int sectors_per_cluster, const unsigned long int no_of_cluster, const unsigned int reserved, const unsigned int fat_length, const int interface, const int verbose, const unsigned int expert, const unsigned int first_free_cluster, const unsigned int fats);
+static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, const unsigned int reserved, const int verbose, const unsigned int dir_entries, const unsigned long int root_cluster, const unsigned int sectors_per_cluster, const unsigned int fat_length, const upart_type_t upart_type, const unsigned int fats, char **current_cmd);
+static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *partition,const unsigned int sectors_per_cluster, const unsigned long int no_of_cluster, const unsigned int reserved, const unsigned int fat_length, const int verbose, const unsigned int expert, const unsigned int first_free_cluster, const unsigned int fats);
static int write_FAT_boot_code_aux(unsigned char *buffer);
static int find_dir_entries(disk_t *disk_car,const partition_t *partition, const unsigned int offset,const int verbose);
static int analyse_dir_entries(disk_t *disk_car,const partition_t *partition, const unsigned int offset, const int verbose);
@@ -317,7 +317,7 @@ static int is_root_cluster_candidat(const file_info_t *dir_list)
return (!td_list_empty(&dir_list->list) && (&file2->list==&dir_list->list || file1->st_ino!=file2->st_ino));
}
-static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *partition,const unsigned int sectors_per_cluster, const unsigned long int no_of_cluster,const unsigned int reserved, const unsigned int fat_length, const int interface, const int verbose, const unsigned int expert, const unsigned int first_free_cluster, const unsigned int fats)
+static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *partition,const unsigned int sectors_per_cluster, const unsigned long int no_of_cluster,const unsigned int reserved, const unsigned int fat_length, const int verbose, const unsigned int expert, const unsigned int first_free_cluster, const unsigned int fats)
{
unsigned long int root_cluster=0;
const uint64_t start_data=reserved+fats*fat_length;
@@ -337,19 +337,16 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
TD_INIT_LIST_HEAD(&rootdir_list.list);
buffer=(unsigned char *)MALLOC(cluster_size);
#ifdef HAVE_NCURSES
- if(interface)
- {
- wmove(stdscr,22,0);
- wattrset(stdscr, A_REVERSE);
- waddstr(stdscr," Stop ");
- wattroff(stdscr, A_REVERSE);
- }
+ wmove(stdscr,22,0);
+ wattrset(stdscr, A_REVERSE);
+ waddstr(stdscr," Stop ");
+ wattroff(stdscr, A_REVERSE);
#endif
for(root_cluster=2;(root_cluster<2+no_of_cluster)&&(ind_stop==0);root_cluster++)
{
#ifdef HAVE_NCURSES
const unsigned long int percent=root_cluster*100/(2+no_of_cluster);
- if(interface>0 && (root_cluster&0xfff)==0)
+ if((root_cluster&0xfff)==0)
{
wmove(stdscr,9,0);
wclrtoeol(stdscr);
@@ -516,7 +513,7 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
test_date=dir_aff_log(NULL, &dir_list);
}
#ifdef HAVE_NCURSES
- if(interface>0 && interactive>0 && test_date>0)
+ if(interactive>0 && test_date>0)
{
switch(ask_root_directory(disk_car, partition, &dir_list, root_cluster))
{
@@ -557,7 +554,7 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
{
dir_aff_log(NULL, &rootdir_list);
#ifdef HAVE_NCURSES
- if(interface && expert>0)
+ if(expert>0)
{
if(ask_confirmation("Create a new root cluster with %u first-level directories (Expert only) (Y/N)",dir_nbr)!=0 && ask_confirmation("Write root cluster, confirm ? (Y/N)")!=0)
{
@@ -1078,7 +1075,7 @@ static void menu_write_fat_boot_sector(disk_t *disk_car, partition_t *partition,
log_info("Don't write new boot!\n");
}
-static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, const unsigned int reserved, const int verbose, const unsigned int dir_entries, const unsigned long int root_cluster, const unsigned int sectors_per_cluster, const unsigned int fat_length,const int interface, const upart_type_t upart_type, const unsigned int fats, char **current_cmd)
+static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, const unsigned int reserved, const int verbose, const unsigned int dir_entries, const unsigned long int root_cluster, const unsigned int sectors_per_cluster, const unsigned int fat_length, const upart_type_t upart_type, const unsigned int fats, char **current_cmd)
{
unsigned char *orgboot;
unsigned char *newboot;
@@ -1274,8 +1271,7 @@ static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, con
{
log_info("Extrapolated boot sector and current boot sector are identical.\n");
}
- if(interface)
- menu_write_fat_boot_sector(disk_car, partition, verbose, upart_type, orgboot, newboot, error, current_cmd);
+ menu_write_fat_boot_sector(disk_car, partition, verbose, upart_type, orgboot, newboot, error, current_cmd);
free(orgboot);
free(newboot);
}
@@ -1576,7 +1572,7 @@ static unsigned int fat_find_fat_start(const unsigned char *buffer,const int p_f
return 0;
}
-static int fat_find_type(disk_t *disk_car,const partition_t *partition,const uint64_t max_offset,const int p_fat12,const int p_fat16,const int p_fat32,const int verbose,const int dump_ind,const int interface,unsigned int *nbr_offset,info_offset_t *info_offset, const unsigned int max_nbr_offset)
+static int fat_find_type(disk_t *disk_car, const partition_t *partition, const uint64_t max_offset, const int p_fat12, const int p_fat16, const int p_fat32, const int verbose, const int dump_ind, unsigned int *nbr_offset, info_offset_t *info_offset, const unsigned int max_nbr_offset)
{
uint64_t offset;
#ifdef HAVE_NCURSES
@@ -1590,15 +1586,12 @@ static int fat_find_type(disk_t *disk_car,const partition_t *partition,const uin
(long unsigned)(max_offset/disk_car->sector_size), p_fat12, p_fat16, p_fat32, verbose, dump_ind);
}
#ifdef HAVE_NCURSES
- if(interface)
- {
- wmove(stdscr,8,0);
- wprintw(stdscr,"FAT : %s%s%s?\n",p_fat12?"12 ":"", p_fat16?"16 ":"", p_fat32?"32 ":"");
- wmove(stdscr,22,0);
- wattrset(stdscr, A_REVERSE);
- waddstr(stdscr," Stop ");
- wattroff(stdscr, A_REVERSE);
- }
+ wmove(stdscr,8,0);
+ wprintw(stdscr,"FAT : %s%s%s?\n",p_fat12?"12 ":"", p_fat16?"16 ":"", p_fat32?"32 ":"");
+ wmove(stdscr,22,0);
+ wattrset(stdscr, A_REVERSE);
+ waddstr(stdscr," Stop ");
+ wattroff(stdscr, A_REVERSE);
#endif
for(offset=disk_car->sector_size;
offset<max_offset && !ind_stop;
@@ -1606,7 +1599,7 @@ static int fat_find_type(disk_t *disk_car,const partition_t *partition,const uin
{
#ifdef HAVE_NCURSES
const unsigned long int percent=offset*100/max_offset;
- if(interface && (percent!=old_percent))
+ if(percent!=old_percent)
{
wmove(stdscr,8,30);
wclrtoeol(stdscr); /* before addstr for BSD compatibility */
@@ -1657,24 +1650,21 @@ static int fat_find_type(disk_t *disk_car,const partition_t *partition,const uin
}
}
#ifdef HAVE_NCURSES
- if(interface)
- {
- wmove(stdscr,22,0);
- wclrtoeol(stdscr);
- wrefresh(stdscr);
- }
+ wmove(stdscr,22,0);
+ wclrtoeol(stdscr);
+ wrefresh(stdscr);
#endif
free(buffer);
return 0;
}
-static upart_type_t fat_find_info(disk_t *disk_car,unsigned int*reserved, unsigned int*fat_length, const partition_t *partition,const uint64_t max_offset,const int p_fat12,const int p_fat16,const int p_fat32,const int verbose,const int dump_ind,const int interface, const unsigned int expert, unsigned int *fats)
+static upart_type_t fat_find_info(disk_t *disk_car,unsigned int*reserved, unsigned int*fat_length, const partition_t *partition, const uint64_t max_offset, const int p_fat12, const int p_fat16, const int p_fat32, const int verbose, const int dump_ind, const unsigned int expert, unsigned int *fats)
{
unsigned int nbr_offset=0;
unsigned int i;
info_offset_t info_offset[0x400];
upart_type_t upart_type=UP_UNK;
- fat_find_type(disk_car, partition,max_offset,p_fat12,p_fat16,p_fat32,verbose,dump_ind,interface,&nbr_offset,&info_offset[0], 0x400);
+ fat_find_type(disk_car, partition, max_offset, p_fat12, p_fat16, p_fat32, verbose, dump_ind, &nbr_offset, &info_offset[0], 0x400);
for(i=0;i<nbr_offset;i++)
{
const uint64_t end=partition->part_offset+(uint64_t)info_offset[i].offset*disk_car->sector_size;
@@ -1684,7 +1674,7 @@ static upart_type_t fat_find_info(disk_t *disk_car,unsigned int*reserved, unsign
offset2sector(disk_car,end),
info_offset[i].nbr);
#ifdef HAVE_NCURSES
- if(dump_ind>0 && interface>0)
+ if(dump_ind>0)
{
unsigned char *buffer=(unsigned char *)MALLOC(disk_car->sector_size);
if((unsigned)disk_car->pread(disk_car, &buffer, disk_car->sector_size, end) == disk_car->sector_size)
@@ -1807,7 +1797,7 @@ static upart_type_t fat_find_info(disk_t *disk_car,unsigned int*reserved, unsign
log_info("first_fat %lu, second_fat %lu\n",info_offset[first_fat].offset, info_offset[second_fat].offset);
}
}
- if(expert>0 && interface>0)
+ if(expert>0)
{
#ifdef HAVE_NCURSES
return select_fat_info(info_offset,nbr_offset,reserved,fat_length,max_offset/disk_car->sector_size,fats);
@@ -1897,7 +1887,7 @@ static upart_type_t select_fat_info(const info_offset_t *info_offset, const unsi
}
#endif
-int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface,const unsigned int expert, char**current_cmd)
+int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind, const unsigned int expert, char**current_cmd)
{
unsigned long int max_offset;
unsigned int fat_length=0;
@@ -1974,44 +1964,38 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
log_debug("search_fat16(partition,max_offset=%d,p_fat12=%d,p_fat16=%d,p_fat32=%d,debug=%d,dump_ind=%d)\n",max_offset,p_fat12,p_fat16,p_fat32,verbose,dump_ind);
*/
#ifdef HAVE_NCURSES
- if(interface)
- {
- aff_copy(stdscr);
- wmove(stdscr,4,0);
- wprintw(stdscr,"%s",disk_car->description(disk_car));
- mvwaddstr(stdscr,5,0,msg_PART_HEADER_LONG);
- wmove(stdscr,6,0);
- aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition);
- wrefresh(stdscr);
- }
+ aff_copy(stdscr);
+ wmove(stdscr,4,0);
+ wprintw(stdscr,"%s",disk_car->description(disk_car));
+ mvwaddstr(stdscr,5,0,msg_PART_HEADER_LONG);
+ wmove(stdscr,6,0);
+ aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition);
+ wrefresh(stdscr);
#endif
- upart_type=fat_find_info(disk_car,&reserved, &fat_length, partition,max_offset,p_fat12,p_fat16,p_fat32,verbose,dump_ind,interface,expert,&fats);
+ upart_type=fat_find_info(disk_car, &reserved, &fat_length, partition, max_offset, p_fat12, p_fat16, p_fat32, verbose, dump_ind, expert, &fats);
#ifdef HAVE_NCURSES
- if(interface)
+ aff_copy(stdscr);
+ wmove(stdscr,4,0);
+ wprintw(stdscr,"%s",disk_car->description(disk_car));
+ mvwaddstr(stdscr,5,0,msg_PART_HEADER_LONG);
+ wmove(stdscr,6,0);
+ aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition);
+ wmove(stdscr,8,0);
+ wclrtoeol(stdscr);
+ switch(upart_type)
{
- aff_copy(stdscr);
- wmove(stdscr,4,0);
- wprintw(stdscr,"%s",disk_car->description(disk_car));
- mvwaddstr(stdscr,5,0,msg_PART_HEADER_LONG);
- wmove(stdscr,6,0);
- aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition);
- wmove(stdscr,8,0);
- wclrtoeol(stdscr);
- switch(upart_type)
- {
- case UP_FAT12:
- waddstr(stdscr,"FAT : 12");
- break;
- case UP_FAT16:
- waddstr(stdscr,"FAT : 16");
- break;
- case UP_FAT32:
- waddstr(stdscr,"FAT : 32");
- break;
- default:
- waddstr(stdscr,"No FAT found");
- break;
- }
+ case UP_FAT12:
+ waddstr(stdscr,"FAT : 12");
+ break;
+ case UP_FAT16:
+ waddstr(stdscr,"FAT : 16");
+ break;
+ case UP_FAT32:
+ waddstr(stdscr,"FAT : 32");
+ break;
+ default:
+ waddstr(stdscr,"No FAT found");
+ break;
}
#endif
if(verbose>0)
@@ -2037,7 +2021,7 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
(fat_length==0)||(reserved==0))
{
uint64_t start_data=0;
- if(find_sectors_per_cluster(disk_car, partition, verbose, dump_ind, interface, &sectors_per_cluster, &start_data, upart_type)==0)
+ if(find_sectors_per_cluster(disk_car, partition, verbose, dump_ind, &sectors_per_cluster, &start_data, upart_type)==0)
{
display_message("Can't find cluster size\n");
return 0;
@@ -2100,12 +2084,9 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
log_info("fat_length %u\n",fat_length);
}
#ifdef HAVE_NCURSES
- if(interface)
- {
- if(fat_length==0)
- waddstr(stdscr," Can't find FAT length\n");
- wrefresh(stdscr);
- }
+ if(fat_length==0)
+ waddstr(stdscr," Can't find FAT length\n");
+ wrefresh(stdscr);
#endif
if(upart_type && (fat_length>1))
{
@@ -2196,7 +2177,7 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
/* Use first fat */
fat32_free_info(disk_car,partition,reserved,data_size/sectors_per_cluster,&first_free_cluster,&free_cluster_count);
/* FAT32 : Find root cluster */
- root_cluster=fat32_find_root_cluster(disk_car,partition,sectors_per_cluster,data_size/sectors_per_cluster,reserved,fat_length,interface,verbose,expert,first_free_cluster,fats);
+ root_cluster=fat32_find_root_cluster(disk_car, partition, sectors_per_cluster, data_size/sectors_per_cluster, reserved, fat_length, verbose, expert, first_free_cluster, fats);
if(expert>0)
{
#ifdef HAVE_NCURSES
@@ -2216,14 +2197,11 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
}
}
#ifdef HAVE_NCURSES
- if(interface)
- {
- wmove(stdscr,9,0);
- wclrtoeol(stdscr);
- wrefresh(stdscr);
- }
+ wmove(stdscr,9,0);
+ wclrtoeol(stdscr);
+ wrefresh(stdscr);
#endif
- create_fat_boot_sector(disk_car,partition, reserved, verbose,dir_entries,root_cluster,sectors_per_cluster,fat_length,interface,upart_type,fats,current_cmd);
+ create_fat_boot_sector(disk_car, partition, reserved, verbose, dir_entries, root_cluster, sectors_per_cluster, fat_length, upart_type, fats, current_cmd);
if(verbose)
{
log_info("\n");
diff --git a/src/fat_adv.h b/src/fat_adv.h
index 3d3e12d..c87fb64 100644
--- a/src/fat_adv.h
+++ b/src/fat_adv.h
@@ -25,7 +25,7 @@
extern "C" {
#endif
-int rebuild_FAT_BS(disk_t *disk_car,partition_t *partition, const int verbose, const int dump_ind,const int interface, const unsigned int expert, char**current_cmd);
+int rebuild_FAT_BS(disk_t *disk_car,partition_t *partition, const int verbose, const int dump_ind, const unsigned int expert, char**current_cmd);
int FAT_init_rootdir(disk_t *disk_car, partition_t *partition, const int verbose, char **current_cmd);
int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose, char **current_cmd);
diff --git a/src/fat_cluster.c b/src/fat_cluster.c
index 2d9d387..1384202 100644
--- a/src/fat_cluster.c
+++ b/src/fat_cluster.c
@@ -42,7 +42,7 @@
/* Using a couple of inodes of "." directory entries, get the cluster size and where the first cluster begins.
* */
-int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *sectors_per_cluster, uint64_t *offset_org, const upart_type_t upart_type)
+int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind, unsigned int *sectors_per_cluster, uint64_t *offset_org, const upart_type_t upart_type)
{
unsigned int nbr_subdir=0;
sector_cluster_t sector_cluster[10];
@@ -51,13 +51,10 @@ int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int
int ind_stop=0;
unsigned char *buffer=(unsigned char *)MALLOC(disk_car->sector_size);
#ifdef HAVE_NCURSES
- if(interface)
- {
- wmove(stdscr,22,0);
- wattrset(stdscr, A_REVERSE);
- waddstr(stdscr," Stop ");
- wattroff(stdscr, A_REVERSE);
- }
+ wmove(stdscr,22,0);
+ wattrset(stdscr, A_REVERSE);
+ waddstr(stdscr," Stop ");
+ wattroff(stdscr, A_REVERSE);
#endif
/* 2 fats, maximum cluster size=128 */
skip_offset=(uint64_t)((partition->part_size-32*disk_car->sector_size)/disk_car->sector_size/128*3/2/disk_car->sector_size*2)*disk_car->sector_size;
@@ -72,7 +69,7 @@ int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int
offset+=disk_car->sector_size)
{
#ifdef HAVE_NCURSES
- if(interface>0 && ((offset&(1024*disk_car->sector_size-1))==0))
+ if((offset&(1024*disk_car->sector_size-1))==0)
{
wmove(stdscr,9,0);
wclrtoeol(stdscr);
diff --git a/src/fat_cluster.h b/src/fat_cluster.h
index c890a42..a5b3d2f 100644
--- a/src/fat_cluster.h
+++ b/src/fat_cluster.h
@@ -42,7 +42,7 @@ struct cluster_offset_struct
unsigned int first_sol;
};
-int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *sectors_per_cluster, uint64_t *offset, const upart_type_t upart_type);
+int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind, unsigned int *sectors_per_cluster, uint64_t *offset, const upart_type_t upart_type);
upart_type_t no_of_cluster2part_type(const unsigned long int no_of_cluster);
int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const unsigned int nbr_sector_cluster,unsigned int *sectors_per_cluster, uint64_t *offset, const int verbose, const unsigned long int part_size_in_sectors, const upart_type_t upart_type);
diff --git a/src/tntfs.c b/src/tntfs.c
index 155bf5a..730a2f2 100644
--- a/src/tntfs.c
+++ b/src/tntfs.c
@@ -72,11 +72,146 @@ static void dump_NTFS(disk_t *disk_car, const partition_t *partition, const unsi
#endif
}
-int ntfs_boot_sector(disk_t *disk_car, partition_t *partition, const int verbose, const unsigned int expert, char **current_cmd)
+static int ntfs_boot_sector_command(char **current_cmd, const char *options)
+{
+ while(*current_cmd[0]==',')
+ (*current_cmd)++;
+ if(strncmp(*current_cmd,"rebuildbs",9)==0)
+ {
+ (*current_cmd)+=9;
+ return 'R';
+ }
+ else if(strncmp(*current_cmd,"dump",4)==0)
+ {
+ (*current_cmd)+=4;
+ return 'D';
+ }
+ else if(strncmp(*current_cmd,"list",4)==0)
+ {
+ (*current_cmd)+=4;
+ return 'L';
+ }
+ else if(strncmp(*current_cmd,"originalntfs",12)==0)
+ {
+ (*current_cmd)+=12;
+ if(strchr(options,'O')!=NULL)
+ return 'O';
+ }
+ else if(strncmp(*current_cmd,"backupntfs",10)==0)
+ {
+ (*current_cmd)+=10;
+ if(strchr(options,'B')!=NULL)
+ return 'B';
+ }
+ else if(strncmp(*current_cmd,"repairmft",9)==0)
+ {
+ (*current_cmd)+=9;
+ if(strchr(options,'M')!=NULL)
+ return 'M';
+ }
+ return 0;
+}
+
+static int is_no_confirm_command(char **current_cmd)
+{
+ while(*current_cmd[0]==',')
+ (*current_cmd)++;
+ if(strncmp(*current_cmd,"noconfirm",9)==0)
+ {
+ (*current_cmd)+=9;
+ return 1;
+ }
+ return 0;
+}
+
+static const char *ntfs_boot_sector_scan(disk_t *disk, partition_t *partition, unsigned char *buffer_bs, unsigned char *buffer_backup_bs, unsigned int *menu, const int verbose, const unsigned int expert)
+{
+ int identical_sectors;
+ int opt_B=0;
+ int opt_O=0;
+#ifdef HAVE_NCURSES
+ aff_copy(stdscr);
+ wmove(stdscr,4,0);
+ wprintw(stdscr,"%s",disk->description(disk));
+ mvwaddstr(stdscr,5,0,msg_PART_HEADER_LONG);
+ wmove(stdscr,6,0);
+ aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk,partition);
+#endif
+ log_info("\nntfs_boot_sector\n");
+ log_partition(disk,partition);
+ screen_buffer_add("Boot sector\n");
+ if(disk->pread(disk, buffer_bs, NTFS_BOOT_SECTOR_SIZE, partition->part_offset) != NTFS_BOOT_SECTOR_SIZE)
+ {
+ screen_buffer_add("ntfs_boot_sector: Can't read boot sector.\n");
+ memset(buffer_bs,0,NTFS_BOOT_SECTOR_SIZE);
+ }
+ if(test_NTFS(disk,(struct ntfs_boot_sector*)buffer_bs,partition,verbose,0)==0)
+ {
+ screen_buffer_add("Status: OK\n");
+ opt_O=1;
+ }
+ else
+ {
+ screen_buffer_add("Status: Bad\n");
+ }
+ screen_buffer_add("\nBackup boot sector\n");
+ if(disk->pread(disk, buffer_backup_bs, NTFS_BOOT_SECTOR_SIZE, partition->part_offset + partition->part_size - disk->sector_size) != NTFS_BOOT_SECTOR_SIZE)
+ {
+ screen_buffer_add("ntfs_boot_sector: Can't read backup boot sector.\n");
+ memset(buffer_backup_bs,0,NTFS_BOOT_SECTOR_SIZE);
+ }
+ if(test_NTFS(disk,(struct ntfs_boot_sector*)buffer_backup_bs,partition,verbose,0)==0)
+ {
+ screen_buffer_add("Status: OK\n");
+ opt_B=1;
+ }
+ else
+ {
+ screen_buffer_add("Status: Bad\n");
+ }
+ screen_buffer_add("\n");
+ if(memcmp(buffer_bs,buffer_backup_bs,NTFS_BOOT_SECTOR_SIZE)==0)
+ {
+ log_ntfs_info((const struct ntfs_boot_sector *)buffer_bs);
+ screen_buffer_add("Sectors are identical.\n");
+ identical_sectors=1;
+ }
+ else
+ {
+ log_ntfs2_info((const struct ntfs_boot_sector *)buffer_bs, (const struct ntfs_boot_sector *)buffer_backup_bs);
+ screen_buffer_add("Sectors are not identical.\n");
+ identical_sectors=0;
+ }
+ screen_buffer_add("\n");
+ screen_buffer_add("A valid NTFS Boot sector must be present in order to access\n");
+ screen_buffer_add("any data; even if the partition is not bootable.\n");
+ if(opt_B!=0 && opt_O!=0)
+ {
+ if(identical_sectors==0)
+ return "DOBRL";
+ else
+ return "DRML";
+ }
+ else if(opt_B!=0)
+ {
+ *menu=5;
+ if(expert>0)
+ return "DBRML";
+ else
+ return "DBRL";
+ }
+ else if(opt_O!=0)
+ {
+ *menu=4;
+ return "DORL";
+ }
+ return "DR";
+}
+
+int ntfs_boot_sector(disk_t *disk, partition_t *partition, const int verbose, const unsigned int expert, char **current_cmd)
{
unsigned char *buffer_bs;
unsigned char *buffer_backup_bs;
- const char *options="";
#ifdef HAVE_NCURSES
const struct MenuItem menu_ntfs[]=
{
@@ -92,142 +227,22 @@ int ntfs_boot_sector(disk_t *disk_car, partition_t *partition, const int verbose
{ 0, NULL, NULL }
};
#endif
- int no_confirm = 0;
buffer_bs=(unsigned char*)MALLOC(NTFS_BOOT_SECTOR_SIZE);
buffer_backup_bs=(unsigned char*)MALLOC(NTFS_BOOT_SECTOR_SIZE);
while(1)
{
unsigned int menu=0;
+ int no_confirm = 0;
int command;
+ const char *options;
screen_buffer_reset();
- {
- int identical_sectors=0;
- int opt_B=0;
- int opt_O=0;
-#ifdef HAVE_NCURSES
- aff_copy(stdscr);
- wmove(stdscr,4,0);
- wprintw(stdscr,"%s",disk_car->description(disk_car));
- mvwaddstr(stdscr,5,0,msg_PART_HEADER_LONG);
- wmove(stdscr,6,0);
- aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition);
-#endif
- log_info("\nntfs_boot_sector\n");
- log_partition(disk_car,partition);
- screen_buffer_add("Boot sector\n");
- if(disk_car->pread(disk_car, buffer_bs, NTFS_BOOT_SECTOR_SIZE, partition->part_offset) != NTFS_BOOT_SECTOR_SIZE)
- {
- screen_buffer_add("ntfs_boot_sector: Can't read boot sector.\n");
- memset(buffer_bs,0,NTFS_BOOT_SECTOR_SIZE);
- }
- if(test_NTFS(disk_car,(struct ntfs_boot_sector*)buffer_bs,partition,verbose,0)==0)
- {
- screen_buffer_add("Status: OK\n");
- opt_O=1;
- }
- else
- {
- screen_buffer_add("Status: Bad\n");
- }
- screen_buffer_add("\nBackup boot sector\n");
- if(disk_car->pread(disk_car, buffer_backup_bs, NTFS_BOOT_SECTOR_SIZE, partition->part_offset + partition->part_size - disk_car->sector_size) != NTFS_BOOT_SECTOR_SIZE)
- {
- screen_buffer_add("ntfs_boot_sector: Can't read backup boot sector.\n");
- memset(buffer_backup_bs,0,NTFS_BOOT_SECTOR_SIZE);
- }
- if(test_NTFS(disk_car,(struct ntfs_boot_sector*)buffer_backup_bs,partition,verbose,0)==0)
- {
- screen_buffer_add("Status: OK\n");
- opt_B=1;
- }
- else
- {
- screen_buffer_add("Status: Bad\n");
- }
- screen_buffer_add("\n");
- if(memcmp(buffer_bs,buffer_backup_bs,NTFS_BOOT_SECTOR_SIZE)==0)
- {
- log_ntfs_info((const struct ntfs_boot_sector *)buffer_bs);
- screen_buffer_add("Sectors are identical.\n");
- identical_sectors=1;
- }
- else
- {
- log_ntfs2_info((const struct ntfs_boot_sector *)buffer_bs, (const struct ntfs_boot_sector *)buffer_backup_bs);
- screen_buffer_add("Sectors are not identical.\n");
- identical_sectors=0;
- }
- screen_buffer_add("\n");
- screen_buffer_add("A valid NTFS Boot sector must be present in order to access\n");
- screen_buffer_add("any data; even if the partition is not bootable.\n");
- if(opt_B!=0 && opt_O!=0)
- {
- if(identical_sectors==0)
- options="DOBRL";
- else
- options="DRML";
- }
- else if(opt_B!=0)
- {
- menu=5;
- if(expert>0)
- options="DBRML";
- else
- options="DBRL";
- }
- else if(opt_O!=0)
- {
- menu=4;
- options="DORL";
- }
- else
- options="DR";
- }
+ options=ntfs_boot_sector_scan(disk, partition, buffer_bs, buffer_backup_bs, &menu, verbose, expert);
screen_buffer_to_log();
if(*current_cmd!=NULL)
{
- command=0;
- while(*current_cmd[0]==',')
- (*current_cmd)++;
- if(strncmp(*current_cmd,"rebuildbs",9)==0)
- {
- (*current_cmd)+=9;
- command='R';
- }
- else if(strncmp(*current_cmd,"dump",4)==0)
- {
- (*current_cmd)+=4;
- command='D';
- }
- else if(strncmp(*current_cmd,"list",4)==0)
- {
- (*current_cmd)+=4;
- command='L';
- }
- else if(strncmp(*current_cmd,"originalntfs",12)==0)
- {
- (*current_cmd)+=12;
- if(strchr(options,'O')!=NULL)
- command='O';
- }
- else if(strncmp(*current_cmd,"backupntfs",10)==0)
- {
- (*current_cmd)+=10;
- if(strchr(options,'B')!=NULL)
- command='B';
- }
- else if(strncmp(*current_cmd,"repairmft",9)==0)
- {
- (*current_cmd)+=9;
- if(strchr(options,'M')!=NULL)
- command='M';
- }
- else if(strncmp(*current_cmd,"noconfirm",9)==0)
- {
- (*current_cmd)+=9;
- no_confirm = 1;
- }
+ no_confirm=is_no_confirm_command(current_cmd);
+ command=ntfs_boot_sector_command(current_cmd, options);
}
else
{