diff --git a/src/bsp/pc-rtems/src/bsp_start.c b/src/bsp/pc-rtems/src/bsp_start.c index bcce3f6e2..cece37736 100644 --- a/src/bsp/pc-rtems/src/bsp_start.c +++ b/src/bsp/pc-rtems/src/bsp_start.c @@ -47,29 +47,6 @@ extern rtems_status_code rtems_ide_part_table_initialize(const char *); extern int rtems_rtl_shell_command (int argc, char* argv[]); -/* - * The RAM Disk configuration. - */ -rtems_ramdisk_config rtems_ramdisk_configuration[RTEMS_NUMBER_OF_RAMDISKS]; - -/* - * The number of RAM Disk configurations. - */ -size_t rtems_ramdisk_configuration_size = RTEMS_NUMBER_OF_RAMDISKS; - -/* -** RAM Disk IO op table. -*/ -rtems_driver_address_table rtems_ramdisk_io_ops = -{ - .initialization_entry = ramdisk_initialize, - .open_entry = rtems_blkdev_generic_open, - .close_entry = rtems_blkdev_generic_close, - .read_entry = rtems_blkdev_generic_read, - .write_entry = rtems_blkdev_generic_write, - .control_entry = rtems_blkdev_generic_ioctl -}; - /* * Additional shell commands for the RTL functionality */ diff --git a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h index 89656d2c7..cf969525d 100644 --- a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h +++ b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h @@ -28,7 +28,6 @@ * BSP compile-time tuning */ #define RTEMS_MAX_USER_OPTIONS 4 -#define RTEMS_NUMBER_OF_RAMDISKS 1 #define RTEMS_MAX_CMDLINE 256 /* diff --git a/src/os/rtems/src/os-impl-filesys.c b/src/os/rtems/src/os-impl-filesys.c index 40d127522..4003cf484 100644 --- a/src/os/rtems/src/os-impl-filesys.c +++ b/src/os/rtems/src/os-impl-filesys.c @@ -46,7 +46,8 @@ typedef struct { char blockdev_name[OS_MAX_PATH_LEN]; - rtems_device_minor_number minor; + + struct ramdisk *allocated_disk; /* other data to pass to "mount" when mounting this disk */ const char *mount_fstype; @@ -65,19 +66,6 @@ typedef struct */ OS_impl_filesys_internal_record_t OS_impl_filesys_table[OS_MAX_FILE_SYSTEMS]; - -/* - * These external references are for the RTEMS RAM disk device descriptor table - * This is necessary for the RAM disk. These tables can either be here, or - * in a RTEMS kernel startup file. In this case, the tables are in the - * application startup - * - * Currently, it does not appear possible to create multiple arbitrary disks - * The RAM disk driver appears to require these specific variables. - */ -extern rtems_ramdisk_config rtems_ramdisk_configuration[]; -extern size_t rtems_ramdisk_configuration_size; - /**************************************************************************************** Filesys API ***************************************************************************************/ @@ -110,7 +98,7 @@ int32 OS_FileSysStartVolume_Impl (uint32 filesys_id) { OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; - uint32 os_idx; + rtems_status_code sc; int32 return_code; return_code = OS_ERR_NOT_IMPLEMENTED; @@ -136,48 +124,41 @@ int32 OS_FileSysStartVolume_Impl (uint32 filesys_id) } case OS_FILESYS_TYPE_VOLATILE_DISK: { - /* - * This finds the correct driver "minor number" - * to use for the RAM disk (i.e. /dev/rd) - */ + OS_DEBUG("No RAMDISK available at address %p\n", local->address); - /* find a matching entry in the OS ramdisk table, - * (identified by the location address) */ - for (os_idx = 0; os_idx < rtems_ramdisk_configuration_size; ++os_idx) - { - if (rtems_ramdisk_configuration[os_idx].location == local->address) - { - impl->minor = os_idx; - break; - } - } + impl->allocated_disk = ramdisk_allocate( + local->address, + local->blocksize, + local->numblocks, + false + ); - if (os_idx >= rtems_ramdisk_configuration_size) + if (impl->allocated_disk == NULL) { - OS_DEBUG("No RAMDISK available at address %p\n", local->address); + OS_DEBUG("ramdisk_allocate() failed\n"); return_code = OS_INVALID_POINTER; break; } - if ( local->numblocks > rtems_ramdisk_configuration[os_idx].block_num) - { - OS_DEBUG("OSAL: Error: RAM disk too large, %lu blocks requested, %lu available.\n", - (unsigned long)local->numblocks, - (unsigned long)rtems_ramdisk_configuration[os_idx].block_num); - return_code = OS_ERROR; - break; - } - if ( local->blocksize != rtems_ramdisk_configuration[os_idx].block_size ) + + impl->mount_fstype = RTEMS_FILESYSTEM_TYPE_RFS; + impl->mount_options = RTEMS_FILESYSTEM_READ_WRITE; + snprintf(impl->blockdev_name, sizeof(impl->blockdev_name), "%s%c", RAMDISK_DEVICE_BASE_NAME, (int)filesys_id + 'a'); + + sc = rtems_blkdev_create( + impl->blockdev_name, + local->blocksize, + local->numblocks, + ramdisk_ioctl, + impl->allocated_disk + ); + if (sc != RTEMS_SUCCESSFUL) { - OS_DEBUG("OSAL: Error: RAM Disk needs a block size of %lu.\n", - (unsigned long)rtems_ramdisk_configuration[os_idx].block_size); - return_code = OS_ERROR; - break; + OS_DEBUG("rtems_blkdev_create() failed: %s.\n", rtems_status_text(sc)); + return_code = OS_ERROR; } - snprintf(impl->blockdev_name, sizeof(impl->blockdev_name), "%s%c", RAMDISK_DEVICE_BASE_NAME, (int)impl->minor + 'a'); - impl->mount_fstype = RTEMS_FILESYSTEM_TYPE_RFS; - OS_DEBUG("OSAL: RAM disk initialized: volume=%s device=%s address=0x%08lX\n", + OS_DEBUG("RAM disk initialized: volume=%s device=%s address=0x%08lX\n", local->volume_name, impl->blockdev_name, (unsigned long)local->address); return_code = OS_SUCCESS; @@ -218,7 +199,16 @@ int32 OS_FileSysStartVolume_Impl (uint32 filesys_id) *-----------------------------------------------------------------*/ int32 OS_FileSysStopVolume_Impl (uint32 filesys_id) { - /* Currently nothing to do here */ + OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + + /* + * If this was a dynamically allocated disk, then unlink it. + */ + if (impl->allocated_disk != NULL) + { + unlink(impl->blockdev_name); + } + return OS_SUCCESS; } /* end OS_FileSysStopVolume_Impl */ @@ -265,6 +255,7 @@ int32 OS_FileSysFormatVolume_Impl (uint32 filesys_id) ** Format the RAM disk with the RFS file system */ memset (&config, 0, sizeof(config)); + config.inode_overhead = 30; sc = rtems_rfs_format(impl->blockdev_name, &config); if ( sc < 0 ) { diff --git a/src/unit-tests/osfile-test/ut_osfile_test.c b/src/unit-tests/osfile-test/ut_osfile_test.c index 8a511a73b..4cc5ae3f9 100644 --- a/src/unit-tests/osfile-test/ut_osfile_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_test.c @@ -56,7 +56,7 @@ int32 UT_os_setup_fs() { int32 res; - res = OS_mkfs(g_fsAddrPtr, g_devName, " ", 512, 20); + res = OS_mkfs(g_fsAddrPtr, g_devName, "RAM3", 512, 64); if (res != OS_SUCCESS) { UT_OS_LOG("OS_mkfs() returns %d\n", (int)res);;