You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/09/09 11:28:04 UTC

[incubator-nuttx] 01/02: driver: move find_mtddriver() to fs.h and add close_mtddriver.c

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

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 25c2f3e042b9e07d604ad0d883380db7a289efa9
Author: wangbowen6 <wa...@xiaomi.com>
AuthorDate: Mon Sep 5 09:49:57 2022 +0800

    driver: move find_mtddriver() to fs.h and add close_mtddriver.c
    
    Rpmsg mtd need a way to find the mtd device according to the
    mtd device path.
    
    Signed-off-by: wangbowen6 <wa...@xiaomi.com>
---
 fs/driver/Make.defs                                |  2 +-
 fs/driver/driver.h                                 | 22 -------
 .../{fs_findmtddriver.c => fs_closemtddriver.c}    | 72 ++++------------------
 fs/driver/fs_findmtddriver.c                       |  1 -
 include/nuttx/fs/fs.h                              | 38 ++++++++++++
 5 files changed, 51 insertions(+), 84 deletions(-)

diff --git a/fs/driver/Make.defs b/fs/driver/Make.defs
index e34f437781..330f559b10 100644
--- a/fs/driver/Make.defs
+++ b/fs/driver/Make.defs
@@ -25,7 +25,7 @@ CSRCS += fs_registerdriver.c fs_unregisterdriver.c
 ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
 CSRCS += fs_registerblockdriver.c fs_unregisterblockdriver.c
 CSRCS += fs_findblockdriver.c fs_openblockdriver.c fs_closeblockdriver.c
-CSRCS += fs_blockpartition.c fs_findmtddriver.c
+CSRCS += fs_blockpartition.c fs_findmtddriver.c fs_closemtddriver.c
 
 ifeq ($(CONFIG_MTD),y)
 CSRCS += fs_registermtddriver.c fs_unregistermtddriver.c
diff --git a/fs/driver/driver.h b/fs/driver/driver.h
index a0bfa4cde2..b8d9959821 100644
--- a/fs/driver/driver.h
+++ b/fs/driver/driver.h
@@ -124,28 +124,6 @@ int mtd_proxy(FAR const char *mtddev, int mountflags,
               FAR struct inode **ppinode);
 #endif
 
-/****************************************************************************
- * Name: find_mtddriver
- *
- * Description:
- *   Return the inode of the named MTD driver specified by 'pathname'
- *
- * Input Parameters:
- *   pathname   - the full path to the named MTD driver to be located
- *   ppinode    - address of the location to return the inode reference
- *
- * Returned Value:
- *   Returns zero on success or a negated errno on failure:
- *
- *   ENOENT  - No MTD driver of this name is registered
- *   ENOTBLK - The inode associated with the pathname is not an MTD driver
- *
- ****************************************************************************/
-
-#ifndef CONFIG_DISABLE_MOUNTPOINT
-int find_mtddriver(FAR const char *pathname, FAR struct inode **ppinode);
-#endif
-
 #undef EXTERN
 #if defined(__cplusplus)
 }
diff --git a/fs/driver/fs_findmtddriver.c b/fs/driver/fs_closemtddriver.c
similarity index 53%
copy from fs/driver/fs_findmtddriver.c
copy to fs/driver/fs_closemtddriver.c
index 7dc4a83fef..3d9d6922a7 100644
--- a/fs/driver/fs_findmtddriver.c
+++ b/fs/driver/fs_closemtddriver.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * fs/driver/fs_findmtddriver.c
+ * fs/driver/fs_closemtddriver.c
  *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -24,96 +24,48 @@
 
 #include <nuttx/config.h>
 
-#include <sys/types.h>
-#include <stdbool.h>
-#include <assert.h>
 #include <errno.h>
-#include <debug.h>
-
 #include <nuttx/fs/fs.h>
 
 #include "inode/inode.h"
-#include "driver/driver.h"
-
-#ifdef CONFIG_MTD
 
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: find_mtddriver
+ * Name: close_mtddriver
  *
  * Description:
- *   Return the inode of the named MTD driver specified by 'pathname'
+ *   Release the inode got by function find_mtddriver()
  *
  * Input Parameters:
