You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ut...@apache.org on 2018/12/27 11:21:15 UTC

[mynewt-nffs] branch master updated: Move platform #ifdefery to

This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nffs.git


The following commit(s) were added to refs/heads/master by this push:
     new 65e6998  Move platform #ifdefery to <nffs/os.h>
65e6998 is described below

commit 65e6998b299763e40eea7752864f4780e6ba4957
Author: Fabio Utzig <ut...@apache.org>
AuthorDate: Tue Dec 18 11:29:37 2018 -0200

    Move platform #ifdefery to <nffs/os.h>
    
    This adds new macros and includes in <nffs/os.h>, and updates source
    files to avoid having to use ifdefery to include features per OS.
    
    Signed-off-by: Fabio Utzig <ut...@apache.org>
---
 include/nffs/config.h |  2 +-
 include/nffs/nffs.h   | 21 ++++++---------------
 include/nffs/os.h     | 22 +++++++++++++++++++++-
 src/nffs_dir.c        | 14 ++------------
 src/nffs_file.c       | 10 +---------
 src/nffs_gc.c         |  4 +---
 src/nffs_hash.c       |  4 +---
 src/nffs_misc.c       |  3 ---
 8 files changed, 33 insertions(+), 47 deletions(-)

diff --git a/include/nffs/config.h b/include/nffs/config.h
index 9662b78..3320458 100644
--- a/include/nffs/config.h
+++ b/include/nffs/config.h
@@ -28,7 +28,7 @@ typedef struct k_mem_slab nffs_os_mempool_t;
 #define NFFS_CONFIG_MAX_AREAS           CONFIG_NFFS_FILESYSTEM_MAX_AREAS
 #define NFFS_CONFIG_MAX_BLOCK_SIZE      CONFIG_NFFS_FILESYSTEM_MAX_BLOCK_SIZE
 
-#else
+#elif MYNEWT
 
 /* Default to Mynewt */
 
diff --git a/include/nffs/nffs.h b/include/nffs/nffs.h
index ea50b74..877c0d5 100644
--- a/include/nffs/nffs.h
+++ b/include/nffs/nffs.h
@@ -24,11 +24,7 @@
 #include <inttypes.h>
 #include <nffs/config.h>
 #include <nffs/queue.h>
