mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/3] fat: revert fat caching mechanism
Date: Wed, 15 Feb 2012 09:10:49 +0100	[thread overview]
Message-ID: <1329293450-10234-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1329293450-10234-1-git-send-email-s.hauer@pengutronix.de>

There seems to be a bug in this mechanism. It's easy to
get the cached fat out of sync with the device. Revert
it for now. This includes a huge write performance drop.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fat/ff.c |   93 ++++++++++++----------------------------------------------
 1 files changed, 20 insertions(+), 73 deletions(-)

diff --git a/fs/fat/ff.c b/fs/fat/ff.c
index 0087e21..a720389 100644
--- a/fs/fat/ff.c
+++ b/fs/fat/ff.c
@@ -234,89 +234,38 @@ struct fat_sector {
 	unsigned char data[0];
 };
 
-#ifdef CONFIG_FS_FAT_WRITE
-static int push_fat_sector(FATFS *fs, DWORD sector)
-{
-	struct fat_sector *s;
-
-	list_for_each_entry(s, &fs->dirtylist, list) {
-		if (s->sector == sector) {
-			memcpy(s->data, fs->win, SS(fs));
-			return 0;
-		}
-	}
-
-	s = xmalloc(sizeof(*s) + SS(fs));
-	memcpy(s->data, fs->win, SS(fs));
-	s->sector = sector;
-	list_add_tail(&s->list, &fs->dirtylist);
-
-	return 0;
-}
-#endif
-
-static int get_fat_sector(FATFS *fs, DWORD sector)
-{
-	struct fat_sector *s;
-
-	list_for_each_entry(s, &fs->dirtylist, list) {
-		if (s->sector == sector) {
-			memcpy(fs->win, s->data, SS(fs));
-			return 0;
-		}
-	}
-
-	return disk_read(fs, fs->win, sector, 1);
-}
+/*-----------------------------------------------------------------------*/
+/* Change window offset                                                  */
+/*-----------------------------------------------------------------------*/
 
-#ifdef CONFIG_FS_FAT_WRITE
-static int flush_dirty_fat(FATFS *fs)
-{
-	struct fat_sector *s, *tmp;
-
-	list_for_each_entry_safe(s, tmp, &fs->dirtylist, list) {
-		disk_write(fs, s->data, s->sector, 1);
-		if (s->sector < (fs->fatbase + fs->fsize)) {
-			/* In FAT area */
-			BYTE nf;
-			DWORD wsect = s->sector;
-			/* Reflect the change to all FAT copies */
-			for (nf = fs->n_fats; nf > 1; nf--) {
-				wsect += fs->fsize;
-				disk_write(fs, s->data, wsect, 1);
-			}
-		}
-		list_del(&s->list);
-		free(s);
-	}
-
-	return 0;
-}
-#endif
-
-static int move_window (
-	FATFS *fs,	/* File system object */
+static
+int move_window (
+	FATFS *fs,		/* File system object */
 	DWORD sector	/* Sector number to make appearance in the fs->win[] */
-)			/* Move to zero only writes back dirty window */
+)					/* Move to zero only writes back dirty window */
 {
 	DWORD wsect;
-	int ret;
+
 
 	wsect = fs->winsect;
 	if (wsect != sector) {	/* Changed current window */
 #ifdef CONFIG_FS_FAT_WRITE
-		/* Write back dirty window if needed */
-		if (fs->wflag) {
-			ret = push_fat_sector(fs, wsect);
-			if (ret)
-				return ret;
+		if (fs->wflag) {	/* Write back dirty window if needed */
+			if (disk_write(fs, fs->win, wsect, 1) != RES_OK)
+				return -EIO;
 			fs->wflag = 0;
+			if (wsect < (fs->fatbase + fs->fsize)) {	/* In FAT area */
+				BYTE nf;
+				for (nf = fs->n_fats; nf > 1; nf--) {	/* Reflect the change to all FAT copies */
+					wsect += fs->fsize;
+					disk_write(fs, fs->win, wsect, 1);
+				}
+			}
 		}
 #endif
 		if (sector) {
-			ret = get_fat_sector(fs, sector);
-			if (ret)
-				return ret;
+			if (disk_read(fs, fs->win, sector, 1) != RES_OK)
+				return -EIO;
 			fs->winsect = sector;
 		}
 	}
@@ -2091,8 +2040,6 @@ int f_sync (
 	fp->fs->wflag = 1;
 	res = sync(fp->fs);
 
-	flush_dirty_fat(fp->fs);
-
 	return res;
 }
 
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2012-02-15  8:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-15  8:10 Fix FAT block caching Sascha Hauer
2012-02-15  8:10 ` [PATCH 1/3] list: add list_last_entry function Sascha Hauer
2012-02-15  8:10 ` Sascha Hauer [this message]
2012-02-15  8:10 ` [PATCH 3/3] block: reimplement caching Sascha Hauer

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=1329293450-10234-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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