rtems_status_code rtems_sparse_disk_create_and_register( const char *device_file_name, uint32_t media_block_size, rtems_blkdev_bnum blocks_with_buffer, rtems_blkdev_bnum media_block_count, uint8_t fill_pattern ) { rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_sparse_disk *sparse_disk = sparse_disk_allocate( media_block_size, blocks_with_buffer ); if ( sparse_disk != NULL ) { sc = rtems_sparse_disk_register( device_file_name, sparse_disk, media_block_size, blocks_with_buffer, media_block_count, fill_pattern, rtems_sparse_disk_free ); } else { sc = RTEMS_NO_MEMORY; } return sc; }
/* * Read write testing with a statically allocated disk. Thus white box testing can be done */ static void test_with_whitebox( const char *device_name ) { rtems_status_code sc; int rv; unsigned int i; sparse_disk_container disk_container; int file_descriptor; rtems_blkdev_bnum block_count = 0; unsigned int byte_count; uint8_t fill_pattern = 0; memset( disk_container.data, 0, sizeof( disk_container.data ) ); memset( disk_container.keytable, 0, sizeof( disk_container.keytable ) ); for ( i = 0; i < STATIC_PATTERN_SIZE; ++i ) disk_container.pattern[i] = (uint8_t) ( STATIC_PATTERN_SIZE - 1 - i ); sc = rtems_sparse_disk_register( "/dev/sda1", &disk_container.sparse_disk, STATIC_BLOCK_SIZE, STATIC_ALLOCATED_BLOCK_COUNT, STATIC_SIMULATED_BLOCK_COUNT, fill_pattern, NULL ); rtems_test_assert( RTEMS_SUCCESSFUL == sc ); test_static_key_table( &disk_container, STATIC_ALLOCATED_BLOCK_COUNT, STATIC_BLOCK_SIZE ); for ( i = 0; i < ( STATIC_BLOCK_SIZE * STATIC_ALLOCATED_BLOCK_COUNT ); ++i ) rtems_test_assert( 0 == disk_container.data[i] ); test_static_pattern( STATIC_PATTERN_SIZE, &disk_container.pattern[0] ); file_descriptor = open( device_name, O_RDWR ); rtems_test_assert( 0 <= file_descriptor ); test_disk_params( file_descriptor, STATIC_BLOCK_SIZE, STATIC_BLOCK_SIZE, STATIC_SIMULATED_BLOCK_COUNT ); test_writing( file_descriptor, STATIC_BLOCK_SIZE, STATIC_ALLOCATED_BLOCK_COUNT ); test_reading( file_descriptor, STATIC_BLOCK_SIZE, STATIC_ALLOCATED_BLOCK_COUNT, fill_pattern ); rv = close( file_descriptor ); rtems_test_assert( 0 == rv ); test_static_key_table( &disk_container, STATIC_ALLOCATED_BLOCK_COUNT, STATIC_BLOCK_SIZE ); for ( block_count = 0; block_count < STATIC_ALLOCATED_BLOCK_COUNT; block_count++ ) { for ( byte_count = 0; byte_count < ( STATIC_BLOCK_SIZE / sizeof( byte_count ) ); byte_count++ ) { rv = memcmp( &disk_container.data[byte_count * sizeof( byte_count )], &byte_count, sizeof( byte_count ) ); rtems_test_assert( 0 == rv ); } } test_static_pattern( STATIC_PATTERN_SIZE, &disk_container.pattern[0] ); }