From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/4] fs: fat: flush metadata updates to the block device
Date: Tue, 25 Aug 2026 12:10:56 +0200 [thread overview]
Message-ID: <20260825101106.2127202-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260825101106.2127202-1-a.fatoum@pengutronix.de>
The disk_ioctl glue that barebox provides can take a CTRL_SYNC command,
but barebox implemented it as a no-op.
Instead, various file system callbacks did flushing manually instead
of having fat.c do it via disk_ioctl.
Implement disk_ioctl(..., CTRL_SYNC) and drop the now superfluous
flushes.
Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fat/diskio.h | 1 +
fs/fat/fat-diskio.c | 4 ++++
fs/fat/fat.c | 46 ++++++++++++++-------------------------------
3 files changed, 19 insertions(+), 32 deletions(-)
diff --git a/fs/fat/diskio.h b/fs/fat/diskio.h
index 04a587e3bc47..86fa0f21e365 100644
--- a/fs/fat/diskio.h
+++ b/fs/fat/diskio.h
@@ -40,6 +40,7 @@ DSTATUS disk_status (FATFS *fatfs);
DRESULT disk_read (FATFS *fatfs, BYTE*, DWORD, BYTE);
#if _READONLY == 0
DRESULT disk_write (FATFS *fatfs, const BYTE*, DWORD, BYTE);
+DRESULT disk_flush (FATFS *fatfs);
#endif
DRESULT disk_ioctl (FATFS *fatfs, BYTE, void*);
diff --git a/fs/fat/fat-diskio.c b/fs/fat/fat-diskio.c
index 6ba18993b870..8e26b6b1e9bb 100644
--- a/fs/fat/fat-diskio.c
+++ b/fs/fat/fat-diskio.c
@@ -28,7 +28,11 @@ DRESULT disk_ioctl (FATFS *fat, BYTE command, void *buf)
*(WORD *)buf = disk_sector_size(fat);
return RES_OK;
case CTRL_SYNC:
+#if _READONLY == 0
+ return disk_flush(fat);
+#else
return RES_OK;
+#endif
default:
return RES_PARERR;
}
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index b50867524a74..c2e6969f8109 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -78,6 +78,13 @@ DRESULT disk_write(FATFS *fat, const BYTE *buf, DWORD sector, BYTE count)
return RES_OK;
}
+DRESULT disk_flush(FATFS *fat)
+{
+ struct fat_priv *priv = fat->userdata;
+
+ return cdev_flush(priv->cdev) ? RES_ERROR : RES_OK;
+}
+
/* ---------------------------------------------------------------*/
#ifdef CONFIG_FS_FAT_WRITE
@@ -91,51 +98,28 @@ static int fat_create(struct device *dev, const char *pathname, mode_t mode)
if (ret)
return ret;
- f_close(&f_file);
-
- return 0;
+ return f_close(&f_file);
}
static int fat_unlink(struct device *dev, const char *pathname)
{
struct fat_priv *priv = dev->priv;
- int ret;
- ret = f_unlink(&priv->fat, pathname);
- if (ret)
- return ret;
-
- cdev_flush(priv->cdev);
-
- return 0;
+ return f_unlink(&priv->fat, pathname);
}
static int fat_mkdir(struct device *dev, const char *pathname)
{
struct fat_priv *priv = dev->priv;
- int ret;
- ret = f_mkdir(&priv->fat, pathname);
- if (ret)
- return ret;
-
- cdev_flush(priv->cdev);
-
- return 0;
+ return f_mkdir(&priv->fat, pathname);
}
static int fat_rmdir(struct device *dev, const char *pathname)
{
struct fat_priv *priv = dev->priv;
- int ret;
- ret = f_unlink(&priv->fat, pathname);
- if (ret)
- return ret;
-
- cdev_flush(priv->cdev);
-
- return 0;
+ return f_unlink(&priv->fat, pathname);
}
static int fat_write(struct file *f, const void *buf, size_t insize)
@@ -224,16 +208,14 @@ static int fat_open(struct device *dev, struct file *file, const char *filename)
static int fat_close(struct device *dev, struct file *f)
{
- struct fat_priv *priv = dev->priv;
FIL *f_file = f->private_data;
+ int ret;
- f_close(f_file);
+ ret = f_close(f_file);
free(f_file);
- cdev_flush(priv->cdev);
-
- return 0;
+ return ret;
}
static int fat_read(struct file *f, void *buf, size_t insize)
--
2.47.3
next prev parent reply other threads:[~2026-08-25 10:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 10:10 [PATCH 1/4] fs: fat: propagate actual error code when opening/creating files Ahmad Fatoum
2026-08-25 10:10 ` [PATCH 2/4] fs: fat: drop stray printf debug output Ahmad Fatoum
2026-08-25 10:10 ` [PATCH 3/4] fs: fat: use fixed-width 32-bit FatFs types Ahmad Fatoum
2026-08-25 10:10 ` Ahmad Fatoum [this message]
2026-08-28 11:53 ` [PATCH 1/4] fs: fat: propagate actual error code when opening/creating files 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=20260825101106.2127202-4-a.fatoum@pengutronix.de \
--to=a.fatoum@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