fsdsosfsname01: Ensure endian correctness

This commit is contained in:
Ralf Kirchner
2013-03-22 15:14:11 +01:00
committed by Sebastian Huber
parent e1483973c4
commit 581c9982a3
3 changed files with 6421 additions and 36 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,7 @@
#include "config.h"
#endif
#include "tmacros.h"
#include <fcntl.h>
@@ -27,17 +28,25 @@
#include <rtems/dosfs.h>
#include <rtems/ramdisk.h>
#include <rtems/libcsupport.h>
#include "ramdisk_support.h"
#include "image.h"
#include "image_bin_le_singlebyte.h"
#include "image_bin_le_multibyte.h"
#include "files.h"
#include <errno.h>
#define PRINT_DISK_IMAGE 0
#define MOUNT_DIR "/mnt"
#define MOUNT_DIR_SIZE 4
#define START_DIR_SIZE 4
#define RAMDISK_PATH "/dev/rda"
#define BLOCK_NUM 47
#define BLOCK_SIZE 512
#define NUMBER_OF_DIRECTORIES 8
#define NUMBER_OF_FILES 13
#define NUMBER_OF_DIRECTORIES_INVALID 18
#define NUMBER_OF_DIRECTORIES_INVALID 25
#define NUMBER_OF_DIRECTORIES_DUPLICATED 2
#define NUMBER_OF_MULTIBYTE_NAMES_DUPLICATED 2
#define NUMBER_OF_FILES_DUPLICATED 2
@@ -109,7 +118,13 @@ static const char DIRECTORY_NAMES_INVALID[
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 17, 28, 29, 30, 31},
{127}
{127},
"э*_то длинное имя",
"э:_то длинное имя",
"э<_то длинное имя",
"э>_то длинное имя",
"э?_то длинное имя",
"э|_то длинное имя"
};
static const char NAMES_MULTIBYTE[
@@ -308,20 +323,22 @@ static void mount_device_with_defaults( const char *start_dir )
mount_device( start_dir, NULL );
}
static void mount_device_with_iconv( const char *start_dir )
static void mount_device_with_iconv(
const char *start_dir,
rtems_dosfs_mount_options *mount_opts
)
{
int rc;
rtems_dosfs_mount_options mount_opts;
rc = msdos_format( RAMDISK_PATH, &rqdata );
rtems_test_assert( rc == 0 );
rtems_resource_snapshot_take( &before_mount );
mount_opts.string_opts = rtems_dosfs_string_options_init_utf8( "CP850" );
mount_opts->converter = rtems_dosfs_create_utf8_converter( "CP850" );
rtems_test_assert( mount_opts->converter != NULL );
mount_device( start_dir, &mount_opts );
mount_device( start_dir, mount_opts );
}
static void unmount_and_close_device( void )
@@ -723,6 +740,221 @@ static void test_finding_directories(
rtems_test_assert( rc == 0 );
}
#if (PRINT_DISK_IMAGE != 0)
static void print_image(
const char* include_guard,
const char* image_name
)
{
#define BYTES_PER_ROW 8
int rc;
int fd;
ssize_t bytes_read;
uint8_t buf[BLOCK_SIZE];
unsigned int index_block;
unsigned int index_row;
unsigned int index_column;
unsigned int index_buf;
#ifdef SHOW_LINE_NUMBERS
size_t index_row_start = 1;
#endif /* SWOW_LINE_NUMBERS */
size_t bytes_written = 0;
const size_t DISK_SIZE = BLOCK_SIZE * BLOCK_NUM;
const unsigned int ROWS_PER_BLOCK = BLOCK_SIZE / BYTES_PER_ROW;
printf ("/*\n"
" * Declarations for C structure representing a disk image\n"
" *\n"
" * WARNING: Automatically generated by init.c -- do not edit!\n"
" */\n"
"#ifndef %s\n"
"#define %s\n"
"\n"
"#include <sys/types.h>\n"
"\n"
"#ifdef __cplusplus\n"
"extern \"C\" {\n"
"#endif /* __cplusplus */\n"
"\n"
"static unsigned char %s[] = {\n",
include_guard,
include_guard,
image_name);
fd = open( RAMDISK_PATH, O_RDWR );
rtems_test_assert( fd >= 0 );
for ( index_block = 0; index_block < BLOCK_NUM; ++index_block )
{
bytes_read = read( fd, &buf[0], BLOCK_SIZE );
rtems_test_assert( bytes_read = BLOCK_SIZE );
index_buf = 0;
for ( index_row = 0; index_row < ROWS_PER_BLOCK; ++index_row )
{
printf( " " );
for ( index_column = 0;
index_column < BYTES_PER_ROW;
++index_column ) {
printf("0x%02x", buf[index_buf]);
++bytes_written;
++index_buf;
if ( bytes_written < DISK_SIZE ) {
printf (", ");
} else {
printf (" ");
}
}
#ifdef SHOW_LINE_NUMBERS
printf( "/* %6u - %6u */", index_row_start, bytes_written );
index_row_start = bytes_written + 1;
#endif /* SWOW_LINE_NUMBERS */
printf( "\n" );
}
}
rc = close( fd );
rtems_test_assert( rc == 0 );
printf ("};\n"
"#ifdef __cplusplus\n"
"}\n"
"#endif /* __cplusplus */\n"
"\n"
"#endif /* %s */\n",
include_guard);
}
#else /* PRINT_DISK_IMAGE */
static void print_image(
const char* include_guard,
const char* image_name
)
{
/* Nothing to be done */
}
#endif /* PRINT_DISK_IMAGE */
static void compare_files(
const char *file0,
const char *file1
)
{
struct stat stat_buf[2];
int fd[2];
unsigned int index;
uint8_t buf[2];
ssize_t bytes_read;
int rc;
rc = stat( file0 , &stat_buf[0] );
rtems_test_assert( rc == 0 );
rc = stat( file1 , &stat_buf[1] );
rtems_test_assert( rc == 0 );
rtems_test_assert( stat_buf[0].st_size == stat_buf[1].st_size );
fd[0] = open( file0, O_RDONLY );
rtems_test_assert( fd[0] > 0 );
fd[1] = open( file1, O_RDONLY );
rtems_test_assert( fd[1] > 0 );
for ( index = 0; index < stat_buf[0].st_size; ++index ) {
bytes_read = read( fd[0], &buf[0], 1 );
rtems_test_assert( bytes_read == 1 );
bytes_read = read( fd[1], &buf[1], 1 );
rtems_test_assert( bytes_read == 1 );
rtems_test_assert( buf[0] == buf[1] );
}
rc = close( fd[0] );
rtems_test_assert( rc == 0 );
rc = close( fd[1] );
rtems_test_assert( rc == 0 );
}
static void compare_directories(
const char *dir0,
const char *dir1)
{
int rc;
DIR *dir_stream[2];
struct dirent *dp;
struct stat stat_buf[2];
char *path[2];
const unsigned int PATH_LENGTH = 1024;
path[0] = calloc( PATH_LENGTH, sizeof(char) );
rtems_test_assert( path[0] != NULL );
path[1] = calloc( PATH_LENGTH, sizeof(char) );
rtems_test_assert( path[1] != NULL );
dir_stream[0] = opendir( dir0 );
rtems_test_assert( dir_stream[0] != NULL );
dir_stream[1] = opendir( dir1 );
rtems_test_assert( dir_stream[1] != NULL );
dp = readdir( dir_stream[0] );
rtems_test_assert( dp != NULL );
while ( dp != NULL ) {
rc = snprintf(path[0], PATH_LENGTH, "%s/%s", dir0, dp->d_name);
rtems_test_assert( rc < PATH_LENGTH );
rtems_test_assert( rc >= 0 );
rc = snprintf(path[1], PATH_LENGTH, "%s/%s", dir1, dp->d_name);
rtems_test_assert( rc < PATH_LENGTH );
rtems_test_assert( rc >= 0 );
rc = stat( path[0] , &stat_buf[0] );
rtems_test_assert( rc == 0 );
if ( ( strcmp( dp->d_name, "." ) != 0)
&& ( strcmp( dp->d_name, ".." ) != 0) ) {
if ( S_ISDIR( stat_buf[0].st_mode ) ) {
compare_directories( path[0], path[1] );
} else {
compare_files( path[0], path[1] );
}
}
dp = readdir( dir_stream[0] );
}
rc = closedir( dir_stream[0] );
rtems_test_assert( rc == 0 );
rc = closedir( dir_stream[1] );
rtems_test_assert( rc == 0 );
free (path[0]);
free (path[1]);
}
static void compare_image(
const char *mount_dir,
const char *dev,
const rtems_dosfs_mount_options *mount_opts )
{
#define MOUNT_DIR2 "/mnt2"
int rc;
rc = mount_and_make_target_path(
dev,
MOUNT_DIR2,
RTEMS_FILESYSTEM_TYPE_DOSFS,
RTEMS_FILESYSTEM_READ_WRITE,
mount_opts );
rtems_test_assert( rc == 0 );
compare_directories(mount_dir, MOUNT_DIR2);
rc = unmount( MOUNT_DIR2 );
rtems_test_assert( rc == 0 );
rc = rmdir( MOUNT_DIR2 );
rtems_test_assert( rc == 0 );
}
/*
* Test the compatibility with a genuine MS Windows FAT file system.
*/
@@ -836,12 +1068,11 @@ static void test( void )
{
int rc;
char start_dir[MOUNT_DIR_SIZE + START_DIR_SIZE + 2];
rtems_dosfs_mount_options mount_opts[2];
rc = mkdir( MOUNT_DIR, S_IRWXU | S_IRWXG | S_IRWXO );
rtems_test_assert( rc == 0 );
init_ramdisk();
snprintf( start_dir, sizeof( start_dir ), "%s/%s", MOUNT_DIR, "strt" );
/*
@@ -883,6 +1114,11 @@ static void test( void )
&FILE_NAMES[0][0],
NUMBER_OF_FILES );
compare_image(
MOUNT_DIR,
"/dev/rdb",
NULL);
rc = unmount( MOUNT_DIR );
rtems_test_assert( rc == 0 );
@@ -891,8 +1127,9 @@ static void test( void )
* but with multibyte string compatible conversion methods which use
* iconv and utf8proc
*/
rtems_dosfs_mount_options mount_opts;
mount_opts.string_opts = rtems_dosfs_string_options_init_utf8( "CP850" );
mount_opts[0].converter = rtems_dosfs_create_utf8_converter( "CP850" );
rtems_test_assert( mount_opts[0].converter != NULL );
rc = mount(
RAMDISK_PATH,
MOUNT_DIR,
@@ -909,9 +1146,27 @@ static void test( void )
NUMBER_OF_FILES );
unmount_and_close_device();
mount_device_with_iconv( start_dir );
mount_device_with_iconv( start_dir, &mount_opts[0] );
test_creating_invalid_directories();
test_creating_duplicate_directories(
&start_dir[0],
&DIRECTORY_DUPLICATES[0],
NUMBER_OF_DIRECTORIES_DUPLICATED );
unmount_and_close_device();
mount_device_with_iconv( start_dir, &mount_opts[0] );
test_duplicated_files(
MOUNT_DIR,
FILES_DUPLICATES,
NUMBER_OF_FILES_DUPLICATED );
unmount_and_close_device();
mount_device_with_iconv( start_dir, &mount_opts[0] );
test_creating_directories(
&start_dir[0],
&DIRECTORY_NAMES[0][0],
@@ -923,32 +1178,39 @@ static void test( void )
NUMBER_OF_DIRECTORIES,
&FILE_NAMES[0][0],
NUMBER_OF_FILES );
unmount_and_close_device();
mount_device_with_iconv( start_dir );
mount_opts[1].converter = rtems_dosfs_create_utf8_converter( "CP850" );
rtems_test_assert( mount_opts[1].converter != NULL );
test_creating_duplicate_directories(
&start_dir[0],
&DIRECTORY_DUPLICATES[0],
NUMBER_OF_DIRECTORIES_DUPLICATED );
unmount_and_close_device();
mount_device_with_iconv( start_dir );
test_duplicated_files(
compare_image(
MOUNT_DIR,
FILES_DUPLICATES,
NUMBER_OF_FILES_DUPLICATED );
"/dev/rdb",
&mount_opts[1]);
rc = unmount( MOUNT_DIR );
rtems_test_assert( rc == 0 );
print_image(
"IMAGE_BIN_LE_SINGLEBYTE_H_",
"IMAGE_BIN_LE_SINGLEBYTE");
rc = mount(
RAMDISK_PATH,
MOUNT_DIR,
"dosfs",
RTEMS_FILESYSTEM_READ_WRITE,
NULL );
rtems_test_assert( rc == 0 );
unmount_and_close_device();
/*
* Tests with multibyte directory and file names and
* with multibyte string compatible conversion methods which use
* iconv and utf8proc
*/
mount_device_with_iconv( start_dir );
mount_device_with_iconv( start_dir, &mount_opts[0] );
test_creating_duplicate_directories(
&start_dir[0],
@@ -957,7 +1219,7 @@ static void test( void )
unmount_and_close_device();
mount_device_with_iconv( start_dir );
mount_device_with_iconv( start_dir, &mount_opts[0] );
test_duplicated_files(
MOUNT_DIR,
@@ -966,12 +1228,13 @@ static void test( void )
unmount_and_close_device();
mount_device_with_iconv( start_dir );
mount_device_with_iconv( start_dir, &mount_opts[0] );
test_creating_directories(
&start_dir[0],
&NAMES_MULTIBYTE[0][0],
NUMBER_OF_NAMES_MULTIBYTE );
test_handling_directories(
&start_dir[0],
&NAMES_MULTIBYTE[0][0],
@@ -979,9 +1242,21 @@ static void test( void )
&NAMES_MULTIBYTE[0][0],
NUMBER_OF_NAMES_MULTIBYTE );
mount_opts[1].converter = rtems_dosfs_create_utf8_converter( "CP850" );
rtems_test_assert( mount_opts[1].converter != NULL );
compare_image(
MOUNT_DIR,
"/dev/rdc",
&mount_opts[1]);
rc = unmount( MOUNT_DIR );
rtems_test_assert( rc == 0 );
print_image(
"IMAGE_BIN_LE_MULTIBYTE_H_",
"IMAGE_BIN_LE_MULTIBYTE");
rc = mount(
RAMDISK_PATH,
MOUNT_DIR,
@@ -1000,8 +1275,6 @@ static void test( void )
unmount_and_close_device();
test_compatibility();
del_ramdisk();
}
static void Init( rtems_task_argument arg )
@@ -1015,11 +1288,20 @@ static void Init( rtems_task_argument arg )
rtems_test_exit( 0 );
}
rtems_ramdisk_config rtems_ramdisk_configuration [] = {
{ .block_size = BLOCK_SIZE, .block_num = BLOCK_NUM },
{ .block_size = BLOCK_SIZE, .block_num = BLOCK_NUM, .location = &IMAGE_BIN_LE_SINGLEBYTE[0] },
{ .block_size = BLOCK_SIZE, .block_num = BLOCK_NUM, .location = &IMAGE_BIN_LE_MULTIBYTE[0] }
};
size_t rtems_ramdisk_configuration_size = RTEMS_ARRAY_SIZE(rtems_ramdisk_configuration);
#define CONFIGURE_INIT_TASK_STACK_SIZE ( 1024 * 64 )
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_MAXIMUM_DRIVERS 4
#define CONFIGURE_MAXIMUM_SEMAPHORES RTEMS_DOSFS_SEMAPHORES_PER_INSTANCE
#define CONFIGURE_MAXIMUM_SEMAPHORES (2 * RTEMS_DOSFS_SEMAPHORES_PER_INSTANCE)
#define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
@@ -1027,8 +1309,9 @@ static void Init( rtems_task_argument arg )
#define CONFIGURE_FILESYSTEM_DOSFS
/* 1 RAM disk device file + 1 mount_dir + stdin + stdout + stderr + 2 for open directories/files */
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS ( 5 + 2 )
/* 2 RAM disk device files + 2 mount_dir + stdin + stdout + stderr +
* 2 for open directories/files + 4 * 2 for recursive tree compares*/
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS ( 7 + 2 + ( 4 * 2 ) )
#define CONFIGURE_MAXIMUM_TASKS 1