driver/mtd_config : add mtdconfig_register_by_path()
Signed-off-by: xucheng5 <xucheng5@xiaomi.com>
This commit is contained in:
parent
8c19fc547d
commit
d0a2fa626a
@ -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:
|
* 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;
|
int ret;
|
||||||
FAR struct nvs_fs *fs;
|
FAR struct nvs_fs *fs;
|
||||||
@ -2035,7 +2036,7 @@ int mtdconfig_register(FAR struct mtd_dev_s *mtd)
|
|||||||
goto mutex_err;
|
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)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
ferr("ERROR: register mtd config failed: %d\n", ret);
|
ferr("ERROR: register mtd config failed: %d\n", ret);
|
||||||
@ -2052,6 +2053,51 @@ errout:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mtdconfig_register
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Register a /dev/config device backed by an fail-safe NVS.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
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, path, 0);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
ferr("ERROR: open file %s err: %d\n", path, ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
inode = file.f_inode;
|
||||||
|
fs = (FAR struct nvs_fs *)inode->i_private;
|
||||||
|
nxmutex_destroy(&fs->nvs_lock);
|
||||||
|
kmm_free(fs);
|
||||||
|
file_close(&file);
|
||||||
|
unregister_driver(path);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: mtdconfig_unregister
|
* Name: mtdconfig_unregister
|
||||||
*
|
*
|
||||||
@ -2062,25 +2108,5 @@ errout:
|
|||||||
|
|
||||||
int mtdconfig_unregister(void)
|
int mtdconfig_unregister(void)
|
||||||
{
|
{
|
||||||
int ret;
|
return mtdconfig_unregister_by_path("/dev/config");
|
||||||
struct file file;
|
|
||||||
FAR struct inode *inode;
|
|
||||||
FAR struct nvs_fs *fs;
|
|
||||||
|
|
||||||
ret = file_open(&file, "/dev/config", 0);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
ferr("ERROR: open /dev/config failed: %d\n", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
inode = file.f_inode;
|
|
||||||
fs = (FAR struct nvs_fs *)inode->i_private;
|
|
||||||
nxmutex_destroy(&fs->nvs_lock);
|
|
||||||
kmm_free(fs);
|
|
||||||
file_close(&file);
|
|
||||||
unregister_driver("/dev/config");
|
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +135,44 @@ int mtdconfig_register(FAR struct mtd_dev_s *mtd);
|
|||||||
|
|
||||||
int mtdconfig_unregister(void);
|
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
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user