mirror of
https://xff.cz/git/u-boot/
synced 2025-09-01 08:42:12 +02:00
fs: fat: Fix mkcksum() function parameters
The mkcksum() function now takes one parameter, the pointer to 11-byte wide character array, which it then operates on. Currently, the function is wrongly passed (dir_entry)->name, which is only 8-byte wide character array. Though by further inspecting the dir_entry structure, it can be noticed that the name[8] entry is immediatelly followed by ext[3] entry. Thus, name[8] and ext[3] in the dir_entry structure actually work as this 11-byte wide array since they're placed right next to each other by current compiler behavior. Depending on this is obviously wrong, thus fix this by correctly passing both (dir_entry)->name and (dir_entry)->ext to the mkcksum() function and adjust the function appropriately. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Tom Rini <trini@ti.com>
This commit is contained in:
20
fs/fat/fat.c
20
fs/fat/fat.c
@@ -567,15 +567,16 @@ get_vfatname(fsdata *mydata, int curclust, __u8 *cluster,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate short name checksum */
|
/* Calculate short name checksum */
|
||||||
static __u8 mkcksum(const char *str)
|
static __u8 mkcksum(const char name[8], const char ext[3])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
__u8 ret = 0;
|
__u8 ret = 0;
|
||||||
|
|
||||||
for (i = 0; i < 11; i++) {
|
for (i = 0; i < sizeof(name); i++)
|
||||||
ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + str[i];
|
ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + name[i];
|
||||||
}
|
for (i = 0; i < sizeof(ext); i++)
|
||||||
|
ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + ext[i];
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -678,7 +679,8 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_SUPPORT_VFAT
|
#ifdef CONFIG_SUPPORT_VFAT
|
||||||
if (dols && mkcksum(dentptr->name) == prevcksum) {
|
__u8 csum = mkcksum(dentptr->name, dentptr->ext);
|
||||||
|
if (dols && csum == prevcksum) {
|
||||||
prevcksum = 0xffff;
|
prevcksum = 0xffff;
|
||||||
dentptr++;
|
dentptr++;
|
||||||
continue;
|
continue;
|
||||||
@@ -946,13 +948,16 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
|
|||||||
|
|
||||||
for (i = 0; i < DIRENTSPERBLOCK; i++) {
|
for (i = 0; i < DIRENTSPERBLOCK; i++) {
|
||||||
char s_name[14], l_name[VFAT_MAXLEN_BYTES];
|
char s_name[14], l_name[VFAT_MAXLEN_BYTES];
|
||||||
|
__u8 csum;
|
||||||
|
|
||||||
l_name[0] = '\0';
|
l_name[0] = '\0';
|
||||||
if (dentptr->name[0] == DELETED_FLAG) {
|
if (dentptr->name[0] == DELETED_FLAG) {
|
||||||
dentptr++;
|
dentptr++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((dentptr->attr & ATTR_VOLUME)) {
|
|
||||||
|
csum = mkcksum(dentptr->name, dentptr->ext);
|
||||||
|
if (dentptr->attr & ATTR_VOLUME) {
|
||||||
#ifdef CONFIG_SUPPORT_VFAT
|
#ifdef CONFIG_SUPPORT_VFAT
|
||||||
if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
|
if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
|
||||||
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
|
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
|
||||||
@@ -1015,8 +1020,7 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_SUPPORT_VFAT
|
#ifdef CONFIG_SUPPORT_VFAT
|
||||||
else if (dols == LS_ROOT &&
|
else if (dols == LS_ROOT && csum == prevcksum) {
|
||||||
mkcksum(dentptr->name) == prevcksum) {
|
|
||||||
prevcksum = 0xffff;
|
prevcksum = 0xffff;
|
||||||
dentptr++;
|
dentptr++;
|
||||||
continue;
|
continue;
|
||||||
|
@@ -335,7 +335,7 @@ fill_dir_slot(fsdata *mydata, dir_entry **dentptr, const char *l_name)
|
|||||||
|
|
||||||
/* Get short file name and checksum value */
|
/* Get short file name and checksum value */
|
||||||
strncpy(s_name, (*dentptr)->name, 16);
|
strncpy(s_name, (*dentptr)->name, 16);
|
||||||
checksum = mkcksum(s_name);
|
checksum = mkcksum((*dentptr)->name, (*dentptr)->ext);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
memset(slotptr, 0x00, sizeof(dir_slot));
|
memset(slotptr, 0x00, sizeof(dir_slot));
|
||||||
|
Reference in New Issue
Block a user