mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/4] fs: fat: use fixed-width 32-bit FatFs types
Date: Tue, 25 Aug 2026 12:10:55 +0200	[thread overview]
Message-ID: <20260825101106.2127202-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260825101106.2127202-1-a.fatoum@pengutronix.de>

The comment already says LONG/ULONG/DWORD types should be 32-bit, but
barebox's long is always pointer-sized, so 64-bit on 64-bit platforms.

Use explicit 32-bit types for the FatFs fields that are written to disk
or used in sector calculations.

Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fat/fat.c     | 4 ++--
 fs/fat/ff.c      | 9 ++++++++-
 fs/fat/integer.h | 8 +++++---
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index b17157d1ea34..b50867524a74 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -52,7 +52,7 @@ DRESULT disk_read(FATFS *fat, BYTE *buf, DWORD sector, BYTE count)
 	size_t len = count * sector_size;
 	int ret;
 
-	debug("%s: sector: %ld count: %d\n", __func__, sector, count);
+	debug("%s: sector: %u count: %d\n", __func__, sector, count);
 
 	ret = cdev_read(priv->cdev, buf, len, (loff_t)sector * sector_size, 0);
 	if (ret != len)
@@ -68,7 +68,7 @@ DRESULT disk_write(FATFS *fat, const BYTE *buf, DWORD sector, BYTE count)
 	size_t len = count * sector_size;
 	int ret;
 
-	debug("%s: buf: %p sector: %ld count: %d\n",
+	debug("%s: buf: %p sector: %u count: %d\n",
 			__func__, buf, sector, count);
 
 	ret = cdev_write(priv->cdev, buf, len, (loff_t)sector * sector_size, 0);
diff --git a/fs/fat/ff.c b/fs/fat/ff.c
index e4d83a35605f..2f4e3b14f0a5 100644
--- a/fs/fat/ff.c
+++ b/fs/fat/ff.c
@@ -1539,14 +1539,21 @@ static enum filetype check_fs (	/* 0:The FAT BR, 1:Valid BR but not an FAT, 2:No
 	DWORD *bootsec
 )
 {
+	unsigned long bootsec_ul = 0;
 	DRESULT ret;
+	enum filetype type;
 
 	/* Load boot record */
 	ret = disk_read(fs, fs->win, sect, 1);
 	if (ret)
 		return filetype_unknown;
 
-	return is_fat_or_mbr(fs->win, bootsec);
+	type = is_fat_or_mbr(fs->win, &bootsec_ul);
+
+	if (bootsec)
+		*bootsec = bootsec_ul;
+
+	return type;
 }
 
 /*
diff --git a/fs/fat/integer.h b/fs/fat/integer.h
index fe94e374f356..d8b13402afe3 100644
--- a/fs/fat/integer.h
+++ b/fs/fat/integer.h
@@ -7,6 +7,8 @@
 #ifndef _INTEGER
 #define _INTEGER
 
+#include <linux/types.h>
+
 /* These types must be 16-bit, 32-bit or larger integer */
 typedef int		INT;
 typedef unsigned int	UINT;
@@ -23,8 +25,8 @@ typedef unsigned short	WORD;
 typedef unsigned short	WCHAR;
 
 /* These types must be 32-bit integer */
-typedef long		LONG;
-typedef unsigned long	ULONG;
-typedef unsigned long	DWORD;
+typedef s32		LONG;
+typedef u32		ULONG;
+typedef u32		DWORD;
 
 #endif
-- 
2.47.3




  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 ` Ahmad Fatoum [this message]
2026-08-25 10:10 ` [PATCH 4/4] fs: fat: flush metadata updates to the block device Ahmad Fatoum
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-3-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