Commit cb940c7ede85994847c80f4300f2f7eac6e94c48

Authored by Richard Genoud
Committed by Tom Rini
1 parent fb7e16cc1c

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>

Showing 2 changed files with 32 additions and 34 deletions Side-by-side Diff

... ... @@ -35,6 +35,12 @@
35 35 #include <linux/compiler.h>
36 36 #include <linux/ctype.h>
37 37  
  38 +#ifdef CONFIG_SUPPORT_VFAT
  39 +static const int vfat_enabled = 1;
  40 +#else
  41 +static const int vfat_enabled = 0;
  42 +#endif
  43 +
38 44 /*
39 45 * Convert a string to lowercase.
40 46 */
... ... @@ -442,7 +448,6 @@
442 448 } while (1);
443 449 }
444 450  
445   -#ifdef CONFIG_SUPPORT_VFAT
446 451 /*
447 452 * Extract the file name information from 'slotptr' into 'l_name',
448 453 * starting at l_name[*idx].
... ... @@ -577,7 +582,6 @@
577 582  
578 583 return ret;
579 584 }
580   -#endif /* CONFIG_SUPPORT_VFAT */
581 585  
582 586 /*
583 587 * Get the directory entry associated with 'filename' from the directory
... ... @@ -618,8 +622,8 @@
618 622 continue;
619 623 }
620 624 if ((dentptr->attr & ATTR_VOLUME)) {
621   -#ifdef CONFIG_SUPPORT_VFAT
622   - if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
  625 + if (vfat_enabled &&
  626 + (dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
623 627 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
624 628 prevcksum = ((dir_slot *)dentptr)->alias_checksum;
625 629 get_vfatname(mydata, curclust,
... ... @@ -659,9 +663,7 @@
659 663 continue;
660 664 }
661 665 debug("vfatname: |%s|\n", l_name);
662   - } else
663   -#endif
664   - {
  666 + } else {
665 667 /* Volume label or VFAT entry */
666 668 dentptr++;
667 669 continue;
668 670  
... ... @@ -675,14 +677,15 @@
675 677 debug("Dentname == NULL - %d\n", i);
676 678 return NULL;
677 679 }
678   -#ifdef CONFIG_SUPPORT_VFAT
679   - __u8 csum = mkcksum(dentptr->name, dentptr->ext);
680   - if (dols && csum == prevcksum) {
681   - prevcksum = 0xffff;
682   - dentptr++;
683   - continue;
  680 + if (vfat_enabled) {
  681 + __u8 csum = mkcksum(dentptr->name, dentptr->ext);
  682 + if (dols && csum == prevcksum) {
  683 + prevcksum = 0xffff;
  684 + dentptr++;
  685 + continue;
  686 + }
684 687 }
685   -#endif
  688 +
686 689 get_name(dentptr, s_name);
687 690 if (dols) {
688 691 int isdir = (dentptr->attr & ATTR_DIR);
... ... @@ -885,9 +888,9 @@
885 888 return -1;
886 889 }
887 890  
888   -#ifdef CONFIG_SUPPORT_VFAT
889   - debug("VFAT Support enabled\n");
890   -#endif
  891 + if (vfat_enabled)
  892 + debug("VFAT Support enabled\n");
  893 +
891 894 debug("FAT%d, fat_sect: %d, fatlength: %d\n",
892 895 mydata->fatsize, mydata->fat_sect, mydata->fatlength);
893 896 debug("Rootdir begins at cluster: %d, sector: %d, offset: %x\n"
894 897  
... ... @@ -953,10 +956,12 @@
953 956 continue;
954 957 }
955 958  
956   - csum = mkcksum(dentptr->name, dentptr->ext);
  959 + if (vfat_enabled)
  960 + csum = mkcksum(dentptr->name, dentptr->ext);
  961 +
957 962 if (dentptr->attr & ATTR_VOLUME) {
958   -#ifdef CONFIG_SUPPORT_VFAT
959   - if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
  963 + if (vfat_enabled &&
  964 + (dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
960 965 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
961 966 prevcksum =
962 967 ((dir_slot *)dentptr)->alias_checksum;
... ... @@ -1000,9 +1005,7 @@
1000 1005 }
1001 1006 debug("Rootvfatname: |%s|\n",
1002 1007 l_name);
1003   - } else
1004   -#endif
1005   - {
  1008 + } else {
1006 1009 /* Volume label or VFAT entry */
1007 1010 dentptr++;
1008 1011 continue;
1009 1012  
... ... @@ -1016,13 +1019,13 @@
1016 1019 }
1017 1020 goto exit;
1018 1021 }
1019   -#ifdef CONFIG_SUPPORT_VFAT
1020   - else if (dols == LS_ROOT && csum == prevcksum) {
  1022 + else if (vfat_enabled &&
  1023 + dols == LS_ROOT && csum == prevcksum) {
1021 1024 prevcksum = 0xffff;
1022 1025 dentptr++;
1023 1026 continue;
1024 1027 }
1025   -#endif
  1028 +
1026 1029 get_name(dentptr, s_name);
1027 1030  
1028 1031 if (dols == LS_ROOT) {
... ... @@ -249,7 +249,6 @@
249 249 return ret;
250 250 }
251 251  
252   -#ifdef CONFIG_SUPPORT_VFAT
253 252 /*
254 253 * Set the file name information from 'name' into 'slotptr',
255 254 */
... ... @@ -469,8 +468,6 @@
469 468 return 0;
470 469 }
471 470  
472   -#endif
473   -
474 471 /*
475 472 * Set the entry at index 'entry' in a FAT (16/32) table.
476 473 */
477 474  
... ... @@ -854,16 +851,14 @@
854 851 continue;
855 852 }
856 853 if ((dentptr->attr & ATTR_VOLUME)) {
857   -#ifdef CONFIG_SUPPORT_VFAT
858   - if ((dentptr->attr & ATTR_VFAT) &&
  854 + if (vfat_enabled &&
  855 + (dentptr->attr & ATTR_VFAT) &&
859 856 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
860 857 get_long_file_name(mydata, curclust,
861 858 get_dentfromdir_block,
862 859 &dentptr, l_name);
863 860 debug("vfatname: |%s|\n", l_name);
864   - } else
865   -#endif
866   - {
  861 + } else {
867 862 /* Volume label or VFAT entry */
868 863 dentptr++;
869 864 if (is_next_clust(mydata, dentptr))