- *   pathname   - the full path to the named MTD driver to be located
- *   ppinode    - address of the location to return the inode reference
+ *   pinode    - pointer to the inode
  *
  * Returned Value:
  *   Returns zero on success or a negated errno on failure:
  *
- *   ENOENT  - No MTD driver of this name is registered
- *   ENOTBLK - The inode associated with the pathname is not an MTD driver
+ *   EINVAL  - inode is NULL
  *
  ****************************************************************************/
 
-int find_mtddriver(FAR const char *pathname, FAR struct inode **ppinode)
+#ifdef CONFIG_MTD
+int close_mtddriver(FAR struct inode *pinode)
 {
-  struct inode_search_s desc;
-  FAR struct inode *inode;
-  int ret = 0; /* Assume success */
-
-  DEBUGASSERT(pathname != NULL || ppinode != NULL);
+  /* Sanity checks */
 
-  /* Find the inode registered with this pathname */
-
-  SETUP_SEARCH(&desc, pathname, false);
-
-  ret = inode_find(&desc);
-  if (ret < 0)
+  if (pinode == NULL)
     {
-      ferr("ERROR: Failed to find %s\n", pathname);
-      ret = -ENOENT;
-      goto errout_with_search;
+      return -EINVAL;
     }
 
-  /* Get the search results */
-
-  inode = desc.node;
-  DEBUGASSERT(inode != NULL);
+  inode_release(pinode);
 
-  /* Verify that the inode is a block driver. */
-
-  if (!INODE_IS_MTD(inode))
-    {
-      ferr("ERROR: %s is not a named MTD driver\n", pathname);
-      ret = -ENOTBLK;
-      goto errout_with_inode;
-    }
-
-  /* Return the MTD inode reference */
-
-  DEBUGASSERT(inode->u.i_mtd != NULL);
-
-  *ppinode = inode;
-  RELEASE_SEARCH(&desc);
   return OK;
-
-errout_with_inode:
-  inode_release(inode);
-
-errout_with_search:
-  RELEASE_SEARCH(&desc);
-  return ret;
 }
-
 #else
-
-int find_mtddriver(FAR const char *pathname, FAR struct inode **ppinode)
+int close_mtddriver(FAR struct inode *pinode)
 {
   return -ENODEV;
 }
-
 #endif /* CONFIG_MTD */
diff --git a/fs/driver/fs_findmtddriver.c b/fs/driver/fs_findmtddriver.c
index 7dc4a83fef..fad08f0900 100644
--- a/fs/driver/fs_findmtddriver.c
+++ b/fs/driver/fs_findmtddriver.c
@@ -33,7 +33,6 @@
 #include <nuttx/fs/fs.h>
 
 #include "inode/inode.h"
-#include "driver/driver.h"
 
 #ifdef CONFIG_MTD
 
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index 0e631ea05c..92ffdc432e 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -986,6 +986,44 @@ int open_blockdriver(FAR const char *pathname, int mountflags,
 
 int close_blockdriver(FAR struct inode *inode);
 
+/****************************************************************************
+ * Name: find_mtddriver
+ *
+ * Description:
+ *   Return the inode of the named MTD driver specified by 'pathname'
+ *
+ * Input Parameters:
+ *   pathname   - the full path to the named MTD driver to be located
+ *   ppinode    - address of the location to return the inode reference
+ *
+ * Returned Value:
+ *   Returns zero on success or a negated errno on failure:
+ *
+ *   ENOENT  - No MTD driver of this name is registered
+ *   ENOTBLK - The inode associated with the pathname is not an MTD driver
+ *
+ ****************************************************************************/
+
+int find_mtddriver(FAR const char *pathname, FAR struct inode **ppinode);
+
+/****************************************************************************
+ * Name: close_mtddriver
+ *
+ * Description:
+ *   Release the inode got by function find_mtddriver()
+ *
+ * Input Parameters:
+ *   pinode    - pointer to the inode
+ *
+ * Returned Value:
+ *   Returns zero on success or a negated errno on failure:
+ *
+ *   EINVAL  - inode is NULL
+ *
+ ****************************************************************************/
+
+int close_mtddriver(FAR struct inode *pinode);
+
 /****************************************************************************
  * Name: fs_fdopen
  *