-
-#if __ZEPHYR__
-#include <zephyr/types.h>
-#include <stats.h>
-#endif
+#include <nffs/os.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -213,9 +209,7 @@ struct nffs_block {
 };
 
 struct nffs_file {
-#if !__ZEPHYR__
-    struct fs_ops *fops;
-#endif
+    OS_MULTIFS_CONTAINER;
     struct nffs_inode_entry *nf_inode_entry;
     uint32_t nf_offset;
     uint8_t nf_access_flags;
@@ -283,16 +277,12 @@ struct nffs_cache_inode {
 };
 
 struct nffs_dirent {
-#if !__ZEPHYR__
-    struct fs_ops *fops;
-#endif
+    OS_MULTIFS_CONTAINER;
     struct nffs_inode_entry *nde_inode_entry;
 };
 
 struct nffs_dir {
-#if !__ZEPHYR__
-    struct fs_ops *fops;
-#endif
+    OS_MULTIFS_CONTAINER;
     struct nffs_inode_entry *nd_parent_inode_entry;
     struct nffs_dirent nd_dirent;
 };
@@ -575,7 +565,7 @@ int nffs_write_to_file(struct nffs_file *file, const void *data, int len);
 #define MYNEWT_VAL(val) 0
 #define ASSERT_IF_TEST(cond)
 
-#else
+#elif MYNEWT
 
 /* Default to Mynewt */
 #include "log/log.h"
@@ -583,6 +573,7 @@ int nffs_write_to_file(struct nffs_file *file, const void *data, int len);
 
 #define NFFS_LOG(lvl, ...) \
     LOG_ ## lvl(&nffs_log, LOG_MODULE_NFFS, __VA_ARGS__)
+
 #endif
 
 #ifdef __cplusplus
diff --git a/include/nffs/os.h b/include/nffs/os.h
index d2c6585..2247c41 100644
--- a/include/nffs/os.h
+++ b/include/nffs/os.h
@@ -21,9 +21,29 @@
 #define H_OS_
 
 #include <stdint.h>
-#if __ZEPHYR__
+
+#if MYNEWT
+
+#include "fs/fs.h"
+#include "fs/fs_if.h"
+extern struct fs_ops nffs_ops;
+#define OS_MULTIFS_CONTAINER struct fs_ops *fops
+#define OS_MULTIFS_SETOPS(x) ((x) = &nffs_ops)
+
+#elif __ZEPHYR__
+
 #include <kernel.h>
+#include <zephyr/types.h>
+#include <stats.h>
+#define OS_MULTIFS_CONTAINER
+#define OS_MULTIFS_SETOPS(x)
+
+#else
+
+#error "Unsupported OS"
+
 #endif
+
 #include <nffs/config.h>
 
 #ifdef __cplusplus
diff --git a/src/nffs_dir.c b/src/nffs_dir.c
index f232bc1..130e5fd 100644
--- a/src/nffs_dir.c
+++ b/src/nffs_dir.c
@@ -22,12 +22,6 @@
 #include <nffs/nffs.h>
 #include <nffs/os.h>
 
-#if !__ZEPHYR__
-#include "fs/fs.h"
-#include "fs/fs_if.h"
-struct fs_ops nffs_ops;
-#endif
-
 static struct nffs_dir *
 nffs_dir_alloc(void)
 {
@@ -80,9 +74,7 @@ nffs_dir_open(const char *path, struct nffs_dir **out_dir)
     dir->nd_parent_inode_entry = parent_inode_entry;
     nffs_inode_inc_refcnt(dir->nd_parent_inode_entry);
     memset(&dir->nd_dirent, 0, sizeof dir->nd_dirent);
-#if !__ZEPHYR__
-    dir->fops = &nffs_ops;
-#endif
+    OS_MULTIFS_SETOPS(dir->fops);
 
     *out_dir = dir;
 
@@ -113,9 +105,7 @@ nffs_dir_read(struct nffs_dir *dir, struct nffs_dirent **out_dirent)
     }
 
     nffs_inode_inc_refcnt(child);
-#if !__ZEPHYR__
-    dir->nd_dirent.fops = &nffs_ops;
-#endif
+    OS_MULTIFS_SETOPS(dir->nd_dirent.fops);
     *out_dirent = &dir->nd_dirent;
 
     return 0;
diff --git a/src/nffs_file.c b/src/nffs_file.c
index b02db98..3a98991 100644
--- a/src/nffs_file.c
+++ b/src/nffs_file.c
@@ -22,12 +22,6 @@
 #include <nffs/nffs.h>
 #include <nffs/os.h>
 
-#if !__ZEPHYR__
-#include "fs/fs.h"
-#include "fs/fs_if.h"
-struct fs_ops nffs_ops;
-#endif
-
 static struct nffs_file *
 nffs_file_alloc(void)
 {
@@ -248,9 +242,7 @@ nffs_file_open(struct nffs_file **out_file, const char *path,
     }
     nffs_inode_inc_refcnt(file->nf_inode_entry);
     file->nf_access_flags = access_flags;
-#if !__ZEPHYR__
-    file->fops = &nffs_ops;
-#endif
+    OS_MULTIFS_SETOPS(file->fops);
 
     *out_file = file;
 
diff --git a/src/nffs_gc.c b/src/nffs_gc.c
index bfc45bf..0b661ce 100644
--- a/src/nffs_gc.c
+++ b/src/nffs_gc.c
@@ -19,10 +19,8 @@
 
 #include <assert.h>
 #include <string.h>
-#if __ZEPHYR__
-#include <kernel.h>
-#endif
 #include <nffs/nffs.h>
+#include <nffs/os.h>
 
 /**
  * Keeps track of the number of garbage collections performed.  The exact
diff --git a/src/nffs_hash.c b/src/nffs_hash.c
index 925d51e..68ff8d6 100644
--- a/src/nffs_hash.c
+++ b/src/nffs_hash.c
@@ -20,10 +20,8 @@
 #include <stddef.h>
 #include <string.h>
 #include <assert.h>
-#if __ZEPHYR__
-#include <kernel.h>
-#endif
 #include <nffs/nffs.h>
+#include <nffs/os.h>
 
 struct nffs_hash_list *nffs_hash;
 #if !NFFS_CONFIG_USE_HEAP
diff --git a/src/nffs_misc.c b/src/nffs_misc.c
index aecae4c..9953c36 100644
--- a/src/nffs_misc.c
+++ b/src/nffs_misc.c
@@ -20,9 +20,6 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
-#if __ZEPHYR__
-#include <kernel.h>
-#endif
 #include <nffs/nffs.h>
 #include <nffs/os.h>