[PATCH 5/7] dosfs: Add and use msdos_lfn_checksum()
Sebastian Huber
sebastian.huber at embedded-brains.de
Tue Mar 14 13:43:30 UTC 2017
Update #2929.
---
cpukit/libfs/src/dosfs/msdos.h | 2 ++
cpukit/libfs/src/dosfs/msdos_dir.c | 10 ++--------
cpukit/libfs/src/dosfs/msdos_misc.c | 35 +++++++++++++++++++++--------------
3 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/cpukit/libfs/src/dosfs/msdos.h b/cpukit/libfs/src/dosfs/msdos.h
index d5c48d7..abfede8 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 b10ed9e..577dc4d 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 464c981..5c16f4a 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);
}
/*
--
1.8.4.5
More information about the devel
mailing list