Example #1
0
static void test(void)
{
  rtems_status_code sc;
  dev_t dev = 0;
  rtems_disk_device *dd;

  sc = rtems_disk_io_initialize();
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_disk_create_phys(
    dev,
    1,
    BLOCK_COUNT,
    test_disk_ioctl,
    NULL,
    NULL
  );
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  dd = rtems_disk_obtain(dev);
  rtems_test_assert(dd != NULL);

  test_actions(dd);

  sc = rtems_disk_release(dd);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  sc = rtems_disk_delete(dev);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
}
Example #2
0
static void test(const char *rda, const char *mnt, const char *file)
{
  static const msdos_format_request_param_t rqdata = {
    .quick_format = true,
    .sync_device = true
  };

  rtems_status_code sc;
  int disk_fd;
  int rv;

  sc = rtems_disk_io_initialize();
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  disk_fd = open(rda, O_RDWR);
  rtems_test_assert(disk_fd >= 0);

  rv = msdos_format(rda, &rqdata);
  rtems_test_assert(rv == 0);

  rv = mount_and_make_target_path(
    rda,
    mnt,
    RTEMS_FILESYSTEM_TYPE_DOSFS,
    RTEMS_FILESYSTEM_READ_WRITE,
    NULL
  );
  rtems_test_assert(rv == 0);

  create_file(file);
  rv = rtems_disk_fd_purge(disk_fd);
  rtems_test_assert(rv == 0);

  write_to_file(file, false);
  rv = rtems_disk_fd_purge(disk_fd);
  rtems_test_assert(rv == 0);
  check_file_size(file, 0);

  write_to_file(file, true);
  rv = rtems_disk_fd_purge(disk_fd);
  rtems_test_assert(rv == 0);
  check_file_size(file, 1);

  rv = unmount(mnt);
  rtems_test_assert(rv == 0);

  rv = close(disk_fd);
  rtems_test_assert(rv == 0);
}

static void Init(rtems_task_argument arg)
{
  puts("\n\n*** TEST FSDOSFSSYNC 1 ***");

  test("/dev/rda", "/mnt", "/mnt/file");

  puts("*** END OF TEST FSDOSFSSYNC 1 ***");

  rtems_test_exit(0);
}
Example #3
0
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_bdbuf_buffer *bd = NULL;
  dev_t dev = 0;
  rtems_disk_device *dd = NULL;

  printk("\n\n*** TEST BLOCK 9 ***\n");

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = disk_register(BLOCK_SIZE, BLOCK_COUNT, &dev);
  ASSERT_SC(sc);

  dd = rtems_disk_obtain(dev);
  assert(dd != NULL);

  check_read(dd, BLOCK_READ_IO_ERROR, RTEMS_IO_ERROR);
  check_read(dd, BLOCK_READ_UNSATISFIED, RTEMS_UNSATISFIED);
  check_read(dd, BLOCK_READ_SUCCESSFUL, RTEMS_SUCCESSFUL);
  check_read(dd, BLOCK_WRITE_IO_ERROR, RTEMS_SUCCESSFUL);

  /* Check write IO error */

  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
  ASSERT_SC(sc);

  bd->buffer [0] = 1;

  sc = rtems_bdbuf_sync(bd);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
  ASSERT_SC(sc);

  assert(bd->buffer [0] == 0);

  sc = rtems_bdbuf_release(bd);
  ASSERT_SC(sc);

  /* Check write to deleted disk */

  sc = rtems_bdbuf_read(dd, BLOCK_READ_SUCCESSFUL, &bd);
  ASSERT_SC(sc);

  sc = rtems_disk_delete(dev);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_sync(bd);
  ASSERT_SC(sc);

  sc = rtems_disk_release(dd);
  ASSERT_SC(sc);

  printk("*** END OF TEST BLOCK 9 ***\n");

  exit(0);
}
/* ramdisk_initialize --
 *     RAM disk device driver initialization. Run through RAM disk
 *     configuration information and configure appropriate RAM disks.
 *
 * PARAMETERS:
 *     major - RAM disk major device number
 *     minor - minor device number, not applicable
 *     arg   - initialization argument, not applicable
 *
 * RETURNS:
 *     none
 */
