From patchwork Mon Sep 28 13:45:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Th=C3=A9baudeau?= X-Patchwork-Id: 523346 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 62C8714017E for ; Mon, 28 Sep 2015 23:54:24 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 708EA4B972; Mon, 28 Sep 2015 15:54:06 +0200 (CEST) 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 XIsouRX8vSCd; Mon, 28 Sep 2015 15:54:06 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D53074B949; Mon, 28 Sep 2015 15:53:44 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 608D04B924 for ; Mon, 28 Sep 2015 15:51:12 +0200 (CEST) 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 EB2hzFMUOg7Y for ; Mon, 28 Sep 2015 15:51:12 +0200 (CEST) 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 authsmtp.register.it (authsmtp83.register.it [195.110.122.168]) by theia.denx.de (Postfix) with ESMTP id 290EF4B919 for ; Mon, 28 Sep 2015 15:51:10 +0200 (CEST) Received: from rad-ubuntu.home ([90.25.112.137]) by paganini34 with id Ndm31r01b2xv6ya01dm840; Mon, 28 Sep 2015 15:46:08 +0200 X-Rid: benoit@wsystem.com@90.25.112.137 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= To: u-boot@lists.denx.de Date: Mon, 28 Sep 2015 15:45:31 +0200 Message-Id: <1443447932-14139-4-git-send-email-benoit@wsystem.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1443447932-14139-1-git-send-email-benoit@wsystem.com> References: <807994631.1713509.1365795559751.JavaMail.root@advansee.com> <1443447932-14139-1-git-send-email-benoit@wsystem.com> MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 28 Sep 2015 15:53:33 +0200 Cc: Tom Rini , =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Subject: [U-Boot] [PATCH 4/5] fs/fat/fat_write: Factor out duplicate code X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Signed-off-by: Benoît Thébaudeau --- fs/fat/fat_write.c | 72 +++++++++++++++++------------------------------------- 1 file changed, 22 insertions(+), 50 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 2399844..2d032ee 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -1028,10 +1028,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, if (retdent) { /* Update file size and start_cluster in a directory entry */ retdent->size = cpu_to_le32(size); - start_cluster = FAT2CPU16(retdent->start); - if (mydata->fatsize == 32) - start_cluster |= - (FAT2CPU16(retdent->starthi) << 16); + start_cluster = START(retdent); ret = check_overflow(mydata, start_cluster, size); if (ret) { @@ -1044,29 +1041,6 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, printf("Error: clearing FAT entries\n"); goto exit; } - - ret = set_contents(mydata, retdent, buffer, size, actwrite); - if (ret < 0) { - printf("Error: writing contents\n"); - goto exit; - } - debug("attempt to write 0x%llx bytes\n", *actwrite); - - /* Flush fat buffer */ - ret = flush_fat_buffer(mydata); - if (ret) { - printf("Error: flush fat buffer\n"); - goto exit; - } - - /* Write directory table to device */ - ret = set_cluster(mydata, dir_curclust, - get_dentfromdir_block, - mydata->clust_size * mydata->sect_size); - if (ret) { - printf("Error: writing directory entry\n"); - goto exit; - } } else { /* Set short name to set alias checksum field in dir_slot */ set_name(empty_dentptr, filename); @@ -1088,31 +1062,29 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, fill_dentry(mydata, empty_dentptr, filename, start_cluster, size, 0x20); - ret = set_contents(mydata, empty_dentptr, buffer, size, - actwrite); - if (ret < 0) { - printf("Error: writing contents\n"); - goto exit; - } - debug("attempt to write 0x%llx bytes\n", *actwrite); - - /* Flush fat buffer */ - ret = flush_fat_buffer(mydata); - if (ret) { - printf("Error: flush fat buffer\n"); - goto exit; - } - - /* Write directory table to device */ - ret = set_cluster(mydata, dir_curclust, - get_dentfromdir_block, - mydata->clust_size * mydata->sect_size); - if (ret) { - printf("Error: writing directory entry\n"); - goto exit; - } + retdent = empty_dentptr; } + ret = set_contents(mydata, retdent, buffer, size, actwrite); + if (ret < 0) { + printf("Error: writing contents\n"); + goto exit; + } + debug("attempt to write 0x%llx bytes\n", *actwrite); + + /* Flush fat buffer */ + ret = flush_fat_buffer(mydata); + if (ret) { + printf("Error: flush fat buffer\n"); + goto exit; + } + + /* Write directory table to device */ + ret = set_cluster(mydata, dir_curclust, get_dentfromdir_block, + mydata->clust_size * mydata->sect_size); + if (ret) + printf("Error: writing directory entry\n"); + exit: free(mydata->fatbuf); return ret;