Ejemplo n.º 1
0
int
rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
{
    rtems_status_code  sc;
    int                rc = 0;

    switch (req)
    {
        case RTEMS_BLKIO_GETMEDIABLKSIZE:
            *(uint32_t *) argp = dd->media_block_size;
            break;

        case RTEMS_BLKIO_GETBLKSIZE:
            *(uint32_t *) argp = dd->block_size;
            break;

        case RTEMS_BLKIO_SETBLKSIZE:
            sc = rtems_bdbuf_set_block_size(dd, *(uint32_t *) argp);
            if (sc != RTEMS_SUCCESSFUL) {
                errno = EIO;
                rc = -1;
            }
            break;

        case RTEMS_BLKIO_GETSIZE:
            *(rtems_blkdev_bnum *) argp = dd->size;
            break;

        case RTEMS_BLKIO_SYNCDEV:
            sc = rtems_bdbuf_syncdev(dd);
            if (sc != RTEMS_SUCCESSFUL) {
                errno = EIO;
                rc = -1;
            }
            break;

        case RTEMS_BLKIO_GETDISKDEV:
            *(rtems_disk_device **) argp = dd;
            break;

        case RTEMS_BLKIO_PURGEDEV:
            rtems_bdbuf_purge_dev(dd);
            break;

        case RTEMS_BLKIO_GETDEVSTATS:
            rtems_bdbuf_get_device_stats(dd, (rtems_blkdev_stats *) argp);
            break;

        case RTEMS_BLKIO_RESETDEVSTATS:
            rtems_bdbuf_reset_device_stats(dd);
            break;

        default:
            errno = EINVAL;
            rc = -1;
            break;
    }

    return rc;
}
Ejemplo n.º 2
0
int
rtems_rfs_buffer_sync (rtems_rfs_file_system* fs)
{
  int result = 0;
#if RTEMS_RFS_USE_LIBBLOCK
  rtems_status_code sc;
#endif

  if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SYNC))
    printf ("rtems-rfs: buffer-sync: syncing\n");

  /*
   * @todo Split in the separate files for each type.
   */
#if RTEMS_RFS_USE_LIBBLOCK
  sc = rtems_bdbuf_syncdev (rtems_rfs_fs_device (fs));
  if (sc != RTEMS_SUCCESSFUL)
  {
    if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SYNC))
      printf ("rtems-rfs: buffer-sync: device sync failed: %s\n",
              rtems_status_text (sc));
    result = EIO;
  }
  rtems_disk_release (fs->disk);
#else
  if (fsync (fs->device) < 0)
  {
    result = errno;
    if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CLOSE))
      printf ("rtems-rfs: buffer-sync: file sync failed: %d: %s\n",
              result, strerror (result));
  }
#endif
  return result;
}
Ejemplo n.º 3
0
static void
bdbuf_tests_task_0_test_7 (bdbuf_task_control* tc)
{
  rtems_status_code   sc;
  bool                passed;
  int                 i;
  rtems_bdbuf_buffer* bd;
  rtems_chain_control buffers;
  dev_t               device;

  /*
   * Set task control's passed to false to handle a timeout.
   */
  tc->passed = false;
  passed = true;

  /*
   * Clear any disk settings.
   */
  bdbuf_clear_disk_driver_watch (tc);
  bdbuf_set_disk_driver_action (tc, BDBUF_DISK_NOOP);

  device = rtems_filesystem_make_dev_t (tc->major, tc->minor);

  /*
   * Get the blocks 0 -> 4 and hold them.
   */
  rtems_chain_initialize_empty (&buffers);

  for (i = 0; (i < 5) && passed; i++)
  {
    bdbuf_test_printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i);
    sc = rtems_bdbuf_get (device, i, &bd);
    if (!bdbuf_test_print_sc (sc, true))
      passed = false;

    rtems_chain_append (&buffers, &bd->link);
  }

  for (i = 0; (i < 5) && passed; i++)
  {
    bdbuf_test_printf ("%s: rtems_bdbuf_release_modified[%d]: ",
                       tc->name, i);
    bd = (rtems_bdbuf_buffer*) rtems_chain_get (&buffers);
    passed = bdbuf_test_print_sc (rtems_bdbuf_release_modified (bd),
                                  true);
  }

  if (passed)
  {
    bdbuf_test_printf ("%s: rtems_bdbuf_syncdev[%d:%d]: ",
                       tc->name, i,
                       rtems_filesystem_dev_major_t (device),
                       rtems_filesystem_dev_minor_t (device));
    passed = bdbuf_test_print_sc (rtems_bdbuf_syncdev (device), true);
  }

  tc->passed = passed;
  tc->test = 0;
}
Ejemplo n.º 4
0
int
rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
{
    size_t            *arg_size = argp;
    int                rc = 0;

    switch (req)
    {
        case RTEMS_BLKIO_GETMEDIABLKSIZE:
            *arg_size = dd->media_block_size;
            break;

        case RTEMS_BLKIO_GETBLKSIZE:
            *arg_size = dd->block_size;
            break;

        case RTEMS_BLKIO_SETBLKSIZE:
            dd->block_size = *arg_size;
            break;

        case RTEMS_BLKIO_GETSIZE:
            *arg_size = dd->size;
            break;

        case RTEMS_BLKIO_SYNCDEV:
        {
            rtems_status_code sc = rtems_bdbuf_syncdev(dd);
            if (sc != RTEMS_SUCCESSFUL) {
                errno = EIO;
                rc = -1;
            }
            break;
        }

        case RTEMS_BLKIO_GETDISKDEV:
        {
            rtems_disk_device **dd_ptr = argp;
            *dd_ptr = dd;
            break;
        }

        default:
            errno = EINVAL;
            rc = -1;
            break;
    }

    return rc;
}
Ejemplo n.º 5
0
/* fat_shutdown_drive --
 *     Free all allocated resources and synchronize all necessary data
 *
 * PARAMETERS:
 *     mt_entry - mount table entry
 *
 * RETURNS:
 *     RC_OK on success, or -1 if error occured
 *     and errno set appropriately
 */
