[RFC PATCH 03/11] fs: fat: Use strlower() to normalise case
Simon Glass
sjg at chromium.org
Fri May 15 22:32:54 CEST 2026
Drop the local downcase() helper. The two get_name() call sites
operate on buffers that are NUL-terminated before the lowercase
pass, and the trailing FAT-name padding is spaces which tolower()
leaves untouched, so strlower() gives the same result without
needing an explicit length.
Move the 'ptr[3] = '\0'' assignment in get_name() to before the
extension is lowercased so strlower() sees a terminated string.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
fs/fat/fat.c | 20 ++++----------------
fs/fat/fat_write.c | 2 +-
2 files changed, 5 insertions(+), 17 deletions(-)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index c1ccf30771a..dd328f948fb 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -26,23 +26,11 @@
#include <linux/compiler.h>
#include <linux/ctype.h>
#include <linux/log2.h>
+#include <linux/string.h>
/* maximum number of clusters for FAT12 */
#define MAX_FAT12 0xFF4
-/*
- * 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, size_t len)
-{
- while (*str != '\0' && len--) {
- *str = tolower(*str);
- str++;
- }
-}
-
static struct blk_desc *cur_dev;
static struct disk_partition cur_part_info;
static int fat_sect_size;
@@ -270,13 +258,13 @@ static void get_name(dir_entry *dirent, char *s_name)
while (*ptr && *ptr != ' ')
ptr++;
if (dirent->lcase & CASE_LOWER_BASE)
- downcase(s_name, (unsigned)(ptr - s_name));
+ strlower(s_name);
if (dirent->nameext.ext[0] && dirent->nameext.ext[0] != ' ') {
*ptr++ = '.';
memcpy(ptr, dirent->nameext.ext, 3);
- if (dirent->lcase & CASE_LOWER_EXT)
- downcase(ptr, 3);
ptr[3] = '\0';
+ if (dirent->lcase & CASE_LOWER_EXT)
+ strlower(ptr);
while (*ptr && *ptr != ' ')
ptr++;
}
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index c98b530f747..ea8d301514c 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -1464,7 +1464,7 @@ static int normalize_longname(char *l_filename, const char *filename)
}
strcpy(l_filename, filename);
- downcase(l_filename, VFAT_MAXLEN_BYTES);
+ strlower(l_filename);
return 0;
}
--
2.43.0
More information about the U-Boot
mailing list