Filesystem library designed for flash devices

Dependents:   flash-fs-example Dragonfly_Filesystem_Example STM32F407VET6_SPIFlash Dragonfly_Filesystem_Example_mbed_5

Files at this revision

API Documentation at this revision

Comitter:
Leon Lindenfelser
Date:
Fri Jun 26 14:21:17 2020 -0500
Parent:
2:de478b250060
Commit message:
Update to latest from Multitech git repo

1. Change "errno" to "err_code" to address ARM compiler errors
2. Feature: add move file support

Changed in this revision

spiffs.h Show annotated file Show diff for this revision Revisions of this file
spiffs_cache.c Show annotated file Show diff for this revision Revisions of this file
spiffs_config.h Show annotated file Show diff for this revision Revisions of this file
spiffs_hydrogen.c Show annotated file Show diff for this revision Revisions of this file
spiffs_nucleus.h Show annotated file Show diff for this revision Revisions of this file
diff -r de478b250060 -r 7a3c79b0d570 spiffs.h
--- a/spiffs.h	Mon Dec 29 14:10:45 2014 -0600
+++ b/spiffs.h	Fri Jun 26 14:21:17 2020 -0500
@@ -185,7 +185,7 @@
   u32_t fd_count;
 
   // last error
-  s32_t errno;
+  s32_t err_code;
 
   // current number of free blocks
   u32_t free_blocks;
@@ -322,6 +322,14 @@
 s32_t SPIFFS_remove(spiffs *fs, const char *path);
 
 /**
+ * Removes a file by path
+ * @param fs            the file system struct
+ * @param path          the path of the file to move
+ * @param new_path          the path of the file to move
+ */
+s32_t SPIFFS_move(spiffs *fs, const char *path, const char *new_path);
+
+/**
  * Removes a file by filehandle
  * @param fs            the file system struct
  * @param fh            the filehandle of the file to remove
diff -r de478b250060 -r 7a3c79b0d570 spiffs_cache.c
--- a/spiffs_cache.c	Mon Dec 29 14:10:45 2014 -0600
+++ b/spiffs_cache.c	Fri Jun 26 14:21:17 2020 -0500
@@ -298,4 +298,4 @@
   }
 }
 
-#endif // SPIFFS_CACHE
\ No newline at end of file
+#endif // SPIFFS_CACHE
diff -r de478b250060 -r 7a3c79b0d570 spiffs_config.h
--- a/spiffs_config.h	Mon Dec 29 14:10:45 2014 -0600
+++ b/spiffs_config.h	Fri Jun 26 14:21:17 2020 -0500
@@ -205,4 +205,4 @@
 // i.e. (spiffs_file_system_size / log_page_size) - 1
 typedef u16_t spiffs_span_ix;
 
-#endif /* SPIFFS_CONFIG_H_ */
\ No newline at end of file
+#endif /* SPIFFS_CONFIG_H_ */
diff -r de478b250060 -r 7a3c79b0d570 spiffs_hydrogen.c
--- a/spiffs_hydrogen.c	Mon Dec 29 14:10:45 2014 -0600
+++ b/spiffs_hydrogen.c	Fri Jun 26 14:21:17 2020 -0500
@@ -101,7 +101,7 @@
 }
 
 s32_t SPIFFS_errno(spiffs *fs) {
-  return fs->errno;
+  return fs->err_code;
 }
 
 s32_t SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode mode) {
@@ -461,6 +461,45 @@
   return 0;
 }
 