int
fat_shutdown_drive(rtems_filesystem_mount_table_entry_t *mt_entry)
{
    int            rc = RC_OK;
    fat_fs_info_t *fs_info = mt_entry->fs_info;
    int            i = 0;

    if (fs_info->vol.type & FAT_FAT32)
    {
        rc = fat_fat32_update_fsinfo_sector(mt_entry, fs_info->vol.free_cls,
                                            fs_info->vol.next_cl);
        if ( rc != RC_OK )
            rc = -1;
    }

    fat_buf_release(fs_info);

    if (rtems_bdbuf_syncdev(fs_info->vol.dev) != RTEMS_SUCCESSFUL)
        rc = -1;

    for (i = 0; i < FAT_HASH_SIZE; i++)
    {
        Chain_Node    *node = NULL;
        Chain_Control *the_chain = fs_info->vhash + i;

        while ( (node = _Chain_Get(the_chain)) != NULL )
            free(node);
    }

    for (i = 0; i < FAT_HASH_SIZE; i++)
    {
        Chain_Node    *node = NULL;
        Chain_Control *the_chain = fs_info->rhash + i;

        while ( (node = _Chain_Get(the_chain)) != NULL )
            free(node);
    }

    free(fs_info->vhash);
    free(fs_info->rhash);

    free(fs_info->uino);
    free(fs_info->sec_buf);
    rtems_disk_release(fs_info->vol.dd);

    if (rc)
        errno = EIO;
    return rc;
}
Ejemplo n.º 6
0
static int rtems_blkdev_imfs_fsync_or_fdatasync(
  rtems_libio_t *iop
)
{
  int rv = 0;
  rtems_blkdev_imfs_context *ctx = IMFS_generic_get_context_by_iop(iop);
  rtems_disk_device *dd = &ctx->dd;
  rtems_status_code sc = rtems_bdbuf_syncdev(dd);

  if (sc != RTEMS_SUCCESSFUL) {
    errno = EIO;
    rv = -1;
  }

  return rv;
}
Ejemplo n.º 7
0
static IMFS_jnode_t *rtems_blkdev_imfs_destroy(IMFS_jnode_t *node)
{
  rtems_blkdev_imfs_context *ctx = IMFS_generic_get_context_by_node(node);
  rtems_disk_device *dd = &ctx->dd;

  rtems_bdbuf_syncdev(dd);
  rtems_bdbuf_purge_dev(dd);

  if (ctx->fd >= 0) {
    close(ctx->fd);
  } else {
    (*dd->ioctl)(dd, RTEMS_BLKIO_DELETED, NULL);
  }

  free(ctx);

  return node;
}
Ejemplo n.º 8
0
static void execute_test(unsigned i)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_bdbuf_buffer *bd = NULL;
  bool suspend = false;

  print(
    1,
    "[%05u]T(%c,%c,%s,%c)L(%c,%s,%c)H(%c,%s,%c)\n",
    i,
    trig_style_desc [trig],
    get_type_desc [trig_get],
    blk_kind_desc [trig_blk],
    rel_type_desc [trig_rel],
    get_type_desc [low_get],
    blk_kind_desc [low_blk],
    rel_type_desc [low_rel],
    get_type_desc [high_get],
    blk_kind_desc [high_blk],
    rel_type_desc [high_rel]
  );

  set_task_prio(task_id_low, PRIORITY_LOW);

  finish_low = false;
  finish_high = false;

  sc = rtems_task_resume(task_id_low);
  ASSERT_SC(sc);

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

  sc = rtems_bdbuf_get(dd_b, 0, &bd);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL && bd->dd == dd_b && bd->block == 0);

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

  switch (trig) {
    case SUSP:
      suspend = true;
      break;
    case CONT:
      suspend = false;
      break;
    default:
      rtems_test_assert(false);
      break;
  }

  print(2, "TG\n");
  bd = get(trig_get, trig_blk);

  if (suspend) {
    print(2, "S\n");
    resume = RESUME_IMMEDIATE;
    sc = rtems_task_suspend(RTEMS_SELF);
    ASSERT_SC(sc);
  }
  resume = RESUME_FINISH;

  print(2, "TR\n");
  rel(bd, trig_rel);

  sc = rtems_task_suspend(RTEMS_SELF);
  ASSERT_SC(sc);

  print(2, "F\n");

  sc = rtems_bdbuf_syncdev(dd_a);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_syncdev(dd_b);
  ASSERT_SC(sc);
}
Ejemplo n.º 9
0
static void
bdbuf_tests_task_0_test_8 (bdbuf_task_control* tc)
{
  rtems_status_code   sc;
  bool                passed;
  int                 i;
  rtems_bdbuf_buffer* bd;
  rtems_chain_control buffers;
  rtems_chain_node*   node;
  rtems_chain_node*   pnode;

  /*
   * Set task control's passed to false to handle a timeout.
   */
  tc->passed = false;
  passed = true;

  /*
   * Clear any disk settings.
   */
  bdbuf_clear_disk_driver_watch (tc);
  bdbuf_set_disk_driver_action (tc, BDBUF_DISK_NOOP);

  /*
   * Get the blocks 0 -> 4 and hold them.
   */
  rtems_chain_initialize_empty (&buffers);

  for (i = 0; (i < 5) && passed; i++)
  {
    bdbuf_test_printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i);
    sc = rtems_bdbuf_get (tc->dd, i, &bd);
    if (!bdbuf_test_print_sc (sc, true))
      passed = false;

    rtems_chain_append (&buffers, &bd->link);
  }

  node = rtems_chain_tail (&buffers);
  node = node->previous;

  bd = (rtems_bdbuf_buffer*) node;
  pnode = node->previous;
  rtems_chain_extract (node);
  node = pnode;
  bdbuf_test_printf ("%s: rtems_bdbuf_release_modified[4]: ", tc->name);
  passed = bdbuf_test_print_sc (rtems_bdbuf_release_modified (bd), true);

  bd = (rtems_bdbuf_buffer*) node;
  pnode = node->previous;
  rtems_chain_extract (node);
  node = pnode;
  bdbuf_test_printf ("%s: rtems_bdbuf_release_modified[3]: ", tc->name);
  passed = bdbuf_test_print_sc (rtems_bdbuf_release_modified (bd), true);

  for (i = 0; (i < 3) && passed; i++)
  {
    bdbuf_test_printf ("%s: rtems_bdbuf_release_modified[%d]: ",
                       tc->name, i);
    bd = (rtems_bdbuf_buffer*) rtems_chain_get (&buffers);
    passed = bdbuf_test_print_sc (rtems_bdbuf_release_modified (bd),
                                  true);
  }

  if (passed)
  {
    /*
     * Check the block order.
     */
    bdbuf_set_disk_driver_action (tc, BDBUF_DISK_BLOCKS_INORDER);

    bdbuf_test_printf ("%s: rtems_bdbuf_syncdev[%d:%d]: checking order\n",
                       tc->name, i,
                       tc->major,
                       tc->minor);
    sc = rtems_bdbuf_syncdev (tc->dd);
    bdbuf_test_printf ("%s: rtems_bdbuf_syncdev[%d:%d]: ",
                       tc->name, i,
                       tc->major,
                       tc->minor);
    passed = bdbuf_test_print_sc (sc, true);
  }

  tc->passed = passed;
  tc->test = 0;
}