rtems_device_driver
ramdisk_initialize(
    rtems_device_major_number major,
    rtems_device_minor_number minor,
    void *arg)
{
    rtems_device_minor_number i;
    rtems_ramdisk_config *c = rtems_ramdisk_configuration;
    struct ramdisk *r;
    rtems_status_code rc;

    rc = rtems_disk_io_initialize();
    if (rc != RTEMS_SUCCESSFUL)
        return rc;

    r = ramdisk = calloc(rtems_ramdisk_configuration_size,
                         sizeof(struct ramdisk));

    for (i = 0; i < rtems_ramdisk_configuration_size; i++, c++, r++)
    {
        dev_t dev = rtems_filesystem_make_dev_t(major, i);
        char name[sizeof(RAMDISK_DEVICE_BASE_NAME "0123456789")];
        snprintf(name, sizeof(name), RAMDISK_DEVICE_BASE_NAME "%" PRIu32, i);
        r->block_size = c->block_size;
        r->block_num = c->block_num;
        if (c->location == NULL)
        {
            r->malloced = TRUE;
            r->area = malloc(r->block_size * r->block_num);
            if (r->area == NULL) /* No enough memory for this disk */
            {
                r->initialized = FALSE;
                continue;
            }
            else
            {
                r->initialized = TRUE;
            }
        }
        else
        {
            r->malloced = FALSE;
            r->initialized = TRUE;
            r->area = c->location;
        }
        rc = rtems_disk_create_phys(dev, c->block_size, c->block_num,
                                    ramdisk_ioctl, name);
        if (rc != RTEMS_SUCCESSFUL)
        {
            if (r->malloced)
            {
                free(r->area);
            }
            r->initialized = FALSE;
        }
    }
    nramdisks = rtems_ramdisk_configuration_size;
    return RTEMS_SUCCESSFUL;
}
Example #5
0
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_bdbuf_buffer *bd = NULL;
  dev_t dev = 0;

  printk("\n\n*** TEST BLOCK 3 ***\n");

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, false, "/dev/rda", &dev);
  ASSERT_SC(sc);

  dd = rtems_disk_obtain(dev);
  rtems_test_assert(dd != NULL);

  sc = rtems_task_create(
    rtems_build_name(' ', 'L', 'O', 'W'),
    PRIORITY_LOW,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_low
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_low, task_low, 0);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('H', 'I', 'G', 'H'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_high
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_high, task_high, 0);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_get(dd, 0, &bd);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_sync(bd);
  ASSERT_SC(sc);

  printk("I: sync done: 0\n");

  sync_done = true;

  sc = rtems_task_suspend(RTEMS_SELF);
  ASSERT_SC(sc);
}
void
init_ramdisk (void)
{

  int rc = 0;
  rc = rtems_disk_io_initialize ();
  rtems_test_assert (rc == 0);
  rc = ramdisk_register (RAMDISK_BLOCK_SIZE, RAMDISK_BLOCK_COUNT,
                         false, RAMDISK_PATH, &dev);
  rtems_test_assert (rc == 0);
}
Example #7
0
/**
 * BDBuf disk device driver initialization.
 *
 * @param major Disk major device number.
 * @param minor Minor device number, not applicable.
 * @param arg Initialization argument, not applicable.
 */
