problems with RFS filesystem and mkdir

Phil Smith philip.smith.ucl at gmail.com
Thu Jan 2 21:41:26 UTC 2014


On Wed, Mar 20, 2013 at 08:03:20PM +0000, Cudmore, Alan P. (GSFC-5820) wrote:

> On 19 Mar 2013 21:05, "Cudmore, Alan P. (GSFC-5820)" <alan.p.cudmore at nasa.gov<mailto:alan.p.cudmore at nasa.gov>> wrote:
> I took your code below and created an example that would build and run on my 4.10.2 setup. I ran this on the sparc-sis simulator, and it seems to work fine.
> 
> Are you sure you have valid memory for the nvramdisk device?
> 
> We rely on RFS on 4.10.2 and are giving a pretty good stress test right now.
> 
> Alan

Did you get Matthew's test example to actually create a directory/file?

Firstly, there are two points about the example code:
1. For the line:
     if (rtems_rfs_format (sram_driver, &config) < 0)
   the return should be tested against RTEMS_SUCCESSFUL rather than "< 0" since returned status codes are an enum (all errors are positive and RTEMS_SUCCESSFUL is 0).  This does not affect this specific test though.
2. The line
     rtems_mkdir("sram/DB", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
   doesn't have its return checked and this is where we see the example fails with rtems-4.10.2.

We ran Matthew's example (modified as little as possible for the SIS SPARC simulator, with extra checks added and included below) and it fails on rtems-4.10.2 but works OK on rtems-4.11, specifically commit db8a89e21254b0756a053709e56e5119fa75c2f1 Thu Dec 19 19:01:23
2013 +1100.  It also fails with rtems-4.10.2 on two LEON development boards.

Try compiling the following code for 4.10.2 and for 4.11 and you should see that the output is:

4.10.2
------
  rtems_io_register_driver() successful
  format of /dev/nvda successful
  mount of /dev/nvda to /sram successful
  rtems_mkdir /sram/DA failed. rc=-1
  rtems_mkdir /sram/DA/DB/ failed. rc=-1
  file /sram/DA/DB/1 open for R/W failed, errno = 5 (I/O error)

and

4.11
----
  rtems_io_register_driver() successful
  format of /dev/nvda successful
  mount of /dev/nvda to /sram successful
  mkdir /sram/DA OK
  mkdir /sram/DA/DB/ OK
  file /sram/DA/DB/1 open for R/W successful


Does this not indicate a bug in 4.10.2?


-------------------------------------8<-----cut here-----8<----------------------------

#define CONFIGURE_EXTRA_TASK_STACKS         (CONFIGURE_MAXIMUM_TASKS * RTEMS_MINIMUM_STACK_SIZE)

#define CONFIGURE_MAXIMUM_DRIVERS           6

/* NOTICE: the clock driver is explicitly disabled */
#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER

#define CONFIGURE_DISABLE_CLASSIC_API_NOTEPADS
#define CONFIGURE_MAXIMUM_TASKS 40      // TX MAX_THREAD
#define CONFIGURE_MAXIMUM_TIMERS 40     // TX MAX_TIMER
#define CONFIGURE_MAXIMUM_SEMAPHORES 40 // TX MAX_MUTEX
#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 40     // TX MAX_MSG_QUEUE
#define CONFIGURE_MAXIMUM_PARTITIONS 5
#define CONFIGURE_MAXIMUM_REGIONS 5
#define CONFIGURE_MAXIMUM_PORTS 0
#define CONFIGURE_MAXIMUM_PERIODS 0
#define CONFIGURE_MAXIMUM_BARRIERS 0

#define CONFIGURE_MICROSECONDS_PER_TICK   10000 /* 10 milliseconds */
#define CONFIGURE_TICKS_PER_TIMESLICE       50  /* 50 milliseconds */

#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
#define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS  2
#define CONFIGURE_BDBUF_MAX_WRITE_BLOCKS       8
#define CONFIGURE_SWAPOUT_TASK_PRIORITY        15
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_FILESYSTEM_RFS
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 10

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT
#include <rtems/confdefs.h>

/**
 * Let the IO system allocation the next available major number.
 */
#define RTEMS_DRIVER_AUTO_MAJOR (0)

/* this errno.h is necessary for rtems-4.10 */
#include <errno.h>

#include <fcntl.h>
#include <rtems/rtems-rfs-format.h>
#include <rtems/nvdisk-sram.h>

uint32_t rtems_nvdisk_configuration_size = 1;
const char *sram_driver = "/dev/nvda";  // RTEMS_NVDISK_DEVICE_BASE_NAME, 1st device
const char *sram_path = "/sram";

void mount_rfs_on_sram(int cold_boot);
int setup_sram_disk(int cold_boot);


/**
 * The SRAM Device setup
 */
rtems_nvdisk_device_desc rtems_sram_device_descriptor[] = {
  {
   .flags = 0,
   .base = 0,
   .size = 256 * 1024,          // 256K (Adjust when ROM.ld, _IMFS_DiskSize is changed)
   .nv_ops = &rtems_nvdisk_sram_handlers}
};

const rtems_nvdisk_config rtems_nvdisk_configuration[] = {
  {
   .block_size = 512,
   .device_count = 1,
   .devices = &rtems_sram_device_descriptor[0],
   .flags = 0,
   .info_level = 0}
};

/**
 * Create the SRAM Disk Driver entry.
 */
rtems_driver_address_table rtems_sram_ops = {
  .initialization_entry = rtems_nvdisk_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
};


rtems_task Init(rtems_task_argument __attribute__ ((unused)) ignored)
{
  int rc;
  char tempfname[] = "/sram/DA/DB/1";
  int fd;

  mount_rfs_on_sram(1);
  rc = rtems_mkdir("/sram/DA", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  if (rc != RTEMS_SUCCESSFUL) {
    printf("rtems_mkdir /sram/DA failed. rc=%d\n", rc);
  } else {
    printf("mkdir /sram/DA OK\n");
  }
  rc = rtems_mkdir("/sram/DA/DB/", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  if (rc != RTEMS_SUCCESSFUL) {
    printf("rtems_mkdir /sram/DA/DB/ failed. rc=%d\n", rc);
  } else {
    printf("mkdir /sram/DA/DB/ OK\n");
  }
  fd = open(tempfname, O_CREAT | O_TRUNC | O_RDWR, 0644);
  if (fd < 0) {
    printf("file %s open for R/W failed, errno = %d (%s)\n", tempfname, errno, strerror(errno));
  } else {
    printf("file %s open for R/W successful\n", tempfname);
    close(fd);
  }
}

int setup_sram_disk(int cold_boot)
{
  rtems_device_major_number major;
  rtems_status_code rc;

  // settings
  rtems_sram_device_descriptor[0].base = (uint32_t *)malloc(256 * 1024);
  if (rtems_sram_device_descriptor[0].base == 0) {
    printf("malloc() failed\n");
    exit(1);
  }

  if (cold_boot) {
    memset(rtems_sram_device_descriptor[0].base, 0xff, rtems_sram_device_descriptor[0].size);
  }

  /*
   * Register the NV Disk driver.
   */
  rc = rtems_io_register_driver(RTEMS_DRIVER_AUTO_MAJOR, &rtems_sram_ops, &major);
  if (rc != RTEMS_SUCCESSFUL) {
    printf("rtems_io_register_driver() rc=%d\n", rc);
  } else {
    printf("rtems_io_register_driver() successful\n");
  }
  return rc;
}

/*
 *
 * RFS on SRAM
 *
 */

void mount_rfs_on_sram(int cold_boot)
{
  rtems_rfs_format_config config;

  setup_sram_disk(cold_boot);

  // zero is a good set of defaults
  memset(&config, 0, sizeof(rtems_rfs_format_config));

  if (rtems_rfs_format(sram_driver, &config) < 0) {
    printf("error: format of %s failed: %s\n", sram_driver, strerror(errno));
  } else {
    printf("format of %s successful\n", sram_driver);
  }

  if (mount_and_make_target_path(sram_driver, sram_path, RTEMS_FILESYSTEM_TYPE_RFS, RTEMS_FILESYSTEM_READ_WRITE, NULL) != 0) {
    printf("error: mount of %s to %s failed: %s\n", sram_driver, sram_path, strerror(errno));
  } else {
    printf("mount of %s to %s successful\n", sram_driver, sram_path);
  }
}

-------------------------------------8<-----cut here-----8<----------------------------

--
Philip J. Smith
Mullard Space Science Laboratory,
Dept. of Space and Climate Physics,
University College London.



More information about the users mailing list