diff options
author | Heinrich Schuchardt | 2021-01-30 14:12:10 +0100 |
---|---|---|
committer | Heinrich Schuchardt | 2021-02-03 11:41:02 +0100 |
commit | 3ecc5277f42eba5703901671f218a7f40d5ed45f (patch) | |
tree | 6c58617a9862b9bd7a0adaf63239e72c92afa691 /fs/fat | |
parent | 0be286cd6de995d6249508ebde6cfb8066045d77 (diff) |
fs: fat: remove trailing periods from long name
The FAT32 File System Specification [1] requires leading and trailing
spaces as well as trailing periods of long names to be ignored.
[1]
Microsoft Extensible Firmware Initiative
FAT32 File System Specification
Version 1.03, December 6, 2000
Microsoft Corporation
https://www.win.tue.nl/~aeb/linux/fs/fat/fatgen103.pdf
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Diffstat (limited to 'fs/fat')
-rw-r--r-- | fs/fat/fat_write.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 89456499778..8ff2f6def08 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -1237,12 +1237,38 @@ again: } *last_slash_cont = '\0'; - *basename = last_slash_cont + 1; + filename = last_slash_cont + 1; } else { *dirname = "/"; /* root by default */ - *basename = filename; } + /* + * The FAT32 File System Specification v1.03 requires leading and + * trailing spaces as well as trailing periods to be ignored. + */ + for (; *filename == ' '; ++filename) + ; + + /* Keep special entries '.' and '..' */ + if (filename[0] == '.' && + (!filename[1] || (filename[1] == '.' && !filename[2]))) + goto done; + + /* Remove trailing periods and spaces */ + for (p = filename + strlen(filename) - 1; p >= filename; --p) { + switch (*p) { + case ' ': + case '.': + *p = 0; + break; + default: + goto done; + } + } + +done: + *basename = filename; + return 0; } |