summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-03-14 09:36:07 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-03-21 16:14:59 +0100
commit565b1a57b731c14847e60c6783237a0665cf859f (patch)
tree418c9f352a1c355aefbaa9b59b4734f641ebabbf /cpukit
parentad3a744ac4e52deb0202c0b28d32e1077a260630 (diff)
downloadrtems-565b1a57b731c14847e60c6783237a0665cf859f.tar.bz2
dosfs: Add and use msdos_lfn_checksum()
Update #2929.
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/libfs/src/dosfs/msdos.h2
-rw-r--r--cpukit/libfs/src/dosfs/msdos_dir.c10
-rw-r--r--cpukit/libfs/src/dosfs/msdos_misc.c35
3 files changed, 25 insertions, 22 deletions
diff --git a/cpukit/libfs/src/dosfs/msdos.h b/cpukit/libfs/src/dosfs/msdos.h
index d1ce5ad039..1911cfd78b 100644
--- a/cpukit/libfs/src/dosfs/msdos.h
+++ b/cpukit/libfs/src/dosfs/msdos.h
@@ -482,6 +482,8 @@ int msdos_get_dotdot_dir_info_cluster_num_and_offset(
int msdos_sync(rtems_libio_t *iop);
+uint8_t msdos_lfn_checksum(const void *entry);
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/libfs/src/dosfs/msdos_dir.c b/cpukit/libfs/src/dosfs/msdos_dir.c
index b10ed9edfc..577dc4d4db 100644
--- a/cpukit/libfs/src/dosfs/msdos_dir.c
+++ b/cpukit/libfs/src/dosfs/msdos_dir.c
@@ -281,14 +281,8 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
*/
if (lfn_start != FAT_FILE_SHORT_NAME)
{
- uint8_t cs = 0;
- uint8_t* p = (uint8_t*) entry;
- int i;
-
- for (i = 0; i < 11; i++, p++)
- cs = ((cs & 1) ? 0x80 : 0) + (cs >> 1) + *p;
-
- if (lfn_entries || (lfn_checksum != cs))
+ if (lfn_entries ||
+ lfn_checksum != msdos_lfn_checksum(entry))
lfn_start = FAT_FILE_SHORT_NAME;
eno = (*convert_handler->utf16_to_utf8) (
diff --git a/cpukit/libfs/src/dosfs/msdos_misc.c b/cpukit/libfs/src/dosfs/msdos_misc.c
index c854d4882d..da59668691 100644
--- a/cpukit/libfs/src/dosfs/msdos_misc.c
+++ b/cpukit/libfs/src/dosfs/msdos_misc.c
@@ -55,6 +55,23 @@
const char *const MSDOS_DOT_NAME = ". ";
const char *const MSDOS_DOTDOT_NAME = ".. ";
+uint8_t
+msdos_lfn_checksum(const void *entry)
+{
+ const uint8_t *name;
+ uint8_t cs;
+ int i;
+
+ name = (const uint8_t *) MSDOS_DIR_NAME(entry);
+ cs = 0;
+
+ for (i = 0; i < MSDOS_SHORT_NAME_LEN; ++i) {
+ cs = ((cs & 1) ? 0x80 : 0) + (cs >> 1) + name[i];
+ }
+
+ return cs;
+}
+
/* msdos_is_valid_name_char --
* Routine to check the character in a file or directory name.
* The characters support in the short file name are letters,
@@ -1535,14 +1552,8 @@ msdos_find_file_in_directory (
*/
if (entry_matched)
{
- uint8_t cs = 0;
- uint8_t* p = (uint8_t*) MSDOS_DIR_NAME(entry);
- int i;
-
- for (i = 0; i < MSDOS_SHORT_NAME_LEN; i++, p++)
- cs = ((cs & 1) ? 0x80 : 0) + (cs >> 1) + *p;
-
- if (lfn_entry || (lfn_checksum != cs))
+ if (lfn_entry ||
+ lfn_checksum != msdos_lfn_checksum(entry))
entry_matched = false;
else if (filename_size_remaining == 0) {
filename_matched = true;
@@ -1561,7 +1572,7 @@ msdos_find_file_in_directory (
#if MSDOS_FIND_PRINT
printf ("MSFS:[9.2] checksum, entry_matched:%i, lfn_entry:%i, lfn_checksum:%02x/%02x\n",
- entry_matched, lfn_entry, lfn_checksum, cs);
+ entry_matched, lfn_entry, lfn_checksum, msdos_lfn_checksum(entry));
#endif
} else {
bytes_in_entry = MSDOS_SHORT_NAME_LEN + 1;
@@ -1670,11 +1681,7 @@ msdos_add_file (
if (fat_entries)
{
- uint8_t* p = (uint8_t*) MSDOS_DIR_NAME(name_dir_entry);
- int i;
- for (i = 0; i < 11; i++, p++)
- lfn_checksum =
- ((lfn_checksum & 1) ? 0x80 : 0) + (lfn_checksum >> 1) + *p;
+ lfn_checksum = msdos_lfn_checksum(name_dir_entry);
}
/*