CC3220 FS support

For now, we only support SPIFFS-in-a-box, same as CC3200.
On CC3200SF it should be possible to have SPIFFS on built-in flash, but that is left for later.

PUBLISHED_FROM=dee337c8cd8ed288c22abe9960eef81e6e90cc4a
This commit is contained in:
Deomid Ryabkov 2017-08-30 17:44:36 +01:00 committed by Cesanta Bot
parent d5a9000d46
commit c7bea65ae7
2 changed files with 58 additions and 21 deletions

View File

@ -12675,12 +12675,22 @@ void fs_slfs_set_new_file_size(const char *name, size_t size);
#if CS_PLATFORM == CS_P_CC3200 #if CS_PLATFORM == CS_P_CC3200
#include <inc/hw_types.h> #include <inc/hw_types.h>
#endif #endif
#include <simplelink/include/simplelink.h>
#include <simplelink/include/fs.h>
/* Amalgamated: #include "common/cs_dbg.h" */ /* Amalgamated: #include "common/cs_dbg.h" */
/* Amalgamated: #include "common/mg_mem.h" */ /* Amalgamated: #include "common/mg_mem.h" */
#if SL_MAJOR_VERSION_NUM < 2
int slfs_open(const unsigned char *fname, uint32_t flags) {
_i32 fh;
_i32 r = sl_FsOpen(fname, flags, NULL /* token */, &fh);
return (r < 0 ? r : fh);
}
#else /* SL_MAJOR_VERSION_NUM >= 2 */
int slfs_open(const unsigned char *fname, uint32_t flags) {
return sl_FsOpen(fname, flags, NULL /* token */);
}
#endif
/* From sl_fs.c */ /* From sl_fs.c */
int set_errno(int e); int set_errno(int e);
const char *drop_dir(const char *fname, bool *is_slfs); const char *drop_dir(const char *fname, bool *is_slfs);
@ -12712,18 +12722,18 @@ static int sl_fs_to_errno(_i32 r) {
switch (r) { switch (r) {
case SL_FS_OK: case SL_FS_OK:
return 0; return 0;
case SL_FS_FILE_NAME_EXIST: case SL_ERROR_FS_FILE_NAME_EXIST:
return EEXIST; return EEXIST;
case SL_FS_WRONG_FILE_NAME: case SL_ERROR_FS_WRONG_FILE_NAME:
return EINVAL; return EINVAL;
case SL_FS_ERR_NO_AVAILABLE_NV_INDEX: case SL_ERROR_FS_NO_AVAILABLE_NV_INDEX:
case SL_FS_ERR_NO_AVAILABLE_BLOCKS: case SL_ERROR_FS_NOT_ENOUGH_STORAGE_SPACE:
return ENOSPC; return ENOSPC;
case SL_FS_ERR_FAILED_TO_ALLOCATE_MEM: case SL_ERROR_FS_FAILED_TO_ALLOCATE_MEM:
return ENOMEM; return ENOMEM;
case SL_FS_ERR_FILE_NOT_EXISTS: case SL_ERROR_FS_FILE_NOT_EXISTS:
return ENOENT; return ENOENT;
case SL_FS_ERR_NOT_SUPPORTED: case SL_ERROR_FS_NOT_SUPPORTED:
return ENOTSUP; return ENOTSUP;
} }
return ENXIO; return ENXIO;
@ -12751,9 +12761,9 @@ int fs_slfs_open(const char *pathname, int flags, mode_t mode) {
SlFsFileInfo_t sl_fi; SlFsFileInfo_t sl_fi;
_i32 r = sl_FsGetInfo((const _u8 *) pathname, 0, &sl_fi); _i32 r = sl_FsGetInfo((const _u8 *) pathname, 0, &sl_fi);
if (r == SL_FS_OK) { if (r == SL_FS_OK) {
fi->size = sl_fi.FileLen; fi->size = SL_FI_FILE_SIZE(sl_fi);
} }
am = FS_MODE_OPEN_READ; am = SL_FS_READ;
} else { } else {
if (!(flags & O_TRUNC) || (flags & O_APPEND)) { if (!(flags & O_TRUNC) || (flags & O_APPEND)) {
// FailFS files cannot be opened for append and will be truncated // FailFS files cannot be opened for append and will be truncated
@ -12773,18 +12783,18 @@ int fs_slfs_open(const char *pathname, int flags, mode_t mode) {
} }
am = FS_MODE_OPEN_CREATE(new_size, 0); am = FS_MODE_OPEN_CREATE(new_size, 0);
} else { } else {
am = FS_MODE_OPEN_WRITE; am = SL_FS_WRITE;
} }
} }
_i32 r = sl_FsOpen((_u8 *) pathname, am, NULL, &fi->fh); fi->fh = slfs_open((_u8 *) pathname, am);
LOG(LL_DEBUG, ("sl_FsOpen(%s, 0x%x) sz %u = %d, %d", pathname, (int) am, LOG(LL_DEBUG, ("sl_FsOpen(%s, 0x%x) sz %u = %d", pathname, (int) am,
(unsigned int) new_size, (int) r, (int) fi->fh)); (unsigned int) new_size, (int) fi->fh));
if (r == SL_FS_OK) { int r;
if (fi->fh >= 0) {
fi->pos = 0; fi->pos = 0;
r = fd; r = fd;
} else { } else {
fi->fh = -1; r = set_errno(sl_fs_to_errno(fi->fh));
r = set_errno(sl_fs_to_errno(r));
} }
return r; return r;
} }
@ -12838,7 +12848,7 @@ int fs_slfs_stat(const char *pathname, struct stat *s) {
if (r == SL_FS_OK) { if (r == SL_FS_OK) {
s->st_mode = S_IFREG | 0666; s->st_mode = S_IFREG | 0666;
s->st_nlink = 1; s->st_nlink = 1;
s->st_size = sl_fi.FileLen; s->st_size = SL_FI_FILE_SIZE(sl_fi);
return 0; return 0;
} }
return set_errno(sl_fs_to_errno(r)); return set_errno(sl_fs_to_errno(r));

View File

@ -1210,23 +1210,50 @@ int sl_set_ssl_opts(struct mg_connection *nc);
/* Compatibility with older versions of SimpleLink */ /* Compatibility with older versions of SimpleLink */
#if SL_MAJOR_VERSION_NUM < 2 #if SL_MAJOR_VERSION_NUM < 2
#define SL_ERROR_BSD_EAGAIN SL_EAGAIN #define SL_ERROR_BSD_EAGAIN SL_EAGAIN
#define SL_ERROR_BSD_EALREADY SL_EALREADY #define SL_ERROR_BSD_EALREADY SL_EALREADY
#define SL_ERROR_BSD_ENOPROTOOPT SL_ENOPROTOOPT #define SL_ERROR_BSD_ENOPROTOOPT SL_ENOPROTOOPT
#define SL_ERROR_BSD_ESECDATEERROR SL_ESECDATEERROR #define SL_ERROR_BSD_ESECDATEERROR SL_ESECDATEERROR
#define SL_ERROR_BSD_ESECSNOVERIFY SL_ESECSNOVERIFY #define SL_ERROR_BSD_ESECSNOVERIFY SL_ESECSNOVERIFY
#define SL_ERROR_FS_FAILED_TO_ALLOCATE_MEM SL_FS_ERR_FAILED_TO_ALLOCATE_MEM
#define SL_ERROR_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY \
SL_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY
#define SL_ERROR_FS_FILE_NAME_EXIST SL_FS_FILE_NAME_EXIST
#define SL_ERROR_FS_FILE_NOT_EXISTS SL_FS_ERR_FILE_NOT_EXISTS
#define SL_ERROR_FS_NO_AVAILABLE_NV_INDEX SL_FS_ERR_NO_AVAILABLE_NV_INDEX
#define SL_ERROR_FS_NOT_ENOUGH_STORAGE_SPACE SL_FS_ERR_NO_AVAILABLE_BLOCKS
#define SL_ERROR_FS_NOT_SUPPORTED SL_FS_ERR_NOT_SUPPORTED
#define SL_ERROR_FS_WRONG_FILE_NAME SL_FS_WRONG_FILE_NAME
#define SL_ERROR_FS_INVALID_HANDLE SL_FS_ERR_INVALID_HANDLE
#define SL_SOCKET_FD_ZERO SL_FD_ZERO #define SL_SOCKET_FD_ZERO SL_FD_ZERO
#define SL_SOCKET_FD_SET SL_FD_SET #define SL_SOCKET_FD_SET SL_FD_SET
#define SL_SOCKET_FD_ISSET SL_FD_ISSET #define SL_SOCKET_FD_ISSET SL_FD_ISSET
#define SL_SO_SECURE_DOMAIN_NAME_VERIFICATION SO_SECURE_DOMAIN_NAME_VERIFICATION #define SL_SO_SECURE_DOMAIN_NAME_VERIFICATION SO_SECURE_DOMAIN_NAME_VERIFICATION
#define SL_FS_READ FS_MODE_OPEN_READ
#define SL_FS_WRITE FS_MODE_OPEN_WRITE
#define SL_FI_FILE_SIZE(fi) ((fi).FileLen)
#define SL_FI_FILE_MAX_SIZE(fi) ((fi).AllocatedLen)
#define SlDeviceVersion_t SlVersionFull #define SlDeviceVersion_t SlVersionFull
#define sl_DeviceGet sl_DevGet #define sl_DeviceGet sl_DevGet
#define SL_DEVICE_GENERAL SL_DEVICE_GENERAL_CONFIGURATION #define SL_DEVICE_GENERAL SL_DEVICE_GENERAL_CONFIGURATION
#define SL_DEV_GET_LEN_TYPE _u8 #define SL_DEV_GET_LEN_TYPE _u8
#else
#else /* SL_MAJOR_VERSION_NUM >= 2 */
#define FS_MODE_OPEN_CREATE(max_size, flag) \
(SL_FS_CREATE | SL_FS_CREATE_MAX_SIZE(max_size))
#define SL_FI_FILE_SIZE(fi) ((fi).Len)
#define SL_FI_FILE_MAX_SIZE(fi) ((fi).MaxSize)
#define SL_DEV_GET_LEN_TYPE _u16 #define SL_DEV_GET_LEN_TYPE _u16
#endif
#endif /* SL_MAJOR_VERSION_NUM < 2 */
int slfs_open(const unsigned char *fname, uint32_t flags);
#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK */ #endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK */