mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +08:00
fs/spiffs: Correct error in MTD multi-block read/write logic.
This commit is contained in:
@@ -1439,7 +1439,7 @@ int spiffs_object_update_index_hdr(FAR struct spiffs_s *fs,
|
|||||||
return ret;
|
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);
|
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)
|
if (offset > fobj->size)
|
||||||
{
|
{
|
||||||
finfo("Offset reversed to size\n");
|
finfo("Offset replaced with size\n");
|
||||||
offset = fobj->size;
|
offset = fobj->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1717,8 +1717,8 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
objhdr = (FAR struct spiffs_pgobj_ndxheader_s *) fs->work;
|
objhdr = (FAR struct spiffs_pgobj_ndxheader_s *)fs->work;
|
||||||
objndx = (FAR struct spiffs_page_objndx_s *) fs->work;
|
objndx = (FAR struct spiffs_page_objndx_s *)fs->work;
|
||||||
cur_objndx_spndx = 0;
|
cur_objndx_spndx = 0;
|
||||||
prev_objndx_spndx = (int16_t)-1;
|
prev_objndx_spndx = (int16_t)-1;
|
||||||
cur_objndx_pgndx = fobj->objhdr_pgndx;
|
cur_objndx_pgndx = fobj->objhdr_pgndx;
|
||||||
@@ -2249,8 +2249,8 @@ int spiffs_object_modify(FAR struct spiffs_s *fs,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
objhdr = (FAR struct spiffs_pgobj_ndxheader_s *) fs->work;
|
objhdr = (FAR struct spiffs_pgobj_ndxheader_s *)fs->work;
|
||||||
objndx = (FAR struct spiffs_page_objndx_s *) fs->work;
|
objndx = (FAR struct spiffs_page_objndx_s *)fs->work;
|
||||||
|
|
||||||
cur_objndx_spndx = 0;
|
cur_objndx_spndx = 0;
|
||||||
prev_objndx_spndx = (int16_t) - 1;
|
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;
|
min_i = 0;
|
||||||
map = (uint8_t *) fs->work;
|
map = (uint8_t *)fs->work;
|
||||||
min_count = 0xff;
|
min_count = 0xff;
|
||||||
|
|
||||||
for (i = 0;
|
for (i = 0;
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -382,7 +382,8 @@ static int spiffs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
fobj->crefs = 1;
|
fobj->crefs = 1;
|
||||||
|
fobj->oflags = oflags;
|
||||||
|
|
||||||
/* Get exclusive access to the file system */
|
/* 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",
|
"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),
|
||||||
fobj->cache_page->offset,
|
fobj->cache_page->offset,
|
||||||
fobj->cache_page->size);
|
fobj->cache_page->size);
|
||||||
spiffs_cache_page_release(fs, fobj->cache_page);
|
spiffs_cache_page_release(fs, fobj->cache_page);
|
||||||
if (nwritten < 0)
|
if (nwritten < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user