From e51a1174a3bb4a68dab4d41019b91d092a84c498 Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Wed, 5 Dec 2007 00:09:34 +0100 Subject: [PATCH] Fix disk cache sync and disk error handling --- src/hdaccess.c | 24 ++++++++++++++---------- src/hdcache.c | 8 ++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/hdaccess.c b/src/hdaccess.c index 387c3e12..def383ef 100644 --- a/src/hdaccess.c +++ b/src/hdaccess.c @@ -120,6 +120,7 @@ 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_sync(disk_t *disk_car); #ifndef DJGPP static disk_t *disk_get_geometry(const int hd_h, const char *device, const int verbose); #endif @@ -150,7 +151,7 @@ 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)) + if(fnct_read(disk_car, disk_car->rbuffer, count_new, offset_new/disk_car->sector_size*disk_car->sector_size)<0) return -1; memcpy(buf,(char*)disk_car->rbuffer+(offset_new%disk_car->sector_size),count); return 0; @@ -179,7 +180,7 @@ 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)) + if(fnct_read(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); @@ -613,20 +614,22 @@ static int disk_read_aux(disk_t *disk_car, void *buf, const unsigned int count, uint64_t read_offset=0; do { - int i; - int rc=4; /* sector not found/read error */ + int i=0; + int rc; read_size=count-read_offset>16*512?16*512:count-read_offset; - for(i=0;(rc!=0) && (rc!=1) && (isector_size,rc); - return rc; + return -rc; } read_offset+=read_size; } while(read_offsetdata; - int i,rc=4; /* sector not found/read error */ + int i=0; + int rc; disk_car->write_used=1; - for(i=0;(rc==4)&&(isector_size, hd_offset/disk_car->sector_size); if(rc!=0) disk_reset_error(disk_car); - } + } while(rc==4 && ++idata; + data->disk_car->sync(data->disk_car); +} + disk_t *new_diskcache(disk_t *disk_car, const unsigned int testdisk_mode) { unsigned int i; @@ -255,6 +262,7 @@ disk_t *new_diskcache(disk_t *disk_car, const unsigned int testdisk_mode) new_disk_car->data=data; new_disk_car->read=cache_read; new_disk_car->write=cache_write; + new_disk_car->sync=cache_sync; new_disk_car->clean=cache_clean; new_disk_car->description=cache_description; new_disk_car->description_short=cache_description_short;