Ramdisks

Chris Johns chrisj at rtems.org
Thu Apr 6 22:46:50 UTC 2017


On 07/04/2017 00:08, Mathew Benson wrote:
> Can I create a ramdisk, append to the rtems_ramdisk_configuration object
> and register a new set of drivers to mount another ramdisk?  Or are the
> drivers registered oncecand only once at initialization?  Basically, do
> I have to predefine all the ramdisks?  I have an application that
> calculates the number of blocks at initialization and creates them one
> at a time.  But it appears that only the first call to register the
> driver actually results in the creation of a new ramdisk device.
>

I create a RAM disk by calling `ramdisk_register`. For example:

#define RAMDISK_BLOCK_SIZE  512
#define RAMDISK_BLOCK_COUNT ((32 * (1024 * 1024UL))/RAMDISK_BLOCK_SIZE)
#define RAMDISK_PATH        "/dev/rda"

void setup_ramdisk (void)
{
#if HAS_RAMDISK
   dev_t             dev = 0;
   rtems_status_code sc;

   printf("RAM disk: ");

   sc = rtems_disk_io_initialize ();
   if (sc != RTEMS_SUCCESSFUL)
   {
     printf ("error: disk io not initialised: %s\n",
             rtems_status_text (sc));
     return;
   }

   sc = ramdisk_register (RAMDISK_BLOCK_SIZE, RAMDISK_BLOCK_COUNT,
                          false, RAMDISK_PATH, &dev);
   if (sc != RTEMS_SUCCESSFUL)
   {
     printf ("error: ramdisk driver not initialised: %s\n",
             rtems_status_text (sc));
     return;
   }

   printf ("successful\n");
#endif
}

I then RFS format and mount the disk using a `#! joel` script:

  #! joel
  # Format and mount the RAM disk
  mkrfs /dev/rda
  mkdir /ram
  mount -t rfs /dev/rda /ram

Chris


More information about the users mailing list