This commit corrects a problem with NSH: NSH was calling the OS internal function ramdisk_register() in violation of the portable POSIX interface. This commit solves the problem by introducing a new boardctl() function BOARDIOC_MKRD which moves the RAM disk creation into the OS.

Squashed commit of the following:

    drivers/:  Run tools/nxstyle against all drivers/*.c.

    boards/boardctl.c:  Add new boardctl() command, BOARDIOC_MKRD, that can be used to create a RAM disk.  This will replace the illegal call to ramdisk_register() currently used by NSH.

    drivers/mkrd.c:  Add wrapper around ramdisk_register() for creating a proper ramdisk.
This commit is contained in:
Gregory Nutt 2019-10-26 09:35:32 -06:00
parent dae3640dc5
commit be325924fb
7 changed files with 96 additions and 18 deletions

View File

@ -49,6 +49,10 @@
#include <nuttx/lib/modlib.h>
#include <nuttx/binfmt/symtab.h>
#ifdef CONFIG_FS_WRITABLE
# include <nuttx/drivers/ramdisk.h>
#endif
#ifdef CONFIG_NX
# include <nuttx/nx/nxmu.h>
#endif
@ -354,6 +358,32 @@ int boardctl(unsigned int cmd, uintptr_t arg)
break;
#endif
#ifdef CONFIG_FS_WRITABLE
/* CMD: BOARDIOC_MKRD
* DESCRIPTION: Create a RAM disk
* ARG: Pointer to read-only instance of struct boardioc_mkrd_s.
* CONFIGURATION: CONFIG_FS_WRITABLE
* DEPENDENCIES: None
*/
case BOARDIOC_MKRD:
{
FAR const struct boardioc_mkrd_s *desc =
(FAR const struct boardioc_mkrd_s *)arg;
if (desc == NULL)
{
ret = -EINVAL;
}
else
{
ret = mkrd((int)desc->minor, desc->nsectors, desc->sectsize,
desc->rdflags);
}
}
break;
#endif
#ifdef CONFIG_BOARDCTL_APP_SYMTAB
/* CMD: BOARDIOC_APP_SYMTAB
* DESCRIPTION: Select the application symbol table. This symbol table

View File

@ -90,7 +90,7 @@ endif
CSRCS += dev_null.c dev_zero.c
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
CSRCS += ramdisk.c
CSRCS += ramdisk.c mkrd.c
ifeq ($(CONFIG_DRVR_WRITEBUFFER),y)
CSRCS += rwbuffer.c
else

View File

@ -86,7 +86,8 @@ static const struct file_operations devnull_fops =
* Name: devnull_read
****************************************************************************/
static ssize_t devnull_read(FAR struct file *filep, FAR char *buffer, size_t len)
static ssize_t devnull_read(FAR struct file *filep, FAR char *buffer,
size_t len)
{
return 0; /* Return EOF */
}
@ -95,7 +96,8 @@ static ssize_t devnull_read(FAR struct file *filep, FAR char *buffer, size_t len
* Name: devnull_write
****************************************************************************/
static ssize_t devnull_write(FAR struct file *filep, FAR const char *buffer, size_t len)
static ssize_t devnull_write(FAR struct file *filep, FAR const char *buffer,
size_t len)
{
return len; /* Say that everything was written */
}

View File

@ -118,6 +118,7 @@ static int devzero_poll(FAR struct file *filep, FAR struct pollfd *fds,
nxsem_post(fds->sem);
}
}
return OK;
}

View File

@ -185,7 +185,6 @@ static void rwb_wrflush(struct rwbuffer_s *rwb)
rwb_resetwrbuffer(rwb);
}
}
#endif
@ -933,12 +932,13 @@ ssize_t rwb_read(FAR struct rwbuffer_s *rwb, off_t startblock,
ret = rwb_read_(rwb, startblock, nblocks, rdbuffer);
if (ret < 0)
return ret;
{
return ret;
}
return readblocks + ret;
}
/****************************************************************************
* Name: rwb_write
****************************************************************************/

View File

