[PATCH 1/6] fat: Create an internal header file
Heinrich Schuchardt
heinrich.schuchardt at canonical.com
Thu Nov 13 07:46:51 CET 2025
From: Simon Glass <simon.glass at canonical.com>
As a first step towards separating fat.c from fat_write.c, create a
header file for the definitions.
Co-developed-by: Claude <noreply at anthropic.com>
Signed-off-by: Simon Glass <simon.glass at canonical.com>
Tested-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
fs/fat/fat.c | 91 +---------------------------------
fs/fat/fat_internal.h | 112 ++++++++++++++++++++++++++++++++++++++++++
fs/fat/fat_write.c | 1 +
3 files changed, 114 insertions(+), 90 deletions(-)
create mode 100644 fs/fat/fat_internal.h
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 89f2acbba1e..5114e97e924 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -26,9 +26,7 @@
#include <linux/compiler.h>
#include <linux/ctype.h>
#include <linux/log2.h>
-
-/* maximum number of clusters for FAT12 */
-#define MAX_FAT12 0xFF4
+#include "fat_internal.h"
/*
* Convert a string to lowercase. Converts at most 'len' characters,
@@ -46,10 +44,6 @@ static void downcase(char *str, size_t len)
static struct blk_desc *cur_dev;
static struct disk_partition cur_part_info;
-#define DOS_BOOT_MAGIC_OFFSET 0x1fe
-#define DOS_FS_TYPE_OFFSET 0x36
-#define DOS_FS32_TYPE_OFFSET 0x52
-
static int disk_read(__u32 block, __u32 nr_blocks, void *buf)
{
ulong ret;
@@ -705,89 +699,6 @@ static int get_fs_info(fsdata *mydata)
return 0;
}
-/**
- * struct fat_itr - directory iterator, to simplify filesystem traversal
- *
- * Implements an iterator pattern to traverse directory tables,
- * transparently handling directory tables split across multiple
- * clusters, and the difference between FAT12/FAT16 root directory
- * (contiguous) and subdirectories + FAT32 root (chained).
- *
- * Rough usage
- *
- * .. code-block:: c
- *
- * for (fat_itr_root(&itr, fsdata); fat_itr_next(&itr); ) {
- * // to traverse down to a subdirectory pointed to by
- * // current iterator position:
- * fat_itr_child(&itr, &itr);
- * }
- *
- * For a more complete example, see fat_itr_resolve().
- */
-struct fat_itr {
- /**
- * @fsdata: filesystem parameters
- */
- fsdata *fsdata;
- /**
- * @start_clust: first cluster
- */
- unsigned int start_clust;
- /**
- * @clust: current cluster
- */
- unsigned int clust;
- /**
- * @next_clust: next cluster if remaining == 0
- */
- unsigned int next_clust;
- /**
- * @last_cluster: set if last cluster of directory reached
- */
- int last_cluster;
- /**
- * @is_root: is iterator at root directory
- */
- int is_root;
- /**
- * @remaining: remaining directory entries in current cluster
- */
- int remaining;
- /**
- * @dent: current directory entry
- */
- dir_entry *dent;
- /**
- * @dent_rem: remaining entries after long name start
- */
- int dent_rem;
- /**
- * @dent_clust: cluster of long name start
- */
- unsigned int dent_clust;
- /**
- * @dent_start: first directory entry for long name
- */
- dir_entry *dent_start;
- /**
- * @l_name: long name of current directory entry
- */
- char l_name[VFAT_MAXLEN_BYTES];
- /**
- * @s_name: short 8.3 name of current directory entry
- */
- char s_name[14];
- /**
- * @name: l_name if there is one, else s_name
- */
- char *name;
- /**
- * @block: buffer for current cluster
- */
- u8 block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
-};
-
static int fat_itr_isdir(fat_itr *itr);
/**
diff --git a/fs/fat/fat_internal.h b/fs/fat/fat_internal.h
new file mode 100644
index 00000000000..0174cd611e7
--- /dev/null
+++ b/fs/fat/fat_internal.h
@@ -0,0 +1,112 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * fat_internal.h
+ *
+ * Internal definitions and structures for FAT filesystem implementation
+ */
+
+#ifndef _FAT_INTERNAL_H_
+#define _FAT_INTERNAL_H_
+
+#include <fat.h>
+#include <linux/compiler.h>
+
+struct blk_desc;
+struct disk_partition;
+
+/* Maximum number of clusters for FAT12 */
+#define MAX_FAT12 0xFF4
+
+/* Boot sector offsets */
+#define DOS_BOOT_MAGIC_OFFSET 0x1fe
+#define DOS_FS_TYPE_OFFSET 0x36
+#define DOS_FS32_TYPE_OFFSET 0x52
+
+/**
+ * struct fat_itr - directory iterator, to simplify filesystem traversal
+ *
+ * Implements an iterator pattern to traverse directory tables,
+ * transparently handling directory tables split across multiple
+ * clusters, and the difference between FAT12/FAT16 root directory
+ * (contiguous) and subdirectories + FAT32 root (chained).
+ *
+ * Rough usage
+ *
+ * .. code-block:: c
+ *
+ * for (fat_itr_root(&itr, fsdata); fat_itr_next(&itr); ) {
+ * // to traverse down to a subdirectory pointed to by
+ * // current iterator position:
+ * fat_itr_child(&itr, &itr);
+ * }
+ *
+ * For a more complete example, see fat_itr_resolve().
+ */
+struct fat_itr {
+ /**
+ * @fsdata: filesystem parameters
+ */
+ fsdata *fsdata;
+ /**
+ * @start_clust: first cluster
+ */
+ unsigned int start_clust;
+ /**
+ * @clust: current cluster
+ */
+ unsigned int clust;
+ /**
+ * @next_clust: next cluster if remaining == 0
+ */
+ unsigned int next_clust;
+ /**
+ * @last_cluster: set if last cluster of directory reached
+ */
+ int last_cluster;
+ /**
+ * @is_root: is iterator at root directory
+ */
+ int is_root;
+ /**
+ * @remaining: remaining directory entries in current cluster
+ */
+ int remaining;
+ /**
+ * @dent: current directory entry
+ */
+ dir_entry *dent;
+ /**
+ * @dent_rem: remaining entries after long name start
+ */
+ int dent_rem;
+ /**
+ * @dent_clust: cluster of long name start
+ */
+ unsigned int dent_clust;
+ /**
+ * @dent_start: first directory entry for long name
+ */
+ dir_entry *dent_start;
+ /**
+ * @l_name: long name of current directory entry
+ */
+ char l_name[VFAT_MAXLEN_BYTES];
+ /**
+ * @s_name: short 8.3 name of current directory entry
+ */
+ char s_name[14];
+ /**
+ * @name: l_name if there is one, else s_name
+ */
+ char *name;
+ /**
+ * @block: buffer for current cluster
+ */
+ u8 block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
+};
+
+#define TYPE_FILE 0x1
+#define TYPE_DIR 0x2
+#define TYPE_ANY (TYPE_FILE | TYPE_DIR)
+
+#endif /* _FAT_INTERNAL_H_ */
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 0b924541187..45a2eef712b 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -20,6 +20,7 @@
#include <dm/uclass.h>
#include <linux/ctype.h>
#include <linux/math64.h>
+#include "fat_internal.h"
#include "fat.c"
static dir_entry *find_directory_entry(fat_itr *itr, char *filename);
--
2.51.0
More information about the U-Boot
mailing list