[PATCH 3/4] fs: fat: use fixed-width 32-bit FatFs types
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue Aug 25 03:10:55 PDT 2026
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 at 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
More information about the barebox
mailing list