apps/examples/mount: Replace illegal call to ramdisk_register() with a call to boardctl(BOARDIOC_MKRD).

This commit is contained in:
Gregory Nutt 2019-10-26 10:22:34 -06:00
parent c8a066f699
commit 0bc798c7a9
3 changed files with 15 additions and 35 deletions

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* examples/mount/ramdisk.c * examples/mount/ramdisk.c
* *
* Copyright (C) 2008-2009, 2015 Gregory Nutt. All rights reserved. * Copyright (C) 2008-2009, 2015, 2019 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
@ -39,6 +39,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/boardctl.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -56,15 +57,8 @@
* Private Definitions * Private Definitions
****************************************************************************/ ****************************************************************************/
#define BUFFER_SIZE (CONFIG_EXAMPLES_MOUNT_NSECTORS*CONFIG_EXAMPLES_MOUNT_SECTORSIZE) #define BUFFER_SIZE \
(CONFIG_EXAMPLES_MOUNT_NSECTORS * CONFIG_EXAMPLES_MOUNT_SECTORSIZE)
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@ -72,10 +66,6 @@
static struct fat_format_s g_fmt = FAT_FORMAT_INITIALIZER; static struct fat_format_s g_fmt = FAT_FORMAT_INITIALIZER;
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -97,31 +87,21 @@ static struct fat_format_s g_fmt = FAT_FORMAT_INITIALIZER;
int create_ramdisk(void) int create_ramdisk(void)
{ {
FAR char *pbuffer; struct boardioc_mkrd_s desc;
int ret; int ret;
/* Allocate a buffer to hold the file system image. */ /* Create a RAMDISK device to manage */
pbuffer = (char*)malloc(BUFFER_SIZE); desc.minor = CONFIG_EXAMPLES_MOUNT_RAMDEVNO; /* Minor device number of the RAM disk. */
if (!pbuffer) desc.nsectors = CONFIG_EXAMPLES_MOUNT_NSECTORS; /* The number of sectors in the RAM disk. */
{ desc.sectsize = CONFIG_EXAMPLES_MOUNT_SECTORSIZE; /* The size of one sector in bytes. */
printf("create_ramdisk: Failed to allocate ramdisk of size %d\n", desc.rdflags = RDFLAG_WRENABLED | RDFLAG_FUNLINK; /* See ramdisk.h. */
BUFFER_SIZE);
return -ENOMEM;
}
/* Register a RAMDISK device to manage this RAM image */ ret = boardctl(BOARDIOC_MKRD, (uintptr_t)&desc);
ret = ramdisk_register(CONFIG_EXAMPLES_MOUNT_RAMDEVNO,
(FAR uint8_t *)pbuffer,
CONFIG_EXAMPLES_MOUNT_NSECTORS,
CONFIG_EXAMPLES_MOUNT_SECTORSIZE,
RDFLAG_WRENABLED | RDFLAG_FUNLINK);
if (ret < 0) if (ret < 0)
{ {
printf("create_ramdisk: Failed to register ramdisk at %s: %d\n", printf("create_ramdisk: Failed to create ramdisk at %s: %d\n",
g_source, -ret); g_source, -ret);
free(pbuffer);
return ret; return ret;
} }
@ -132,7 +112,6 @@ int create_ramdisk(void)
{ {
printf("create_ramdisk: Failed to create FAT filesystem on ramdisk at %s\n", printf("create_ramdisk: Failed to create FAT filesystem on ramdisk at %s\n",
g_source); g_source);
/* free(pbuffer); -- RAM disk is registered */
return ret; return ret;
} }

View File

@ -31,7 +31,7 @@ config EXAMPLES_SOTEST_BUILTINFS
card, for testing on the target. card, for testing on the target.
NOTE: This option can only be used in the FLAT build mode because NOTE: This option can only be used in the FLAT build mode because
it makes an illegal OS call to ramdisk_register(). it makes an illegal OS call to romdisk_register().
if EXAMPLES_SOTEST_BUILTINFS if EXAMPLES_SOTEST_BUILTINFS

View File

@ -1430,7 +1430,8 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
ret = boardctl(BOARDIOC_MKRD, (uintptr_t)&desc); ret = boardctl(BOARDIOC_MKRD, (uintptr_t)&desc);
if (ret < 0) if (ret < 0)
{ {
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "ramdisk_register", NSH_ERRNO_OF(-ret)); nsh_error(vtbl, g_fmtcmdfailed, argv[0], "boarctl(BOARDIOC_MKRD)",
NSH_ERRNO_OF(-ret));
return ERROR; return ERROR;
} }