Compare commits

...

2 Commits

Author SHA1 Message Date
Slava Monich
e4f3ec6322 Merge pull request #1 from monich/start_block
Fix SIM I/O mess
2021-07-30 15:12:59 +03:00
Slava Monich
95fd4efc37 [simfs] Fix SIM I/O mess. JB#54380
Apparently all simfs reads from any blocks other than the very first one
were badly broken and could even cause a crash :|
2021-07-30 01:50:07 +03:00

View File

@@ -405,18 +405,18 @@ static void sim_fs_op_read_block_cb(const struct ofono_error *error,
}
start_block = op->offset / 256;
end_block = (op->offset + (op->num_bytes - 1)) / 256;
end_block = op->num_bytes ? (op->offset + op->num_bytes - 1) / 256 :
start_block;
if (op->current == start_block) {
bufoff = 0;
dataoff = op->offset % 256;
tocopy = MIN(256 - op->offset % 256,
op->num_bytes - op->current * 256);
tocopy = MIN(256 - dataoff, op->num_bytes);
} else {
bufoff = (op->current - start_block - 1) * 256 +
bufoff = (op->current - start_block) * 256 -
op->offset % 256;
dataoff = 0;
tocopy = MIN(256, op->num_bytes - op->current * 256);
tocopy = MIN(256, op->num_bytes - bufoff);
}
DBG("bufoff: %d, dataoff: %d, tocopy: %d",
@@ -485,13 +485,12 @@ 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->num_bytes - op->current * 256);
toread = MIN(256 - op->offset % 256, op->num_bytes);
} else {
bufoff = (op->current - start_block - 1) * 256 +
bufoff = (op->current - start_block) * 256 -
op->offset % 256;
seekoff = SIM_CACHE_HEADER_SIZE + op->current * 256;
toread = MIN(256, op->num_bytes - op->current * 256);
toread = MIN(256, op->num_bytes - bufoff);
}
DBG("bufoff: %d, seekoff: %d, toread: %d",