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 <wangbowen6@xiaomi.com>
This commit is contained in:
wangbowen6 2022-09-05 09:49:57 +08:00 committed by Xiang Xiao
parent 2892f18f15
commit 25c2f3e042
5 changed files with 110 additions and 24 deletions

View File

@ -25,7 +25,7 @@ CSRCS += fs_registerdriver.c fs_unregisterdriver.c
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
CSRCS += fs_registerblockdriver.c fs_unregisterblockdriver.c CSRCS += fs_registerblockdriver.c fs_unregisterblockdriver.c
CSRCS += fs_findblockdriver.c fs_openblockdriver.c fs_closeblockdriver.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) ifeq ($(CONFIG_MTD),y)
CSRCS += fs_registermtddriver.c fs_unregistermtddriver.c CSRCS += fs_registermtddriver.c fs_unregistermtddriver.c

View File

@ -124,28 +124,6 @@ int mtd_proxy(FAR const char *mtddev, int mountflags,
FAR struct inode **ppinode); FAR struct inode **ppinode);
#endif #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 #undef EXTERN
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View File

@ -0,0 +1,71 @@
/****************************************************************************
* 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
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#include <nuttx/fs/fs.h>
#include "inode/inode.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* 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
*
****************************************************************************/
#ifdef CONFIG_MTD
int close_mtddriver(FAR struct inode *pinode)
{
/* Sanity checks */
if (pinode == NULL)
{
return -EINVAL;
}
inode_release(pinode);
return OK;
}
#else
int close_mtddriver(FAR struct inode *pinode)
{
return -ENODEV;
}
#endif /* CONFIG_MTD */

View File

@ -33,7 +33,6 @@
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#include "inode/inode.h" #include "inode/inode.h"
#include "driver/driver.h"
#ifdef CONFIG_MTD #ifdef CONFIG_MTD

View File

@ -986,6 +986,44 @@ int open_blockdriver(FAR const char *pathname, int mountflags,
int close_blockdriver(FAR struct inode *inode); 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 * Name: fs_fdopen
* *