fs/spiffs: Correct error in MTD multi-block read/write logic.

This commit is contained in:
Gregory Nutt
2018-09-26 12:29:42 -06:00
parent 4eb118afd1
commit 63ba200957
3 changed files with 16 additions and 14 deletions
+1 -1
View File
@@ -1704,7 +1704,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
if (offset > fobj->size) if (offset > fobj->size)
{ {
finfo("Offset reversed to size\n"); finfo("Offset replaced with size\n");
offset = fobj->size; offset = fobj->size;
} }
+2 -2
View File
@@ -162,7 +162,7 @@ ssize_t spiffs_mtd_write(FAR struct spiffs_s *fs, off_t offset, size_t len,
/* Write all intervening complete blocks... all at once */ /* Write all intervening complete blocks... all at once */
nblocks = blkend - blkstart + 1; nblocks = blkend - blkstart + 1;
if (nblocks > 0) if (nblocks > 0 && remaining >= blksize)
{ {
ret = MTD_BWRITE(fs->mtd, blkstart, nblocks, src); ret = MTD_BWRITE(fs->mtd, blkstart, nblocks, src);
if (ret < 0) if (ret < 0)
@@ -304,7 +304,7 @@ ssize_t spiffs_mtd_read(FAR struct spiffs_s *fs, off_t offset, size_t len,
/* Read all intervening complete blocks... all at once */ /* Read all intervening complete blocks... all at once */
nblocks = blkend - blkstart + 1; nblocks = blkend - blkstart + 1;
if (nblocks > 0) if (nblocks > 0 && remaining >= blksize)
{ {
ret = MTD_BREAD(fs->mtd, blkstart, nblocks, dest); ret = MTD_BREAD(fs->mtd, blkstart, nblocks, dest);
if (ret < 0) if (ret < 0)
+2
View File
@@ -383,6 +383,7 @@ static int spiffs_open(FAR struct file *filep, FAR const char *relpath,
} }
fobj->crefs = 1; fobj->crefs = 1;
fobj->oflags = oflags;
/* Get exclusive access to the file system */ /* Get exclusive access to the file system */
@@ -673,6 +674,7 @@ static ssize_t spiffs_write(FAR struct file *filep, FAR const char *buffer,
"Boundary violation, offset=%d size=%d\n", "Boundary violation, offset=%d size=%d\n",
fobj->cache_page->cpndx, fobj->objid, fobj->cache_page->cpndx, fobj->objid,
fobj->cache_page->offset, fobj->cache_page->size); fobj->cache_page->offset, fobj->cache_page->size);
nwritten = spiffs_fobj_write(fs, fobj, nwritten = spiffs_fobj_write(fs, fobj,
spiffs_get_cache_page(fs, spiffs_get_cache(fs), spiffs_get_cache_page(fs, spiffs_get_cache(fs),
fobj->cache_page->cpndx), fobj->cache_page->cpndx),