[PATCH] dosfs: Fix files with same name as volume name.

Christian Mauderer christian.mauderer at embedded-brains.de
Tue Nov 28 12:34:46 UTC 2017


From: Christian Mauderer <Christian.Mauderer at embedded-brains.de>

Take care that a file in the root directory with the same name as the
volume name can be found.
---
 cpukit/libfs/src/dosfs/msdos_misc.c     |   3 +-
 testsuites/fstests/fsdosfsname01/init.c | 110 +++++++++++++++++++++++++++++++-
 2 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/cpukit/libfs/src/dosfs/msdos_misc.c b/cpukit/libfs/src/dosfs/msdos_misc.c
index 915b733330..79aaa36520 100644
--- a/cpukit/libfs/src/dosfs/msdos_misc.c
+++ b/cpukit/libfs/src/dosfs/msdos_misc.c
@@ -1585,7 +1585,8 @@ msdos_find_file_in_directory (
                         printf ("MSFS:[9.2] checksum, entry_matched:%i, lfn_entry:%i, lfn_checksum:%02x/%02x\n",
                                 entry_matched, lfn_entry, lfn_checksum, msdos_lfn_checksum(entry));
 #endif
-                    } else {
+                    } else if ((*MSDOS_DIR_ATTR(entry) & MSDOS_ATTR_VOLUME_ID)
+                               == 0) {
                         bytes_in_entry = MSDOS_SHORT_NAME_LEN + 1;
                         bytes_in_entry = msdos_short_entry_to_utf8_name (
                             converter,
diff --git a/testsuites/fstests/fsdosfsname01/init.c b/testsuites/fstests/fsdosfsname01/init.c
index b796dee40f..29d63484b3 100644
--- a/testsuites/fstests/fsdosfsname01/init.c
+++ b/testsuites/fstests/fsdosfsname01/init.c
@@ -38,6 +38,71 @@
 
 const char rtems_test_name[] = "FSDOSFSNAME 1";
 
+#include <bsp/pin-config.h>
+#define GRISP_PIN_CONFIG                                                      \
+  /* Init everything but Console, SDRAM and Trace port to input pull up */    \
+  {0xFFE27FFE, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP},                         \
+  {0xFFFFFFFF, PIOB, ID_PIOB, PIO_INPUT, PIO_PULLUP},                         \
+  {0x00037F00, PIOC, ID_PIOC, PIO_INPUT, PIO_PULLUP},                         \
+  {0xD97C1E0F, PIOD, ID_PIOD, PIO_INPUT, PIO_PULLUP},                         \
+  {0xFFFFFFC0, PIOE, ID_PIOE, PIO_INPUT, PIO_PULLUP},                         \
+                                                                              \
+  /* Console */                                                               \
+  {PIO_PD25C_URXD2 | PIO_PD26C_UTXD2,                                         \
+      PIOD, ID_PIOD, PIO_PERIPH_C, PIO_DEFAULT},                              \
+                                                                              \
+  /* SDRAM, EBI */                                                            \
+  {0x000000FF, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_DEFAULT}, /* D0 .. D7 */      \
+  {0x0000003F, PIOE, ID_PIOE, PIO_PERIPH_A, PIO_DEFAULT}, /* D8 .. D13 */     \
+  {0x00018000, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}, /* D14 .. D15 */    \
+  {0xFFF80000, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_DEFAULT}, /* (SAF_A1 .. SAF_A13) == (n.u., RAM_A0 .. RAM_A9, n.u., RAM_A11) */ \
+  {0x00002000, PIOD, ID_PIOD, PIO_PERIPH_C, PIO_DEFAULT}, /* RAM_A10 */       \
+  {0x00040000, PIOA, ID_PIOA, PIO_PERIPH_C, PIO_DEFAULT}, /* RAM_A12 == SAF_A14 */ \
+  {0x00180001, PIOA, ID_PIOA, PIO_PERIPH_C, PIO_DEFAULT}, /* (SAF_A15 .. SAF_A17) == (n.u., RAM_BA0, RAM_BA1) */ \
+  {0x00008000, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_DEFAULT}, /* RAM_CS */        \
+  {0x00040000, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_DEFAULT}, /* RAM_DQML / NBS0 */ \
+  {0x00008000, PIOD, ID_PIOD, PIO_PERIPH_C, PIO_DEFAULT}, /* RAM_DQMH / NBS1 */ \
+  {0x00004000, PIOD, ID_PIOD, PIO_PERIPH_C, PIO_DEFAULT}, /* RAM_CKE */       \
+  {0x00010000, PIOD, ID_PIOD, PIO_PERIPH_C, PIO_DEFAULT}, /* RAM_RAS */       \
+  {0x00020000, PIOD, ID_PIOD, PIO_PERIPH_C, PIO_DEFAULT}, /* RAM_CAS */       \
+  {0x00800000, PIOD, ID_PIOD, PIO_PERIPH_C, PIO_DEFAULT}, /* RAM_CLK */       \
+  {0x20000000, PIOD, ID_PIOD, PIO_PERIPH_C, PIO_DEFAULT}, /* RAM_WE */        \
+  {PIO_PA1,    PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}, /* SAF_HC_DACK */   \
+  {PIO_PC8A_NWE, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_DEFAULT}, /* SAF_WR */      \
+  {PIO_PC11A_NRD, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_DEFAULT}, /* SAF_RD */     \
+  {PIO_PC14A_NCS0, PIOC, ID_PIOC, PIO_PERIPH_A, PIO_DEFAULT}, /* SAF_CS */    \
+  {PIO_PD10,   PIOD, ID_PIOD, PIO_INPUT,    PIO_PULLUP }, /* SAF_DREQ */      \
+                                                                              \
+  /* Trace port */                                                            \
+  {0x000000F0, PIOD, ID_PIOC, PIO_PERIPH_C, PIO_DEFAULT}, /* TRACE0..3 */     \
+  {0x00000100, PIOD, ID_PIOC, PIO_PERIPH_D, PIO_DEFAULT}, /* TRACECLK */      \
+                                                                              \
+  /* SD-Card */                                                               \
+  {PIO_PA25D_MCCK, PIOA, ID_PIOA, PIO_PERIPH_D, PIO_DEFAULT},                 \
+  {PIO_PA26C_MCDA2 | PIO_PA27C_MCDA3 | PIO_PA28C_MCCDA | PIO_PA30C_MCDA0 |    \
+      PIO_PA31C_MCDA1, PIOA, ID_PIOA, PIO_PERIPH_C, PIO_DEFAULT},             \
+  {PIO_PD18, PIOD, ID_PIOD, PIO_INPUT, PIO_DEFAULT}, /* DETECT */             \
+                                                                              \
+  /* UART */                                                                  \
+  {PIO_PB0C_RXD0 | PIO_PB1C_TXD0 | PIO_PB2C_CTS0 | PIO_PB3C_RTS0,             \
+      PIOB, ID_PIOB, PIO_PERIPH_C, PIO_DEFAULT},                              \
+                                                                              \
+  /* I2C */                                                                   \
+  {PIO_PA3A_TWD0 | PIO_PA4A_TWCK0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}, \
+                                                                              \
+  /* SPI */                                                                   \
+  {PIO_PA2, PIOA, ID_PIOA, PIO_INPUT, PIO_PULLUP},                            \
+  {PIO_PB12, PIOB, ID_PIOB, PIO_OUTPUT_1, PIO_DEFAULT},                       \
+  {PIO_PD12C_SPI0_NPCS2, PIOD, ID_PIOD, PIO_PERIPH_C, PIO_DEFAULT},           \
+  {PIO_PD20B_SPI0_MISO | PIO_PD21B_SPI0_MOSI | PIO_PD22B_SPI0_SPCK |          \
+      PIO_PD27B_SPI0_NPCS3, PIOD, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT}
+
+#define GRISP_MATRIX_CCFG_SYSIO 0x20400000
+
+const Pin atsam_pin_config[] = {GRISP_PIN_CONFIG};
+const size_t atsam_pin_config_count = PIO_LISTSIZE(atsam_pin_config);
+const uint32_t atsam_matrix_ccfg_sysio = GRISP_MATRIX_CCFG_SYSIO;
+
 #define PRINT_DISK_IMAGE 0
 
 #define MOUNT_DIR "/mnt"
@@ -46,6 +111,7 @@ const char rtems_test_name[] = "FSDOSFSNAME 1";
 #define RAMDISK_PATH "/dev/rda"
 #define BLOCK_NUM 47
 #define BLOCK_SIZE 512
+#define VOLUME_LABEL "MyDisk"
 
 #define NUMBER_OF_DIRECTORIES 8
 #define NUMBER_OF_FILES 13
@@ -78,7 +144,7 @@ static rtems_resource_snapshot            before_mount;
 
 static const msdos_format_request_param_t rqdata = {
   .OEMName             = "RTEMS",
-  .VolLabel            = "RTEMSDisk",
+  .VolLabel            = VOLUME_LABEL,
   .sectors_per_cluster = 2,
   .fat_num             = 0,
   .files_per_root_dir  = 0,
@@ -1107,10 +1173,52 @@ static void test_full_8_3_name( void )
   rtems_test_assert( rc == 0 );
 }
 
+static void test_dir_with_same_name_as_volume_label( void )
+{
+  int  rc;
+  DIR *dirp;
+
+  rc = mkdir( MOUNT_DIR "/" VOLUME_LABEL, S_IRWXU | S_IRWXG | S_IRWXO );
+  rtems_test_assert( rc == 0 );
+
+  dirp = opendir( MOUNT_DIR "/" VOLUME_LABEL );
+  rtems_test_assert( NULL != dirp );
+
+  rc = closedir( dirp );
+  rtems_test_assert( rc == 0 );
+
+  rc = unlink( MOUNT_DIR "/" VOLUME_LABEL );
+  rtems_test_assert( rc == 0 );
+}
+
+static void test_file_with_same_name_as_volume_label( void )
+{
+  int rc;
+  int fd;
+
+  fd = open( MOUNT_DIR "/" VOLUME_LABEL, O_RDWR | O_CREAT,
+             S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH );
+  rtems_test_assert( fd >= 0 );
+
+  rc = close( fd );
+  rtems_test_assert( rc == 0 );
+
+  fd = open( MOUNT_DIR "/" VOLUME_LABEL, O_RDWR );
+  rtems_test_assert( fd >= 0 );
+
+  rc = close( fd );
+  rtems_test_assert( rc == 0 );
+
+  rc = unlink( MOUNT_DIR "/" VOLUME_LABEL );
+  rtems_test_assert( rc == 0 );
+}
+
 static void test_special_cases( void )
 {
   test_end_of_string_matches();
   test_full_8_3_name();
+  test_file_with_same_name_as_volume_label();
+  test_dir_with_same_name_as_volume_label();
 }
 
 /*
-- 
2.12.3



More information about the devel mailing list