From: Richard Genoud <richard.genoud@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] FAT: remove ifdefs to make the code more readable
Date: Thu, 13 Dec 2012 11:47:35 +0100 [thread overview]
Message-ID: <1355395656-5838-2-git-send-email-richard.genoud@gmail.com> (raw)
In-Reply-To: <50BE21CC.4030603@denx.de>
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 and linker instead of the
preprocessor.)
and bonus, now the code compiles even if CONFIG_SUPPORT_VFAT is not
defined.
Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
fs/fat/fat.c | 55 +++++++++++++++++++++++++++------------------------
fs/fat/fat_write.c | 11 ++-------
2 files changed, 32 insertions(+), 34 deletions(-)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 393c378..c79e3e3 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -34,6 +34,12 @@
#include <malloc.h>
#include <linux/compiler.h>
+#ifdef CONFIG_SUPPORT_VFAT
+#define VFAT_ENABLED 1
+#else
+#define VFAT_ENABLED 0
+#endif
+
/*
* Convert a string to lowercase.
*/
@@ -441,7 +447,6 @@ getit:
} while (1);
}
-#ifdef CONFIG_SUPPORT_VFAT
/*
* Extract the file name information from 'slotptr' into 'l_name',
* starting at l_name[*idx].
@@ -576,7 +581,6 @@ static __u8 mkcksum(const char name[8], const char ext[3])
return ret;
}
-#endif /* CONFIG_SUPPORT_VFAT */
/*
* Get the directory entry associated with 'filename' from the directory
@@ -617,8 +621,8 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,
continue;
}
if ((dentptr->attr & ATTR_VOLUME)) {
-#ifdef CONFIG_SUPPORT_VFAT
- if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
+ if (VFAT_ENABLED &&
+ (dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
prevcksum = ((dir_slot *)dentptr)->alias_checksum;
get_vfatname(mydata, curclust,
@@ -658,9 +662,7 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,
continue;
}
debug("vfatname: |%s|\n", l_name);
- } else
-#endif
- {
+ } else {
/* Volume label or VFAT entry */
dentptr++;
continue;
@@ -674,14 +676,15 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,
debug("Dentname == NULL - %d\n", i);
return NULL;
}
-#ifdef CONFIG_SUPPORT_VFAT
- __u8 csum = mkcksum(dentptr->name, dentptr->ext);
- if (dols && csum == prevcksum) {
- prevcksum = 0xffff;
- dentptr++;
- continue;
+ if (VFAT_ENABLED) {
+ __u8 csum = mkcksum(dentptr->name, dentptr->ext);
+ if (dols && csum == prevcksum) {
+ prevcksum = 0xffff;
+ dentptr++;
+ continue;
+ }
}
-#endif
+
get_name(dentptr, s_name);
if (dols) {
int isdir = (dentptr->attr & ATTR_DIR);
@@ -884,9 +887,9 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
return -1;
}
-#ifdef CONFIG_SUPPORT_VFAT
- debug("VFAT Support enabled\n");
-#endif
+ if (VFAT_ENABLED)
+ debug("VFAT Support enabled\n");
+
debug("FAT%d, fat_sect: %d, fatlength: %d\n",
mydata->fatsize, mydata->fat_sect, mydata->fatlength);
debug("Rootdir begins at cluster: %d, sector: %d, offset: %x\n"
@@ -952,10 +955,12 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
continue;
}
- csum = mkcksum(dentptr->name, dentptr->ext);
+ if (VFAT_ENABLED)
+ csum = mkcksum(dentptr->name, dentptr->ext);
+
if (dentptr->attr & ATTR_VOLUME) {
-#ifdef CONFIG_SUPPORT_VFAT
- if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
+ if (VFAT_ENABLED &&
+ (dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
prevcksum =
((dir_slot *)dentptr)->alias_checksum;
@@ -999,9 +1004,7 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
}
debug("Rootvfatname: |%s|\n",
l_name);
- } else
-#endif
- {
+ } else {
/* Volume label or VFAT entry */
dentptr++;
continue;
@@ -1015,13 +1018,13 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
}
goto exit;
}
-#ifdef CONFIG_SUPPORT_VFAT
- else if (dols == LS_ROOT && csum == prevcksum) {
+ else if (VFAT_ENABLED &&
+ dols == LS_ROOT && csum == prevcksum) {
prevcksum = 0xffff;
dentptr++;
continue;
}
-#endif
+
get_name(dentptr, s_name);
if (dols == LS_ROOT) {
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 4a1bda0..ed3eaa0 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -248,7 +248,6 @@ static __u32 get_fatent_value(fsdata *mydata, __u32 entry)
return ret;
}
-#ifdef CONFIG_SUPPORT_VFAT
/*
* Set the file name information from 'name' into 'slotptr',
*/
@@ -468,8 +467,6 @@ get_long_file_name(fsdata *mydata, int curclust, __u8 *cluster,
return 0;
}
-#endif
-
/*
* Set the entry at index 'entry' in a FAT (16/32) table.
*/
@@ -853,16 +850,14 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect,
continue;
}
if ((dentptr->attr & ATTR_VOLUME)) {
-#ifdef CONFIG_SUPPORT_VFAT
- if ((dentptr->attr & ATTR_VFAT) &&
+ if (VFAT_ENABLED &&
+ (dentptr->attr & ATTR_VFAT) &&
(dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
get_long_file_name(mydata, curclust,
get_dentfromdir_block,
&dentptr, l_name);
debug("vfatname: |%s|\n", l_name);
- } else
-#endif
- {
+ } else {
/* Volume label or VFAT entry */
dentptr++;
if (is_next_clust(mydata, dentptr))
--
1.7.2.5
next prev parent reply other threads:[~2012-12-13 10:47 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-04 13:04 [U-Boot] [PATCH] FAT: make FAT compile without VFAT Richard Genoud
2012-12-04 14:24 ` Marek Vasut
2012-12-04 15:32 ` Richard Genoud
2012-12-04 16:16 ` Stefano Babic
2012-12-13 10:47 ` [U-Boot] [PATCH 0/2] clean some FAT code Richard Genoud
2012-12-13 12:45 ` Marek Vasut
2012-12-13 12:57 ` Richard Genoud
2012-12-13 10:47 ` Richard Genoud [this message]
2012-12-13 12:46 ` [U-Boot] [PATCH 1/2] FAT: remove ifdefs to make the code more readable Marek Vasut
2012-12-13 13:00 ` Richard Genoud
2012-12-13 13:12 ` Marek Vasut
2012-12-13 13:16 ` Richard Genoud
2012-12-13 13:19 ` Marek Vasut
2012-12-13 13:30 ` [U-Boot] [PATCHv2] " Richard Genoud
2013-02-04 16:42 ` [U-Boot] [U-Boot, PATCHv2] " Tom Rini
2012-12-13 13:09 ` [U-Boot] [PATCH 1/2] " Tom Rini
2012-12-13 13:15 ` Richard Genoud
2012-12-13 13:51 ` Marek Vasut
2012-12-13 14:24 ` Richard Genoud
2012-12-13 14:41 ` Tom Rini
2012-12-13 10:47 ` [U-Boot] [PATCH 2/2] FAT: use toupper/tolower instead of recoding them Richard Genoud
2012-12-13 12:47 ` Marek Vasut
2012-12-14 8:56 ` Stefano Babic
2013-02-04 16:41 ` [U-Boot] [U-Boot, " Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1355395656-5838-2-git-send-email-richard.genoud@gmail.com \
--to=richard.genoud@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox