[U-Boot] [PATCH v2 8/8] fs/fat: fix case for FAT shortnames

Simon Glass sjg at chromium.org
Tue Sep 5 08:56:41 UTC 2017


Hi Rob,

On 3 September 2017 at 23:22, Łukasz Majewski <lukma at denx.de> wrote:
> On 09/02/2017 06:38 PM, Rob Clark wrote:
>>
>> Noticed when comparing our output to linux.  There are some lcase bits
>> which control whether filename and/or extension should be downcase'd.
>
>
> Reviewed-by: Łukasz Majewski <lukma at denx.de>
>
>
>>
>> Signed-off-by: Rob Clark <robdclark at gmail.com>
>> ---
>>   fs/fat/fat.c       | 17 ++++++++++++-----
>>   fs/fat/fat_write.c |  4 ++--
>>   include/fat.h      |  3 +++
>>   3 files changed, 17 insertions(+), 7 deletions(-)
>>
>> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
>> index fc3106aacb..ccbf7ba1c8 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,16 @@ 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] != ' ') {
>> +               char *ext;
>> +
>>                 *ptr = '.';
>> -               ptr++;
>> +               ext = ++ptr;

I think this would be clearer as:

   *ptr++ = '.';
   ext = ptr;

But given that you only use ext once, can you just drop it?

>>                 memcpy(ptr, dirent->ext, 3);
>> +               if (dirent->lcase & CASE_LOWER_EXT)
>> +                       downcase(ext, 3);
>>                 ptr[3] = '\0';
>>                 while (*ptr && *ptr != ' ')
>>                         ptr++;
>> @@ -144,7 +152,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);
>> diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
>> index 4ca024c208..655ad4ec84 100644
>> --- a/fs/fat/fat_write.c
>> +++ b/fs/fat/fat_write.c
>> @@ -345,7 +345,7 @@ get_long_file_name(fsdata *mydata, int curclust, __u8
>> *cluster,
>>                 *l_name = '\0';
>>         else if (*l_name == aRING)
>>                 *l_name = DELETED_FLAG;
>> -       downcase(l_name);
>> +       downcase(l_name, ~0);

Could this be INT_MAX to indicate all? I think ~0 is a bit obscure

>>         /* Return the real directory entry */
>>         *retdent = realdent;
>> @@ -981,7 +981,7 @@ static int do_fat_write(const char *filename, void
>> *buffer, loff_t size,
>>         memcpy(l_filename, filename, name_len);
>>         l_filename[name_len] = 0; /* terminate the string */
>> -       downcase(l_filename);
>> +       downcase(l_filename, ~0);

here also

>>         startsect = mydata->rootdir_sect;
>>         retdent = find_directory_entry(mydata, startsect,
>> diff --git a/include/fat.h b/include/fat.h
>> index b2d4b952fd..5e4924316a 100644
>> --- a/include/fat.h
>> +++ b/include/fat.h
>> @@ -128,6 +128,9 @@ typedef struct volume_info
>>         /* Boot sign comes last, 2 bytes */
>>   } volume_info;
>>   +#define CASE_LOWER_BASE      8       /* base is lower case */
>> +#define CASE_LOWER_EXT 16      /* extension is lower case */

Where are these two used? If they are flags can you mention somewhere
what uses them?

>> +
>>   typedef struct dir_entry {
>>         char    name[8],ext[3]; /* Name and extension */
>>         __u8    attr;           /* Attribute bits */
>>
>

Regards,
Simon


More information about the U-Boot mailing list