+
+s32_t SPIFFS_move(spiffs *fs, const char *path, const char *new_path) {
+  SPIFFS_API_CHECK_MOUNT(fs);
+  SPIFFS_LOCK(fs);
+
+  spiffs_fd *fd;
+  spiffs_page_ix pix;
+  spiffs_obj_id obj_id;
+  s32_t res;
+
+  res = spiffs_fd_find_new(fs, &fd);
+  SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
+
+  res = spiffs_object_find_object_index_header_by_name(fs, (u8_t*)path, &pix);
+  if (res != SPIFFS_OK) {
+    spiffs_fd_return(fs, fd->file_nbr);
+  }
+  SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
+
+  u32_t obj_id_addr = SPIFFS_BLOCK_TO_PADDR(fs, SPIFFS_BLOCK_FOR_PAGE(fs , pix)) +
+      SPIFFS_OBJ_LOOKUP_ENTRY_FOR_PAGE(fs, pix) * sizeof(spiffs_obj_id);
+  res =_spiffs_rd(fs,  SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ, fd,
+      obj_id_addr, sizeof(spiffs_obj_id), (u8_t *)&obj_id);
+  if (res != SPIFFS_OK) {
+      spiffs_fd_return(fs, fd->file_nbr);
+    }
+  SPIFFS_API_CHECK_RES(fs, res);
+
+  res = spiffs_object_update_index_hdr(fs, fd, obj_id, pix, NULL, new_path, 0, NULL);
+  if (res != SPIFFS_OK) {
+    spiffs_fd_return(fs, fd->file_nbr);
+  }
+  SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
+
+  SPIFFS_UNLOCK(fs);
+  return 0;
+}
+
+
 static s32_t spiffs_stat_pix(spiffs *fs, spiffs_page_ix pix, spiffs_file fh, spiffs_stat *s) {
   spiffs_page_object_ix_header objix_hdr;
   spiffs_obj_id obj_id;
@@ -542,7 +581,7 @@
           spiffs_get_cache_page(fs, spiffs_get_cache(fs), fd->cache_page->ix),
           fd->cache_page->offset, fd->cache_page->size);
       if (res < SPIFFS_OK) {
-        fs->errno = res;
+        fs->err_code = res;
       }
       spiffs_cache_fd_release(fs, fd->cache_page);
     }
@@ -567,7 +606,7 @@
 
 void SPIFFS_close(spiffs *fs, spiffs_file fh) {
   if (!SPIFFS_CHECK_MOUNT(fs)) {
-    fs->errno = SPIFFS_ERR_NOT_MOUNTED;
+    fs->err_code = SPIFFS_ERR_NOT_MOUNTED;
     return;
   }
   SPIFFS_LOCK(fs);
@@ -582,7 +621,7 @@
 
 spiffs_DIR *SPIFFS_opendir(spiffs *fs, const char *name, spiffs_DIR *d) {
   if (!SPIFFS_CHECK_MOUNT(fs)) {
-    fs->errno = SPIFFS_ERR_NOT_MOUNTED;
+    fs->err_code = SPIFFS_ERR_NOT_MOUNTED;
     return 0;
   }
   d->fs = fs;
@@ -626,7 +665,7 @@
 
 struct spiffs_dirent *SPIFFS_readdir(spiffs_DIR *d, struct spiffs_dirent *e) {
   if (!SPIFFS_CHECK_MOUNT(d->fs)) {
-    d->fs->errno = SPIFFS_ERR_NOT_MOUNTED;
+    d->fs->err_code = SPIFFS_ERR_NOT_MOUNTED;
     return 0;
   }
   SPIFFS_LOCK(fs);
@@ -651,7 +690,7 @@
     d->entry = entry + 1;
     ret = e;
   } else {
-    d->fs->errno = res;
+    d->fs->err_code = res;
   }
   SPIFFS_UNLOCK(fs);
   return ret;
@@ -740,7 +779,7 @@
   } // per block
 
   spiffs_printf("era_cnt_max: %i\n", fs->max_erase_count);
-  spiffs_printf("last_errno:  %i\n", fs->errno);
+  spiffs_printf("last_errno:  %i\n", fs->err_code);
   spiffs_printf("blocks:      %i\n", fs->block_count);
   spiffs_printf("free_blocks: %i\n", fs->free_blocks);
   spiffs_printf("page_alloc:  %i\n", fs->stats_p_allocated);
diff -r de478b250060 -r 7a3c79b0d570 spiffs_nucleus.h
--- a/spiffs_nucleus.h	Mon Dec 29 14:10:45 2014 -0600
+++ b/spiffs_nucleus.h	Fri Jun 26 14:21:17 2020 -0500
@@ -247,19 +247,19 @@
 
 #define SPIFFS_API_CHECK_MOUNT(fs) \
   if (!SPIFFS_CHECK_MOUNT((fs))) { \
-    (fs)->errno = SPIFFS_ERR_NOT_MOUNTED; \
+    (fs)->err_code = SPIFFS_ERR_NOT_MOUNTED; \
     return -1; \
   }
 
 #define SPIFFS_API_CHECK_RES(fs, res) \
   if ((res) < SPIFFS_OK) { \
-    (fs)->errno = (res); \
+    (fs)->err_code = (res); \
     return -1; \
   }
 
 #define SPIFFS_API_CHECK_RES_UNLOCK(fs, res) \
   if ((res) < SPIFFS_OK) { \
-    (fs)->errno = (res); \
+    (fs)->err_code = (res); \
     SPIFFS_UNLOCK(fs); \
     return -1; \
   }