Forráskód Böngészése

spiffs: handle CONFIG_VFS_SUPPORT_DIR

Ivan Grokhotkov 5 éve
szülő
commit
dc77ccb24e
1 módosított fájl, 41 hozzáadás és 33 törlés
  1. 41 33
      components/spiffs/esp_spiffs.c

+ 41 - 33
components/spiffs/esp_spiffs.c

@@ -61,6 +61,7 @@ static ssize_t vfs_spiffs_read(void* ctx, int fd, void * dst, size_t size);
 static int vfs_spiffs_close(void* ctx, int fd);
 static off_t vfs_spiffs_lseek(void* ctx, int fd, off_t offset, int mode);
 static int vfs_spiffs_fstat(void* ctx, int fd, struct stat * st);
+#ifdef CONFIG_VFS_SUPPORT_DIR
 static int vfs_spiffs_stat(void* ctx, const char * path, struct stat * st);
 static int vfs_spiffs_unlink(void* ctx, const char *path);
 static int vfs_spiffs_link(void* ctx, const char* n1, const char* n2);
@@ -74,11 +75,12 @@ static long vfs_spiffs_telldir(void* ctx, DIR* pdir);
 static void vfs_spiffs_seekdir(void* ctx, DIR* pdir, long offset);
 static int vfs_spiffs_mkdir(void* ctx, const char* name, mode_t mode);
 static int vfs_spiffs_rmdir(void* ctx, const char* name);
-static void vfs_spiffs_update_mtime(spiffs *fs, spiffs_file f);
-static time_t vfs_spiffs_get_mtime(const spiffs_stat* s);
 #ifdef CONFIG_SPIFFS_USE_MTIME
 static int vfs_spiffs_utime(void *ctx, const char *path, const struct utimbuf *times);
-#endif
+#endif // CONFIG_SPIFFS_USE_MTIME
+#endif // CONFIG_VFS_SUPPORT_DIR
+static void vfs_spiffs_update_mtime(spiffs *fs, spiffs_file f);
+static time_t vfs_spiffs_get_mtime(const spiffs_stat* s);
 
 static esp_spiffs_t * _efs[CONFIG_SPIFFS_MAX_PARTITIONS];
 
@@ -344,6 +346,7 @@ esp_err_t esp_vfs_spiffs_register(const esp_vfs_spiffs_conf_t * conf)
         .open_p = &vfs_spiffs_open,
         .close_p = &vfs_spiffs_close,
         .fstat_p = &vfs_spiffs_fstat,
+#ifdef CONFIG_VFS_SUPPORT_DIR
         .stat_p = &vfs_spiffs_stat,
         .link_p = &vfs_spiffs_link,
         .unlink_p = &vfs_spiffs_unlink,
@@ -361,6 +364,7 @@ esp_err_t esp_vfs_spiffs_register(const esp_vfs_spiffs_conf_t * conf)
 #else
         .utime_p = NULL,
 #endif // CONFIG_SPIFFS_USE_MTIME
+#endif // CONFIG_VFS_SUPPORT_DIR
     };
 
     esp_err_t err = esp_spiffs_init(conf);
@@ -540,6 +544,8 @@ static int vfs_spiffs_fstat(void* ctx, int fd, struct stat * st)
     return res;
 }
 
+#ifdef CONFIG_VFS_SUPPORT_DIR
+
 static int vfs_spiffs_stat(void* ctx, const char * path, struct stat * st)
 {
     assert(path);
@@ -730,36 +736,6 @@ static int vfs_spiffs_link(void* ctx, const char* n1, const char* n2)
     return -1;
 }
 
-static void vfs_spiffs_update_mtime(spiffs *fs, spiffs_file fd)
-{
-#ifdef CONFIG_SPIFFS_USE_MTIME
-    spiffs_time_t t = (spiffs_time_t)time(NULL);
-    spiffs_stat s;
-    int ret = SPIFFS_OK;
-    if (CONFIG_SPIFFS_META_LENGTH > sizeof(t)) {
-        ret = SPIFFS_fstat(fs, fd, &s);
-    }
-    if (ret == SPIFFS_OK) {
-        memcpy(s.meta, &t, sizeof(t));
-        ret = SPIFFS_fupdate_meta(fs, fd, s.meta);
-    }
-    if (ret != SPIFFS_OK) {
-        ESP_LOGW(TAG, "Failed to update mtime (%d)", ret);
-    }
-#endif //CONFIG_SPIFFS_USE_MTIME
-}
-
-static time_t vfs_spiffs_get_mtime(const spiffs_stat* s)
-{
-#ifdef CONFIG_SPIFFS_USE_MTIME
-    spiffs_time_t t = 0;
-    memcpy(&t, s->meta, sizeof(t));
-#else
-    time_t t = 0;
-#endif
-    return (time_t)t;
-}
-
 #ifdef CONFIG_SPIFFS_USE_MTIME
 static int vfs_spiffs_update_mtime_value(spiffs *fs, const char *path, spiffs_time_t t)
 {
@@ -805,3 +781,35 @@ static int vfs_spiffs_utime(void *ctx, const char *path, const struct utimbuf *t
     return 0;
 }
 #endif //CONFIG_SPIFFS_USE_MTIME
+
+#endif // CONFIG_VFS_SUPPORT_DIR
+
+static void vfs_spiffs_update_mtime(spiffs *fs, spiffs_file fd)
+{
+#ifdef CONFIG_SPIFFS_USE_MTIME
+    spiffs_time_t t = (spiffs_time_t)time(NULL);
+    spiffs_stat s;
+    int ret = SPIFFS_OK;
+    if (CONFIG_SPIFFS_META_LENGTH > sizeof(t)) {
+        ret = SPIFFS_fstat(fs, fd, &s);
+    }
+    if (ret == SPIFFS_OK) {
+        memcpy(s.meta, &t, sizeof(t));
+        ret = SPIFFS_fupdate_meta(fs, fd, s.meta);
+    }
+    if (ret != SPIFFS_OK) {
+        ESP_LOGW(TAG, "Failed to update mtime (%d)", ret);
+    }
+#endif //CONFIG_SPIFFS_USE_MTIME
+}
+
+static time_t vfs_spiffs_get_mtime(const spiffs_stat* s)
+{
+#ifdef CONFIG_SPIFFS_USE_MTIME
+    spiffs_time_t t = 0;
+    memcpy(&t, s->meta, sizeof(t));
+#else
+    time_t t = 0;
+#endif
+    return (time_t)t;
+}