From 08d20f16464d1e5176391f126aee06de08e6fb34 Mon Sep 17 00:00:00 2001 From: Evan Green Date: Fri, 7 Dec 2018 14:48:33 -0800 Subject: [PATCH] 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. --- rmtfs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rmtfs.c b/rmtfs.c index 2175166..c190d17 100644 --- a/rmtfs.c +++ b/rmtfs.c @@ -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) {