source: rtems/testsuites/fstests/fsdosfsname01/init.c @ e148397

4.115
Last change on this file since e148397 was e148397, checked in by Ralf Kirchner <ralf.kirchner@…>, on 02/26/13 at 14:58:42

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.

  • Property mode set to 100644
File size: 25.9 KB
Line 
1/*
2 * Copyright (c) 2012, 2013 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include "tmacros.h"
20
21#include <fcntl.h>
22#include <dirent.h>
23
24#include <bsp.h>
25#include <rtems/io.h>
26#include <rtems/libio.h>
27#include <rtems/dosfs.h>
28#include <rtems/ramdisk.h>
29#include <rtems/libcsupport.h>
30#include "ramdisk_support.h"
31#include "image.h"
32#include "files.h"
33
34#define MOUNT_DIR "/mnt"
35#define MOUNT_DIR_SIZE 4
36#define START_DIR_SIZE 4
37
38#define NUMBER_OF_DIRECTORIES 8
39#define NUMBER_OF_FILES 13
40#define NUMBER_OF_DIRECTORIES_INVALID 18
41#define NUMBER_OF_DIRECTORIES_DUPLICATED 2
42#define NUMBER_OF_MULTIBYTE_NAMES_DUPLICATED 2
43#define NUMBER_OF_FILES_DUPLICATED 2
44#define NUMBER_OF_NAMES_MULTIBYTE 10
45#define MAX_NAME_LENGTH ( 255 + 1 )
46#define MAX_NAME_LENGTH_INVALID ( 255 + 2 )
47#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 */
50
51#define BLOCK_SIZE 512
52
53#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};
64
65static rtems_resource_snapshot            before_mount;
66
67static const msdos_format_request_param_t rqdata = {
68  .OEMName             = "RTEMS",
69  .VolLabel            = "RTEMSDisk",
70  .sectors_per_cluster = 2,
71  .fat_num             = 0,
72  .files_per_root_dir  = 0,
73  .media               = 0,
74  .quick_format        = true,
75  .skip_alignment      = 0,
76  .info_level          = 0
77};
78
79static const char                         DIRECTORY_NAMES[NUMBER_OF_DIRECTORIES]
80[MAX_NAME_LENGTH] = {
81  "a dir",
82  "Shortdir",
83  "shrtdir",
84  "shrt.dir",
85  "long_conventional_dir",
86  "long_conventional.dir",
87  "LongConventionalDir",
88  "This is a directory name with with 255 characters. The following numbers are aligned in that way, that the character 0 is the mentioned one. xxxxxx150xxxxxxx160xxxxxxx170xxxxxxx180xxxxxxx190xxxxxxx200xxxxxxx210xxxxxxx220xxxxxxx230xxxxxxx240xxxxxxx250xxxxx"
89};
90
91static const char DIRECTORY_NAMES_INVALID[
92  NUMBER_OF_DIRECTORIES_INVALID][MAX_NAME_LENGTH_INVALID] = {
93  "This is a directory name with with 256 characters. The following numbers are aligned in that way, that the character 0 is the mentioned one. xxxxxx150xxxxxxx160xxxxxxx170xxxxxxx180xxxxxxx190xxxxxxx200xxxxxxx210xxxxxxx220xxxxxxx230xxxxxxx240xxxxxxx250xxxxxx",
94  ".",
95  "..",
96  "...",
97  " ",
98  "... ...",
99  " ... ",
100  "",
101  "*",
102  "/",
103  ":",
104  "<",
105  ">",
106  "?",
107  "\\",
108  "|",
109  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
110    10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
111    20, 21, 22, 23, 24, 25, 26, 17, 28, 29, 30, 31},
112  {127}
113};
114
115static const char NAMES_MULTIBYTE[
116  NUMBER_OF_NAMES_MULTIBYTE][MAX_NAME_LENGTH] = {
117  "đây là một tên tập tin dài",
118  "Bu uzun bir dosya adı",
119  "هذا هو اسم Ù…لف طويل",
120  "αυτό είΜαι έΜα Όεγάλο όΜοΌα αρχείου",
121  "этП ЎлОММПе ОЌя",
122  "гэта ЎПўгае іЌя",
123  "тПва е ЎългП ОЌе Ма файла",
124  "这是䞀䞪长文件名",
125  "shrtname",
126  "long_conventional_name"
127};
128
129static const char NAMES_MULTIBYTE_IN_CODEPAGE_FORMAT[
130  NUMBER_OF_NAMES_MULTIBYTE][MAX_NAME_LENGTH] = {
131  "_\2030005~1._t",
132  "bu0008~1.bir",
133  "__000b~1.__",
134  "__000f~1.__",
135  "__0012~1.___",
136  "__0015~1.___",
137  "__0018~1.___",
138  "__001a~1",
139  "shrtname",
140  "long_conventional_name"
141};
142
143static const char FILE_NAMES[NUMBER_OF_FILES][
144  MAX_NAME_LENGTH] = {
145  "a file",
146  "shrtfile",
147  "ShrtFle",
148  "The quick brown.fox",
149  "long_conventional_file",
150  "This is a filename with with 255 characters. The following numbers are aligned in that way, that the character 0 is the mentioned one. xx140xxxxxxx150xxxxxxx160xxxxxxx170xxxxxxx180xxxxxxx190xxxxxxx200xxxxxxx210xxxxxxx220xxxxxxx230xxxxxxx240xxxxxxx250xxxxx",
151  "+",
152  ",",
153  "a.a",
154  ";",
155  "=",
156  "[",
157  "]"
158};
159
160typedef struct {
161  char name[MAX_NAME_LENGTH];
162  unsigned int number_of_duplicates;
163  char name_duplicates[MAX_DUPLICATES_PER_NAME][MAX_NAME_LENGTH];
164} name_duplicates;
165
166static const name_duplicates DIRECTORY_DUPLICATES[
167  NUMBER_OF_DIRECTORIES_DUPLICATED] = {
168  {
169    "shrtdir",
170    3,
171    {
172      "shrtdir",
173      "SHRTDIR",
174      "Shrtdir"
175    }
176  },
177  {
178    "long_conventional_dir",
179    3,
180    {
181      "long_conventional_dir",
182      "LONG_CONVENTIONAL_DIR",
183      "Long_conventional_dir"
184    }
185  }
186};
187
188static const name_duplicates MULTIBYTE_DUPLICATES[
189  NUMBER_OF_MULTIBYTE_NAMES_DUPLICATED] = {
190  {
191    /* The angstroem encoded differently. These encodings might become short entries */
192    {0xc3, 0x85}, /* '̊A' */
193    2,
194    {
195      {0xc3, 0x85}, /* '̊A' */
196      {0xe2, 0x84, 0xab} /* 'Å' */
197    }
198  },
199
200  /* Again the angstroem encoded differently,
201   * but this time with additional characters in order to enforce a long entry. */
202  {
203    {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', 0xc3,
204     0x85},
205    2,
206    {
207      {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', 0xc3,
208       0x85},
209      {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', 0xe2,
210       0x84, 0xab}
211    }
212  }
213};
214
215
216static const name_duplicates FILES_DUPLICATES[NUMBER_OF_FILES_DUPLICATED] = {
217  {
218    "shrtfile",
219    3,
220    {
221      "shrtfile",
222      "SHRTFILE",
223      "Shrtfile"
224    }
225  },
226  {
227    "long_conventional_file",
228    3,
229    {
230      "long_conventional_file",
231      "LONG_CONVENTIONAL_FILE",
232      "Long_conventional_file"
233    }
234  }
235};
236
237static int path_is_directory( const char *path )
238{
239  struct stat s_buf;
240
241
242  if ( stat( path, &s_buf ) )
243    return 0;
244
245  return S_ISDIR( s_buf.st_mode );
246}
247
248static void delete_folder_tree( const char *directory_name )
249{
250  DIR           *dp;
251  struct dirent *ep;
252  char           p_buf[1024] = {0};
253  int            rc          = 0;
254
255
256  dp = opendir( directory_name );
257  rtems_test_assert( dp != NULL );
258
259  while ( ( ep = readdir( dp ) ) != NULL && rc == 0 ) {
260    if ( 0 != strcmp( ".", ep->d_name )
261         && 0 != strcmp( "..", ep->d_name ) ) {
262      snprintf( p_buf, sizeof( p_buf ), "%s/%s", directory_name, ep->d_name );
263
264      if ( path_is_directory( p_buf ) ) {
265        delete_folder_tree( p_buf );
266        rc = rmdir( p_buf );
267        rtems_test_assert( rc == 0 );
268        rewinddir( dp );
269      } else {
270        rc = unlink( p_buf );
271        rtems_test_assert( rc == 0 );
272        rewinddir( dp );
273      }
274    }
275  }
276
277  rc = closedir( dp );
278  rtems_test_assert( rc == 0 );
279}
280
281static void mount_device( const char *start_dir,
282  const rtems_dosfs_mount_options    *mount_opts )
283{
284  int rc;
285
286  rc = mount(
287    RAMDISK_PATH,
288    MOUNT_DIR,
289    "dosfs",
290    RTEMS_FILESYSTEM_READ_WRITE,
291    mount_opts );
292  rtems_test_assert( rc == 0 );
293
294  rc = mkdir( start_dir, S_IRWXU | S_IRWXG | S_IRWXO );
295  rtems_test_assert( rc == 0 || ( rc == -1 && errno == EEXIST ) );
296}
297
298static void mount_device_with_defaults( const char *start_dir )
299{
300  int rc;
301
302
303  rc = msdos_format( RAMDISK_PATH, &rqdata );
304  rtems_test_assert( rc == 0 );
305
306  rtems_resource_snapshot_take( &before_mount );
307
308  mount_device( start_dir, NULL );
309}
310
311static void mount_device_with_iconv( const char *start_dir )
312{
313  int                       rc;
314  rtems_dosfs_mount_options mount_opts;
315
316
317  rc = msdos_format( RAMDISK_PATH, &rqdata );
318  rtems_test_assert( rc == 0 );
319
320  rtems_resource_snapshot_take( &before_mount );
321
322  mount_opts.string_opts = rtems_dosfs_string_options_init_utf8( "CP850" );
323
324  mount_device( start_dir, &mount_opts );
325}
326
327static void unmount_and_close_device( void )
328{
329  int                     rc;
330  rtems_resource_snapshot now;
331  bool                    are_resources_freed;
332
333
334  delete_folder_tree( MOUNT_DIR );
335
336  rc = unmount( MOUNT_DIR );
337  rtems_test_assert( rc == 0 );
338
339  are_resources_freed = rtems_resource_snapshot_check( &before_mount );
340
341  if ( !are_resources_freed )
342    rtems_resource_snapshot_take( &now );
343
344  rtems_test_assert( are_resources_freed );
345}
346
347/*
348 * Simply create a few directories. These tests should all succeed
349 */
350static void test_creating_directories(
351  const char        *start_dir,
352  const char        *directories,
353  const unsigned int number_of_directories )
354{
355  unsigned int   index;
356  int            rc;
357  char           dirname[MAX_NAME_LENGTH + strlen( start_dir ) + 1];
358  DIR           *dirp;
359  struct dirent *dp;
360
361
362  for ( index = 0; index < number_of_directories; ++index ) {
363    snprintf( dirname, sizeof( dirname ), "%s/%s", start_dir, directories
364              + ( index * MAX_NAME_LENGTH ) );
365    rc = mkdir( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
366    rtems_test_assert( rc == 0 );
367  }
368
369  dirp = opendir( start_dir );
370  rtems_test_assert( NULL != dirp );
371
372  index = 0;
373  dp    = readdir( dirp );
374  rtems_test_assert( dp != NULL );
375  rtems_test_assert( 0 == strcmp( ".", dp->d_name ) );
376
377  dp = readdir( dirp );
378  rtems_test_assert( dp != NULL );
379  rtems_test_assert( 0 == strcmp( "..", dp->d_name ) );
380
381  dp = readdir( dirp );
382  rtems_test_assert( dp != NULL );
383
384  while ( dp != NULL ) {
385    rtems_test_assert( 0
386                       == strcmp( directories + ( index * MAX_NAME_LENGTH ),
387                                  dp->d_name ) );
388    ++index;
389    dp = readdir( dirp );
390  }
391
392  rtems_test_assert( number_of_directories == index );
393
394  rc = closedir( dirp );
395  rtems_test_assert( rc == 0 );
396}
397
398/*
399 * Try creating directories with invalid names.
400 */
401static void test_creating_invalid_directories( void )
402{
403  unsigned int index;
404  int          rc;
405  char         dirname[MAX_NAME_LENGTH_INVALID + MOUNT_DIR_SIZE + 1];
406
407
408  for ( index = 0; index < NUMBER_OF_DIRECTORIES_INVALID; ++index ) {
409    snprintf( dirname,
410              sizeof( dirname ),
411              "%s/%s",
412              MOUNT_DIR,
413              DIRECTORY_NAMES_INVALID[index] );
414    rc = mkdir( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
415    rtems_test_assert( rc == -1 );
416  }
417}
418
419/*
420 * Try creating directories which do already exist
421 * (although names may have different capitalization/encoding)
422 */
423static void test_creating_duplicate_directories(
424  const char            *start_dir,
425  const name_duplicates *duplicates,
426  const unsigned int     number_of_duplicates )
427{
428  unsigned int index_dir;
429  unsigned int index_duplicate;
430  int          rc;
431  char         dirname[MAX_NAME_LENGTH + MOUNT_DIR_SIZE + START_DIR_SIZE + 2];
432
433
434  for ( index_dir = 0; index_dir < number_of_duplicates; ++index_dir ) {
435    snprintf( dirname, sizeof( dirname ), "%s/%s", start_dir,
436              duplicates[index_dir].name );
437    rc = mkdir( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
438    rtems_test_assert( rc == 0 );
439
440    for ( index_duplicate = 0;
441          index_duplicate < duplicates[index_dir].number_of_duplicates;
442          ++index_duplicate ) {
443      snprintf( dirname, sizeof( dirname ), "%s/%s", start_dir,
444                duplicates[index_dir].name_duplicates[index_duplicate] );
445      rc = mkdir( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
446      rtems_test_assert( rc < 0 );
447    }
448  }
449}
450
451/*
452 * Try creating and opening files with valid names
453 */
454static void test_handling_files(
455  const char        *dirname,
456  const char        *file_names,
457  const unsigned int number_of_files )
458{
459  unsigned int index;
460  int          rc;
461  char         filename[MAX_NAME_LENGTH * 2 + MOUNT_DIR_SIZE + START_DIR_SIZE
462                        + 4];
463  int          fd;
464
465
466  for ( index = 0; index < number_of_files; ++index ) {
467    snprintf(
468      filename,
469      sizeof( filename ) - 1,
470      "%s/%s",
471      dirname,
472      file_names + index * MAX_NAME_LENGTH );
473    fd = open( filename,
474               O_RDWR | O_CREAT,
475               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH );
476    rtems_test_assert( fd >= 0 );
477
478    rc = close( fd );
479    rtems_test_assert( rc == 0 );
480
481    /* See if the file still exists and can be found */
482    fd = open( filename, O_RDWR );
483    rtems_test_assert( fd >= 0 );
484
485    rc = close( fd );
486    rtems_test_assert( rc == 0 );
487  }
488}
489
490/*
491 * Try to find (and open) all of the file names from an
492 * array in a given directory
493 */
494static void test_finding_files(
495  const char        *dirname,
496  const char        *file_names,
497  const unsigned int number_of_files )
498{
499  int            rc;
500  DIR           *dir_stream;
501  struct dirent *dp;
502  int            fd;
503  unsigned int   index_file;
504  char           filename[MAX_NAME_LENGTH * 2 + MOUNT_DIR_SIZE
505                          + START_DIR_SIZE + 4];
506
507
508  dir_stream = opendir( dirname );
509  rtems_test_assert( dir_stream != NULL );
510
511  dp = readdir( dir_stream );
512  rtems_test_assert( dp != NULL );
513  rtems_test_assert( 0 == strcmp( ".", dp->d_name ) );
514
515  dp = readdir( dir_stream );
516  rtems_test_assert( dp != NULL );
517  rtems_test_assert( 0 == strcmp( "..", dp->d_name ) );
518
519  dp         = readdir( dir_stream );
520  rtems_test_assert( dp != NULL );
521  index_file = 0;
522
523  while ( dp != NULL ) {
524    rtems_test_assert( 0 == strcmp(
525                         file_names + index_file * MAX_NAME_LENGTH,
526                         dp->d_name ) );
527
528    snprintf(
529      filename,
530      sizeof( filename ) - 1,
531      "%s/%s",
532      dirname,
533      file_names + index_file * MAX_NAME_LENGTH );
534
535    /* See if the file still exists and can be found */
536    fd = open( filename, O_RDWR );
537    rtems_test_assert( fd >= 0 );
538
539    rc = close( fd );
540    rtems_test_assert( rc == 0 );
541
542    ++index_file;
543    dp = readdir( dir_stream );
544  }
545
546  rtems_test_assert( number_of_files == index_file );
547
548  rc = closedir( dir_stream );
549  rtems_test_assert( rc == 0 );
550}
551
552/*
553 * Try opening files which do already exist (with different capitalization in their names)
554 */
555static void test_duplicated_files( const char *dirname,
556  const name_duplicates                       *files_duplicated,
557  const unsigned int                           number_of_files_duplicated )
558{
559  unsigned int index_file;
560  unsigned int index_duplicate;
561  int          rc;
562  char         filename[MAX_NAME_LENGTH + strlen( dirname ) + 1];
563  int          fd;
564
565
566  for ( index_file = 0; index_file < number_of_files_duplicated;
567        ++index_file ) {
568    snprintf( filename,
569              sizeof( filename ) - 1,
570              "%s/%s",
571              dirname,
572              files_duplicated[index_file].name );
573    fd = open( filename,
574               O_RDWR | O_CREAT,
575               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH );
576    rtems_test_assert( fd >= 0 );
577
578    rc = close( fd );
579    rtems_test_assert( rc == 0 );
580
581    for ( index_duplicate = 0;
582          index_duplicate < files_duplicated[index_file].number_of_duplicates;
583          ++index_duplicate ) {
584      snprintf( filename,
585                sizeof( filename ) - 1,
586                "%s/%s",
587                dirname,
588                files_duplicated[index_file].name_duplicates[index_duplicate] );
589      fd = open( filename, O_RDWR );
590      rtems_test_assert( fd >= 0 );
591
592      rc = close( fd );
593      rtems_test_assert( rc == 0 );
594    }
595
596    rc = remove( filename );
597    rtems_test_assert( rc == 0 );
598  }
599}
600
601/*
602 * Open and read existing valid directories
603 */
604static void test_handling_directories(
605  const char        *start_dir,
606  const char        *directory_names,
607  const unsigned int number_of_directories,
608  const char        *file_names,
609  const unsigned int number_of_files )
610{
611  unsigned int   index_directory;
612  unsigned int   index_file;
613  int            rc;
614  DIR           *dir_stream;
615  char           dirname[MAX_NAME_LENGTH * 2];
616  struct dirent *dp;
617
618
619  for ( index_directory = 0;
620        index_directory < number_of_directories;
621        ++index_directory ) {
622    snprintf(
623      dirname,
624      sizeof( dirname ) - 1,
625      "%s/%s",
626      start_dir,
627      directory_names + index_directory * MAX_NAME_LENGTH );
628
629    test_handling_files(
630      dirname,
631      file_names,
632      number_of_files );
633
634    dir_stream = opendir( dirname );
635    rtems_test_assert( dir_stream != NULL );
636
637    dp = readdir( dir_stream );
638    rtems_test_assert( dp != NULL );
639    rtems_test_assert( 0 == strcmp( ".", dp->d_name ) );
640
641    dp = readdir( dir_stream );
642    rtems_test_assert( dp != NULL );
643    rtems_test_assert( 0 == strcmp( "..", dp->d_name ) );
644
645    dp         = readdir( dir_stream );
646    rtems_test_assert( dp != NULL );
647    index_file = 0;
648
649    while ( dp != NULL ) {
650      rtems_test_assert( 0 == strcmp(
651                           file_names + index_file * MAX_NAME_LENGTH,
652                           dp->d_name ) );
653      ++index_file;
654      dp = readdir( dir_stream );
655    }
656
657    rtems_test_assert( number_of_files == index_file );
658
659    rc = closedir( dir_stream );
660    rtems_test_assert( rc == 0 );
661  }
662}
663
664/*
665 * Try to find all sub-directories from an array
666 * in a given start directory.
667 * In addition try to find and open files
668 * in these sub-directories.
669 */
670static void test_finding_directories(
671  const char        *start_dir,
672  const char        *directory_names,
673  const unsigned int number_of_directories,
674  const char        *file_names,
675  const unsigned int number_of_files )
676{
677  unsigned int   index_directory;
678  int            rc;
679  DIR           *dir_stream;
680  struct dirent *dp;
681  char           dirname[MAX_NAME_LENGTH * 2];
682
683
684  dir_stream = opendir( start_dir );
685  rtems_test_assert( dir_stream != NULL );
686
687  dp = readdir( dir_stream );
688  rtems_test_assert( dp != NULL );
689  rtems_test_assert( 0 == strcmp( ".", dp->d_name ) );
690
691  dp = readdir( dir_stream );
692  rtems_test_assert( dp != NULL );
693  rtems_test_assert( 0 == strcmp( "..", dp->d_name ) );
694
695  dp              = readdir( dir_stream );
696  rtems_test_assert( dp != NULL );
697  index_directory = 0;
698
699  while ( dp != NULL ) {
700    rtems_test_assert( 0 == strcmp(
701                         directory_names + index_directory * MAX_NAME_LENGTH,
702                         dp->d_name ) );
703
704    snprintf(
705      dirname,
706      sizeof( dirname ) - 1,
707      "%s/%s",
708      start_dir,
709      directory_names + index_directory * MAX_NAME_LENGTH );
710
711    test_finding_files(
712      dirname,
713      file_names,
714      number_of_files );
715
716    ++index_directory;
717    dp = readdir( dir_stream );
718  }
719
720  rtems_test_assert( number_of_directories == index_directory );
721
722  rc = closedir( dir_stream );
723  rtems_test_assert( rc == 0 );
724}
725
726/*
727 * Test the compatibility with a genuine MS Windows FAT file system.
728 */
729static void test_compatibility( void )
730{
731  int                       rc;
732  rtems_status_code         sc;
733  dev_t                     dev;
734  char                      diskpath[] = "/dev/ramdisk1";
735  rtems_dosfs_mount_options mount_opts;
736  rtems_device_major_number major;
737  FILE                     *fp;
738  int                       buffer;
739  unsigned int              index_file = 0;
740  unsigned int              index_char;
741  unsigned int              offset;
742  char                      content_buf[MAX_NAME_LENGTH + strlen( MOUNT_DIR )
743                                        + 1];
744  char                      file_path[MAX_NAME_LENGTH + strlen( MOUNT_DIR )
745                                      + 1];
746  DIR                      *dir_stream;
747  struct dirent            *dp;
748
749
750  mount_opts.converter = rtems_dosfs_create_utf8_converter( "CP850" );
751  rtems_test_assert( mount_opts.converter != NULL );
752
753  sc = rtems_io_register_driver( 0, &ramdisk_ops, &major );
754  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
755
756  dev = rtems_filesystem_make_dev_t( major, 1 );
757
758  sc  = rtems_disk_create_phys(
759    dev,
760    BLOCK_SIZE,
761    BLOCK_COUNT,
762    ramdisk_ioctl,
763    &disk_image,
764    diskpath );
765  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
766
767  rc = mount_and_make_target_path(
768    diskpath,
769    MOUNT_DIR,
770    RTEMS_FILESYSTEM_TYPE_DOSFS,
771    RTEMS_FILESYSTEM_READ_WRITE,
772    &mount_opts );
773  rtems_test_assert( rc == 0 );
774
775  dir_stream = opendir( MOUNT_DIR );
776  rtems_test_assert( dir_stream != NULL );
777
778  dp = readdir( dir_stream );
779  rtems_test_assert( dp != NULL );
780
781  while ( dp != NULL ) {
782    index_char = 0;
783
784    size_t len = strlen( filenames[index_file] );
785
786    if ( filenames[index_file][len - 1] == '.' )
787      rtems_test_assert( ( len - 1 ) == dp->d_namlen );
788    else
789      rtems_test_assert( len == dp->d_namlen );
790
791    rtems_test_assert( 0
792                       == memcmp( &filenames[index_file][0], &dp->d_name[0],
793                                  dp->d_namlen ) );
794
795    snprintf( file_path, sizeof( file_path ), "%s/%s", MOUNT_DIR,
796              filenames[index_file] );
797    fp = fopen( file_path, "r" );
798    rtems_test_assert( fp != NULL );
799
800    /* These files should contain their own file names. */
801    while ( ( buffer = fgetc( fp ) ) != EOF ) {
802      content_buf[index_char] = buffer;
803      ++index_char;
804    }
805
806    if ( 0 == strncmp( content_buf, UTF8_BOM, UTF8_BOM_SIZE ) )
807      offset = UTF8_BOM_SIZE;
808    else
809      offset = 0;
810
811    rtems_test_assert( 0
812                       == memcmp( filenames[index_file],
813                                  &content_buf[offset],
814                                  index_char - offset ) );
815
816    rc = fclose( fp );
817    rtems_test_assert( rc == 0 );
818
819    ++index_file;
820    dp = readdir( dir_stream );
821  }
822
823  rtems_test_assert( index_file == FILES_FILENAMES_NUMBER_OF );
824
825  rc = closedir( dir_stream );
826  rtems_test_assert( rc == 0 );
827
828  rc = unmount( MOUNT_DIR );
829  rtems_test_assert( rc == 0 );
830}
831
832/*
833 * Main test method
834 */
835static void test( void )
836{
837  int  rc;
838  char start_dir[MOUNT_DIR_SIZE + START_DIR_SIZE + 2];
839
840  rc = mkdir( MOUNT_DIR, S_IRWXU | S_IRWXG | S_IRWXO );
841  rtems_test_assert( rc == 0 );
842
843  init_ramdisk();
844
845  snprintf( start_dir, sizeof( start_dir ), "%s/%s", MOUNT_DIR, "strt" );
846
847  /*
848   * Tests with code page 850 compatible directory and file names
849   * and the code page 850 backwards compatible default mode mode of the
850   * FAT file system
851   */
852  mount_device_with_defaults( start_dir );
853
854  test_creating_duplicate_directories(
855    &start_dir[0],
856    &DIRECTORY_DUPLICATES[0],
857    NUMBER_OF_DIRECTORIES_DUPLICATED );
858
859  unmount_and_close_device();
860
861  mount_device_with_defaults( start_dir );
862
863  test_duplicated_files(
864    MOUNT_DIR,
865    FILES_DUPLICATES,
866    NUMBER_OF_FILES_DUPLICATED );
867
868  unmount_and_close_device();
869
870  mount_device_with_defaults( start_dir );
871
872  test_creating_invalid_directories();
873
874  test_creating_directories(
875    &start_dir[0],
876    &DIRECTORY_NAMES[0][0],
877    NUMBER_OF_DIRECTORIES );
878
879  test_handling_directories(
880    &start_dir[0],
881    &DIRECTORY_NAMES[0][0],
882    NUMBER_OF_DIRECTORIES,
883    &FILE_NAMES[0][0],
884    NUMBER_OF_FILES );
885
886  rc = unmount( MOUNT_DIR );
887  rtems_test_assert( rc == 0 );
888
889  /*
890   * Again tests with code page 850 compatible directory and file names
891   * but with multibyte string compatible conversion methods which use
892   * iconv and utf8proc
893   */
894  rtems_dosfs_mount_options mount_opts;
895  mount_opts.string_opts = rtems_dosfs_string_options_init_utf8( "CP850" );
896  rc                     = mount(
897    RAMDISK_PATH,
898    MOUNT_DIR,
899    "dosfs",
900    RTEMS_FILESYSTEM_READ_WRITE,
901    &mount_opts );
902  rtems_test_assert( rc == 0 );
903
904  test_finding_directories(
905    &start_dir[0],
906    &DIRECTORY_NAMES[0][0],
907    NUMBER_OF_DIRECTORIES,
908    &FILE_NAMES[0][0],
909    NUMBER_OF_FILES );
910  unmount_and_close_device();
911
912  mount_device_with_iconv( start_dir );
913  test_creating_invalid_directories();
914
915  test_creating_directories(
916    &start_dir[0],
917    &DIRECTORY_NAMES[0][0],
918    NUMBER_OF_DIRECTORIES );
919
920  test_handling_directories(
921    &start_dir[0],
922    &DIRECTORY_NAMES[0][0],
923    NUMBER_OF_DIRECTORIES,
924    &FILE_NAMES[0][0],
925    NUMBER_OF_FILES );
926  unmount_and_close_device();
927
928  mount_device_with_iconv( start_dir );
929
930  test_creating_duplicate_directories(
931    &start_dir[0],
932    &DIRECTORY_DUPLICATES[0],
933    NUMBER_OF_DIRECTORIES_DUPLICATED );
934
935  unmount_and_close_device();
936
937  mount_device_with_iconv( start_dir );
938
939  test_duplicated_files(
940    MOUNT_DIR,
941    FILES_DUPLICATES,
942    NUMBER_OF_FILES_DUPLICATED );
943
944  unmount_and_close_device();
945
946  /*
947   * Tests with multibyte directory and file names and
948   * with multibyte string compatible conversion methods which use
949   * iconv and utf8proc
950   */
951  mount_device_with_iconv( start_dir );
952
953  test_creating_duplicate_directories(
954    &start_dir[0],
955    &MULTIBYTE_DUPLICATES[0],
956    NUMBER_OF_MULTIBYTE_NAMES_DUPLICATED );
957
958  unmount_and_close_device();
959
960  mount_device_with_iconv( start_dir );
961
962  test_duplicated_files(
963    MOUNT_DIR,
964    &MULTIBYTE_DUPLICATES[0],
965    NUMBER_OF_MULTIBYTE_NAMES_DUPLICATED );
966
967  unmount_and_close_device();
968
969  mount_device_with_iconv( start_dir );
970
971  test_creating_directories(
972    &start_dir[0],
973    &NAMES_MULTIBYTE[0][0],
974    NUMBER_OF_NAMES_MULTIBYTE );
975  test_handling_directories(
976    &start_dir[0],
977    &NAMES_MULTIBYTE[0][0],
978    NUMBER_OF_NAMES_MULTIBYTE,
979    &NAMES_MULTIBYTE[0][0],
980    NUMBER_OF_NAMES_MULTIBYTE );
981
982  rc = unmount( MOUNT_DIR );
983  rtems_test_assert( rc == 0 );
984
985  rc = mount(
986    RAMDISK_PATH,
987    MOUNT_DIR,
988    "dosfs",
989    RTEMS_FILESYSTEM_READ_WRITE,
990    NULL );
991  rtems_test_assert( rc == 0 );
992
993  test_finding_directories(
994    &start_dir[0],
995    &NAMES_MULTIBYTE_IN_CODEPAGE_FORMAT[0][0],
996    NUMBER_OF_NAMES_MULTIBYTE,
997    &NAMES_MULTIBYTE_IN_CODEPAGE_FORMAT[0][0],
998    NUMBER_OF_NAMES_MULTIBYTE );
999
1000  unmount_and_close_device();
1001
1002  test_compatibility();
1003
1004  del_ramdisk();
1005}
1006
1007static void Init( rtems_task_argument arg )
1008{
1009  puts( "\n\n*** TEST fsdosfsname01 ***" );
1010
1011  test();
1012
1013  puts( "*** END OF TEST fsdosfsname01 ***" );
1014
1015  rtems_test_exit( 0 );
1016}
1017
1018#define CONFIGURE_INIT_TASK_STACK_SIZE ( 1024 * 64 )
1019#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
1020#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
1021#define CONFIGURE_MAXIMUM_DRIVERS 4
1022#define CONFIGURE_MAXIMUM_SEMAPHORES RTEMS_DOSFS_SEMAPHORES_PER_INSTANCE
1023
1024#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
1025
1026#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
1027
1028#define CONFIGURE_FILESYSTEM_DOSFS
1029
1030/* 1 RAM disk device file + 1 mount_dir + stdin + stdout + stderr + 2 for open directories/files */
1031#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS ( 5 + 2 )
1032
1033#define CONFIGURE_MAXIMUM_TASKS 1
1034
1035#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
1036
1037#define CONFIGURE_INIT
1038
1039#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.