diff --git a/fs/driver/Make.defs b/fs/driver/Make.defs index 12228798150..33013d0f6aa 100644 --- a/fs/driver/Make.defs +++ b/fs/driver/Make.defs @@ -46,6 +46,10 @@ CSRCS += fs_registerblockdriver.c fs_unregisterblockdriver.c CSRCS += fs_findblockdriver.c fs_openblockdriver.c fs_closeblockdriver.c CSRCS += fs_blockpartition.c +ifeq ($(CONFIG_MTD),y) +CSRCS += fs_registermtddriver.c fs_unregistermtddriver.c fs_findmtddriver.c +endif + ifneq ($(CONFIG_DISABLE_PSEUDOFS_OPERATIONS),y) CSRCS += fs_blockproxy.c endif diff --git a/fs/driver/driver.h b/fs/driver/driver.h index dd15fb33bb0..5731c35e25a 100644 --- a/fs/driver/driver.h +++ b/fs/driver/driver.h @@ -1,7 +1,8 @@ /**************************************************************************** * fs/driver/driver.h * - * Copyright (C) 2007, 2009, 2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012, 2014, 2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -70,19 +71,18 @@ extern "C" * Return the inode of the block driver specified by 'pathname' * * Input Parameters: - * pathname - the full path to the block driver to be located - * mountflags - if MS_RDONLY is not set, then driver must support write - * operations (see include/sys/mount.h) - * ppinode - address of the location to return the inode reference + * pathname - The full path to the block driver to be located + * mountflags - If MS_RDONLY is not set, then driver must support write + * operations (see include/sys/mount.h) + * ppinode - Address of the location to return the inode reference * * Returned Value: * Returns zero on success or a negated errno on failure: * - * EINVAL - pathname or pinode is NULL * ENOENT - No block driver of this name is registered * ENOTBLK - The inode associated with the pathname is not a block driver * EACCESS - The MS_RDONLY option was not set but this driver does not - * support write access + * support write access * ****************************************************************************/ @@ -122,6 +122,28 @@ int find_blockdriver(FAR const char *pathname, int mountflags, int block_proxy(FAR const char *blkdev, int oflags); #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 + * + ****************************************************************************/ + +#if defined(CONFIG_MTD) && !defined(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_findblockdriver.c b/fs/driver/fs_findblockdriver.c index f85bff032f4..bb0aab3bae2 100644 --- a/fs/driver/fs_findblockdriver.c +++ b/fs/driver/fs_findblockdriver.c @@ -1,5 +1,5 @@ /**************************************************************************** - * fs/driver/fs_openblockdriver.c + * fs/driver/fs_findblockdriver.c * * Copyright (C) 2008, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -62,36 +62,29 @@ * Return the inode of the block driver specified by 'pathname' * * Input Parameters: - * pathname - the full path to the block driver to be located - * mountflags - if MS_RDONLY is not set, then driver must support write - * operations (see include/sys/mount.h) - * ppinode - address of the location to return the inode reference + * pathname - The full path to the block driver to be located + * mountflags - If MS_RDONLY is not set, then driver must support write + * operations (see include/sys/mount.h) + * ppinode - Address of the location to return the inode reference * * Returned Value: * Returns zero on success or a negated errno on failure: * - * EINVAL - pathname or pinode is NULL * ENOENT - No block driver of this name is registered * ENOTBLK - The inode associated with the pathname is not a block driver * EACCESS - The MS_RDONLY option was not set but this driver does not - * support write access + * support write access * ****************************************************************************/ -int find_blockdriver(FAR const char *pathname, int mountflags, FAR struct inode **ppinode) +int find_blockdriver(FAR const char *pathname, int mountflags, + FAR struct inode **ppinode) { struct inode_search_s desc; FAR struct inode *inode; int ret = 0; /* Assume success */ - /* Sanity checks */ - -#ifdef CONFIG_DEBUG_FEATURES - if (!pathname || !ppinode) - { - return -EINVAL; - } -#endif + DEBUGASSERT(pathname != NULL || ppinode != NULL); /* Find the inode registered with this pathname */ diff --git a/fs/driver/fs_findmtddriver.c b/fs/driver/fs_findmtddriver.c new file mode 100644 index 00000000000..c46c50ba454 --- /dev/null +++ b/fs/driver/fs_findmtddriver.c @@ -0,0 +1,128 @@ +/**************************************************************************** + * fs/driver/fs_findmtddriver.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in pathname and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of pathname code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "inode/inode.h" +#include "driver/driver.h" + +#ifdef CONFIG_MTD + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * 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) +{ + struct inode_search_s desc; + FAR struct inode *inode; + int ret = 0; /* Assume success */ + + DEBUGASSERT(pathname != NULL || ppinode != NULL); + + /* Find the inode registered with this pathname */ + + SETUP_SEARCH(&desc, pathname, false); + + ret = inode_find(&desc); + if (ret < 0) + { + ferr("ERROR: Failed to find %s\n", pathname); + ret = -ENOENT; + goto errout_with_search; + } + + /* Get the search results */ + + inode = desc.node; + DEBUGASSERT(inode != NULL); + + /* 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; +} + +#endif /* CONFIG_MTD */ diff --git a/fs/driver/fs_registermtddriver.c b/fs/driver/fs_registermtddriver.c new file mode 100644 index 00000000000..924c76531c2 --- /dev/null +++ b/fs/driver/fs_registermtddriver.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * fs/driver/fs_registermtddriver.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "inode/inode.h" + +#if defined(CONFIG_MTD) && !defined(CONFIG_DISABLE_MOUNTPOINT) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: register_mtddriver + * + * Description: + * Register an MTD driver inode the pseudo file system. + * + * Input Parameters: + * path - The path to the inode to create + * mtd - The MTD driver structure + * mode - inode privileges (not used) + * priv - Private, user data that will be associated with the inode. + * + * Returned Value: + * Zero on success (with the inode point in 'inode'); A negated errno + * value is returned on a failure (all error values returned by + * inode_reserve): + * + * EINVAL - 'path' is invalid for this operation + * EEXIST - An inode already exists at 'path' + * ENOMEM - Failed to allocate in-memory resources for the operation + * + ****************************************************************************/ + +int register_mtddriver(FAR const char *path, FAR struct mtd_dev_s *mtd, + mode_t mode, FAR void *priv) +{ + FAR struct inode *node; + int ret; + + /* Insert an inode for the device driver -- we need to hold the inode + * semaphore to prevent access to the tree while we this. This is because + * we will have a momentarily bad true until we populate the inode with + * valid data. + */ + + inode_semtake(); + ret = inode_reserve(path, &node); + if (ret >= 0) + { + /* We have it, now populate it with block driver specific information. + * NOTE that the initial reference count on the new inode is zero. + */ + + INODE_SET_MTD(node); + + node->u.i_mtd = mtd; +#ifdef CONFIG_FILE_MODE + node->i_mode = mode; +#endif + node->i_private = priv; + ret = OK; + } + + inode_semgive(); + return ret; +} + +#endif /* CONFIG_MTD && !CONFIG_DISABLE_MOUNTPOINT */ + diff --git a/fs/driver/fs_unregisterblockdriver.c b/fs/driver/fs_unregisterblockdriver.c index 23470e9ba31..cd28dc10873 100644 --- a/fs/driver/fs_unregisterblockdriver.c +++ b/fs/driver/fs_unregisterblockdriver.c @@ -55,7 +55,7 @@ * ****************************************************************************/ -int unregister_blockdriver(const char *path) +int unregister_blockdriver(FAR const char *path) { int ret; diff --git a/fs/driver/fs_unregistermtddriver.c b/fs/driver/fs_unregistermtddriver.c new file mode 100644 index 00000000000..3f2fef90ff6 --- /dev/null +++ b/fs/driver/fs_unregistermtddriver.c @@ -0,0 +1,67 @@ +/**************************************************************************** + * fs/driver/fs_unregistermtddriver.c + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "inode/inode.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: unregister_mtddriver + * + * Description: + * Remove the named TMD driver inode at 'path' from the pseudo-file system + * + ****************************************************************************/ + +int unregister_mtddriver(FAR const char *path) +{ + int ret; + + inode_semtake(); + ret = inode_remove(path); + inode_semgive(); + return ret; +} diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c index e6a7d1665fa..463dd7ba1cf 100644 --- a/fs/mount/fs_mount.c +++ b/fs/mount/fs_mount.c @@ -52,7 +52,7 @@ #include "driver/driver.h" /* At least one filesystem must be defined, or this file will not compile. - * It may be desire-able to make filesystems dynamically registered at + * It may be desire-able to make file systems dynamically registered at * some time in the future, but at present, this file needs to know about * every configured filesystem. */ @@ -75,13 +75,17 @@ # define BDFS_SUPPORT 1 #endif -/* These file systems do not require block drivers */ +/* These file systems require MTD drivers */ + +#undef MDFS_SUPPORT + +/* These file systems do not require block or MTD drivers */ #if defined(CONFIG_FS_NXFFS) || defined(CONFIG_FS_BINFS) || \ defined(CONFIG_FS_PROCFS) || defined(CONFIG_NFS) || \ defined(CONFIG_FS_TMPFS) || defined(CONFIG_FS_USERFS) || \ defined(CONFIG_FS_CROMFS) -# define NONBDFS_SUPPORT +# define NODFS_SUPPORT #endif /**************************************************************************** @@ -99,6 +103,8 @@ struct fsmap_t ****************************************************************************/ #ifdef BDFS_SUPPORT +/* File systems that require block drivers */ + #ifdef CONFIG_FS_FAT extern const struct mountpt_operations fat_operations; #endif @@ -122,9 +128,19 @@ static const struct fsmap_t g_bdfsmap[] = #endif { NULL, NULL }, }; -#endif /* BDFS_SUPPORT*/ +#endif /* BDFS_SUPPORT */ + +#ifdef MDFS_SUPPORT +/* File systems that require MTD drivers */ + +static const struct fsmap_t g_mdfsmap[] = +{ +}; +#endif /* MDFS_SUPPORT */ + +#ifdef NODFS_SUPPORT +/* File systems that require neither block nor MTD drivers */ -#ifdef NONBDFS_SUPPORT #ifdef CONFIG_FS_NXFFS extern const struct mountpt_operations nxffs_operations; #endif @@ -178,7 +194,7 @@ static const struct fsmap_t g_nonbdfsmap[] = #endif { NULL, NULL }, }; -#endif /* NONBDFS_SUPPORT */ +#endif /* NODFS_SUPPORT */ /**************************************************************************** * Private Functions @@ -192,7 +208,7 @@ static const struct fsmap_t g_nonbdfsmap[] = * ****************************************************************************/ -#if defined(BDFS_SUPPORT) || defined(NONBDFS_SUPPORT) +#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) || defined(NODFS_SUPPORT) static FAR const struct mountpt_operations * mount_findfs(FAR const struct fsmap_t *fstab, FAR const char *filesystemtype) { @@ -242,9 +258,9 @@ int mount(FAR const char *source, FAR const char *target, FAR const char *filesystemtype, unsigned long mountflags, FAR const void *data) { -#if defined(BDFS_SUPPORT) || defined(NONBDFS_SUPPORT) -#ifdef BDFS_SUPPORT - FAR struct inode *blkdrvr_inode = NULL; +#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) || defined(NODFS_SUPPORT) +#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) + FAR struct inode *drvr_inode = NULL; #endif FAR struct inode *mountpt_inode; FAR const struct mountpt_operations *mops; @@ -262,15 +278,11 @@ int mount(FAR const char *source, FAR const char *target, /* Find the specified filesystem. Try the block driver file systems first */ #ifdef BDFS_SUPPORT - if (source && (mops = mount_findfs(g_bdfsmap, filesystemtype)) != NULL) + if (source != NULL && (mops = mount_findfs(g_bdfsmap, filesystemtype)) != NULL) { - /* Make sure that a block driver argument was provided */ - - DEBUGASSERT(source); - /* Find the block driver */ - ret = find_blockdriver(source, mountflags, &blkdrvr_inode); + ret = find_blockdriver(source, mountflags, &drvr_inode); if (ret < 0) { ferr("ERROR: Failed to find block driver %s\n", source); @@ -280,12 +292,27 @@ int mount(FAR const char *source, FAR const char *target, } else #endif /* BDFS_SUPPORT */ -#ifdef NONBDFS_SUPPORT +#ifdef MDFS_SUPPORT + if (source != NULL && (mops = mount_findfs(g_mdfsmap, filesystemtype)) != NULL) + { + /* Find the named MTD driver */ + + ret = find_mtddriver(source, mountflags, &drvr_inode); + if (ret < 0) + { + ferr("ERROR: Failed to find MTD driver %s\n", source); + errcode = -ret; + goto errout; + } + } + else +#endif /* MDFS_SUPPORT */ +#ifdef NODFS_SUPPORT if ((mops = mount_findfs(g_nonbdfsmap, filesystemtype)) != NULL) { } else -#endif /* NONBDFS_SUPPORT */ +#endif /* NODFS_SUPPORT */ { ferr("ERROR: Failed to find file system %s\n", filesystemtype); errcode = ENODEV; @@ -353,7 +380,7 @@ int mount(FAR const char *source, FAR const char *target, * that encapsulates this binding. */ - if (!mops->bind) + if (mops->bind == NULL) { /* The filesystem does not support the bind operation ??? */ @@ -364,38 +391,40 @@ int mount(FAR const char *source, FAR const char *target, /* Increment reference count for the reference we pass to the file system */ -#ifdef BDFS_SUPPORT -#ifdef NONBDFS_SUPPORT - if (blkdrvr_inode) +#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) +#ifdef NODFS_SUPPORT + if (drvr_inode != NULL) #endif { - blkdrvr_inode->i_crefs++; + drvr_inode->i_crefs++; } #endif /* On failure, the bind method returns -errorcode */ -#ifdef BDFS_SUPPORT - ret = mops->bind(blkdrvr_inode, data, &fshandle); +#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) + ret = mops->bind(drvr_inode, data, &fshandle); #else ret = mops->bind(NULL, data, &fshandle); #endif - if (ret != 0) + if (ret < 0) { - /* The inode is unhappy with the blkdrvr for some reason. Back out + /* The inode is unhappy with the driver for some reason. Back out * the count for the reference we failed to pass and exit with an * error. */ ferr("ERROR: Bind method failed: %d\n", ret); -#ifdef BDFS_SUPPORT -#ifdef NONBDFS_SUPPORT - if (blkdrvr_inode) + +#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) +#ifdef NODFS_SUPPORT + if (drvr_inode != NULL) #endif { - blkdrvr_inode->i_crefs--; + drvr_inode->i_crefs--; } #endif + errcode = -ret; goto errout_with_mountpt; } @@ -417,12 +446,12 @@ int mount(FAR const char *source, FAR const char *target, * that will persist until umount2() is called. */ -#ifdef BDFS_SUPPORT -#ifdef NONBDFS_SUPPORT - if (blkdrvr_inode) +#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) +#ifdef NODFS_SUPPORT + if (drvr_inode != NULL) #endif { - inode_release(blkdrvr_inode); + inode_release(drvr_inode); } #endif @@ -437,12 +466,13 @@ errout_with_mountpt: mountpt_inode->i_crefs = 0; inode_remove(target); inode_semgive(); -#ifdef BDFS_SUPPORT -#ifdef NONBDFS_SUPPORT - if (blkdrvr_inode) + +#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) +#ifdef NODFS_SUPPORT + if (drvr_inode != NULL) #endif { - inode_release(blkdrvr_inode); + inode_release(drvr_inode); } #endif @@ -455,12 +485,12 @@ errout_with_mountpt: errout_with_semaphore: inode_semgive(); -#ifdef BDFS_SUPPORT -#ifdef NONBDFS_SUPPORT - if (blkdrvr_inode) +#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) +#ifdef NODFS_SUPPORT + if (drvr_inode != NULL) #endif { - inode_release(blkdrvr_inode); + inode_release(drvr_inode); } #endif @@ -476,7 +506,7 @@ errout: ferr("ERROR: No filesystems enabled\n"); set_errno(ENOSYS); return ERROR; -#endif /* BDFS_SUPPORT || NONBDFS_SUPPORT */ +#endif /* BDFS_SUPPORT || MDFS_SUPPORT || NODFS_SUPPORT */ } #endif /* CONFIG_FS_READABLE */ diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index b611ad675ca..82de23a8707 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -113,22 +113,23 @@ #define __FS_FLAG_LBF (1 << 2) /* Line buffered */ #define __FS_FLAG_UBF (1 << 3) /* Buffer allocated by caller of setvbuf */ -/* Inode i_flag values: +/* Inode i_flags values: * - * Bit 0-3: Inode type (Bit 4 indicates internal OS types) + * Bit 0-3: Inode type (Bit 3 indicates internal OS types) * Bit 4: Set if inode has been unlinked and is pending removal. */ -#define FSNODEFLAG_TYPE_MASK 0x00000007 /* Isolates type field */ -#define FSNODEFLAG_TYPE_DRIVER 0x00000000 /* Character driver */ -#define FSNODEFLAG_TYPE_BLOCK 0x00000001 /* Block driver */ -#define FSNODEFLAG_TYPE_MOUNTPT 0x00000002 /* Mount point */ -#define FSNODEFLAG_TYPE_SPECIAL 0x00000004 /* Special OS type */ -#define FSNODEFLAG_TYPE_NAMEDSEM 0x00000004 /* Named semaphore */ -#define FSNODEFLAG_TYPE_MQUEUE 0x00000005 /* Message Queue */ -#define FSNODEFLAG_TYPE_SHM 0x00000006 /* Shared memory region */ -#define FSNODEFLAG_TYPE_SOFTLINK 0x00000007 /* Soft link */ -#define FSNODEFLAG_DELETED 0x00000008 /* Unlinked */ +#define FSNODEFLAG_TYPE_MASK 0x0000000f /* Isolates type field */ +#define FSNODEFLAG_TYPE_DRIVER 0x00000000 /* Character driver */ +#define FSNODEFLAG_TYPE_BLOCK 0x00000001 /* Block driver */ +#define FSNODEFLAG_TYPE_MOUNTPT 0x00000002 /* Mount point */ +#define FSNODEFLAG_TYPE_SPECIAL 0x00000008 /* Special OS type */ +#define FSNODEFLAG_TYPE_NAMEDSEM 0x00000008 /* Named semaphore */ +#define FSNODEFLAG_TYPE_MQUEUE 0x00000009 /* Message Queue */ +#define FSNODEFLAG_TYPE_SHM 0x0000000a /* Shared memory region */ +#define FSNODEFLAG_TYPE_MTD 0x0000000b /* Named MTD driver */ +#define FSNODEFLAG_TYPE_SOFTLINK 0x0000000c /* Soft link */ +#define FSNODEFLAG_DELETED 0x00000010 /* Unlinked */ #define INODE_IS_TYPE(i,t) \ (((i)->i_flags & FSNODEFLAG_TYPE_MASK) == (t)) @@ -141,6 +142,7 @@ #define INODE_IS_NAMEDSEM(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_NAMEDSEM) #define INODE_IS_MQUEUE(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_MQUEUE) #define INODE_IS_SHM(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_SHM) +#define INODE_IS_MTD(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_MTD) #define INODE_IS_SOFTLINK(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_SOFTLINK) #define INODE_GET_TYPE(i) ((i)->i_flags & FSNODEFLAG_TYPE_MASK) @@ -157,6 +159,7 @@ #define INODE_SET_NAMEDSEM(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_NAMEDSEM) #define INODE_SET_MQUEUE(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_MQUEUE) #define INODE_SET_SHM(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_SHM) +#define INODE_SET_MTD(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_MTD) #define INODE_SET_SOFTLINK(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_SOFTLINK) /* Mountpoint fd_flags values */ @@ -207,6 +210,7 @@ struct stat; struct statfs; struct pollfd; struct fs_dirent_s; +struct mtd_dev_s; /* This structure is provided by devices when they are registered with the * system. It is used to call back to perform device specific operations. @@ -377,6 +381,9 @@ union inode_ops_u #ifndef CONFIG_DISABLE_MQUEUE FAR struct mqueue_inode_s *i_mqueue; /* POSIX message queue */ #endif +#ifndef CONFIGMTD + FAR struct mtd_dev_s *i_mtd; /* MTD device driver */ +#endif #ifdef CONFIG_PSEUDOFS_SOFTLINKS FAR char *i_link; /* Full path to link target */ #endif @@ -606,6 +613,46 @@ int unregister_driver(FAR const char *path); int unregister_blockdriver(FAR const char *path); +/**************************************************************************** + * Name: register_mtddriver + * + * Description: + * Register an MTD driver inode the pseudo file system. + * + * Input Parameters: + * path - The path to the inode to create + * mtd - The MTD driver structure + * mode - inode privileges (not used) + * priv - Private, user data that will be associated with the inode. + * + * Returned Value: + * Zero on success (with the inode point in 'inode'); A negated errno + * value is returned on a failure (all error values returned by + * inode_reserve): + * + * EINVAL - 'path' is invalid for this operation + * EEXIST - An inode already exists at 'path' + * ENOMEM - Failed to allocate in-memory resources for the operation + * + ****************************************************************************/ + +#ifdef CONFIG_MTD +int register_mtddriver(FAR const char *path, FAR struct mtd_dev_s *mtd, + mode_t mode, FAR void *priv); +#endif + +/**************************************************************************** + * Name: unregister_mtddriver + * + * Description: + * Remove the named TMD driver inode at 'path' from the pseudo-file system + * + ****************************************************************************/ + +#ifdef CONFIG_MTD +int unregister_mtddriver(FAR const char *path); +#endif + /**************************************************************************** * Name: inode_checkflags * diff --git a/include/sys/stat.h b/include/sys/stat.h index eb4eeb5c0ed..ca7cad70355 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -91,6 +91,7 @@ #define S_IFSEM (6 << 11) #define S_IFSHM (7 << 11) #define S_IFSOCK (8 << 11) +#define S_IFMTD (9 << 11) #define s_IFTGT (15 << 11) /* May be the target of a symbolic link */ #define S_IFLNK (1 << 15) /* Bit 15: Symbolic link */ @@ -98,16 +99,17 @@ /* File type macros that operate on an instance of mode_t */ -#define S_ISLNK(m) (((m) & S_IFLNK) != 0) #define S_ISFIFO(m) (0) #define S_ISCHR(m) (((m) & s_IFTGT) == S_IFCHR) #define S_ISDIR(m) (((m) & s_IFTGT) == S_IFDIR) #define S_ISBLK(m) (((m) & s_IFTGT) == S_IFBLK) #define S_ISREG(m) (((m) & s_IFTGT) == S_IFREG) -#define S_ISSOCK(m) (((m) & s_IFTGT) == S_IFSOCK) #define S_ISMQ(m) (((m) & s_IFTGT) == S_IFMQ) #define S_ISSEM(m) (((m) & s_IFTGT) == S_IFSEM) #define S_ISSHM(m) (((m) & s_IFTGT) == S_IFSHM) +#define S_ISSOCK(m) (((m) & s_IFTGT) == S_IFSOCK) +#define S_ISMTD(m) (((m) & s_IFTGT) == S_IFMTD) +#define S_ISLNK(m) (((m) & S_IFLNK) != 0) /**************************************************************************** * Type Definitions