From patchwork Thu Dec 13 13:30:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 205838 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 91DC32C0092 for ; Fri, 14 Dec 2012 00:30:32 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B72884A322; Thu, 13 Dec 2012 14:30:30 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EJm9aHUdBJqr; Thu, 13 Dec 2012 14:30:29 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 683394A306; Thu, 13 Dec 2012 14:30:28 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 65ABD4A306 for ; Thu, 13 Dec 2012 14:30:26 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9nIrVsIftogp for ; Thu, 13 Dec 2012 14:30:25 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-wg0-f54.google.com (mail-wg0-f54.google.com [74.125.82.54]) by theia.denx.de (Postfix) with ESMTPS id 3AE5A4A2CE for ; Thu, 13 Dec 2012 14:30:23 +0100 (CET) Received: by mail-wg0-f54.google.com with SMTP id fg15so824861wgb.9 for ; Thu, 13 Dec 2012 05:30:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=3v/bRjNbZErv2rY/bbzlEGRg+UB+DpWppf2IgABZgmk=; b=Xz3PWiaKL2wNdh54OaM7TorUuslot1Ccw8q5nb2vdCx2rRxhjOpKbN0lEf8Oeq4HVc c+mvbZ6zb7WrQ1rMto4zwP5i+CwaQY41YvxlrXPx3C9nGa2UWp5Sswgjac7lvQ1MjZqu RzehQiUIUxv/1mv+KOm3A/R0xYlyVvRPe0BtAuIcAKBRN6U6b6BGWWjhpQkAV/pjtDhG cDkwuHWvKq1kCDVTHWHzM6scIjRP11dCIQowlVazXm4sly0wKbMcL+9/431/+Xszrmhr jES/8tuDAg9CNRj2HUxTEtFffUhUa7wmtSCM/isp737EO1fyfpe0vVVSpOYVO3vB5piv zDcQ== Received: by 10.194.177.199 with SMTP id cs7mr8385731wjc.41.1355405422266; Thu, 13 Dec 2012 05:30:22 -0800 (PST) Received: from localhost.localdomain (lyon.paratronic.fr. [213.41.177.106]) by mx.google.com with ESMTPS id b1sm2573315wix.11.2012.12.13.05.30.21 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Dec 2012 05:30:21 -0800 (PST) From: Richard Genoud To: u-boot@lists.denx.de Date: Thu, 13 Dec 2012 14:30:10 +0100 Message-Id: <1355405410-2783-1-git-send-email-richard.genoud@gmail.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <201212131419.59090.marex@denx.de> References: <201212131419.59090.marex@denx.de> Cc: Tom Rini , Marek Vasut Subject: [U-Boot] [PATCHv2] FAT: remove ifdefs to make the code more readable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.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 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 --- 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..7c23b67 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -34,6 +34,12 @@ #include #include +#ifdef CONFIG_SUPPORT_VFAT +static const int vfat_enabled = 1; +#else +static const int 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..e7cda17 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))