---
src/simfs.c | 21 ++++++++++++---------
1 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/simfs.c b/src/simfs.c
index 5fbee8b..bfcdf23 100644
--- a/src/simfs.c
+++ b/src/simfs.c
@@ -229,14 +229,16 @@ static void sim_fs_op_read_block_cb(const struct
ofono_error *error,
if (op->current == start_block) {
bufoff = 0;
dataoff = op->offset % 256;
- tocopy = MIN(256 - op->offset % 256, len);
} else {
- bufoff = (op->current - start_block - 1) * 256 +
- op->offset % 256;
+ bufoff = op->current * 256;
dataoff = 0;
- tocopy = len;
}
+ tocopy = op->num_bytes % 256;
+
+ if ((tocopy == 0) || (op->current != end_block))
+ tocopy = 256;
+
memcpy(fs->buffer + bufoff, data + dataoff, tocopy);
cache_block(fs, op->current, 256, data, len);
@@ -288,15 +290,16 @@ static gboolean sim_fs_op_read_block(gpointer user_data)
bufoff = 0;
seekoff = SIM_CACHE_HEADER_SIZE + op->current * 256 +
op->offset % 256;
- toread = MIN(256 - op->offset % 256,
- op->length - op->current * 256);
} else {
- bufoff = (op->current - start_block - 1) * 256 +
- op->offset % 256;
+ bufoff = op->current * 256;
seekoff = SIM_CACHE_HEADER_SIZE + op->current * 256;
- toread = MIN(256, op->length - op->current * 256);
}
+ toread = op->num_bytes % 256;
+
+ if ((toread == 0) || (op->current != end_block))
+ toread = 256;
+
if (lseek(fs->fd, seekoff, SEEK_SET) == (off_t) -1)
break;
--
1.7.2.1
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono