public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Benoît Thébaudeau" <benoit@wsystem.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/5] fs/fat/fat_write: Factor out duplicate code
Date: Mon, 28 Sep 2015 15:45:31 +0200	[thread overview]
Message-ID: <1443447932-14139-4-git-send-email-benoit@wsystem.com> (raw)
In-Reply-To: <1443447932-14139-1-git-send-email-benoit@wsystem.com>

Signed-off-by: Beno?t Th?baudeau <benoit@wsystem.com>
---
 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;
-- 
2.1.4

  parent reply	other threads:[~2015-09-28 13:45 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-12 12:46 [U-Boot] fatwrite problem Ruud Commandeur
2013-04-12 14:11 ` Mats Kärrman
2013-04-12 15:06   ` Ruud Commandeur
2013-04-12 15:12     ` Tom Rini
2013-04-12 15:23       ` Ruud Commandeur
2013-04-12 15:43         ` Tom Rini
2013-04-12 19:39       ` Benoît Thébaudeau
2013-04-12 20:42         ` Tom Rini
2013-04-12 21:17           ` Benoît Thébaudeau
2013-04-16  9:32             ` Ruud Commandeur
2013-05-14 15:13             ` Ruud Commandeur
2013-05-14 15:31               ` Tom Rini
2015-09-28 13:45         ` [U-Boot] [PATCH 1/5] fs/fat/fat_write: Fix buffer alignments Benoît Thébaudeau
2015-09-28 13:45           ` [U-Boot] [PATCH 2/5] fs/fat/fat_write: Merge calls to set_cluster() Benoît Thébaudeau
2015-10-12 15:15             ` [U-Boot] [U-Boot, " Tom Rini
2015-09-28 13:45           ` [U-Boot] [PATCH 3/5] fs/fat/fat_write: Fix curclust/newclust mix-up Benoît Thébaudeau
2015-10-12 15:15             ` [U-Boot] [U-Boot, " Tom Rini
2015-09-28 13:45           ` Benoît Thébaudeau [this message]
2015-10-12 15:15             ` [U-Boot] [U-Boot, 4/5] fs/fat/fat_write: Factor out duplicate code Tom Rini
2015-09-28 13:45           ` [U-Boot] [PATCH 5/5] fs/fat/fat_write: Fix management of empty files Benoît Thébaudeau
2015-10-12 15:15             ` [U-Boot] [U-Boot, " Tom Rini
2015-09-28 15:22           ` [U-Boot] [PATCH 1/5] fs/fat/fat_write: Fix buffer alignments Tom Rini
2015-10-07 19:48             ` Benoît Thébaudeau
2015-10-12 15:15           ` [U-Boot] [U-Boot,1/5] " 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=1443447932-14139-4-git-send-email-benoit@wsystem.com \
    --to=benoit@wsystem.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