apps/nshlib/nsh_fscmds.c: The NSH mkrd command was in violation of the NuttX portable POSIX interface. it was calling the internal OS function ramdisk_register() directly. No only is this a violation of the interface specification, but also prevents use of mkrd in PROTECTED or KERNEL buils.
With this commit, the NSH mkrd command now used the BOARDIOC_MKRD boardctl() command. This command is availabe in all build modes. The effect of this change is to move the hear of the NSH mkrd command into to OS and provide user-space access via boardctl().
This commit is contained in:
parent
3e4db5cb40
commit
c8a066f699
@ -1494,10 +1494,9 @@ Command Dependencies on Configuration Settings
|
||||
2. Special TFTP server start-up options will probably be required to permit
|
||||
creation of file for the correct operation of the put command.
|
||||
3. CONFIG_FS_READABLE is not a user configuration but is set automatically
|
||||
if any readable file system is selected. At present, this is either CONFIG_FS_FAT
|
||||
and CONFIG_FS_ROMFS.
|
||||
if any readable file system is selected.
|
||||
4. CONFIG_FS_WRITABLE is not a user configuration but is set automatically
|
||||
if any writeable file system is selected. At present, this is only CONFIG_FS_FAT.
|
||||
if any writable file system is selected.
|
||||
|
||||
In addition, each NSH command can be individually disabled via one of the following
|
||||
settings. All of these settings make the configuration of NSH potentially complex but
|
||||
|
20
nshlib/nsh.h
20
nshlib/nsh.h
@ -546,26 +546,6 @@
|
||||
# define IOBUFFERSIZE (PATH_MAX + 1)
|
||||
#endif
|
||||
|
||||
/* Certain commands are not available in a kernel builds because they depend
|
||||
* on interfaces that are not exported by the kernel. These are actually
|
||||
* bugs that need to be fixed but for now the commands are simply disabled.
|
||||
* There are three classes of fixes required:
|
||||
*
|
||||
* - Some of these interfaces are inherently internal to the OS (such as
|
||||
* register_ramdisk()) and should never be made available to user
|
||||
* applications as OS interfaces.
|
||||
* - Other interfaces are more standard and for these there probably should
|
||||
* be new system calls to support the OS interface. Such interfaces
|
||||
* include things like mkrd.
|
||||
* - Other interfaces simply need to be moved out of the OS and into the C
|
||||
* library where they will become accessible to application code.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)
|
||||
# undef CONFIG_NSH_DISABLE_MKRD /* 'mkrd' depends on ramdisk_register */
|
||||
# define CONFIG_NSH_DISABLE_MKRD 1
|
||||
#endif
|
||||
|
||||
/* Certain commands/features are only available if the procfs file system is
|
||||
* enabled.
|
||||
*/
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* apps/nshlib/nsh_fscmds.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011-2014, 2017-2018 Gregory Nutt. All rights
|
||||
* Copyright (C) 2007-2009, 2011-2014, 2017-2019 Gregory Nutt. All rights
|
||||
* reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
@ -45,10 +45,22 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
#include <libgen.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT)
|
||||
# ifdef CONFIG_FS_READABLE /* Need at least one filesytem in configuration */
|
||||
# include <sys/mount.h>
|
||||
# include <sys/boardctl.h>
|
||||
# include <nuttx/drivers/ramdisk.h>
|
||||
# endif
|
||||
# ifdef CONFIG_DEV_LOOP
|
||||
@ -72,16 +84,6 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
#include <libgen.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#ifdef CONFIG_FSUTILS_MKFATFS
|
||||
# include "fsutils/mkfatfs.h"
|
||||
#endif
|
||||
@ -1348,8 +1350,8 @@ int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
#ifndef CONFIG_NSH_DISABLE_MKRD
|
||||
int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
const char *fmt;
|
||||
FAR uint8_t *buffer;
|
||||
FAR const char *fmt;
|
||||
struct boardioc_mkrd_s desc;
|
||||
uint32_t nsectors;
|
||||
bool badarg = false;
|
||||
int sectsize = 512;
|
||||
@ -1418,28 +1420,17 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
goto errout_with_fmt;
|
||||
}
|
||||
|
||||
/* Allocate the memory backing up the ramdisk */
|
||||
/* Then create the ramdisk */
|
||||
|
||||
buffer = (FAR uint8_t *)malloc(sectsize * nsectors);
|
||||
if (!buffer)
|
||||
{
|
||||
fmt = g_fmtcmdoutofmemory;
|
||||
goto errout_with_fmt;
|
||||
}
|
||||
desc.minor = minor; /* Minor device number of the RAM disk. */
|
||||
desc.nsectors = nsectors; /* The number of sectors in the RAM disk. */
|
||||
desc.sectsize = sectsize; /* The size of one sector in bytes. */
|
||||
desc.rdflags = RDFLAG_WRENABLED | RDFLAG_FUNLINK; /* See ramdisk.h. */
|
||||
|
||||
#ifdef CONFIG_DEBUG_INFO
|
||||
memset(buffer, 0, sectsize * nsectors);
|
||||
#endif
|
||||
finfo("RAMDISK at %p\n", buffer);
|
||||
|
||||
/* Then register the ramdisk */
|
||||
|
||||
ret = ramdisk_register(minor, buffer, nsectors, sectsize,
|
||||
RDFLAG_WRENABLED | RDFLAG_FUNLINK);
|
||||
ret = boardctl(BOARDIOC_MKRD, (uintptr_t)&desc);
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "ramdisk_register", NSH_ERRNO_OF(-ret));
|
||||
free(buffer);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user