simfs: Fix the number of bytes copied

In block reading operations we read too much when the number of bytes to
read is smaller than the size of the file.
This commit is contained in:
Denis Kenzior 2010-10-13 02:38:11 -05:00
parent e755292874
commit bd8c7e92bb
1 changed files with 5 additions and 4 deletions

View File

@ -227,12 +227,13 @@ 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);
tocopy = MIN(256 - op->offset % 256,
op->num_bytes - op->current * 256);
} else {
bufoff = (op->current - start_block - 1) * 256 +
op->offset % 256;
dataoff = 0;
tocopy = len;
tocopy = MIN(256, op->num_bytes - op->current * 256);
}
DBG("bufoff: %d, dataoff: %d, tocopy: %d",
@ -290,12 +291,12 @@ static gboolean sim_fs_op_read_block(gpointer user_data)
seekoff = SIM_CACHE_HEADER_SIZE + op->current * 256 +
op->offset % 256;
toread = MIN(256 - op->offset % 256,
op->length - op->current * 256);
op->num_bytes - op->current * 256);
} else {
bufoff = (op->current - start_block - 1) * 256 +
op->offset % 256;
seekoff = SIM_CACHE_HEADER_SIZE + op->current * 256;
toread = MIN(256, op->length - op->current * 256);
toread = MIN(256, op->num_bytes - op->current * 256);
}
DBG("bufoff: %d, seekoff: %d, toread: %d",