@ -48,6 +48,7 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Values for rdflags */
#define RDFLAG_WRENABLED (1 << 0) /* Bit 0: 1=Can write to RAM disk */
@ -93,11 +94,36 @@ extern "C"
#ifdef CONFIG_FS_WRITABLE
int ramdisk_register(int minor, FAR uint8_t *buffer, uint32_t nsectors,
uint16_t sectize, uint8_t rdflags);
uint16_t sectsize, uint8_t rdflags);
#define romdisk_register(m,b,n,s) ramdisk_register(m,(FAR uint8_t *)b,n,s,0)
#else
int romdisk_register(int minor, FAR const uint8_t *buffer, uint32_t nsectors,
uint16_t sectize);
uint16_t sectsize);
#endif
/****************************************************************************
* Name: mkrd
*
* Description:
* This is a wrapper function around ramdisk_register. It combines the
* necessary operations to create a RAM disk into a single callable
* function. Memory for the RAM disk is allocated, appropriated, from
* the kernel heap (in build modes where there is a distinct kernel heap).
*
* Input Parameters:
* minor: Selects suffix of device named /dev/ramN, N={1,2,3...}
* nsectors: Number of sectors on device
* sectize: The size of one sector
* rdflags: See RDFLAG_* definitions. Typically
* RDFLAG_WRENABLED | RDFLAG_FUNLINK
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_FS_WRITABLE
int mkrd(int minor, uint32_t nsectors, uint16_t sectsize, uint8_t rdflags);
#endif
#undef EXTERN

View File

@ -96,6 +96,12 @@
* which to receive the board unique ID.
* DEPENDENCIES: Board logic must provide the board_uniqueid() interface.
*
* CMD: BOARDIOC_MKRD
* DESCRIPTION: Create a RAM disk
* ARG: Pointer to read-only instance of struct boardioc_mkrd_s.
* CONFIGURATION: CONFIG_FS_WRITABLE
* DEPENDENCIES: None
*
* CMD: BOARDIOC_APP_SYMTAB
* DESCRIPTION: Select the application symbol table. This symbol table
* provides the symbol definitions exported to application
@ -181,15 +187,16 @@
#define BOARDIOC_POWEROFF _BOARDIOC(0x0003)
#define BOARDIOC_RESET _BOARDIOC(0x0004)
#define BOARDIOC_UNIQUEID _BOARDIOC(0x0005)
#define BOARDIOC_APP_SYMTAB _BOARDIOC(0x0006)
#define BOARDIOC_OS_SYMTAB _BOARDIOC(0x0007)
#define BOARDIOC_BUILTINS _BOARDIOC(0x0008)
#define BOARDIOC_USBDEV_CONTROL _BOARDIOC(0x0009)
#define BOARDIOC_NX_START _BOARDIOC(0x000a)
#define BOARDIOC_VNC_START _BOARDIOC(0x000b)
#define BOARDIOC_NXTERM _BOARDIOC(0x000c)
#define BOARDIOC_NXTERM_IOCTL _BOARDIOC(0x000d)
#define BOARDIOC_TESTSET _BOARDIOC(0x000e)
#define BOARDIOC_MKRD _BOARDIOC(0x0006)
#define BOARDIOC_APP_SYMTAB _BOARDIOC(0x0007)
#define BOARDIOC_OS_SYMTAB _BOARDIOC(0x0008)
#define BOARDIOC_BUILTINS _BOARDIOC(0x0009)
#define BOARDIOC_USBDEV_CONTROL _BOARDIOC(0x000a)
#define BOARDIOC_NX_START _BOARDIOC(0x000b)
#define BOARDIOC_VNC_START _BOARDIOC(0x000c)
#define BOARDIOC_NXTERM _BOARDIOC(0x000d)
#define BOARDIOC_NXTERM_IOCTL _BOARDIOC(0x000e)
#define BOARDIOC_TESTSET _BOARDIOC(0x000f)
/* If CONFIG_BOARDCTL_IOCTL=y, then board-specific commands will be support.
* In this case, all commands not recognized by boardctl() will be forwarded
@ -198,7 +205,7 @@
* User defined board commands may begin with this value:
*/
#define BOARDIOC_USER _BOARDIOC(0x000f)
#define BOARDIOC_USER _BOARDIOC(0x0010)
/****************************************************************************
* Public Type Definitions
@ -206,6 +213,18 @@
/* Structures used with IOCTL commands */
#ifdef CONFIG_FS_WRITABLE
/* Describes the RAM disk to be created */
struct boardioc_mkrd_s
{
uint8_t minor; /* Minor device number of the RAM disk. */
uint32_t nsectors; /* The number of sectors in the RAM disk */
uint16_t sectsize; /* The size of one sector in bytes */
uint8_t rdflags; /* See RD_FLAGS_* definitions in include/nuttx/ramdisk.h */
};
#endif
/* In order to full describe a symbol table, a vector containing the address
* of the symbol table and the number of elements in the symbol table is
* required.