summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2009-01-31 17:07:08 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2009-01-31 17:07:08 +0100
commit56d98fd7a229c8839a364a8a194c89c8fa650fff (patch)
treefabc87d58b2ea35831496d5f9762f6b64b481072
parent9970a484b6983cbf5659ebf17335b4192065025e (diff)
Use pread() and pwrite() argument style for internal I/O
-rw-r--r--src/alignio.h20
-rw-r--r--src/analyse.c35
-rw-r--r--src/bfs.c2
-rw-r--r--src/bsd.c2
-rw-r--r--src/common.h4
-rw-r--r--src/cramfs.c2
-rw-r--r--src/dimage.c2
-rw-r--r--src/edit.c2
-rw-r--r--src/ewf.c18
-rw-r--r--src/ext2.c2
-rw-r--r--src/ext2_dir.c4
-rw-r--r--src/ext2_sbn.c2
-rw-r--r--src/ext2grp.c4
-rw-r--r--src/fat.c38
-rw-r--r--src/fat1x.c2
-rw-r--r--src/fat32.c8
-rw-r--r--src/fat_adv.c83
-rw-r--r--src/fat_dir.c9
-rw-r--r--src/fatp.c6
-rw-r--r--src/fatx.c2
-rw-r--r--src/godmode.c9
-rw-r--r--src/hdaccess.c49
-rw-r--r--src/hdcache.c145
-rw-r--r--src/hfs.c2
-rw-r--r--src/hfsp.c2
-rw-r--r--src/io_redir.c37
-rw-r--r--src/jfs.c2
-rw-r--r--src/luks.c2
-rw-r--r--src/lvm.c4
-rw-r--r--src/md.c12
-rw-r--r--src/msdos.c101
-rw-r--r--src/netware.c2
-rw-r--r--src/ntfs.c4
-rw-r--r--src/ntfs_adv.c18
-rw-r--r--src/ntfs_fix.c10
-rw-r--r--src/ntfs_io.c4
-rw-r--r--src/ntfsp.c2
-rw-r--r--src/partgpt.c12
-rw-r--r--src/parti386.c24
-rw-r--r--src/partmac.c4
-rw-r--r--src/partsun.c2
-rw-r--r--src/partxbox.c2
-rw-r--r--src/phrecn.c16
-rw-r--r--src/rfs.c2
-rw-r--r--src/rfs_dir.c4
-rw-r--r--src/savehdr.c2
-rw-r--r--src/sun.c2
-rw-r--r--src/swap.c2
-rw-r--r--src/sysv.c2
-rw-r--r--src/thfs.c8
-rw-r--r--src/tntfs.c8
-rw-r--r--src/ufs.c2
-rw-r--r--src/win32.c48
-rw-r--r--src/xfs.c2
54 files changed, 402 insertions, 392 deletions
diff --git a/src/alignio.h b/src/alignio.h
index fd2715d..3d1f08d 100644
--- a/src/alignio.h
+++ b/src/alignio.h
@@ -19,7 +19,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-static int align_read(int (*fnct_read)(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset),
+static int align_pread(int (*fnct_pread)(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset),
disk_t *disk_car, void*buf, const unsigned int count, const uint64_t offset)
{
const uint64_t offset_new=offset+disk_car->offset;
@@ -30,6 +30,7 @@ static int align_read(int (*fnct_read)(disk_t *disk_car, void *buf, const unsign
(buf!=disk_car->rbuffer || disk_car->rbuffer_size<count_new))
)
{
+ int res;
if(disk_car->rbuffer==NULL)
disk_car->rbuffer_size=128*512;
while(disk_car->rbuffer_size < count_new)
@@ -40,16 +41,15 @@ static int align_read(int (*fnct_read)(disk_t *disk_car, void *buf, const unsign
}
if(disk_car->rbuffer==NULL)
disk_car->rbuffer=(char*)MALLOC(disk_car->rbuffer_size);
- if(fnct_read(disk_car, disk_car->rbuffer, count_new, offset_new/disk_car->sector_size*disk_car->sector_size)<0)
- return -1;
+ res=fnct_pread(disk_car, disk_car->rbuffer, count_new, offset_new/disk_car->sector_size*disk_car->sector_size);
memcpy(buf,(char*)disk_car->rbuffer+(offset_new%disk_car->sector_size),count);
- return 0;
+ return (res < (signed)count ? res : (signed)count );
}
- return fnct_read(disk_car, buf, count_new, offset_new);
+ return fnct_pread(disk_car, buf, count, offset_new);
}
-static int align_write(int (*fnct_read)(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset),
- int (*fnct_write)(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset),
+static int align_pwrite(int (*fnct_pread)(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset),
+ int (*fnct_pwrite)(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset),
disk_t *disk_car, const void*buf, const unsigned int count, const uint64_t offset)
{
const uint64_t offset_new=offset+disk_car->offset;
@@ -69,14 +69,14 @@ static int align_write(int (*fnct_read)(disk_t *disk_car, void *buf, const unsig
}
if(disk_car->wbuffer==NULL)
disk_car->wbuffer=(char*)MALLOC(disk_car->wbuffer_size);
- if(fnct_read(disk_car, disk_car->wbuffer, count_new, offset_new/disk_car->sector_size*disk_car->sector_size)<0)
+ if(fnct_pread(disk_car, disk_car->wbuffer, count_new, offset_new/disk_car->sector_size*disk_car->sector_size)<0)
{
log_error("read failed but try to write anyway");
memset(disk_car->wbuffer,0, disk_car->wbuffer_size);
}
memcpy((char*)disk_car->wbuffer+(offset_new%disk_car->sector_size),buf,count);
- return fnct_write(disk_car, disk_car->wbuffer, count_new, offset_new/disk_car->sector_size*disk_car->sector_size);
+ return fnct_pwrite(disk_car, disk_car->wbuffer, count_new, offset_new/disk_car->sector_size*disk_car->sector_size);
}
- return fnct_write(disk_car, buf, count_new, offset_new);
+ return fnct_pwrite(disk_car, buf, count, offset_new);
}
diff --git a/src/analyse.c b/src/analyse.c
index 3ffee03..749ae02 100644
--- a/src/analyse.c
+++ b/src/analyse.c
@@ -63,7 +63,7 @@
int search_NTFS_backup(unsigned char *buffer, disk_t *disk_car,partition_t *partition, const int verbose, const int dump_ind)
{
// assert(sizeof(struct ntfs_boot_sector)<=DEFAULT_SECTOR_SIZE);
- if(disk_car->read(disk_car,DEFAULT_SECTOR_SIZE, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, DEFAULT_SECTOR_SIZE, partition->part_offset) != DEFAULT_SECTOR_SIZE)
return -1;
/* NTFS recovery using backup sector */
if(recover_NTFS(disk_car,(const struct ntfs_boot_sector*)buffer,partition,verbose,dump_ind,1)==0)
@@ -75,7 +75,7 @@ int search_HFS_backup(unsigned char *buffer, disk_t *disk_car,partition_t *parti
{
// assert(sizeof(hfs_mdb_t)<=0x400);
// assert(sizeof(struct hfsp_vh)==0x200);
- if(disk_car->read(disk_car,0x400, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, 0x400, partition->part_offset) != 0x400)
return -1;
/* HFS recovery using backup sector */
if(recover_HFS(disk_car,(const hfs_mdb_t*)buffer,partition,verbose,dump_ind,1)==0)
@@ -94,7 +94,7 @@ int search_HFS_backup(unsigned char *buffer, disk_t *disk_car,partition_t *parti
int search_FAT_backup(unsigned char *buffer, disk_t *disk_car,partition_t *partition, const int verbose, const int dump_ind)
{
// assert(sizeof(struct fat_boot_sector)==DEFAULT_SECTOR_SIZE);
- if(disk_car->read(disk_car,DEFAULT_SECTOR_SIZE, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, DEFAULT_SECTOR_SIZE, partition->part_offset) != DEFAULT_SECTOR_SIZE)
return -1;
/* FAT32 recovery using backup sector */
if(recover_FAT(disk_car,(const struct fat_boot_sector*)buffer,partition,verbose,dump_ind,1)==0)
@@ -118,7 +118,7 @@ int search_type_0(unsigned char *buffer,disk_t *disk_car,partition_t *partition,
{
log_trace("search_type_0 lba=%lu\n",(long unsigned)(partition->part_offset/disk_car->sector_size));
}
- if(disk_car->read(disk_car,8*DEFAULT_SECTOR_SIZE, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, 8 * DEFAULT_SECTOR_SIZE, partition->part_offset) != 8 * DEFAULT_SECTOR_SIZE)
return -1;
if(recover_Linux_SWAP(disk_car,(const union swap_header *)buffer,partition,verbose,dump_ind)==0) return 1;
if(recover_LVM(disk_car,(const pv_disk_t*)buffer,partition,verbose,dump_ind)==0) return 1;
@@ -153,7 +153,7 @@ int search_type_1(unsigned char *buffer, disk_t *disk_car,partition_t *partition
{
log_trace("search_type_1 lba=%lu\n",(long unsigned)(partition->part_offset/disk_car->sector_size));
}
- if(disk_car->read(disk_car,8*DEFAULT_SECTOR_SIZE, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, 8 * DEFAULT_SECTOR_SIZE, partition->part_offset) != 8 * DEFAULT_SECTOR_SIZE)
return -1;
if(recover_BSD(disk_car,(const struct disklabel *)(buffer+0x200),partition,verbose,dump_ind)==0) return 1;
if(recover_BeFS(disk_car,(const struct disk_super_block *)(buffer+0x200),partition,verbose,dump_ind)==0) return 1;
@@ -173,7 +173,7 @@ int search_type_2(unsigned char *buffer, disk_t *disk_car,partition_t *partition
{
log_trace("search_type_2 lba=%lu\n",(long unsigned)(partition->part_offset/disk_car->sector_size));
}
- if(disk_car->read(disk_car,1024, (buffer+0x400), partition->part_offset+1024)!=0)
+ if(disk_car->pread(disk_car, (buffer + 0x400), 1024, partition->part_offset + 1024) != 1024)
return -1;
if(recover_EXT2(disk_car,(const struct ext2_super_block*)(buffer+0x400),partition,verbose,dump_ind)==0) return 1;
if(recover_HFS(disk_car,(const hfs_mdb_t*)(buffer+0x400),partition,verbose,dump_ind,0)==0) return 1;
@@ -187,7 +187,7 @@ int search_type_8(unsigned char *buffer, disk_t *disk_car,partition_t *partition
{
log_trace("search_type_8 lba=%lu\n",(long unsigned)(partition->part_offset/disk_car->sector_size));
}
- if(disk_car->read(disk_car,4096, buffer, partition->part_offset+4096)!=0)
+ if(disk_car->pread(disk_car, buffer, 4096, partition->part_offset + 4096) != 4096)
return -1;
{ /* MD 1.2 */
const struct mdp_superblock_1 *sb1=(const struct mdp_superblock_1 *)buffer;
@@ -208,7 +208,7 @@ int search_type_16(unsigned char *buffer, disk_t *disk_car,partition_t *partitio
{
log_trace("search_type_16 lba=%lu\n",(long unsigned)(partition->part_offset/disk_car->sector_size));
}
- if(disk_car->read(disk_car,3*DEFAULT_SECTOR_SIZE, buffer, partition->part_offset+16*512)!=0) /* 8k offset */
+ if(disk_car->pread(disk_car, buffer, 3 * DEFAULT_SECTOR_SIZE, partition->part_offset + 16 * 512) != 3 * DEFAULT_SECTOR_SIZE) /* 8k offset */
return -1;
/* Test UFS */
if(recover_ufs(disk_car,(const struct ufs_super_block*)buffer,partition,verbose,dump_ind)==0) return 1;
@@ -223,15 +223,9 @@ int search_type_64(unsigned char *buffer, disk_t *disk_car,partition_t *partitio
log_trace("search_type_64 lba=%lu\n",(long unsigned)(partition->part_offset/disk_car->sector_size));
}
/* Test JFS */
-#if 0
- if(disk_car->read(disk_car,2*DEFAULT_SECTOR_SIZE, buffer, partition->part_offset+64*512)!=0) /* 32k offset */
- return -1;
- if(recover_JFS(disk_car,(const struct jfs_superblock*)buffer,partition,verbose,dump_ind)==0) return 1;
-#else
- if(disk_car->read(disk_car,3*DEFAULT_SECTOR_SIZE, buffer, partition->part_offset+63*512)!=0) /* 32k offset */
+ if(disk_car->pread(disk_car, buffer, 3 * DEFAULT_SECTOR_SIZE, partition->part_offset + 63 * 512) != 3 * DEFAULT_SECTOR_SIZE) /* 32k offset */
return -1;
if(recover_JFS(disk_car,(const struct jfs_superblock*)(buffer+0x200),partition,verbose,dump_ind)==0) return 1;
-#endif
return 0;
}
@@ -245,20 +239,11 @@ int search_type_128(unsigned char *buffer, disk_t *disk_car,partition_t *partiti
{
log_trace("search_type_128 lba=%lu\n",(long unsigned)(partition->part_offset/disk_car->sector_size));
}
-#if 0
/* Test ReiserFS */
- if(disk_car->read(disk_car,9*DEFAULT_SECTOR_SIZE, buffer, partition->part_offset+128*512)!=0) /* 64k offset */
- return -1;
- if(recover_rfs(disk_car,(const struct reiserfs_super_block*)buffer,partition,verbose,dump_ind)==0) return 1;
- /* Test UFS2 */
- if(recover_ufs(disk_car,(const struct ufs_super_block*)buffer,partition,verbose,dump_ind)==0) return 1;
-#else
- /* Test ReiserFS */
- if(disk_car->read(disk_car,11*DEFAULT_SECTOR_SIZE, buffer, partition->part_offset+126*512)!=0) /* 64k offset */
+ if(disk_car->pread(disk_car, buffer, 11 * DEFAULT_SECTOR_SIZE, partition->part_offset + 126 * 512) != 11 * DEFAULT_SECTOR_SIZE) /* 64k offset */
return -1;
if(recover_rfs(disk_car,(const struct reiserfs_super_block*)(buffer+0x400),partition,verbose,dump_ind)==0) return 1;
/* Test UFS2 */
if(recover_ufs(disk_car,(const struct ufs_super_block*)(buffer+0x400),partition,verbose,dump_ind)==0) return 1;
-#endif
return 0;
}
diff --git a/src/bfs.c b/src/bfs.c
index d1ffa34..3847f46 100644
--- a/src/bfs.c
+++ b/src/bfs.c
@@ -41,7 +41,7 @@ int check_BeFS(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer;
buffer=(unsigned char*)MALLOC(BFS_SUPERBLOCK_SIZE);
- if(disk_car->read(disk_car,BFS_SUPERBLOCK_SIZE, buffer, partition->part_offset+0x200)!=0)
+ if(disk_car->pread(disk_car, buffer, BFS_SUPERBLOCK_SIZE, partition->part_offset + 0x200) != BFS_SUPERBLOCK_SIZE)
{
free(buffer);
return 1;
diff --git a/src/bsd.c b/src/bsd.c
index 9bab4b3..c6526f4 100644
--- a/src/bsd.c
+++ b/src/bsd.c
@@ -40,7 +40,7 @@ int check_BSD(disk_t *disk_car,partition_t *partition,const int verbose, const u
{
unsigned char *buffer;
buffer=(unsigned char*)MALLOC(BSD_DISKLABEL_SIZE);
- if(disk_car->read(disk_car,BSD_DISKLABEL_SIZE, buffer, partition->part_offset+0x200))
+ if(disk_car->pread(disk_car, buffer, BSD_DISKLABEL_SIZE, partition->part_offset + 0x200) != BSD_DISKLABEL_SIZE)
{
free(buffer);
return 1;
diff --git a/src/common.h b/src/common.h
index de33c0b..6066848 100644
--- a/src/common.h
+++ b/src/common.h
@@ -311,8 +311,8 @@ struct param_disk_struct
char description_short_txt[DISKDESCRIPTION_MAX];
const char *(*description)(disk_t *disk_car);
const char *(*description_short)(disk_t *disk_car);
- int (*read)(disk_t *disk_car,const unsigned int count, void *buf, const uint64_t offset);
- int (*write)(disk_t *disk_car,const unsigned int count, const void *buf, const uint64_t offset);
+ int (*pread)(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset);
+ int (*pwrite)(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset);
int (*sync)(disk_t *disk_car);
int (*clean)(disk_t *disk_car);
const arch_fnct_t *arch;
diff --git a/src/cramfs.c b/src/cramfs.c
index dd61236..9ddf309 100644
--- a/src/cramfs.c
+++ b/src/cramfs.c
@@ -43,7 +43,7 @@ static int test_cramfs(const disk_t *disk_car, const struct cramfs_super *sb,par
int check_cramfs(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(CRAMFS_SUPERBLOCK_SIZE);
- if(disk_car->read(disk_car,CRAMFS_SUPERBLOCK_SIZE, buffer, partition->part_offset+0x200)!=0)
+ if(disk_car->pread(disk_car, buffer, CRAMFS_SUPERBLOCK_SIZE, partition->part_offset + 0x200) != CRAMFS_SUPERBLOCK_SIZE)
{
free(buffer);
return 1;
diff --git a/src/dimage.c b/src/dimage.c
index 81cc449..adbf910 100644
--- a/src/dimage.c
+++ b/src/dimage.c
@@ -102,7 +102,7 @@ int disk_image(disk_t *disk_car, const partition_t *partition, const char *image
int update=0;
if(offset_end-offset < READ_SIZE)
readsize=offset_end-offset;
- if(disk_car->read(disk_car, readsize, buffer_disk, offset)<0)
+ if(disk_car->pread(disk_car, buffer_disk, readsize, offset) != readsize)
{
update=1;
nbr_read_error++;
diff --git a/src/edit.c b/src/edit.c
index 8b2e5c8..7026c0d 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -79,7 +79,7 @@ static void interface_editor_ncurses(disk_t *disk_car)
wclrtoeol(stdscr);
wprintw(stdscr,"%lu ", (unsigned long)(hd_offset/disk_car->sector_size));
aff_LBA2CHS(disk_car,hd_offset/disk_car->sector_size);
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, hd_offset))
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, hd_offset) != disk_car->sector_size)
{
wprintw(stdscr,msg_PART_RD_ERR);
}
diff --git a/src/ewf.c b/src/ewf.c
index 5f1317e..361da99 100644
--- a/src/ewf.c
+++ b/src/ewf.c
@@ -58,8 +58,8 @@
static const char *fewf_description(disk_t *disk_car);
static const char *fewf_description_short(disk_t *disk_car);
static int fewf_clean(disk_t *disk_car);
-static int fewf_read(disk_t *disk_car, const unsigned int count, void *nom_buffer, const uint64_t offset);
-static int fewf_nowrite(disk_t *disk_car, const unsigned int count, const void *nom_buffer, const uint64_t offset);
+static int fewf_pread(disk_t *disk_car, const unsigned int count, void *nom_buffer, const uint64_t offset);
+static int fewf_nopwrite(disk_t *disk_car, const unsigned int count, const void *nom_buffer, const uint64_t offset);
static int fewf_sync(disk_t *disk_car);
struct info_fewf_struct
@@ -129,8 +129,8 @@ disk_t *fewf_init(const char *device, const int verbose, const arch_fnct_t *arch
disk_car->data=data;
disk_car->description=fewf_description;
disk_car->description_short=fewf_description_short;
- disk_car->read=fewf_read;
- disk_car->write=fewf_nowrite;
+ disk_car->pread=fewf_pread;
+ disk_car->pwrite=fewf_nopwrite;
disk_car->sync=fewf_sync;
disk_car->access_mode=TESTDISK_O_RDONLY;
disk_car->clean=fewf_clean;
@@ -216,14 +216,14 @@ static int fewf_sync(disk_t *disk_car)
return -1;
}
-static int fewf_read(disk_t *disk_car,const unsigned int count, void *nom_buffer, const uint64_t offset)
+static int fewf_pread(disk_t *disk_car,const unsigned int count, void *nom_buffer, const uint64_t offset)
{
struct info_fewf_struct *data=(struct info_fewf_struct *)disk_car->data;
int64_t taille;
taille=libewf_read_random(data->handle, nom_buffer, count, offset);
if(taille!=count)
{
- log_error("fewf_read(xxx,%u,buffer,%lu(%u/%u/%u)) read err: ",
+ log_error("fewf_pread(xxx,%u,buffer,%lu(%u/%u/%u)) read err: ",
(unsigned)(count/disk_car->sector_size), (long unsigned)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset), offset2head(disk_car,offset), offset2sector(disk_car,offset));
if(taille<0)
@@ -235,12 +235,12 @@ static int fewf_read(disk_t *disk_car,const unsigned int count, void *nom_buffer
if(taille<=0)
return -1;
}
- return 0;
+ return taille;
}
-static int fewf_nowrite(disk_t *disk_car,const unsigned int count, const void *nom_buffer, const uint64_t offset)
+static int fewf_nopwrite(disk_t *disk_car,const unsigned int count, const void *nom_buffer, const uint64_t offset)
{
- log_error("fewf_nowrite(xx,%u,buffer,%lu(%u/%u/%u)) write refused\n",
+ log_error("fewf_nopwrite(xx,%u,buffer,%lu(%u/%u/%u)) write refused\n",
(unsigned)(count/disk_car->sector_size), (long unsigned)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset), offset2head(disk_car,offset), offset2sector(disk_car,offset));
return -1;
diff --git a/src/ext2.c b/src/ext2.c
index e7a81ba..f522126 100644
--- a/src/ext2.c
+++ b/src/ext2.c
@@ -43,7 +43,7 @@ static int test_EXT2(const struct ext2_super_block *sb, partition_t *partition);
int check_EXT2(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(EXT2_SUPERBLOCK_SIZE);
- if(disk_car->read(disk_car,EXT2_SUPERBLOCK_SIZE, buffer, partition->part_offset+0x400)!=0)
+ if(disk_car->pread(disk_car, buffer, EXT2_SUPERBLOCK_SIZE, partition->part_offset + 0x400) != EXT2_SUPERBLOCK_SIZE)
{
free(buffer);
return 1;
diff --git a/src/ext2_dir.c b/src/ext2_dir.c
index 2745cb4..3dadcca 100644
--- a/src/ext2_dir.c
+++ b/src/ext2_dir.c
@@ -168,7 +168,7 @@ static errcode_t my_read_blk(io_channel channel, unsigned long block, int count,
log_trace("my_read_blk start size=%lu, offset=%lu name=%s\n",
(long unsigned)size, (unsigned long)(block*channel->block_size), my_data->partition->fsname);
#endif
- if(my_data->disk_car->read(my_data->disk_car,size,buf,my_data->partition->part_offset+(uint64_t)block*channel->block_size)!=0)
+ if(my_data->disk_car->pread(my_data->disk_car, buf, size, my_data->partition->part_offset + (uint64_t)block * channel->block_size) != size)
return 1;
#ifdef DEBUG
log_trace("my_read_blk done\n");
@@ -182,7 +182,7 @@ static errcode_t my_write_blk(io_channel channel, unsigned long block, int count
#if 1
{
my_data_t *my_data=(my_data_t*)channel;
- if(my_data->disk_car->write(my_data->disk_car,count*channel->block_size,buf,my_data->partition->part_offset+(uint64_t)block*channel->block_size)!=0)
+ if(my_data->disk_car->pwrite(my_data->disk_car, buf, count * channel->block_size, my_data->partition->part_offset + (uint64_t)block * channel->block_size) != count * channel->block_size)
return 1;
return 0;
}
diff --git a/src/ext2_sbn.c b/src/ext2_sbn.c
index 36c5baa..bfe08f5 100644
--- a/src/ext2_sbn.c
+++ b/src/ext2_sbn.c
@@ -98,7 +98,7 @@ list_part_t *search_superblock(disk_t *disk_car, const partition_t *partition, c
hd_offset%(5*(EXT2_MIN_BLOCK_SIZE<<2)*8*(EXT2_MIN_BLOCK_SIZE<<2))==0 ||
hd_offset%(7*(EXT2_MIN_BLOCK_SIZE<<2)*8*(EXT2_MIN_BLOCK_SIZE<<2))==0)
{
- if(disk_car->read(disk_car,1024, buffer, partition->part_offset+hd_offset)==0)
+ if(disk_car->pread(disk_car, buffer, 1024, partition->part_offset + hd_offset) == 1024)
{
if(le16(sb->s_magic)==EXT2_SUPER_MAGIC)
{
diff --git a/src/ext2grp.c b/src/ext2grp.c
index 61d421e..4e40bbd 100644
--- a/src/ext2grp.c
+++ b/src/ext2grp.c
@@ -57,7 +57,7 @@ unsigned int ext2_fix_group(alloc_data_t *list_search_space, disk_t *disk, parti
}
buffer=(unsigned char*)MALLOC(EXT2_SUPERBLOCK_SIZE);
- if(disk->read(disk,EXT2_SUPERBLOCK_SIZE, buffer, partition->part_offset+0x400)!=0)
+ if(disk->pread(disk, buffer, EXT2_SUPERBLOCK_SIZE, partition->part_offset + 0x400) != EXT2_SUPERBLOCK_SIZE)
{
free(buffer);
return 0;
@@ -94,7 +94,7 @@ unsigned int ext2_fix_inode(alloc_data_t *list_search_space, disk_t *disk, parti
}
buffer=(unsigned char*)MALLOC(EXT2_SUPERBLOCK_SIZE);
- if(disk->read(disk,EXT2_SUPERBLOCK_SIZE, buffer, partition->part_offset+0x400)!=0)
+ if(disk->pread(disk, buffer, EXT2_SUPERBLOCK_SIZE, partition->part_offset + 0x400) != EXT2_SUPERBLOCK_SIZE)
{
free(buffer);
return 0;
diff --git a/src/fat.c b/src/fat.c
index 1d114b2..54c4fb0 100644
--- a/src/fat.c
+++ b/src/fat.c
@@ -181,7 +181,7 @@ int check_FAT(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer;
buffer=(unsigned char *)MALLOC(3*disk_car->sector_size);
- if(disk_car->read(disk_car,3*disk_car->sector_size, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, 3 * disk_car->sector_size, partition->part_offset) != 3 * disk_car->sector_size)
{
screen_buffer_add("check_FAT: can't read FAT boot sector\n");
log_error("check_FAT: can't read FAT boot sector\n");
@@ -255,7 +255,8 @@ unsigned int get_next_cluster(disk_t *disk_car,const partition_t *partition, con
{
offset_s=(cluster+cluster/2)/disk_car->sector_size;
offset_o=(cluster+cluster/2)%disk_car->sector_size;
- if(disk_car->read(disk_car,2*disk_car->sector_size, buffer, partition->part_offset+(uint64_t)(offset+offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pread(disk_car, buffer, 2 * disk_car->sector_size,
+ partition->part_offset + (uint64_t)(offset + offset_s) * disk_car->sector_size) != 2 * disk_car->sector_size)
{
log_error("get_next_cluster read error\n");
free(buffer);
@@ -273,7 +274,8 @@ unsigned int get_next_cluster(disk_t *disk_car,const partition_t *partition, con
const uint16_t *p16=(const uint16_t*)buffer;
offset_s=cluster/(disk_car->sector_size/2);
offset_o=cluster%(disk_car->sector_size/2);
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, partition->part_offset+(uint64_t)(offset+offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size,
+ partition->part_offset + (uint64_t)(offset + offset_s) * disk_car->sector_size) != disk_car->sector_size)
{
log_error("get_next_cluster read error\n");
free(buffer);
@@ -288,7 +290,8 @@ unsigned int get_next_cluster(disk_t *disk_car,const partition_t *partition, con
const uint32_t *p32=(const uint32_t*)buffer;
offset_s=cluster/(disk_car->sector_size/4);
offset_o=cluster%(disk_car->sector_size/4);
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, partition->part_offset+(uint64_t)(offset+offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size,
+ partition->part_offset + (uint64_t)(offset + offset_s) * disk_car->sector_size) != disk_car->sector_size)
{
log_error("get_next_cluster read error\n");
free(buffer);
@@ -337,7 +340,8 @@ int set_next_cluster(disk_t *disk_car,const partition_t *partition, const upart_
free(buffer);
return 1;
}
- if(disk_car->read(disk_car,buffer_size, buffer, partition->part_offset+(uint64_t)(offset+offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pread(disk_car, buffer, buffer_size,
+ partition->part_offset + (uint64_t)(offset + offset_s) * disk_car->sector_size) != buffer_size)
{
log_error("set_next_cluster read error\n");
free(buffer);
@@ -371,7 +375,7 @@ int set_next_cluster(disk_t *disk_car,const partition_t *partition, const upart_
default: /* Avoid compiler warning */
break;
}
- if(disk_car->write(disk_car,buffer_size, buffer, partition->part_offset+(uint64_t)(offset+offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, buffer, buffer_size, partition->part_offset + (uint64_t)(offset + offset_s) * disk_car->sector_size) != buffer_size)
{
log_error("Write error: set_next_cluster write error\n");
free(buffer);
@@ -395,7 +399,7 @@ unsigned int fat32_get_prev_cluster(disk_t *disk_car,const partition_t *partitio
offset_o=prev_cluster%(disk_car->sector_size/4);
if((offset_o==0)||(prev_cluster==2))
{
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, hd_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, hd_offset) != disk_car->sector_size)
{
log_error("fat32_get_prev_cluster error\n"); return 0;
}
@@ -693,14 +697,16 @@ int comp_FAT(disk_t *disk_car,const partition_t *partition,const unsigned long i
{
const unsigned int read_size=reste>NBR_SECT?NBR_SECT:reste;
reste-=read_size;
- if(disk_car->read(disk_car,read_size*disk_car->sector_size, buffer, hd_offset))
+ if(disk_car->pread(disk_car, buffer, read_size * disk_car->sector_size,
+ hd_offset) != read_size * disk_car->sector_size)
{
log_error("comp_FAT: can't read FAT1\n");
free(buffer2);
free(buffer);
return 1;
}
- if(disk_car->read(disk_car,read_size*disk_car->sector_size, buffer2, hd_offset2))
+ if(disk_car->pread(disk_car, buffer2, read_size * disk_car->sector_size,
+ hd_offset2) != read_size * disk_car->sector_size)
{
log_error("comp_FAT: can't read FAT2\n");
free(buffer2);
@@ -820,11 +826,9 @@ static int fat32_set_part_name(disk_t *disk_car, partition_t *partition, const s
if((fat_header->sectors_per_cluster>0)&&(fat_header->sectors_per_cluster<=128))
{
unsigned char *buffer=(unsigned char*)MALLOC(fat_header->sectors_per_cluster*disk_car->sector_size);
- if(disk_car->read(disk_car,
- 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->sectors_per_cluster) * disk_car->sector_size))
+ if(disk_car->pread(disk_car, buffer,
+ fat_header->sectors_per_cluster * disk_car->sector_size,
+ 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->sectors_per_cluster) * disk_car->sector_size) != fat_header->sectors_per_cluster * disk_car->sector_size)
{
log_error("fat32_set_part_name() cannot read FAT32 root cluster.\n");
}
@@ -861,7 +865,7 @@ static int fat32_set_part_name(disk_t *disk_car, partition_t *partition, const s
int check_HPFS(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char buffer[512];
- if(disk_car->read(disk_car,disk_car->sector_size, &buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, &buffer, disk_car->sector_size, partition->part_offset) != disk_car->sector_size)
{
screen_buffer_add("check_HPFS: Read error\n");
log_error("check_HPFS: Read error\n");
@@ -920,7 +924,7 @@ int recover_HPFS(disk_t *disk_car,const struct fat_boot_sector*fat_header, parti
int check_OS2MB(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char buffer[0x200];
- if(disk_car->read(disk_car,disk_car->sector_size, &buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, &buffer, disk_car->sector_size, partition->part_offset) != disk_car->sector_size)
{
screen_buffer_add("check_OS2MB: Read error\n");
log_error("check_OS2MB: Read error\n");
@@ -1089,7 +1093,7 @@ int fat32_free_info(disk_t *disk_car,const partition_t *partition, const unsigne
offset_o=prev_cluster%(disk_car->sector_size/4);
if((offset_o==0)||(prev_cluster==2))
{
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, hd_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, hd_offset) != disk_car->sector_size)
{
log_error("fat32_free_info read error\n");
*next_free=0xFFFFFFFF;
diff --git a/src/fat1x.c b/src/fat1x.c
index e8beaef..1d82233 100644
--- a/src/fat1x.c
+++ b/src/fat1x.c
@@ -111,7 +111,7 @@ int fat1x_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos
log_info("\nfat1x_boot_sector\n");
log_partition(disk_car,partition);
screen_buffer_add("Boot sector\n");
- if(disk_car->read(disk_car,FAT1x_BOOT_SECTOR_SIZE, buffer_bs, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer_bs, FAT1x_BOOT_SECTOR_SIZE, partition->part_offset) != FAT1x_BOOT_SECTOR_SIZE)
{
screen_buffer_add("fat1x_boot_sector: Can't read boot sector.\n");
memset(buffer_bs,0,FAT1x_BOOT_SECTOR_SIZE);
diff --git a/src/fat32.c b/src/fat32.c
index b83da0f..0f23b10 100644
--- a/src/fat32.c
+++ b/src/fat32.c
@@ -119,7 +119,7 @@ int fat32_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos
log_info("\nfat32_boot_sector\n");
log_partition(disk_car,partition);
screen_buffer_add("Boot sector\n");
- if(disk_car->read(disk_car,3*disk_car->sector_size, buffer_bs, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer_bs, 3 * disk_car->sector_size, partition->part_offset) != 3 * disk_car->sector_size)
{
screen_buffer_add("fat32_boot_sector: Can't read boot sector.\n");
memset(buffer_bs,0,3*disk_car->sector_size);
@@ -142,7 +142,7 @@ int fat32_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos
screen_buffer_add("Bad\n");
}
screen_buffer_add("\nBackup boot sector\n");
- if(disk_car->read(disk_car,3*disk_car->sector_size, buffer_backup_bs, partition->part_offset+6*disk_car->sector_size)!=0)
+ if(disk_car->pread(disk_car, buffer_backup_bs, 3 * disk_car->sector_size, partition->part_offset + 6 * disk_car->sector_size) != 3 * disk_car->sector_size)
{
screen_buffer_add("fat32_boot_sector: Can't read backup boot sector.\n");
memset(buffer_backup_bs,0,3*disk_car->sector_size);
@@ -268,7 +268,7 @@ int fat32_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos
if(ask_confirmation("Copy original FAT32 boot sector over backup boot, confirm ? (Y/N)")!=0)
{
log_info("copy original boot sector over backup boot\n");
- if(disk_car->write(disk_car,3*disk_car->sector_size, buffer_bs, partition->part_offset+6*disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, buffer_bs, 3 * disk_car->sector_size, partition->part_offset + 6 * disk_car->sector_size) != 3 * disk_car->sector_size)
{
display_message("Write error: Can't overwrite FAT32 backup boot sector\n");
}
@@ -282,7 +282,7 @@ int fat32_boot_sector(disk_t *disk_car, partition_t *partition, const int verbos
if(ask_confirmation("Copy backup FAT32 boot sector over boot sector, confirm ? (Y/N)")!=0)
{
log_info("copy backup boot sector over boot sector\n");
- if(disk_car->write(disk_car,3*disk_car->sector_size, buffer_backup_bs, partition->part_offset)!=0)
+ if(disk_car->pwrite(disk_car, buffer_backup_bs, 3 * disk_car->sector_size, partition->part_offset) != 3 * disk_car->sector_size)
{
display_message("Write error: Can't overwrite FAT32 boot sector\n");
}
diff --git a/src/fat_adv.c b/src/fat_adv.c
index 9e4237a..a5cbfd7 100644
--- a/src/fat_adv.c
+++ b/src/fat_adv.c
@@ -172,7 +172,7 @@ static int check_FAT_dir_entry(const unsigned char *entry, const unsigned int en
static unsigned long int get_subdirectory(disk_t *disk_car,const uint64_t hd_offset,const unsigned long int i)
{
unsigned char buffer[DEFAULT_SECTOR_SIZE];
- if(disk_car->read(disk_car,sizeof(buffer), &buffer, hd_offset)!=0)
+ if(disk_car->pread(disk_car, &buffer, sizeof(buffer), hd_offset) != sizeof(buffer))
{
log_error("fat_dir, get_subdirectory(), can't read directory\n");
return 1;
@@ -356,8 +356,9 @@ 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, buffer,
- partition->part_offset+(start_data+(uint64_t)(root_cluster-2)*sectors_per_cluster)*disk_car->sector_size)==0)
+ if(disk_car->pread(disk_car, buffer, cluster_size,
+ partition->part_offset + (start_data + (uint64_t)(root_cluster - 2) * sectors_per_cluster) *
+ disk_car->sector_size) == cluster_size)
{
if(verbose>1)
{
@@ -475,8 +476,8 @@ 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, buffer,
- partition->part_offset+(start_data+(uint64_t)(tmp-2)*sectors_per_cluster)*disk_car->sector_size)!=0)
+ if(disk_car->pread(disk_car, buffer, cluster_size,
+ partition->part_offset + (start_data + (uint64_t)(tmp - 2) * sectors_per_cluster) * disk_car->sector_size) != cluster_size)
{
log_critical("cluster can't be read\n");
free(buffer);
@@ -653,8 +654,8 @@ static int fat32_create_rootdir(disk_t *disk_car,const partition_t *partition, c
if(++current_entry==(cluster_size/sizeof(struct msdos_dir_entry)))
{
unsigned int next_cluster;
- 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)
+ if(disk_car->pwrite(disk_car, buffer, cluster_size,
+ partition->part_offset + (start_data + (uint64_t)(cluster - 2) * sectors_per_cluster) * disk_car->sector_size) != cluster_size)
{
display_message("Write error: Can't create FAT32 root cluster.\n");
}
@@ -673,8 +674,8 @@ static int fat32_create_rootdir(disk_t *disk_car,const partition_t *partition, c
cluster=next_cluster;
}
}
- 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)
+ if(disk_car->pwrite(disk_car, buffer, cluster_size, partition->part_offset + (start_data + (uint64_t)(cluster - 2) * sectors_per_cluster) * disk_car->sector_size) != cluster_size
+ )
{
display_message("Write error: Can't create FAT32 root cluster.\n");
}
@@ -708,7 +709,7 @@ static int find_dir_entries(disk_t *disk_car,const partition_t *partition, const
hd_offset=partition->part_offset+(uint64_t)offset*disk_car->sector_size;
for(i=0; i<200 && i<offset; i++)
{
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, hd_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, hd_offset) != disk_car->sector_size)
{
log_error("dir_entries: read error, dir_entries>=%u (%u sectors)\n",i*(disk_car->sector_size/32),i);
}
@@ -763,7 +764,7 @@ static int analyse_dir_entries(disk_t *disk_car,const partition_t *partition, co
hd_offset=partition->part_offset+(uint64_t)offset*disk_car->sector_size;
for(i=0;i<200;i++)
{
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, hd_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, hd_offset) != disk_car->sector_size)
{
log_error("dir_entries: read error, dir_entries>=%u (%u sectors)\n",i*(disk_car->sector_size/32),i);
}
@@ -821,7 +822,8 @@ static int analyse_dir_entries2(disk_t *disk_car,const partition_t *partition, c
}
root_dir_size=(root_size_max*32+disk_car->sector_size-1)/disk_car->sector_size*disk_car->sector_size;
buffer_dir=(unsigned char *)MALLOC(root_dir_size);
- if(disk_car->read(disk_car, root_dir_size, buffer_dir, partition->part_offset+(uint64_t)(reserved+fats*fat_length)*disk_car->sector_size)!=0)
+ if(disk_car->pread(disk_car, buffer_dir, root_dir_size,
+ partition->part_offset + (uint64_t)(reserved + fats * fat_length) * disk_car->sector_size) != root_dir_size)
{
log_error("FAT 1x can't read root directory\n");
free(buffer_dir);
@@ -854,8 +856,8 @@ static int analyse_dir_entries2(disk_t *disk_car,const partition_t *partition, c
{
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)*sectors_per_cluster)*disk_car->sector_size)==0)
+ if(disk_car->pread(disk_car, buffer_dir, disk_car->sector_size,
+ partition->part_offset + (start_data + (uint64_t)(new_inode - 2) * sectors_per_cluster) * disk_car->sector_size) == disk_car->sector_size)
{
if((memcmp(&buffer_dir[0],". ",8+3)==0)&&(memcmp(&buffer_dir[0x20],".. ",8+3)==0))
{
@@ -1040,13 +1042,13 @@ static void menu_write_fat_boot_sector(disk_t *disk_car, partition_t *partition,
/* Write boot sector and backup boot sector */
if(upart_type==UP_FAT32)
{
- if(disk_car->write(disk_car,3*disk_car->sector_size, newboot, partition->part_offset)!=0 ||
- disk_car->write(disk_car,3*disk_car->sector_size, newboot, partition->part_offset+(uint64_t)le16(fat_header->backup_boot)*disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, newboot, 3 * disk_car->sector_size, partition->part_offset) != 3 * disk_car->sector_size ||
+ disk_car->pwrite(disk_car, newboot, 3 * disk_car->sector_size, partition->part_offset + (uint64_t)le16(fat_header->backup_boot) * disk_car->sector_size) != 3 * disk_car->sector_size)
err=1;
}
else
{
- if(disk_car->write(disk_car,DEFAULT_SECTOR_SIZE, newboot, partition->part_offset)!=0)
+ if(disk_car->pwrite(disk_car, newboot, DEFAULT_SECTOR_SIZE, partition->part_offset) != DEFAULT_SECTOR_SIZE)
err=1;
}
disk_car->sync(disk_car);
@@ -1072,7 +1074,7 @@ static void create_fat_boot_sector(disk_t *disk_car, partition_t *partition, con
newboot=(unsigned char *)MALLOC(3*disk_car->sector_size);
org_fat_header=(struct fat_boot_sector *)orgboot;
fat_header=(struct fat_boot_sector *)newboot;
- if(disk_car->read(disk_car,3*disk_car->sector_size, orgboot, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, orgboot, 3 * disk_car->sector_size, partition->part_offset) != 3 * disk_car->sector_size)
{
log_error("create_fat_boot_sector: Can't read old boot sector\n");
memset(orgboot,0,3*disk_car->sector_size);
@@ -1593,7 +1595,7 @@ static int fat_find_type(disk_t *disk_car,const partition_t *partition,const uin
ind_stop|=check_enter_key_or_s(stdscr);
}
#endif
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, partition->part_offset+offset)==0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, partition->part_offset + offset) == disk_car->sector_size)
{
unsigned long int fat_offset=0;
unsigned int fat_type;
@@ -1665,7 +1667,7 @@ static upart_type_t fat_find_info(disk_t *disk_car,unsigned int*reserved, unsign
if(dump_ind>0 && interface>0)
{
unsigned char *buffer=(unsigned char *)MALLOC(disk_car->sector_size);
- if(disk_car->read(disk_car,disk_car->sector_size, &buffer, end)==0)
+ if(disk_car->pread(disk_car, &buffer, disk_car->sector_size, end) == disk_car->sector_size)
{
dump_ncurses(buffer,disk_car->sector_size);
}
@@ -1904,7 +1906,7 @@ static int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, co
ind_stop|=check_enter_key_or_s(stdscr);
}
#endif
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, partition->part_offset+offset)==0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, partition->part_offset + offset) == disk_car->sector_size)
{
if(memcmp(&buffer[0],". ",8+3)==0 && memcmp(&buffer[0x20],".. ",8+3)==0)
{
@@ -2382,7 +2384,7 @@ int FAT_init_rootdir(disk_t *disk_car, partition_t *partition, const int verbose
}
buffer=(unsigned char *)MALLOC(disk_car->sector_size);
fat_header=(struct fat_boot_sector *)buffer;
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, partition->part_offset) != disk_car->sector_size)
{
display_message("FAT_init_rootdir: Can't read boot sector\n");
free(buffer);
@@ -2393,7 +2395,8 @@ int FAT_init_rootdir(disk_t *disk_car, partition_t *partition, const int verbose
start_data=start_rootdir+(get_dir_entries(fat_header)*32+disk_car->sector_size-1)/disk_car->sector_size;
for(sector=start_rootdir;error==0 && sector<start_data;sector++)
{
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, partition->part_offset+(uint64_t)sector*disk_car->sector_size)!=0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size,
+ partition->part_offset + (uint64_t)sector * disk_car->sector_size) != disk_car->sector_size)
{
log_error("FAT_init_rootdir: read error at sector %lu\n", sector);
}
@@ -2423,8 +2426,8 @@ int FAT_init_rootdir(disk_t *disk_car, partition_t *partition, const int verbose
memset(buffer,0,disk_car->sector_size);
for(sector=start_rootdir;sector<start_data;sector++)
{
- if(disk_car->write(disk_car,disk_car->sector_size, buffer,
- partition->part_offset+(uint64_t)sector*disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, buffer, disk_car->sector_size,
+ partition->part_offset + (uint64_t)sector * disk_car->sector_size) != disk_car->sector_size)
{
err=1;
}
@@ -2466,7 +2469,7 @@ int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose
unsigned char *buffer;
buffer=(unsigned char *)MALLOC(disk_car->sector_size);
fat_header=(struct fat_boot_sector *)buffer;
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, partition->part_offset) != disk_car->sector_size)
{
display_message("repair_FAT_table: Can't read boot sector\n");
return 1;
@@ -2627,8 +2630,8 @@ int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose
{
log_info("repair_FAT_table: correcting FAT%u (sector %lu) using FAT%u\n",fat_nbr+1,
start_fat1+fat_length*fat_nbr+old_offset_s, good_fat_nbr+1);
- if(disk_car->write(disk_car, rw_size, buffer_fat[good_fat_nbr],
- partition->part_offset+(uint64_t)(start_fat1+fat_length*fat_nbr+old_offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, buffer_fat[good_fat_nbr], rw_size,
+ partition->part_offset + (uint64_t)(start_fat1 + fat_length * fat_nbr + old_offset_s) * disk_car->sector_size) != rw_size)
{
display_message("repair_FAT_table: write failed.\n");
}
@@ -2659,8 +2662,8 @@ int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose
{
log_info("repair_FAT_table: correcting FAT%u (sector %lu)\n",fat_nbr+1,
start_fat1+fat_length*fat_nbr+old_offset_s);
- if(disk_car->write(disk_car, rw_size, buffer_fat[fat_nbr],
- partition->part_offset+(uint64_t)(start_fat1+fat_length*fat_nbr+old_offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, buffer_fat[fat_nbr], rw_size,
+ partition->part_offset + (uint64_t)(start_fat1 + fat_length * fat_nbr + old_offset_s) * disk_car->sector_size) != rw_size)
{
display_message("repair_FAT_table: write failed.\n");
}
@@ -2699,8 +2702,8 @@ int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose
}
if(allow_write[fat_nbr]==FAT_REPAIR_YES)
{
- if(disk_car->write(disk_car, rw_size, buffer_fat[fat_nbr],
- partition->part_offset+(uint64_t)(start_fat1+fat_length*fat_nbr+old_offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, buffer_fat[fat_nbr], rw_size,
+ partition->part_offset + (uint64_t)(start_fat1 + fat_length * fat_nbr + old_offset_s) * disk_car->sector_size) != rw_size )
{
display_message("repair_FAT_table: write failed.\n");
}
@@ -2717,8 +2720,8 @@ int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose
{
log_info("repair_FAT_table: read sector %lu (FAT%u)\n",(start_fat1+fat_length*fat_nbr+offset_s),fat_nbr+1);
}
- if(disk_car->read(disk_car, rw_size,
- buffer_fat[fat_nbr], partition->part_offset+(uint64_t)(start_fat1+fat_length*fat_nbr+offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pread(disk_car, buffer_fat[fat_nbr], rw_size,
+ partition->part_offset + (uint64_t)(start_fat1 + fat_length * fat_nbr + offset_s) * disk_car->sector_size) != rw_size)
{
log_error("repair_FAT_table: read error sector %lu\n",(start_fat1+fat_length*fat_nbr+offset_s));
memset(buffer_fat[fat_nbr],0, rw_size);
@@ -2871,8 +2874,8 @@ int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose
}
if(allow_write[fat_nbr]==FAT_REPAIR_YES)
{
- if(disk_car->write(disk_car, rw_size, buffer_fat[good_fat_nbr],
- partition->part_offset+(uint64_t)(start_fat1+fat_length*fat_nbr+old_offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, buffer_fat[good_fat_nbr], rw_size,
+ partition->part_offset + (uint64_t)(start_fat1 + fat_length * fat_nbr + old_offset_s) * disk_car->sector_size) != rw_size)
{
display_message("repair_FAT_table: write failed.\n");
}
@@ -2903,8 +2906,8 @@ int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose
}
if(allow_write[fat_nbr]==FAT_REPAIR_YES)
{
- if(disk_car->write(disk_car, rw_size, buffer_fat[fat_nbr],
- partition->part_offset+(uint64_t)(start_fat1+fat_length*fat_nbr+old_offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, buffer_fat[fat_nbr], rw_size,
+ partition->part_offset + (uint64_t)(start_fat1 + fat_length * fat_nbr + old_offset_s) * disk_car->sector_size) != rw_size)
{
display_message("repair_FAT_table: write failed.\n");
}
@@ -2943,8 +2946,8 @@ int repair_FAT_table(disk_t *disk_car, partition_t *partition, const int verbose
}
if(allow_write[fat_nbr]==FAT_REPAIR_YES)
{
- if(disk_car->write(disk_car, rw_size, buffer_fat[fat_nbr],
- partition->part_offset+(uint64_t)(start_fat1+fat_length*fat_nbr+old_offset_s)*disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, buffer_fat[fat_nbr], rw_size,
+ partition->part_offset + (uint64_t)(start_fat1 + fat_length * fat_nbr + old_offset_s) * disk_car->sector_size) != rw_size)
{
display_message("repair_FAT_table: write failed.\n");
}
diff --git a/src/fat_dir.c b/src/fat_dir.c
index ed2f930..06ae3ac 100644
--- a/src/fat_dir.c
+++ b/src/fat_dir.c
@@ -380,7 +380,7 @@ static file_data_t *fat_dir(disk_t *disk_car, const partition_t *partition, dir_
{
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, buffer_dir+(uint64_t)cluster_size*nbr_cluster, start))
+ if(disk_car->pread(disk_car, buffer_dir + (uint64_t)cluster_size * nbr_cluster, cluster_size, start) != cluster_size)
{
log_error("FAT: Can't read directory cluster.\n");
stop=1;
@@ -446,7 +446,7 @@ static file_data_t *fat1x_rootdir(disk_t *disk_car, const partition_t *partition
unsigned char *buffer_dir;
buffer_dir=(unsigned char*)MALLOC(root_size);
start=partition->part_offset+(uint64_t)((le16(fat_header->reserved)+fat_header->fats*le16(fat_header->fat_length))*disk_car->sector_size);
- if(disk_car->read(disk_car, root_size, buffer_dir, start))
+ if(disk_car->pread(disk_car, buffer_dir, root_size, start) != root_size)
{
log_error("FAT 1x: Can't read root directory.\n");
/* Don't return yet, it may have been a partial read */
@@ -485,8 +485,9 @@ int dir_partition_fat_init(disk_t *disk_car, const partition_t *partition, dir_d
static unsigned char *buffer;
static struct fat_dir_struct *ls;
buffer=(unsigned char*)MALLOC(0x200);
- if(disk_car->read(disk_car,0x200, buffer, partition->part_offset))
+ if(disk_car->pread(disk_car, buffer, 0x200, partition->part_offset) != 0x200)
{
+ log_error("Can't read FAT boot sector.\n");
free(buffer);
return -1;
}
@@ -554,7 +555,7 @@ static int fat_copy(disk_t *disk_car, const partition_t *partition, dir_data_t *
unsigned int toread = block_size;
if (toread > file_size)
toread = file_size;
- if(disk_car->read(disk_car, toread, buffer_file, start)<0)
+ if(disk_car->pread(disk_car, buffer_file, toread, start) != toread)
{
log_error("fat_copy: Can't read cluster %u.\n", cluster);
}
diff --git a/src/fatp.c b/src/fatp.c
index 5f90309..32f627c 100644
--- a/src/fatp.c
+++ b/src/fatp.c
@@ -57,7 +57,7 @@ static void fat16_remove_used_space(disk_t *disk_car,const partition_t *partitio
offset_o=prev_cluster%(sector_size/2);
if((offset_o==0)||(prev_cluster==2))
{
- if(disk_car->read(disk_car, sector_size, buffer, hd_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, sector_size, hd_offset) != sector_size)
{
/* Consider these FAT sectors points to free clusters */
}
@@ -100,7 +100,7 @@ static void fat32_remove_used_space(disk_t *disk_car,const partition_t *partitio
offset_o=prev_cluster%(sector_size/4);
if((offset_o==0)||(prev_cluster==2))
{
- if(disk_car->read(disk_car,sector_size, buffer, hd_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, sector_size, hd_offset) != sector_size)
{
/* Consider these FAT sectors points to free clusters */
}
@@ -139,7 +139,7 @@ unsigned int fat_remove_used_space(disk_t *disk_car, const partition_t *partitio
const struct fat_boot_sector *fat_header;
buffer=(unsigned char *)MALLOC(3*disk_car->sector_size);
fat_header=(const struct fat_boot_sector *)buffer;
- if(disk_car->read(disk_car,3*disk_car->sector_size, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, 3 * disk_car->sector_size, partition->part_offset) != 3 * disk_car->sector_size)
{
free(buffer);
return 0;
diff --git a/src/fatx.c b/src/fatx.c
index 02f9750..cb6fe55 100644
--- a/src/fatx.c
+++ b/src/fatx.c
@@ -45,7 +45,7 @@ static int test_fatx(disk_t *disk_car, const struct disk_fatx *fatx_block,partit
int check_FATX(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char buffer[8*DEFAULT_SECTOR_SIZE];
- if(disk_car->read(disk_car,sizeof(buffer), &buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, &buffer, sizeof(buffer), partition->part_offset) != sizeof(buffer))
{ return 1; }
if(test_fatx(disk_car,(const struct disk_fatx *)&buffer,partition,verbose,0)!=0)
return 1;
diff --git a/src/godmode.c b/src/godmode.c
index 9f0368a..13df273 100644
--- a/src/godmode.c
+++ b/src/godmode.c
@@ -535,7 +535,7 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
{
if(search_now_raid>0 || fast_mode>1)
{ /* Search Linux software RAID */
- if(disk_car->read(disk_car,8*DEFAULT_SECTOR_SIZE, buffer_disk, search_location)!=0)
+ if(disk_car->pread(disk_car, buffer_disk, 8 * DEFAULT_SECTOR_SIZE, search_location) != 8 * DEFAULT_SECTOR_SIZE)
{
res = -1;
}
@@ -622,7 +622,7 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
if((disk_car->arch==&arch_i386 && start_ext2.sector==1 && (start_ext2.head<=2 || fast_mode>1)) ||
(disk_car->arch!=&arch_i386 && search_location%location_boundary==0))
{
- if(disk_car->read(disk_car,1024, buffer_disk, search_location)==0)
+ if(disk_car->pread(disk_car, buffer_disk, 1024, search_location) == 1024)
{
const struct ext2_super_block *sb=(const struct ext2_super_block*)buffer_disk;
if(le16(sb->s_block_group_nr)>0)
@@ -674,7 +674,8 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
if(res<=0 && test_nbr==11)
{
/* read to fill the cache */
- disk_car->read(disk_car,8*DEFAULT_SECTOR_SIZE, buffer_disk, partition->part_offset+(63+16)*512);
+ disk_car->pread(disk_car, buffer_disk, 8 * DEFAULT_SECTOR_SIZE,
+ partition->part_offset + (63 + 16) * 512);
/* Try to catch disklabel before BSD FFS partition */
res=search_type_128(buffer_disk,disk_car,partition,verbose,dump_ind);
test_nbr++;
@@ -832,7 +833,7 @@ static list_part_t *search_part(disk_t *disk_car, const list_part_t *list_part_o
{
partition->part_size=(uint64_t)0;
partition->part_offset=element->part->part_offset - i * disk_car->sector_size;
- if(disk_car->read(disk_car, DEFAULT_SECTOR_SIZE, buffer_disk, partition->part_offset)==0)
+ if(disk_car->pread(disk_car, buffer_disk, DEFAULT_SECTOR_SIZE, partition->part_offset) == DEFAULT_SECTOR_SIZE)
{
if(recover_NTFS(disk_car,(const struct ntfs_boot_sector*)buffer_disk,partition,verbose,dump_ind,0)==0)
{
diff --git a/src/hdaccess.c b/src/hdaccess.c
index af3fcf8..7c06ccb 100644
--- a/src/hdaccess.c
+++ b/src/hdaccess.c
@@ -122,9 +122,9 @@ static void autoset_geometry(disk_t * disk_car, const unsigned char *buffer, con
static const char *file_description(disk_t *disk_car);
static const char *file_description_short(disk_t *disk_car);
static int file_clean(disk_t *disk_car);
-static int file_read(disk_t *disk_car, const unsigned int count, void *buf, const uint64_t offset);
-static int file_write(disk_t *disk_car, const unsigned int count, const void *buf, const uint64_t offset);
-static int file_nowrite(disk_t *disk_car, const unsigned int count, const void *buf, const uint64_t offset);
+static int file_pread(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset);
+static int file_pwrite(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset);
+static int file_nopwrite(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset);
static int file_sync(disk_t *disk_car);
#ifndef DJGPP
static uint64_t compute_device_size(const int hd_h, const char *device, const int verbose, const unsigned int sector_size);
@@ -1065,7 +1065,7 @@ static int file_clean(disk_t *disk_car)
return generic_clean(disk_car);
}
-static int file_read_aux(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset)
+static int file_pread_aux(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset)
{
long int ret=-1;
int fd=((struct info_file_struct *)disk_car->data)->handle;
@@ -1077,7 +1077,7 @@ static int file_read_aux(disk_t *disk_car, void *buf, const unsigned int count,
#ifdef __MINGW32__
if(_lseeki64(fd,offset,SEEK_SET)==-1)
{
- log_error("file_read(%d,%u,buffer,%lu(%u/%u/%u)) seek err %s\n", fd,
+ log_error("file_pread(%d,%u,buffer,%lu(%u/%u/%u)) seek err %s\n", fd,
(unsigned)(count/disk_car->sector_size), (long unsigned int)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset), offset2head(disk_car,offset), offset2sector(disk_car,offset),
strerror(errno));
@@ -1086,7 +1086,7 @@ static int file_read_aux(disk_t *disk_car, void *buf, const unsigned int count,
#else
if(lseek(fd,offset,SEEK_SET)==(off_t)-1)
{
- log_error("file_read(%d,%u,buffer,%lu(%u/%u/%u)) lseek err %s\n", fd,
+ log_error("file_pread(%d,%u,buffer,%lu(%u/%u/%u)) lseek err %s\n", fd,
(unsigned)(count/disk_car->sector_size), (long unsigned int)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset), offset2head(disk_car,offset), offset2sector(disk_car,offset),
strerror(errno));
@@ -1113,7 +1113,7 @@ static int file_read_aux(disk_t *disk_car, void *buf, const unsigned int count,
{
if(offset+count <= disk_car->disk_size && offset+count <= disk_car->disk_real_size)
{
- log_error("file_read(%d,%u,buffer,%lu(%u/%u/%u)) read err: ", fd,
+ log_error("file_pread(%d,%u,buffer,%lu(%u/%u/%u)) read err: ", fd,
(unsigned)(count/disk_car->sector_size), (long unsigned)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset), offset2head(disk_car,offset), offset2sector(disk_car,offset));
if(ret<0)
@@ -1124,18 +1124,21 @@ static int file_read_aux(disk_t *disk_car, void *buf, const unsigned int count,
log_error("Partial read\n");
}
if(ret<=0)
+ {
+ memset(buf, 0, count);
return -1;
+ }
memset((char*)buf+ret,0,count-ret);
}
- return 0;
+ return ret;
}
-static int file_read(disk_t *disk_car,const unsigned int count, void *buf, const uint64_t offset)
+static int file_pread(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset)
{
- return align_read(&file_read_aux, disk_car, buf, count, offset);
+ return align_pread(&file_pread_aux, disk_car, buf, count, offset);
}
-static int file_write_aux(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset)
+static int file_pwrite_aux(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset)
{
int fd=((struct info_file_struct *)disk_car->data)->handle;
long int ret=-1;
@@ -1147,7 +1150,7 @@ static int file_write_aux(disk_t *disk_car, const void *buf, const unsigned int
#ifdef __MINGW32__
if(_lseeki64(fd,offset,SEEK_SET)==-1)
{
- log_error("file_write(%d,%u,buffer,%lu(%u/%u/%u)) seek err %s\n", fd,
+ log_error("file_pwrite(%d,%u,buffer,%lu(%u/%u/%u)) seek err %s\n", fd,
(unsigned)(count/disk_car->sector_size),
(long unsigned)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset),offset2head(disk_car,offset),offset2sector(disk_car,offset),strerror(errno));
@@ -1156,7 +1159,7 @@ static int file_write_aux(disk_t *disk_car, const void *buf, const unsigned int
#else
if(lseek(fd,offset,SEEK_SET)==-1)
{
- log_error("file_write(%d,%u,buffer,%lu(%u/%u/%u)) seek err %s\n", fd,(unsigned)(count/disk_car->sector_size),(long unsigned)(offset/disk_car->sector_size),
+ log_error("file_pwrite(%d,%u,buffer,%lu(%u/%u/%u)) seek err %s\n", fd,(unsigned)(count/disk_car->sector_size),(long unsigned)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset),offset2head(disk_car,offset),offset2sector(disk_car,offset),strerror(errno));
return -1;
}
@@ -1166,22 +1169,22 @@ static int file_write_aux(disk_t *disk_car, const void *buf, const unsigned int
disk_car->write_used=1;
if(ret!=count)
{
- log_error("file_write(%d,%u,buffer,%lu(%u/%u/%u)) write err %s\n", fd,(unsigned)(count/disk_car->sector_size),(long unsigned)(offset/disk_car->sector_size),
+ log_error("file_pwrite(%d,%u,buffer,%lu(%u/%u/%u)) write err %s\n", fd,(unsigned)(count/disk_car->sector_size),(long unsigned)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset),offset2head(disk_car,offset),offset2sector(disk_car,offset),(ret<0?strerror(errno):"File truncated"));
return -1;
}
- return 0;
+ return ret;
}
-static int file_write(disk_t *disk_car, const unsigned int count, const void *buf, const uint64_t offset)
+static int file_pwrite(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset)
{
- return align_write(&file_read_aux, &file_write_aux, disk_car, buf, count, offset);
+ return align_pwrite(&file_pread_aux, &file_pwrite_aux, disk_car, buf, count, offset);
}
-static int file_nowrite(disk_t *disk_car,const unsigned int count, const void *buf, const uint64_t offset)
+static int file_nopwrite(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset)
{
struct info_file_struct *data=(struct info_file_struct *)disk_car->data;
- log_warning("file_nowrite(%d,%u,buffer,%lu(%u/%u/%u)) write refused\n", data->handle,
+ log_warning("file_nopwrite(%d,%u,buffer,%lu(%u/%u/%u)) write refused\n", data->handle,
(unsigned)(count/disk_car->sector_size),(long unsigned)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset),offset2head(disk_car,offset),offset2sector(disk_car,offset));
return -1;
@@ -1354,8 +1357,8 @@ disk_t *file_test_availability(const char *device, const int verbose, const arch
disk_car->data=data;
disk_car->description=file_description;
disk_car->description_short=file_description_short;
- disk_car->read=file_read;
- disk_car->write=((mode&O_RDWR)==O_RDWR?file_write:file_nowrite);
+ disk_car->pread=file_pread;
+ disk_car->pwrite=((mode&O_RDWR)==O_RDWR?file_pwrite:file_nopwrite);
disk_car->sync=file_sync;
disk_car->access_mode=((mode&O_RDWR)==O_RDWR?TESTDISK_O_RDWR:TESTDISK_O_RDONLY);
#ifdef O_DIRECT
@@ -1474,7 +1477,7 @@ void hd_update_geometry(disk_t *disk_car, const int allow_partial_last_cylinder,
buffer=(unsigned char *)MALLOC(disk_car->sector_size);
if(disk_car->autodetect!=0)
{
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, 0)==0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, 0) == disk_car->sector_size)
{
if(verbose>1)
{
@@ -1506,7 +1509,7 @@ void hd_update_geometry(disk_t *disk_car, const int allow_partial_last_cylinder,
data->geo_phys.cylinders=0;
}
#endif
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, pos)>=0)
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, pos) == 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)
diff --git a/src/hdcache.c b/src/hdcache.c
index 2804559..f54d1fe 100644
--- a/src/hdcache.c
+++ b/src/hdcache.c
@@ -52,87 +52,86 @@ struct cache_struct
{
disk_t *disk_car;
struct cache_buffer_struct cache[CACHE_BUFFER_NBR];
+#ifdef DEBUG_CACHE
uint64_t nbr_fnct_sect;
- uint64_t nbr_read_sect;
+ uint64_t nbr_pread_sect;
unsigned int nbr_fnct_call;
- unsigned int nbr_read_call;
+ unsigned int nbr_pread_call;
+#endif
unsigned int cache_buffer_nbr;
unsigned int cache_size_min;
unsigned int last_io_error_nbr;
};
-static int cache_read(disk_t *disk_car,const unsigned int count, void *nom_buffer, const uint64_t offset);
-static int cache_write(disk_t *disk_car,const unsigned int count, const void *nom_buffer, const uint64_t offset);
+static int cache_pread_aux(disk_t *disk_car, void *buffer, const unsigned int count, const uint64_t offset, const unsigned int read_ahead);
+static int cache_pread(disk_t *disk_car, void *buffer, const unsigned int count, const uint64_t offset);
+static int cache_pwrite(disk_t *disk_car, const void *buffer, const unsigned int count, const uint64_t offset);
static int cache_sync(disk_t *clean);
static int cache_clean(disk_t *clean);
static const char *cache_description(disk_t *disk_car);
static const char *cache_description_short(disk_t *disk_car);
-static int cache_read_aux(disk_t *disk_car,const unsigned int count, void *nom_buffer, const uint64_t offset, const unsigned int read_ahead);
-static int cache_read(disk_t *disk_car,const unsigned int count, void *nom_buffer, const uint64_t offset)
+static int cache_pread(disk_t *disk_car, void *buffer, const unsigned int count, const uint64_t offset)
{
const struct cache_struct *data=(const struct cache_struct *)disk_car->data;
- return cache_read_aux(disk_car, count, nom_buffer, offset, (data->last_io_error_nbr==0));
+ return cache_pread_aux(disk_car, buffer, count, offset, (data->last_io_error_nbr==0));
}
-static int cache_read_aux(disk_t *disk_car,const unsigned int count, void *nom_buffer, const uint64_t offset, const unsigned int read_ahead)
+static int cache_pread_aux(disk_t *disk_car, void *buffer, const unsigned int count, const uint64_t offset, const unsigned int read_ahead)
{
struct cache_struct *data=(struct cache_struct *)disk_car->data;
#ifdef DEBUG_CACHE
- log_trace("cache_read(count=%u,buffer,offset=%llu)\n", count,(long long unsigned)offset);
-#endif
+ log_info("cache_pread(buffer, count=%u, offset=%llu, read_ahead=%u)\n", count,(long long unsigned)offset, read_ahead);
data->nbr_fnct_call++;
+#endif
{
unsigned int i;
/* Data is probably in the last two buffers */
unsigned int cache_buffer_nbr=(data->cache_buffer_nbr+CACHE_BUFFER_NBR-1)%CACHE_BUFFER_NBR;
for(i=0;i<CACHE_BUFFER_NBR;i++,cache_buffer_nbr=(cache_buffer_nbr+1)%CACHE_BUFFER_NBR)
{
- struct cache_buffer_struct *cache=&data->cache[cache_buffer_nbr];
+ const struct cache_buffer_struct *cache=&data->cache[cache_buffer_nbr];
if(cache->buffer!=NULL && cache->cache_size>0 &&
cache->cache_offset <= offset &&
offset < cache->cache_offset +cache->cache_size)
{
- const unsigned data_available=cache->cache_offset +cache->cache_size-offset;
+ const unsigned int data_available= cache->cache_size + cache->cache_offset - offset;
+ const int res=cache->cache_status + cache->cache_offset - offset;
#ifdef DEBUG_CACHE
if(cache_buffer_nbr==data->cache_buffer_nbr)
- log_trace("hit\n");
+ log_info("hit ");
else
- log_trace("bid\n");
- log_trace("use cache %u count=%u, offset=%llu\n",i,
- cache->cache_size, cache->cache_offset);
+ log_info("bid ");
#endif
if(count<=data_available)
{
+#ifdef DEBUG_CACHE
+ log_info("cache use %5u count=%u, coffset=%llu, cstatus=%d\n",
+ cache_buffer_nbr, cache->cache_size, (long long unsigned)cache->cache_offset,
+ cache->cache_status);
data->nbr_fnct_sect+=count;
- memcpy(nom_buffer, cache->buffer+offset-cache->cache_offset, count);
- return cache->cache_status;
+#endif
+ memcpy(buffer, cache->buffer + offset - cache->cache_offset, count);
+ return (res < (signed)count ? res : (signed)count );
}
else
{
- int newres;
- int res=cache->cache_status;
+#ifdef DEBUG_CACHE
+ log_info("cache USE %5u count=%u, coffset=%llu, ctstatus=%d, call again cache_pread_aux\n",
+ cache_buffer_nbr, cache->cache_size, (long long unsigned)cache->cache_offset,
+ cache->cache_status);
data->nbr_fnct_sect+=data_available;
- memcpy(nom_buffer, cache->buffer+offset-cache->cache_offset, data_available);
- newres=cache_read_aux(disk_car, count-data_available,
- (unsigned char*)nom_buffer+data_available, offset+data_available, read_ahead);
- if(res>=0)
- res=newres;
- return res;
+#endif
+ memcpy(buffer, cache->buffer + offset - cache->cache_offset, data_available);
+ return res + cache_pread_aux(disk_car, (unsigned char*)buffer+data_available,
+ count-data_available, offset+data_available, read_ahead);
}
}
}
}
{
struct cache_buffer_struct *cache;
- int res;
const unsigned int count_new=(read_ahead!=0 && count<data->cache_size_min && (offset+data->cache_size_min<data->disk_car->disk_real_size)?data->cache_size_min:count);
- data->nbr_fnct_sect+=count;
- data->nbr_read_call++;
- data->nbr_read_sect+=count_new;
-#ifdef DEBUG_CACHE
- log_trace("read(count=%u,buffer,offset=%llu)\n", count_new,(long long unsigned)offset);
-#endif
data->cache_buffer_nbr=(data->cache_buffer_nbr+1)%CACHE_BUFFER_NBR;
cache=&data->cache[data->cache_buffer_nbr];
if(cache->buffer_size < count_new)
@@ -145,47 +144,52 @@ static int cache_read_aux(disk_t *disk_car,const unsigned int count, void *nom_b
cache->buffer_size=(count_new<CACHE_DEFAULT_SIZE?CACHE_DEFAULT_SIZE:count_new);
cache->buffer=(unsigned char *)MALLOC(cache->buffer_size);
}
- res=data->disk_car->read(data->disk_car, count_new, cache->buffer, offset);
cache->cache_size=count_new;
cache->cache_offset=offset;
- cache->cache_status=res;
- if(res>=0)
- {
- data->last_io_error_nbr=0;
- memcpy(nom_buffer, cache->buffer, count);
+ cache->cache_status=data->disk_car->pread(data->disk_car, cache->buffer, count_new, offset);
#ifdef DEBUG_CACHE
- log_trace("cache_read offset=%llu size=%lu, update cache %u, res=%d\n",
- (long long unsigned)cache->cache_offset,
- (long unsigned)cache->cache_size,
- data->cache_buffer_nbr-1, res);
+ data->nbr_fnct_sect+=count;
+ data->nbr_pread_call++;
+ data->nbr_pread_sect+=count_new;
+ log_info("cache PREAD(buffer[%u], count=%u, count_new=%u, offset=%llu, cstatus=%d)\n",
+ data->cache_buffer_nbr, count, count_new, (long long unsigned)offset,
+ cache->cache_status);
#endif
- return res;
+ if(cache->cache_status >= (signed)count)
+ {
+ data->last_io_error_nbr=0;
+ memcpy(buffer, cache->buffer, count);
+ return count;
+ }
+ /* Read failure */
+ data->last_io_error_nbr++;
+ if(count<=disk_car->sector_size || disk_car->sector_size<=0 || data->last_io_error_nbr>1)
+ {
+ memcpy(buffer, cache->buffer, count);
+ return cache->cache_status;
}
- { /* read failure */
+ /* Free the existing cache */
+ cache->cache_size=0;
+ /* split the read sector by sector */
+ {
unsigned int i;
- data->last_io_error_nbr++;
- if(count<=disk_car->sector_size || disk_car->sector_size<=0 || data->last_io_error_nbr>1)
- {
- memset(cache->buffer, 0, cache->cache_size);
- memcpy(nom_buffer, cache->buffer, count);
- return res;
- }
- /* split the read sector by sector */
- cache->cache_size=0;
- res = -1;
+ memset(buffer, 0, count);
for(i=0;i*disk_car->sector_size<count;i++)
{
- const int newres=cache_read_aux(disk_car, (count>(i+1)*disk_car->sector_size?disk_car->sector_size:count - i*disk_car->sector_size), (unsigned char*)nom_buffer+i*disk_car->sector_size, offset+i*disk_car->sector_size, 0);
- /* If one read succeed, considered that's ok, we are doing data recovery */
- if(newres>=0)
- res=0;
+ if(cache_pread_aux(disk_car,
+ (unsigned char*)buffer+i*disk_car->sector_size,
+ (count>(i+1)*disk_car->sector_size?disk_car->sector_size:count - i*disk_car->sector_size),
+ offset+i*disk_car->sector_size, 0) <= 0)
+ {
+ return i*disk_car->sector_size;
+ }
}
- return res;
+ return count;
}
}
}
-static int cache_write(disk_t *disk_car,const unsigned int count, const void *nom_buffer, const uint64_t offset)
+static int cache_pwrite(disk_t *disk_car, const void *buffer, const unsigned int count, const uint64_t offset)
{
struct cache_struct *data=(struct cache_struct *)disk_car->data;
unsigned int i;
@@ -199,7 +203,7 @@ static int cache_write(disk_t *disk_car,const unsigned int count, const void *no
}
}
disk_car->write_used=1;
- return data->disk_car->write(data->disk_car,count,nom_buffer,offset);
+ return data->disk_car->pwrite(data->disk_car, buffer, count, offset);
}
static int cache_clean(disk_t *disk_car)
@@ -209,10 +213,10 @@ static int cache_clean(disk_t *disk_car)
struct cache_struct *data=(struct cache_struct *)disk_car->data;
unsigned int i;
#ifdef DEBUG_CACHE
- log_trace("%s\ncache_read total_call=%u, total_count=%llu\n read total_call=%u, total_count=%llu\n",
+ log_info("%s\ncache_pread total_call=%u, total_count=%llu\n read total_call=%u, total_count=%llu\n",
data->disk_car->description(data->disk_car),
data->nbr_fnct_call, (long long unsigned)data->nbr_fnct_sect,
- data->nbr_read_call, (long long unsigned)data->nbr_read_sect);
+ data->nbr_pread_call, (long long unsigned)data->nbr_pread_sect);
#endif
data->disk_car->clean(data->disk_car);
for(i=0;i<CACHE_BUFFER_NBR;i++)
@@ -248,10 +252,12 @@ disk_t *new_diskcache(disk_t *disk_car, const unsigned int testdisk_mode)
disk_t *new_disk_car=(disk_t *)MALLOC(sizeof(*new_disk_car));
memcpy(new_disk_car,disk_car,sizeof(*new_disk_car));
data->disk_car=disk_car;
+#ifdef DEBUG_CACHE
data->nbr_fnct_sect=0;
- data->nbr_read_sect=0;
+ data->nbr_pread_sect=0;
data->nbr_fnct_call=0;
- data->nbr_read_call=0;
+ data->nbr_pread_call=0;
+#endif
data->cache_buffer_nbr=0;
data->last_io_error_nbr=0;
if(testdisk_mode&TESTDISK_O_READAHEAD_8K)
@@ -265,8 +271,8 @@ disk_t *new_diskcache(disk_t *disk_car, const unsigned int testdisk_mode)
new_disk_car->disk_real_size=disk_car->disk_real_size;
new_disk_car->write_used=0;
new_disk_car->data=data;
- new_disk_car->read=cache_read;
- new_disk_car->write=cache_write;
+ new_disk_car->pread=cache_pread;
+ new_disk_car->pwrite=cache_pwrite;
new_disk_car->sync=cache_sync;
new_disk_car->clean=cache_clean;
new_disk_car->description=cache_description;
@@ -276,7 +282,10 @@ disk_t *new_diskcache(disk_t *disk_car, const unsigned int testdisk_mode)
new_disk_car->rbuffer_size=0;
new_disk_car->wbuffer_size=0;
for(i=0;i<CACHE_BUFFER_NBR;i++)
+ {
data->cache[i].buffer=NULL;
+ data->cache[i].buffer_size=0;
+ }
return new_disk_car;
}
diff --git a/src/hfs.c b/src/hfs.c
index 845e227..4b0e09d 100644
--- a/src/hfs.c
+++ b/src/hfs.c
@@ -40,7 +40,7 @@ static int set_HFS_info(partition_t *partition, const hfs_mdb_t *hfs_mdb);
int check_HFS(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(HFS_SUPERBLOCK_SIZE);
- if(disk_car->read(disk_car,HFS_SUPERBLOCK_SIZE, buffer, partition->part_offset+0x400)!=0)
+ if(disk_car->pread(disk_car, buffer, HFS_SUPERBLOCK_SIZE, partition->part_offset + 0x400) != HFS_SUPERBLOCK_SIZE)
{
free(buffer);
return 1;
diff --git a/src/hfsp.c b/src/hfsp.c
index 242cb3e..931ee47 100644
--- a/src/hfsp.c
+++ b/src/hfsp.c
@@ -41,7 +41,7 @@ static int set_HFSP_info(partition_t *partition, const struct hfsp_vh *vh);
int check_HFSP(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(HFSP_BOOT_SECTOR_SIZE);
- if(disk_car->read(disk_car,HFSP_BOOT_SECTOR_SIZE, buffer, partition->part_offset+0x400)!=0)
+ if(disk_car->pread(disk_car, buffer, HFSP_BOOT_SECTOR_SIZE, partition->part_offset + 0x400) != HFSP_BOOT_SECTOR_SIZE)
{
free(buffer);
return 1;
diff --git a/src/io_redir.c b/src/io_redir.c
index 7e57f8e..c9b9c5b 100644
--- a/src/io_redir.c
+++ b/src/io_redir.c
@@ -56,12 +56,12 @@ struct info_io_redir
list_redir_t *list_redir;
};
-static int io_redir_read(disk_t *disk_car,const unsigned int count, void *nom_buffer, const uint64_t offset);
+static int io_redir_pread(disk_t *disk_car, void *buffer, const unsigned int count, const uint64_t offset);
static int io_redir_clean(disk_t *clean);
int io_redir_add_redir(disk_t *disk_car, const uint64_t org_offset, const unsigned int size, const uint64_t new_offset, const void *mem)
{
- if(disk_car->read!=io_redir_read)
+ if(disk_car->pread!=io_redir_pread)
{
struct info_io_redir*data=(struct info_io_redir*)MALLOC(sizeof(*data));
disk_t *old_disk_car=(disk_t *)MALLOC(sizeof(*old_disk_car));
@@ -78,8 +78,8 @@ int io_redir_add_redir(disk_t *disk_car, const uint64_t org_offset, const unsign
disk_car->write_used=0;
disk_car->data=data;
disk_car->description=old_disk_car->description;
- disk_car->write=old_disk_car->write;
- disk_car->read=io_redir_read;
+ disk_car->pwrite=old_disk_car->pwrite;
+ disk_car->pread=io_redir_pread;
disk_car->clean=io_redir_clean;
}
{
@@ -115,7 +115,7 @@ int io_redir_add_redir(disk_t *disk_car, const uint64_t org_offset, const unsign
int io_redir_del_redir(disk_t *disk_car, uint64_t org_offset)
{
- if(disk_car->read!=io_redir_read)
+ if(disk_car->pread!=io_redir_pread)
{
log_critical("io_redir_del_redir: BUG, no redirection present.\n");
return 1;
@@ -152,19 +152,19 @@ int io_redir_del_redir(disk_t *disk_car, uint64_t org_offset)
}
}
-static int io_redir_read(disk_t *disk_car,const unsigned int count, void *buffer, const uint64_t offset)
+static int io_redir_pread(disk_t *disk_car, void *buffer, const unsigned int count, const uint64_t offset)
{
struct info_io_redir *data=(struct info_io_redir *)disk_car->data;
uint64_t current_offset=offset;
unsigned int current_count=count;
- int res=0;
list_redir_t *current_redir;
#ifdef DEBUG_IO_REDIR
- log_trace("io_redir_read: offset=%llu count=%u\n",(long long unsigned) offset, count);
+ log_trace("io_redir_pread: count=%u offset=%llu\n", count, (long long unsigned) offset);
#endif
while(current_count!=0)
{
unsigned int read_size;
+ int res=0;
for(current_redir=data->list_redir;(current_redir!=NULL) &&
!(current_redir->org_offset<=offset && offset<current_redir->org_offset+current_redir->size);
current_redir=current_redir->next);
@@ -175,9 +175,9 @@ static int io_redir_read(disk_t *disk_car,const unsigned int count, void *buffer
/* Read data before redirection */
read_size=current_redir->org_offset-current_offset;
#ifdef DEBUG_IO_REDIR
- log_trace("io_redir_read: read %u bytes before redirection\n",read_size);
+ log_trace("io_redir_pread: read %u bytes before redirection\n",read_size);
#endif
- res|=data->disk_car->read(data->disk_car,read_size,buffer,current_offset);
+ res=data->disk_car->pread(data->disk_car, buffer, read_size, current_offset);
current_count-=read_size;
current_offset+=read_size;
buffer=(unsigned char*)buffer+read_size;
@@ -187,34 +187,35 @@ static int io_redir_read(disk_t *disk_car,const unsigned int count, void *buffer
if(current_redir->mem!=NULL)
{
#ifdef DEBUG_IO_REDIR
- log_trace("io_redir_read: copy %u bytes from memory\n",read_size);
+ log_trace("io_redir_pread: copy %u bytes from memory\n",read_size);
#endif
memcpy(buffer, (const unsigned char*)current_redir->mem + current_offset - current_redir->org_offset, read_size);
+ res=read_size;
}
else
{
#ifdef DEBUG_IO_REDIR
- log_trace("io_redir_read: read %u from another position\n",read_size);
+ log_trace("io_redir_pread: read %u from another position\n",read_size);
#endif
- res|=data->disk_car->read(data->disk_car, read_size, buffer,
- current_redir->new_offset + current_offset - current_redir->org_offset);
+ res=data->disk_car->pread(data->disk_car, buffer, read_size, current_redir->new_offset + current_offset - current_redir->org_offset);
+ ;
}
}
else
{
read_size=current_count;
#ifdef DEBUG_IO_REDIR
- log_trace("io_redir_read: normal read of %u bytes\n",read_size);
+ log_trace("io_redir_pread: normal read of %u bytes\n",read_size);
#endif
- res|=data->disk_car->read(data->disk_car,read_size,buffer,current_offset);
+ res=data->disk_car->pread(data->disk_car, buffer, read_size, current_offset);
}
- if(res!=0)
+ if(res!=read_size)
return res;
current_count-=read_size;
current_offset+=read_size;
buffer=(unsigned char*)buffer+read_size;
}
- return 0;
+ return count;
}
static int io_redir_clean(disk_t *disk_car)
diff --git a/src/jfs.c b/src/jfs.c
index 202fa41..868ba3a 100644
--- a/src/jfs.c
+++ b/src/jfs.c
@@ -43,7 +43,7 @@ static int set_JFS_info(disk_t *disk_car, const struct jfs_superblock *sb,partit
int check_JFS(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(JFS_SUPERBLOCK_SIZE);
- if(disk_car->read(disk_car,JFS_SUPERBLOCK_SIZE, buffer, partition->part_offset+64*512)!=0)
+ if(disk_car->pread(disk_car, buffer, JFS_SUPERBLOCK_SIZE, partition->part_offset + 64 * 512) != JFS_SUPERBLOCK_SIZE)
{
free(buffer);
return 1;
diff --git a/src/luks.c b/src/luks.c
index 079a907..756b2e3 100644
--- a/src/luks.c
+++ b/src/luks.c
@@ -43,7 +43,7 @@ static const uint8_t LUKS_MAGIC[LUKS_MAGIC_L] = {'L','U','K','S', 0xba, 0xbe};
int check_LUKS(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(DEFAULT_SECTOR_SIZE);
- if(disk_car->read(disk_car,DEFAULT_SECTOR_SIZE, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, DEFAULT_SECTOR_SIZE, partition->part_offset) != DEFAULT_SECTOR_SIZE)
{
free(buffer);
return 1;
diff --git a/src/lvm.c b/src/lvm.c
index 58df7e6..7acce61 100644
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -46,7 +46,7 @@ static int test_LVM2(disk_t *disk_car, const struct lvm2_label_header *lh,partit
int check_LVM(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(LVM_PV_DISK_SIZE);
- if(disk_car->read(disk_car,LVM_PV_DISK_SIZE, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, LVM_PV_DISK_SIZE, partition->part_offset) != LVM_PV_DISK_SIZE)
{
free(buffer);
return 1;
@@ -130,7 +130,7 @@ static int set_LVM_info(partition_t *partition, const pv_disk_t *pv)
int check_LVM2(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char *)MALLOC(DEFAULT_SECTOR_SIZE);
- if(disk_car->read(disk_car,DEFAULT_SECTOR_SIZE, buffer, partition->part_offset+0x200)!=0)
+ if(disk_car->pread(disk_car, buffer, DEFAULT_SECTOR_SIZE, partition->part_offset + 0x200) != DEFAULT_SECTOR_SIZE)
{
free(buffer);
return 1;
diff --git a/src/md.c b/src/md.c
index 71d89df..388ca30 100644
--- a/src/md.c
+++ b/src/md.c
@@ -44,7 +44,7 @@ int check_MD(disk_t *disk_car, partition_t *partition, const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(MD_SB_BYTES);
/* MD version 1.1 */
- if(disk_car->read(disk_car,MD_SB_BYTES, buffer, partition->part_offset)==0)
+ if(disk_car->pread(disk_car, buffer, MD_SB_BYTES, partition->part_offset) == MD_SB_BYTES)
{
const struct mdp_superblock_1 *sb1=(const struct mdp_superblock_1 *)buffer;
if(le32(sb1->md_magic)==(unsigned int)MD_SB_MAGIC &&
@@ -69,7 +69,7 @@ int check_MD(disk_t *disk_car, partition_t *partition, const int verbose)
}
}
/* MD version 1.2 */
- if(disk_car->read(disk_car,MD_SB_BYTES, buffer, partition->part_offset+4096)==0)
+ if(disk_car->pread(disk_car, buffer, MD_SB_BYTES, partition->part_offset + 4096) == MD_SB_BYTES)
{
const struct mdp_superblock_1 *sb1=(const struct mdp_superblock_1 *)buffer;
if(le32(sb1->md_magic)==(unsigned int)MD_SB_MAGIC &&
@@ -101,7 +101,7 @@ int check_MD(disk_t *disk_car, partition_t *partition, const int verbose)
{
log_verbose("Raid md 0.90 offset %llu\n", (long long unsigned)offset/512);
}
- if(disk_car->read(disk_car,MD_SB_BYTES, buffer, partition->part_offset+offset)==0)
+ if(disk_car->pread(disk_car, buffer, MD_SB_BYTES, partition->part_offset + offset) == MD_SB_BYTES)
{
if(le32(sb->md_magic)==(unsigned int)MD_SB_MAGIC &&
le32(sb->major_version)==0 &&
@@ -131,7 +131,7 @@ int check_MD(disk_t *disk_car, partition_t *partition, const int verbose)
{
log_verbose("Raid md 1.0 offset %llu\n", (long long unsigned)offset/512);
}
- if(disk_car->read(disk_car,MD_SB_BYTES, buffer, partition->part_offset+offset)==0)
+ if(disk_car->pread(disk_car, buffer, MD_SB_BYTES, partition->part_offset + offset) == MD_SB_BYTES)
{
const struct mdp_superblock_1 *sb1=(const struct mdp_superblock_1 *)buffer;
if(le32(sb1->md_magic)==(unsigned int)MD_SB_MAGIC &&
@@ -166,7 +166,7 @@ int recover_MD_from_partition(disk_t *disk_car, partition_t *partition, const in
/* MD version 0.90 */
{
uint64_t offset=MD_NEW_SIZE_SECTORS(partition->part_size/512)*512;
- if(disk_car->read(disk_car,MD_SB_BYTES, buffer, partition->part_offset+offset)==0)
+ if(disk_car->pread(disk_car, buffer, MD_SB_BYTES, partition->part_offset + offset) == MD_SB_BYTES)
{
if(recover_MD(disk_car,(struct mdp_superblock_s*)buffer,partition,verbose,0)==0)
{
@@ -179,7 +179,7 @@ int recover_MD_from_partition(disk_t *disk_car, partition_t *partition, const in
if(partition->part_size > 8*2*512)
{
uint64_t offset=(((partition->part_size/512)-8*2) & ~(4*2-1))*512;
- if(disk_car->read(disk_car,MD_SB_BYTES, buffer, partition->part_offset+offset)==0)
+ if(disk_car->pread(disk_car, buffer, MD_SB_BYTES, partition->part_offset + offset) == MD_SB_BYTES)
{
const struct mdp_superblock_1 *sb1=(const struct mdp_superblock_1 *)buffer;
if(le32(sb1->major_version)==1 &&
diff --git a/src/msdos.c b/src/msdos.c
index d641e5b..3425b41 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -52,9 +52,9 @@ static int hd_identify_enh_bios(disk_t *param_disk,const int verbose);
static int check_enh_bios(const unsigned int disk, const int verbose);
static int hd_report_error(disk_t *disk_car, const uint64_t hd_offset, const unsigned int count, const int rc);
static const char *disk_description_short(disk_t *disk_car);
-static int disk_read(disk_t *disk_car, const unsigned int count, void *buf, const uint64_t hd_offset);
-static int disk_write(disk_t *disk_car, const unsigned int count, const void *buf, const uint64_t hd_offset);
-static int disk_nowrite(disk_t *disk_car, const unsigned int count, const void *buf, const uint64_t offset);
+static int disk_pread(disk_t *disk_car, const unsigned int count, void *buf, const uint64_t hd_offset);
+static int disk_pwrite(disk_t *disk_car, const unsigned int count, const void *buf, const uint64_t hd_offset);
+static int disk_nopwrite(disk_t *disk_car, const unsigned int count, const void *buf, const uint64_t offset);
static int disk_sync(disk_t *disk_car);
static int disk_clean(disk_t *disk_car);
@@ -88,7 +88,7 @@ static void disk_reset_error(disk_t *disk_car)
biosdisk(0, data->disk, 0, 0, 1, 1, NULL);
}
-static int hd_read(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset)
+static int hd_pread(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset)
{
__dpmi_regs r;
unsigned char buf_cmd[HD_RW_BUF_SIZ];
@@ -103,22 +103,25 @@ static int hd_read(disk_t *disk_car, void *buf, const unsigned int count, const
int head, track, sector;
if(data->geo_phys.sectors_per_head==0)
{
- log_critical("hd_read: BUG geo_phys.sectors_per_head=0 !\n");
- return 1;
+ log_critical("hd_pread: BUG geo_phys.sectors_per_head=0 !\n");
+ return -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;
+ {
+ const int res=biosdisk(2, data->disk, head, track, sector, nsects, buf);
+ return (res!=0 ? -res: count);
+ }
+ return -1;
}
if(cmd_dos_segment==0)
if(alloc_cmd_dos_buffer())
- return 1;
+ return -1;
if ( (xfer_dos_segment=__dpmi_allocate_dos_memory((count + 15) >> 4, &xfer_dos_selector)) == -1 )
- return 1;
+ return -1;
*(uint16_t*)&buf_cmd[0]=HD_RW_BUF_SIZ;
*(uint16_t*)&buf_cmd[2]=nsects;
*(uint32_t*)&buf_cmd[0x4]=xfer_dos_segment<<16;
@@ -133,10 +136,10 @@ static int hd_read(disk_t *disk_car, void *buf, const unsigned int count, const
__dpmi_int(0x13, &r);
dosmemget(xfer_dos_segment<<4, count, buf);
__dpmi_free_dos_memory(xfer_dos_selector);
- return r.h.ah;
+ return (r.h.ah!=0 ? -r.h.ah : count);
}
-static int hd_write(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset)
+static int hd_pwrite(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset)
{
__dpmi_regs r;
unsigned char buf_cmd[HD_RW_BUF_SIZ];
@@ -152,22 +155,25 @@ static int hd_write(disk_t *disk_car, const void *buf, const unsigned int count,
int head, track, sector;
if(data->geo_phys.sectors_per_head==0)
{
- log_critical("hd_write: BUG geo_phys.sectors_per_head=0 !\n");
- return 1;
+ log_critical("hd_pwrite: BUG geo_phys.sectors_per_head=0 !\n");
+ return -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;
+ {
+ const int res=biosdisk(3, data->disk, head, track, sector, nsects, buf);
+ return (res!=0 ? -res : count);
+ }
+ return -1;
}
if(cmd_dos_segment==0)
if(alloc_cmd_dos_buffer())
- return 1;
+ return -1;
if ( (xfer_dos_segment=__dpmi_allocate_dos_memory((count + 15) >> 4, &xfer_dos_selector)) == -1 )
- return 1;
+ return -1;
*(uint16_t*)&buf_cmd[0]=HD_RW_BUF_SIZ;
*(uint16_t*)&buf_cmd[2]=nsects;
*(uint32_t*)&buf_cmd[0x4]=xfer_dos_segment<<16;
@@ -182,7 +188,7 @@ static int hd_write(disk_t *disk_car, const void *buf, const unsigned int count,
dosmemput(&buf_cmd, HD_RW_BUF_SIZ, cmd_dos_segment<<4);
__dpmi_int(0x13, &r);
__dpmi_free_dos_memory(xfer_dos_selector);
- return r.h.ah;
+ return (r.h.ah!=0 ? -r.h.ah : count);
}
static int check_enh_bios(const unsigned int disk, const int verbose)
@@ -370,8 +376,8 @@ disk_t *hd_identify(const int verbose, const unsigned int disk, const arch_fnct_
disk_car->sector_size=DEFAULT_SECTOR_SIZE;
disk_car->description=disk_description;
disk_car->description_short=disk_description_short;
- disk_car->read=disk_read;
- disk_car->write=((testdisk_mode&TESTDISK_O_RDWR)==TESTDISK_O_RDWR?disk_write:disk_nowrite);
+ disk_car->pread=disk_pread;
+ disk_car->pwrite=((testdisk_mode&TESTDISK_O_RDWR)==TESTDISK_O_RDWR?disk_pwrite:disk_nopwrite);
disk_car->sync=disk_sync;
disk_car->access_mode=testdisk_mode;
disk_car->clean=disk_clean;
@@ -442,12 +448,12 @@ static const char *disk_description_short(disk_t *disk_car)
return disk_car->description_short_txt;
}
-static int disk_read_aux(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset)
+static int disk_pread_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->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");
+ log_error("disk_pread_aux: Don't read after the end of the disk\n");
return -1;
}
{
@@ -460,30 +466,30 @@ static int disk_read_aux(disk_t *disk_car, void *buf, const unsigned int count,
read_size=count-read_offset>16*512?16*512:count-read_offset;
do
{
- rc=hd_read(disk_car, (char*)buf+read_offset, read_size, offset+read_offset);
- if(rc!=0)
+ rc=hd_pread(disk_car, (char*)buf+read_offset, read_size, offset+read_offset);
+ if(rc < 0)
disk_reset_error(disk_car);
- } while(rc!=0 && rc!=1 && ++i<MAX_IO_NBR);
- // 0=successful completion
- // 1=invalid function in AH or invalid parameter
- if(rc!=0)
+ } while(rc!=read_size && rc!=-1 && ++i<MAX_IO_NBR);
+ // <0 invalid function in AH or invalid parameter
+ if(rc < 0)
{
- log_error("disk_read_aux failed ");
- hd_report_error(disk_car, offset, count, rc);
- return -rc;
+ log_error("disk_pread_aux failed ");
+ hd_report_error(disk_car, offset, count, -rc);
}
+ if(rc != read_size)
+ return (read_offset==0 ? rc : read_offset);
read_offset+=read_size;
} while(read_offset<count);
}
- return 0;
+ return count;
}
-static int disk_read(disk_t *disk_car, const unsigned int count, void *buf, const uint64_t offset)
+static int disk_pread(disk_t *disk_car, const unsigned int count, void *buf, const uint64_t offset)
{
- return align_read(&disk_read_aux, disk_car, buf, count, offset);
+ return align_pread(&disk_pread_aux, disk_car, buf, count, offset);
}
-static int disk_write_aux(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t hd_offset)
+static int disk_pwrite_aux(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t hd_offset)
{
struct info_disk_struct*data=disk_car->data;
@@ -491,29 +497,28 @@ static int disk_write_aux(disk_t *disk_car, const void *buf, const unsigned int
int rc;
disk_car->write_used=1;
{
- rc=hd_write(disk_car, buf, count, hd_offset);
- if(rc!=0)
+ rc=hd_pwrite(disk_car, buf, count, hd_offset);
+ if(rc < 0)
disk_reset_error(disk_car);
- } while(rc==4 && ++i<MAX_IO_NBR);
+ } while(rc==-4 && ++i<MAX_IO_NBR);
/* 4=sector not found/read error */
- if(rc!=0)
+ if(rc < 0)
{
- log_error("disk_write error\n");
- hd_report_error(disk_car, hd_offset, count, rc);
- return -rc;
+ log_error("disk_pwrite error\n");
+ hd_report_error(disk_car, hd_offset, count, -rc);
}
- return 0;
+ return rc;
}
-static int disk_write(disk_t *disk_car, const unsigned int count, const void *buf, const uint64_t offset)
+static int disk_pwrite(disk_t *disk_car, const unsigned int count, const void *buf, const uint64_t offset)
{
- return align_write(&disk_read_aux, &disk_write_aux, disk_car, buf, count, offset);
+ return align_pwrite(&disk_pread_aux, &disk_pwrite_aux, disk_car, buf, count, offset);
}
-static int disk_nowrite(disk_t *disk_car,const unsigned int count, const void *buf, const uint64_t offset)
+static int disk_nopwrite(disk_t *disk_car,const unsigned int count, const void *buf, const uint64_t offset)
{
struct info_disk_struct *data=disk_car->data;
- log_warning("disk_nowrite(%d,%u,buffer,%lu(%u/%u/%u)) write refused\n", data->disk,
+ log_warning("disk_nopwrite(%d,%u,buffer,%lu(%u/%u/%u)) write refused\n", data->disk,
(unsigned)(count/disk_car->sector_size),(long unsigned)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset),offset2head(disk_car,offset),offset2sector(disk_car,offset));
return -1;
diff --git a/src/netware.c b/src/netware.c
index a5fae4f..5c7bb8c 100644
--- a/src/netware.c
+++ b/src/netware.c
@@ -47,7 +47,7 @@ static int test_netware(disk_t *disk_car, const struct disk_netware *netware_blo
int check_netware(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char *)MALLOC(DEFAULT_SECTOR_SIZE);
- if(disk_car->read(disk_car,DEFAULT_SECTOR_SIZE, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, DEFAULT_SECTOR_SIZE, partition->part_offset) != DEFAULT_SECTOR_SIZE)
{
free(buffer);
return 1;
diff --git a/src/ntfs.c b/src/ntfs.c
index 9691603..d12debf 100644
--- a/src/ntfs.c
+++ b/src/ntfs.c
@@ -58,7 +58,7 @@ int check_NTFS(disk_t *disk_car,partition_t *partition,const int verbose,const i
{
unsigned char *buffer=(unsigned char*)MALLOC(DEFAULT_SECTOR_SIZE);
/* log_trace("check_NTFS part_offset=%llu\n",(long long unsigned)partition->part_offset); */
- if(disk_car->read(disk_car,DEFAULT_SECTOR_SIZE, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, DEFAULT_SECTOR_SIZE, partition->part_offset) != DEFAULT_SECTOR_SIZE)
{
free(buffer);
return 1;
@@ -424,7 +424,7 @@ static int ntfs_read_MFT(disk_t *disk_car, partition_t *partition, const struct
return 1;
}
buffer=(unsigned char *)MALLOC(mft_size);
- if(disk_car->read(disk_car,mft_size, buffer, mft_pos)!=0)
+ if(disk_car->pread(disk_car, buffer, mft_size, mft_pos) != mft_size)
{
log_error("NTFS: Can't read MFT\n");
free(buffer);
diff --git a/src/ntfs_adv.c b/src/ntfs_adv.c
index fc736f3..814877b 100644
--- a/src/ntfs_adv.c
+++ b/src/ntfs_adv.c
@@ -141,11 +141,11 @@ static void menu_write_ntfs_boot_sector_cli(disk_t *disk_car, partition_t *parti
{
log_info("Write new boot!\n");
/* Write boot sector and backup boot sector */
- if(disk_car->write(disk_car,NTFS_SECTOR_SIZE, newboot, partition->part_offset))
+ if(disk_car->pwrite(disk_car, newboot, NTFS_SECTOR_SIZE, partition->part_offset) != NTFS_SECTOR_SIZE)
{
display_message("Write error: Can't write new NTFS boot sector\n");
}
- if(disk_car->write(disk_car,NTFS_SECTOR_SIZE, newboot, partition->part_offset+partition->part_size-disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, newboot, NTFS_SECTOR_SIZE, partition->part_offset + partition->part_size - disk_car->sector_size) != NTFS_SECTOR_SIZE)
{
display_message("Write error: Can't write new NTFS backup boot sector\n");
}
@@ -210,11 +210,11 @@ static void menu_write_ntfs_boot_sector_ncurses(disk_t *disk_car, partition_t *p
{
log_info("Write new boot!\n");
/* Write boot sector and backup boot sector */
- if(disk_car->write(disk_car,NTFS_SECTOR_SIZE, newboot, partition->part_offset))
+ if(disk_car->pwrite(disk_car, newboot, NTFS_SECTOR_SIZE, partition->part_offset) != NTFS_SECTOR_SIZE)
{
display_message("Write error: Can't write new NTFS boot sector\n");
}
- if(disk_car->write(disk_car,NTFS_SECTOR_SIZE, newboot, partition->part_offset+partition->part_size-disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, newboot, NTFS_SECTOR_SIZE, partition->part_offset + partition->part_size - disk_car->sector_size) != NTFS_SECTOR_SIZE)
{
display_message("Write error: Can't write new NTFS backup boot sector\n");
}
@@ -277,7 +277,7 @@ static int create_ntfs_boot_sector(disk_t *disk_car, partition_t *partition, con
struct ntfs_boot_sector *org_ntfs_header=(struct ntfs_boot_sector *)&orgboot;
struct ntfs_boot_sector *ntfs_header=(struct ntfs_boot_sector *)&newboot;
int error=0;
- if(disk_car->read(disk_car,NTFS_SECTOR_SIZE, &orgboot, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, &orgboot, NTFS_SECTOR_SIZE, partition->part_offset) != NTFS_SECTOR_SIZE)
{
log_error("create_ntfs_boot_sector: Can't read boot sector.\n");
memset(&orgboot,0,NTFS_SECTOR_SIZE);
@@ -355,7 +355,7 @@ static int read_mft_info(disk_t *disk_car, partition_t *partition, const uint64_
{
char buffer[8*DEFAULT_SECTOR_SIZE];
const char *attr=buffer;
- if(disk_car->read(disk_car,sizeof(buffer), &buffer, partition->part_offset+(uint64_t)mft_sector*disk_car->sector_size)!=0)
+ if(disk_car->pread(disk_car, &buffer, sizeof(buffer), partition->part_offset + (uint64_t)mft_sector * disk_car->sector_size) != sizeof(buffer))
{
display_message("NTFS: Can't read mft_sector\n");
return 1;
@@ -464,7 +464,7 @@ int rebuild_NTFS_BS(disk_t *disk_car, partition_t *partition, const int verbose,
/* try to find MFT Backup first */
for(sector=(partition->part_size/disk_car->sector_size/2-20>0?partition->part_size/disk_car->sector_size/2-20:1);(sector<partition->part_size/disk_car->sector_size)&&(sector<=partition->part_size/disk_car->sector_size/2+20)&&(ind_stop==0);sector++)
{
- if(disk_car->read(disk_car,2*DEFAULT_SECTOR_SIZE, &buffer, partition->part_offset+sector*(uint64_t)disk_car->sector_size)==0)
+ if(disk_car->pread(disk_car, &buffer, 2 * DEFAULT_SECTOR_SIZE, partition->part_offset + sector * (uint64_t)disk_car->sector_size) == 2 * DEFAULT_SECTOR_SIZE)
{
if(memcmp(buffer,"FILE",4)==0 && (NTFS_GETU16(buffer+ 0x14)%8==0) && (NTFS_GETU16(buffer+ 0x14)>=42)
&&(NTFS_GETU16(buffer+22)==1)) /* MFT_RECORD_IN_USE */
@@ -519,7 +519,7 @@ int rebuild_NTFS_BS(disk_t *disk_car, partition_t *partition, const int verbose,
}
}
#endif
- if(disk_car->read(disk_car,2*DEFAULT_SECTOR_SIZE, &buffer, partition->part_offset+sector*(uint64_t)disk_car->sector_size)==0)
+ if(disk_car->pread(disk_car, &buffer, 2 * DEFAULT_SECTOR_SIZE, partition->part_offset + sector * (uint64_t)disk_car->sector_size) == 2 * DEFAULT_SECTOR_SIZE)
{
if(memcmp(buffer,"FILE",4)==0 && (NTFS_GETU16(buffer+ 0x14)%8==0) && (NTFS_GETU16(buffer+ 0x14)>=42))
{
@@ -632,7 +632,7 @@ int rebuild_NTFS_BS(disk_t *disk_car, partition_t *partition, const int verbose,
log_info("ntfs_find_mft: mftmirr_lcn %lu\n",(long unsigned int)mftmirr_lcn);
log_info("ntfs_find_mft: mft_record_size %u\n",mft_record_size);
/* Read "root directory" in MFT */
- if(disk_car->read(disk_car,mft_record_size, &buffer, partition->part_offset+(uint64_t)mft_lcn*sectors_per_cluster*disk_car->sector_size+5*(uint64_t)mft_record_size)!=0)
+ if(disk_car->pread(disk_car, &buffer, mft_record_size, partition->part_offset + (uint64_t)mft_lcn * sectors_per_cluster * disk_car->sector_size + 5 * (uint64_t)mft_record_size) != mft_record_size)
{
display_message("NTFS Can't read \"root directory\" in MFT\n");
return 1;
diff --git a/src/ntfs_fix.c b/src/ntfs_fix.c
index f71d386..956e7d3 100644
--- a/src/ntfs_fix.c
+++ b/src/ntfs_fix.c
@@ -70,7 +70,7 @@ int repair_MFT(disk_t *disk_car, partition_t *partition, const int verbose, cons
return -1;
}
ntfs_header=(struct ntfs_boot_sector *)MALLOC(DEFAULT_SECTOR_SIZE);
- if(disk_car->read(disk_car,DEFAULT_SECTOR_SIZE, ntfs_header, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, ntfs_header, DEFAULT_SECTOR_SIZE, partition->part_offset) != DEFAULT_SECTOR_SIZE)
{
free(ntfs_header);
display_message("Can't read NTFS boot sector.\n");
@@ -103,7 +103,7 @@ int repair_MFT(disk_t *disk_car, partition_t *partition, const int verbose, cons
}
/* Check if MFT mirror is identical to the beginning of MFT */
buffer_mft=(unsigned char *)MALLOC(mftmirr_size_bytes);
- if(disk_car->read(disk_car, mftmirr_size_bytes, buffer_mft, mft_pos)!=0)
+ if(disk_car->pread(disk_car, buffer_mft, mftmirr_size_bytes, mft_pos) != mftmirr_size_bytes)
{
display_message("Can't read NTFS MFT.\n");
log_error("Can't read NTFS MFT.\n");
@@ -112,7 +112,7 @@ int repair_MFT(disk_t *disk_car, partition_t *partition, const int verbose, cons
return -1;
}
buffer_mftmirr=(unsigned char *)MALLOC(mftmirr_size_bytes);
- if(disk_car->read(disk_car, mftmirr_size_bytes, buffer_mftmirr, mftmirr_pos)!=0)
+ if(disk_car->pread(disk_car, buffer_mftmirr, mftmirr_size_bytes, mftmirr_pos) != mftmirr_size_bytes)
{
display_message("Can't read NTFS MFT mirror.\n");
log_error("Can't read NTFS MFT mirror.\n");
@@ -278,7 +278,7 @@ int repair_MFT(disk_t *disk_car, partition_t *partition, const int verbose, cons
}
if(use_MFT==2)
{
- if(disk_car->write(disk_car, mftmirr_size_bytes, buffer_mftmirr, mft_pos)!=0)
+ if(disk_car->pwrite(disk_car, buffer_mftmirr, mftmirr_size_bytes, mft_pos) != mftmirr_size_bytes)
{
display_message("Failed to fix MFT: write error.\n");
}
@@ -290,7 +290,7 @@ int repair_MFT(disk_t *disk_car, partition_t *partition, const int verbose, cons
}
else if(use_MFT==1)
{
- if(disk_car->write(disk_car, mftmirr_size_bytes, buffer_mft, mftmirr_pos)!=0)
+ if(disk_car->pwrite(disk_car, buffer_mft, mftmirr_size_bytes, mftmirr_pos) != mftmirr_size_bytes)
{
display_message("Failed to fix MFT mirror: write error.\n");
}
diff --git a/src/ntfs_io.c b/src/ntfs_io.c
index aa2436e..fb1be2a 100644
--- a/src/ntfs_io.c
+++ b/src/ntfs_io.c
@@ -101,7 +101,7 @@ static s64 ntfs_device_testdisk_io_read(struct ntfs_device *dev, void *buf,
s64 count)
{
my_data_t *my_data=(my_data_t*)dev->d_private;
- if(my_data->disk_car->read(my_data->disk_car,count,buf,my_data->partition->part_offset+my_data->offset))
+ if(my_data->disk_car->pread(my_data->disk_car, buf, count, my_data->partition->part_offset + my_data->offset) != count)
return 0;
my_data->offset+=count;
return count;
@@ -111,7 +111,7 @@ static s64 ntfs_device_testdisk_io_write(struct ntfs_device *dev, const void *bu
s64 count)
{
my_data_t *my_data=(my_data_t*)dev->d_private;
- if(my_data->disk_car->write(my_data->disk_car,count,buf,my_data->partition->part_offset+my_data->offset))
+ if(my_data->disk_car->pwrite(my_data->disk_car, buf, count, my_data->partition->part_offset + my_data->offset) != count)
return 0;
my_data->offset+=count;
return count;
diff --git a/src/ntfsp.c b/src/ntfsp.c
index 7a12ac8..86d5e9a 100644
--- a/src/ntfsp.c
+++ b/src/ntfsp.c
@@ -75,7 +75,7 @@ unsigned int ntfs_remove_used_space(disk_t *disk_car,const partition_t *partitio
buffer=(unsigned char *)MALLOC(SIZEOF_BUFFER);
{
const struct ntfs_boot_sector*ntfs_header=(const struct ntfs_boot_sector*)buffer;
- if(disk_car->read(disk_car,512, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, 512, partition->part_offset) != 512)
{
free(buffer);
return 0;
diff --git a/src/partgpt.c b/src/partgpt.c
index 9772c4a..dc853f6 100644
--- a/src/partgpt.c
+++ b/src/partgpt.c
@@ -164,7 +164,7 @@ list_part_t *read_part_gpt(disk_t *disk_car, const int verbose, const int savehe
gpt=(struct gpt_hdr*)MALLOC(disk_car->sector_size);
screen_buffer_reset();
- if(disk_car->read(disk_car, disk_car->sector_size, gpt, disk_car->sector_size)!=0)
+ if(disk_car->pread(disk_car, gpt, disk_car->sector_size, disk_car->sector_size) != disk_car->sector_size)
{
free(gpt);
return NULL;
@@ -262,7 +262,7 @@ list_part_t *read_part_gpt(disk_t *disk_car, const int verbose, const int savehe
}
gpt_entries=(struct gpt_ent*)MALLOC(gpt_entries_size);
- if(disk_car->read(disk_car, gpt_entries_size, gpt_entries, gpt_entries_offset)!=0)
+ if(disk_car->pread(disk_car, gpt_entries, gpt_entries_size, gpt_entries_offset) != gpt_entries_size)
{
free(gpt_entries);
free(gpt);
@@ -479,13 +479,13 @@ static int write_part_gpt(disk_t *disk_car, const list_part_t *list_part, const
gpt->hdr_lba_alt=le64((disk_car->disk_size-1)/disk_car->sector_size);
gpt->hdr_lba_table=le64(1+1);
gpt->hdr_crc_self=le32(get_crc32(gpt, le32(gpt->hdr_size), 0xFFFFFFFF)^0xFFFFFFFF);
- if(disk_car->write(disk_car, gpt_entries_size, gpt_entries, le64(gpt->hdr_lba_table) * disk_car->sector_size))
+ if(disk_car->pwrite(disk_car, gpt_entries, gpt_entries_size, le64(gpt->hdr_lba_table) * disk_car->sector_size) != gpt_entries_size)
{
free(gpt);
free(gpt_entries);
return 1;
}
- if(disk_car->write(disk_car, disk_car->sector_size, gpt, le64(gpt->hdr_lba_self) * disk_car->sector_size))
+ if(disk_car->pwrite(disk_car, gpt, disk_car->sector_size, le64(gpt->hdr_lba_self) * disk_car->sector_size) != disk_car->sector_size)
{
free(gpt);
free(gpt_entries);
@@ -495,13 +495,13 @@ static int write_part_gpt(disk_t *disk_car, const list_part_t *list_part, const
gpt->hdr_lba_alt=le64(1);
gpt->hdr_lba_table=le64((disk_car->disk_size-1 - gpt_entries_size)/disk_car->sector_size);
gpt->hdr_crc_self=le32(get_crc32(gpt, le32(gpt->hdr_size), 0xFFFFFFFF)^0xFFFFFFFF);
- if(disk_car->write(disk_car, gpt_entries_size, gpt_entries, le64(gpt->hdr_lba_table) * disk_car->sector_size))
+ if(disk_car->pwrite(disk_car, gpt_entries, gpt_entries_size, le64(gpt->hdr_lba_table) * disk_car->sector_size) != gpt_entries_size)
{
free(gpt);
free(gpt_entries);
return 1;
}
- if(disk_car->write(disk_car, disk_car->sector_size, gpt, le64(gpt->hdr_lba_self) * disk_car->sector_size))
+ if(disk_car->pwrite(disk_car, gpt, disk_car->sector_size, le64(gpt->hdr_lba_self) * disk_car->sector_size) != disk_car->sector_size)
{
free(gpt);
free(gpt_entries);
diff --git a/src/parti386.c b/src/parti386.c
index 8b4a182..a721b8d 100644
--- a/src/parti386.c
+++ b/src/parti386.c
@@ -363,7 +363,7 @@ static list_part_t *read_part_i386(disk_t *disk_car, const int verbose, const in
list_part_t *new_list_part=NULL;
unsigned char *buffer=(unsigned char *)MALLOC(disk_car->sector_size);
screen_buffer_reset();
- if(disk_car->read(disk_car,disk_car->sector_size, buffer, (uint64_t)0))
+ if(disk_car->pread(disk_car, buffer, disk_car->sector_size, (uint64_t)0) != disk_car->sector_size)
{
screen_buffer_add( msg_PART_RD_ERR);
free(buffer);
@@ -492,7 +492,7 @@ static list_part_t *get_ext_data_i386(disk_t *disk_car, list_part_t *list_part,
{
unsigned char buffer[DEFAULT_SECTOR_SIZE];
int nb_hidden=0, nb_mb=0, nb_part=0, nb_ext=0, nb_boot=0;
- if(disk_car->read(disk_car,sizeof(buffer), &buffer, partition_ext->part_offset)!=0)
+ if(disk_car->pread(disk_car, &buffer, sizeof(buffer), partition_ext->part_offset) != sizeof(buffer))
return list_part;
if((buffer[0x1FE]!=(unsigned char)0x55)||(buffer[0x1FF]!=(unsigned char)0xAA))
{
@@ -648,7 +648,7 @@ static int write_mbr_i386(disk_t *disk_car, const list_part_t *list_part, const
{
log_trace("\nwrite_mbr_i386: starting...\n");
}
- if(disk_car->read(disk_car,DEFAULT_SECTOR_SIZE, buffer_org, (uint64_t)0))
+ if(disk_car->pread(disk_car, buffer_org, DEFAULT_SECTOR_SIZE, (uint64_t)0) != DEFAULT_SECTOR_SIZE)
{
log_error(msg_PART_RD_ERR);
memset(buffer_org,0,DEFAULT_SECTOR_SIZE);
@@ -702,7 +702,7 @@ static int write_mbr_i386(disk_t *disk_car, const list_part_t *list_part, const
}
if(ro==0)
{
- if(disk_car->write(disk_car,DEFAULT_SECTOR_SIZE, buffer, (uint64_t)0))
+ if(disk_car->pwrite(disk_car, buffer, DEFAULT_SECTOR_SIZE, (uint64_t)0) != DEFAULT_SECTOR_SIZE)
{
free(buffer_org);
free(buffer);
@@ -755,7 +755,7 @@ static int write_all_log_i386(disk_t *disk_car, const list_part_t *list_part, co
{
log_info("write_all_log_i386: CHS: %u/%u/%u,lba=%lu\n", offset2cylinder(disk_car,current_pos), offset2head(disk_car,current_pos), offset2sector(disk_car,current_pos),(long unsigned)(current_pos/disk_car->sector_size));
}
- if(disk_car->read(disk_car,sizeof(buffer_org), &buffer_org, current_pos))
+ if(disk_car->pread(disk_car, &buffer_org, sizeof(buffer_org), current_pos) != sizeof(buffer_org))
{
memset(buffer_org,0,DEFAULT_SECTOR_SIZE);
}
@@ -770,7 +770,7 @@ static int write_all_log_i386(disk_t *disk_car, const list_part_t *list_part, co
}
else
{
- if(disk_car->write(disk_car,sizeof(buffer), &buffer, current_pos))
+ if(disk_car->pwrite(disk_car, &buffer, sizeof(buffer), current_pos) != sizeof(buffer))
{
res=1;
}
@@ -787,7 +787,7 @@ static int write_all_log_i386(disk_t *disk_car, const list_part_t *list_part, co
{
log_info("write_all_log_i386: CHS: %u/%u/%u,lba=%lu\n", offset2cylinder(disk_car,current_pos), offset2head(disk_car,current_pos), offset2sector(disk_car,current_pos),(long unsigned)(current_pos/disk_car->sector_size));
}
- if(disk_car->read(disk_car,sizeof(buffer_org), &buffer_org, current_pos))
+ if(disk_car->pread(disk_car, &buffer_org, sizeof(buffer_org), current_pos) != sizeof(buffer_org))
{
memset(buffer_org,0,DEFAULT_SECTOR_SIZE);
}
@@ -853,7 +853,7 @@ static int write_all_log_i386(disk_t *disk_car, const list_part_t *list_part, co
}
else
{
- if(disk_car->write(disk_car,sizeof(buffer), &buffer, current_pos))
+ if(disk_car->pwrite(disk_car, &buffer, sizeof(buffer), current_pos) != sizeof(buffer))
{
res=1;
}
@@ -896,13 +896,13 @@ static int diff(const disk_t *disk_car, const unsigned char buffer[DEFAULT_SECTO
static int write_MBR_code_i386(disk_t *disk_car)
{
unsigned char buffer[DEFAULT_SECTOR_SIZE];
- if(disk_car->read(disk_car,DEFAULT_SECTOR_SIZE, buffer, (uint64_t)0))
+ if(disk_car->pread(disk_car, buffer, DEFAULT_SECTOR_SIZE, (uint64_t)0) != DEFAULT_SECTOR_SIZE)
{
log_error(msg_PART_RD_ERR);
memset(buffer,0,sizeof(buffer));
}
write_MBR_code_i386_aux(buffer);
- if(disk_car->write(disk_car,DEFAULT_SECTOR_SIZE, buffer, (uint64_t)0))
+ if(disk_car->pwrite(disk_car, buffer, DEFAULT_SECTOR_SIZE, (uint64_t)0) != DEFAULT_SECTOR_SIZE)
{
return 1;
}
@@ -1445,13 +1445,13 @@ static void init_structure_i386(const disk_t *disk_car,list_part_t *list_part, c
static int erase_list_part_i386(disk_t *disk_car)
{
unsigned char buffer[DEFAULT_SECTOR_SIZE];
- if(disk_car->read(disk_car,DEFAULT_SECTOR_SIZE, buffer, (uint64_t)0))
+ if(disk_car->pread(disk_car, buffer, DEFAULT_SECTOR_SIZE, (uint64_t)0) != DEFAULT_SECTOR_SIZE)
{
log_error(msg_PART_RD_ERR);
memset(buffer,0,sizeof(buffer));
}
memset(buffer+TAB_PART,0,0x40);
- if(disk_car->write(disk_car,DEFAULT_SECTOR_SIZE, buffer, (uint64_t)0))
+ if(disk_car->pwrite(disk_car, buffer, DEFAULT_SECTOR_SIZE, (uint64_t)0) != DEFAULT_SECTOR_SIZE)
{
return 1;
}
diff --git a/src/partmac.c b/src/partmac.c
index 91765bc..609f3d6 100644
--- a/src/partmac.c
+++ b/src/partmac.c
@@ -119,7 +119,7 @@ list_part_t *read_part_mac(disk_t *disk_car, const int verbose, const int savehe
unsigned int i;
unsigned int limit=1;
screen_buffer_reset();
- if(disk_car->read(disk_car,sizeof(buffer), &buffer, 0)!=0)
+ if(disk_car->pread(disk_car, &buffer, sizeof(buffer), 0) != sizeof(buffer))
return NULL;
{
mac_Block0 *maclabel=(mac_Block0*)&buffer;
@@ -133,7 +133,7 @@ list_part_t *read_part_mac(disk_t *disk_car, const int verbose, const int savehe
for(i=1;i<=limit;i++)
{
mac_DPME *dpme=(mac_DPME *)buffer;
- if(disk_car->read(disk_car,sizeof(buffer), &buffer, (uint64_t)i*PBLOCK_SIZE)!=0)
+ if(disk_car->pread(disk_car, &buffer, sizeof(buffer), (uint64_t)i * PBLOCK_SIZE) != sizeof(buffer))
return new_list_part;
if(be16(dpme->dpme_signature) != DPME_SIGNATURE)
{
diff --git a/src/partsun.c b/src/partsun.c
index 8153715..15b3b62 100644
--- a/src/partsun.c
+++ b/src/partsun.c
@@ -144,7 +144,7 @@ list_part_t *read_part_sun(disk_t *disk_car, const int verbose, const int savehe
unsigned char *buffer=(unsigned char *)MALLOC(disk_car->sector_size);
screen_buffer_reset();
sunlabel=(sun_partition*)buffer;
- if(disk_car->read(disk_car,DEFAULT_SECTOR_SIZE, buffer, (uint64_t)0))
+ if(disk_car->pread(disk_car, buffer, DEFAULT_SECTOR_SIZE, (uint64_t)0) != DEFAULT_SECTOR_SIZE)
{
screen_buffer_add( msg_PART_RD_ERR);
free(buffer);
diff --git a/src/partxbox.c b/src/partxbox.c
index e867a04..06930ab 100644
--- a/src/partxbox.c
+++ b/src/partxbox.c
@@ -96,7 +96,7 @@ list_part_t *read_part_xbox(disk_t *disk_car, const int verbose, const int saveh
unsigned char buffer[0x800];
list_part_t *new_list_part=NULL;
screen_buffer_reset();
- if(disk_car->read(disk_car,sizeof(buffer), &buffer, 0)!=0)
+ if(disk_car->pread(disk_car, &buffer, sizeof(buffer), 0) != sizeof(buffer))
return new_list_part;
{
uint64_t offsets[]={ 0x00080000, 0x2ee80000, 0x5dc80000, 0x8ca80000, 0xabe80000 };
diff --git a/src/phrecn.c b/src/phrecn.c
index d653adc..38ff73e 100644
--- a/src/phrecn.c
+++ b/src/phrecn.c
@@ -332,7 +332,7 @@ static int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbo
buffer=buffer_olddata+blocksize;
reset_file_recovery(&file_recovery);
memset(buffer_olddata, 0, blocksize);
- disk_car->read(disk_car,READ_SIZE, buffer, offset);
+ disk_car->pread(disk_car, buffer, READ_SIZE, offset);
#ifdef DEBUG_BF
info_list_search_space(list_search_space, current_search_space, disk_car->sector_size, 0, verbose);
#endif
@@ -448,7 +448,7 @@ static int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbo
(unsigned long)((offset-partition->part_offset)/disk_car->sector_size),
(unsigned long)((partition->part_size-1)/disk_car->sector_size));
}
- disk_car->read(disk_car,READ_SIZE, buffer, offset);
+ disk_car->pread(disk_car, buffer, READ_SIZE, offset);
}
}
} while(need_to_check_file==0);
@@ -507,7 +507,7 @@ static int photorec_bf_aux(disk_t *disk_car, partition_t *partition, const int p
file_recovery->file_size=0;
for(i=0; i<(original_offset_error+blocksize-1)/blocksize; i++)
{
- disk_car->read(disk_car,blocksize, block_buffer, offset);
+ disk_car->pread(disk_car, block_buffer, blocksize, offset);
fwrite(block_buffer, blocksize, 1, file_recovery->handle);
list_append_block(&file_recovery->location, offset, blocksize, 1);
file_recovery->file_size+=blocksize;
@@ -595,7 +595,7 @@ static int photorec_bf_aux(disk_t *disk_car, partition_t *partition, const int p
file_recovery->file_size+=blocksize)
{
/* FIXME: handle fwrite return value */
- disk_car->read(disk_car, blocksize, block_buffer, offset);
+ disk_car->pread(disk_car, block_buffer, blocksize, offset);
fwrite(block_buffer, blocksize, 1, file_recovery->handle);
list_append_block(&file_recovery->location, offset, blocksize, 1);
get_next_sector(list_search_space, &current_search_space, &offset, blocksize);
@@ -738,7 +738,7 @@ static int photorec_find_blocksize(disk_t *disk_car, partition_t *partition, con
offset=current_search_space->start;
if(verbose>0)
info_list_search_space(list_search_space, current_search_space, disk_car->sector_size, 0, verbose);
- disk_car->read(disk_car,READ_SIZE, buffer, offset);
+ disk_car->pread(disk_car, buffer, READ_SIZE, offset);
while(current_search_space!=list_search_space)
{
uint64_t old_offset=offset;
@@ -825,7 +825,7 @@ static int photorec_find_blocksize(disk_t *disk_car, partition_t *partition, con
{
log_verbose("Reading sector %10lu/%lu\n",(unsigned long)((offset-partition->part_offset)/disk_car->sector_size),(unsigned long)((partition->part_size-1)/disk_car->sector_size));
}
- if(disk_car->read(disk_car,READ_SIZE, buffer, offset)<0)
+ if(disk_car->pread(disk_car, buffer, READ_SIZE, offset) != READ_SIZE)
{
#ifdef HAVE_NCURSES
if(interface!=0)
@@ -894,7 +894,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const int verb
offset=current_search_space->start;
if(verbose>0)
info_list_search_space(list_search_space, current_search_space, disk_car->sector_size, 0, verbose);
- disk_car->read(disk_car,READ_SIZE, buffer, offset);
+ disk_car->pread(disk_car, buffer, READ_SIZE, offset);
while(current_search_space!=list_search_space)
{
int move_next=1;
@@ -1123,7 +1123,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const int verb
{
log_verbose("Reading sector %10lu/%lu\n",(unsigned long)((offset-partition->part_offset)/disk_car->sector_size),(unsigned long)((partition->part_size-1)/disk_car->sector_size));
}
- if(disk_car->read(disk_car,READ_SIZE, buffer, offset)<0)
+ if(disk_car->pread(disk_car, buffer, READ_SIZE, offset) != READ_SIZE)
{
#ifdef HAVE_NCURSES
if(interface!=0)
diff --git a/src/rfs.c b/src/rfs.c
index 19efd7c..f616935 100644
--- a/src/rfs.c
+++ b/src/rfs.c
@@ -47,7 +47,7 @@ static int set_rfs4_info(const disk_t *disk_car, const struct reiser4_master_sb*
int check_rfs(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(REISERFS_SUPER_BLOCK_SIZE);
- if(disk_car->read(disk_car,REISERFS_SUPER_BLOCK_SIZE, buffer, partition->part_offset+128*512)!=0) /* 64k offset */
+ if(disk_car->pread(disk_car, buffer, REISERFS_SUPER_BLOCK_SIZE, partition->part_offset + 128 * 512) != REISERFS_SUPER_BLOCK_SIZE) /* 64k offset */
{
free(buffer);
return 1;
diff --git a/src/rfs_dir.c b/src/rfs_dir.c
index 9772cad..9c76fd2 100644
--- a/src/rfs_dir.c
+++ b/src/rfs_dir.c
@@ -132,7 +132,7 @@ static int file_read(dal_t *dal, void *buff, blk_t block, blk_t count) {
blocklen = count * dal->blocksize;
#endif
/* log_debug("blocklen=%ld\n",blocklen); */
- if(my_data->disk_car->read(my_data->disk_car,blocklen,buff,my_data->partition->part_offset+off))
+ if(my_data->disk_car->pread(my_data->disk_car, buff, blocklen, my_data->partition->part_offset + off) != blocklen)
return 0;
return 1;
}
@@ -151,7 +151,7 @@ static int file_write(dal_t *dal, void *buff, blk_t block, blk_t count)
off = (uint64_t)block * (uint64_t)dal->blocksize;
blocklen = (uint64_t)count * (uint64_t)dal->blocksize;
#endif
- if(my_data->disk_car->write(my_data->disk_car,blocklen,buff,my_data->partition->part_offset+off))
+ if(my_data->disk_car->pwrite(my_data->disk_car, buff, blocklen, my_data->partition->part_offset + off) != blocklen)
return 0;
return 1;
}
diff --git a/src/savehdr.c b/src/savehdr.c
index fb78963..a179a40 100644
--- a/src/savehdr.c
+++ b/src/savehdr.c
@@ -81,7 +81,7 @@ int save_header(disk_t *disk_car,partition_t *partition, const int verbose)
}
if(fwrite(buffer,DEFAULT_SECTOR_SIZE,1,f_backup)!=1)
res = -1;
- if(res>=0 && disk_car->read(disk_car,256*DEFAULT_SECTOR_SIZE, buffer, partition->part_offset)!=0)
+ if(res>=0 && disk_car->pread(disk_car, buffer, 256 * DEFAULT_SECTOR_SIZE, partition->part_offset) != 256 * DEFAULT_SECTOR_SIZE)
res = -1;
if(res>=0 && fwrite(buffer,DEFAULT_SECTOR_SIZE,256,f_backup)!=256)
res = -1;
diff --git a/src/sun.c b/src/sun.c
index b5400f6..fb81430 100644
--- a/src/sun.c
+++ b/src/sun.c
@@ -48,7 +48,7 @@ int check_sun_i386(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(SUN_PARTITION_I386_SIZE);
sun_partition_i386 *sunlabel=(sun_partition_i386*)buffer;
- if(disk_car->read(disk_car,SUN_PARTITION_I386_SIZE, buffer, partition->part_offset+0x200)!=0)
+ if(disk_car->pread(disk_car, buffer, SUN_PARTITION_I386_SIZE, partition->part_offset + 0x200) != SUN_PARTITION_I386_SIZE)
{
free(buffer);
return 1;
diff --git a/src/swap.c b/src/swap.c
index e715423..6f2ab71 100644
--- a/src/swap.c
+++ b/src/swap.c
@@ -40,7 +40,7 @@ static int test_Linux_SWAP(disk_t *disk_car, const union swap_header *swap_heade
int check_Linux_SWAP(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(SWAP_SIZE);
- if(disk_car->read(disk_car,SWAP_SIZE, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, SWAP_SIZE, partition->part_offset) != SWAP_SIZE)
{
free(buffer);
return 1;
diff --git a/src/sysv.c b/src/sysv.c
index 000b4d3..42e5c05 100644
--- a/src/sysv.c
+++ b/src/sysv.c
@@ -64,7 +64,7 @@ static int test_sysv4(const disk_t *disk_car, const struct sysv4_super_block *sb
int check_sysv(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(SYSV4_SECTOR_SIZE);
- if(disk_car->read(disk_car,SYSV4_SECTOR_SIZE, buffer, partition->part_offset+0x200)!=0)
+ if(disk_car->pread(disk_car, buffer, SYSV4_SECTOR_SIZE, partition->part_offset + 0x200) != SYSV4_SECTOR_SIZE)
{
free(buffer);
return 1;
diff --git a/src/thfs.c b/src/thfs.c
index f5f047a..6b44282 100644
--- a/src/thfs.c
+++ b/src/thfs.c
@@ -116,7 +116,7 @@ int HFS_HFSP_boot_sector(disk_t *disk_car, partition_t *partition, const int ver
log_info("\nHFS_HFSP_boot_sector\n");
log_partition(disk_car,partition);
screen_buffer_add("Volume header\n");
- if(disk_car->read(disk_car,HFSP_BOOT_SECTOR_SIZE, buffer_bs, partition->part_offset+0x400)!=0)
+ if(disk_car->pread(disk_car, buffer_bs, HFSP_BOOT_SECTOR_SIZE, partition->part_offset + 0x400) != HFSP_BOOT_SECTOR_SIZE)
{
screen_buffer_add("Bad: can't read HFS/HFS+ volume header.\n");
memset(buffer_bs,0,HFSP_BOOT_SECTOR_SIZE);
@@ -136,7 +136,7 @@ int HFS_HFSP_boot_sector(disk_t *disk_car, partition_t *partition, const int ver
else
screen_buffer_add("Bad\n");
screen_buffer_add("\nBackup volume header\n");
- if(disk_car->read(disk_car,HFSP_BOOT_SECTOR_SIZE, buffer_backup_bs, partition->part_offset+partition->part_size-0x400)!=0)
+ if(disk_car->pread(disk_car, buffer_backup_bs, HFSP_BOOT_SECTOR_SIZE, partition->part_offset + partition->part_size - 0x400) != HFSP_BOOT_SECTOR_SIZE)
{
screen_buffer_add("Bad: can't read HFS/HFS+ backup volume header.\n");
memset(buffer_backup_bs,0,HFSP_BOOT_SECTOR_SIZE);
@@ -220,7 +220,7 @@ int HFS_HFSP_boot_sector(disk_t *disk_car, partition_t *partition, const int ver
if(ask_confirmation("Copy original HFS/HFS+ volume header over backup, confirm ? (Y/N)")!=0)
{
log_info("copy original superblock over backup boot\n");
- if(disk_car->write(disk_car,HFSP_BOOT_SECTOR_SIZE, buffer_bs, partition->part_offset+partition->part_size-0x400)!=0)
+ if(disk_car->pwrite(disk_car, buffer_bs, HFSP_BOOT_SECTOR_SIZE, partition->part_offset + partition->part_size - 0x400) != HFSP_BOOT_SECTOR_SIZE)
{
display_message("Write error: Can't overwrite HFS/HFS+ backup volume header\n");
}
@@ -234,7 +234,7 @@ int HFS_HFSP_boot_sector(disk_t *disk_car, partition_t *partition, const int ver
if(ask_confirmation("Copy backup HFS/HFS+ volume header over main volume header, confirm ? (Y/N)")!=0)
{
log_info("copy backup superblock over main superblock\n");
- if(disk_car->write(disk_car,HFSP_BOOT_SECTOR_SIZE, buffer_backup_bs, partition->part_offset+0x400)!=0)
+ if(disk_car->pwrite(disk_car, buffer_backup_bs, HFSP_BOOT_SECTOR_SIZE, partition->part_offset + 0x400) != HFSP_BOOT_SECTOR_SIZE)
{
display_message("Write error: Can't overwrite HFS/HFS+ main volume header\n");
}
diff --git a/src/tntfs.c b/src/tntfs.c
index 34ecafa..8d7c552 100644
--- a/src/tntfs.c
+++ b/src/tntfs.c
@@ -116,7 +116,7 @@ int ntfs_boot_sector(disk_t *disk_car, partition_t *partition, const int verbose
log_info("\nntfs_boot_sector\n");
log_partition(disk_car,partition);
screen_buffer_add("Boot sector\n");
- if(disk_car->read(disk_car,NTFS_BOOT_SECTOR_SIZE, buffer_bs, partition->part_offset)!=0)
+ 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);
@@ -131,7 +131,7 @@ int ntfs_boot_sector(disk_t *disk_car, partition_t *partition, const int verbose
screen_buffer_add("Status: Bad\n");
}
screen_buffer_add("\nBackup boot sector\n");
- if(disk_car->read(disk_car,NTFS_BOOT_SECTOR_SIZE, buffer_backup_bs, partition->part_offset+partition->part_size-disk_car->sector_size)!=0)
+ 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);
@@ -245,7 +245,7 @@ int ntfs_boot_sector(disk_t *disk_car, partition_t *partition, const int verbose
if(ask_confirmation("Copy original NTFS boot sector over backup boot, confirm ? (Y/N)")!=0)
{
log_info("copy original boot sector over backup boot\n");
- if(disk_car->write(disk_car,NTFS_BOOT_SECTOR_SIZE, buffer_bs, partition->part_offset+partition->part_size-disk_car->sector_size)!=0)
+ if(disk_car->pwrite(disk_car, buffer_bs, NTFS_BOOT_SECTOR_SIZE, partition->part_offset + partition->part_size - disk_car->sector_size) != NTFS_BOOT_SECTOR_SIZE)
{
display_message("Write error: Can't overwrite NTFS backup boot sector\n");
}
@@ -259,7 +259,7 @@ int ntfs_boot_sector(disk_t *disk_car, partition_t *partition, const int verbose
if(ask_confirmation("Copy backup NTFS boot sector over boot sector, confirm ? (Y/N)")!=0)
{
log_info("copy backup boot sector over boot sector\n");
- if(disk_car->write(disk_car,NTFS_BOOT_SECTOR_SIZE, buffer_backup_bs, partition->part_offset)!=0)
+ if(disk_car->pwrite(disk_car, buffer_backup_bs, NTFS_BOOT_SECTOR_SIZE, partition->part_offset) != NTFS_BOOT_SECTOR_SIZE)
{
display_message("Write error: Can't overwrite NTFS boot sector\n");
}
diff --git a/src/ufs.c b/src/ufs.c
index 84d1a01..452d40f 100644
--- a/src/ufs.c
+++ b/src/ufs.c
@@ -46,7 +46,7 @@ int check_ufs(disk_t *disk_car,partition_t *partition,const int verbose)
unsigned char *buffer;
buffer=(unsigned char*)MALLOC(UFS_SUPERBLOCK_SIZE);
sb=(const struct ufs_super_block*)buffer;
- if(disk_car->read(disk_car,UFS_SUPERBLOCK_SIZE, buffer, partition->part_offset+UFS_SBLOCK)!=0)
+ if(disk_car->pread(disk_car, buffer, UFS_SUPERBLOCK_SIZE, partition->part_offset + UFS_SBLOCK) != UFS_SUPERBLOCK_SIZE)
{
free(buffer);
return 1;
diff --git a/src/win32.c b/src/win32.c
index cc4b10c..21f8ece 100644
--- a/src/win32.c
+++ b/src/win32.c
@@ -65,9 +65,9 @@ static uint64_t filewin32_getfilesize(HANDLE handle, const char *device);
static const char *file_win32_description(disk_t *disk_car);
static const char *file_win32_description_short(disk_t *disk_car);
static int file_win32_clean(disk_t *disk_car);
-static int file_win32_read(disk_t *disk_car, const unsigned int count, void *buf, const uint64_t offset);
-static int file_win32_write(disk_t *disk_car,const unsigned int count, const void *buf, const uint64_t offset);
-static int file_win32_nowrite(disk_t *disk_car, const unsigned int count, const void *buf, const uint64_t offset);
+static int file_win32_pread(disk_t *disk_car, const unsigned int count, void *buf, const uint64_t offset);
+static int file_win32_pwrite(disk_t *disk_car,const unsigned int count, const void *buf, const uint64_t offset);
+static int file_win32_nopwrite(disk_t *disk_car, const unsigned int count, const void *buf, const uint64_t offset);
static int file_win32_sync(disk_t *disk_car);
static uint64_t filewin32_setfilepointer(HANDLE handle, const char *device);
@@ -326,8 +326,8 @@ disk_t *file_test_availability_win32(const char *device, const int verbose, cons
disk_car->data=data;
disk_car->description=file_win32_description;
disk_car->description_short=file_win32_description_short;
- disk_car->read=file_win32_read;
- disk_car->write=((data->mode&FILE_WRITE_DATA)==FILE_WRITE_DATA?file_win32_write:file_win32_nowrite);
+ disk_car->pread=file_win32_pread;
+ disk_car->pwrite=((data->mode&FILE_WRITE_DATA)==FILE_WRITE_DATA?file_win32_pwrite:file_win32_nopwrite);
disk_car->sync=file_win32_sync;
disk_car->access_mode=testdisk_mode;
disk_car->clean=file_win32_clean;
@@ -429,7 +429,7 @@ static unsigned int file_win32_compute_sector_size(HANDLE handle)
return 0;
}
-static int file_win32_read_aux(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset)
+static int file_win32_pread_aux(disk_t *disk_car, void *buf, const unsigned int count, const uint64_t offset)
{
long int ret;
HANDLE fd=((struct info_file_win32_struct *)disk_car->data)->handle;
@@ -448,7 +448,7 @@ static int file_win32_read_aux(disk_t *disk_car, void *buf, const unsigned int c
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
- log_error("file_win32_read(%d,%u,buffer,%lu(%u/%u/%u)) seek err %s\n", (int)fd,
+ log_error("file_win32_pread(%d,%u,buffer,%lu(%u/%u/%u)) seek err %s\n", (int)fd,
(unsigned)(count/disk_car->sector_size), (long unsigned int)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset), offset2head(disk_car,offset), offset2sector(disk_car,offset),
(char*)lpMsgBuf);
@@ -461,11 +461,11 @@ static int file_win32_read_aux(disk_t *disk_car, void *buf, const unsigned int c
if(ret)
ret=dwByteRead;
}
- if(ret!=count)
+ if(ret!=(signed)count)
{
if(ret>0 || offset<disk_car->disk_size)
{
- log_error("file_win32_read(%d,%u,buffer,%lu(%u/%u/%u)) read err: ", (int)fd,
+ log_error("file_win32_pread(%d,%u,buffer,%lu(%u/%u/%u)) read err: ", (int)fd,
(unsigned)(count/disk_car->sector_size), (long unsigned)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset), offset2head(disk_car,offset), offset2sector(disk_car,offset));
if(ret<0)
@@ -488,19 +488,18 @@ static int file_win32_read_aux(disk_t *disk_car, void *buf, const unsigned int c
else
log_error("Partial read\n");
}
- if(ret<=0)
- return -1;
- memset((char*)buf+ret,0,count-ret);
+ if(ret>0)
+ memset((char*)buf+ret,0,count-ret);
}
- return 0;
+ return ret;
}
-static int file_win32_read(disk_t *disk_car,const unsigned int count, void *buf, const uint64_t offset)
+static int file_win32_pread(disk_t *disk_car,const unsigned int count, void *buf, const uint64_t offset)
{
- return align_read(&file_win32_read_aux, disk_car, buf, count, offset);
+ return align_pread(&file_win32_pread_aux, disk_car, buf, count, offset);
}
-static int file_win32_write_aux(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset)
+static int file_win32_pwrite_aux(disk_t *disk_car, const void *buf, const unsigned int count, const uint64_t offset)
{
long int ret;
HANDLE fd=((struct info_file_win32_struct *)disk_car->data)->handle;
@@ -519,7 +518,7 @@ static int file_win32_write_aux(disk_t *disk_car, const void *buf, const unsigne
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
- log_error("file_win32_write(%d,%u,buffer,%lu(%u/%u/%u)) seek err %s\n", (int)fd,
+ log_error("file_win32_pwrite(%d,%u,buffer,%lu(%u/%u/%u)) seek err %s\n", (int)fd,
(unsigned)(count/disk_car->sector_size), (long unsigned int)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset), offset2head(disk_car,offset), offset2sector(disk_car,offset),
(char*)lpMsgBuf);
@@ -533,25 +532,24 @@ static int file_win32_write_aux(disk_t *disk_car, const void *buf, const unsigne
ret=dwByteRead;
}
disk_car->write_used=1;
- if(ret!=count)
+ if(ret!=(signed)count)
{
- log_error("file_win32_write(%u,%u,buffer,%lu(%u/%u/%u)) write err\n", (int)fd,
+ log_error("file_win32_pwrite(%u,%u,buffer,%lu(%u/%u/%u)) write err\n", (int)fd,
(unsigned)(count/disk_car->sector_size), (long unsigned)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset),offset2head(disk_car,offset),offset2sector(disk_car,offset));
- return -1;
}
- return 0;
+ return ret;
}
-static int file_win32_write(disk_t *disk_car,const unsigned int count, const void *buf, const uint64_t offset)
+static int file_win32_pwrite(disk_t *disk_car,const unsigned int count, const void *buf, const uint64_t offset)
{
- return align_write(&file_win32_read_aux, &file_win32_write_aux, disk_car, buf, count, offset);
+ return align_pwrite(&file_win32_pread_aux, &file_win32_pwrite_aux, disk_car, buf, count, offset);
}
-static int file_win32_nowrite(disk_t *disk_car,const unsigned int count, const void *buf, const uint64_t offset)
+static int file_win32_nopwrite(disk_t *disk_car,const unsigned int count, const void *buf, const uint64_t offset)
{
const struct info_file_win32_struct *data=disk_car->data;
- log_warning("file_win32_nowrite(%d,%u,buffer,%lu(%u/%u/%u)) write refused\n", (unsigned int)data->handle,
+ log_warning("file_win32_nopwrite(%d,%u,buffer,%lu(%u/%u/%u)) write refused\n", (unsigned int)data->handle,
(unsigned)(count/disk_car->sector_size),(long unsigned)(offset/disk_car->sector_size),
offset2cylinder(disk_car,offset),offset2head(disk_car,offset),offset2sector(disk_car,offset));
return -1;
diff --git a/src/xfs.c b/src/xfs.c
index c461ad6..e575f18 100644
--- a/src/xfs.c
+++ b/src/xfs.c
@@ -44,7 +44,7 @@ static int test_xfs(const disk_t *disk_car, const struct xfs_sb *sb,partition_t
int check_xfs(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(XFS_SUPERBLOCK_SIZE);
- if(disk_car->read(disk_car,XFS_SUPERBLOCK_SIZE, buffer, partition->part_offset)!=0)
+ if(disk_car->pread(disk_car, buffer, XFS_SUPERBLOCK_SIZE, partition->part_offset) != XFS_SUPERBLOCK_SIZE)
{
free(buffer);
return 1;