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/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new d0a2fa626a driver/mtd_config : add mtdconfig_register_by_path()
d0a2fa626a is described below
commit d0a2fa626a324bec85e32150e5203ae11de1aab7
Author: xucheng5 <[email protected]>
AuthorDate: Thu Apr 6 15:53:02 2023 +0800
driver/mtd_config : add mtdconfig_register_by_path()
Signed-off-by: xucheng5 <[email protected]>
---
drivers/mtd/mtd_config_fs.c | 46 +++++++++++++++++++++++++++++++++---------
include/nuttx/mtd/configdata.h | 38 ++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/mtd_config_fs.c b/drivers/mtd/mtd_config_fs.c
index 8c425fe89b..ec82e71295 100644
--- a/drivers/mtd/mtd_config_fs.c
+++ b/drivers/mtd/mtd_config_fs.c
@@ -2000,14 +2000,15 @@ static int mtdconfig_poll(FAR struct file *filep, FAR
struct pollfd *fds,
****************************************************************************/
/****************************************************************************
- * Name: mtdconfig_register
+ * Name: mtdconfig_register_by_path
*
* Description:
- * Register a /dev/config device backed by an fail-safe NVS.
+ * Register a "path" device backed by an fail-safe NVS.
*
****************************************************************************/
-int mtdconfig_register(FAR struct mtd_dev_s *mtd)
+int mtdconfig_register_by_path(FAR struct mtd_dev_s *mtd,
+ FAR const char *path)
{
int ret;
FAR struct nvs_fs *fs;
@@ -2035,7 +2036,7 @@ int mtdconfig_register(FAR struct mtd_dev_s *mtd)
goto mutex_err;
}
- ret = register_driver("/dev/config", &g_mtdnvs_fops, 0666, fs);
+ ret = register_driver(path, &g_mtdnvs_fops, 0666, fs);
if (ret < 0)
{
ferr("ERROR: register mtd config failed: %d\n", ret);
@@ -2053,24 +2054,37 @@ errout:
}
/****************************************************************************
- * Name: mtdconfig_unregister
+ * Name: mtdconfig_register
*
* Description:
- * Unregister a /dev/config device backed by an fail-safe NVS.
+ * Register a /dev/config device backed by an fail-safe NVS.
*
****************************************************************************/
-int mtdconfig_unregister(void)
+int mtdconfig_register(FAR struct mtd_dev_s *mtd)
+{
+ return mtdconfig_register_by_path(mtd, "/dev/config");
+}
+
+/****************************************************************************
+ * Name: mtdconfig_unregister_by_path
+ *
+ * Description:
+ * Unregister a MTD device backed by an fail-safe NVS.
+ *
+ ****************************************************************************/
+
+int mtdconfig_unregister_by_path(FAR const char *path)
{
int ret;
struct file file;
FAR struct inode *inode;
FAR struct nvs_fs *fs;
- ret = file_open(&file, "/dev/config", 0);
+ ret = file_open(&file, path, 0);
if (ret < 0)
{
- ferr("ERROR: open /dev/config failed: %d\n", ret);
+ ferr("ERROR: open file %s err: %d\n", path, ret);
return ret;
}
@@ -2079,8 +2093,20 @@ int mtdconfig_unregister(void)
nxmutex_destroy(&fs->nvs_lock);
kmm_free(fs);
file_close(&file);
- unregister_driver("/dev/config");
+ unregister_driver(path);
return OK;
}
+/****************************************************************************
+ * Name: mtdconfig_unregister
+ *
+ * Description:
+ * Unregister a /dev/config device backed by an fail-safe NVS.
+ *
+ ****************************************************************************/
+
+int mtdconfig_unregister(void)
+{
+ return mtdconfig_unregister_by_path("/dev/config");
+}
diff --git a/include/nuttx/mtd/configdata.h b/include/nuttx/mtd/configdata.h
index af76333977..275370238c 100644
--- a/include/nuttx/mtd/configdata.h
+++ b/include/nuttx/mtd/configdata.h
@@ -135,6 +135,44 @@ int mtdconfig_register(FAR struct mtd_dev_s *mtd);
int mtdconfig_unregister(void);
+/****************************************************************************
+ * Name: mtdconfig_register_by_path
+ *
+ * Description:
+ * This function binds an instance of an MTD device to the path specified
+ * device.
+ *
+ * When this function is called, the MTD device pass in should already
+ * be initialized appropriately to access the physical device or partition.
+ *
+ * Input Parameters:
+ * mtd - Pointer to the MTD device to bind with the path device
+ * path - Path name of the file backing the MTD device
+ *
+ * Returned Value:
+ * Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int mtdconfig_register_by_path(FAR struct mtd_dev_s *mtd,
+ FAR const char *path);
+
+/****************************************************************************
+ * Name: mtdconfig_unregister_by_path
+ *
+ * Description:
+ * This function unregisters path device.
+ *
+ * Input Parameters:
+ * path - Path name of the file backing the MTD device
+ *
+ * Returned Value:
+ * Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int mtdconfig_unregister_by_path(FAR const char *path);
+
#undef EXTERN
#ifdef __cplusplus
}