mirror of
https://github.com/apache/nuttx.git
synced 2026-09-28 15:54:57 +08:00
fs/spiffs: Various fixes from initial testing. Still lots of issues. Also changes from further review to get better naming consistency and functional partitioning.
This commit is contained in:
@@ -2,6 +2,7 @@ CONFIG_ARCH="sim"
|
||||
CONFIG_ARCH_BOARD="sim"
|
||||
CONFIG_ARCH_BOARD_SIM=y
|
||||
CONFIG_ARCH_SIM=y
|
||||
CONFIG_BOARD_INITIALIZE=y
|
||||
CONFIG_DEBUG_ASSERTIONS=y
|
||||
CONFIG_DEBUG_FEATURES=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
@@ -11,6 +12,7 @@ CONFIG_DISABLE_POSIX_TIMERS=y
|
||||
CONFIG_DISABLE_PTHREAD=y
|
||||
CONFIG_DISABLE_SIGNALS=y
|
||||
CONFIG_EXAMPLES_FSTEST=y
|
||||
CONFIG_EXAMPLES_FSTEST_MOUNTPT="/mnt/spiffs"
|
||||
CONFIG_EXPERIMENTAL=y
|
||||
CONFIG_FS_SPIFFS=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=4096
|
||||
|
||||
@@ -181,6 +181,16 @@ int sim_bringup(void)
|
||||
ret);
|
||||
}
|
||||
|
||||
/* Mount the SPIFFS file system */
|
||||
|
||||
ret = mount("/dev/rammtd", "/mnt/spiffs", "spiffs", 0, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to mount SPIFFS at /mnt/spiffs: %d\n",
|
||||
ret);
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_FS_NXFFS)
|
||||
/* Initialize to provide NXFFS on the MTD interface */
|
||||
|
||||
|
||||
@@ -147,12 +147,13 @@ struct spiffs_s
|
||||
FAR uint8_t *work; /* Secondary work buffer, size of a logical page */
|
||||
FAR void *cache; /* Cache memory */
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
off64_t phys_size; /* Physical size of the SPI flash */
|
||||
off64_t media_size; /* Physical size of the SPI flash */
|
||||
#else
|
||||
off_t phys_size; /* Physical size of the SPI flash */
|
||||
off_t media_size; /* Physical size of the SPI flash */
|
||||
#endif
|
||||
int free_entry; /* Cursor for free blocks, entry index */
|
||||
int lu_entry; /* Cursor when searching, entry index */
|
||||
uint32_t total_pages; /* Total number of pages on the media */
|
||||
uint32_t free_blocks; /* Current number of free blocks */
|
||||
uint32_t stats_p_allocated; /* Current number of busy pages */
|
||||
uint32_t stats_p_deleted; /* Current number of deleted pages */
|
||||
@@ -164,10 +165,10 @@ struct spiffs_s
|
||||
uint32_t cache_hits; /* Number of cache hits */
|
||||
uint32_t cache_misses; /* Number of cache misses */
|
||||
#endif
|
||||
uint32_t config_magic; /* Config magic */
|
||||
int16_t free_blkndx; /* cursor for free blocks, block index */
|
||||
int16_t free_blkndx; /* Cursor for free blocks, block index */
|
||||
int16_t lu_blkndx; /* Cursor when searching, block index */
|
||||
int16_t max_erase_count; /* Max erase count amongst all blocks */
|
||||
uint8_t pages_per_block; /* Pages per block */
|
||||
};
|
||||
|
||||
/* This structure represents the state of an open file */
|
||||
|
||||
@@ -144,7 +144,7 @@ static int spiffs_cache_page_free(FAR struct spiffs_s *fs, int cpndx,
|
||||
cpndx, cp->pgndx);
|
||||
|
||||
ret = spiffs_mtd_write(fs, SPIFFS_PAGE_TO_PADDR(fs, cp->pgndx),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), mem);
|
||||
SPIFFS_GEO_PAGE_SIZE(fs), mem);
|
||||
}
|
||||
|
||||
if (cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR)
|
||||
@@ -460,7 +460,7 @@ ssize_t spiffs_cache_read(FAR struct spiffs_s *fs, uint8_t op, int16_t objid,
|
||||
|
||||
ret = spiffs_mtd_read(fs, addr -
|
||||
SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr),
|
||||
SPIFFS_CFG_LOG_PAGE_SZ(fs),
|
||||
SPIFFS_GEO_PAGE_SIZE(fs),
|
||||
spiffs_get_cache_page(fs, cache, cp->cpndx));
|
||||
|
||||
mem = spiffs_get_cache_page(fs, cache, cp->cpndx);
|
||||
|
||||
@@ -61,7 +61,7 @@ extern "C"
|
||||
#define SPIFFS_CACHE_FLAG_TYPE_WR (1 << 7)
|
||||
|
||||
#define SPIFFS_CACHE_PAGE_SIZE(fs) \
|
||||
(sizeof(struct spiffs_cache_page_s) + SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
(sizeof(struct spiffs_cache_page_s) + SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
|
||||
#define spiffs_get_cache(fs) \
|
||||
((FAR struct spiffs_cache_s *)((fs)->cache))
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+100
-99
File diff suppressed because it is too large
Load Diff
+51
-73
@@ -174,138 +174,116 @@
|
||||
|
||||
#define SPIFFS_VIS_END (SPIFFS_ERR_INTERNAL - 22)
|
||||
|
||||
/* updating an object index contents */
|
||||
/* Events */
|
||||
|
||||
#define SPIFFS_EV_IX_UPD (0)
|
||||
#define SPIFFS_EV_NDXUPD (0) /* Updating object index contents */
|
||||
#define SPIFFS_EV_NDXNEW (1) /* Creating new object index */
|
||||
#define SPIFFS_EV_NDXDEL (2) /* Deleting object index */
|
||||
#define SPIFFS_EV_NDXMOV (3) /* Moving abject index without
|
||||
* updating contents */
|
||||
#define SPIFFS_EV_NDXUPD_HDR (4) /* Updating object index header
|
||||
* data only (not the table itself */
|
||||
|
||||
/* creating a new object index */
|
||||
|
||||
#define SPIFFS_EV_IX_NEW (1)
|
||||
|
||||
/* deleting an object index */
|
||||
|
||||
#define SPIFFS_EV_IX_DEL (2)
|
||||
|
||||
/* moving an object index without updating contents */
|
||||
|
||||
#define SPIFFS_EV_IX_MOV (3)
|
||||
|
||||
/* updating an object index header data only, not the table itself */
|
||||
|
||||
#define SPIFFS_EV_IX_UPD_HDR (4)
|
||||
|
||||
#define SPIFFS_OBJ_ID_IX_FLAG ((int16_t)(1<<(8*sizeof(int16_t)-1)))
|
||||
#define SPIFFS_OBJID_NDXFLAG ((int16_t)(1 << (8 * sizeof(int16_t) - 1)))
|
||||
|
||||
#define SPIFFS_UNDEFINED_LEN (uint32_t)(-1)
|
||||
|
||||
#define SPIFFS_OBJ_ID_DELETED ((int16_t)0)
|
||||
#define SPIFFS_OBJ_ID_FREE ((int16_t)-1)
|
||||
#define SPIFFS_OBJID_DELETED ((int16_t)0)
|
||||
#define SPIFFS_OBJID_FREE ((int16_t)-1)
|
||||
|
||||
/* total number of pages */
|
||||
/* Number of object lookup pages per block */
|
||||
|
||||
#define SPIFFS_MAX_PAGES(fs) \
|
||||
(SPIFFS_CFG_PHYS_SZ(fs)/SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
#define SPIFFS_OBJ_LOOKUP_PAGES(fs) \
|
||||
(MAX(1, (SPIFFS_GEO_PAGES_PER_BLOCK(fs) * sizeof(int16_t)) / SPIFFS_GEO_PAGE_SIZE(fs)))
|
||||
|
||||
/* total number of pages per block, including object lookup pages */
|
||||
|
||||
#define SPIFFS_PAGES_PER_BLOCK(fs) \
|
||||
(SPIFFS_CFG_LOG_BLOCK_SZ(fs)/SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
|
||||
/* number of object lookup pages per block */
|
||||
|
||||
#define SPIFFS_OBJ_LOOKUP_PAGES(fs) \
|
||||
(MAX(1, (SPIFFS_PAGES_PER_BLOCK(fs) * sizeof(int16_t)) / SPIFFS_CFG_LOG_PAGE_SZ(fs)))
|
||||
|
||||
/* checks if page index belongs to object lookup */
|
||||
/* Checks if page index belongs to object lookup */
|
||||
|
||||
#define SPIFFS_IS_LOOKUP_PAGE(fs,pgndx) \
|
||||
(((pgndx) % SPIFFS_PAGES_PER_BLOCK(fs)) < SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
(((pgndx) % SPIFFS_GEO_PAGES_PER_BLOCK(fs)) < SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
|
||||
/* number of object lookup entries in all object lookup pages */
|
||||
/* Number of object lookup entries in all object lookup pages */
|
||||
|
||||
#define SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) \
|
||||
(SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
(SPIFFS_GEO_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
|
||||
/* converts a block to physical address */
|
||||
/* Converts a block to physical address */
|
||||
|
||||
#define SPIFFS_BLOCK_TO_PADDR(fs, block) ((block) * SPIFFS_CFG_LOG_BLOCK_SZ(fs))
|
||||
#define SPIFFS_BLOCK_TO_PADDR(fs, block) ((block) * SPIFFS_GEO_BLOCK_SIZE(fs))
|
||||
|
||||
/* converts a object lookup entry to page index */
|
||||
/* Converts a object lookup entry to page index */
|
||||
|
||||
#define SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, block, entry) \
|
||||
((block)*SPIFFS_PAGES_PER_BLOCK(fs) + (SPIFFS_OBJ_LOOKUP_PAGES(fs) + entry))
|
||||
((block)*SPIFFS_GEO_PAGES_PER_BLOCK(fs) + (SPIFFS_OBJ_LOOKUP_PAGES(fs) + entry))
|
||||
|
||||
/* converts a object lookup entry to physical address of corresponding page */
|
||||
/* Converts a object lookup entry to physical address of corresponding page */
|
||||
|
||||
#define SPIFFS_OBJ_LOOKUP_ENTRY_TO_PADDR(fs, block, entry) \
|
||||
(SPIFFS_BLOCK_TO_PADDR(fs, block) + (SPIFFS_OBJ_LOOKUP_PAGES(fs) + entry) * SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
(SPIFFS_BLOCK_TO_PADDR(fs, block) + (SPIFFS_OBJ_LOOKUP_PAGES(fs) + entry) * SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
|
||||
/* converts a page to physical address */
|
||||
/* Converts a page to physical address */
|
||||
|
||||
#define SPIFFS_PAGE_TO_PADDR(fs, page) ((page) * SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
#define SPIFFS_PAGE_TO_PADDR(fs, page) ((page) * SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
|
||||
/* converts a physical address to page */
|
||||
/* Converts a physical address to page */
|
||||
|
||||
#define SPIFFS_PADDR_TO_PAGE(fs, addr) ((addr) / SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
#define SPIFFS_PADDR_TO_PAGE(fs, addr) ((addr) / SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
|
||||
/* gives index in page for a physical address */
|
||||
/* Gives index in page for a physical address */
|
||||
|
||||
#define SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr) ((addr) % SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
#define SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr) ((addr) % SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
|
||||
/* returns containing block for given page */
|
||||
/* Returns containing block for given page */
|
||||
|
||||
#define SPIFFS_BLOCK_FOR_PAGE(fs, page) ((page) / SPIFFS_PAGES_PER_BLOCK(fs))
|
||||
#define SPIFFS_BLOCK_FOR_PAGE(fs, page) ((page) / SPIFFS_GEO_PAGES_PER_BLOCK(fs))
|
||||
|
||||
/* returns starting page for block */
|
||||
/* Returns starting page for block */
|
||||
|
||||
#define SPIFFS_PAGE_FOR_BLOCK(fs, block) ((block) * SPIFFS_PAGES_PER_BLOCK(fs))
|
||||
#define SPIFFS_PAGE_FOR_BLOCK(fs, block) ((block) * SPIFFS_GEO_PAGES_PER_BLOCK(fs))
|
||||
|
||||
/* converts page to entry in object lookup page */
|
||||
/* Converts page to entry in object lookup page */
|
||||
|
||||
#define SPIFFS_OBJ_LOOKUP_ENTRY_FOR_PAGE(fs, page) \
|
||||
((page) % SPIFFS_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
((page) % SPIFFS_GEO_PAGES_PER_BLOCK(fs) - SPIFFS_OBJ_LOOKUP_PAGES(fs))
|
||||
|
||||
/* returns data size in a data page */
|
||||
/* Returns data size in a data page */
|
||||
|
||||
#define SPIFFS_DATA_PAGE_SIZE(fs) \
|
||||
(SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(struct spiffs_page_header_s))
|
||||
(SPIFFS_GEO_PAGE_SIZE(fs) - sizeof(struct spiffs_page_header_s))
|
||||
|
||||
/* returns physical address for block's erase count,
|
||||
/* Returns physical address for block's erase count,
|
||||
* always in the physical last entry of the last object lookup page
|
||||
*/
|
||||
|
||||
#define SPIFFS_ERASE_COUNT_PADDR(fs, blkndx) \
|
||||
(SPIFFS_BLOCK_TO_PADDR(fs, blkndx) + SPIFFS_OBJ_LOOKUP_PAGES(fs) * SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(int16_t))
|
||||
(SPIFFS_BLOCK_TO_PADDR(fs, blkndx) + SPIFFS_OBJ_LOOKUP_PAGES(fs) * SPIFFS_GEO_PAGE_SIZE(fs) - sizeof(int16_t))
|
||||
|
||||
/* checks if there is any room for magic in the object luts */
|
||||
/* Checks if there is any room for magic in the object luts */
|
||||
|
||||
#define SPIFFS_CHECK_MAGIC_POSSIBLE(fs) \
|
||||
((SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) % (SPIFFS_CFG_LOG_PAGE_SZ(fs)/sizeof(int16_t))) * sizeof(int16_t) \
|
||||
<= (SPIFFS_CFG_LOG_PAGE_SZ(fs)-sizeof(int16_t)*2))
|
||||
((SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) % (SPIFFS_GEO_PAGE_SIZE(fs)/sizeof(int16_t))) * sizeof(int16_t) \
|
||||
<= (SPIFFS_GEO_PAGE_SIZE(fs)-sizeof(int16_t)*2))
|
||||
|
||||
/* define helpers object */
|
||||
|
||||
/* entries in an object header page index */
|
||||
/* Entries in an object header page index */
|
||||
|
||||
#define SPIFFS_OBJ_HDR_IX_LEN(fs) \
|
||||
((SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(struct spiffs_pgobj_ndxheader_s))/sizeof(int16_t))
|
||||
((SPIFFS_GEO_PAGE_SIZE(fs) - sizeof(struct spiffs_pgobj_ndxheader_s))/sizeof(int16_t))
|
||||
|
||||
/* entries in an object page index */
|
||||
/* Entries in an object page index */
|
||||
|
||||
#define SPIFFS_OBJ_IX_LEN(fs) \
|
||||
((SPIFFS_CFG_LOG_PAGE_SZ(fs) - sizeof(struct spiffs_page_objndx_s))/sizeof(int16_t))
|
||||
((SPIFFS_GEO_PAGE_SIZE(fs) - sizeof(struct spiffs_page_objndx_s))/sizeof(int16_t))
|
||||
|
||||
/* object index entry for given data span index */
|
||||
/* Object index entry for given data span index */
|
||||
|
||||
#define SPIFFS_OBJ_IX_ENTRY(fs, spndx) \
|
||||
((spndx) < SPIFFS_OBJ_HDR_IX_LEN(fs) ? (spndx) : (((spndx)-SPIFFS_OBJ_HDR_IX_LEN(fs))%SPIFFS_OBJ_IX_LEN(fs)))
|
||||
|
||||
/* object index span index number for given data span index or entry */
|
||||
/* Object index span index number for given data span index or entry */
|
||||
|
||||
#define SPIFFS_OBJ_IX_ENTRY_SPAN_IX(fs, spndx) \
|
||||
((spndx) < SPIFFS_OBJ_HDR_IX_LEN(fs) ? 0 : (1+((spndx)-SPIFFS_OBJ_HDR_IX_LEN(fs))/SPIFFS_OBJ_IX_LEN(fs)))
|
||||
|
||||
/* get data span index for object index span index */
|
||||
/* Get data span index for object index span index */
|
||||
|
||||
#define SPIFFS_DATA_SPAN_IX_FOR_OBJ_IX_SPAN_IX(fs, spndx) \
|
||||
((spndx) == 0 ? 0 : (SPIFFS_OBJ_HDR_IX_LEN(fs) + (((spndx)-1) * SPIFFS_OBJ_IX_LEN(fs))))
|
||||
@@ -422,7 +400,7 @@ int spiffs_foreach_objlu(FAR struct spiffs_s *fs, int16_t starting_block,
|
||||
FAR void *user_var, FAR int16_t *blkndx, int *lu_entry);
|
||||
int spiffs_erase_block(FAR struct spiffs_s *fs, int16_t blkndx);
|
||||
int spiffs_objlu_scan(FAR struct spiffs_s *fs);
|
||||
int spiffs_objlu_find_free_obj_id(FAR struct spiffs_s *fs,
|
||||
int spiffs_objlu_find_free_objid(FAR struct spiffs_s *fs,
|
||||
int16_t *objid, FAR const uint8_t *conflicting_name);
|
||||
int spiffs_objlu_find_free(FAR struct spiffs_s *fs,
|
||||
int16_t starting_block, int starting_lu_entry,
|
||||
|
||||
+75
-67
File diff suppressed because it is too large
Load Diff
+17
-16
@@ -64,13 +64,13 @@
|
||||
* Write data to FLASH memory
|
||||
*
|
||||
* Input Parameters:
|
||||
* fs - A reference to the volume structure
|
||||
* fs - A reference to the volume structure
|
||||
* offset - The physical offset to write to
|
||||
* len - The number of bytes to write
|
||||
* src - A reference to the bytes to be written
|
||||
* len - The number of bytes to write
|
||||
* src - A reference to the bytes to be written
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes written is returned. On failure, a
|
||||
* On success, the number of bytes written is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
@@ -81,28 +81,30 @@ ssize_t spiffs_mtd_write(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
int16_t blksize;
|
||||
off_t blkstart;
|
||||
off_t blkend;
|
||||
|
||||
ssize_t ret;
|
||||
|
||||
DEBUGASSERT(fs != NULL && fs->mtd != NULL && src != NULL);
|
||||
|
||||
#warning REVISIT: What are units of offset and len?
|
||||
|
||||
#ifdef CONFIG_MTD_BYTE_WRITE
|
||||
ret = MTD_WRITE(fs->mtd, offset, len, src);
|
||||
if (ret < 0)
|
||||
#endif
|
||||
{
|
||||
/* We will have to do a block read */
|
||||
|
||||
blksize = fs->geo.blocksize;
|
||||
DEBUGASSERT(offset = offset % blksize);
|
||||
DEBUGASSERT(len = len % blksize);
|
||||
DEBUGASSERT(offset == offset % blksize);
|
||||
DEBUGASSERT(len == len % blksize);
|
||||
|
||||
blkstart = offset / blksize; /* Truncates to floor */
|
||||
blkend = (offset + len + blksize - 1) / blksize; /* Rounds up to ceil */
|
||||
|
||||
#warning WRONG: Needs to use page work buffer, not 'src'
|
||||
ret = MTD_BWRITE(fs->mtd, blkstart, blkend - blkstart, src);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret < 0 ret : len;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -118,7 +120,7 @@ ssize_t spiffs_mtd_write(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
* dest - The user provide location to store the bytes read from FLASH.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes read is returned. On failure, a
|
||||
* On success, the number of bytes read is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
@@ -133,22 +135,21 @@ ssize_t spiffs_mtd_read(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
|
||||
DEBUGASSERT(fs != NULL && fs->mtd != NULL && dest != NULL);
|
||||
|
||||
#warning REVISIT: What are units of offset and len?
|
||||
|
||||
ret = MTD_READ(fs->mtd, offset, len, dest);
|
||||
if (ret < 0)
|
||||
{
|
||||
blksize = fs->geo.blocksize;
|
||||
DEBUGASSERT(offset = offset % blksize);
|
||||
DEBUGASSERT(len = len % blksize);
|
||||
DEBUGASSERT(offset == offset % blksize);
|
||||
DEBUGASSERT(len == len % blksize);
|
||||
|
||||
blkstart = offset / blksize; /* Truncates to floor */
|
||||
blkend = (offset + len + blksize - 1) / blksize; /* Rounds up to ceil */
|
||||
|
||||
#warning WRONG: Needs to use page work buffer, not 'dest'
|
||||
ret = MTD_BREAD(fs->mtd, blkstart, blkend - blkstart, dest);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret < 0 ret : len;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -163,7 +164,7 @@ ssize_t spiffs_mtd_read(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
* len - The number of bytes to erase
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes erased is returned. On failure, a
|
||||
* On success, the number of bytes erased is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -53,11 +53,18 @@ extern "C"
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define SPIFFS_CFG_EBLOCK_COUNT(fs) ((fs)->geo.neraseblocks)
|
||||
#define SPIFFS_CFG_LOG_PAGE_SZ(fs) ((fs)->geo.blocksize)
|
||||
#define SPIFFS_CFG_LOG_BLOCK_SZ(fs) ((fs)->geo.blocksize)
|
||||
#define SPIFFS_CFG_PHYS_SZ(fs) ((fs)->phys_size)
|
||||
#define SPIFFS_CFG_PHYS_ERASE_SZ(fs) ((fs)->geo.erasesize)
|
||||
/* The MTD interface does not deal with pages explicitly. With most
|
||||
* hardware a logical block is the same as an SPIFFS page.
|
||||
*/
|
||||
|
||||
#define SPIFFS_GEO_MEDIA_SIZE(fs) ((fs)->media_size)
|
||||
#define SPIFFS_GEO_EBLOCK_COUNT(fs) ((fs)->geo.neraseblocks)
|
||||
#define SPIFFS_GEO_EBLOCK_SIZE(fs) ((fs)->geo.erasesize)
|
||||
#define SPIFFS_GEO_BLOCK_COUNT(fs) ((fs)->geo.neraseblocks)
|
||||
#define SPIFFS_GEO_BLOCK_SIZE(fs) ((fs)->geo.erasesize)
|
||||
#define SPIFFS_GEO_PAGE_COUNT(fs) ((fs)->total_pages)
|
||||
#define SPIFFS_GEO_PAGE_SIZE(fs) ((fs)->geo.blocksize)
|
||||
#define SPIFFS_GEO_PAGES_PER_BLOCK(fs) ((fs)->pages_per_block)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
@@ -76,7 +83,7 @@ extern "C"
|
||||
* src - A reference to the bytes to be written
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes written is returned. On failure, a
|
||||
* On success, the number of bytes written is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
@@ -97,7 +104,7 @@ ssize_t spiffs_mtd_write(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
* dest - The user provide location to store the bytes read from FLASH.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes read is returned. On failure, a
|
||||
* On success, the number of bytes read is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
@@ -117,7 +124,7 @@ ssize_t spiffs_mtd_read(FAR struct spiffs_s *fs, off_t offset, size_t len,
|
||||
* len - The number of bytes to erase
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the number of bytes erased is returned. On failure, a
|
||||
* On success, the number of bytes erased is returned. On failure, a
|
||||
* negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
+20
-17
@@ -297,8 +297,8 @@ static int spiffs_readdir_callback(FAR struct spiffs_s *fs,
|
||||
int16_t pgndx;
|
||||
int ret;
|
||||
|
||||
if (objid == SPIFFS_OBJ_ID_FREE || objid == SPIFFS_OBJ_ID_DELETED ||
|
||||
(objid & SPIFFS_OBJ_ID_IX_FLAG) == 0)
|
||||
if (objid == SPIFFS_OBJID_FREE || objid == SPIFFS_OBJID_DELETED ||
|
||||
(objid & SPIFFS_OBJID_NDXFLAG) == 0)
|
||||
{
|
||||
return SPIFFS_VIS_COUNTINUE;
|
||||
}
|
||||
@@ -314,7 +314,7 @@ static int spiffs_readdir_callback(FAR struct spiffs_s *fs,
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((objid & SPIFFS_OBJ_ID_IX_FLAG) &&
|
||||
if ((objid & SPIFFS_OBJID_NDXFLAG) &&
|
||||
objhdr.phdr.spndx == 0 &&
|
||||
(objhdr.phdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL |
|
||||
SPIFFS_PH_FLAG_IXDELE)) ==
|
||||
@@ -411,7 +411,7 @@ static int spiffs_open(FAR struct file *filep, FAR const char *relpath,
|
||||
|
||||
/* The file does not exist. We need to create the it. */
|
||||
|
||||
ret = spiffs_objlu_find_free_obj_id(fs, &objid, 0);
|
||||
ret = spiffs_objlu_find_free_objid(fs, &objid, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout_with_fileobject;
|
||||
@@ -644,7 +644,7 @@ static ssize_t spiffs_write(FAR struct file *filep, FAR const char *buffer,
|
||||
|
||||
if ((fobj->flags & O_DIRECT) == 0)
|
||||
{
|
||||
if (buflen < (size_t)SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
if (buflen < (size_t)SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
{
|
||||
/* Small write, try to cache it */
|
||||
|
||||
@@ -657,7 +657,7 @@ static ssize_t spiffs_write(FAR struct file *filep, FAR const char *buffer,
|
||||
|
||||
if (offset < fobj->cache_page->offset ||
|
||||
offset > fobj->cache_page->offset + fobj->cache_page->size ||
|
||||
offset + buflen > fobj->cache_page->offset + SPIFFS_CFG_LOG_PAGE_SZ(fs))
|
||||
offset + buflen > fobj->cache_page->offset + SPIFFS_GEO_PAGE_SIZE(fs))
|
||||
{
|
||||
/* Boundary violation, write back cache first and allocate
|
||||
* new
|
||||
@@ -881,7 +881,7 @@ static off_t spiffs_seek(FAR struct file *filep, off_t offset, int whence)
|
||||
{
|
||||
int16_t pgndx;
|
||||
|
||||
ret = spiffs_objlu_find_id_and_span(fs, fobj->objid | SPIFFS_OBJ_ID_IX_FLAG,
|
||||
ret = spiffs_objlu_find_id_and_span(fs, fobj->objid | SPIFFS_OBJID_NDXFLAG,
|
||||
objndx_spndx, 0, &pgndx);
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -956,7 +956,7 @@ static int spiffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
/* No.. we will have to erase a block at a time */
|
||||
|
||||
int16_t blkndx = 0;
|
||||
while (blkndx < fs->geo.neraseblocks)
|
||||
while (blkndx < SPIFFS_GEO_BLOCK_COUNT(fs))
|
||||
{
|
||||
fs->max_erase_count = 0;
|
||||
ret = spiffs_erase_block(fs, blkndx);
|
||||
@@ -1289,7 +1289,7 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
int ret;
|
||||
|
||||
finfo("mtdinode: %p data: %p handle: %p\n", mtdinode, data, handle);
|
||||
DEBUGASSERT(mtdinode == NULL && handle != NULL);
|
||||
DEBUGASSERT(mtdinode != NULL && handle != NULL);
|
||||
|
||||
/* Extract the MTD interface reference */
|
||||
|
||||
@@ -1316,7 +1316,9 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
goto errout_with_volume;
|
||||
}
|
||||
|
||||
fs->phys_size = fs->geo.neraseblocks * fs->geo.erasesize;
|
||||
fs->media_size = SPIFFS_GEO_EBLOCK_COUNT(fs) * SPIFFS_GEO_EBLOCK_SIZE(fs);
|
||||
fs->total_pages = fs->media_size / SPIFFS_GEO_PAGE_SIZE(fs);
|
||||
fs->pages_per_block = SPIFFS_GEO_EBLOCK_SIZE(fs) / SPIFFS_GEO_PAGE_SIZE(fs);
|
||||
|
||||
/* Get the aligned cache size */
|
||||
|
||||
@@ -1325,7 +1327,7 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
|
||||
/* Don't let the cache size exceed the maximum that is needed */
|
||||
|
||||
cache_max = SPIFFS_CFG_LOG_PAGE_SZ(fs) << 5;
|
||||
cache_max = SPIFFS_GEO_PAGE_SIZE(fs) << 5;
|
||||
if (cache_size > cache_max)
|
||||
{
|
||||
cache_size = cache_max;
|
||||
@@ -1351,7 +1353,7 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
* NOTE: Currently page size is equivalent to block size.
|
||||
*/
|
||||
|
||||
work_size = SPIFFS_CFG_LOG_PAGE_SZ(fs) << 1;
|
||||
work_size = SPIFFS_GEO_PAGE_SIZE(fs) << 1;
|
||||
work = (FAR uint8_t *)kmm_malloc(work_size);
|
||||
|
||||
if (work == NULL)
|
||||
@@ -1363,7 +1365,8 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
|
||||
fs->work = &work[0];
|
||||
fs->lu_work = &work[work_size >> 1];
|
||||
fs->config_magic = SPIFFS_SUPER_MAGIC;
|
||||
|
||||
(void)nxsem_init(&fs->exclsem.sem, 0, 1);
|
||||
|
||||
/* Check the file system */
|
||||
|
||||
@@ -1375,11 +1378,11 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
|
||||
}
|
||||
|
||||
finfo("page index byte len: %u\n",
|
||||
(unsigned int)SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
(unsigned int)SPIFFS_GEO_PAGE_SIZE(fs));
|
||||
finfo("object lookup pages: %u\n",
|
||||
(unsigned int)SPIFFS_OBJ_LOOKUP_PAGES(fs));
|
||||
finfo("page pages per block: %u\n",
|
||||
(unsigned int)SPIFFS_PAGES_PER_BLOCK(fs));
|
||||
(unsigned int)SPIFFS_GEO_PAGES_PER_BLOCK(fs));
|
||||
finfo("page header length: %u\n",
|
||||
(unsigned int)sizeof(struct spiffs_page_header_s));
|
||||
finfo("object header index entries: %u\n",
|
||||
@@ -1505,8 +1508,8 @@ static int spiffs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)
|
||||
|
||||
/* Collect some statistics */
|
||||
|
||||
pages_per_block = SPIFFS_PAGES_PER_BLOCK(fs);
|
||||
blocks = fs->geo.neraseblocks;
|
||||
pages_per_block = SPIFFS_GEO_PAGES_PER_BLOCK(fs);
|
||||
blocks = SPIFFS_GEO_BLOCK_COUNT(fs);
|
||||
obj_lupages = SPIFFS_OBJ_LOOKUP_PAGES(fs);
|
||||
data_pgsize = SPIFFS_DATA_PAGE_SIZE(fs);
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ int spiffs_stat_pgndx(FAR struct spiffs_s *fs, int16_t pgndx, int16_t objid,
|
||||
buf->st_mode = mode;
|
||||
buf->st_size = objhdr.size == SPIFFS_UNDEFINED_LEN ? 0 : objhdr.size;
|
||||
buf->st_blksize = fs->geo.blocksize;
|
||||
buf->st_blocks = fs->phys_size / fs->geo.blocksize;
|
||||
buf->st_blocks = fs->media_size / fs->geo.blocksize;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user