mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-17 12:41:32 +00:00
fs/fat: fix case for FAT shortnames
Noticed when comparing our output to linux. There are some lcase bits which control whether filename and/or extension should be downcase'd. Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Łukasz Majewski <lukma@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
89191d6267
commit
21a24c3bf3
3 changed files with 17 additions and 9 deletions
16
fs/fat/fat.c
16
fs/fat/fat.c
|
@ -29,11 +29,13 @@ static const int vfat_enabled = 0;
|
||||||
#endif
|
#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 = tolower(*str);
|
||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
|
@ -131,10 +133,13 @@ static void get_name(dir_entry *dirent, char *s_name)
|
||||||
ptr = s_name;
|
ptr = s_name;
|
||||||
while (*ptr && *ptr != ' ')
|
while (*ptr && *ptr != ' ')
|
||||||
ptr++;
|
ptr++;
|
||||||
|
if (dirent->lcase & CASE_LOWER_BASE)
|
||||||
|
downcase(s_name, (unsigned)(ptr - s_name));
|
||||||
if (dirent->ext[0] && dirent->ext[0] != ' ') {
|
if (dirent->ext[0] && dirent->ext[0] != ' ') {
|
||||||
*ptr = '.';
|
*ptr++ = '.';
|
||||||
ptr++;
|
|
||||||
memcpy(ptr, dirent->ext, 3);
|
memcpy(ptr, dirent->ext, 3);
|
||||||
|
if (dirent->lcase & CASE_LOWER_EXT)
|
||||||
|
downcase(ptr, 3);
|
||||||
ptr[3] = '\0';
|
ptr[3] = '\0';
|
||||||
while (*ptr && *ptr != ' ')
|
while (*ptr && *ptr != ' ')
|
||||||
ptr++;
|
ptr++;
|
||||||
|
@ -144,7 +149,6 @@ static void get_name(dir_entry *dirent, char *s_name)
|
||||||
*s_name = '\0';
|
*s_name = '\0';
|
||||||
else if (*s_name == aRING)
|
else if (*s_name == aRING)
|
||||||
*s_name = DELETED_FLAG;
|
*s_name = DELETED_FLAG;
|
||||||
downcase(s_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int flush_dirty_fat_buffer(fsdata *mydata);
|
static int flush_dirty_fat_buffer(fsdata *mydata);
|
||||||
|
|
|
@ -345,7 +345,7 @@ get_long_file_name(fsdata *mydata, int curclust, __u8 *cluster,
|
||||||
*l_name = '\0';
|
*l_name = '\0';
|
||||||
else if (*l_name == aRING)
|
else if (*l_name == aRING)
|
||||||
*l_name = DELETED_FLAG;
|
*l_name = DELETED_FLAG;
|
||||||
downcase(l_name);
|
downcase(l_name, INT_MAX);
|
||||||
|
|
||||||
/* Return the real directory entry */
|
/* Return the real directory entry */
|
||||||
*retdent = realdent;
|
*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);
|
memcpy(l_filename, filename, name_len);
|
||||||
l_filename[name_len] = 0; /* terminate the string */
|
l_filename[name_len] = 0; /* terminate the string */
|
||||||
downcase(l_filename);
|
downcase(l_filename, INT_MAX);
|
||||||
|
|
||||||
startsect = mydata->rootdir_sect;
|
startsect = mydata->rootdir_sect;
|
||||||
retdent = find_directory_entry(mydata, startsect,
|
retdent = find_directory_entry(mydata, startsect,
|
||||||
|
|
|
@ -128,10 +128,14 @@ typedef struct volume_info
|
||||||
/* Boot sign comes last, 2 bytes */
|
/* Boot sign comes last, 2 bytes */
|
||||||
} volume_info;
|
} volume_info;
|
||||||
|
|
||||||
|
/* see dir_entry::lcase: */
|
||||||
|
#define CASE_LOWER_BASE 8 /* base (name) is lower case */
|
||||||
|
#define CASE_LOWER_EXT 16 /* extension is lower case */
|
||||||
|
|
||||||
typedef struct dir_entry {
|
typedef struct dir_entry {
|
||||||
char name[8],ext[3]; /* Name and extension */
|
char name[8],ext[3]; /* Name and extension */
|
||||||
__u8 attr; /* Attribute bits */
|
__u8 attr; /* Attribute bits */
|
||||||
__u8 lcase; /* Case for base and extension */
|
__u8 lcase; /* Case for name and ext (CASE_LOWER_x) */
|
||||||
__u8 ctime_ms; /* Creation time, milliseconds */
|
__u8 ctime_ms; /* Creation time, milliseconds */
|
||||||
__u16 ctime; /* Creation time */
|
__u16 ctime; /* Creation time */
|
||||||
__u16 cdate; /* Creation date */
|
__u16 cdate; /* Creation date */
|
||||||
|
|
Loading…
Add table
Reference in a new issue