mirror of
https://github.com/apache/nuttx.git
synced 2026-05-29 20:56:47 +08:00
Update SMART FS procfs support. From Ken Pettit
This commit is contained in:
+42
-2
@@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Sector Mapped Allocation for Really Tiny (SMART) Flash block driver.
|
* Sector Mapped Allocation for Really Tiny (SMART) Flash block driver.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Ken Pettit. All rights reserved.
|
* Copyright (C) 2013-2014 Ken Pettit. All rights reserved.
|
||||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -56,6 +56,7 @@
|
|||||||
#include <nuttx/fs/fs.h>
|
#include <nuttx/fs/fs.h>
|
||||||
#include <nuttx/fs/ioctl.h>
|
#include <nuttx/fs/ioctl.h>
|
||||||
#include <nuttx/mtd/mtd.h>
|
#include <nuttx/mtd/mtd.h>
|
||||||
|
#include <nuttx/mtd/smart.h>
|
||||||
#include <nuttx/fs/smart.h>
|
#include <nuttx/fs/smart.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -1976,6 +1977,8 @@ static int smart_ioctl(FAR struct inode *inode, int cmd, unsigned long arg)
|
|||||||
{
|
{
|
||||||
struct smart_struct_s *dev ;
|
struct smart_struct_s *dev ;
|
||||||
int ret;
|
int ret;
|
||||||
|
uint32_t sector;
|
||||||
|
struct mtd_smart_procfs_data_s * procfs_data;
|
||||||
|
|
||||||
fvdbg("Entry\n");
|
fvdbg("Entry\n");
|
||||||
DEBUGASSERT(inode && inode->i_private);
|
DEBUGASSERT(inode && inode->i_private);
|
||||||
@@ -2059,9 +2062,46 @@ static int smart_ioctl(FAR struct inode *inode, int cmd, unsigned long arg)
|
|||||||
goto ok_out;
|
goto ok_out;
|
||||||
#endif /* CONFIG_FS_WRITABLE */
|
#endif /* CONFIG_FS_WRITABLE */
|
||||||
|
|
||||||
|
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS)
|
||||||
|
case BIOC_GETPROCFSD:
|
||||||
|
|
||||||
|
/* Get ProcFS data */
|
||||||
|
|
||||||
|
procfs_data = (FAR struct mtd_smart_procfs_data_s *) arg;
|
||||||
|
procfs_data->totalsectors = dev->totalsectors;
|
||||||
|
procfs_data->sectorsize = dev->sectorsize;
|
||||||
|
procfs_data->freesectors = dev->freesectors;
|
||||||
|
procfs_data->releasesectors = 0;
|
||||||
|
for (sector = 0; sector < dev->neraseblocks; sector++)
|
||||||
|
{
|
||||||
|
procfs_data->releasesectors += dev->releasecount[sector];
|
||||||
|
}
|
||||||
|
|
||||||
|
procfs_data->namelen = dev->namesize;
|
||||||
|
procfs_data->formatversion = dev->formatversion;
|
||||||
|
procfs_data->unusedsectors = 0;
|
||||||
|
procfs_data->blockerases = 0;
|
||||||
|
procfs_data->sectorsperblk = dev->sectorsPerBlk;
|
||||||
|
|
||||||
|
#ifndef CONFIG_MTD_SMART_MINIMIZE_RAM
|
||||||
|
procfs_data->formatsector = dev->sMap[0];
|
||||||
|
procfs_data->dirsector = dev->sMap[3];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_MTD_SMART_SECTOR_ERASE_DEBUG
|
||||||
|
procfs_data->neraseblocks = dev->geo.neraseblocks;
|
||||||
|
procfs_data->erasecounts = dev->erasecounts;
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_MTD_SMART_ALLOC_DEBUG
|
||||||
|
procfs_data->allocs = dev->alloc;
|
||||||
|
procfs_data->alloccount = SMART_MAX_ALLOCS;
|
||||||
|
#endif
|
||||||
|
ret = OK;
|
||||||
|
goto ok_out;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No other block driver ioctl commmands are not recognized by this
|
/* No other block driver ioctl commands are not recognized by this
|
||||||
* driver. Other possible MTD driver ioctl commands are passed through
|
* driver. Other possible MTD driver ioctl commands are passed through
|
||||||
* to the MTD driver (unchanged).
|
* to the MTD driver (unchanged).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* fs/smartfs/smartfs.h
|
* fs/smartfs/smartfs.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Ken Pettit. All rights reserved.
|
* Copyright (C) 2013-2014 Ken Pettit. All rights reserved.
|
||||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||||
*
|
*
|
||||||
* References: Linux/Documentation/filesystems/romfs.txt
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@@ -289,7 +287,7 @@ struct smartfs_ofile_s
|
|||||||
|
|
||||||
struct smartfs_mountpt_s
|
struct smartfs_mountpt_s
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
#if defined(CONFIG_SMARTFS_MULTI_ROOT_DIRS) || defined(CONFIG_FS_PROCFS)
|
||||||
struct smartfs_mountpt_s *fs_next; /* Pointer to next SMART filesystem */
|
struct smartfs_mountpt_s *fs_next; /* Pointer to next SMART filesystem */
|
||||||
#endif
|
#endif
|
||||||
FAR struct inode *fs_blkdriver; /* Our underlying block device */
|
FAR struct inode *fs_blkdriver; /* Our underlying block device */
|
||||||
@@ -344,6 +342,10 @@ int smartfs_countdirentries(struct smartfs_mountpt_s *fs,
|
|||||||
int smartfs_truncatefile(struct smartfs_mountpt_s *fs,
|
int smartfs_truncatefile(struct smartfs_mountpt_s *fs,
|
||||||
struct smartfs_entry_s *entry);
|
struct smartfs_entry_s *entry);
|
||||||
|
|
||||||
|
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS)
|
||||||
|
struct smartfs_mountpt_s* smartfs_get_first_mount(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
struct file; /* Forward references */
|
struct file; /* Forward references */
|
||||||
struct inode;
|
struct inode;
|
||||||
struct fs_dirent_s;
|
struct fs_dirent_s;
|
||||||
|
|||||||
+535
-53
File diff suppressed because it is too large
Load Diff
+34
-10
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* fs/smartfs/smartfs_utils.c
|
* fs/smartfs/smartfs_utils.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Ken Pettit. All rights reserved.
|
* Copyright (C) 2013-2014 Ken Pettit. All rights reserved.
|
||||||
* Author: Ken Pettit <pettitkd@gmail.com>
|
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -72,7 +72,8 @@
|
|||||||
* Private Variables
|
* Private Variables
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
#if defined(CONFIG_SMARTFS_MULTI_ROOT_DIRS) || \
|
||||||
|
(defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS))
|
||||||
static struct smartfs_mountpt_s* g_mounthead = NULL;
|
static struct smartfs_mountpt_s* g_mounthead = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -226,11 +227,18 @@ int smartfs_mount(struct smartfs_mountpt_s *fs, bool writeable)
|
|||||||
|
|
||||||
fs->fs_rootsector = SMARTFS_ROOT_DIR_SECTOR + fs->fs_llformat.rootdirnum;
|
fs->fs_rootsector = SMARTFS_ROOT_DIR_SECTOR + fs->fs_llformat.rootdirnum;
|
||||||
|
|
||||||
#else
|
#else /* CONFIG_SMARTFS_MULTI_ROOT_DIRS */
|
||||||
|
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS)
|
||||||
|
/* Now add ourselves to the linked list of SMART mounts */
|
||||||
|
|
||||||
|
fs->fs_next = g_mounthead;
|
||||||
|
g_mounthead = fs;
|
||||||
|
#endif
|
||||||
|
|
||||||
fs->fs_rwbuffer = (char *) kmm_malloc(fs->fs_llformat.availbytes);
|
fs->fs_rwbuffer = (char *) kmm_malloc(fs->fs_llformat.availbytes);
|
||||||
fs->fs_workbuffer = (char *) kmm_malloc(256);
|
fs->fs_workbuffer = (char *) kmm_malloc(256);
|
||||||
fs->fs_rootsector = SMARTFS_ROOT_DIR_SECTOR;
|
fs->fs_rootsector = SMARTFS_ROOT_DIR_SECTOR;
|
||||||
#endif
|
#endif /* CONFIG_SMARTFS_MULTI_ROOT_DIRS */
|
||||||
|
|
||||||
/* We did it! */
|
/* We did it! */
|
||||||
|
|
||||||
@@ -267,14 +275,16 @@ int smartfs_unmount(struct smartfs_mountpt_s *fs)
|
|||||||
{
|
{
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
#if defined(CONFIG_SMARTFS_MULTI_ROOT_DIRS) || \
|
||||||
|
(defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS))
|
||||||
struct smartfs_mountpt_s *nextfs;
|
struct smartfs_mountpt_s *nextfs;
|
||||||
struct smartfs_mountpt_s *prevfs;
|
struct smartfs_mountpt_s *prevfs;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int found = FALSE;
|
int found = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
#if defined(CONFIG_SMARTFS_MULTI_ROOT_DIRS) || \
|
||||||
|
(defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS))
|
||||||
/* Start at the head of the mounts and search for our entry. Also
|
/* Start at the head of the mounts and search for our entry. Also
|
||||||
* count the number of entries that match our blkdriver.
|
* count the number of entries that match our blkdriver.
|
||||||
*/
|
*/
|
||||||
@@ -392,7 +402,7 @@ int smartfs_unmount(struct smartfs_mountpt_s *fs)
|
|||||||
* If found, the direntry will be populated with information
|
* If found, the direntry will be populated with information
|
||||||
* for accessing the entry.
|
* for accessing the entry.
|
||||||
*
|
*
|
||||||
* If the final directory segement of relpath just before the
|
* If the final directory segment of relpath just before the
|
||||||
* last segment (the target file/dir) is valid, then the
|
* last segment (the target file/dir) is valid, then the
|
||||||
* parentdirsector will indicate the logical sector number of
|
* parentdirsector will indicate the logical sector number of
|
||||||
* the parent directory where a new entry should be created,
|
* the parent directory where a new entry should be created,
|
||||||
@@ -582,7 +592,7 @@ int smartfs_finddirentry(struct smartfs_mountpt_s *fs,
|
|||||||
direntry->datlen = 0;
|
direntry->datlen = 0;
|
||||||
|
|
||||||
/* Scan the file's sectors to calculate the length and perform
|
/* Scan the file's sectors to calculate the length and perform
|
||||||
* a rudamentary check.
|
* a rudimentary check.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((entry->flags & SMARTFS_DIRENT_TYPE) == SMARTFS_DIRENT_TYPE_FILE)
|
if ((entry->flags & SMARTFS_DIRENT_TYPE) == SMARTFS_DIRENT_TYPE_FILE)
|
||||||
@@ -954,8 +964,8 @@ int smartfs_deleteentry(struct smartfs_mountpt_s *fs,
|
|||||||
|
|
||||||
* TODO: We really should walk the list backward to avoid lost
|
* TODO: We really should walk the list backward to avoid lost
|
||||||
* sectors in the event we lose power. However this requires
|
* sectors in the event we lose power. However this requires
|
||||||
* allocting a buffer to build the sector list since we don't
|
* allocating a buffer to build the sector list since we don't
|
||||||
* store a doubly-linked list of sectors on the deivce. We
|
* store a doubly-linked list of sectors on the device. We
|
||||||
* could test if the sector data buffer is big enough and
|
* could test if the sector data buffer is big enough and
|
||||||
* just use that, and only allocate a new buffer if the
|
* just use that, and only allocate a new buffer if the
|
||||||
* sector buffer isn't big enough. Do do this, however, we
|
* sector buffer isn't big enough. Do do this, however, we
|
||||||
@@ -1294,3 +1304,17 @@ int smartfs_truncatefile(struct smartfs_mountpt_s *fs,
|
|||||||
errout:
|
errout:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: smartfs_get_first_mount
|
||||||
|
*
|
||||||
|
* Description: Returns a pointer to the first mounted smartfs volume.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS)
|
||||||
|
struct smartfs_mountpt_s* smartfs_get_first_mount(void)
|
||||||
|
{
|
||||||
|
return g_mounthead;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* include/nuttx/fs/ioctl.h
|
* include/nuttx/fs/ioctl.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008, 2009, 2011-2013 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2008, 2009, 2011-2014 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -196,6 +196,13 @@
|
|||||||
* buffer address
|
* buffer address
|
||||||
* OUT: None (ioctl return value provides
|
* OUT: None (ioctl return value provides
|
||||||
* success/failure indication). */
|
* success/failure indication). */
|
||||||
|
#define BIOC_GETPROCFSD _BIOC(0x000A) /* Get ProcFS data specific to the
|
||||||
|
* block device.
|
||||||
|
* IN: Pointer to a struct defined for
|
||||||
|
* the block to load with it's
|
||||||
|
* ProcFS data.
|
||||||
|
* OUT: None (ioctl return value provides
|
||||||
|
* success/failure indication). */
|
||||||
|
|
||||||
/* NuttX MTD driver ioctl definitions ***************************************/
|
/* NuttX MTD driver ioctl definitions ***************************************/
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* include/nuttx/mtd/smart.h
|
||||||
|
* Memory Technology Device (MTD) SMART specific interfaces
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014 Ken Pettit. All rights reserved.
|
||||||
|
* Author: Ken Pettit <pettitkd@gmail.com>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __INCLUDE_NUTTX_MTD_SMART_H
|
||||||
|
#define __INCLUDE_NUTTX_MTD_SMART_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-Processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Structure to track SMART allocations for debugging */
|
||||||
|
|
||||||
|
#ifdef CONFIG_MTD_SMART_ALLOC_DEBUG
|
||||||
|
struct smart_alloc_s
|
||||||
|
{
|
||||||
|
size_t size; /* Size of the allocation */
|
||||||
|
void* ptr; /* Pointer to the data */
|
||||||
|
const char* name; /* Name of the allocation */
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* The following defines the procfs data passed from the SMART MTD layer
|
||||||
|
* from a BIOC_GETPROCFSD ioctl command.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct mtd_smart_procfs_data_s
|
||||||
|
{
|
||||||
|
uint16_t totalsectors; /* Total number of sectors on device */
|
||||||
|
uint16_t sectorsize; /* Size of each sector */
|
||||||
|
uint16_t freesectors; /* Number of free sectors */
|
||||||
|
uint16_t releasesectors; /* Number of released sectors */
|
||||||
|
uint16_t sectorsperblk; /* Number of sectors per erase block */
|
||||||
|
uint16_t formatsector; /* Physical sector number for sector 0 */
|
||||||
|
uint16_t dirsector; /* Physical sector number for sector 1 */
|
||||||
|
uint8_t namelen; /* Length of names on the volume */
|
||||||
|
uint8_t formatversion; /* Version of the volume format */
|
||||||
|
uint32_t unusedsectors; /* Number of unused sectors (free when erased) */
|
||||||
|
uint32_t blockerases; /* Number block erase operations */
|
||||||
|
|
||||||
|
#ifdef CONFIG_MTD_SMART_SECTOR_ERASE_DEBUG
|
||||||
|
FAR const uint8_t* erasecounts; /* Array of erase counts per erase block */
|
||||||
|
size_t neraseblocks; /* Number of erase blocks */
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_MTD_SMART_ALLOC_DEBUG
|
||||||
|
FAR const struct smart_alloc_s *allocs; /* Array of allocations */
|
||||||
|
uint16_t alloccount; /* Number of items in the array */
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#endif /* __INCLUDE_NUTTX_MTD_SMART_H */
|
||||||
Reference in New Issue
Block a user