Esempio n. 1
0
/* msdos_file_stat --
 *
 * PARAMETERS:
 *     loc - node description
 *     buf - stat buffer provided by user
 *
 * RETURNS:
 *     RC_OK on success, or -1 if error occured (errno set appropriately)
 */
int
msdos_file_stat(
    const rtems_filesystem_location_info_t *loc,
    struct stat *buf
)
{
    rtems_status_code  sc = RTEMS_SUCCESSFUL;
    msdos_fs_info_t   *fs_info = loc->mt_entry->fs_info;
    fat_file_fd_t     *fat_fd = loc->node_access;
    uint32_t           cl_mask = fs_info->fat.vol.bpc - 1;

    sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
                                MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    if (sc != RTEMS_SUCCESSFUL)
        rtems_set_errno_and_return_minus_one(EIO);

    buf->st_dev = rtems_disk_get_device_identifier(fs_info->fat.vol.dd);
    buf->st_ino = fat_fd->ino;
    buf->st_mode  = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
    buf->st_rdev = 0ll;
    buf->st_size = fat_fd->fat_file_size;
    buf->st_blocks = ((fat_fd->fat_file_size + cl_mask) & ~cl_mask)
      >> FAT_SECTOR512_BITS;
    buf->st_blksize = fs_info->fat.vol.bpc;
    buf->st_atime = fat_fd->mtime;
    buf->st_ctime = fat_fd->ctime;
    buf->st_mtime = fat_fd->mtime;

    rtems_semaphore_release(fs_info->vol_sema);
    return RC_OK;
}
Esempio n. 2
0
static int rtems_blkdev_imfs_fstat(
  const rtems_filesystem_location_info_t *loc,
  struct stat *buf
)
{
  rtems_blkdev_imfs_context *ctx =
    IMFS_generic_get_context_by_location(loc);
  rtems_disk_device *dd = &ctx->dd;

  buf->st_rdev = rtems_disk_get_device_identifier(dd);
  buf->st_blksize = rtems_disk_get_block_size(dd);
  buf->st_blocks = rtems_disk_get_block_count(dd);

  return IMFS_stat(loc, buf);
}
Esempio n. 3
0
static void test_blkdev_imfs_parameters(void)
{
  rtems_status_code sc;
  int rv;
  ramdisk *rd;
  int fd;
  rtems_disk_device *dd;
  struct stat st;

  rd = ramdisk_allocate(NULL, BLOCK_SIZE, BLOCK_COUNT, false);
  rtems_test_assert(rd != NULL);

  ramdisk_enable_free_at_delete_request(rd);

  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  ASSERT_SC(sc);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    1,
    BLOCK_COUNT - 1
  );
  ASSERT_SC(sc);

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

  rv = fstat(fd, &st);
  rtems_test_assert(rv == 0);

  rv = rtems_disk_fd_get_disk_device(fd, &dd);
  rtems_test_assert(rv == 0);

  rtems_test_assert(rtems_disk_get_driver_data(dd) == rd);
  rtems_test_assert(rtems_disk_get_device_identifier(dd) == st.st_rdev);
  rtems_test_assert(rtems_disk_get_media_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_begin(dd) == 0);
  rtems_test_assert(rtems_disk_get_block_count(dd) == BLOCK_COUNT);

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

  fd = open(rda1, O_RDWR);
  rtems_test_assert(fd >= 0);

  rv = fstat(fd, &st);
  rtems_test_assert(rv == 0);

  rv = rtems_disk_fd_get_disk_device(fd, &dd);
  rtems_test_assert(rv == 0);

  rtems_test_assert(rtems_disk_get_driver_data(dd) == rd);
  rtems_test_assert(rtems_disk_get_device_identifier(dd) == st.st_rdev);
  rtems_test_assert(rtems_disk_get_media_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_size(dd) == BLOCK_SIZE);
  rtems_test_assert(rtems_disk_get_block_begin(dd) == 1);
  rtems_test_assert(rtems_disk_get_block_count(dd) == BLOCK_COUNT - 1);

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

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

  rv = unlink(rda);
  rtems_test_assert(rv == 0);
}
Esempio n. 4
0
rtems_status_code rtems_bdpart_register(
  const char *disk_name,
  const rtems_bdpart_partition *pt,
  size_t count
)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_status_code esc = RTEMS_SUCCESSFUL;
  rtems_device_major_number major = 0;
  rtems_device_minor_number minor = 0;
  rtems_blkdev_bnum disk_end = 0;
  dev_t disk = 0;
  dev_t logical_disk = 0;
  char *logical_disk_name = NULL;
  char *logical_disk_marker = NULL;
  size_t disk_name_size = strlen( disk_name);
  size_t i = 0;
  int fd = -1;
  const rtems_disk_device *dd = NULL;

  /* Get disk data */
  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
  if (sc != RTEMS_SUCCESSFUL) {
    return sc;
  }
  disk = rtems_disk_get_device_identifier( dd);
  close( fd);

  /* Get the disk device identifier */
  rtems_filesystem_split_dev_t( disk, major, minor);

  /* Create logical disk name */
  logical_disk_name = malloc( disk_name_size + RTEMS_BDPART_NUMBER_SIZE);
  if (logical_disk_name == NULL) {
    return RTEMS_NO_MEMORY;
  }
  strncpy( logical_disk_name, disk_name, disk_name_size);
  logical_disk_marker = logical_disk_name + disk_name_size;

  /* Create a logical disk for each partition */
  for (i = 0; i < count; ++i) {
    const rtems_bdpart_partition *p = pt + i;
    int rv = 0;

    /* New minor number */
    ++minor;

    /* Create a new device identifier */
    logical_disk = rtems_filesystem_make_dev_t( major, minor);

    /* Set partition number for logical disk name */
    rv = snprintf( logical_disk_marker, RTEMS_BDPART_NUMBER_SIZE, "%zu", i + 1);
    if (rv >= RTEMS_BDPART_NUMBER_SIZE) {
      esc = RTEMS_INVALID_NAME;
      goto cleanup;
    }

    /* Create logical disk */
    sc = rtems_disk_create_log(
      logical_disk,
      disk,
      p->begin,
      p->end - p->begin,
      logical_disk_name
    );
    if (sc != RTEMS_SUCCESSFUL) {
      esc = sc;
      goto cleanup;
    }
  }

