summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2009-01-31 17:46:22 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2009-01-31 17:46:22 +0100
commit84767da6eb046b9256bbca169111bc2234bd37a5 (patch)
tree7e3ee89c7dc977b8a87b2fd181b508a27aacfa68 /src
parent56d98fd7a229c8839a364a8a194c89c8fa650fff (diff)
comp_FAT() cleanup
Diffstat (limited to 'src')
-rw-r--r--src/fat.c29
-rw-r--r--src/fat.h2
2 files changed, 14 insertions, 17 deletions
diff --git a/src/fat.c b/src/fat.c
index 54c4fb0..570193c 100644
--- a/src/fat.c
+++ b/src/fat.c
@@ -680,7 +680,7 @@ int test_FAT(disk_t *disk_car,const struct fat_boot_sector *fat_header, partitio
return 0;
}
-int comp_FAT(disk_t *disk_car,const partition_t *partition,const unsigned long int fat_size,const unsigned long int sect_res)
+int comp_FAT(disk_t *disk, const partition_t *partition, const unsigned long int fat_size, const unsigned long int sect_res)
{
/*
return 0 if FATs match
@@ -688,43 +688,42 @@ int comp_FAT(disk_t *disk_car,const partition_t *partition,const unsigned long i
unsigned int reste;
uint64_t hd_offset, hd_offset2;
unsigned char *buffer, *buffer2;
- buffer=(unsigned char *)MALLOC(NBR_SECT*disk_car->sector_size);
- buffer2=(unsigned char *)MALLOC(NBR_SECT*disk_car->sector_size);
- hd_offset=partition->part_offset+(uint64_t)sect_res*disk_car->sector_size;
- hd_offset2=hd_offset+(uint64_t)fat_size*disk_car->sector_size;
+ buffer=(unsigned char *)MALLOC(16*disk->sector_size);
+ buffer2=(unsigned char *)MALLOC(16*disk->sector_size);
+ hd_offset=partition->part_offset+(uint64_t)sect_res*disk->sector_size;
+ hd_offset2=hd_offset+(uint64_t)fat_size*disk->sector_size;
reste=(fat_size>1000?1000:fat_size); /* Quick check ! */
+ reste*=disk->sector_size;
while(reste>0)
{
- const unsigned int read_size=reste>NBR_SECT?NBR_SECT:reste;
+ const unsigned int read_size=(reste > 16 * disk->sector_size ? 16 * disk->sector_size :reste);
reste-=read_size;
- if(disk_car->pread(disk_car, buffer, read_size * disk_car->sector_size,
- hd_offset) != read_size * disk_car->sector_size)
+ if(disk->pread(disk, buffer, read_size, hd_offset) != read_size)
{
log_error("comp_FAT: can't read FAT1\n");
free(buffer2);
free(buffer);
return 1;
}
- if(disk_car->pread(disk_car, buffer2, read_size * disk_car->sector_size,
- hd_offset2) != read_size * disk_car->sector_size)
+ if(disk->pread(disk, buffer2, read_size, hd_offset2) != read_size)
{
log_error("comp_FAT: can't read FAT2\n");
free(buffer2);
free(buffer);
return 1;
}
- if(memcmp(buffer,buffer2,disk_car->sector_size*read_size)!=0)
+ if(memcmp(buffer, buffer2, read_size)!=0)
{
log_error("FAT differs, FAT sectors=%lu-%lu/%lu\n",
- (unsigned long) ((hd_offset-partition->part_offset)/disk_car->sector_size-sect_res),
- (unsigned long) ((hd_offset-partition->part_offset)/disk_car->sector_size-sect_res+read_size),
+ (unsigned long) ((hd_offset-partition->part_offset)/disk->sector_size-sect_res),
+ (unsigned long) ((hd_offset-partition->part_offset+read_size)/disk->sector_size-sect_res),
fat_size);
free(buffer2);
free(buffer);
return 1;
}
- hd_offset+=read_size*disk_car->sector_size;
- hd_offset2+=read_size*disk_car->sector_size;
+ hd_offset+=read_size;
+ hd_offset2+=read_size;
}
free(buffer2);
free(buffer);
diff --git a/src/fat.h b/src/fat.h
index 1d46c32..b3779da 100644
--- a/src/fat.h
+++ b/src/fat.h
@@ -33,8 +33,6 @@ extern "C" {
#define NTFS_NAME 0x03
#define OS2_NAME 0x03
-#define NBR_SECT 8
-
/*
* FAT partition boot sector information, taken from the Linux
* kernel sources.