Changeset e148397 in rtems


Ignore:
Timestamp:
Feb 26, 2013, 2:58:42 PM (7 years ago)
Author:
Ralf Kirchner <ralf.kirchner@…>
Branches:
4.11, master
Children:
581c9982
Parents:
52f3aa0
git-author:
Ralf Kirchner <ralf.kirchner@…> (02/26/13 14:58:42)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/03/13 15:28:41)
Message:

fsdosfsname01: Add compatibility tests

Test handling of file names and directory names according to Microsofts
specification for the FAT file system. Tests for compatibility with a
genuine MS Windows FAT file system have been added.

Location:
testsuites/fstests/fsdosfsname01
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • testsuites/fstests/fsdosfsname01/init.c

    r52f3aa0 re148397  
    2929#include <rtems/libcsupport.h>
    3030#include "ramdisk_support.h"
     31#include "image.h"
     32#include "files.h"
    3133
    3234#define MOUNT_DIR "/mnt"
     
    4446#define MAX_NAME_LENGTH_INVALID ( 255 + 2 )
    4547#define MAX_DUPLICATES_PER_NAME 3
     48static const char UTF8_BOM[] = {0xEF, 0xBB, 0xBF};
     49#define UTF8_BOM_SIZE 3 /* Size of the UTF-8 byte-order-mark */
    4650
    4751#define BLOCK_SIZE 512
    4852
    4953#define BLOCK_COUNT ( sizeof( image_bin ) / BLOCK_SIZE )
     54
     55static ramdisk                            disk_image = {
     56  .block_size             = BLOCK_SIZE,
     57  .block_num              = BLOCK_COUNT,
     58  .area                   = &image_bin[0],
     59  .initialized            = true,
     60  .malloced               = false,
     61  .trace                  = false,
     62  .free_at_delete_request = false
     63};
    5064
    5165static rtems_resource_snapshot            before_mount;
     
    716730
    717731/*
     732 * Test the compatibility with a genuine MS Windows FAT file system.
     733 */
     734static void test_compatibility( void )
     735{
     736  int                       rc;
     737  rtems_status_code         sc;
     738  dev_t                     dev;
     739  char                      diskpath[] = "/dev/ramdisk1";
     740  rtems_dosfs_mount_options mount_opts;
     741  rtems_device_major_number major;
     742  FILE                     *fp;
     743  int                       buffer;
     744  unsigned int              index_file = 0;
     745  unsigned int              index_char;
     746  unsigned int              offset;
     747  char                      content_buf[MAX_NAME_LENGTH + strlen( MOUNT_DIR )
     748                                        + 1];
     749  char                      file_path[MAX_NAME_LENGTH + strlen( MOUNT_DIR )
     750                                      + 1];
     751  DIR                      *dir_stream;
     752  struct dirent            *dp;
     753
     754
     755  mount_opts.converter = rtems_dosfs_create_utf8_converter( "CP850" );
     756  rtems_test_assert( mount_opts.converter != NULL );
     757
     758  sc = rtems_io_register_driver( 0, &ramdisk_ops, &major );
     759  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     760
     761  dev = rtems_filesystem_make_dev_t( major, 1 );
     762
     763  sc  = rtems_disk_create_phys(
     764    dev,
     765    BLOCK_SIZE,
     766    BLOCK_COUNT,
     767    ramdisk_ioctl,
     768    &disk_image,
     769    diskpath );
     770  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     771
     772  rc = mount_and_make_target_path(
     773    diskpath,
     774    MOUNT_DIR,
     775    RTEMS_FILESYSTEM_TYPE_DOSFS,
     776    RTEMS_FILESYSTEM_READ_WRITE,
     777    &mount_opts );
     778  rtems_test_assert( rc == 0 );
     779
     780  dir_stream = opendir( MOUNT_DIR );
     781  rtems_test_assert( dir_stream != NULL );
     782
     783  dp = readdir( dir_stream );
     784  rtems_test_assert( dp != NULL );
     785
     786  while ( dp != NULL ) {
     787    index_char = 0;
     788
     789    size_t len = strlen( filenames[index_file] );
     790
     791    if ( filenames[index_file][len - 1] == '.' )
     792      rtems_test_assert( ( len - 1 ) == dp->d_namlen );
     793    else
     794      rtems_test_assert( len == dp->d_namlen );
     795
     796    rtems_test_assert( 0
     797                       == memcmp( &filenames[index_file][0], &dp->d_name[0],
     798                                  dp->d_namlen ) );
     799
     800    snprintf( file_path, sizeof( file_path ), "%s/%s", MOUNT_DIR,
     801              filenames[index_file] );
     802    fp = fopen( file_path, "r" );
     803    rtems_test_assert( fp != NULL );
     804
     805    /* These files should contain their own file names. */
     806    while ( ( buffer = fgetc( fp ) ) != EOF ) {
     807      content_buf[index_char] = buffer;
     808      ++index_char;
     809    }
     810
     811    if ( 0 == strncmp( content_buf, UTF8_BOM, UTF8_BOM_SIZE ) )
     812      offset = UTF8_BOM_SIZE;
     813    else
     814      offset = 0;
     815
     816    rtems_test_assert( 0
     817                       == memcmp( filenames[index_file],
     818                                  &content_buf[offset],
     819                                  index_char - offset ) );
     820
     821    rc = fclose( fp );
     822    rtems_test_assert( rc == 0 );
     823
     824    ++index_file;
     825    dp = readdir( dir_stream );
     826  }
     827
     828  rtems_test_assert( index_file == FILES_FILENAMES_NUMBER_OF );
     829
     830  rc = closedir( dir_stream );
     831  rtems_test_assert( rc == 0 );
     832
     833  rc = unmount( MOUNT_DIR );
     834  rtems_test_assert( rc == 0 );
     835}
     836
     837/*
    718838 * Main test method
    719839 */
     
    8851005  unmount_and_close_device();
    8861006
     1007  test_compatibility();
     1008
    8871009  del_ramdisk();
    8881010}
Note: See TracChangeset for help on using the changeset viewer.