static rtems_status_code disk_register( uint32_t block_size, rtems_blkdev_bnum block_count, dev_t *dev_ptr ) { rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_device_major_number major = 0; dev_t dev = 0; sc = rtems_io_register_driver(0, &disk_ops, &major); ASSERT_SC(sc); dev = rtems_filesystem_make_dev_t(major, 0); sc = rtems_disk_create_phys( dev, block_size, block_count, disk_ioctl, NULL, NULL ); ASSERT_SC(sc); *dev_ptr = dev; return RTEMS_SUCCESSFUL; }
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); }
static void disk_register( uint32_t block_size, rtems_blkdev_bnum block_count, rtems_disk_device **dd_ptr ) { rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_device_major_number major = 0; dev_t dev = 0; sc = rtems_io_register_driver(0, &disk_ops, &major); ASSERT_SC(sc); dev = rtems_filesystem_make_dev_t(major, 0); sc = rtems_disk_create_phys( dev, block_size, block_count, disk_ioctl, NULL, NULL ); ASSERT_SC(sc); *dd_ptr = rtems_disk_obtain(dev); rtems_test_assert(*dd_ptr!= NULL); }
static void test_block_io_control_api(dev_t dev, ramdisk *rd) { rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_disk_device *dd = NULL; const rtems_disk_device *fd_dd = NULL; int fd = -1; int rv = -1; uint32_t value = 0; rtems_blkdev_bnum block_count = 0; sc = rtems_disk_create_phys(dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, rd, "/dev/rda"); ASSERT_SC(sc); dd = rtems_disk_obtain(dev); rtems_test_assert(dd != NULL); fd = open("/dev/rda", O_RDWR); rtems_test_assert(fd >= 0); value = 0; rv = rtems_disk_fd_get_media_block_size(fd, &value); rtems_test_assert(rv == 0); rtems_test_assert(value == BLOCK_SIZE); value = 0; rv = rtems_disk_fd_get_block_size(fd, &value); rtems_test_assert(rv == 0); rtems_test_assert(value == BLOCK_SIZE); value = 1024; rv = rtems_disk_fd_set_block_size(fd, value); rtems_test_assert(rv == 0); value = 0; rv = rtems_disk_fd_get_block_size(fd, &value); rtems_test_assert(rv == 0); rtems_test_assert(value == 1024); block_count = 0; rv = rtems_disk_fd_get_block_count(fd, &block_count); rtems_test_assert(rv == 0); rtems_test_assert(block_count == BLOCK_COUNT); rv = rtems_disk_fd_get_disk_device(fd, &fd_dd); rtems_test_assert(rv == 0); rtems_test_assert(fd_dd == dd); rv = rtems_disk_fd_sync(fd); rtems_test_assert(rv == 0); rv = close(fd); rtems_test_assert(rv == 0); sc = rtems_disk_release(dd); ASSERT_SC(sc); sc = rtems_disk_delete(dev); ASSERT_SC(sc); }
/* 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; }
/** * 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; }
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; }
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); }
/* * Test the compatibility with a genuine MS Windows FAT file system. */ static void test_compatibility( void ) { int rc; rtems_status_code sc; dev_t dev; char diskpath[] = "/dev/ramdisk1"; rtems_dosfs_mount_options mount_opts; rtems_device_major_number major; FILE *fp; int buffer; unsigned int index_file = 0; unsigned int index_char; unsigned int offset; char content_buf[MAX_NAME_LENGTH + strlen( MOUNT_DIR ) + 1]; char file_path[MAX_NAME_LENGTH + strlen( MOUNT_DIR ) + 1]; DIR *dir_stream; struct dirent *dp; mount_opts.converter = rtems_dosfs_create_utf8_converter( "CP850" ); rtems_test_assert( mount_opts.converter != NULL ); sc = rtems_io_register_driver( 0, &ramdisk_ops, &major ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); dev = rtems_filesystem_make_dev_t( major, 1 ); sc = rtems_disk_create_phys( dev, BLOCK_SIZE, BLOCK_COUNT, ramdisk_ioctl, &disk_image, diskpath ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); rc = mount_and_make_target_path( diskpath, MOUNT_DIR, RTEMS_FILESYSTEM_TYPE_DOSFS, RTEMS_FILESYSTEM_READ_WRITE, &mount_opts ); rtems_test_assert( rc == 0 ); dir_stream = opendir( MOUNT_DIR ); rtems_test_assert( dir_stream != NULL ); dp = readdir( dir_stream ); rtems_test_assert( dp != NULL ); while ( dp != NULL ) { index_char = 0; size_t len = strlen( filenames[index_file] ); if ( filenames[index_file][len - 1] == '.' ) rtems_test_assert( ( len - 1 ) == dp->d_namlen ); else rtems_test_assert( len == dp->d_namlen ); rtems_test_assert( 0 == memcmp( &filenames[index_file][0], &dp->d_name[0], dp->d_namlen ) ); snprintf( file_path, sizeof( file_path ), "%s/%s", MOUNT_DIR, filenames[index_file] ); fp = fopen( file_path, "r" ); rtems_test_assert( fp != NULL ); /* These files should contain their own file names. */ while ( ( buffer = fgetc( fp ) ) != EOF ) { content_buf[index_char] = buffer; ++index_char; } if ( 0 == strncmp( content_buf, UTF8_BOM, UTF8_BOM_SIZE ) ) offset = UTF8_BOM_SIZE; else offset = 0; rtems_test_assert( 0 == memcmp( filenames[index_file], &content_buf[offset], index_char - offset ) ); rc = fclose( fp ); rtems_test_assert( rc == 0 ); ++index_file; dp = readdir( dir_stream ); } rtems_test_assert( index_file == FILES_FILENAMES_NUMBER_OF ); rc = closedir( dir_stream ); rtems_test_assert( rc == 0 ); rc = unmount( MOUNT_DIR ); rtems_test_assert( rc == 0 ); }