[PATCH v2] dosfs: Fix files with same name as volume name.
Christian Mauderer
christian.mauderer at embedded-brains.de
Tue Nov 28 15:42:00 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 | 45 ++++++++++++++++++++++++++++++++-
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/cpukit/libfs/src/dosfs/msdos_misc.c b/cpukit/libfs/src/dosfs/msdos_misc.c
index dec894f133..addfd7fa84 100644
--- a/cpukit/libfs/src/dosfs/msdos_misc.c
+++ b/cpukit/libfs/src/dosfs/msdos_misc.c
@@ -1562,7 +1562,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 f272945d89..d0c909877c 100644
--- a/testsuites/fstests/fsdosfsname01/init.c
+++ b/testsuites/fstests/fsdosfsname01/init.c
@@ -46,6 +46,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 +79,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 +1108,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