fs/spiffs: Still uses some internal error codes that should be replaced with errors from errno.h. For now, I just added a mapping function before any value is returned to the caller: And of these detailed internal errors are simply mapped to -EFTYPE. Most are related to improper internal data structures so -ETYPE is possibly appropriate. Aslo SPIFFs is no longer is EXPERIMENTAL. Many things work but I the code is very immature and many things will not work.

This commit is contained in:
Gregory Nutt
2018-09-27 11:33:09 -06:00
parent 554745946d
commit 65ef3acf70
4 changed files with 54 additions and 35 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ config FS_SPIFFS
default n default n
select FS_READABLE select FS_READABLE
select FS_WRITABLE select FS_WRITABLE
depends on !DISABLE_MOUNTPOINT && EXPERIMENTAL depends on !DISABLE_MOUNTPOINT
---help--- ---help---
Build the SPIFFS file system. This is a port of version 0.3.7 of Build the SPIFFS file system. This is a port of version 0.3.7 of
the SPIFFS file system by Peter Andersson. It was originally the SPIFFS file system by Peter Andersson. It was originally
-14
View File
@@ -64,20 +64,6 @@ extern "C"
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define SPIFFS_ERR_DELETED -10004
#define SPIFFS_ERR_NOT_FINALIZED -10005
#define SPIFFS_ERR_NOT_INDEX -10006
#define SPIFFS_ERR_IS_INDEX -10011
#define SPIFFS_ERR_IS_FREE -10012
#define SPIFFS_ERR_INDEX_SPAN_MISMATCH -10013
#define SPIFFS_ERR_DATA_SPAN_MISMATCH -10014
#define SPIFFS_ERR_INDEX_REF_FREE -10015
#define SPIFFS_ERR_INDEX_REF_LU -10016
#define SPIFFS_ERR_INDEX_REF_INVALID -10017
#define SPIFFS_ERR_INDEX_FREE -10018
#define SPIFFS_ERR_INDEX_LU -10019
#define SPIFFS_ERR_INDEX_INVALID -10020
/* Flags on open file/directory options */ /* Flags on open file/directory options */
#define SFO_FLAG_UNLINKED (1 << 0) #define SFO_FLAG_UNLINKED (1 << 0)
+28 -6
View File
@@ -160,19 +160,41 @@
* obj.objid:0123 span.ndx:0005 flags:DATA * obj.objid:0123 span.ndx:0005 flags:DATA
*/ */
/* Internal error numbers.
*
* REVISIT: These should all be converted to standard errors as defined in
* errno.h. -EFTYPE might be a good choice for most. Only three are
* actually referenced from within SPIFFS a require special naming.
*/
#define SPIFFS_ERR_INTERNAL (-256) #define SPIFFS_ERR_INTERNAL (-256)
/* visitor result, continue searching */ #define SPIFFS_ERR_DELETED (SPIFFS_ERR_INTERNAL - 1)
#define SPIFFS_ERR_NOT_FINALIZED (SPIFFS_ERR_INTERNAL - 2)
#define SPIFFS_ERR_NOT_INDEX (SPIFFS_ERR_INTERNAL - 3)
#define SPIFFS_ERR_IS_INDEX (SPIFFS_ERR_INTERNAL - 4)
#define SPIFFS_ERR_IS_FREE (SPIFFS_ERR_INTERNAL - 5)
#define SPIFFS_ERR_INDEX_SPAN_MISMATCH (SPIFFS_ERR_INTERNAL - 6)
#define SPIFFS_ERR_DATA_SPAN_MISMATCH (SPIFFS_ERR_INTERNAL - 7)
#define SPIFFS_ERR_INDEX_REF_FREE (SPIFFS_ERR_INTERNAL - 8)
#define SPIFFS_ERR_INDEX_REF_LU (SPIFFS_ERR_INTERNAL - 9)
#define SPIFFS_ERR_INDEX_REF_INVALID (SPIFFS_ERR_INTERNAL - 10)
#define SPIFFS_ERR_INDEX_FREE (SPIFFS_ERR_INTERNAL - 11)
#define SPIFFS_ERR_INDEX_LU (SPIFFS_ERR_INTERNAL - 12)
#define SPIFFS_ERR_INDEX_INVALID (SPIFFS_ERR_INTERNAL - 13)
#define SPIFFS_VIS_COUNTINUE (SPIFFS_ERR_INTERNAL - 20) /* These are not errors, but live in the same number space */
/* Visitor result, continue searching */
/* visitor result, continue searching after reloading lu buffer */ #define SPIFFS_VIS_COUNTINUE (SPIFFS_ERR_INTERNAL - 14)
#define SPIFFS_VIS_COUNTINUE_RELOAD (SPIFFS_ERR_INTERNAL - 21) /* Visitor result, continue searching after reloading lu buffer */
/* visitor result, stop searching */ #define SPIFFS_VIS_COUNTINUE_RELOAD (SPIFFS_ERR_INTERNAL - 15)
#define SPIFFS_VIS_END (SPIFFS_ERR_INTERNAL - 22) /* Visitor result, stop searching */
#define SPIFFS_VIS_END (SPIFFS_ERR_INTERNAL - 16)
/* Events */ /* Events */
+25 -14
View File
@@ -161,6 +161,17 @@ const struct mountpt_operations spiffs_operations =
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: spiffs_map_errno
****************************************************************************/
static inline int spiffs_map_errno(int errcode)
{
/* Don't return any or our internal error codes to the application */
return errcode < SPIFFS_ERR_INTERNAL ? -EFTYPE : errcode;
}
/**************************************************************************** /****************************************************************************
* Name: spiffs_lock_reentrant * Name: spiffs_lock_reentrant
****************************************************************************/ ****************************************************************************/
@@ -281,7 +292,7 @@ static int spiffs_consistency_check(FAR struct spiffs_s *fs)
} }
} }
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************
@@ -311,7 +322,7 @@ static int spiffs_readdir_callback(FAR struct spiffs_s *fs,
if (ret < 0) if (ret < 0)
{ {
ferr("ERROR: spiffs_cache_read failed: %d\n", ret); ferr("ERROR: spiffs_cache_read failed: %d\n", ret);
return ret; return spiffs_map_errno(ret);
} }
if ((objid & SPIFFS_OBJID_NDXFLAG) && if ((objid & SPIFFS_OBJID_NDXFLAG) &&
@@ -487,7 +498,7 @@ static int spiffs_open(FAR struct file *filep, FAR const char *relpath,
errout_with_fileobject: errout_with_fileobject:
kmm_free(fobj); kmm_free(fobj);
spiffs_unlock_volume(fs); spiffs_unlock_volume(fs);
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************
@@ -970,7 +981,7 @@ static int spiffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
ret = spiffs_erase_block(fs, blkndx); ret = spiffs_erase_block(fs, blkndx);
if (ret < 0) if (ret < 0)
{ {
return ret; return spiffs_map_errno(ret);
} }
blkndx++; blkndx++;
@@ -998,7 +1009,7 @@ static int spiffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
} }
spiffs_unlock_volume(fs); spiffs_unlock_volume(fs);
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************
@@ -1040,7 +1051,7 @@ static int spiffs_sync(FAR struct file *filep)
ret = spiffs_fflush_cache(fs, fobj); ret = spiffs_fflush_cache(fs, fobj);
spiffs_unlock_volume(fs); spiffs_unlock_volume(fs);
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************
@@ -1127,7 +1138,7 @@ static int spiffs_fstat(FAR const struct file *filep, FAR struct stat *buf)
} }
spiffs_unlock_volume(fs); spiffs_unlock_volume(fs);
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************
@@ -1184,7 +1195,7 @@ static int spiffs_truncate(FAR struct file *filep, off_t length)
} }
spiffs_unlock_volume(fs); spiffs_unlock_volume(fs);
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************
@@ -1259,7 +1270,7 @@ static int spiffs_readdir(FAR struct inode *mountpt,
/* Release the lock on the file system */ /* Release the lock on the file system */
spiffs_unlock_volume(fs); spiffs_unlock_volume(fs);
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************
@@ -1427,7 +1438,7 @@ errout_with_cache:
errout_with_volume: errout_with_volume:
kmm_free(fs); kmm_free(fs);
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************
@@ -1487,7 +1498,7 @@ static int spiffs_unbind(FAR void *handle, FAR struct inode **mtdinode,
errout_with_lock: errout_with_lock:
spiffs_unlock_volume(fs); spiffs_unlock_volume(fs);
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************
@@ -1655,7 +1666,7 @@ static int spiffs_unlink(FAR struct inode *mountpt, FAR const char *relpath)
errout_with_lock: errout_with_lock:
spiffs_unlock_volume(fs); spiffs_unlock_volume(fs);
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************
@@ -1775,7 +1786,7 @@ errout_with_fobj:
errout_with_lock: errout_with_lock:
spiffs_unlock_volume(fs); spiffs_unlock_volume(fs);
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************
@@ -1824,7 +1835,7 @@ static int spiffs_stat(FAR struct inode *mountpt, FAR const char *relpath,
errout_with_lock: errout_with_lock:
spiffs_unlock_volume(fs); spiffs_unlock_volume(fs);
return ret; return spiffs_map_errno(ret);
} }
/**************************************************************************** /****************************************************************************