diff --git a/fs/spiffs/src/spiffs_core.c b/fs/spiffs/src/spiffs_core.c index 0098afcfcb2..f0c0a58a9d3 100644 --- a/fs/spiffs/src/spiffs_core.c +++ b/fs/spiffs/src/spiffs_core.c @@ -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; diff --git a/fs/spiffs/src/spiffs_mtd.c b/fs/spiffs/src/spiffs_mtd.c index 6f7ce28f8b9..c9ac884f2bc 100644 --- a/fs/spiffs/src/spiffs_mtd.c +++ b/fs/spiffs/src/spiffs_mtd.c @@ -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) diff --git a/fs/spiffs/src/spiffs_vfs.c b/fs/spiffs/src/spiffs_vfs.c index b2c91754ede..740b1b66d52 100644 --- a/fs/spiffs/src/spiffs_vfs.c +++ b/fs/spiffs/src/spiffs_vfs.c @@ -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) {