mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-21 14:42:20 +08:00
mksmartfs: Move into apps/fsutils from kernel, now uses only open and ioctl. Add configuration option to supported multiple root directories. From Ken Petit
This commit is contained in:
10
fsutils/Kconfig
Normal file
10
fsutils/Kconfig
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#
|
||||||
|
# For a description of the syntax of this configuration file,
|
||||||
|
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||||
|
#
|
||||||
|
|
||||||
|
menu "File System Utilities"
|
||||||
|
|
||||||
|
source "$APPSDIR/fsutils/mksmartfs/Kconfig"
|
||||||
|
|
||||||
|
endmenu # FS Utilities
|
37
fsutils/Make.defs
Normal file
37
fsutils/Make.defs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/fsutils/Make.defs
|
||||||
|
# Adds selected applications to apps/ build
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 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.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
include $(wildcard fsutils/*/Make.defs)
|
36
fsutils/Makefile
Normal file
36
fsutils/Makefile
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/fsutils/Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011-2015 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
include $(APPDIR)/Directory.mk
|
11
fsutils/mksmartfs/.gitignore
vendored
Normal file
11
fsutils/mksmartfs/.gitignore
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/Make.dep
|
||||||
|
/.depend
|
||||||
|
/.built
|
||||||
|
/*.asm
|
||||||
|
/*.rel
|
||||||
|
/*.lst
|
||||||
|
/*.sym
|
||||||
|
/*.adb
|
||||||
|
/*.lib
|
||||||
|
/*.src
|
||||||
|
/*.obj
|
12
fsutils/mksmartfs/Kconfig
Normal file
12
fsutils/mksmartfs/Kconfig
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#
|
||||||
|
# For a description of the syntax of this configuration file,
|
||||||
|
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||||
|
#
|
||||||
|
|
||||||
|
config FSUTILS_MKSMARTFS
|
||||||
|
bool "mksmartfs utility"
|
||||||
|
default y
|
||||||
|
depends on FS_SMARTFS && !DISABLE_PSEUDOFS_OPERATIONS
|
||||||
|
---help---
|
||||||
|
Enables support for the mksmartfs utility
|
||||||
|
|
38
fsutils/mksmartfs/Make.defs
Normal file
38
fsutils/mksmartfs/Make.defs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/fsutils/mksmartfs/Make.defs
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 Ken Pettit
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_FSUTILS_MKSMARTFS),y)
|
||||||
|
CONFIGURED_APPS += fsutils/mksmartfs
|
||||||
|
endif
|
104
fsutils/mksmartfs/Makefile
Normal file
104
fsutils/mksmartfs/Makefile
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/fsutils/mksmartfs/Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
#
|
||||||
|
# Modified by Ken Pettit <pettitkd@gmail.com> for mksmartfs usage.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
-include $(TOPDIR)/.config
|
||||||
|
-include $(TOPDIR)/Make.defs
|
||||||
|
include $(APPDIR)/Make.defs
|
||||||
|
|
||||||
|
# Web client library
|
||||||
|
|
||||||
|
ASRCS =
|
||||||
|
CSRCS =
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_FSUTILS_MKSMARTFS),y)
|
||||||
|
CSRCS = mksmartfs.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||||
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||||
|
|
||||||
|
SRCS = $(ASRCS) $(CSRCS)
|
||||||
|
OBJS = $(AOBJS) $(COBJS)
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||||
|
BIN = ..\..\libapps$(LIBEXT)
|
||||||
|
else
|
||||||
|
ifeq ($(WINTOOL),y)
|
||||||
|
BIN = ..\\..\\libapps$(LIBEXT)
|
||||||
|
else
|
||||||
|
BIN = ../../libapps$(LIBEXT)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ROOTDEPPATH = --dep-path .
|
||||||
|
|
||||||
|
# Common build
|
||||||
|
|
||||||
|
VPATH =
|
||||||
|
|
||||||
|
all: .built
|
||||||
|
.PHONY: context depend clean distclean
|
||||||
|
|
||||||
|
$(AOBJS): %$(OBJEXT): %.S
|
||||||
|
$(call ASSEMBLE, $<, $@)
|
||||||
|
|
||||||
|
$(COBJS): %$(OBJEXT): %.c
|
||||||
|
$(call COMPILE, $<, $@)
|
||||||
|
|
||||||
|
.built: $(OBJS)
|
||||||
|
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||||
|
$(Q) touch .built
|
||||||
|
|
||||||
|
install:
|
||||||
|
|
||||||
|
context:
|
||||||
|
|
||||||
|
.depend: Makefile $(SRCS)
|
||||||
|
$(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||||
|
$(Q) touch $@
|
||||||
|
|
||||||
|
depend: .depend
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(call DELFILE, .built)
|
||||||
|
$(call CLEAN)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
$(call DELFILE, Make.dep)
|
||||||
|
$(call DELFILE, .depend)
|
||||||
|
|
||||||
|
-include Make.dep
|
194
fsutils/mksmartfs/mksmartfs.c
Normal file
194
fsutils/mksmartfs/mksmartfs.c
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/fsutils/mksmartfs/mksmartfs.c
|
||||||
|
* Implementation of the SMARTFS mksmartfs utility
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015, 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. The name of the author may not be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <nuttx/config.h>
|
||||||
|
|
||||||
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
|
# include <sys/stat.h>
|
||||||
|
# include <sys/ioctl.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
# if !defined(CONFIG_DISABLE_MOUNTPOINT)
|
||||||
|
# ifdef CONFIG_FS_SMARTFS
|
||||||
|
# include <apps/fsutils/mksmartfs.h>
|
||||||
|
# include <nuttx/fs/ioctl.h>
|
||||||
|
# include <nuttx/fs/smart.h>
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
# include <unistd.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mksmartfs
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Make a SMART Flash file system image on the specified block device
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* pathname - the full path to a registered block driver
|
||||||
|
* sectorsize - the size of logical sectors on the device from 256-16384.
|
||||||
|
* Setting this to zero will cause the device to be formatted
|
||||||
|
* using the default CONFIG_MTD_SMART_SECTOR_SIZE value.
|
||||||
|
* nrootdirs - Number of root directory entries to create.
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* Zero (OK) on success; -1 (ERROR) on failure with errno set appropriately:
|
||||||
|
*
|
||||||
|
* EINVAL - NULL block driver string, bad number of FATS in 'fmt', bad FAT
|
||||||
|
* size in 'fmt', bad cluster size in 'fmt'
|
||||||
|
* ENOENT - 'pathname' does not refer to anything in the filesystem.
|
||||||
|
* ENOTBLK - 'pathname' does not refer to a block driver
|
||||||
|
* EACCES - block driver does not support wrie or geometry methods
|
||||||
|
*
|
||||||
|
* Assumptions:
|
||||||
|
* - The caller must assure that the block driver is not mounted and not in
|
||||||
|
* use when this function is called. The result of formatting a mounted
|
||||||
|
* device is indeterminate (but likely not good).
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
||||||
|
int mksmartfs(FAR const char *pathname, uint16_t sectorsize, uint8_t nrootdirs)
|
||||||
|
#else
|
||||||
|
int mksmartfs(FAR const char *pathname, uint16_t sectorsize)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
struct smart_format_s fmt;
|
||||||
|
int ret, fd;
|
||||||
|
int x;
|
||||||
|
uint8_t type;
|
||||||
|
struct smart_read_write_s request;
|
||||||
|
|
||||||
|
/* Find the inode of the block driver indentified by 'source' */
|
||||||
|
|
||||||
|
fd = open(pathname, O_RDWR);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Perform a low-level SMART format */
|
||||||
|
|
||||||
|
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
||||||
|
ret = ioctl(fd, BIOC_LLFORMAT, (sectorsize << 16) | nrootdirs);
|
||||||
|
#else
|
||||||
|
ret = ioctl(fd, BIOC_LLFORMAT, sectorsize << 16);
|
||||||
|
#endif
|
||||||
|
if (ret != OK)
|
||||||
|
{
|
||||||
|
goto errout_with_driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the format information so we know how big the sectors are */
|
||||||
|
|
||||||
|
ret = ioctl(fd, BIOC_GETFORMAT, (unsigned long) &fmt);
|
||||||
|
|
||||||
|
/* Now Write the filesystem to media. Loop for each root dir entry and
|
||||||
|
* allocate the reserved Root Dir Enty, then write a blank root dir for it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
type = SMARTFS_SECTOR_TYPE_DIR;
|
||||||
|
request.offset = 0;
|
||||||
|
request.count = 1;
|
||||||
|
request.buffer = &type;
|
||||||
|
x = 0;
|
||||||
|
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
||||||
|
for (; x < nrootdirs; x++)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
ret = ioctl(fd, BIOC_ALLOCSECT, SMARTFS_ROOT_DIR_SECTOR + x);
|
||||||
|
if (ret != SMARTFS_ROOT_DIR_SECTOR + x)
|
||||||
|
{
|
||||||
|
ret = -EIO;
|
||||||
|
goto errout_with_driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mark this block as a directory entry */
|
||||||
|
|
||||||
|
request.logsector = SMARTFS_ROOT_DIR_SECTOR + x;
|
||||||
|
|
||||||
|
/* Issue a write to the sector, single byte */
|
||||||
|
|
||||||
|
ret = ioctl(fd, BIOC_WRITESECT, (unsigned long) &request);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
ret = -EIO;
|
||||||
|
goto errout_with_driver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
errout_with_driver:
|
||||||
|
/* Close the driver */
|
||||||
|
|
||||||
|
(void)close(fd);
|
||||||
|
|
||||||
|
errout:
|
||||||
|
/* Release all allocated memory */
|
||||||
|
|
||||||
|
/* Return any reported errors */
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
set_errno(-ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
111
include/fsutils/mksmartfs.h
Normal file
111
include/fsutils/mksmartfs.h
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/include/fsutils/mksmartfs.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 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_APPS_INCLUDE_FSUTILS_MKSMARTFS_H
|
||||||
|
#define __INCLUDE_APPS_INCLUDE_FSUTILS_MKSMARTFS_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Variables
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mksmartfs
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Make a SMART (Sector Mapped Allocation for Really Tiny) Flash file
|
||||||
|
* system image on the specified block device (must be a SMART device).
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* pathname - the full path to a registered block driver
|
||||||
|
* nrootdirs - the number of Root Directory entries to support
|
||||||
|
* on this device (supports multiple mount points).
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* Zero (OK) on success; -1 (ERROR) on failure with errno set appropriately:
|
||||||
|
*
|
||||||
|
* EINVAL - NULL block driver string
|
||||||
|
* ENOENT - 'pathname' does not refer to anything in the filesystem.
|
||||||
|
* ENOTBLK - 'pathname' does not refer to a block driver
|
||||||
|
* EACCESS - block driver does not support write or geometry methods or
|
||||||
|
* is not a SMART device
|
||||||
|
*
|
||||||
|
* Assumptions:
|
||||||
|
* - The caller must assure that the block driver is not mounted and not in
|
||||||
|
* use when this function is called. The result of formatting a mounted
|
||||||
|
* device is indeterminate (but likely not good).
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
||||||
|
int mksmartfs(FAR const char *pathname, uint16_t sectorsize,
|
||||||
|
uint8_t nrootdirs);
|
||||||
|
#else
|
||||||
|
int mksmartfs(FAR const char *pathname, uint16_t sectorsize);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __INCLUDE_APPS_INCLUDE_FSUTILS_MKSMARTFS_H */
|
@@ -280,6 +280,12 @@ config NSH_DISABLE_MKRD
|
|||||||
default y if DEFAULT_SMALL
|
default y if DEFAULT_SMALL
|
||||||
default n if !DEFAULT_SMALL
|
default n if !DEFAULT_SMALL
|
||||||
|
|
||||||
|
config NSH_DISABLE_MKSMARTFS
|
||||||
|
bool "Disable mksmartfs"
|
||||||
|
default y if DEFAULT_SMALL
|
||||||
|
default n if !DEFAULT_SMALL
|
||||||
|
depends on FS_SMARTFS && FSUTILS_MKSMARTFS
|
||||||
|
|
||||||
config NSH_DISABLE_MH
|
config NSH_DISABLE_MH
|
||||||
bool "Disable mh"
|
bool "Disable mh"
|
||||||
default n
|
default n
|
||||||
|
@@ -189,6 +189,13 @@
|
|||||||
# define CONFIG_NSH_DISABLE_WGET 1
|
# define CONFIG_NSH_DISABLE_WGET 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* mksmartfs depends on smartfs and mksmartfs support */
|
||||||
|
|
||||||
|
#if !defined(CONFIG_FS_SMARTFS) || !defined(CONFIG_FSUTILS_MKSMARTFS)
|
||||||
|
# undef CONFIG_NSH_DISABLE_MKSMARTFS
|
||||||
|
# define CONFIG_NSH_DISABLE_MKSMARTFS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
/* One front end must be defined */
|
/* One front end must be defined */
|
||||||
|
|
||||||
#if !defined(CONFIG_NSH_CONSOLE) && !defined(CONFIG_NSH_TELNET)
|
#if !defined(CONFIG_NSH_CONSOLE) && !defined(CONFIG_NSH_TELNET)
|
||||||
@@ -922,7 +929,7 @@ void nsh_usbtrace(void);
|
|||||||
int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||||
# endif
|
# endif
|
||||||
# endif /* CONFIG_FS_FAT */
|
# endif /* CONFIG_FS_FAT */
|
||||||
# ifdef CONFIG_FS_SMARTFS
|
#if defined(CONFIG_FS_SMARTFS) && defined(CONFIG_FSUTILS_MKSMARTFS)
|
||||||
# ifndef CONFIG_NSH_DISABLE_MKSMARTFS
|
# ifndef CONFIG_NSH_DISABLE_MKSMARTFS
|
||||||
int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||||
# endif
|
# endif
|
||||||
|
@@ -280,13 +280,14 @@ static const struct cmdmap_s g_cmdmap[] =
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_SMARTFS)
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \
|
||||||
|
defined(CONFIG_FS_SMARTFS) && defined(CONFIG_FSUTILS_MKSMARTFS)
|
||||||
# ifndef CONFIG_NSH_DISABLE_MKSMARTFS
|
# ifndef CONFIG_NSH_DISABLE_MKSMARTFS
|
||||||
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
# ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
||||||
{ "mksmartfs", cmd_mksmartfs, 2, 3, "<path> [<num-root-directories>]" },
|
{ "mksmartfs", cmd_mksmartfs, 2, 5, "[-s sector-size] <path> [<num-root-directories>]" },
|
||||||
#else
|
# else
|
||||||
{ "mksmartfs", cmd_mksmartfs, 2, 2, "<path>" },
|
{ "mksmartfs", cmd_mksmartfs, 2, 4, "[-s sector-size] <path>" },
|
||||||
#endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -55,7 +55,7 @@
|
|||||||
# include <nuttx/fs/mkfatfs.h>
|
# include <nuttx/fs/mkfatfs.h>
|
||||||
# endif
|
# endif
|
||||||
# ifdef CONFIG_FS_SMARTFS
|
# ifdef CONFIG_FS_SMARTFS
|
||||||
# include <nuttx/fs/mksmartfs.h>
|
# include <apps/fsutils/mksmartfs.h>
|
||||||
# endif
|
# endif
|
||||||
# ifdef CONFIG_NFS
|
# ifdef CONFIG_NFS
|
||||||
# include <sys/socket.h>
|
# include <sys/socket.h>
|
||||||
@@ -1279,24 +1279,58 @@ errout_with_fmt:
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \
|
||||||
defined(CONFIG_FS_SMARTFS)
|
defined(CONFIG_FS_SMARTFS) && defined(CONFIG_FSUTILS_MKSMARTFS)
|
||||||
#ifndef CONFIG_NSH_DISABLE_MKSMARTFS
|
#ifndef CONFIG_NSH_DISABLE_MKSMARTFS
|
||||||
int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *fullpath = nsh_getfullpath(vtbl, argv[1]);
|
char *fullpath = NULL;
|
||||||
int ret = ERROR;
|
int ret = ERROR;
|
||||||
|
uint16_t sectorsize = 0;
|
||||||
|
int opt;
|
||||||
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
||||||
int nrootdirs = 1;
|
int nrootdirs = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Process any options */
|
||||||
|
|
||||||
|
optind = 0;
|
||||||
|
while ((opt = getopt(argc, argv, "s:")) != -1)
|
||||||
|
{
|
||||||
|
switch (opt)
|
||||||
|
{
|
||||||
|
case 's':
|
||||||
|
sectorsize = atoi(optarg);
|
||||||
|
if (sectorsize < 256 || sectorsize > 16384)
|
||||||
|
{
|
||||||
|
nsh_output(vtbl, "Sector size must be 256-16384\n");
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
if (sectorsize & (sectorsize-1))
|
||||||
|
{
|
||||||
|
nsh_output(vtbl, "Sector size must be power of 2\n");
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optind < argc)
|
||||||
|
{
|
||||||
|
fullpath = nsh_getfullpath(vtbl, argv[optind]);
|
||||||
|
}
|
||||||
|
|
||||||
if (fullpath)
|
if (fullpath)
|
||||||
{
|
{
|
||||||
/* Test if number of root directories was supplied */
|
/* Test if number of root directories was supplied */
|
||||||
|
|
||||||
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
||||||
if (argc == 3)
|
if (optind + 1 < argc)
|
||||||
{
|
{
|
||||||
nrootdirs = atoi(argv[2]);
|
nrootdirs = atoi(argv[optind + 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nrootdirs > 8 || nrootdirs < 1)
|
if (nrootdirs > 8 || nrootdirs < 1)
|
||||||
@@ -1307,9 +1341,9 @@ int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
||||||
ret = mksmartfs(fullpath, nrootdirs);
|
ret = mksmartfs(fullpath, sectorsize, nrootdirs);
|
||||||
#else
|
#else
|
||||||
ret = mksmartfs(fullpath);
|
ret = mksmartfs(fullpath, sectorsize);
|
||||||
#endif
|
#endif
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user