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

View File

@ -1439,7 +1439,7 @@ int spiffs_object_update_index_hdr(FAR struct spiffs_s *fs,
return ret;
}
objhdr = (FAR struct spiffs_pgobj_ndxheader_s *) fs->work;
objhdr = (FAR struct spiffs_pgobj_ndxheader_s *)fs->work;
}
ret = spiffs_validate_objndx(&objhdr->phdr, objid, 0);
@ -1704,7 +1704,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
if (offset > fobj->size)
{
finfo("Offset reversed to size\n");
finfo("Offset replaced with size\n");
offset = fobj->size;
}
@ -1717,8 +1717,8 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
return ret;
}
objhdr = (FAR struct spiffs_pgobj_ndxheader_s *) fs->work;
objndx = (FAR struct spiffs_page_objndx_s *) fs->work;
objhdr = (FAR struct spiffs_pgobj_ndxheader_s *)fs->work;
objndx = (FAR struct spiffs_page_objndx_s *)fs->work;
cur_objndx_spndx = 0;
prev_objndx_spndx = (int16_t)-1;
cur_objndx_pgndx = fobj->objhdr_pgndx;
@ -2249,8 +2249,8 @@ int spiffs_object_modify(FAR struct spiffs_s *fs,
return ret;
}
objhdr = (FAR struct spiffs_pgobj_ndxheader_s *) fs->work;
objndx = (FAR struct spiffs_page_objndx_s *) fs->work;
objhdr = (FAR struct spiffs_pgobj_ndxheader_s *)fs->work;
objndx = (FAR struct spiffs_page_objndx_s *)fs->work;
cur_objndx_spndx = 0;
prev_objndx_spndx = (int16_t) - 1;
@ -3469,7 +3469,7 @@ int spiffs_objlu_find_free_objid(FAR struct spiffs_s *fs, int16_t *objid,
*/
min_i = 0;
map = (uint8_t *) fs->work;
map = (uint8_t *)fs->work;
min_count = 0xff;
for (i = 0;

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 */
nblocks = blkend - blkstart + 1;
if (nblocks > 0)
if (nblocks > 0 && remaining >= blksize)
{
ret = MTD_BWRITE(fs->mtd, blkstart, nblocks, src);
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 */
nblocks = blkend - blkstart + 1;
if (nblocks > 0)
if (nblocks > 0 && remaining >= blksize)
{
ret = MTD_BREAD(fs->mtd, blkstart, nblocks, dest);
if (ret < 0)

View File

@ -382,7 +382,8 @@ static int spiffs_open(FAR struct file *filep, FAR const char *relpath,
return -ENOMEM;
}
fobj->crefs = 1;
fobj->crefs = 1;
fobj->oflags = oflags;
/* Get exclusive access to the file system */
@ -673,11 +674,12 @@ static ssize_t spiffs_write(FAR struct file *filep, FAR const char *buffer,
"Boundary violation, offset=%d size=%d\n",
fobj->cache_page->cpndx, fobj->objid,
fobj->cache_page->offset, fobj->cache_page->size);
nwritten = spiffs_fobj_write(fs, fobj,
spiffs_get_cache_page(fs, spiffs_get_cache(fs),
fobj->cache_page->cpndx),
fobj->cache_page->offset,
fobj->cache_page->size);
spiffs_get_cache_page(fs, spiffs_get_cache(fs),
fobj->cache_page->cpndx),
fobj->cache_page->offset,
fobj->cache_page->size);
spiffs_cache_page_release(fs, fobj->cache_page);
if (nwritten < 0)
{