diff --git a/mongoose.c b/mongoose.c
index 974a9d7ceb3ce892f65d1197a6d2a577092d1b08..5b80e7244a8cc107f98d4fa7d621786616e87f08 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -12675,12 +12675,22 @@ void fs_slfs_set_new_file_size(const char *name, size_t size);
 #if CS_PLATFORM == CS_P_CC3200
 #include <inc/hw_types.h>
 #endif
-#include <simplelink/include/simplelink.h>
-#include <simplelink/include/fs.h>
 
 /* Amalgamated: #include "common/cs_dbg.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 */
 int set_errno(int e);
 const char *drop_dir(const char *fname, bool *is_slfs);
@@ -12712,18 +12722,18 @@ static int sl_fs_to_errno(_i32 r) {
   switch (r) {
     case SL_FS_OK:
       return 0;
-    case SL_FS_FILE_NAME_EXIST:
+    case SL_ERROR_FS_FILE_NAME_EXIST:
       return EEXIST;
-    case SL_FS_WRONG_FILE_NAME:
+    case SL_ERROR_FS_WRONG_FILE_NAME:
       return EINVAL;
-    case SL_FS_ERR_NO_AVAILABLE_NV_INDEX:
-    case SL_FS_ERR_NO_AVAILABLE_BLOCKS:
+    case SL_ERROR_FS_NO_AVAILABLE_NV_INDEX:
+    case SL_ERROR_FS_NOT_ENOUGH_STORAGE_SPACE:
       return ENOSPC;
-    case SL_FS_ERR_FAILED_TO_ALLOCATE_MEM:
+    case SL_ERROR_FS_FAILED_TO_ALLOCATE_MEM:
       return ENOMEM;
-    case SL_FS_ERR_FILE_NOT_EXISTS:
+    case SL_ERROR_FS_FILE_NOT_EXISTS:
       return ENOENT;
-    case SL_FS_ERR_NOT_SUPPORTED:
+    case SL_ERROR_FS_NOT_SUPPORTED:
       return ENOTSUP;
   }
   return ENXIO;
@@ -12751,9 +12761,9 @@ int fs_slfs_open(const char *pathname, int flags, mode_t mode) {
     SlFsFileInfo_t sl_fi;
     _i32 r = sl_FsGetInfo((const _u8 *) pathname, 0, &sl_fi);
     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 {
     if (!(flags & O_TRUNC) || (flags & O_APPEND)) {
       // 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);
     } else {
-      am = FS_MODE_OPEN_WRITE;
+      am = SL_FS_WRITE;
     }
   }
-  _i32 r = sl_FsOpen((_u8 *) pathname, am, NULL, &fi->fh);
-  LOG(LL_DEBUG, ("sl_FsOpen(%s, 0x%x) sz %u = %d, %d", pathname, (int) am,
-                 (unsigned int) new_size, (int) r, (int) fi->fh));
-  if (r == SL_FS_OK) {
+  fi->fh = slfs_open((_u8 *) pathname, am);
+  LOG(LL_DEBUG, ("sl_FsOpen(%s, 0x%x) sz %u = %d", pathname, (int) am,
+                 (unsigned int) new_size, (int) fi->fh));
+  int r;
+  if (fi->fh >= 0) {
     fi->pos = 0;
     r = fd;
   } else {
-    fi->fh = -1;
-    r = set_errno(sl_fs_to_errno(r));
+    r = set_errno(sl_fs_to_errno(fi->fh));
   }
   return r;
 }
@@ -12838,7 +12848,7 @@ int fs_slfs_stat(const char *pathname, struct stat *s) {
   if (r == SL_FS_OK) {
     s->st_mode = S_IFREG | 0666;
     s->st_nlink = 1;
-    s->st_size = sl_fi.FileLen;
+    s->st_size = SL_FI_FILE_SIZE(sl_fi);
     return 0;
   }
   return set_errno(sl_fs_to_errno(r));
diff --git a/mongoose.h b/mongoose.h
index 8757a6d7ebc5707c71e7d9951cd63d86347e71cf..d62fc888248ed1923c8b8ba4d06aca223f124769 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -1210,23 +1210,50 @@ int sl_set_ssl_opts(struct mg_connection *nc);
 
 /* Compatibility with older versions of SimpleLink */
 #if SL_MAJOR_VERSION_NUM < 2
+
 #define SL_ERROR_BSD_EAGAIN SL_EAGAIN
 #define SL_ERROR_BSD_EALREADY SL_EALREADY
 #define SL_ERROR_BSD_ENOPROTOOPT SL_ENOPROTOOPT
 #define SL_ERROR_BSD_ESECDATEERROR SL_ESECDATEERROR
 #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_SET SL_FD_SET
 #define SL_SOCKET_FD_ISSET SL_FD_ISSET
 #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 sl_DeviceGet sl_DevGet
 #define SL_DEVICE_GENERAL SL_DEVICE_GENERAL_CONFIGURATION
 #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
-#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 */