summaryrefslogtreecommitdiffstats
path: root/src/alignio.h
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 /src/alignio.h
parent9970a484b6983cbf5659ebf17335b4192065025e (diff)
Use pread() and pwrite() argument style for internal I/O
Diffstat (limited to 'src/alignio.h')
-rw-r--r--src/alignio.h20
1 files changed, 10 insertions, 10 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);
}