[U-Boot] [PATCH 05/17] fs: fat: check and normailze file name
Heinrich Schuchardt
xypron.glpk at gmx.de
Tue Jul 31 04:31:19 UTC 2018
On 07/20/2018 04:57 AM, AKASHI Takahiro wrote:
> FAT file system's long file name support is a bit complicated and has some
> restrictions on its naming. We should be careful about it especially for
> write as it may easily end up with wrong file system.
>
> normalize_longname() check for the rules and normalize a file name
> if necessary. Please note, however, that this function is yet to be
> extended to fully comply with the standard.
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
The patch has to be rebased on current master due to
fs: fat: cannot write to subdirectories
0dc1bfb7302d220a48364263d5632d6d572b069b
which has been merged into U-Boot master.
> ---
> fs/fat/fat_write.c | 52 +++++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 44 insertions(+), 8 deletions(-)
>
> diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
> index 3b77557b3e..6c715a70f4 100644
> --- a/fs/fat/fat_write.c
> +++ b/fs/fat/fat_write.c
> @@ -899,6 +899,44 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect,
> return NULL;
> }
>
> +static int normalize_longname(char *l_filename, const char *filename)
> +{
> + const char *p, legal[] = "!#$%&\'()-.@^`_{}~";
The logic below gets simpler if you define the illegal characters like
in the aforementioned patch.
Best regards
Heinrich
> + char c;
> + int name_len;
> +
> + /* Check that the filename is valid */
> + for (p = filename; p < filename + strlen(filename); p++) {
> + c = *p;
> +
> + if (('0' <= c) && (c <= '9'))
> + continue;
> + if (('A' <= c) && (c <= 'Z'))
> + continue;
> + if (('a' <= c) && (c <= 'z'))
> + continue;
> + if (strchr(legal, c))
> + continue;
> + /* extended code */
> + if ((0x80 <= c) && (c <= 0xff))
> + continue;
> +
> + return -1;
> + }
> +
<snip />
More information about the U-Boot
mailing list