diff options
author | Rob Clark <robdclark@gmail.com> | 2017-09-09 13:15:59 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2017-09-15 09:03:14 -0400 |
commit | 21a24c3bf35bac83d66ce4a48eb0c7dd8a7227cb (patch) | |
tree | fec8d889d3fa7117d349502b07e146819bf12e44 /fs/fat/fat.c | |
parent | 89191d626793490b579e1d36e7d7a4464a20f9f6 (diff) | |
download | u-boot-21a24c3bf35bac83d66ce4a48eb0c7dd8a7227cb.zip u-boot-21a24c3bf35bac83d66ce4a48eb0c7dd8a7227cb.tar.gz u-boot-21a24c3bf35bac83d66ce4a48eb0c7dd8a7227cb.tar.bz2 |
fs/fat: fix case for FAT shortnames
Noticed when comparing our output to linux. There are some lcase bits
which control whether filename and/or extension should be downcase'd.
Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Ćukasz Majewski <lukma@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'fs/fat/fat.c')
-rw-r--r-- | fs/fat/fat.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/fs/fat/fat.c b/fs/fat/fat.c index c951d84..65873a2 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -29,11 +29,13 @@ static const int vfat_enabled = 0; #endif /* - * Convert a string to lowercase. + * Convert a string to lowercase. Converts at most 'len' characters, + * 'len' may be larger than the length of 'str' if 'str' is NULL + * terminated. */ -static void downcase(char *str) +static void downcase(char *str, size_t len) { - while (*str != '\0') { + while (*str != '\0' && len--) { *str = tolower(*str); str++; } @@ -131,10 +133,13 @@ static void get_name(dir_entry *dirent, char *s_name) ptr = s_name; while (*ptr && *ptr != ' ') ptr++; + if (dirent->lcase & CASE_LOWER_BASE) + downcase(s_name, (unsigned)(ptr - s_name)); if (dirent->ext[0] && dirent->ext[0] != ' ') { - *ptr = '.'; - ptr++; + *ptr++ = '.'; memcpy(ptr, dirent->ext, 3); + if (dirent->lcase & CASE_LOWER_EXT) + downcase(ptr, 3); ptr[3] = '\0'; while (*ptr && *ptr != ' ') ptr++; @@ -144,7 +149,6 @@ static void get_name(dir_entry *dirent, char *s_name) *s_name = '\0'; else if (*s_name == aRING) *s_name = DELETED_FLAG; - downcase(s_name); } static int flush_dirty_fat_buffer(fsdata *mydata); |