Add fops return func for single fs registered

Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2f8213bd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2f8213bd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2f8213bd

Branch: refs/heads/develop
Commit: 2f8213bd7599c062a71ba1882ee26bbf265a8fe8
Parents: ca1b491
Author: Fabio Utzig <[email protected]>
Authored: Thu Jan 5 20:32:53 2017 -0200
Committer: Fabio Utzig <[email protected]>
Committed: Thu Jan 12 10:51:46 2017 -0200

----------------------------------------------------------------------
 fs/fs/include/fs/fs_if.h |  8 ++++++++
 fs/fs/src/fs_mount.c     | 12 ++++++++++++
 2 files changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2f8213bd/fs/fs/include/fs/fs_if.h
----------------------------------------------------------------------
diff --git a/fs/fs/include/fs/fs_if.h b/fs/fs/include/fs/fs_if.h
index 015d832..ade4f97 100644
--- a/fs/fs/include/fs/fs_if.h
+++ b/fs/fs/include/fs/fs_if.h
@@ -68,6 +68,14 @@ struct fs_ops {
 int fs_register(struct fs_ops *fops);
 
 /**
+ * Will look for the number of registered filesystems and will return
+ * the fops if there is only one.
+ *
+ * @return fops if there's only one registered filesystem, NULL otherwise.
+ */
+struct fs_ops *fs_ops_try_unique(void);
+
+/**
  * Retrieve a filesystem's operations table
  *
  * @param name Name of the filesystem to retrieve fs_ops for

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2f8213bd/fs/fs/src/fs_mount.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_mount.c b/fs/fs/src/fs_mount.c
index 5f020cf..3fceb70 100644
--- a/fs/fs/src/fs_mount.c
+++ b/fs/fs/src/fs_mount.c
@@ -53,6 +53,18 @@ fs_register(struct fs_ops *fops)
 }
 
 struct fs_ops *
+fs_ops_try_unique(void)
+{
+    struct fs_ops *fops = SLIST_FIRST(&root_fops);
+
+    if (fops && !SLIST_NEXT(fops, sc_next)) {
+        return fops;
+    }
+
+    return NULL;
+}
+
+struct fs_ops *
 fs_ops_for(const char *fs_name)
 {
     struct fs_ops *fops = NULL;

Reply via email to