rmtfs: Better support for EFS backed by files

Currently, in order to back the EFS storage with a regular file,
those files have to be pre-allocated, and with their correct size.
This is especially problematic when preparing a minimal FSG, since
we do not know ahead of time what size to pre-allocate.

Allow reads that go beyond the end of the backing storage to simply
read zeroes. When a write comes in, the file will be automatically
expanded to the correct size. (And should really only be written
if a full sector was pulled out of the modem). For solutions
that use partitions instead of files, this change should be a no-op.
This commit is contained in:
Evan Green 2018-12-07 14:48:33 -08:00 committed by Bjorn Andersson
parent 0d3c49ec5a
commit 08d20f1646

View File

@ -188,10 +188,15 @@ static void rmtfs_iovec(int sock, struct qrtr_packet *pkt)
for (j = 0; j < entries[i].num_sector; j++) {
if (is_write) {
n = rmtfs_mem_read(rmem, phys_offset, buf, SECTOR_SIZE);
n = write(fd, buf, n);
if (n == SECTOR_SIZE)
n = write(fd, buf, n);
} else {
n = read(fd, buf, SECTOR_SIZE);
n = rmtfs_mem_write(rmem, phys_offset, buf, n);
if (n >= 0) {
if (n < SECTOR_SIZE)
memset(buf + n, 0, SECTOR_SIZE - n);
n = rmtfs_mem_write(rmem, phys_offset, buf, SECTOR_SIZE);
}
}
if (n != SECTOR_SIZE) {