From ad48d89fe2fbb37d0dfe8163a5ad84bf0a2c3e68 Mon Sep 17 00:00:00 2001 From: Ken Pettit Date: Mon, 23 Nov 2015 06:59:56 -0600 Subject: [PATCH] mksmartfs: Move into apps/fsutils from kernel, now uses only open and ioctl. Add configuration option to supported multiple root directories. From Ken Petit --- fsutils/Kconfig | 10 ++ fsutils/Make.defs | 37 +++++++ fsutils/Makefile | 36 +++++++ fsutils/mksmartfs/.gitignore | 11 ++ fsutils/mksmartfs/Kconfig | 12 +++ fsutils/mksmartfs/Make.defs | 38 +++++++ fsutils/mksmartfs/Makefile | 104 ++++++++++++++++++ fsutils/mksmartfs/mksmartfs.c | 194 ++++++++++++++++++++++++++++++++++ include/fsutils/mksmartfs.h | 111 +++++++++++++++++++ nshlib/Kconfig | 6 ++ nshlib/nsh.h | 9 +- nshlib/nsh_command.c | 13 +-- nshlib/nsh_fscmds.c | 48 +++++++-- 13 files changed, 615 insertions(+), 14 deletions(-) create mode 100644 fsutils/Kconfig create mode 100644 fsutils/Make.defs create mode 100644 fsutils/Makefile create mode 100644 fsutils/mksmartfs/.gitignore create mode 100644 fsutils/mksmartfs/Kconfig create mode 100644 fsutils/mksmartfs/Make.defs create mode 100644 fsutils/mksmartfs/Makefile create mode 100644 fsutils/mksmartfs/mksmartfs.c create mode 100644 include/fsutils/mksmartfs.h diff --git a/fsutils/Kconfig b/fsutils/Kconfig new file mode 100644 index 000000000..e0fcb8d56 --- /dev/null +++ b/fsutils/Kconfig @@ -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 diff --git a/fsutils/Make.defs b/fsutils/Make.defs new file mode 100644 index 000000000..4e5a68db5 --- /dev/null +++ b/fsutils/Make.defs @@ -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 +# +# 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) diff --git a/fsutils/Makefile b/fsutils/Makefile new file mode 100644 index 000000000..55351c3f3 --- /dev/null +++ b/fsutils/Makefile @@ -0,0 +1,36 @@ +############################################################################ +# apps/fsutils/Makefile +# +# Copyright (C) 2011-2015 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. +# +############################################################################ + +include $(APPDIR)/Directory.mk diff --git a/fsutils/mksmartfs/.gitignore b/fsutils/mksmartfs/.gitignore new file mode 100644 index 000000000..83bd7b811 --- /dev/null +++ b/fsutils/mksmartfs/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src +/*.obj diff --git a/fsutils/mksmartfs/Kconfig b/fsutils/mksmartfs/Kconfig new file mode 100644 index 000000000..1b902125f --- /dev/null +++ b/fsutils/mksmartfs/Kconfig @@ -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 + diff --git a/fsutils/mksmartfs/Make.defs b/fsutils/mksmartfs/Make.defs new file mode 100644 index 000000000..f2275af8d --- /dev/null +++ b/fsutils/mksmartfs/Make.defs @@ -0,0 +1,38 @@ +############################################################################ +# apps/fsutils/mksmartfs/Make.defs +# +# Copyright (C) 2015 Ken Pettit +# Author: Ken Pettit +# +# 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 diff --git a/fsutils/mksmartfs/Makefile b/fsutils/mksmartfs/Makefile new file mode 100644 index 000000000..9e4d06588 --- /dev/null +++ b/fsutils/mksmartfs/Makefile @@ -0,0 +1,104 @@ +############################################################################ +# apps/fsutils/mksmartfs/Makefile +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Modified by Ken Pettit 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 diff --git a/fsutils/mksmartfs/mksmartfs.c b/fsutils/mksmartfs/mksmartfs.c new file mode 100644 index 000000000..de9488dfd --- /dev/null +++ b/fsutils/mksmartfs/mksmartfs.c @@ -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 + * + * 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 + +#if CONFIG_NFILE_DESCRIPTORS > 0 +# include +# include +# include +#include +# if !defined(CONFIG_DISABLE_MOUNTPOINT) +# ifdef CONFIG_FS_SMARTFS +# include +# include +# include +# endif +#endif +#endif + +# include + +/**************************************************************************** + * 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; +} + diff --git a/include/fsutils/mksmartfs.h b/include/fsutils/mksmartfs.h new file mode 100644 index 000000000..7e58a72bb --- /dev/null +++ b/include/fsutils/mksmartfs.h @@ -0,0 +1,111 @@ +/**************************************************************************** + * apps/include/fsutils/mksmartfs.h + * + * Copyright (C) 2015 Ken Pettit. All rights reserved. + * Author: Ken Pettit + * + * 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 +#include + +/**************************************************************************** + * 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 */ diff --git a/nshlib/Kconfig b/nshlib/Kconfig index 3ae39f098..916d77cc0 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -280,6 +280,12 @@ config NSH_DISABLE_MKRD default y 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 bool "Disable mh" default n diff --git a/nshlib/nsh.h b/nshlib/nsh.h index 3da4a8860..1b9656d90 100644 --- a/nshlib/nsh.h +++ b/nshlib/nsh.h @@ -189,6 +189,13 @@ # define CONFIG_NSH_DISABLE_WGET 1 #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 */ #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); # endif # endif /* CONFIG_FS_FAT */ -# ifdef CONFIG_FS_SMARTFS +#if defined(CONFIG_FS_SMARTFS) && defined(CONFIG_FSUTILS_MKSMARTFS) # ifndef CONFIG_NSH_DISABLE_MKSMARTFS int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index 855ebb09d..a7a00c028 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -280,13 +280,14 @@ static const struct cmdmap_s g_cmdmap[] = # 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 -#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - { "mksmartfs", cmd_mksmartfs, 2, 3, " []" }, -#else - { "mksmartfs", cmd_mksmartfs, 2, 2, "" }, -#endif +# ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS + { "mksmartfs", cmd_mksmartfs, 2, 5, "[-s sector-size] []" }, +# else + { "mksmartfs", cmd_mksmartfs, 2, 4, "[-s sector-size] " }, +# endif # endif #endif diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c index ea8578bb5..d3a9845c6 100644 --- a/nshlib/nsh_fscmds.c +++ b/nshlib/nsh_fscmds.c @@ -55,7 +55,7 @@ # include # endif # ifdef CONFIG_FS_SMARTFS -# include +# include # endif # ifdef CONFIG_NFS # include @@ -1279,24 +1279,58 @@ errout_with_fmt: ****************************************************************************/ #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 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; + uint16_t sectorsize = 0; + int opt; #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS int nrootdirs = 1; #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) { /* Test if number of root directories was supplied */ #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) @@ -1307,9 +1341,9 @@ int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #endif { #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - ret = mksmartfs(fullpath, nrootdirs); + ret = mksmartfs(fullpath, sectorsize, nrootdirs); #else - ret = mksmartfs(fullpath); + ret = mksmartfs(fullpath, sectorsize); #endif if (ret < 0) {