static rtems_device_driver
bdbuf_disk_initialize (rtems_device_major_number major,
                       rtems_device_minor_number minor,
                       void*                     arg)
{
  rtems_status_code sc;

  bdbuf_test_printf ("disk io init: ");
  sc = rtems_disk_io_initialize ();
  if (!bdbuf_test_print_sc (sc, true))
    return sc;

  for (minor = 0; minor < BDBUF_DISKS; minor++)
  {
    char              name[sizeof (BDBUF_DISK_DEVICE_BASE_NAME) + 10];
    bdbuf_disk*       bdd = &bdbuf_disks[minor];
    rtems_status_code sc;

    snprintf (name, sizeof (name),
              BDBUF_DISK_DEVICE_BASE_NAME "%" PRIu32, minor);

    bdd->name = strdup (name);

    bdbuf_test_printf ("disk init: %s\n", bdd->name);
    bdbuf_test_printf ("disk lock: ");

    sc = rtems_semaphore_create (rtems_build_name ('B', 'D', 'D', 'K'), 1,
                                 RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE |
                                 RTEMS_INHERIT_PRIORITY, 0, &bdd->lock);
    if (!bdbuf_test_print_sc (sc, true))
      return RTEMS_IO_ERROR;

    bdd->block_size  = 512 * (minor + 1);
    bdd->block_count = BDBUF_SIZE * (minor + 1);

    sc = rtems_disk_create_phys(rtems_filesystem_make_dev_t (major, minor),
                                bdd->block_size, bdd->block_count,
                                bdbuf_disk_ioctl, bdd, name);
    if (sc != RTEMS_SUCCESSFUL)
    {
      bdbuf_test_printf ("disk init: create phys failed: ");
      bdbuf_test_print_sc (sc, true);
      return sc;
    }

  }
  return RTEMS_SUCCESSFUL;
}
Example #8
0
rtems_device_driver
test_disk_initialize(
    rtems_device_major_number major,
    rtems_device_minor_number minor,
    void *arg)
{
    rtems_status_code rc;
    dev_t             dev;

    rc = rtems_disk_io_initialize();
    if (rc != RTEMS_SUCCESSFUL)
        return rc;

    dev = rtems_filesystem_make_dev_t(major, minor);
    rc = rtems_disk_create_phys(dev,
                                TEST_DISK_BLOCK_SIZE, TEST_DISK_BLOCK_NUM,
                                test_disk_ioctl,
                                NULL,
                                TEST_DISK_NAME);
    if (rc != RTEMS_SUCCESSFUL)
    {
        printf("Failed to create %s disk\n", TEST_DISK_NAME);
        return rc;
    }

    rc = bdbuf_test_create_drv_rx_queue(&drvq_id);
    if (rc != RTEMS_SUCCESSFUL)
    {
        printk("%s() Failed to create Msg Queue for RX: %u\n",
               __FUNCTION__, rc);
        return rc;
    }

    rc = bdbuf_test_create_drv_tx_queue(&testq_id);
    if (rc != RTEMS_SUCCESSFUL)
    {
        printf("%s() Failed to get Msg Queue for TX: %u\n",
               __FUNCTION__, rc);
        return rc;
    }

    printk("TEST DISK - OK\n");
    return RTEMS_SUCCESSFUL;
}
Example #9
0
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc;

  puts("\n\n*** TEST BLOCK 11 ***");

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  test_blkdev_imfs_read_and_write();
  test_blkdev_imfs_parameters();
  test_blkdev_imfs_errors();

  sc = rtems_disk_io_done();
  ASSERT_SC(sc);

  puts("*** END OF TEST BLOCK 11 ***");

  exit(0);
}
Example #10
0
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc;

  TEST_BEGIN();

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  test_blkdev_imfs_read_and_write();
  test_blkdev_imfs_parameters();
  test_blkdev_imfs_errors();

  sc = rtems_disk_io_done();
  ASSERT_SC(sc);

  TEST_END();

  exit(0);
}
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;

  printk("\n\n*** TEST BLOCK 4 ***\n");

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, false, "/dev/rda", &dev);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name(' ', 'L', 'O', 'W'),
    PRIORITY_LOW,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_low
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_low, task_low, 0);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('H', 'I', 'G', 'H'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_high
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_high, task_high, 0);
  ASSERT_SC(sc);

  sc = rtems_task_suspend(RTEMS_SELF);
  ASSERT_SC(sc);
}
Example #12
0
static void test( void )
{
  rtems_status_code            sc;
  int                          rv;
  const char                   dev_name[]  = "/dev/rda";
  const char                   mount_dir[] = "/mnt";
  msdos_format_request_param_t rqdata;
  rtems_blkdev_bnum            media_block_count;

  memset( &rqdata, 0, sizeof( rqdata ) );

  sc = rtems_disk_io_initialize();
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  rv = mkdir( mount_dir, S_IRWXU | S_IRWXG | S_IRWXO );
  rtems_test_assert( 0 == rv );

  /* FAT12 */
  /* For 1.44 MB disks */
  sc = rtems_sparse_disk_create_and_register(
    dev_name,
    SECTOR_SIZE,
    64,
    2880,
    0
    );
  rtems_test_assert( RTEMS_SUCCESSFUL == sc );

  /* Optimized for disk space */
  rqdata.OEMName             = NULL;
  rqdata.VolLabel            = NULL;
  rqdata.sectors_per_cluster = 1;
  rqdata.fat_num             = 1;
  rqdata.files_per_root_dir  = 32;
  rqdata.media               = 0; /* Media code. 0 == Default */
  rqdata.quick_format        = true;
  rqdata.skip_alignment      = true;
  rv                         = msdos_format( dev_name, &rqdata );
  rtems_test_assert( rv == 0 );
  test_disk_params( dev_name, mount_dir, SECTOR_SIZE, SECTOR_SIZE, 1 );
  test_file_creation( dev_name, mount_dir, rqdata.files_per_root_dir );

  /* Try formatting with invalid values */
  rqdata.OEMName             = NULL;
  rqdata.VolLabel            = NULL;
  rqdata.sectors_per_cluster = 1;
  rqdata.fat_num             = 7; /* Invalid number of fats */
  rqdata.files_per_root_dir  = 32;
  rqdata.media               = 0; /* Media code. 0 == Default */
  rqdata.quick_format        = true;
  rqdata.skip_alignment      = true;
  rv                         = msdos_format( dev_name, &rqdata );
  rtems_test_assert( rv != 0 );

  rqdata.OEMName             = NULL;
  rqdata.VolLabel            = NULL;
  rqdata.sectors_per_cluster = 1;
  rqdata.fat_num             = 1;
  rqdata.files_per_root_dir  = 32;
  rqdata.media               = 0x11; /* Invalid media code */
  rqdata.quick_format        = true;
  rqdata.skip_alignment      = true;
  rv                         = msdos_format( dev_name, &rqdata );
  rtems_test_assert( rv != 0 );

  /* Optimized for read/write speed */
  rqdata.OEMName             = NULL;
  rqdata.VolLabel            = NULL;
  rqdata.sectors_per_cluster = 8;
  rqdata.fat_num             = 0;
  rqdata.files_per_root_dir  = 0;
  rqdata.media               = 0; /* Media code. 0 == Default */
  rqdata.quick_format        = true;
  rqdata.skip_alignment      = false;
  rv                         = msdos_format( dev_name, &rqdata );
  rtems_test_assert( rv == 0 );
  test_disk_params( dev_name,
                    mount_dir,
                    SECTOR_SIZE,
                    SECTOR_SIZE * rqdata.sectors_per_cluster,
                    rqdata.sectors_per_cluster );

  /* The same disk formatted with FAT16 because sectors per cluster is too high
   * for FAT12 */
  rqdata.OEMName             = NULL;
  rqdata.VolLabel            = NULL;
  rqdata.sectors_per_cluster = 16;
  rqdata.fat_num             = 1;
  rqdata.files_per_root_dir  = 32;
  rqdata.media               = 0; /* Media code. 0 == Default */
  rqdata.quick_format        = true;
  rqdata.skip_alignment      = false;
  rv                         = msdos_format( dev_name, &rqdata );
  rtems_test_assert( rv == 0 );
  test_disk_params( dev_name,
                    mount_dir,
                    SECTOR_SIZE,
                    SECTOR_SIZE * rqdata.sectors_per_cluster,
                    rqdata.sectors_per_cluster );

  rv = unlink( dev_name );
  rtems_test_assert( rv == 0 );

  /* Largest FAT12 disk */
  sc = rtems_sparse_disk_create_and_register(
    dev_name,
    SECTOR_SIZE,
    64,
    ( FAT12_MAX_CLN * FAT12_DEFAULT_SECTORS_PER_CLUSTER ) - 1L,
    0
    );
  rtems_test_assert( RTEMS_SUCCESSFUL == sc );

  /* Default parameters (corresponds to optimization for read/write speed) */
  rv = msdos_format( dev_name, NULL );
  rtems_test_assert( rv == 0 );
  test_disk_params( dev_name,
                    mount_dir,
                    SECTOR_SIZE,
                    SECTOR_SIZE * FAT12_DEFAULT_SECTORS_PER_CLUSTER,
                    FAT12_DEFAULT_SECTORS_PER_CLUSTER );

  rv = unlink( dev_name );
  rtems_test_assert( rv == 0 );

  /* FAT16 */
  sc = rtems_sparse_disk_create_and_register(
    dev_name,
    SECTOR_SIZE,
    1024,
    ( FAT12_MAX_CLN * FAT12_DEFAULT_SECTORS_PER_CLUSTER ) + 1L,
    0
    );
  rtems_test_assert( RTEMS_SUCCESSFUL == sc );

  /* Optimized for disk space */
  rqdata.OEMName             = NULL;
  rqdata.VolLabel            = NULL;
  rqdata.sectors_per_cluster = 1;
  rqdata.fat_num             = 1;
  rqdata.files_per_root_dir  = 32;
  rqdata.media               = 0; /* Media code. 0 == Default */
  rqdata.quick_format        = true;
  rqdata.skip_alignment      = true;
  rv                         = msdos_format( dev_name, &rqdata );
  rtems_test_assert( rv == 0 );
  test_disk_params( dev_name,
                    mount_dir,
                    SECTOR_SIZE,
                    rqdata.sectors_per_cluster * SECTOR_SIZE,
                    rqdata.sectors_per_cluster );

  rv = unlink( dev_name );
  rtems_test_assert( rv == 0 );

  sc = rtems_sparse_disk_create_and_register(
    dev_name,
    SECTOR_SIZE,
    1024,
    ( FAT16_MAX_CLN * FAT16_DEFAULT_SECTORS_PER_CLUSTER ) - 1L,
    0
    );
  rtems_test_assert( RTEMS_SUCCESSFUL == sc );

  /* Optimized for read/write speed */
  rqdata.OEMName             = NULL;
  rqdata.VolLabel            = NULL;
  rqdata.sectors_per_cluster = 64;
  rqdata.fat_num             = 0;
  rqdata.files_per_root_dir  = 0;
  rqdata.media               = 0; /* Media code. 0 == Default */
  rqdata.quick_format        = true;
  rqdata.skip_alignment      = false;
  rv                         = msdos_format( dev_name, &rqdata );
  rtems_test_assert( rv == 0 );
  test_disk_params( dev_name,
                    mount_dir,
                    SECTOR_SIZE,
                    SECTOR_SIZE * rqdata.sectors_per_cluster,
                    rqdata.sectors_per_cluster );

  /* Default parameters (corresponds to optimization for read/write speed) */
  rv = msdos_format( dev_name, NULL );
  rtems_test_assert( rv == 0 );
  test_disk_params( dev_name,
                    mount_dir,
                    SECTOR_SIZE,
                    SECTOR_SIZE * FAT16_DEFAULT_SECTORS_PER_CLUSTER,
                    FAT16_DEFAULT_SECTORS_PER_CLUSTER );

  rv = unlink( dev_name );
  rtems_test_assert( rv == 0 );

  sc = rtems_sparse_disk_create_and_register(
    dev_name,
    SECTOR_SIZE,
    1024,
    ( FAT16_MAX_CLN + 10 ) * 64,
    0
    );
  rtems_test_assert( RTEMS_SUCCESSFUL == sc );

  rqdata.OEMName             = NULL;
  rqdata.VolLabel            = NULL;
  rqdata.sectors_per_cluster = 64;
  rqdata.fat_num             = 0;
  rqdata.files_per_root_dir  = 0;
  rqdata.media               = 0; /* Media code. 0 == Default */
  rqdata.quick_format        = true;
  rqdata.skip_alignment      = false;
  rv                         = msdos_format( dev_name, &rqdata );
  rtems_test_assert( rv == 0 );
  test_disk_params( dev_name,
                    mount_dir,
                    SECTOR_SIZE,
                    SECTOR_SIZE * rqdata.sectors_per_cluster,
                    rqdata.sectors_per_cluster );
  rv = unlink( dev_name );
  rtems_test_assert( rv == 0 );

  /* Format some disks from 1MB up to 128GB */
  rqdata.OEMName             = NULL;
  rqdata.VolLabel            = NULL;
  rqdata.sectors_per_cluster = 64;
  rqdata.fat_num             = 0;
  rqdata.files_per_root_dir  = 0;
  rqdata.media               = 0;
  rqdata.quick_format        = true;
  rqdata.skip_alignment      = false;
  for (
    media_block_count = 1 * 1024 * ( 1024 / SECTOR_SIZE );
    media_block_count <= 128 * 1024 * 1024 * ( 1024 / SECTOR_SIZE );
    media_block_count *= 2
  ) {
    sc = rtems_sparse_disk_create_and_register(
      dev_name,
      SECTOR_SIZE,
      64,
      media_block_count,
      0
    );
    rtems_test_assert( sc == RTEMS_SUCCESSFUL );

    rv = msdos_format( dev_name, &rqdata );
    rtems_test_assert( rv == 0 );

    test_disk_params(
      dev_name,
      mount_dir,
      SECTOR_SIZE,
      SECTOR_SIZE * rqdata.sectors_per_cluster,
      rqdata.sectors_per_cluster
    );

    rv = unlink( dev_name );
    rtems_test_assert( rv == 0 );
  }

  /* FAT32 */

  sc = rtems_sparse_disk_create_and_register(
    dev_name,
    SECTOR_SIZE,
    1024,
    ( FAT16_MAX_CLN * FAT16_DEFAULT_SECTORS_PER_CLUSTER ) + 41L,
    0
    );
  rtems_test_assert( RTEMS_SUCCESSFUL == sc );

  /* Default parameters */
  rv = msdos_format( dev_name, NULL );
  rtems_test_assert( rv == 0 );
  test_disk_params( dev_name, mount_dir, SECTOR_SIZE, SECTOR_SIZE, 1 );
  rv = unlink( dev_name );
  rtems_test_assert( rv == 0 );

  sc = rtems_sparse_disk_create_and_register(
    dev_name,
    SECTOR_SIZE,
    1024,
    ( FAT16_MAX_CLN + 20 ) * 64L,
    0
    );
  rtems_test_assert( RTEMS_SUCCESSFUL == sc );

  /* Optimized for read/write speed */
  rqdata.OEMName             = NULL;
  rqdata.VolLabel            = NULL;
  rqdata.sectors_per_cluster = 64;
  rqdata.fat_num             = 0;
  rqdata.files_per_root_dir  = 0;
  rqdata.media               = 0; /* Media code. 0 == Default */
  rqdata.quick_format        = true;
  rqdata.skip_alignment      = false;
  rv                         = msdos_format( dev_name, &rqdata );
  rtems_test_assert( rv == 0 );
  test_disk_params( dev_name,
                    mount_dir,
                    SECTOR_SIZE,
                    SECTOR_SIZE * rqdata.sectors_per_cluster,
                    rqdata.sectors_per_cluster );

  rv = unlink( dev_name );
  rtems_test_assert( rv == 0 );
}
static void test_diskdevs(void)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_device_major_number major = 0;
  rtems_device_minor_number minor = 0;
  rtems_disk_device *physical_dd = NULL;
  rtems_disk_device *logical_dd = NULL;
  rtems_disk_device *dd = NULL;
  dev_t physical_dev = 0;
  dev_t logical_dev = 0;
  dev_t logical_2_dev = 0;
  dev_t const big_major_dev = rtems_filesystem_make_dev_t((rtems_device_major_number) -2, 0);
  dev_t const big_minor_dev = rtems_filesystem_make_dev_t(0, (rtems_device_minor_number) -2);
  ramdisk *const rd = ramdisk_allocate(NULL, BLOCK_SIZE, BLOCK_COUNT, false);

  rtems_test_assert(rd != NULL);

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = rtems_io_register_driver(0, &ramdisk_ops, &major);
  ASSERT_SC(sc);

  physical_dev = rtems_filesystem_make_dev_t(major, minor);
  logical_dev = rtems_filesystem_make_dev_t(major, minor + 1);
  logical_2_dev = rtems_filesystem_make_dev_t(major, minor + 2);

  /* Consistency checks for physical disks creation */

  sc = rtems_disk_create_phys(physical_dev, BLOCK_SIZE, BLOCK_COUNT, NULL, rd, "/dev/rda");
  ASSERT_SC_EQ(sc, RTEMS_INVALID_ADDRESS);

  sc = rtems_disk_create_phys(physical_dev, 0, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda");
  ASSERT_SC_EQ(sc, RTEMS_INVALID_NUMBER);

  sc = rtems_disk_create_phys(big_major_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda");
  ASSERT_SC_EQ(sc, RTEMS_NO_MEMORY);

  sc = rtems_disk_create_phys(big_minor_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda");
  ASSERT_SC_EQ(sc, RTEMS_NO_MEMORY);

  sc = rtems_disk_create_phys(physical_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, NULL);
  ASSERT_SC(sc);

  sc = rtems_disk_create_phys(physical_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, NULL);
  ASSERT_SC_EQ(sc, RTEMS_RESOURCE_IN_USE);

  sc = rtems_disk_delete(physical_dev);
  ASSERT_SC(sc);

  /* Consistency checks for logical disks creation */

  sc = rtems_disk_create_log(logical_dev, physical_dev, 0, 1, "/dev/rda1");
  ASSERT_SC_EQ(sc, RTEMS_INVALID_ID);

  sc = rtems_disk_create_phys(physical_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda");
  ASSERT_SC(sc);

  sc = rtems_disk_create_log(big_major_dev, physical_dev, 0, 1, "/dev/rda1");
  ASSERT_SC_EQ(sc, RTEMS_NO_MEMORY);

  sc = rtems_disk_create_log(big_minor_dev, physical_dev, 0, 1, "/dev/rda1");
  ASSERT_SC_EQ(sc, RTEMS_NO_MEMORY);

  sc = rtems_disk_create_log(logical_dev, physical_dev, BLOCK_COUNT, 0, "/dev/rda1");
  ASSERT_SC_EQ(sc, RTEMS_INVALID_NUMBER);

  sc = rtems_disk_create_log(logical_dev, physical_dev, 0, BLOCK_COUNT + 1, "/dev/rda1");
  ASSERT_SC_EQ(sc, RTEMS_INVALID_NUMBER);

  sc = rtems_disk_create_log(logical_dev, physical_dev, 1, BLOCK_COUNT, "/dev/rda1");
  ASSERT_SC_EQ(sc, RTEMS_INVALID_NUMBER);

  sc = rtems_disk_create_log(logical_dev, physical_dev, 0, 1, "/dev/rda1");
  ASSERT_SC(sc);

  sc = rtems_disk_create_log(logical_dev, physical_dev, 0, 1, "/dev/rda1");
  ASSERT_SC_EQ(sc, RTEMS_RESOURCE_IN_USE);

  sc = rtems_disk_create_log(logical_2_dev, logical_dev, 0, 1, "/dev/rda1");
  ASSERT_SC_EQ(sc, RTEMS_INVALID_ID);

  sc = rtems_disk_delete(logical_dev);
  ASSERT_SC(sc);

  /* Consistency checks delete */

  sc = rtems_disk_create_log(logical_dev, physical_dev, 0, 1, "/dev/rda1");
  ASSERT_SC(sc);

  physical_dd = rtems_disk_obtain(physical_dev);
  rtems_test_assert(physical_dd != NULL && physical_dd->uses == 2);

  sc = rtems_disk_release(physical_dd);
  ASSERT_SC(sc);

  logical_dd = rtems_disk_obtain(logical_dev);
  rtems_test_assert(logical_dd != NULL && logical_dd->uses == 1);

  sc = rtems_disk_delete(physical_dev);
  ASSERT_SC(sc);

  sc = rtems_disk_create_phys(physical_dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda");
  ASSERT_SC_EQ(sc, RTEMS_RESOURCE_IN_USE);

  dd = rtems_disk_obtain(physical_dev);
  rtems_test_assert(dd == NULL);

  dd = rtems_disk_obtain(logical_dev);
  rtems_test_assert(dd == NULL);

  sc = rtems_disk_release(logical_dd);
  ASSERT_SC(sc);

  /* Cleanup */

  sc = rtems_io_unregister_driver(major);
  ASSERT_SC(sc);

  ramdisk_free(rd);

  sc = rtems_disk_io_done();
  ASSERT_SC(sc);
}
Example #14
0
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_task_priority cur_prio = 0;
  rtems_bdbuf_buffer *bd = NULL;
  dev_t dev = 0;

  rtems_test_begink();

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT, false, "/dev/rda", &dev);
  ASSERT_SC(sc);

  dd = rtems_disk_obtain(dev);
  rtems_test_assert(dd != NULL);

  sc = rtems_task_create(
    rtems_build_name(' ', 'L', 'O', 'W'),
    PRIORITY_LOW,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_low
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_low, task_low, 0);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name(' ', 'M', 'I', 'D'),
    PRIORITY_MID,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_mid
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_mid, task_mid, 0);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('H', 'I', 'G', 'H'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_high
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_high, task_high, 0);
  ASSERT_SC(sc);

  sc = rtems_task_suspend(task_id_mid);
  ASSERT_SC(sc);

  sc = rtems_task_suspend(task_id_high);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_get(dd, 1, &bd);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_release(bd);
  ASSERT_SC(sc);

  printk("I: try access: 0\n");

  sc = rtems_bdbuf_get(dd, 0, &bd);
  ASSERT_SC(sc);

  printk("I: access: 0\n");

  sc = rtems_task_set_priority(RTEMS_SELF, PRIORITY_IDLE, &cur_prio);
  ASSERT_SC(sc);

  sc = rtems_task_resume(task_id_high);
  ASSERT_SC(sc);

  sc = rtems_task_resume(task_id_mid);
  ASSERT_SC(sc);

  sc = rtems_task_set_priority(RTEMS_SELF, PRIORITY_INIT, &cur_prio);
  ASSERT_SC(sc);

  printk("I: release: 0\n");

  sc = rtems_bdbuf_release(bd);
  ASSERT_SC(sc);

  printk("I: release done: 0\n");

  rtems_task_delete(RTEMS_SELF);
}
Example #15
0
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  unsigned i = 0;

  rtems_test_begink();

  task_id_init = rtems_task_self();

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  disk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, &dd_a);

  disk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, &dd_b);

  sc = rtems_task_create(
    rtems_build_name(' ', 'L', 'O', 'W'),
    PRIORITY_LOW,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_low
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_low, task_low, 0);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('H', 'I', 'G', 'H'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_high
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_high, task_high, 0);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('R', 'E', 'S', 'U'),
    PRIORITY_RESUME,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_resume
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_resume, task_resume, 0);
  ASSERT_SC(sc);

  sc = rtems_task_suspend(task_id_low);
  ASSERT_SC(sc);

  sc = rtems_task_suspend(task_id_high);
  ASSERT_SC(sc);

  for (trig = SUSP; trig <= CONT; ++trig) {
    for (trig_get = GET; trig_get <= READ; ++trig_get) {
      for (low_get = GET; low_get <= READ; ++low_get) {
        for (high_get = GET; high_get <= READ; ++high_get) {
          for (trig_blk = BLK_A0; trig_blk <= BLK_B0; ++trig_blk) {
            for (low_blk = BLK_A0; low_blk <= BLK_B0; ++low_blk) {
              for (high_blk = BLK_A0; high_blk <= BLK_B0; ++high_blk) {
                for (trig_rel = REL; trig_rel <= SYNC; ++trig_rel) {
                  for (low_rel = REL; low_rel <= SYNC; ++low_rel) {
                    for (high_rel = REL; high_rel <= SYNC; ++high_rel) {
                      execute_test(i);
                      ++i;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

  rtems_test_endk();

  exit(0);
}
Example #16
0
/*
 * The test sequence
 */
static
void test( void )
{
  rtems_status_code sc;
  int               rv;
  char              device_name[] = "/dev/sda1";
  uint32_t          block_size;
  rtems_blkdev_bnum block_number;
  rtems_blkdev_bnum blocks_allocated;
  int               file_descriptor;
  uint8_t           fill_pattern = 0;


  sc = rtems_disk_io_initialize();
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  block_size       = 512;
  block_number     = 4 * 2 * 1024;
  blocks_allocated = 8;
  sc               = rtems_sparse_disk_create_and_register(
    "/dev/sda1",
    block_size,
    blocks_allocated,
    block_number,
    fill_pattern
    );
  rtems_test_assert( RTEMS_SUCCESSFUL == sc );

  /* Test reading and writing with sector size 512 and 8 such sectors
   * allocated. Block size will default to 512 */
  test_device_io(
    device_name,
    block_size,
    block_size,
    block_number,
    blocks_allocated,
    fill_pattern
    );

  file_descriptor = open( device_name, O_RDWR );
  rtems_test_assert( 0 <= file_descriptor );

  rv = rtems_disk_fd_set_block_size( file_descriptor,
                                     blocks_allocated * block_size );
  rtems_test_assert( 0 == rv );

  rv = close( file_descriptor );
  rtems_test_assert( 0 == rv );

  /* Block size was increased to 4k. Thus all to allocated disk space
   * corresponds to one block. Repeat the read write tests */
  test_device_io(
    device_name,
    block_size * blocks_allocated,
    block_size,
    block_number,
    1,
    fill_pattern
    );

  rv = unlink( device_name );
  rtems_test_assert( 0 == rv );

  /* Do testing with a statically allocated disk. This permits white box
   * testing */
  test_with_whitebox( device_name );
}
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  size_t i_w = 0;
  size_t i_ac = 0;
  size_t i_rel = 0;
  size_t i_p = 0;

  printk("\n\n*** TEST BLOCK 10 ***\n");

  task_id_init = rtems_task_self();

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = disk_register(BLOCK_SIZE, BLOCK_COUNT, &dev);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('P', 'U', 'R', 'G'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_purger
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_purger, task_purger, 0);
  ASSERT_SC(sc);

  set_task_prio(task_id_purger, PRIORITY_LOW);

  sc = rtems_task_create(
    rtems_build_name('W', 'A', 'I', 'T'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_waiter
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_waiter, task_waiter, 0);
  ASSERT_SC(sc);

  for (i_ac = 0; i_ac < ACCESS_COUNT; ++i_ac) {
    for (i_rel = 0; i_rel < RELEASE_COUNT; ++i_rel) {
      for (i_w = 0; i_w < WAITER_COUNT; ++i_w) {
        printk("test case [access]: %s and %s %s\n", access_assoc_table [i_ac], release_assoc_table [i_rel], waiter_assoc_table [i_w]);
        check_access(access_table [i_ac], release_table [i_rel], waiter_table [i_w]);
      }
    }
  }

  for (i_rel = 0; i_rel < RELEASE_COUNT; ++i_rel) {
    for (i_w = 0; i_w < WAITER_COUNT; ++i_w) {
      printk("test case [intermediate]: %s %s\n", release_assoc_table [i_rel], waiter_assoc_table [i_w]);
      check_intermediate(release_table [i_rel], waiter_table [i_w]);
    }
  }

  for (i_p = 0; i_p < PURGER_COUNT; ++i_p) {
    for (i_w = 0; i_w < WAITER_COUNT; ++i_w) {
      printk("test case [transfer]: %s %s\n", purger_assoc_table [i_p], waiter_assoc_table [i_w]);
      check_transfer(purger_table [i_p], waiter_table [i_w]);
    }
  }

  printk("*** END OF TEST BLOCK 10 ***\n");

  exit(0);
}
Example #18
0
static void test_normal_file_write(
  const char *dev_name,
  const char *mount_dir,
  const char *file_name )
{
  static const rtems_blkdev_stats complete_block_stats = {
    .read_hits            = 0,
    .read_misses          = 0,
    .read_ahead_transfers = 0,
    .read_blocks          = 0,
    .read_errors          = 0,
    .write_transfers      = 1,
    .write_blocks         = 1,
    .write_errors         = 0
  };
  static const rtems_blkdev_stats new_block_stats = {
    .read_hits            = 8,
    .read_misses          = 2,
    .read_ahead_transfers = 0,
    .read_blocks          = 2,
    .read_errors          = 0,
    .write_transfers      = 1,
    .write_blocks         = 4,
    .write_errors         = 0
  };

  int                             rv;
  int                             fd;
  ssize_t                         num_bytes;
  uint8_t                         cluster_buf[SECTOR_SIZE
                                              * SECTORS_PER_CLUSTER];
  uint32_t                        cluster_size = sizeof( cluster_buf );
  off_t                           off;


  memset( cluster_buf, 0xFE, cluster_size );

  format_and_mount( dev_name, mount_dir );

  fd = create_file( file_name );
  rtems_test_assert( fd >= 0 );

  num_bytes = write( fd, cluster_buf, cluster_size );
  rtems_test_assert( (ssize_t) cluster_size == num_bytes );

  off = lseek( fd, 0, SEEK_SET );
  rtems_test_assert( off == 0 );

  reset_block_stats( dev_name, mount_dir );

  /* Write a complete cluster into an existing file space */
  num_bytes = write( fd, cluster_buf, cluster_size );
  rtems_test_assert( (ssize_t) cluster_size == num_bytes );

  check_block_stats( dev_name, mount_dir, &complete_block_stats );
  reset_block_stats( dev_name, mount_dir );

  num_bytes = write( fd, cluster_buf, cluster_size );
  rtems_test_assert( (ssize_t) cluster_size == num_bytes );

  /* Write a new partial cluster into a new file space */
  num_bytes = write( fd, cluster_buf, 1 );
  rtems_test_assert( num_bytes == 1 );

  check_block_stats( dev_name, mount_dir, &new_block_stats );

  rv = close( fd );
  rtems_test_assert( 0 == rv );

  rv = unmount( mount_dir );
  rtems_test_assert( 0 == rv );
}

static void test_fat12_root_directory_write( const char *dev_name,
  const char                                            *mount_dir,
  const char                                            *file_name )
{
  static const rtems_blkdev_stats fat12_root_dir_stats = {
    .read_hits            = 11,
    .read_misses          = 2,
    .read_ahead_transfers = 0,
    .read_blocks          = 2,
    .read_errors          = 0,
    .write_transfers      = 1,
    .write_blocks         = 1,
    .write_errors         = 0
  };

  int                             fd;
  int                             rv;


  format_and_mount( dev_name, mount_dir );

  reset_block_stats( dev_name, mount_dir );

  fd = create_file( file_name );
  rtems_test_assert( fd >= 0 );

  rv = close( fd );
  rtems_test_assert( rv == 0 );

  check_block_stats( dev_name, mount_dir, &fat12_root_dir_stats );

  rv = unmount( mount_dir );
  rtems_test_assert( rv == 0 );
}

static void test( void )
{
  static const char dev_name[]  = "/dev/sda";
  static const char mount_dir[] = "/mnt";
  static const char file_name[] = "/mnt/file.txt";

  rtems_status_code sc;
  int               rv;


  sc = rtems_disk_io_initialize();
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  rv = mkdir( mount_dir, S_IRWXU | S_IRWXG | S_IRWXO );
  rtems_test_assert( 0 == rv );

  /* A 1.44 MB disk */
  sc = rtems_sparse_disk_create_and_register(
    dev_name,
    SECTOR_SIZE,
    64,
    2880,
    0
    );
  rtems_test_assert( RTEMS_SUCCESSFUL == sc );

  test_fat12_root_directory_write( dev_name, mount_dir, file_name );

  test_normal_file_write( dev_name, mount_dir, file_name );

  rv = unlink( dev_name );
  rtems_test_assert( rv == 0 );
}

static void Init( rtems_task_argument arg )
{
  TEST_BEGIN();

  test();

  TEST_END();
  rtems_test_exit( 0 );
}