示例#1
0
static ssize_t rtems_blkdev_imfs_write(
  rtems_libio_t *iop,
  const void *buffer,
  size_t count
)
{
  int rv;
  rtems_blkdev_imfs_context *ctx = IMFS_generic_get_context_by_iop(iop);
  rtems_disk_device *dd = &ctx->dd;
  ssize_t remaining = (ssize_t) count;
  off_t offset = iop->offset;
  ssize_t block_size = (ssize_t) rtems_disk_get_block_size(dd);
  rtems_blkdev_bnum block = (rtems_blkdev_bnum) (offset / block_size);
  ssize_t block_offset = (ssize_t) (offset % block_size);
  const char *src = buffer;

  while (remaining > 0) {
    rtems_status_code sc;
    rtems_bdbuf_buffer *bd;

    if (block_offset == 0 && remaining >= block_size) {
       sc = rtems_bdbuf_get(dd, block, &bd);
    } else {
       sc = rtems_bdbuf_read(dd, block, &bd);
    }

    if (sc == RTEMS_SUCCESSFUL) {
      ssize_t copy = block_size - block_offset;

      if (copy > remaining) {
        copy = remaining;
      }

      memcpy((char *) bd->buffer + block_offset, src, (size_t) copy);

      sc = rtems_bdbuf_release_modified(bd);
      if (sc == RTEMS_SUCCESSFUL) {
        block_offset = 0;
        remaining -= copy;
        src += copy;
        ++block;
      } else {
        remaining = -1;
      }
    } else {
      remaining = -1;
    }
  }

  if (remaining >= 0) {
    iop->offset += count;
    rv = (ssize_t) count;
  } else {
    errno = EIO;
    rv = -1;
  }

  return rv;
}
示例#2
0
文件: init.c 项目: 0871087123/rtems
static int handler_fdatasync(
  rtems_libio_t *iop
)
{
  test_state *state = IMFS_generic_get_context_by_iop(iop);

  rtems_test_assert(*state == TEST_FSYNC);
  *state = TEST_FDATASYNC;

  return 0;
}
示例#3
0
文件: init.c 项目: 0871087123/rtems
static int handler_close(
  rtems_libio_t *iop
)
{
  test_state *state = IMFS_generic_get_context_by_iop(iop);

  rtems_test_assert(*state == TEST_FCNTL);
  *state = TEST_CLOSED;

  return 0;
}
示例#4
0
文件: init.c 项目: 0871087123/rtems
static int handler_fcntl(
  rtems_libio_t *iop,
  int cmd
)
{
  test_state *state = IMFS_generic_get_context_by_iop(iop);

  rtems_test_assert(*state == TEST_FDATASYNC);
  *state = TEST_FCNTL;

  return 0;
}
示例#5
0
文件: init.c 项目: 0871087123/rtems
static int handler_ftruncate(
  rtems_libio_t *iop,
  off_t length
)
{
  test_state *state = IMFS_generic_get_context_by_iop(iop);

  rtems_test_assert(*state == TEST_LSEEK);
  *state = TEST_FTRUNCATE;

  return 0;
}
示例#6
0
文件: init.c 项目: 0871087123/rtems
static ssize_t handler_write(
  rtems_libio_t *iop,
  const void *buffer,
  size_t count
)
{
  test_state *state = IMFS_generic_get_context_by_iop(iop);

  rtems_test_assert(*state == TEST_READ);
  *state = TEST_WRITE;

  return 0;
}
示例#7
0
文件: init.c 项目: 0871087123/rtems
static ssize_t handler_read(
  rtems_libio_t *iop,
  void *buffer,
  size_t count
)
{
  test_state *state = IMFS_generic_get_context_by_iop(iop);

  rtems_test_assert(*state == TEST_OPEN);
  *state = TEST_READ;

  return 0;
}
示例#8
0
文件: init.c 项目: 0871087123/rtems
static off_t handler_lseek(
  rtems_libio_t *iop,
  off_t length,
  int whence
)
{
  test_state *state = IMFS_generic_get_context_by_iop(iop);

  rtems_test_assert(*state == TEST_IOCTL);
  *state = TEST_LSEEK;

  return 0;
}
示例#9
0
文件: init.c 项目: 0871087123/rtems
static int handler_ioctl(
  rtems_libio_t *iop,
  uint32_t request,
  void *buffer
)
{
  test_state *state = IMFS_generic_get_context_by_iop(iop);

  rtems_test_assert(*state == TEST_WRITE);
  *state = TEST_IOCTL;

  return 0;
}
示例#10
0
文件: init.c 项目: gedare/rtems
static int handler_close(rtems_libio_t *iop)
{
  test_context *ctx;

  ctx = IMFS_generic_get_context_by_iop(iop);

  if (rtems_libio_iop_is_append(iop)) {
    ++ctx->append_count;
  } else {
    ++ctx->no_append_count;
  }

  return 0;
}
示例#11
0
文件: init.c 项目: 0871087123/rtems
static int handler_open(
  rtems_libio_t *iop,
  const char *path,
  int oflag,
  mode_t mode
)
{
  test_state *state = IMFS_generic_get_context_by_iop(iop);

  rtems_test_assert(*state == TEST_FSTAT_OPEN);
  *state = TEST_OPEN;

  return 0;
}
示例#12
0
static ssize_t i2c_dev_write(
  rtems_libio_t *iop,
  const void *buffer,
  size_t count
)
{
  i2c_dev *dev = IMFS_generic_get_context_by_iop(iop);
  ssize_t n;

  n = (*dev->write)(dev, buffer, count, iop->offset);
  if (n > 0) {
    iop->offset += n;
  }

  return n;
}
示例#13
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;
}
示例#14
0
static int i2c_dev_ioctl(
  rtems_libio_t *iop,
  ioctl_command_t command,
  void *arg
)
{
  i2c_dev *dev = IMFS_generic_get_context_by_iop(iop);
  int err;

  err = (*dev->ioctl)(dev, command, arg);

  if (err == 0) {
    return 0;
  } else {
    rtems_set_errno_and_return_minus_one(-err);
  }
}
示例#15
0
static int rtems_blkdev_imfs_ioctl(
  rtems_libio_t *iop,
  uint32_t request,
  void *buffer
)
{
  int rv = 0;

  if (request != RTEMS_BLKIO_REQUEST) {
    rtems_blkdev_imfs_context *ctx = IMFS_generic_get_context_by_iop(iop);
    rtems_disk_device *dd = &ctx->dd;

    rv = (*dd->ioctl)(dd, request, buffer);
  } else {
    /*
     * It is not allowed to directly access the driver circumventing the cache.
     */
    errno = EINVAL;
    rv = -1;
  }

  return rv;
}