summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2008-07-05 22:57:58 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2008-07-05 22:57:58 +0200
commita6b58b4150c20f4f3d1a6ebf80ce41d6ed16e4d5 (patch)
tree9d35982dc8ff9a13c8350ef3d63108d2f3864a89 /src
parent84cd4095ed29660b2258846da9a89f9c8bc2c5d7 (diff)
FAT: Fix confusion between cluster_size and sectors_per_cluster
Diffstat (limited to 'src')
-rw-r--r--src/fat.c28
-rw-r--r--src/fat.h2
-rw-r--r--src/fat_adv.c190
-rw-r--r--src/fat_dir.c27
-rw-r--r--src/fatp.c8
5 files changed, 128 insertions, 127 deletions
diff --git a/src/fat.c b/src/fat.c
index 5a8a438..b39bf3d 100644
--- a/src/fat.c
+++ b/src/fat.c
@@ -68,7 +68,7 @@ static void fat_set_part_name(partition_t *partition,const unsigned char *src,co
static int log_fat_info(const struct fat_boot_sector*fh1, const upart_type_t upart_type, const unsigned int sector_size)
{
log_info("sector_size %u\n", fat_sector_size(fh1));
- log_info("cluster_size %u\n", fh1->cluster_size);
+ log_info("cluster_size %u\n", fh1->sectors_per_cluster);
log_info("reserved %u\n", le16(fh1->reserved));
log_info("fats %u\n", fh1->fats);
log_info("dir_entries %u\n", get_dir_entries(fh1));
@@ -117,7 +117,7 @@ static int dump_fat_info_ncurses(const struct fat_boot_sector*fh1, const upart_t
wprintw(stdscr,"Not a FAT\n");
return 0;
}
- wprintw(stdscr,"cluster_size %u\n", fh1->cluster_size);
+ wprintw(stdscr,"cluster_size %u\n", fh1->sectors_per_cluster);
wprintw(stdscr,"reserved %u\n", le16(fh1->reserved));
if(sectors(fh1)!=0)
wprintw(stdscr,"sectors %u\n", sectors(fh1));
@@ -175,7 +175,7 @@ static int dump_2fat_info_ncurses(const struct fat_boot_sector*fh1, const struct
wprintw(stdscr,"Not a FAT\n");
return 1;
}
- wprintw(stdscr,"cluster_size %u %u\n", fh1->cluster_size, fh2->cluster_size);
+ wprintw(stdscr,"cluster_size %u %u\n", fh1->sectors_per_cluster, fh2->sectors_per_cluster);
wprintw(stdscr,"reserved %u %u\n", le16(fh1->reserved),le16(fh2->reserved));
if(sectors(fh1)!=0 || sectors(fh2)!=0)
wprintw(stdscr,"sectors %u %u\n", sectors(fh1), sectors(fh2));
@@ -237,7 +237,7 @@ int log_fat2_info(const struct fat_boot_sector*fh1, const struct fat_boot_sector
return 1;
}
log_info("sector_size %u %u\n", fat_sector_size(fh1),fat_sector_size(fh2));
- log_info("cluster_size %u %u\n", fh1->cluster_size,fh2->cluster_size);
+ log_info("cluster_size %u %u\n", fh1->sectors_per_cluster,fh2->sectors_per_cluster);
log_info("reserved %u %u\n", le16(fh1->reserved),le16(fh2->reserved));
log_info("fats %u %u\n", fh1->fats,fh2->fats);
log_info("dir_entries %u %u\n", get_dir_entries(fh1),get_dir_entries(fh2));
@@ -551,7 +551,7 @@ int test_FAT(disk_t *disk_car,const struct fat_boot_sector *fat_header, partitio
log_error("check_FAT: Incorrect number of bytes per sector %u (FAT) != %u (HD)\n",fat_sector_size(fat_header),disk_car->sector_size);
return 1;
}
- switch(fat_header->cluster_size)
+ switch(fat_header->sectors_per_cluster)
{
case 1:
case 2:
@@ -596,8 +596,8 @@ int test_FAT(disk_t *disk_car,const struct fat_boot_sector *fat_header, partitio
start_fat1=le16(fat_header->reserved);
start_fat2=start_fat1+(fat_header->fats>1?fat_length:0);
start_data=start_fat1+fat_header->fats*fat_length+(get_dir_entries(fat_header)*32+disk_car->sector_size-1)/disk_car->sector_size;
- no_of_cluster=(part_size-start_data)/fat_header->cluster_size;
- end_data=start_data+no_of_cluster*fat_header->cluster_size-1;
+ no_of_cluster=(part_size-start_data)/fat_header->sectors_per_cluster;
+ end_data=start_data+no_of_cluster*fat_header->sectors_per_cluster-1;
if(verbose>1)
{
log_info("number of cluster = %lu\n",no_of_cluster);
@@ -712,7 +712,7 @@ int test_FAT(disk_t *disk_car,const struct fat_boot_sector *fat_header, partitio
log_error("Bad root_cluster\n");
return 1;
}
- start_rootdir=start_data+(uint64_t)(le32(fat_header->root_cluster)-2)*fat_header->cluster_size;
+ start_rootdir=start_data+(uint64_t)(le32(fat_header->root_cluster)-2)*fat_header->sectors_per_cluster;
fat_length_calc=((no_of_cluster+2+disk_car->sector_size/4-1)*4/disk_car->sector_size);
partition->upart_type=UP_FAT32;
if(memcmp(buffer+FAT_NAME2,"FAT32 ",8)!=0)
@@ -750,7 +750,7 @@ int test_FAT(disk_t *disk_car,const struct fat_boot_sector *fat_header, partitio
log_info(" root cluster : %u",(unsigned int)le32(fat_header->root_cluster));
log_info("\nData : %lu-%lu\n", (long unsigned)start_data, (long unsigned)end_data);
log_info("sectors : %lu\n", (long unsigned)part_size);
- log_info("cluster_size : %u\n",fat_header->cluster_size);
+ log_info("cluster_size : %u\n", fat_header->sectors_per_cluster);
log_info("no_of_cluster : %lu (2 - %lu)\n", no_of_cluster,no_of_cluster+1);
log_info("fat_length %lu calculated %lu\n",fat_length,fat_length_calc);
}
@@ -911,14 +911,14 @@ int recover_FAT(disk_t *disk_car, const struct fat_boot_sector*fat_header, parti
int fat32_set_part_name(disk_t *disk_car, partition_t *partition, const struct fat_boot_sector*fat_header)
{
partition->fsname[0]='\0';
- if((fat_header->cluster_size>0)&&(fat_header->cluster_size<=128))
+ if((fat_header->sectors_per_cluster>0)&&(fat_header->sectors_per_cluster<=128))
{
- unsigned char *buffer=(unsigned char*)MALLOC(fat_header->cluster_size*disk_car->sector_size);
+ unsigned char *buffer=(unsigned char*)MALLOC(fat_header->sectors_per_cluster*disk_car->sector_size);
if(disk_car->read(disk_car,
- fat_header->cluster_size*disk_car->sector_size,
+ fat_header->sectors_per_cluster*disk_car->sector_size,
buffer,
partition->part_offset +
- (le16(fat_header->reserved)+fat_header->fats*le32(fat_header->fat32_length)+(uint64_t)(le32(fat_header->root_cluster)-2)*fat_header->cluster_size) * disk_car->sector_size))
+ (le16(fat_header->reserved)+fat_header->fats*le32(fat_header->fat32_length)+(uint64_t)(le32(fat_header->root_cluster)-2)*fat_header->sectors_per_cluster) * disk_car->sector_size))
{
log_error("fat32_set_part_name() cannot read FAT32 root cluster.\n");
}
@@ -926,7 +926,7 @@ int fat32_set_part_name(disk_t *disk_car, partition_t *partition, const struct f
{
int i;
int stop=0;
- for(i=0;(i<16*fat_header->cluster_size)&&(stop==0);i++)
+ for(i=0;(i<16*fat_header->sectors_per_cluster)&&(stop==0);i++)
{ /* Test attribut volume name and check if the volume name is erased or not */
if(((buffer[i*0x20+0xB] & ATTR_EXT) !=ATTR_EXT) && ((buffer[i*0x20+0xB] & ATTR_VOLUME) !=0) && (buffer[i*0x20]!=0xE5))
{
diff --git a/src/fat.h b/src/fat.h
index a5a54bc..b84a503 100644
--- a/src/fat.h
+++ b/src/fat.h
@@ -41,7 +41,7 @@ struct fat_boot_sector {
int8_t system_id[8]; /* 0x03 Name - can be used to special case
partition manager volumes */
uint8_t sector_size[2]; /* 0x0B bytes per logical sector */
- uint8_t cluster_size; /* 0x0D sectors/cluster */
+ uint8_t sectors_per_cluster; /* 0x0D sectors/cluster */
uint16_t reserved; /* 0x0E reserved sectors */
uint8_t fats; /* 0x10 number of FATs */
uint8_t dir_entries[2]; /* 0x11 root directory entries */
diff --git a/src/fat_adv.c b/src/fat_adv.c
index af7cafe..92944fd 100644
--- a/src/fat_adv.c
+++ b/src/fat_adv.c
@@ -80,7 +80,7 @@ struct info_offset_struct
struct cluster_offset_struct
{
- unsigned int cluster_size;
+ unsigned int sectors_per_cluster;
unsigned long int offset;
unsigned int nbr;
unsigned int first_sol;
@@ -91,17 +91,17 @@ static int fat_find_type(disk_t *disk_car,const partition_t *partition,const uin
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 upart_type_t no_of_cluster2part_type(const unsigned long int no_of_cluster);
-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 cluster_size, 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 cluster_size, 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 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 int write_FAT_boot_code_aux(unsigned char *buffer);
-static int find_cluster_size(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *cluster_size, uint64_t *offset);
+static 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);
static int find_dir_entries(disk_t *disk_car,const partition_t *partition, const unsigned int offset,const int verbose);
-static int find_cluster_size_aux(const sector_cluster_t *sector_cluster, const unsigned int nbr_sector_cluster,unsigned int *cluster_size, uint64_t *offset, const int verbose, const unsigned long int part_size_in_sectors);
+static 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);
static int analyse_dir_entries(disk_t *disk_car,const partition_t *partition, const unsigned int offset, const int verbose);
static int analyse_dir_entries2(disk_t *disk_car,const partition_t *partition, const unsigned int reserved, const unsigned int fat_length,const int verbose, unsigned int root_size_max,const upart_type_t upart_type, const unsigned int fats);
-static int calcul_cluster_size(const upart_type_t upart_type, const unsigned long int data_size, const unsigned int fat_length, const unsigned int sector_size);
+static int calcul_sectors_per_cluster(const upart_type_t upart_type, const unsigned long int data_size, const unsigned int fat_length, const unsigned int sector_size);
static int check_FAT_dir_entry(const unsigned char *entry, const unsigned int entry_nr);
-static int fat32_create_rootdir(disk_t *disk_car,const partition_t *partition, const unsigned int reserved, const unsigned int fat_length, const unsigned int root_cluster, const unsigned int cluster_size, const int verbose, file_data_t *rootdir_list, const unsigned int fats);
+static int fat32_create_rootdir(disk_t *disk_car,const partition_t *partition, const unsigned int reserved, const unsigned int fat_length, const unsigned int root_cluster, const unsigned int sectors_per_cluster, const int verbose, file_data_t *rootdir_list, const unsigned int fats);
static void fat_date_unix2dos(int unix_date,unsigned short *mstime, unsigned short *msdate);
static unsigned long int get_subdirectory(disk_t *disk_car,const uint64_t hd_offset, const unsigned long int i);
@@ -319,13 +319,14 @@ static int ask_root_directory(disk_t *disk_car, const partition_t *partition, co
}
#endif
-static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *partition,const unsigned int cluster_size, 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 interface, 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;
+ const unsigned int cluster_size=sectors_per_cluster*disk_car->sector_size;
if(verbose>0)
- log_trace("fat32_find_root_cluster(cluster_size=%u,no_of_cluster=%lu,reserved=%u,fat_length=%u,expert=%u,first_free_cluster=%u)\n",cluster_size,no_of_cluster,reserved,fat_length,expert,first_free_cluster);
- if(cluster_size==0)
+ log_trace("fat32_find_root_cluster(sectors_per_cluster=%u,no_of_cluster=%lu,reserved=%u,fat_length=%u,expert=%u,first_free_cluster=%u)\n",sectors_per_cluster,no_of_cluster,reserved,fat_length,expert,first_free_cluster);
+ if(sectors_per_cluster==0)
return 0;
{
file_data_t *rootdir_list=NULL;
@@ -334,7 +335,7 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
int interactive=1;
unsigned char *buffer;
int ind_stop=0;
- buffer=(unsigned char *)MALLOC(cluster_size*disk_car->sector_size);
+ buffer=(unsigned char *)MALLOC(cluster_size);
#ifdef HAVE_NCURSES
if(interface)
{
@@ -357,14 +358,14 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
ind_stop|=check_enter_key_or_s(stdscr);
}
#endif
- if(disk_car->read(disk_car,cluster_size*disk_car->sector_size, buffer,
- partition->part_offset+(start_data+(uint64_t)(root_cluster-2)*cluster_size)*disk_car->sector_size)==0)
+ if(disk_car->read(disk_car,cluster_size, buffer,
+ partition->part_offset+(start_data+(uint64_t)(root_cluster-2)*sectors_per_cluster)*disk_car->sector_size)==0)
{
if(verbose>1)
{
log_verbose("fat32_find_root_cluster test cluster=%lu\n",root_cluster);
/*
- dump_ncurses(buffer,cluster_size*disk_car->sector_size);
+ dump_ncurses(buffer,cluster_size);
*/
}
if((memcmp(&buffer[0],". ",8+3)==0) &&
@@ -378,8 +379,8 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
{
file_data_t *dir_list;
log_info("First-level directory found at cluster %lu\n",root_cluster);
- /* dump_ncurses(buffer,cluster_size*disk_car->sector_size); */
- dir_list=dir_fat_aux(buffer,cluster_size*disk_car->sector_size,cluster_size,0);
+ /* dump_ncurses(buffer,cluster_size); */
+ dir_list=dir_fat_aux(buffer, cluster_size, cluster_size, 0);
if(verbose>0)
{
dir_aff_log(disk_car, partition, NULL, dir_list);
@@ -403,7 +404,7 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
{ /* Potential root directory */
unsigned int i,found=1;
int etat=0,nb_subdir=0,nb_subdir_ok=0;
- for(i=0;found && (i<cluster_size*disk_car->sector_size/0x20);i++)
+ for(i=0;found && (i<cluster_size/0x20);i++)
{
int res=check_FAT_dir_entry(&buffer[i*0x20],i);
if(verbose>2)
@@ -430,7 +431,7 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
nb_subdir++;
}
}
- for(i=0;found && (i<16*cluster_size);i++)
+ for(i=0;found && (i<cluster_size/32);i++)
{
if((buffer[i*0x20]!=DELETED_FLAG) && (buffer[i*0x20+0xB]!= ATTR_EXT && (buffer[i*0x20+0xB]&ATTR_DIR)!=0)) /* Test directory */
{
@@ -439,7 +440,7 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
/* log_debug("cluster %u\n",cluster); */
if(cluster>2+no_of_cluster ||
get_subdirectory(disk_car,
- partition->part_offset+(start_data+(uint64_t)(cluster-2)*cluster_size) * disk_car->sector_size,
+ partition->part_offset+(start_data+(uint64_t)(cluster-2)*sectors_per_cluster) * disk_car->sector_size,
cluster)!=0)
{
/* if(verbose) */
@@ -476,15 +477,15 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
return new_root_cluster;
}
/* Read the cluster */
- if(disk_car->read(disk_car,cluster_size*disk_car->sector_size, buffer,
- partition->part_offset+(start_data+(uint64_t)(tmp-2)*cluster_size)*disk_car->sector_size)!=0)
+ if(disk_car->read(disk_car,cluster_size, buffer,
+ partition->part_offset+(start_data+(uint64_t)(tmp-2)*sectors_per_cluster)*disk_car->sector_size)!=0)
{
log_critical("cluster can't be read\n");
free(buffer);
return new_root_cluster;
}
/* Check if this cluster is a directory structure. FAT can be damaged */
- for(i=0;i<16*cluster_size;i++)
+ for(i=0;i<cluster_size/32;i++)
{
if(check_FAT_dir_entry(&buffer[i*0x20],i)!=1)
{
@@ -508,7 +509,7 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
}
{
file_data_t *dir_list;
- dir_list=dir_fat_aux(buffer,cluster_size*disk_car->sector_size,cluster_size,0);
+ dir_list=dir_fat_aux(buffer, cluster_size, cluster_size, 0);
if(dir_list!=NULL && (dir_list->next==NULL || dir_list->filestat.st_ino!=dir_list->next->filestat.st_ino))
{
int test_date=1;
@@ -560,7 +561,7 @@ static unsigned int fat32_find_root_cluster(disk_t *disk_car,const partition_t *
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)
{
root_cluster=first_free_cluster;
- fat32_create_rootdir(disk_car, partition, reserved, fat_length, root_cluster, cluster_size, verbose, rootdir_list, fats);
+ fat32_create_rootdir(disk_car, partition, reserved, fat_length, root_cluster, sectors_per_cluster, verbose, rootdir_list, fats);
}
}
delete_list_file(rootdir_list);
@@ -631,33 +632,34 @@ static int file2entry(struct msdos_dir_entry *de, const file_data_t *current_fil
return 0;
}
-static int fat32_create_rootdir(disk_t *disk_car,const partition_t *partition, const unsigned int reserved, const unsigned int fat_length, const unsigned int root_cluster, const unsigned int cluster_size, const int verbose, file_data_t *rootdir_list, const unsigned int fats)
+static int fat32_create_rootdir(disk_t *disk_car,const partition_t *partition, const unsigned int reserved, const unsigned int fat_length, const unsigned int root_cluster, const unsigned int sectors_per_cluster, const int verbose, file_data_t *rootdir_list, const unsigned int fats)
{
const uint64_t start_data=reserved+fats*fat_length;
+ const unsigned int cluster_size=disk_car->sector_size*sectors_per_cluster;
unsigned int current_entry=0;
unsigned int cluster;
unsigned char *buffer;
file_data_t *current_file;
if(verbose>0)
{
- log_trace("fat32_create_rootdir(reserved=%u,fat_length=%u,root_cluster=%u,cluster_size=%u)\n",reserved,fat_length,root_cluster,cluster_size);
+ log_trace("fat32_create_rootdir(reserved=%u,fat_length=%u,root_cluster=%u,sectors_per_cluster=%u)\n",reserved,fat_length,root_cluster,sectors_per_cluster);
}
cluster=root_cluster;
- buffer=(unsigned char *)MALLOC(disk_car->sector_size*cluster_size);
- memset(buffer,0,disk_car->sector_size*cluster_size);
+ buffer=(unsigned char *)MALLOC(cluster_size);
+ memset(buffer,0,cluster_size);
for(current_file=rootdir_list;current_file!=NULL;current_file=current_file->next)
{
file2entry((struct msdos_dir_entry*)buffer+current_entry,current_file);
- if(++current_entry==(disk_car->sector_size*cluster_size/sizeof(struct msdos_dir_entry)))
+ if(++current_entry==(cluster_size/sizeof(struct msdos_dir_entry)))
{
unsigned int next_cluster;
- if(disk_car->write(disk_car,disk_car->sector_size*cluster_size, buffer,
- partition->part_offset+(start_data+(uint64_t)(cluster-2)*cluster_size)*disk_car->sector_size)!=0)
+ if(disk_car->write(disk_car,cluster_size, buffer,
+ partition->part_offset+(start_data+(uint64_t)(cluster-2)*sectors_per_cluster)*disk_car->sector_size)!=0)
{
display_message("Write error: Can't create FAT32 root cluster.\n");
}
current_entry=0;
- memset(buffer,0,disk_car->sector_size*cluster_size);
+ memset(buffer,0,cluster_size);
/* FIXME need to write fat32_get_next_free_cluster */
next_cluster=cluster++;
set_next_cluster(disk_car,partition,UP_FAT32,reserved,cluster,next_cluster);
@@ -665,8 +667,8 @@ static int fat32_create_rootdir(disk_t *disk_car,const partition_t *partition, c
cluster=next_cluster;
}
}
- if(disk_car->write(disk_car,disk_car->sector_size*cluster_size, buffer,
- partition->part_offset+(start_data+(uint64_t)(cluster-2)*cluster_size)*disk_car->sector_size)!=0)
+ if(disk_car->write(disk_car,cluster_size, buffer,
+ partition->part_offset+(start_data+(uint64_t)(cluster-2)*sectors_per_cluster)*disk_car->sector_size)!=0)
{
display_message("Write error: Can't create FAT32 root cluster.\n");
}
@@ -675,7 +677,7 @@ static int fat32_create_rootdir(disk_t *disk_car,const partition_t *partition, c
#ifdef DEBUG
{
file_data_t *dir_list;
- dir_list=dir_fat_aux(buffer,disk_car->sector_size*cluster_size,cluster_size,0);
+ dir_list=dir_fat_aux(buffer, cluster_size, cluster_size, 0);
dir_aff_log(disk_car, partition, NULL, dir_list);
delete_list_file(dir_list);
}
@@ -814,8 +816,8 @@ static int analyse_dir_entries2(disk_t *disk_car,const partition_t *partition, c
}
{
uint64_t start_data=reserved+fats*fat_length+(root_size_max+(disk_car->sector_size/32)-1)/(disk_car->sector_size/32);
- unsigned int cluster_size=calcul_cluster_size(upart_type,partition->part_size/disk_car->sector_size-start_data,fat_length,disk_car->sector_size);
- dir_list=dir_fat_aux(buffer_dir, root_dir_size, cluster_size,
+ unsigned int sectors_per_cluster=calcul_sectors_per_cluster(upart_type,partition->part_size/disk_car->sector_size-start_data,fat_length,disk_car->sector_size);
+ dir_list=dir_fat_aux(buffer_dir, root_dir_size, sectors_per_cluster*disk_car->sector_size,
(partition->upart_type==UP_FAT12?FLAG_LIST_MASK12:FLAG_LIST_MASK16));
}
if(verbose>1)
@@ -834,13 +836,13 @@ static int analyse_dir_entries2(disk_t *disk_car,const partition_t *partition, c
for(dir_entries=(disk_car->sector_size/32);dir_entries<=root_size_max;dir_entries+=(disk_car->sector_size/32))
{
uint64_t start_data=reserved+fats*fat_length+(dir_entries+(disk_car->sector_size/32)-1)/(disk_car->sector_size/32);
- unsigned int cluster_size=calcul_cluster_size(upart_type,partition->part_size/disk_car->sector_size-start_data,fat_length,disk_car->sector_size);
+ unsigned int sectors_per_cluster=calcul_sectors_per_cluster(upart_type,partition->part_size/disk_car->sector_size-start_data,fat_length,disk_car->sector_size);
if(verbose>1)
{
- log_verbose("dir_entries %u, cluster_size %u\n",dir_entries,cluster_size);
+ log_verbose("dir_entries %u, sectors_per_cluster %u\n",dir_entries,sectors_per_cluster);
}
if(disk_car->read(disk_car, disk_car->sector_size, buffer_dir,
- partition->part_offset+(start_data+(uint64_t)(new_inode-2)*cluster_size)*disk_car->sector_size)==0)
+ partition->part_offset+(start_data+(uint64_t)(new_inode-2)*sectors_per_cluster)*disk_car->sector_size)==0)
{
if((memcmp(&buffer_dir[0],". ",8+3)==0)&&(memcmp(&buffer_dir[0x20],".. ",8+3)==0))
{
@@ -1039,7 +1041,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 cluster_size, 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 int interface, const upart_type_t upart_type, const unsigned int fats, char **current_cmd)
{
unsigned char *orgboot;
unsigned char *newboot;
@@ -1086,19 +1088,19 @@ static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, con
fat_header->hidden=le32(disk_car->CHS.sector);
else
fat_header->hidden=le32((partition->part_offset/disk_car->sector_size));
- fat_header->cluster_size=cluster_size;
+ fat_header->sectors_per_cluster=sectors_per_cluster;
fat_header->reserved=le16(reserved);
/* The filesystem size can be smaller than the partition size */
switch(upart_type)
{
case UP_FAT12:
- part_size=le16(fat_header->reserved)+fats*fat_length+dir_entries*32/disk_car->sector_size+cluster_size*(fat_length*disk_car->sector_size*2/3-2);
+ part_size=le16(fat_header->reserved)+fats*fat_length+dir_entries*32/disk_car->sector_size+sectors_per_cluster*(fat_length*disk_car->sector_size*2/3-2);
break;
case UP_FAT16:
- part_size=le16(fat_header->reserved)+fats*fat_length+dir_entries*32/disk_car->sector_size+cluster_size*(fat_length*(disk_car->sector_size/2)-2);
+ part_size=le16(fat_header->reserved)+fats*fat_length+dir_entries*32/disk_car->sector_size+sectors_per_cluster*(fat_length*(disk_car->sector_size/2)-2);
break;
case UP_FAT32:
- part_size=le16(fat_header->reserved)+fats*fat_length+cluster_size*(fat_length*(disk_car->sector_size/4)-2);
+ part_size=le16(fat_header->reserved)+fats*fat_length+sectors_per_cluster*(fat_length*(disk_car->sector_size/4)-2);
break;
default:
log_critical("create_fat_boot_sector: severe error\n");
@@ -1234,9 +1236,9 @@ static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, con
free(newboot);
}
-static int calcul_cluster_size(const upart_type_t upart_type, const unsigned long int data_size, const unsigned int fat_length, const unsigned int sector_size)
+static int calcul_sectors_per_cluster(const upart_type_t upart_type, const unsigned long int data_size, const unsigned int fat_length, const unsigned int sector_size)
{
- /* log_info("calcul_cluster_size data_size=%lu, fat_length=%u, sector_size=%u\n",data_size,fat_length,sector_size); */
+ /* log_info("calcul_sectors_per_cluster data_size=%lu, fat_length=%u, sector_size=%u\n",data_size,fat_length,sector_size); */
if(fat_length==0)
return 0;
switch(upart_type)
@@ -1248,7 +1250,7 @@ static int calcul_cluster_size(const upart_type_t upart_type, const unsigned lon
case UP_FAT32:
return up2power(data_size/(fat_length*sector_size/4-1));
default:
- log_critical("calcul_cluster_size: severe error\n");
+ log_critical("calcul_sectors_per_cluster: severe error\n");
return 0;
}
}
@@ -1846,7 +1848,7 @@ static upart_type_t select_fat_info(const info_offset_t *info_offset, const unsi
/* Using a couple of inodes of "." directory entries, get the cluster size and where the first cluster begins.
* */
-static int find_cluster_size(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *cluster_size, uint64_t *offset_org)
+static 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)
{
unsigned int nbr_subdir=0;
sector_cluster_t sector_cluster[10];
@@ -1868,7 +1870,7 @@ static int find_cluster_size(disk_t *disk_car, partition_t *partition, const int
skip_offset=(uint64_t)((partition->part_size-32*disk_car->sector_size)/disk_car->sector_size/128*1.5/disk_car->sector_size*2)*disk_car->sector_size;
if(verbose>0)
{
- log_verbose("find_cluster_size skip_sectors=%lu (skip_offset=%lu)\n",
+ log_verbose("find_sectors_per_cluster skip_sectors=%lu (skip_offset=%lu)\n",
(unsigned long)(skip_offset/disk_car->sector_size),
(unsigned long)skip_offset);
}
@@ -1904,10 +1906,10 @@ static int find_cluster_size(disk_t *disk_car, partition_t *partition, const int
}
free(buffer);
}
- return find_cluster_size_aux(sector_cluster,nbr_subdir,cluster_size,offset_org,verbose,partition->part_size/disk_car->sector_size);
+ return find_sectors_per_cluster_aux(sector_cluster,nbr_subdir,sectors_per_cluster,offset_org,verbose,partition->part_size/disk_car->sector_size);
}
-static int find_cluster_size_aux(const sector_cluster_t *sector_cluster, const unsigned int nbr_sector_cluster,unsigned int *cluster_size, uint64_t *offset, const int verbose, const unsigned long int part_size_in_sectors)
+static 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)
{
cluster_offset_t *cluster_offset;
unsigned int i,j;
@@ -1915,15 +1917,15 @@ static int find_cluster_size_aux(const sector_cluster_t *sector_cluster, const u
if(nbr_sector_cluster<2)
return 0;
cluster_offset=(cluster_offset_t *)MALLOC(nbr_sector_cluster*nbr_sector_cluster*sizeof(cluster_offset_t));
- log_info("find_cluster_size_aux\n");
+ log_info("find_sectors_per_cluster_aux\n");
for(i=0;i<nbr_sector_cluster-1;i++)
{
for(j=i+1;j<nbr_sector_cluster;j++)
{
if(sector_cluster[j].cluster > sector_cluster[i].cluster)
{
- unsigned int cluster_size_tmp=(sector_cluster[j].sector-sector_cluster[i].sector)/(sector_cluster[j].cluster-sector_cluster[i].cluster);
- switch(cluster_size_tmp)
+ unsigned int sectors_per_cluster_tmp=(sector_cluster[j].sector-sector_cluster[i].sector)/(sector_cluster[j].cluster-sector_cluster[i].cluster);
+ switch(sectors_per_cluster_tmp)
{
case 1:
case 2:
@@ -1933,27 +1935,27 @@ static int find_cluster_size_aux(const sector_cluster_t *sector_cluster, const u
case 32:
case 64:
case 128:
- if(sector_cluster[i].sector > (uint64_t)(sector_cluster[i].cluster-2) * cluster_size_tmp)
+ if(sector_cluster[i].sector > (uint64_t)(sector_cluster[i].cluster-2) * sectors_per_cluster_tmp)
{
unsigned int sol_cur;
unsigned int found=0;
- uint64_t offset_tmp=sector_cluster[i].sector-(uint64_t)(sector_cluster[i].cluster-2)*cluster_size_tmp;
+ uint64_t offset_tmp=sector_cluster[i].sector-(uint64_t)(sector_cluster[i].cluster-2)*sectors_per_cluster_tmp;
for(sol_cur=0;sol_cur<nbr_sol && !found;sol_cur++)
{
- if(cluster_offset[sol_cur].cluster_size==cluster_size_tmp &&
+ if(cluster_offset[sol_cur].sectors_per_cluster==sectors_per_cluster_tmp &&
cluster_offset[sol_cur].offset==offset_tmp)
{
if(cluster_offset[sol_cur].first_sol==i)
{
cluster_offset[sol_cur].nbr++;
}
- /* log_debug("cluster_size=%u offset=%lu nbr=%u\n",cluster_offset[sol_cur].cluster_size,cluster_offset[sol_cur].offset,cluster_offset[sol_cur].nbr); */
+ /* log_debug("sectors_per_cluster=%u offset=%lu nbr=%u\n",cluster_offset[sol_cur].sectors_per_cluster,cluster_offset[sol_cur].offset,cluster_offset[sol_cur].nbr); */
found=1;
}
}
if(!found)
{
- cluster_offset[nbr_sol].cluster_size=cluster_size_tmp;
+ cluster_offset[nbr_sol].sectors_per_cluster=sectors_per_cluster_tmp;
cluster_offset[nbr_sol].offset=offset_tmp;
cluster_offset[nbr_sol].nbr=1;
cluster_offset[nbr_sol].first_sol=i;
@@ -1972,11 +1974,11 @@ static int find_cluster_size_aux(const sector_cluster_t *sector_cluster, const u
{
if(verbose>0)
{
- log_verbose("cluster_size=%u offset=%lu nbr=%u ",
- cluster_offset[i].cluster_size,
+ log_verbose("sectors_per_cluster=%u offset=%lu nbr=%u ",
+ cluster_offset[i].sectors_per_cluster,
cluster_offset[i].offset,
cluster_offset[i].nbr);
- switch(no_of_cluster2part_type((part_size_in_sectors-cluster_offset[i].offset)/cluster_offset[i].cluster_size))
+ switch(no_of_cluster2part_type((part_size_in_sectors-cluster_offset[i].offset)/cluster_offset[i].sectors_per_cluster))
{
case UP_FAT12:
log_info("FAT : 12\n");
@@ -1994,14 +1996,14 @@ static int find_cluster_size_aux(const sector_cluster_t *sector_cluster, const u
if(cluster_offset[i].nbr>nbr_max)
{
nbr_max=cluster_offset[i].nbr;
- *cluster_size=cluster_offset[i].cluster_size;
+ *sectors_per_cluster=cluster_offset[i].sectors_per_cluster;
*offset=cluster_offset[i].offset;
}
}
free(cluster_offset);
if(nbr_max==0)
return 0;
- log_info("Selected: cluster_size=%u offset=%lu nbr=%u\n", *cluster_size,
+ log_info("Selected: sectors_per_cluster=%u offset=%lu nbr=%u\n", *sectors_per_cluster,
(long unsigned int)(*offset),nbr_max);
return 1;
}
@@ -2024,8 +2026,7 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
unsigned long int data_size;
unsigned long int max_offset;
unsigned int fat_length=0;
- unsigned int cluster_size_min=disk_car->sector_size;
- unsigned int cluster_size=0;
+ unsigned int sectors_per_cluster=0;
unsigned int reserved=0;
unsigned int dir_entries=0;
unsigned int fats=2;
@@ -2067,27 +2068,28 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
{
/* Set fat_length_max */
unsigned long int fat_length_max;
+ unsigned int sectors_per_cluster_min=disk_car->sector_size;
if(p_fat32)
{ /* Cluster 512 bytes */
- fat_length_max=partition->part_size/cluster_size_min*4;
+ fat_length_max=partition->part_size/sectors_per_cluster_min*4;
}
else
if(p_fat16)
{
- while(partition->part_size/cluster_size_min > (1<<16))
- cluster_size_min*=2;
- fat_length_max=partition->part_size/cluster_size_min*2;
+ while(partition->part_size/sectors_per_cluster_min > (1<<16))
+ sectors_per_cluster_min*=2;
+ fat_length_max=partition->part_size/sectors_per_cluster_min*2;
}
else
{
- while(partition->part_size/cluster_size_min > (1<<12))
- cluster_size_min*=2;
- fat_length_max=partition->part_size/cluster_size_min*1.5;
+ while(partition->part_size/sectors_per_cluster_min > (1<<12))
+ sectors_per_cluster_min*=2;
+ fat_length_max=partition->part_size/sectors_per_cluster_min*1.5;
}
fat_length_max=fat_length_max/disk_car->sector_size*disk_car->sector_size;
if(verbose>1)
{
- log_verbose("cluster_size_min %u sectors\n",cluster_size_min/disk_car->sector_size);
+ log_verbose("sectors_per_cluster_min %u sectors\n",sectors_per_cluster_min/disk_car->sector_size);
log_verbose("fat_length_max %ld sectors\n", fat_length_max/disk_car->sector_size);
}
max_offset=fat_length_max+64*disk_car->sector_size;
@@ -2160,17 +2162,17 @@ 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_cluster_size(disk_car, partition, verbose, dump_ind, interface,&cluster_size,&start_data)==0)
+ if(find_sectors_per_cluster(disk_car, partition, verbose, dump_ind, interface,&sectors_per_cluster,&start_data)==0)
{
display_message("Can't find cluster size\n");
return 0;
}
- if((cluster_size<=0) || (partition->part_size/disk_car->sector_size<=start_data))
+ if((sectors_per_cluster<=0) || (partition->part_size/disk_car->sector_size<=start_data))
{
display_message("Can't find cluster size\n");
return 0;
}
- upart_type=no_of_cluster2part_type((partition->part_size/disk_car->sector_size-start_data)/cluster_size);
+ upart_type=no_of_cluster2part_type((partition->part_size/disk_car->sector_size-start_data)/sectors_per_cluster);
switch(upart_type)
{
case UP_FAT12:
@@ -2266,29 +2268,29 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
data_size=partition->part_size/disk_car->sector_size-start_data;
/* Get Cluster Size */
{
- int old_cluster_size=cluster_size;
- cluster_size=calcul_cluster_size(upart_type,data_size,fat_length,disk_car->sector_size);
+ int old_sectors_per_cluster=sectors_per_cluster;
+ sectors_per_cluster=calcul_sectors_per_cluster(upart_type,data_size,fat_length,disk_car->sector_size);
if(verbose>0)
- log_info("cluster_size %u\n",cluster_size);
- if((cluster_size<=0)||(cluster_size>128))
+ log_info("sectors_per_cluster %u\n",sectors_per_cluster);
+ if((sectors_per_cluster<=0)||(sectors_per_cluster>128))
{
- if(old_cluster_size>0)
+ if(old_sectors_per_cluster>0)
{
- cluster_size=old_cluster_size;
+ sectors_per_cluster=old_sectors_per_cluster;
log_info("Assumes previous cluster size was good\n");
}
else
{
- cluster_size=0;
+ sectors_per_cluster=0;
}
}
if(expert>0)
{
#ifdef HAVE_NCURSES
wmove(stdscr, INTER_FAT_ASK_Y, INTER_FAT_ASK_X);
- cluster_size=ask_number(cluster_size,0,128,"cluster size ");
+ sectors_per_cluster=ask_number(sectors_per_cluster,0,128,"cluster size ");
#endif
- switch(cluster_size)
+ switch(sectors_per_cluster)
{
case 1:
case 2:
@@ -2300,11 +2302,11 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
case 128:
break;
default:
- cluster_size=0;
+ sectors_per_cluster=0;
break;
}
}
- if(cluster_size==0)
+ if(sectors_per_cluster==0)
{
display_message("Can't get cluster size\n");
return 0;
@@ -2313,14 +2315,14 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
if(upart_type==UP_FAT32)
{
/* Use first fat */
- fat32_free_info(disk_car,partition,reserved,data_size/cluster_size,&first_free_cluster,&free_cluster_count);
+ 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,cluster_size,data_size/cluster_size,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,interface,verbose,expert,first_free_cluster,fats);
if(expert>0)
{
#ifdef HAVE_NCURSES
wmove(stdscr, INTER_FAT_ASK_Y, INTER_FAT_ASK_X);
- root_cluster=ask_number(root_cluster,2,data_size/cluster_size+1,"root cluster ");
+ root_cluster=ask_number(root_cluster,2,data_size/sectors_per_cluster+1,"root cluster ");
#endif
if(verbose>1)
{
@@ -2336,7 +2338,7 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
wrefresh(stdscr);
}
#endif
- create_fat_boot_sector(disk_car,partition, reserved, verbose,dir_entries,root_cluster,cluster_size,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,interface,upart_type,fats,current_cmd);
if(verbose)
{
log_info("\n");
@@ -2454,7 +2456,7 @@ int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose
start_fat1=le16(fat_header->reserved);
fats=fat_header->fats;
start_data=start_fat1+fats*fat_length+(get_dir_entries(fat_header)*32+disk_car->sector_size-1)/disk_car->sector_size;
- no_of_cluster=(part_size-start_data)/fat_header->cluster_size;
+ no_of_cluster=(part_size-start_data)/fat_header->sectors_per_cluster;
fat32_root_cluster=le32(fat_header->root_cluster);
log_info("repair_FAT_table cluster=2..%lu\n",no_of_cluster+1);
free(buffer);
diff --git a/src/fat_dir.c b/src/fat_dir.c
index 14e93eb..e49e04d 100644
--- a/src/fat_dir.c
+++ b/src/fat_dir.c
@@ -334,7 +334,7 @@ static file_data_t *fat_dir(disk_t *disk_car, const partition_t *partition, dir_
const struct fat_dir_struct *ls=(const struct fat_dir_struct*)dir_data->private_dir_data;
const struct fat_boot_sector*fat_header=ls->boot_sector;
unsigned int cluster=first_cluster;
- if(fat_header->cluster_size<1)
+ if(fat_header->sectors_per_cluster<1)
{
log_error("FAT: Can't list files, bad cluster size.\n");
return NULL;
@@ -357,28 +357,28 @@ static file_data_t *fat_dir(disk_t *disk_car, const partition_t *partition, dir_
}
{
file_data_t *dir_list=NULL;
- const unsigned int cluster_size=fat_header->cluster_size;
- unsigned char *buffer_dir=(unsigned char *)MALLOC(fat_sector_size(fat_header)*cluster_size*10);
+ const unsigned int cluster_size=fat_header->sectors_per_cluster * fat_sector_size(fat_header);
+ unsigned char *buffer_dir=(unsigned char *)MALLOC(cluster_size*10);
unsigned int nbr_cluster;
int stop=0;
uint64_t start_fat1,start_data,part_size;
unsigned long int no_of_cluster,fat_length;
unsigned int fat_meth=FAT_FOLLOW_CLUSTER;
- memset(buffer_dir,0,fat_sector_size(fat_header)*cluster_size*10);
+ memset(buffer_dir,0,cluster_size*10);
fat_length=le16(fat_header->fat_length)>0?le16(fat_header->fat_length):le32(fat_header->fat32_length);
part_size=(sectors(fat_header)>0?sectors(fat_header):le32(fat_header->total_sect));
start_fat1=le16(fat_header->reserved);
start_data=start_fat1+fat_header->fats*fat_length+(get_dir_entries(fat_header)*32+disk_car->sector_size-1)/disk_car->sector_size;
- no_of_cluster=(part_size-start_data)/fat_header->cluster_size;
+ no_of_cluster=(part_size-start_data)/fat_header->sectors_per_cluster;
nbr_cluster=0;
while(!is_EOC(cluster, partition->upart_type) && cluster>=2 && nbr_cluster<10 && stop==0)
{
- uint64_t start=partition->part_offset+(uint64_t)(start_data+(cluster-2)*cluster_size)*fat_sector_size(fat_header);
+ uint64_t start=partition->part_offset+(uint64_t)(start_data+(cluster-2)*fat_header->sectors_per_cluster)*fat_sector_size(fat_header);
// if(dir_data->verbose>0)
{
log_info("FAT: cluster=%u(0x%x), pos=%lu\n",cluster,cluster,(long unsigned)(start/fat_sector_size(fat_header)));
}
- if(disk_car->read(disk_car, cluster_size*fat_sector_size(fat_header), buffer_dir+(uint64_t)fat_sector_size(fat_header)*cluster_size*nbr_cluster, start))
+ if(disk_car->read(disk_car, cluster_size, buffer_dir+(uint64_t)cluster_size*nbr_cluster, start))
{
log_error("FAT: Can't read directory cluster.\n");
stop=1;
@@ -418,7 +418,7 @@ static file_data_t *fat_dir(disk_t *disk_car, const partition_t *partition, dir_
}
}
if(nbr_cluster>0)
- dir_list=dir_fat_aux(buffer_dir, fat_sector_size(fat_header)*cluster_size*nbr_cluster, cluster_size, dir_data->param);
+ dir_list=dir_fat_aux(buffer_dir, cluster_size*nbr_cluster, cluster_size, dir_data->param);
free(buffer_dir);
return dir_list;
}
@@ -442,13 +442,12 @@ static file_data_t *fat1x_rootdir(disk_t *disk_car, const partition_t *partition
log_error("FAT 1x: Can't read root directory.\n");
/* Don't return yet, it may have been a partial read */
}
- res=dir_fat_aux(buffer_dir, root_size, fat_header->cluster_size, dir_data->param);
+ res=dir_fat_aux(buffer_dir, root_size, fat_header->sectors_per_cluster * fat_sector_size(fat_header), dir_data->param);
free(buffer_dir);
return res;
}
}
-
static void set_secwest(void)
{
struct tm *tmptr;
@@ -515,8 +514,8 @@ static int fat_copy(disk_t *disk_car, const partition_t *partition, dir_data_t *
FILE *f_out;
const struct fat_dir_struct *ls=(const struct fat_dir_struct*)dir_data->private_dir_data;
const struct fat_boot_sector *fat_header=ls->boot_sector;
- unsigned int cluster_size=fat_header->cluster_size;
- const unsigned int block_size=fat_sector_size(fat_header)*cluster_size;
+ const unsigned int sectors_per_cluster=fat_header->sectors_per_cluster;
+ const unsigned int block_size=fat_sector_size(fat_header)*sectors_per_cluster;
unsigned char *buffer_file=(unsigned char *)MALLOC(block_size);
unsigned int cluster;
unsigned int file_size=file->filestat.st_size;
@@ -539,11 +538,11 @@ static int fat_copy(disk_t *disk_car, const partition_t *partition, dir_data_t *
part_size=(sectors(fat_header)>0?sectors(fat_header):le32(fat_header->total_sect));
start_fat1=le16(fat_header->reserved);
start_data=start_fat1+fat_header->fats*fat_length+(get_dir_entries(fat_header)*32+disk_car->sector_size-1)/disk_car->sector_size;
- no_of_cluster=(part_size-start_data)/fat_header->cluster_size;
+ no_of_cluster=(part_size-start_data)/sectors_per_cluster;
while(cluster>=2 && cluster<=no_of_cluster+2 && file_size>0)
{
- uint64_t start=partition->part_offset+(uint64_t)(start_data+(cluster-2)*cluster_size)*fat_sector_size(fat_header);
+ const uint64_t start=partition->part_offset+(uint64_t)(start_data+(cluster-2)*sectors_per_cluster)*fat_sector_size(fat_header);
unsigned int toread = block_size;
if (toread > file_size)
toread = file_size;
diff --git a/src/fatp.c b/src/fatp.c
index aec1233..0294b8a 100644
--- a/src/fatp.c
+++ b/src/fatp.c
@@ -151,12 +151,12 @@ unsigned int fat_remove_used_space(disk_t *disk_car, const partition_t *partitio
part_size=(sectors(fat_header)>0?sectors(fat_header):le32(fat_header->total_sect));
start_fat1=le16(fat_header->reserved);
start_data=start_fat1+fat_header->fats*fat_length+(get_dir_entries(fat_header)*32+sector_size-1)/sector_size;
- no_of_cluster=(part_size-start_data)/fat_header->cluster_size;
+ no_of_cluster=(part_size-start_data)/fat_header->sectors_per_cluster;
if(partition->upart_type==UP_FAT16)
- fat16_remove_used_space(disk_car,partition, list_search_space, start_fat1, no_of_cluster, start_data, fat_header->cluster_size,sector_size);
+ fat16_remove_used_space(disk_car,partition, list_search_space, start_fat1, no_of_cluster, start_data, fat_header->sectors_per_cluster,sector_size);
else if(partition->upart_type==UP_FAT32)
- fat32_remove_used_space(disk_car,partition, list_search_space, start_fat1, no_of_cluster, start_data, fat_header->cluster_size,sector_size);
- res=fat_header->cluster_size * sector_size;
+ fat32_remove_used_space(disk_car,partition, list_search_space, start_fat1, no_of_cluster, start_data, fat_header->sectors_per_cluster,sector_size);
+ res=fat_header->sectors_per_cluster * sector_size;
free(buffer);
return res;
}