mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-22 20:58:22 +00:00
FAT: remove ifdefs to make the code more readable
ifdefs in the code are making it harder to read. The use of simple if(vfat_enabled) makes no more code and is cleaner. (the code is discarded by the compiler instead of the preprocessor.) NB: if -O0 is used, the code won't be discarded and bonus, now the code compiles even if CONFIG_SUPPORT_VFAT is not defined. Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
This commit is contained in:
parent
fb7e16cc1c
commit
cb940c7ede
2 changed files with 32 additions and 34 deletions
41
fs/fat/fat.c
41
fs/fat/fat.c
|
@ -35,6 +35,12 @@
|
||||||
#include <linux/compiler.h>
|
#include <linux/compiler.h>
|
||||||
#include <linux/ctype.h>
|
#include <linux/ctype.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_SUPPORT_VFAT
|
||||||
|
static const int vfat_enabled = 1;
|
||||||
|
#else
|
||||||
|
static const int vfat_enabled = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert a string to lowercase.
|
* Convert a string to lowercase.
|
||||||
*/
|
*/
|
||||||
|
@ -442,7 +448,6 @@ getit:
|
||||||
} while (1);
|
} while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SUPPORT_VFAT
|
|
||||||
/*
|
/*
|
||||||
* Extract the file name information from 'slotptr' into 'l_name',
|
* Extract the file name information from 'slotptr' into 'l_name',
|
||||||
* starting at l_name[*idx].
|
* starting at l_name[*idx].
|
||||||
|
@ -577,7 +582,6 @@ static __u8 mkcksum(const char name[8], const char ext[3])
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_SUPPORT_VFAT */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the directory entry associated with 'filename' from the directory
|
* Get the directory entry associated with 'filename' from the directory
|
||||||
|
@ -618,8 +622,8 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((dentptr->attr & ATTR_VOLUME)) {
|
if ((dentptr->attr & ATTR_VOLUME)) {
|
||||||
#ifdef CONFIG_SUPPORT_VFAT
|
if (vfat_enabled &&
|
||||||
if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
|
(dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
|
||||||
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
|
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
|
||||||
prevcksum = ((dir_slot *)dentptr)->alias_checksum;
|
prevcksum = ((dir_slot *)dentptr)->alias_checksum;
|
||||||
get_vfatname(mydata, curclust,
|
get_vfatname(mydata, curclust,
|
||||||
|
@ -659,9 +663,7 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
debug("vfatname: |%s|\n", l_name);
|
debug("vfatname: |%s|\n", l_name);
|
||||||
} else
|
} else {
|
||||||
#endif
|
|
||||||
{
|
|
||||||
/* Volume label or VFAT entry */
|
/* Volume label or VFAT entry */
|
||||||
dentptr++;
|
dentptr++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -675,14 +677,15 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,
|
||||||
debug("Dentname == NULL - %d\n", i);
|
debug("Dentname == NULL - %d\n", i);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_SUPPORT_VFAT
|
if (vfat_enabled) {
|
||||||
__u8 csum = mkcksum(dentptr->name, dentptr->ext);
|
__u8 csum = mkcksum(dentptr->name, dentptr->ext);
|
||||||
if (dols && csum == prevcksum) {
|
if (dols && csum == prevcksum) {
|
||||||
prevcksum = 0xffff;
|
prevcksum = 0xffff;
|
||||||
dentptr++;
|
dentptr++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
|
|
||||||
get_name(dentptr, s_name);
|
get_name(dentptr, s_name);
|
||||||
if (dols) {
|
if (dols) {
|
||||||
int isdir = (dentptr->attr & ATTR_DIR);
|
int isdir = (dentptr->attr & ATTR_DIR);
|
||||||
|
@ -885,9 +888,9 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SUPPORT_VFAT
|
if (vfat_enabled)
|
||||||
debug("VFAT Support enabled\n");
|
debug("VFAT Support enabled\n");
|
||||||
#endif
|
|
||||||
debug("FAT%d, fat_sect: %d, fatlength: %d\n",
|
debug("FAT%d, fat_sect: %d, fatlength: %d\n",
|
||||||
mydata->fatsize, mydata->fat_sect, mydata->fatlength);
|
mydata->fatsize, mydata->fat_sect, mydata->fatlength);
|
||||||
debug("Rootdir begins at cluster: %d, sector: %d, offset: %x\n"
|
debug("Rootdir begins at cluster: %d, sector: %d, offset: %x\n"
|
||||||
|
@ -953,10 +956,12 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (vfat_enabled)
|
||||||
csum = mkcksum(dentptr->name, dentptr->ext);
|
csum = mkcksum(dentptr->name, dentptr->ext);
|
||||||
|
|
||||||
if (dentptr->attr & ATTR_VOLUME) {
|
if (dentptr->attr & ATTR_VOLUME) {
|
||||||
#ifdef CONFIG_SUPPORT_VFAT
|
if (vfat_enabled &&
|
||||||
if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
|
(dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
|
||||||
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
|
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
|
||||||
prevcksum =
|
prevcksum =
|
||||||
((dir_slot *)dentptr)->alias_checksum;
|
((dir_slot *)dentptr)->alias_checksum;
|
||||||
|
@ -1000,9 +1005,7 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
|
||||||
}
|
}
|
||||||
debug("Rootvfatname: |%s|\n",
|
debug("Rootvfatname: |%s|\n",
|
||||||
l_name);
|
l_name);
|
||||||
} else
|
} else {
|
||||||
#endif
|
|
||||||
{
|
|
||||||
/* Volume label or VFAT entry */
|
/* Volume label or VFAT entry */
|
||||||
dentptr++;
|
dentptr++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -1016,13 +1019,13 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
|
||||||
}
|
}
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_SUPPORT_VFAT
|
else if (vfat_enabled &&
|
||||||
else if (dols == LS_ROOT && csum == prevcksum) {
|
dols == LS_ROOT && csum == prevcksum) {
|
||||||
prevcksum = 0xffff;
|
prevcksum = 0xffff;
|
||||||
dentptr++;
|
dentptr++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
get_name(dentptr, s_name);
|
get_name(dentptr, s_name);
|
||||||
|
|
||||||
if (dols == LS_ROOT) {
|
if (dols == LS_ROOT) {
|
||||||
|
|
|
@ -249,7 +249,6 @@ static __u32 get_fatent_value(fsdata *mydata, __u32 entry)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SUPPORT_VFAT
|
|
||||||
/*
|
/*
|
||||||
* Set the file name information from 'name' into 'slotptr',
|
* Set the file name information from 'name' into 'slotptr',
|
||||||
*/
|
*/
|
||||||
|
@ -469,8 +468,6 @@ get_long_file_name(fsdata *mydata, int curclust, __u8 *cluster,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the entry at index 'entry' in a FAT (16/32) table.
|
* Set the entry at index 'entry' in a FAT (16/32) table.
|
||||||
*/
|
*/
|
||||||
|
@ -854,16 +851,14 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((dentptr->attr & ATTR_VOLUME)) {
|
if ((dentptr->attr & ATTR_VOLUME)) {
|
||||||
#ifdef CONFIG_SUPPORT_VFAT
|
if (vfat_enabled &&
|
||||||
if ((dentptr->attr & ATTR_VFAT) &&
|
(dentptr->attr & ATTR_VFAT) &&
|
||||||
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
|
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
|
||||||
get_long_file_name(mydata, curclust,
|
get_long_file_name(mydata, curclust,
|
||||||
get_dentfromdir_block,
|
get_dentfromdir_block,
|
||||||
&dentptr, l_name);
|
&dentptr, l_name);
|
||||||
debug("vfatname: |%s|\n", l_name);
|
debug("vfatname: |%s|\n", l_name);
|
||||||
} else
|
} else {
|
||||||
#endif
|
|
||||||
{
|
|
||||||
/* Volume label or VFAT entry */
|
/* Volume label or VFAT entry */
|
||||||
dentptr++;
|
dentptr++;
|
||||||
if (is_next_clust(mydata, dentptr))
|
if (is_next_clust(mydata, dentptr))
|
||||||
|
|
Loading…
Add table
Reference in a new issue