fs: fat: do not mangle short filenames
authorStefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Fri, 17 Mar 2023 12:04:13 +0000 (13:04 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 30 Mar 2023 19:09:59 +0000 (15:09 -0400)
Do not mangle lower or mixed case filenames which fit into the upper
case 8.3 short filename. This ensures FAT standard compatible short
filenames (SFN) to support systems without long filename (LFN) support
like boot roms (ex. SFN BOOT.BIN instead of BOOT~1.BIN for LFN
boot.bin).

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
fs/fat/fat_write.c

index 00541eb..413fc43 100644 (file)
@@ -141,6 +141,8 @@ static int set_name(fat_itr *itr, const char *filename, char *shortname)
        if (!strcmp(buf, filename)) {
                ret = 1;
                goto out;
+       } else if (!strcasecmp(buf, filename)) {
+               goto out_ret;
        }
 
        /* Construct an indexed short name */
@@ -177,12 +179,13 @@ static int set_name(fat_itr *itr, const char *filename, char *shortname)
                if (find_directory_entry(itr, buf))
                        continue;
 
-               debug("chosen short name: %s\n", buf);
-               /* Each long name directory entry takes 13 characters. */
-               ret = (strlen(filename) + 25) / 13;
-               goto out;
+               goto out_ret;
        }
        return -EIO;
+out_ret:
+       debug("chosen short name: %s\n", buf);
+       /* Each long name directory entry takes 13 characters. */
+       ret = (strlen(filename) + 25) / 13;
 out:
        memcpy(shortname, &dirent, SHORT_NAME_SIZE);
        return ret;