cleanup:

  free( logical_disk_name);

  return esc;
}
Esempio n. 5
0
static int
test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
{
    dev_t             dev = rtems_disk_get_device_identifier(dd);
    rtems_status_code rc;
    bdbuf_test_msg    msg;
    size_t            msg_size;

    switch (req)
    {
        case RTEMS_BLKIO_REQUEST:
        {
            rtems_blkdev_request   *r = argp;
            rtems_blkdev_sg_buffer *sg;
            unsigned int            i;

            printk("DISK_DRV: %s ",
                   r->req == RTEMS_BLKDEV_REQ_READ ? "R" :
                   r->req == RTEMS_BLKDEV_REQ_WRITE ? "W" : "?");
            for (i = 0, sg = r->bufs; i < r->bufnum; i++, sg++)
            {
                printk("[%d] ", sg->block);
            }
            printk("\n");
            break;
        }

        default:
            printk("%s() Unexpected request comes %u\n",
                   __FUNCTION__, req);
            return -1;
    }

    memset(&msg, 0, sizeof(msg));
    msg.type = BDBUF_TEST_MSG_TYPE_DRIVER_REQ;
    msg.val.driver_req.dev = dev;
    msg.val.driver_req.req = req;
    msg.val.driver_req.argp = argp;

    rc = rtems_message_queue_send(testq_id, &msg, sizeof(msg));
    if (rc != RTEMS_SUCCESSFUL)
    {
        printf("Error while sending a message to Test task: %u\n", rc);
        return -1;
    }

    /* Wait for a reply from the test task */
    msg_size = sizeof(msg);
    rc = rtems_message_queue_receive(drvq_id, &msg, &msg_size,
                                     RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    if (rc != RTEMS_SUCCESSFUL)
    {
        printf("Error while reading a message from Test task: %u\n", rc);
        return rc;
    }
    if (msg.type != BDBUF_TEST_MSG_TYPE_DRIVER_REPLY)
    {
        printf("Unexpected message comes to test disk driver: %d\n",
               msg.type);
        return -1;
    }

    if (msg.val.driver_reply.ret_val != 0)
    {
        errno = msg.val.driver_reply.ret_errno;
    }
    else
    {
        rtems_blkdev_request *r = (rtems_blkdev_request *)argp;

        r->req_done(r->done_arg, msg.val.driver_reply.res_status);
    }

    return msg.val.driver_reply.ret_val;
}