Esempio n. 1
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. 2
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. 3
0
rtems_status_code rtems_blkdev_create_partition(
  const char *partition,
  const char *device,
  rtems_blkdev_bnum block_begin,
  rtems_blkdev_bnum block_count
)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  int fd = open(device, O_RDWR);

  if (fd >= 0) {
    int rv;
    struct stat st;

    rv = fstat(fd, &st);
    if (rv == 0 && S_ISBLK(st.st_mode)) {
      rtems_disk_device *dd;

      rv = ioctl(fd, RTEMS_BLKIO_GETDISKDEV, &dd);
      if (rv == 0) {
        rtems_blkdev_bnum device_block_count = rtems_disk_get_block_count(dd);

        if (
          block_begin < device_block_count
            && block_count > 0
            && block_count <= device_block_count - block_begin
        ) {
          rtems_blkdev_imfs_context *ctx = malloc(sizeof(*ctx));

          if (ctx != NULL) {
            memcpy(&ctx->dd, dd, sizeof(ctx->dd));

            ctx->dd.start = block_begin;
            ctx->dd.size = block_count;
            ctx->fd = fd;

            rv = IMFS_make_generic_node(
              partition,
              S_IFBLK | S_IRWXU | S_IRWXG | S_IRWXO,
              &rtems_blkdev_imfs_control,
              ctx
            );

            if (rv != 0) {
              free(ctx);
              sc = RTEMS_UNSATISFIED;
            }
          } else {
            sc = RTEMS_NO_MEMORY;
          }
        } else {
          sc = RTEMS_INVALID_NUMBER;
        }
      } else {
        sc = RTEMS_NOT_IMPLEMENTED;
      }
    } else {
      sc = RTEMS_INVALID_NODE;
    }

    if (sc != RTEMS_SUCCESSFUL) {
      close(fd);
    }
  } else {
    sc = RTEMS_INVALID_ID;
  }

  return sc;
}