[PATCH 0/6] fat: Some code improvements
From: Simon Glass <simon.glass@canonical.com> This is an attempt to improve the structure of the FAT code, since it doesn't fully follow the U-Boot conventions: - fat_write.c includes fat.c which is odd - use of __u32 and its ilk - use of typedef - old-style struct comments This series resolves these problems, making it easier to take on other improvements in future. Simon Glass (6): fat: Create an internal header file fat: Separate fat.c from fat_write.c fat: Update struct fat_itr to kernel-doc style fat: Remove typedefs in fat.h fat: Convert fat.h to kernel-doc style fat: Use standard types for fixed-size values fs/fat/Makefile | 2 +- fs/fat/fat.c | 316 +++++++++------------------------- fs/fat/fat_internal.h | 171 +++++++++++++++++++ fs/fat/fat_write.c | 246 ++++++++++++++------------- include/fat.h | 385 +++++++++++++++++++++++++++++++++--------- 5 files changed, 677 insertions(+), 443 deletions(-) create mode 100644 fs/fat/fat_internal.h -- 2.43.0 base-commit: d3df5a8ca108c08f2136cf04f4f47bd8bd268031 branch: fat
From: Simon Glass <simon.glass@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@anthropic.com> Signed-off-by: Simon Glass <simon.glass@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 0cbfdf49a32..b1a3d71e2fe 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -25,9 +25,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, @@ -45,10 +43,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; @@ -704,89 +698,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+ */ +/* + * 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.43.0
From: Simon Glass <simon.glass@canonical.com> Currently fat_write.c includes fat.c directly, which is unusual and makes the code harder to maintain. Use the internal header file to hold shared functions, to avoid this. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/fat/Makefile | 2 +- fs/fat/fat.c | 91 ++++++----------------------------------- fs/fat/fat_internal.h | 95 +++++++++++++++++++++++++++++++++++++++++-- fs/fat/fat_write.c | 4 +- 4 files changed, 107 insertions(+), 85 deletions(-) diff --git a/fs/fat/Makefile b/fs/fat/Makefile index 3e739044537..f3982fca4c6 100644 --- a/fs/fat/Makefile +++ b/fs/fat/Makefile @@ -2,4 +2,4 @@ # obj-$(CONFIG_$(PHASE_)FS_FAT) = fat.o -obj-$(CONFIG_$(PHASE_)FAT_WRITE) = fat_write.o +obj-$(CONFIG_$(PHASE_)FAT_WRITE) += fat_write.o diff --git a/fs/fat/fat.c b/fs/fat/fat.c index b1a3d71e2fe..f62a9ceaa64 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -32,7 +32,7 @@ * 'len' may be larger than the length of 'str' if 'str' is NULL * terminated. */ -static void downcase(char *str, size_t len) +void downcase(char *str, size_t len) { while (*str != '\0' && len--) { *str = tolower(*str); @@ -40,10 +40,10 @@ static void downcase(char *str, size_t len) } } -static struct blk_desc *cur_dev; -static struct disk_partition cur_part_info; +struct blk_desc *cur_dev; +struct disk_partition cur_part_info; -static int disk_read(__u32 block, __u32 nr_blocks, void *buf) +int disk_read(__u32 block, __u32 nr_blocks, void *buf) { ulong ret; @@ -144,8 +144,6 @@ static void get_name(dir_entry *dirent, char *s_name) *s_name = DELETED_FLAG; } -static int flush_dirty_fat_buffer(fsdata *mydata); - #if !CONFIG_IS_ENABLED(FAT_WRITE) /* Stub for read only operation */ int flush_dirty_fat_buffer(fsdata *mydata) @@ -159,7 +157,7 @@ int flush_dirty_fat_buffer(fsdata *mydata) * Get the entry at index 'entry' in a FAT (12/16/32) table. * On failure 0x00 is returned. */ -static __u32 get_fatent(fsdata *mydata, __u32 entry) +__u32 get_fatent(fsdata *mydata, __u32 entry) { __u32 bufnum; __u32 offset, off8; @@ -468,7 +466,7 @@ static int slot2str(dir_slot *slotptr, char *l_name, int *idx) } /* Calculate short name checksum */ -static __u8 mkcksum(struct nameext *nameext) +__u8 mkcksum(struct nameext *nameext) { int i; u8 *pos = (void *)nameext; @@ -698,17 +696,7 @@ static int get_fs_info(fsdata *mydata) return 0; } -static int fat_itr_isdir(fat_itr *itr); - -/** - * fat_itr_root() - initialize an iterator to start at the root - * directory - * - * @itr: iterator to initialize - * @fsdata: filesystem data for the partition - * Return: 0 on success, else -errno - */ -static int fat_itr_root(fat_itr *itr, fsdata *fsdata) +int fat_itr_root(fat_itr *itr, fsdata *fsdata) { if (get_fs_info(fsdata)) return -ENXIO; @@ -725,24 +713,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata) return 0; } -/** - * fat_itr_child() - initialize an iterator to descend into a sub- - * directory - * - * Initializes 'itr' to iterate the contents of the directory at - * the current cursor position of 'parent'. It is an error to - * call this if the current cursor of 'parent' is pointing at a - * regular file. - * - * Note that 'itr' and 'parent' can be the same pointer if you do - * not need to preserve 'parent' after this call, which is useful - * for traversing directory structure to resolve a file/directory. - * - * @itr: iterator to initialize - * @parent: the iterator pointing at a directory entry in the - * parent directory of the directory to iterate - */ -static void fat_itr_child(fat_itr *itr, fat_itr *parent) +void fat_itr_child(fat_itr *itr, fat_itr *parent) { fsdata *mydata = parent->fsdata; /* for silly macros */ unsigned clustnum = START(parent->dent); @@ -843,7 +814,7 @@ void *fat_next_cluster(fat_itr *itr, unsigned int *nbytes) return itr->block; } -static dir_entry *next_dent(fat_itr *itr) +dir_entry *next_dent(fat_itr *itr) { if (itr->remaining == 0) { unsigned nbytes; @@ -919,16 +890,7 @@ static dir_entry *extract_vfat_name(fat_itr *itr) return dent; } -/** - * fat_itr_next() - step to the next entry in a directory - * - * Must be called once on a new iterator before the cursor is valid. - * - * @itr: the iterator to iterate - * Return: boolean, 1 if success or 0 if no more entries in the - * current directory - */ -static int fat_itr_next(fat_itr *itr) +int fat_itr_next(fat_itr *itr) { dir_entry *dent; @@ -991,41 +953,12 @@ static int fat_itr_next(fat_itr *itr) return 1; } -/** - * fat_itr_isdir() - is current cursor position pointing to a directory - * - * @itr: the iterator - * Return: true if cursor is at a directory - */ -static int fat_itr_isdir(fat_itr *itr) +int fat_itr_isdir(fat_itr *itr) { return !!(itr->dent->attr & ATTR_DIR); } -/* - * Helpers: - */ - -#define TYPE_FILE 0x1 -#define TYPE_DIR 0x2 -#define TYPE_ANY (TYPE_FILE | TYPE_DIR) - -/** - * fat_itr_resolve() - traverse directory structure to resolve the - * requested path. - * - * Traverse directory structure to the requested path. If the specified - * path is to a directory, this will descend into the directory and - * leave it iterator at the start of the directory. If the path is to a - * file, it will leave the iterator in the parent directory with current - * cursor at file's entry in the directory. - * - * @itr: iterator initialized to root - * @path: the requested path - * @type: bitmask of allowable file types - * Return: 0 on success or -errno - */ -static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) { const char *next; diff --git a/fs/fat/fat_internal.h b/fs/fat/fat_internal.h index 0174cd611e7..10881a15569 100644 --- a/fs/fat/fat_internal.h +++ b/fs/fat/fat_internal.h @@ -22,6 +22,14 @@ struct disk_partition; #define DOS_FS_TYPE_OFFSET 0x36 #define DOS_FS32_TYPE_OFFSET 0x52 +#define TYPE_FILE 0x1 +#define TYPE_DIR 0x2 +#define TYPE_ANY (TYPE_FILE | TYPE_DIR) + +/* Global variables shared between fat.c and fat_write.c */ +extern struct blk_desc *cur_dev; +extern struct disk_partition cur_part_info; + /** * struct fat_itr - directory iterator, to simplify filesystem traversal * @@ -105,8 +113,89 @@ struct fat_itr { u8 block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); }; -#define TYPE_FILE 0x1 -#define TYPE_DIR 0x2 -#define TYPE_ANY (TYPE_FILE | TYPE_DIR) +/** + * downcase() - convert a string to lowercase + * @str: string to convert + * @len: maximum number of characters to convert + */ +void downcase(char *str, size_t len); + +/** + * next_dent() - get next directory entry + * @itr: directory iterator + * Return: pointer to next directory entry, or NULL if at end + */ +dir_entry *next_dent(fat_itr *itr); + +/** + * disk_read() - read sectors from the current FAT device + * @block: logical block number + * @nr_blocks: number of blocks to read + * @buf: buffer to read data into + * Return: number of blocks read, -1 on error + */ +int disk_read(__u32 block, __u32 nr_blocks, void *buf); + +/** + * flush_dirty_fat_buffer() - write fat buffer to disk if dirty + * @mydata: filesystem data + * Return: 0 on success, -1 on error + */ +int flush_dirty_fat_buffer(fsdata *mydata); + +/* Internal function declarations */ + +/** + * get_fatent() - get the entry at index 'entry' in a FAT (12/16/32) table + * @mydata: filesystem data + * @entry: FAT entry index + * Return: FAT entry value, 0x00 on failure + */ +__u32 get_fatent(fsdata *mydata, __u32 entry); + +/** + * mkcksum() - calculate short name checksum + * @nameext: name and extension structure + * Return: checksum value + */ +__u8 mkcksum(struct nameext *nameext); + +/** + * fat_itr_root() - initialize an iterator to start at the root directory + * @itr: iterator to initialize + * @fsdata: filesystem data for the partition + * Return: 0 on success, else -errno + */ +int fat_itr_root(fat_itr *itr, fsdata *fsdata); + +/** + * fat_itr_child() - initialize an iterator to descend into a sub-directory + * @itr: iterator to initialize + * @parent: the iterator pointing at a directory entry in the parent directory + */ +void fat_itr_child(fat_itr *itr, fat_itr *parent); + +/** + * fat_itr_next() - step to the next entry in a directory + * @itr: the iterator to iterate + * Return: 1 if success or 0 if no more entries in the current directory + */ +int fat_itr_next(fat_itr *itr); + +/** + * fat_itr_isdir() - is current cursor position pointing to a directory + * @itr: the iterator + * Return: true if cursor is at a directory + */ +int fat_itr_isdir(fat_itr *itr); + +/** + * fat_itr_resolve() - traverse directory structure to resolve the requested path + * @itr: iterator initialized to root + * @path: the requested path + * @type: bitmask of allowable file types + * Return: 0 on success or -errno + */ +int fat_itr_resolve(fat_itr *itr, const char *path, uint type); #endif /* _FAT_INTERNAL_H_ */ diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 45a2eef712b..c202f013f43 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -13,6 +13,7 @@ #include <fat.h> #include <log.h> #include <malloc.h> +#include <memalign.h> #include <part.h> #include <rand.h> #include <asm/byteorder.h> @@ -21,7 +22,6 @@ #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); static int new_dir_table(fat_itr *itr); @@ -216,7 +216,7 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf) /* * Write fat buffer into block device */ -static int flush_dirty_fat_buffer(fsdata *mydata) +int flush_dirty_fat_buffer(fsdata *mydata) { int getsize = FATBUFBLOCKS; __u32 fatlength = mydata->fatlength; -- 2.43.0
On 11/13/25 03:56, Simon Glass wrote:
From: Simon Glass <simon.glass@canonical.com>
Currently fat_write.c includes fat.c directly, which is unusual and makes the code harder to maintain. Use the internal header file to hold shared functions, to avoid this.
Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com>
When applying this patch to upstream I get: ../fs/fat/fat_write.c:1171:21: error: implicit declaration of function ‘dm_rtc_get’ [-Wimplicit-function-declaration] 1171 | if (dm_rtc_get(dev, &tm)) Best regards Heinrich
---
fs/fat/Makefile | 2 +- fs/fat/fat.c | 91 ++++++----------------------------------- fs/fat/fat_internal.h | 95 +++++++++++++++++++++++++++++++++++++++++-- fs/fat/fat_write.c | 4 +- 4 files changed, 107 insertions(+), 85 deletions(-)
diff --git a/fs/fat/Makefile b/fs/fat/Makefile index 3e739044537..f3982fca4c6 100644 --- a/fs/fat/Makefile +++ b/fs/fat/Makefile @@ -2,4 +2,4 @@ #
obj-$(CONFIG_$(PHASE_)FS_FAT) = fat.o -obj-$(CONFIG_$(PHASE_)FAT_WRITE) = fat_write.o +obj-$(CONFIG_$(PHASE_)FAT_WRITE) += fat_write.o diff --git a/fs/fat/fat.c b/fs/fat/fat.c index b1a3d71e2fe..f62a9ceaa64 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -32,7 +32,7 @@ * 'len' may be larger than the length of 'str' if 'str' is NULL * terminated. */ -static void downcase(char *str, size_t len) +void downcase(char *str, size_t len) { while (*str != '\0' && len--) { *str = tolower(*str); @@ -40,10 +40,10 @@ static void downcase(char *str, size_t len) } }
-static struct blk_desc *cur_dev; -static struct disk_partition cur_part_info; +struct blk_desc *cur_dev; +struct disk_partition cur_part_info;
-static int disk_read(__u32 block, __u32 nr_blocks, void *buf) +int disk_read(__u32 block, __u32 nr_blocks, void *buf) { ulong ret;
@@ -144,8 +144,6 @@ static void get_name(dir_entry *dirent, char *s_name) *s_name = DELETED_FLAG; }
-static int flush_dirty_fat_buffer(fsdata *mydata); - #if !CONFIG_IS_ENABLED(FAT_WRITE) /* Stub for read only operation */ int flush_dirty_fat_buffer(fsdata *mydata) @@ -159,7 +157,7 @@ int flush_dirty_fat_buffer(fsdata *mydata) * Get the entry at index 'entry' in a FAT (12/16/32) table. * On failure 0x00 is returned. */ -static __u32 get_fatent(fsdata *mydata, __u32 entry) +__u32 get_fatent(fsdata *mydata, __u32 entry) { __u32 bufnum; __u32 offset, off8; @@ -468,7 +466,7 @@ static int slot2str(dir_slot *slotptr, char *l_name, int *idx) }
/* Calculate short name checksum */ -static __u8 mkcksum(struct nameext *nameext) +__u8 mkcksum(struct nameext *nameext) { int i; u8 *pos = (void *)nameext; @@ -698,17 +696,7 @@ static int get_fs_info(fsdata *mydata) return 0; }
-static int fat_itr_isdir(fat_itr *itr); - -/** - * fat_itr_root() - initialize an iterator to start at the root - * directory - * - * @itr: iterator to initialize - * @fsdata: filesystem data for the partition - * Return: 0 on success, else -errno - */ -static int fat_itr_root(fat_itr *itr, fsdata *fsdata) +int fat_itr_root(fat_itr *itr, fsdata *fsdata) { if (get_fs_info(fsdata)) return -ENXIO; @@ -725,24 +713,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata) return 0; }
-/** - * fat_itr_child() - initialize an iterator to descend into a sub- - * directory - * - * Initializes 'itr' to iterate the contents of the directory at - * the current cursor position of 'parent'. It is an error to - * call this if the current cursor of 'parent' is pointing at a - * regular file. - * - * Note that 'itr' and 'parent' can be the same pointer if you do - * not need to preserve 'parent' after this call, which is useful - * for traversing directory structure to resolve a file/directory. - * - * @itr: iterator to initialize - * @parent: the iterator pointing at a directory entry in the - * parent directory of the directory to iterate - */ -static void fat_itr_child(fat_itr *itr, fat_itr *parent) +void fat_itr_child(fat_itr *itr, fat_itr *parent) { fsdata *mydata = parent->fsdata; /* for silly macros */ unsigned clustnum = START(parent->dent); @@ -843,7 +814,7 @@ void *fat_next_cluster(fat_itr *itr, unsigned int *nbytes) return itr->block; }
-static dir_entry *next_dent(fat_itr *itr) +dir_entry *next_dent(fat_itr *itr) { if (itr->remaining == 0) { unsigned nbytes; @@ -919,16 +890,7 @@ static dir_entry *extract_vfat_name(fat_itr *itr) return dent; }
-/** - * fat_itr_next() - step to the next entry in a directory - * - * Must be called once on a new iterator before the cursor is valid. - * - * @itr: the iterator to iterate - * Return: boolean, 1 if success or 0 if no more entries in the - * current directory - */ -static int fat_itr_next(fat_itr *itr) +int fat_itr_next(fat_itr *itr) { dir_entry *dent;
@@ -991,41 +953,12 @@ static int fat_itr_next(fat_itr *itr) return 1; }
-/** - * fat_itr_isdir() - is current cursor position pointing to a directory - * - * @itr: the iterator - * Return: true if cursor is at a directory - */ -static int fat_itr_isdir(fat_itr *itr) +int fat_itr_isdir(fat_itr *itr) { return !!(itr->dent->attr & ATTR_DIR); }
-/* - * Helpers: - */ - -#define TYPE_FILE 0x1 -#define TYPE_DIR 0x2 -#define TYPE_ANY (TYPE_FILE | TYPE_DIR) - -/** - * fat_itr_resolve() - traverse directory structure to resolve the - * requested path. - * - * Traverse directory structure to the requested path. If the specified - * path is to a directory, this will descend into the directory and - * leave it iterator at the start of the directory. If the path is to a - * file, it will leave the iterator in the parent directory with current - * cursor at file's entry in the directory. - * - * @itr: iterator initialized to root - * @path: the requested path - * @type: bitmask of allowable file types - * Return: 0 on success or -errno - */ -static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) { const char *next;
diff --git a/fs/fat/fat_internal.h b/fs/fat/fat_internal.h index 0174cd611e7..10881a15569 100644 --- a/fs/fat/fat_internal.h +++ b/fs/fat/fat_internal.h @@ -22,6 +22,14 @@ struct disk_partition; #define DOS_FS_TYPE_OFFSET 0x36 #define DOS_FS32_TYPE_OFFSET 0x52
+#define TYPE_FILE 0x1 +#define TYPE_DIR 0x2 +#define TYPE_ANY (TYPE_FILE | TYPE_DIR) + +/* Global variables shared between fat.c and fat_write.c */ +extern struct blk_desc *cur_dev; +extern struct disk_partition cur_part_info; + /** * struct fat_itr - directory iterator, to simplify filesystem traversal * @@ -105,8 +113,89 @@ struct fat_itr { u8 block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); };
-#define TYPE_FILE 0x1 -#define TYPE_DIR 0x2 -#define TYPE_ANY (TYPE_FILE | TYPE_DIR) +/** + * downcase() - convert a string to lowercase + * @str: string to convert + * @len: maximum number of characters to convert + */ +void downcase(char *str, size_t len); + +/** + * next_dent() - get next directory entry + * @itr: directory iterator + * Return: pointer to next directory entry, or NULL if at end + */ +dir_entry *next_dent(fat_itr *itr); + +/** + * disk_read() - read sectors from the current FAT device + * @block: logical block number + * @nr_blocks: number of blocks to read + * @buf: buffer to read data into + * Return: number of blocks read, -1 on error + */ +int disk_read(__u32 block, __u32 nr_blocks, void *buf); + +/** + * flush_dirty_fat_buffer() - write fat buffer to disk if dirty + * @mydata: filesystem data + * Return: 0 on success, -1 on error + */ +int flush_dirty_fat_buffer(fsdata *mydata); + +/* Internal function declarations */ + +/** + * get_fatent() - get the entry at index 'entry' in a FAT (12/16/32) table + * @mydata: filesystem data + * @entry: FAT entry index + * Return: FAT entry value, 0x00 on failure + */ +__u32 get_fatent(fsdata *mydata, __u32 entry); + +/** + * mkcksum() - calculate short name checksum + * @nameext: name and extension structure + * Return: checksum value + */ +__u8 mkcksum(struct nameext *nameext); + +/** + * fat_itr_root() - initialize an iterator to start at the root directory + * @itr: iterator to initialize + * @fsdata: filesystem data for the partition + * Return: 0 on success, else -errno + */ +int fat_itr_root(fat_itr *itr, fsdata *fsdata); + +/** + * fat_itr_child() - initialize an iterator to descend into a sub-directory + * @itr: iterator to initialize + * @parent: the iterator pointing at a directory entry in the parent directory + */ +void fat_itr_child(fat_itr *itr, fat_itr *parent); + +/** + * fat_itr_next() - step to the next entry in a directory + * @itr: the iterator to iterate + * Return: 1 if success or 0 if no more entries in the current directory + */ +int fat_itr_next(fat_itr *itr); + +/** + * fat_itr_isdir() - is current cursor position pointing to a directory + * @itr: the iterator + * Return: true if cursor is at a directory + */ +int fat_itr_isdir(fat_itr *itr); + +/** + * fat_itr_resolve() - traverse directory structure to resolve the requested path + * @itr: iterator initialized to root + * @path: the requested path + * @type: bitmask of allowable file types + * Return: 0 on success or -errno + */ +int fat_itr_resolve(fat_itr *itr, const char *path, uint type);
#endif /* _FAT_INTERNAL_H_ */ diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 45a2eef712b..c202f013f43 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -13,6 +13,7 @@ #include <fat.h> #include <log.h> #include <malloc.h> +#include <memalign.h> #include <part.h> #include <rand.h> #include <asm/byteorder.h> @@ -21,7 +22,6 @@ #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); static int new_dir_table(fat_itr *itr); @@ -216,7 +216,7 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf) /* * Write fat buffer into block device */ -static int flush_dirty_fat_buffer(fsdata *mydata) +int flush_dirty_fat_buffer(fsdata *mydata) { int getsize = FATBUFBLOCKS; __u32 fatlength = mydata->fatlength;
From: Simon Glass <simon.glass@canonical.com> Convert the struct fat_itr documentation from the older style with separate @field comments to the standard kernel-doc style where field descriptions are listed in the header comment block. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/fat/fat_internal.h | 60 +++++++++++-------------------------------- 1 file changed, 15 insertions(+), 45 deletions(-) diff --git a/fs/fat/fat_internal.h b/fs/fat/fat_internal.h index 10881a15569..bc52d534b46 100644 --- a/fs/fat/fat_internal.h +++ b/fs/fat/fat_internal.h @@ -32,6 +32,21 @@ extern struct disk_partition cur_part_info; /** * struct fat_itr - directory iterator, to simplify filesystem traversal + * @fsdata: filesystem parameters + * @start_clust: first cluster + * @clust: current cluster + * @next_clust: next cluster if remaining == 0 + * @last_cluster: set if last cluster of directory reached + * @is_root: is iterator at root directory + * @remaining: remaining directory entries in current cluster + * @dent: current directory entry + * @dent_rem: remaining entries after long name start + * @dent_clust: cluster of long name start + * @dent_start: first directory entry for long name + * @l_name: long name of current directory entry + * @s_name: short 8.3 name of current directory entry + * @name: l_name if there is one, else s_name + * @block: buffer for current cluster * * Implements an iterator pattern to traverse directory tables, * transparently handling directory tables split across multiple @@ -51,65 +66,20 @@ extern struct disk_partition cur_part_info; * 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); }; -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Convert all typedefs in fat.h to normal struct declarations. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/fat/fat.c | 108 ++++++++++++++-------------- fs/fat/fat_internal.h | 22 +++--- fs/fat/fat_write.c | 159 +++++++++++++++++++++--------------------- include/fat.h | 28 ++++---- 4 files changed, 158 insertions(+), 159 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index f62a9ceaa64..1ebf9b4c040 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -117,7 +117,7 @@ int fat_register_device(struct blk_desc *dev_desc, int part_no) /* * Extract zero terminated short name from a directory entry. */ -static void get_name(dir_entry *dirent, char *s_name) +static void get_name(struct dir_entry *dirent, char *s_name) { char *ptr; @@ -146,7 +146,7 @@ static void get_name(dir_entry *dirent, char *s_name) #if !CONFIG_IS_ENABLED(FAT_WRITE) /* Stub for read only operation */ -int flush_dirty_fat_buffer(fsdata *mydata) +int flush_dirty_fat_buffer(struct fsdata *mydata) { (void)(mydata); return 0; @@ -157,7 +157,7 @@ int flush_dirty_fat_buffer(fsdata *mydata) * Get the entry at index 'entry' in a FAT (12/16/32) table. * On failure 0x00 is returned. */ -__u32 get_fatent(fsdata *mydata, __u32 entry) +__u32 get_fatent(struct fsdata *mydata, __u32 entry) { __u32 bufnum; __u32 offset, off8; @@ -242,7 +242,7 @@ __u32 get_fatent(fsdata *mydata, __u32 entry) * Return 0 on success, -1 otherwise. */ static int -get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size) +get_cluster(struct fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size) { __u32 startsect; int ret; @@ -315,7 +315,7 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size) * @gotsize: number of bytes actually read * Return: -1 on error, otherwise 0 */ -static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, +static int get_contents(struct fsdata *mydata, struct dir_entry *dentptr, loff_t pos, __u8 *buffer, loff_t maxsize, loff_t *gotsize) { loff_t filesize = FAT2CPU32(dentptr->size); @@ -439,7 +439,7 @@ getit: * starting at l_name[*idx]. * Return 1 if terminator (zero byte) is found, 0 otherwise. */ -static int slot2str(dir_slot *slotptr, char *l_name, int *idx) +static int slot2str(struct dir_slot *slotptr, char *l_name, int *idx) { int j; @@ -484,12 +484,12 @@ __u8 mkcksum(struct nameext *nameext) * * Based on fat_fill_super() from the Linux kernel's fs/fat/inode.c */ -static int determine_legacy_fat_bits(const boot_sector *bs) +static int determine_legacy_fat_bits(const struct boot_sector *bs) { u16 fat_start = bs->reserved; u32 dir_start = fat_start + bs->fats * bs->fat_length; u32 rootdir_sectors = get_unaligned_le16(bs->dir_entries) * - sizeof(dir_entry) / + sizeof(struct dir_entry) / get_unaligned_le16(bs->sector_size); u32 data_start = dir_start + rootdir_sectors; u16 sectors = get_unaligned_le16(bs->sectors); @@ -515,10 +515,10 @@ static int fat_valid_media(u8 media) * * Based on fat_read_bpb() from the Linux kernel's fs/fat/inode.c */ -static int is_bootsector_valid(const boot_sector *bs) +static int is_bootsector_valid(const struct boot_sector *bs) { u16 sector_size = get_unaligned_le16(bs->sector_size); - u16 dir_per_block = sector_size / sizeof(dir_entry); + u16 dir_per_block = sector_size / sizeof(struct dir_entry); if (!bs->reserved) return 0; @@ -550,10 +550,10 @@ static int is_bootsector_valid(const boot_sector *bs) * Read boot sector and volume info from a FAT filesystem */ static int -read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize) +read_bootsectandvi(struct boot_sector *bs, struct volume_info *volinfo, int *fatsize) { __u8 *block; - volume_info *vistart; + struct volume_info *vistart; int ret = 0; if (cur_dev == NULL) { @@ -573,7 +573,7 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize) goto out_free; } - memcpy(bs, block, sizeof(boot_sector)); + memcpy(bs, block, sizeof(struct boot_sector)); bs->reserved = FAT2CPU16(bs->reserved); bs->fat_length = FAT2CPU16(bs->fat_length); bs->secs_track = FAT2CPU16(bs->secs_track); @@ -594,23 +594,23 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize) bs->root_cluster = FAT2CPU32(bs->root_cluster); bs->info_sector = FAT2CPU16(bs->info_sector); bs->backup_boot = FAT2CPU16(bs->backup_boot); - vistart = (volume_info *)(block + sizeof(boot_sector)); + vistart = (struct volume_info *)(block + sizeof(struct boot_sector)); *fatsize = 32; } else { - vistart = (volume_info *)&(bs->fat32_length); + vistart = (struct volume_info *)&(bs->fat32_length); *fatsize = determine_legacy_fat_bits(bs); } - memcpy(volinfo, vistart, sizeof(volume_info)); + memcpy(volinfo, vistart, sizeof(struct volume_info)); out_free: free(block); return ret; } -static int get_fs_info(fsdata *mydata) +static int get_fs_info(struct fsdata *mydata) { - boot_sector bs; - volume_info volinfo; + struct boot_sector bs; + struct volume_info volinfo; int ret; ret = read_bootsectandvi(&bs, &volinfo, &mydata->fatsize); @@ -661,7 +661,7 @@ static int get_fs_info(fsdata *mydata) mydata->root_cluster = bs.root_cluster; } else { mydata->rootdir_size = (get_unaligned_le16(bs.dir_entries) * - sizeof(dir_entry)) / + sizeof(struct dir_entry)) / mydata->sect_size; mydata->data_begin = mydata->rootdir_sect + mydata->rootdir_size - @@ -696,7 +696,7 @@ static int get_fs_info(fsdata *mydata) return 0; } -int fat_itr_root(fat_itr *itr, fsdata *fsdata) +int fat_itr_root(struct fat_itr *itr, struct fsdata *fsdata) { if (get_fs_info(fsdata)) return -ENXIO; @@ -713,9 +713,9 @@ int fat_itr_root(fat_itr *itr, fsdata *fsdata) return 0; } -void fat_itr_child(fat_itr *itr, fat_itr *parent) +void fat_itr_child(struct fat_itr *itr, struct fat_itr *parent) { - fsdata *mydata = parent->fsdata; /* for silly macros */ + struct fsdata *mydata = parent->fsdata; /* for silly macros */ unsigned clustnum = START(parent->dent); assert(fat_itr_isdir(parent)); @@ -747,7 +747,7 @@ void fat_itr_child(fat_itr *itr, fat_itr *parent) * @nbytes: number of bytes read, 0 on error * Return: first directory entry, NULL on error */ -void *fat_next_cluster(fat_itr *itr, unsigned int *nbytes) +void *fat_next_cluster(struct fat_itr *itr, unsigned int *nbytes) { int ret; u32 sect; @@ -814,7 +814,7 @@ void *fat_next_cluster(fat_itr *itr, unsigned int *nbytes) return itr->block; } -dir_entry *next_dent(fat_itr *itr) +struct dir_entry *next_dent(struct fat_itr *itr) { if (itr->remaining == 0) { unsigned nbytes; @@ -827,7 +827,7 @@ dir_entry *next_dent(fat_itr *itr) return NULL; } - itr->remaining = nbytes / sizeof(dir_entry) - 1; + itr->remaining = nbytes / sizeof(struct dir_entry) - 1; itr->dent = dent; } else { itr->remaining--; @@ -841,18 +841,18 @@ dir_entry *next_dent(fat_itr *itr) return itr->dent; } -static dir_entry *extract_vfat_name(fat_itr *itr) +static struct dir_entry *extract_vfat_name(struct fat_itr *itr) { struct dir_entry *dent = itr->dent; int seqn = itr->dent->nameext.name[0] & ~LAST_LONG_ENTRY_MASK; - u8 chksum, alias_checksum = ((dir_slot *)dent)->alias_checksum; + u8 chksum, alias_checksum = ((struct dir_slot *)dent)->alias_checksum; int n = 0; while (seqn--) { char buf[13]; int idx = 0; - slot2str((dir_slot *)dent, buf, &idx); + slot2str((struct dir_slot *)dent, buf, &idx); if (n + idx >= sizeof(itr->l_name)) return NULL; @@ -890,9 +890,9 @@ static dir_entry *extract_vfat_name(fat_itr *itr) return dent; } -int fat_itr_next(fat_itr *itr) +int fat_itr_next(struct fat_itr *itr) { - dir_entry *dent; + struct dir_entry *dent; itr->name = NULL; @@ -953,12 +953,12 @@ int fat_itr_next(fat_itr *itr) return 1; } -int fat_itr_isdir(fat_itr *itr) +int fat_itr_isdir(struct fat_itr *itr) { return !!(itr->dent->attr & ATTR_DIR); } -int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) +int fat_itr_resolve(struct fat_itr *itr, const char *path, uint type) { const char *next; @@ -1038,8 +1038,8 @@ int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) int file_fat_detectfs(void) { - boot_sector bs; - volume_info volinfo; + struct boot_sector bs; + struct volume_info volinfo; int fatsize; char vol_label[12]; @@ -1069,11 +1069,11 @@ int file_fat_detectfs(void) int fat_exists(const char *filename) { - fsdata fsdata; - fat_itr *itr; + struct fsdata fsdata; + struct fat_itr *itr; int ret; - itr = malloc_cache_aligned(sizeof(fat_itr)); + itr = malloc_cache_aligned(sizeof(struct fat_itr)); if (!itr) return 0; ret = fat_itr_root(itr, &fsdata); @@ -1111,11 +1111,11 @@ static void __maybe_unused fat2rtc(u16 date, u16 time, struct rtc_time *tm) int fat_size(const char *filename, loff_t *size) { - fsdata fsdata; - fat_itr *itr; + struct fsdata fsdata; + struct fat_itr *itr; int ret; - itr = malloc_cache_aligned(sizeof(fat_itr)); + itr = malloc_cache_aligned(sizeof(struct fat_itr)); if (!itr) return -ENOMEM; ret = fat_itr_root(itr, &fsdata); @@ -1149,11 +1149,11 @@ out_free_itr: int fat_read_file(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actread) { - fsdata fsdata; - fat_itr *itr; + struct fsdata fsdata; + struct fat_itr *itr; int ret; - itr = malloc_cache_aligned(sizeof(fat_itr)); + itr = malloc_cache_aligned(sizeof(struct fat_itr)); if (!itr) return -ENOMEM; ret = fat_itr_root(itr, &fsdata); @@ -1167,7 +1167,7 @@ int fat_read_file(const char *filename, void *buf, loff_t offset, loff_t len, debug("reading %s at pos %llu\n", filename, offset); /* For saving default max clustersize memory allocated to malloc pool */ - dir_entry *dentptr = itr->dent; + struct dir_entry *dentptr = itr->dent; ret = get_contents(&fsdata, dentptr, offset, buf, len, actread); @@ -1190,16 +1190,16 @@ int file_fat_read(const char *filename, void *buffer, int maxsize) return actread; } -typedef struct { +struct fat_dir { struct fs_dir_stream parent; struct fs_dirent dirent; - fsdata fsdata; - fat_itr itr; -} fat_dir; + struct fsdata fsdata; + struct fat_itr itr; +}; int fat_opendir(const char *filename, struct fs_dir_stream **dirsp) { - fat_dir *dir; + struct fat_dir *dir; int ret; dir = malloc_cache_aligned(sizeof(*dir)); @@ -1227,7 +1227,7 @@ fail_free_dir: int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp) { - fat_dir *dir = (fat_dir *)dirs; + struct fat_dir *dir = (struct fat_dir *)dirs; struct fs_dirent *dent = &dir->dirent; if (!fat_itr_next(&dir->itr)) @@ -1258,7 +1258,7 @@ int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp) void fat_closedir(struct fs_dir_stream *dirs) { - fat_dir *dir = (fat_dir *)dirs; + struct fat_dir *dir = (struct fat_dir *)dirs; free(dir->fsdata.fatbuf); free(dir); } @@ -1269,8 +1269,8 @@ void fat_close(void) int fat_uuid(char *uuid_str) { - boot_sector bs; - volume_info volinfo; + struct boot_sector bs; + struct volume_info volinfo; int fatsize; int ret; u8 *id; diff --git a/fs/fat/fat_internal.h b/fs/fat/fat_internal.h index bc52d534b46..cefe28c8d00 100644 --- a/fs/fat/fat_internal.h +++ b/fs/fat/fat_internal.h @@ -66,17 +66,17 @@ extern struct disk_partition cur_part_info; * For a more complete example, see fat_itr_resolve(). */ struct fat_itr { - fsdata *fsdata; + struct fsdata *fsdata; unsigned int start_clust; unsigned int clust; unsigned int next_clust; int last_cluster; int is_root; int remaining; - dir_entry *dent; + struct dir_entry *dent; int dent_rem; unsigned int dent_clust; - dir_entry *dent_start; + struct dir_entry *dent_start; char l_name[VFAT_MAXLEN_BYTES]; char s_name[14]; char *name; @@ -95,7 +95,7 @@ void downcase(char *str, size_t len); * @itr: directory iterator * Return: pointer to next directory entry, or NULL if at end */ -dir_entry *next_dent(fat_itr *itr); +struct dir_entry *next_dent(struct fat_itr *itr); /** * disk_read() - read sectors from the current FAT device @@ -111,7 +111,7 @@ int disk_read(__u32 block, __u32 nr_blocks, void *buf); * @mydata: filesystem data * Return: 0 on success, -1 on error */ -int flush_dirty_fat_buffer(fsdata *mydata); +int flush_dirty_fat_buffer(struct fsdata *mydata); /* Internal function declarations */ @@ -121,7 +121,7 @@ int flush_dirty_fat_buffer(fsdata *mydata); * @entry: FAT entry index * Return: FAT entry value, 0x00 on failure */ -__u32 get_fatent(fsdata *mydata, __u32 entry); +__u32 get_fatent(struct fsdata *mydata, __u32 entry); /** * mkcksum() - calculate short name checksum @@ -136,28 +136,28 @@ __u8 mkcksum(struct nameext *nameext); * @fsdata: filesystem data for the partition * Return: 0 on success, else -errno */ -int fat_itr_root(fat_itr *itr, fsdata *fsdata); +int fat_itr_root(struct fat_itr *itr, struct fsdata *fsdata); /** * fat_itr_child() - initialize an iterator to descend into a sub-directory * @itr: iterator to initialize * @parent: the iterator pointing at a directory entry in the parent directory */ -void fat_itr_child(fat_itr *itr, fat_itr *parent); +void fat_itr_child(struct fat_itr *itr, struct fat_itr *parent); /** * fat_itr_next() - step to the next entry in a directory * @itr: the iterator to iterate * Return: 1 if success or 0 if no more entries in the current directory */ -int fat_itr_next(fat_itr *itr); +int fat_itr_next(struct fat_itr *itr); /** * fat_itr_isdir() - is current cursor position pointing to a directory * @itr: the iterator * Return: true if cursor is at a directory */ -int fat_itr_isdir(fat_itr *itr); +int fat_itr_isdir(struct fat_itr *itr); /** * fat_itr_resolve() - traverse directory structure to resolve the requested path @@ -166,6 +166,6 @@ int fat_itr_isdir(fat_itr *itr); * @type: bitmask of allowable file types * Return: 0 on success or -errno */ -int fat_itr_resolve(fat_itr *itr, const char *path, uint type); +int fat_itr_resolve(struct fat_itr *itr, const char *path, uint type); #endif /* _FAT_INTERNAL_H_ */ diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index c202f013f43..be9265be11b 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -23,8 +23,8 @@ #include <linux/math64.h> #include "fat_internal.h" -static dir_entry *find_directory_entry(fat_itr *itr, char *filename); -static int new_dir_table(fat_itr *itr); +static struct dir_entry *find_directory_entry(struct fat_itr *itr, char *filename); +static int new_dir_table(struct fat_itr *itr); /* Characters that may only be used in long file names */ static const char LONG_ONLY_CHARS[] = "+,;=[]"; @@ -76,7 +76,7 @@ static int str2fat(char *dest, char *src, int length) * @cluster cluster * Return: 0 for success, -EIO on error */ -static int fat_move_to_cluster(fat_itr *itr, unsigned int cluster) +static int fat_move_to_cluster(struct fat_itr *itr, unsigned int cluster) { unsigned int nbytes; @@ -85,8 +85,8 @@ static int fat_move_to_cluster(fat_itr *itr, unsigned int cluster) itr->last_cluster = 0; if (!fat_next_cluster(itr, &nbytes)) return -EIO; - itr->dent = (dir_entry *)itr->block; - itr->remaining = nbytes / sizeof(dir_entry) - 1; + itr->dent = (struct dir_entry *)itr->block; + itr->remaining = nbytes / sizeof(struct dir_entry) - 1; return 0; } @@ -103,7 +103,7 @@ static int fat_move_to_cluster(fat_itr *itr, unsigned int cluster) * @shortname: buffer of 11 bytes to receive chosen short name and extension * Return: number of directory entries needed, negative on error */ -static int set_name(fat_itr *itr, const char *filename, char *shortname) +static int set_name(struct fat_itr *itr, const char *filename, char *shortname) { char *period; char *pos; @@ -216,7 +216,7 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf) /* * Write fat buffer into block device */ -int flush_dirty_fat_buffer(fsdata *mydata) +int flush_dirty_fat_buffer(struct fsdata *mydata) { int getsize = FATBUFBLOCKS; __u32 fatlength = mydata->fatlength; @@ -261,10 +261,10 @@ int flush_dirty_fat_buffer(fsdata *mydata) * @count: number of directory entries to find * Return: 0 on success or negative error number */ -static int fat_find_empty_dentries(fat_itr *itr, int count) +static int fat_find_empty_dentries(struct fat_itr *itr, int count) { unsigned int cluster; - dir_entry *dent; + struct dir_entry *dent; int remaining; unsigned int n = 0; int ret; @@ -317,7 +317,7 @@ out: /* * Set the file name information from 'name' into 'slotptr', */ -static int str2slot(dir_slot *slotptr, const char *name, int *idx) +static int str2slot(struct dir_slot *slotptr, const char *name, int *idx) { int j, end_idx = 0; @@ -383,7 +383,7 @@ name11_12: return 1; } -static int flush_dir(fat_itr *itr); +static int flush_dir(struct fat_itr *itr); /** * fill_dir_slot() - fill directory entries for long name @@ -394,10 +394,10 @@ static int flush_dir(fat_itr *itr); * Return: 0 for success, -errno otherwise */ static int -fill_dir_slot(fat_itr *itr, const char *l_name, const char *shortname) +fill_dir_slot(struct fat_itr *itr, const char *l_name, const char *shortname) { - __u8 temp_dir_slot_buffer[MAX_LFN_SLOT * sizeof(dir_slot)]; - dir_slot *slotptr = (dir_slot *)temp_dir_slot_buffer; + __u8 temp_dir_slot_buffer[MAX_LFN_SLOT * sizeof(struct dir_slot)]; + struct dir_slot *slotptr = (struct dir_slot *)temp_dir_slot_buffer; __u8 counter = 0, checksum; int idx = 0, ret; @@ -405,7 +405,7 @@ fill_dir_slot(fat_itr *itr, const char *l_name, const char *shortname) checksum = mkcksum((void *)shortname); do { - memset(slotptr, 0x00, sizeof(dir_slot)); + memset(slotptr, 0x00, sizeof(struct dir_slot)); ret = str2slot(slotptr, l_name, &idx); slotptr->id = ++counter; slotptr->attr = ATTR_VFAT; @@ -417,7 +417,7 @@ fill_dir_slot(fat_itr *itr, const char *l_name, const char *shortname) slotptr->id |= LAST_LONG_ENTRY_MASK; while (counter >= 1) { - memcpy(itr->dent, slotptr, sizeof(dir_slot)); + memcpy(itr->dent, slotptr, sizeof(struct dir_slot)); slotptr--; counter--; @@ -439,7 +439,7 @@ fill_dir_slot(fat_itr *itr, const char *l_name, const char *shortname) /* * Set the entry at index 'entry' in a FAT (12/16/32) table. */ -static int set_fatent_value(fsdata *mydata, __u32 entry, __u32 entry_value) +static int set_fatent_value(struct fsdata *mydata, __u32 entry, __u32 entry_value) { __u32 bufnum, offset, off16; __u16 val1, val2; @@ -546,7 +546,7 @@ static int set_fatent_value(fsdata *mydata, __u32 entry, __u32 entry_value) * Determine the next free cluster after 'entry' in a FAT (12/16/32) table * and link it to 'entry'. EOC marker is not set on returned entry. */ -static __u32 determine_fatent(fsdata *mydata, __u32 entry) +static __u32 determine_fatent(struct fsdata *mydata, __u32 entry) { __u32 next_fat, next_entry = entry + 1; @@ -577,7 +577,7 @@ static __u32 determine_fatent(fsdata *mydata, __u32 entry) * Return: 0 on success, -1 otherwise */ static int -set_sectors(fsdata *mydata, u32 startsect, u8 *buffer, u32 size) +set_sectors(struct fsdata *mydata, u32 startsect, u8 *buffer, u32 size) { int ret; @@ -641,7 +641,7 @@ set_sectors(fsdata *mydata, u32 startsect, u8 *buffer, u32 size) * Return: 0 on success, -1 otherwise */ static int -set_cluster(fsdata *mydata, u32 clustnum, u8 *buffer, u32 size) +set_cluster(struct fsdata *mydata, u32 clustnum, u8 *buffer, u32 size) { return set_sectors(mydata, clust_to_sect(mydata, clustnum), buffer, size); @@ -653,9 +653,9 @@ set_cluster(fsdata *mydata, u32 clustnum, u8 *buffer, u32 size) * @itr: directory iterator * Return: 0 for success, -EIO on error */ -static int flush_dir(fat_itr *itr) +static int flush_dir(struct fat_itr *itr) { - fsdata *mydata = itr->fsdata; + struct fsdata *mydata = itr->fsdata; u32 startsect, sect_offset, nsects; int ret; @@ -685,7 +685,7 @@ out: * Read and modify data on existing and consecutive cluster blocks */ static int -get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer, +get_set_cluster(struct fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer, loff_t size, loff_t *gotsize) { static u8 *tmpbuf_cluster; @@ -803,7 +803,7 @@ get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer, /* * Find the first empty cluster */ -static int find_empty_cluster(fsdata *mydata) +static int find_empty_cluster(struct fsdata *mydata) { __u32 fat_val, entry = 3; @@ -823,9 +823,9 @@ static int find_empty_cluster(fsdata *mydata) * @itr: directory iterator * Return: 0 on success, -EIO otherwise */ -static int new_dir_table(fat_itr *itr) +static int new_dir_table(struct fat_itr *itr) { - fsdata *mydata = itr->fsdata; + struct fsdata *mydata = itr->fsdata; int dir_newclust = 0; int dir_oldclust = itr->clust; unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; @@ -853,9 +853,9 @@ static int new_dir_table(fat_itr *itr) if (flush_dirty_fat_buffer(mydata) < 0) return -EIO; - itr->dent = (dir_entry *)itr->block; + itr->dent = (struct dir_entry *)itr->block; itr->last_cluster = 1; - itr->remaining = bytesperclust / sizeof(dir_entry) - 1; + itr->remaining = bytesperclust / sizeof(struct dir_entry) - 1; return 0; } @@ -863,7 +863,7 @@ static int new_dir_table(fat_itr *itr) /* * Set empty cluster from 'entry' to the end of a file */ -static int clear_fatent(fsdata *mydata, __u32 entry) +static int clear_fatent(struct fsdata *mydata, __u32 entry) { __u32 fat_val; @@ -887,7 +887,7 @@ static int clear_fatent(fsdata *mydata, __u32 entry) /* * Set start cluster in directory entry */ -static void set_start_cluster(const fsdata *mydata, dir_entry *dentptr, +static void set_start_cluster(const struct fsdata *mydata, struct dir_entry *dentptr, __u32 start_cluster) { if (mydata->fatsize == 32) @@ -901,7 +901,7 @@ static void set_start_cluster(const fsdata *mydata, dir_entry *dentptr, * exceed the size of the block device * Return -1 when overflow occurs, otherwise return 0 */ -static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size) +static int check_overflow(struct fsdata *mydata, __u32 clustnum, loff_t size) { __u32 startsect, sect_num, offset; @@ -927,7 +927,7 @@ static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size) * or return -1 on fatal errors. */ static int -set_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, __u8 *buffer, +set_contents(struct fsdata *mydata, struct dir_entry *dentptr, loff_t pos, __u8 *buffer, loff_t maxsize, loff_t *gotsize) { unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; @@ -1157,7 +1157,7 @@ getit: * * @dentptr: directory entry */ -static void dentry_set_time(dir_entry *dentptr) +static void dentry_set_time(struct dir_entry *dentptr) { if (CONFIG_IS_ENABLED(DM_RTC)) { struct udevice *dev; @@ -1197,8 +1197,9 @@ err: * @size: file size * @attr: file attributes */ -static void fill_dentry(fsdata *mydata, dir_entry *dentptr, - const char *shortname, __u32 start_cluster, __u32 size, __u8 attr) +static void fill_dentry(struct fsdata *mydata, struct dir_entry *dentptr, + const char *shortname, __u32 start_cluster, __u32 size, + __u8 attr) { memset(dentptr, 0, sizeof(*dentptr)); @@ -1223,7 +1224,7 @@ static void fill_dentry(fsdata *mydata, dir_entry *dentptr, * @itr: iterator positioned anywhere in a directory * @Return: 0 if the iterator is in the parent directory, -errno otherwise */ -static int fat_itr_parent(fat_itr *itr) +static int fat_itr_parent(struct fat_itr *itr) { int ret; @@ -1245,19 +1246,19 @@ static int fat_itr_parent(fat_itr *itr) * should be updated * @Return: 0 for success, -errno otherwise */ -static int update_parent_dir_props(fat_itr *dir_itr) +static int update_parent_dir_props(struct fat_itr *dir_itr) { int ret = 0; - fat_itr itr; - fsdata fsdata = { .fatbuf = NULL, }, *mydata = &fsdata; + struct fat_itr itr; + struct fsdata fsdata = { .fatbuf = NULL, }, *mydata = &fsdata; __u32 target_clust = dir_itr->start_clust; /* Short circuit if no RTC because it only updates timestamps */ if (!CONFIG_IS_ENABLED(DM_RTC)) return ret; - /* duplicate fsdata */ + /* duplicate struct fsdata */ itr = *dir_itr; fsdata = *itr.fsdata; @@ -1307,7 +1308,7 @@ exit: * @attr: file attributes * Return: 0 for success */ -static int create_link(fat_itr *itr, char *basename, __u32 clust, __u32 size, +static int create_link(struct fat_itr *itr, char *basename, __u32 clust, __u32 size, __u8 attr) { char shortname[SHORT_NAME_SIZE]; @@ -1341,7 +1342,7 @@ static int create_link(fat_itr *itr, char *basename, __u32 clust, __u32 size, * @filename: name of file to find * Return: directory entry or NULL */ -static dir_entry *find_directory_entry(fat_itr *itr, char *filename) +static struct dir_entry *find_directory_entry(struct fat_itr *itr, char *filename) { int match = 0; @@ -1472,10 +1473,10 @@ static int normalize_longname(char *l_filename, const char *filename) int file_fat_write_at(const char *filename, loff_t pos, void *buffer, loff_t size, loff_t *actwrite) { - dir_entry *retdent; - fsdata datablock = { .fatbuf = NULL, }; - fsdata *mydata = &datablock; - fat_itr *itr = NULL; + struct dir_entry *retdent; + struct fsdata datablock = { .fatbuf = NULL, }; + struct fsdata *mydata = &datablock; + struct fat_itr *itr = NULL; int ret = -1; char *filename_copy, *parent, *basename; char l_filename[VFAT_MAXLEN_BYTES]; @@ -1498,7 +1499,7 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, goto exit; } - itr = malloc_cache_aligned(sizeof(fat_itr)); + itr = malloc_cache_aligned(sizeof(struct fat_itr)); if (!itr) { ret = -ENOMEM; goto exit; @@ -1584,21 +1585,21 @@ int file_fat_write(const char *filename, void *buffer, loff_t offset, return file_fat_write_at(filename, offset, buffer, maxsize, actwrite); } -static int fat_dir_entries(fat_itr *itr) +static int fat_dir_entries(struct fat_itr *itr) { - fat_itr *dirs; - fsdata fsdata = { .fatbuf = NULL, }, *mydata = &fsdata; + struct fat_itr *dirs; + struct fsdata fsdata = { .fatbuf = NULL, }, *mydata = &fsdata; /* for FATBUFSIZE */ int count; - dirs = malloc_cache_aligned(sizeof(fat_itr)); + dirs = malloc_cache_aligned(sizeof(struct fat_itr)); if (!dirs) { debug("Error: allocating memory\n"); count = -ENOMEM; goto exit; } - /* duplicate fsdata */ + /* duplicate struct fsdata */ fat_itr_child(dirs, itr); fsdata = *dirs->fsdata; @@ -1627,7 +1628,7 @@ exit: * @itr: directory iterator * Return: 0 for success */ -static int delete_single_dentry(fat_itr *itr) +static int delete_single_dentry(struct fat_itr *itr) { struct dir_entry *dent = itr->dent; @@ -1645,7 +1646,7 @@ static int delete_single_dentry(fat_itr *itr) * @itr: directory iterator * Return: 0 for success */ -static int delete_long_name(fat_itr *itr) +static int delete_long_name(struct fat_itr *itr) { int seqn = itr->dent->nameext.name[0] & ~LAST_LONG_ENTRY_MASK; @@ -1670,7 +1671,7 @@ static int delete_long_name(fat_itr *itr) * @itr: the first directory entry (if a longname) to remove * Return: 0 for success */ -static int delete_dentry_link(fat_itr *itr) +static int delete_dentry_link(struct fat_itr *itr) { int ret; @@ -1699,10 +1700,10 @@ static int delete_dentry_link(fat_itr *itr) * @itr: directory iterator * Return: 0 for success */ -static int delete_dentry_long(fat_itr *itr) +static int delete_dentry_long(struct fat_itr *itr) { - fsdata *mydata = itr->fsdata; - dir_entry *dent = itr->dent; + struct fsdata *mydata = itr->fsdata; + struct dir_entry *dent = itr->dent; /* free cluster blocks */ clear_fatent(mydata, START(dent)); @@ -1723,13 +1724,13 @@ static int delete_dentry_long(fat_itr *itr) int fat_unlink(const char *filename) { - fsdata fsdata = { .fatbuf = NULL, }; - fat_itr *itr = NULL; + struct fsdata fsdata = { .fatbuf = NULL, }; + struct fat_itr *itr = NULL; int n_entries, ret; char *filename_copy, *dirname, *basename; filename_copy = strdup(filename); - itr = malloc_cache_aligned(sizeof(fat_itr)); + itr = malloc_cache_aligned(sizeof(struct fat_itr)); if (!itr || !filename_copy) { printf("Error: out of memory\n"); ret = -ENOMEM; @@ -1788,16 +1789,16 @@ exit: int fat_mkdir(const char *dirname) { - dir_entry *retdent; - fsdata datablock = { .fatbuf = NULL, }; - fsdata *mydata = &datablock; - fat_itr *itr = NULL; + struct dir_entry *retdent; + struct fsdata datablock = { .fatbuf = NULL, }; + struct fsdata *mydata = &datablock; + struct fat_itr *itr = NULL; char *dirname_copy, *parent, *basename; char l_dirname[VFAT_MAXLEN_BYTES]; int ret = -1; loff_t actwrite; unsigned int bytesperclust; - dir_entry *dotdent = NULL; + struct dir_entry *dotdent = NULL; dirname_copy = strdup(dirname); if (!dirname_copy) @@ -1815,7 +1816,7 @@ int fat_mkdir(const char *dirname) goto exit; } - itr = malloc_cache_aligned(sizeof(fat_itr)); + itr = malloc_cache_aligned(sizeof(struct fat_itr)); if (!itr) { ret = -ENOMEM; goto exit; @@ -1925,13 +1926,13 @@ exit: * Return: -errno on error, 0 if path_itr does not have the directory * at prefix_clust as an ancestor. */ -static int check_path_prefix(loff_t prefix_clust, fat_itr *path_itr) +static int check_path_prefix(loff_t prefix_clust, struct fat_itr *path_itr) { - fat_itr itr; - fsdata fsdata = { .fatbuf = NULL, }, *mydata = &fsdata; + struct fat_itr itr; + struct fsdata fsdata = { .fatbuf = NULL, }, *mydata = &fsdata; int ret; - /* duplicate fsdata */ + /* duplicate struct fsdata */ itr = *path_itr; fsdata = *itr.fsdata; @@ -1986,24 +1987,24 @@ exit: */ int fat_rename(const char *old_path, const char *new_path) { - fat_itr *old_itr = NULL, *new_itr = NULL; - fsdata old_datablock = { .fatbuf = NULL, }; - fsdata new_datablock = { .fatbuf = NULL, }; + struct fat_itr *old_itr = NULL, *new_itr = NULL; + struct fsdata old_datablock = { .fatbuf = NULL, }; + struct fsdata new_datablock = { .fatbuf = NULL, }; /* used for START macro */ - fsdata *mydata = &old_datablock; + struct fsdata *mydata = &old_datablock; int ret = -EIO, is_old_dir; char *old_path_copy, *old_dirname, *old_basename; char *new_path_copy, *new_dirname, *new_basename; char l_new_basename[VFAT_MAXLEN_BYTES]; __u32 old_clust; - dir_entry *found_existing; + struct dir_entry *found_existing; /* only set if found_existing != NULL */ __u32 new_clust; old_path_copy = strdup(old_path); new_path_copy = strdup(new_path); - old_itr = malloc_cache_aligned(sizeof(fat_itr)); - new_itr = malloc_cache_aligned(sizeof(fat_itr)); + old_itr = malloc_cache_aligned(sizeof(struct fat_itr)); + new_itr = malloc_cache_aligned(sizeof(struct fat_itr)); if (!old_path_copy || !new_path_copy || !old_itr || !new_itr) { log_debug("Error: out of memory\n"); ret = -ENOMEM; @@ -2143,7 +2144,7 @@ int fat_rename(const char *old_path, const char *new_path) /* update moved directory so the parent is new_path */ if (is_old_dir) { __u32 clust = new_itr->start_clust; - dir_entry *dent; + struct dir_entry *dent; fat_itr_child(new_itr, new_itr); dent = find_directory_entry(new_itr, ".."); diff --git a/include/fat.h b/include/fat.h index 053c34dd0e2..50b528d3cb7 100644 --- a/include/fat.h +++ b/include/fat.h @@ -84,7 +84,7 @@ struct disk_partition; ((fatsize) != 16 ? 0xff0 : 0xfff0) : \ 0xffffff0)) -typedef struct boot_sector { +struct boot_sector { __u8 ignored[3]; /* Bootstrap code */ char system_id[8]; /* Name of fs */ __u8 sector_size[2]; /* Bytes/sector */ @@ -108,10 +108,9 @@ typedef struct boot_sector { __u16 info_sector; /* Filesystem info sector */ __u16 backup_boot; /* Backup boot sector */ __u16 reserved2[6]; /* Unused */ -} boot_sector; +}; -typedef struct volume_info -{ +struct volume_info { __u8 drive_number; /* BIOS drive number */ __u8 reserved; /* Unused */ __u8 ext_boot_sign; /* 0x29 if fields below exist (DOS 3.3+) */ @@ -120,7 +119,7 @@ typedef struct volume_info char fs_type[8]; /* Typically FAT12, FAT16, or FAT32 */ /* Boot code comes next, all but 2 bytes to fill up sector */ /* Boot sign comes last, 2 bytes */ -} volume_info; +}; /* see dir_entry::lcase: */ #define CASE_LOWER_BASE 8 /* base (name) is lower case */ @@ -131,7 +130,7 @@ struct nameext { char ext[3]; }; -typedef struct dir_entry { +struct dir_entry { struct nameext nameext; /* Name and extension */ __u8 attr; /* Attribute bits */ __u8 lcase; /* Case for name and ext (CASE_LOWER_x) */ @@ -142,9 +141,9 @@ typedef struct dir_entry { __u16 starthi; /* High 16 bits of cluster in FAT32 */ __u16 time,date,start;/* Time, date and first cluster */ __u32 size; /* File size in bytes */ -} dir_entry; +}; -typedef struct dir_slot { +struct dir_slot { __u8 id; /* Sequence number for slot */ __u8 name0_4[10]; /* First 5 characters in name */ __u8 attr; /* Attribute byte */ @@ -153,7 +152,7 @@ typedef struct dir_slot { __u8 name5_10[12]; /* 6 more characters in name */ __u16 start; /* Unused */ __u8 name11_12[4]; /* Last 2 characters in name */ -} dir_slot; +}; /* * Private filesystem parameters @@ -161,7 +160,7 @@ typedef struct dir_slot { * Note: FAT buffer has to be 32 bit aligned * (see FAT32 accesses) */ -typedef struct { +struct fsdata { __u8 *fatbuf; /* Current FAT buffer */ int fatsize; /* Size of FAT in bits */ __u32 fatlength; /* Length of FAT in sectors */ @@ -176,17 +175,16 @@ typedef struct { __u32 root_cluster; /* First cluster of root dir for FAT32 */ u32 total_sect; /* Number of sectors */ int fats; /* Number of FATs */ -} fsdata; +}; struct fat_itr; -typedef struct fat_itr fat_itr; -static inline u32 clust_to_sect(fsdata *fsdata, u32 clust) +static inline u32 clust_to_sect(struct fsdata *fsdata, u32 clust) { return fsdata->data_begin + clust * fsdata->clust_size; } -static inline u32 sect_to_clust(fsdata *fsdata, int sect) +static inline u32 sect_to_clust(struct fsdata *fsdata, int sect) { return (sect - fsdata->data_begin) / fsdata->clust_size; } @@ -209,7 +207,7 @@ int fat_unlink(const char *filename); int fat_rename(const char *old_path, const char *new_path); int fat_mkdir(const char *dirname); void fat_close(void); -void *fat_next_cluster(fat_itr *itr, unsigned int *nbytes); +void *fat_next_cluster(struct fat_itr *itr, unsigned int *nbytes); /** * fat_uuid() - get FAT volume ID -- 2.43.0
From: Simon Glass <simon.glass@canonical.com> Add kernel-doc comments to structs and public functions in fat.h so that it is easier to understand the code. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- include/fat.h | 349 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 284 insertions(+), 65 deletions(-) diff --git a/include/fat.h b/include/fat.h index 50b528d3cb7..c44f23b0013 100644 --- a/include/fat.h +++ b/include/fat.h @@ -84,129 +84,348 @@ struct disk_partition; ((fatsize) != 16 ? 0xff0 : 0xfff0) : \ 0xffffff0)) +/** + * struct boot_sector - FAT boot sector structure + * @ignored: bootstrap code (first 3 bytes) + * @system_id: name of filesystem (8 bytes) + * @sector_size: bytes per sector + * @cluster_size: sectors per cluster + * @reserved: number of reserved sectors + * @fats: number of FAT copies + * @dir_entries: number of root directory entries + * @sectors: number of sectors (for small disks) + * @media: media descriptor code + * @fat_length: sectors per FAT (for FAT12/16) + * @secs_track: sectors per track + * @heads: number of heads + * @hidden: number of hidden sectors + * @total_sect: total number of sectors (for larger disks) + * @fat32_length: sectors per FAT (FAT32 only) + * @flags: flags (bit 8: fat mirroring, low 4: active fat) + * @version: filesystem version (FAT32 only) + * @root_cluster: first cluster of root directory (FAT32 only) + * @info_sector: filesystem info sector (FAT32 only) + * @backup_boot: backup boot sector location (FAT32 only) + * @reserved2: unused (FAT32 only) + */ struct boot_sector { - __u8 ignored[3]; /* Bootstrap code */ - char system_id[8]; /* Name of fs */ - __u8 sector_size[2]; /* Bytes/sector */ - __u8 cluster_size; /* Sectors/cluster */ - __u16 reserved; /* Number of reserved sectors */ - __u8 fats; /* Number of FATs */ - __u8 dir_entries[2]; /* Number of root directory entries */ - __u8 sectors[2]; /* Number of sectors */ - __u8 media; /* Media code */ - __u16 fat_length; /* Sectors/FAT */ - __u16 secs_track; /* Sectors/track */ - __u16 heads; /* Number of heads */ - __u32 hidden; /* Number of hidden sectors */ - __u32 total_sect; /* Number of sectors (if sectors == 0) */ + __u8 ignored[3]; + char system_id[8]; + __u8 sector_size[2]; + __u8 cluster_size; + __u16 reserved; + __u8 fats; + __u8 dir_entries[2]; + __u8 sectors[2]; + __u8 media; + __u16 fat_length; + __u16 secs_track; + __u16 heads; + __u32 hidden; + __u32 total_sect; /* FAT32 only */ - __u32 fat32_length; /* Sectors/FAT */ - __u16 flags; /* Bit 8: fat mirroring, low 4: active fat */ - __u8 version[2]; /* Filesystem version */ - __u32 root_cluster; /* First cluster in root directory */ - __u16 info_sector; /* Filesystem info sector */ - __u16 backup_boot; /* Backup boot sector */ - __u16 reserved2[6]; /* Unused */ + __u32 fat32_length; + __u16 flags; + __u8 version[2]; + __u32 root_cluster; + __u16 info_sector; + __u16 backup_boot; + __u16 reserved2[6]; }; +/** + * struct volume_info - FAT volume information structure + * @drive_number: BIOS drive number + * @reserved: unused field + * @ext_boot_sign: extended boot signature (0x29 if fields below exist) + * @volume_id: volume serial number (4 bytes) + * @volume_label: volume label (11 bytes, padded with spaces) + * @fs_type: filesystem type string (typically "FAT12", "FAT16", or "FAT32") + * + * This structure is part of the boot sector, located after the common fields. + * Boot code follows this structure, with boot signature at the end of sector. + */ struct volume_info { - __u8 drive_number; /* BIOS drive number */ - __u8 reserved; /* Unused */ - __u8 ext_boot_sign; /* 0x29 if fields below exist (DOS 3.3+) */ - __u8 volume_id[4]; /* Volume ID number */ - char volume_label[11]; /* Volume label */ - char fs_type[8]; /* Typically FAT12, FAT16, or FAT32 */ - /* Boot code comes next, all but 2 bytes to fill up sector */ - /* Boot sign comes last, 2 bytes */ + __u8 drive_number; + __u8 reserved; + __u8 ext_boot_sign; + __u8 volume_id[4]; + char volume_label[11]; + char fs_type[8]; }; /* see dir_entry::lcase: */ #define CASE_LOWER_BASE 8 /* base (name) is lower case */ #define CASE_LOWER_EXT 16 /* extension is lower case */ +/** + * struct nameext - 8.3 filename components + * @name: filename (8 bytes) + * @ext: extension (3 bytes) + */ struct nameext { char name[8]; char ext[3]; }; +/** + * struct dir_entry - FAT directory entry + * @nameext: filename and extension (8.3 format) + * @attr: file attributes (ATTR_* flags) + * @lcase: case flags for name and extension (CASE_LOWER_* flags) + * @ctime_ms: creation time (milliseconds) + * @ctime: creation time (hours, minutes, seconds) + * @cdate: creation date + * @adate: last access date + * @starthi: high 16 bits of cluster number (FAT32 only) + * @time: modification time + * @date: modification date + * @start: low 16 bits of cluster number + * @size: file size in bytes + */ struct dir_entry { - struct nameext nameext; /* Name and extension */ - __u8 attr; /* Attribute bits */ - __u8 lcase; /* Case for name and ext (CASE_LOWER_x) */ - __u8 ctime_ms; /* Creation time, milliseconds */ - __u16 ctime; /* Creation time */ - __u16 cdate; /* Creation date */ - __u16 adate; /* Last access date */ - __u16 starthi; /* High 16 bits of cluster in FAT32 */ - __u16 time,date,start;/* Time, date and first cluster */ - __u32 size; /* File size in bytes */ + struct nameext nameext; + __u8 attr; + __u8 lcase; + __u8 ctime_ms; + __u16 ctime; + __u16 cdate; + __u16 adate; + __u16 starthi; + __u16 time + __u16 date; + __u16 start; + __u32 size; }; +/** + * struct dir_slot - VFAT long filename entry + * @id: sequence number (bit 6 = last entry, bits 0-4 = sequence) + * @name0_4: characters 0-4 of long filename (UTF-16LE) + * @attr: must be ATTR_VFAT (0x0F) + * @reserved: unused field + * @alias_checksum: checksum of 8.3 alias for this long name + * @name5_10: characters 5-10 of long filename (UTF-16LE) + * @start: unused (always 0) + * @name11_12: characters 11-12 of long filename (UTF-16LE) + * + * Long filename entries precede the corresponding short entry in directory. + * Multiple entries may be used to store names longer than 13 characters. + */ struct dir_slot { - __u8 id; /* Sequence number for slot */ - __u8 name0_4[10]; /* First 5 characters in name */ - __u8 attr; /* Attribute byte */ - __u8 reserved; /* Unused */ - __u8 alias_checksum;/* Checksum for 8.3 alias */ - __u8 name5_10[12]; /* 6 more characters in name */ - __u16 start; /* Unused */ - __u8 name11_12[4]; /* Last 2 characters in name */ + __u8 id; + __u8 name0_4[10]; + __u8 attr; + __u8 reserved; + __u8 alias_checksum; + __u8 name5_10[12]; + __u16 start; + __u8 name11_12[4]; }; -/* - * Private filesystem parameters +/** + * struct fsdata - FAT filesystem instance data + * @fatbuf: buffer for reading/writing FAT (must be 32-bit aligned for FAT32) + * @fatsize: size of FAT in bits (12, 16, or 32) + * @fatlength: length of FAT in sectors + * @fat_sect: starting sector of the FAT + * @fat_dirty: flag indicating if fatbuf has been modified + * @rootdir_sect: starting sector of root directory + * @sect_size: size of sectors in bytes + * @clust_size: size of clusters in sectors + * @data_begin: sector offset of first data cluster (can be negative) + * @fatbufnum: currently buffered FAT sector number (init to -1) + * @rootdir_size: size of root directory in entries (for non-FAT32) + * @root_cluster: first cluster of root directory (FAT32 only) + * @total_sect: total number of sectors + * @fats: number of FAT copies * - * Note: FAT buffer has to be 32 bit aligned - * (see FAT32 accesses) + * This structure holds the runtime state of a mounted FAT filesystem. + * The fatbuf must be 32-bit aligned due to FAT32 sector access requirements. */ struct fsdata { - __u8 *fatbuf; /* Current FAT buffer */ - int fatsize; /* Size of FAT in bits */ - __u32 fatlength; /* Length of FAT in sectors */ - __u16 fat_sect; /* Starting sector of the FAT */ - __u8 fat_dirty; /* Set if fatbuf has been modified */ - __u32 rootdir_sect; /* Start sector of root directory */ - __u16 sect_size; /* Size of sectors in bytes */ - __u16 clust_size; /* Size of clusters in sectors */ - int data_begin; /* The sector of the first cluster, can be negative */ - int fatbufnum; /* Used by get_fatent, init to -1 */ - int rootdir_size; /* Size of root dir for non-FAT32 */ - __u32 root_cluster; /* First cluster of root dir for FAT32 */ - u32 total_sect; /* Number of sectors */ - int fats; /* Number of FATs */ + __u8 *fatbuf; + int fatsize; + __u32 fatlength; + __u16 fat_sect; + __u8 fat_dirty; + __u32 rootdir_sect; + __u16 sect_size; + __u16 clust_size; + int data_begin; + int fatbufnum; + int rootdir_size; + __u32 root_cluster; + u32 total_sect; + int fats; }; struct fat_itr; +/** + * clust_to_sect() - convert cluster number to sector number + * @fsdata: filesystem instance data + * @clust: cluster number + * + * Return: sector number corresponding to the given cluster + */ static inline u32 clust_to_sect(struct fsdata *fsdata, u32 clust) { return fsdata->data_begin + clust * fsdata->clust_size; } +/** + * sect_to_clust() - convert sector number to cluster number + * @fsdata: filesystem instance data + * @sect: sector number + * + * Return: cluster number corresponding to the given sector + */ static inline u32 sect_to_clust(struct fsdata *fsdata, int sect) { return (sect - fsdata->data_begin) / fsdata->clust_size; } +/** + * file_fat_detectfs() - detect and initialize the FAT filesystem + * + * Return: 0 on success, -1 on error + */ int file_fat_detectfs(void); + +/** + * fat_exists() - check if a file exists + * @filename: full path to file + * + * Return: 0 if file exists, -1 if not found or error + */ int fat_exists(const char *filename); + +/** + * fat_size() - get the size of a file + * @filename: full path to file + * @size: pointer to store file size + * + * Return: 0 on success, -1 on error + */ int fat_size(const char *filename, loff_t *size); + +/** + * file_fat_read() - read a file from FAT filesystem + * @filename: full path to file + * @buffer: buffer to read data into + * @maxsize: maximum number of bytes to read + * + * Return: number of bytes read, -1 on error + */ int file_fat_read(const char *filename, void *buffer, int maxsize); + +/** + * fat_set_blk_dev() - set the block device and partition for FAT operations + * @rbdd: block device descriptor + * @info: partition information + * + * Return: 0 on success, -1 on error + */ int fat_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info); + +/** + * fat_register_device() - register a FAT filesystem on a block device + * @dev_desc: block device descriptor + * @part_no: partition number (0 = whole device) + * + * Return: 0 on success, -1 on error + */ int fat_register_device(struct blk_desc *dev_desc, int part_no); +/** + * file_fat_write() - write to a file on FAT filesystem + * @filename: full path to file + * @buf: buffer containing data to write + * @offset: offset in file to start writing + * @len: number of bytes to write + * @actwrite: pointer to store actual number of bytes written + * + * Return: 0 on success, -1 on error + */ int file_fat_write(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actwrite); + +/** + * fat_read_file() - read from a file on FAT filesystem + * @filename: full path to file + * @buf: buffer to read data into + * @offset: offset in file to start reading + * @len: number of bytes to read + * @actread: pointer to store actual number of bytes read + * + * Return: 0 on success, -1 on error + */ int fat_read_file(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actread); + +/** + * fat_opendir() - open a directory for reading + * @filename: full path to directory + * @dirsp: pointer to store directory stream handle + * + * Return: 0 on success, -1 on error + */ int fat_opendir(const char *filename, struct fs_dir_stream **dirsp); + +/** + * fat_readdir() - read next entry from directory + * @dirs: directory stream handle + * @dentp: pointer to store directory entry + * + * Return: 0 on success, -1 on error or end of directory + */ int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp); + +/** + * fat_closedir() - close a directory stream + * @dirs: directory stream handle + */ void fat_closedir(struct fs_dir_stream *dirs); + +/** + * fat_unlink() - delete a file or empty directory + * @filename: full path to file or directory + * + * Return: 0 on success, -1 on error + */ int fat_unlink(const char *filename); + +/** + * fat_rename() - rename a file or directory + * @old_path: current full path + * @new_path: new full path + * + * Return: 0 on success, -1 on error + */ int fat_rename(const char *old_path, const char *new_path); + +/** + * fat_mkdir() - create a directory + * @dirname: full path to new directory + * + * Return: 0 on success, -1 on error + */ int fat_mkdir(const char *dirname); + +/** + * fat_close() - close FAT filesystem and release resources + */ void fat_close(void); + +/** + * fat_next_cluster() - get the next cluster in a chain + * @itr: directory iterator + * @nbytes: pointer to store number of bytes in cluster + * + * Return: pointer to cluster data buffer + */ void *fat_next_cluster(struct fat_itr *itr, unsigned int *nbytes); /** -- 2.43.0
On 11/13/25 03:56, Simon Glass wrote:
From: Simon Glass <simon.glass@canonical.com>
Add kernel-doc comments to structs and public functions in fat.h so that it is easier to understand the code.
Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> ---
include/fat.h | 349 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 284 insertions(+), 65 deletions(-)
diff --git a/include/fat.h b/include/fat.h index 50b528d3cb7..c44f23b0013 100644 --- a/include/fat.h +++ b/include/fat.h @@ -84,129 +84,348 @@ struct disk_partition; ((fatsize) != 16 ? 0xff0 : 0xfff0) : \ 0xffffff0))
+/** + * struct boot_sector - FAT boot sector structure + * @ignored: bootstrap code (first 3 bytes) + * @system_id: name of filesystem (8 bytes) + * @sector_size: bytes per sector + * @cluster_size: sectors per cluster + * @reserved: number of reserved sectors + * @fats: number of FAT copies + * @dir_entries: number of root directory entries + * @sectors: number of sectors (for small disks) + * @media: media descriptor code + * @fat_length: sectors per FAT (for FAT12/16) + * @secs_track: sectors per track + * @heads: number of heads + * @hidden: number of hidden sectors + * @total_sect: total number of sectors (for larger disks) + * @fat32_length: sectors per FAT (FAT32 only) + * @flags: flags (bit 8: fat mirroring, low 4: active fat) + * @version: filesystem version (FAT32 only) + * @root_cluster: first cluster of root directory (FAT32 only) + * @info_sector: filesystem info sector (FAT32 only) + * @backup_boot: backup boot sector location (FAT32 only) + * @reserved2: unused (FAT32 only) + */ struct boot_sector { - __u8 ignored[3]; /* Bootstrap code */ - char system_id[8]; /* Name of fs */ - __u8 sector_size[2]; /* Bytes/sector */ - __u8 cluster_size; /* Sectors/cluster */ - __u16 reserved; /* Number of reserved sectors */ - __u8 fats; /* Number of FATs */ - __u8 dir_entries[2]; /* Number of root directory entries */ - __u8 sectors[2]; /* Number of sectors */ - __u8 media; /* Media code */ - __u16 fat_length; /* Sectors/FAT */ - __u16 secs_track; /* Sectors/track */ - __u16 heads; /* Number of heads */ - __u32 hidden; /* Number of hidden sectors */ - __u32 total_sect; /* Number of sectors (if sectors == 0) */ + __u8 ignored[3]; + char system_id[8]; + __u8 sector_size[2]; + __u8 cluster_size; + __u16 reserved; + __u8 fats; + __u8 dir_entries[2]; + __u8 sectors[2]; + __u8 media; + __u16 fat_length; + __u16 secs_track; + __u16 heads; + __u32 hidden; + __u32 total_sect;
/* FAT32 only */ - __u32 fat32_length; /* Sectors/FAT */ - __u16 flags; /* Bit 8: fat mirroring, low 4: active fat */ - __u8 version[2]; /* Filesystem version */ - __u32 root_cluster; /* First cluster in root directory */ - __u16 info_sector; /* Filesystem info sector */ - __u16 backup_boot; /* Backup boot sector */ - __u16 reserved2[6]; /* Unused */ + __u32 fat32_length; + __u16 flags; + __u8 version[2]; + __u32 root_cluster; + __u16 info_sector; + __u16 backup_boot; + __u16 reserved2[6]; };
+/** + * struct volume_info - FAT volume information structure + * @drive_number: BIOS drive number + * @reserved: unused field + * @ext_boot_sign: extended boot signature (0x29 if fields below exist) + * @volume_id: volume serial number (4 bytes) + * @volume_label: volume label (11 bytes, padded with spaces) + * @fs_type: filesystem type string (typically "FAT12", "FAT16", or "FAT32") + * + * This structure is part of the boot sector, located after the common fields. + * Boot code follows this structure, with boot signature at the end of sector. + */ struct volume_info { - __u8 drive_number; /* BIOS drive number */ - __u8 reserved; /* Unused */ - __u8 ext_boot_sign; /* 0x29 if fields below exist (DOS 3.3+) */ - __u8 volume_id[4]; /* Volume ID number */ - char volume_label[11]; /* Volume label */ - char fs_type[8]; /* Typically FAT12, FAT16, or FAT32 */ - /* Boot code comes next, all but 2 bytes to fill up sector */ - /* Boot sign comes last, 2 bytes */ + __u8 drive_number; + __u8 reserved; + __u8 ext_boot_sign; + __u8 volume_id[4]; + char volume_label[11]; + char fs_type[8]; };
/* see dir_entry::lcase: */ #define CASE_LOWER_BASE 8 /* base (name) is lower case */ #define CASE_LOWER_EXT 16 /* extension is lower case */
+/** + * struct nameext - 8.3 filename components + * @name: filename (8 bytes) + * @ext: extension (3 bytes) + */ struct nameext { char name[8]; char ext[3]; };
+/** + * struct dir_entry - FAT directory entry + * @nameext: filename and extension (8.3 format) + * @attr: file attributes (ATTR_* flags) + * @lcase: case flags for name and extension (CASE_LOWER_* flags) + * @ctime_ms: creation time (milliseconds) + * @ctime: creation time (hours, minutes, seconds) + * @cdate: creation date + * @adate: last access date + * @starthi: high 16 bits of cluster number (FAT32 only) + * @time: modification time + * @date: modification date + * @start: low 16 bits of cluster number + * @size: file size in bytes + */ struct dir_entry { - struct nameext nameext; /* Name and extension */ - __u8 attr; /* Attribute bits */ - __u8 lcase; /* Case for name and ext (CASE_LOWER_x) */ - __u8 ctime_ms; /* Creation time, milliseconds */ - __u16 ctime; /* Creation time */ - __u16 cdate; /* Creation date */ - __u16 adate; /* Last access date */ - __u16 starthi; /* High 16 bits of cluster in FAT32 */ - __u16 time,date,start;/* Time, date and first cluster */ - __u32 size; /* File size in bytes */ + struct nameext nameext; + __u8 attr; + __u8 lcase; + __u8 ctime_ms; + __u16 ctime; + __u16 cdate; + __u16 adate; + __u16 starthi; + __u16 time
Missing semicolon.
+ __u16 date; + __u16 start; + __u32 size; };
+/** + * struct dir_slot - VFAT long filename entry + * @id: sequence number (bit 6 = last entry, bits 0-4 = sequence) + * @name0_4: characters 0-4 of long filename (UTF-16LE) + * @attr: must be ATTR_VFAT (0x0F) + * @reserved: unused field + * @alias_checksum: checksum of 8.3 alias for this long name + * @name5_10: characters 5-10 of long filename (UTF-16LE) + * @start: unused (always 0) + * @name11_12: characters 11-12 of long filename (UTF-16LE) + * + * Long filename entries precede the corresponding short entry in directory. + * Multiple entries may be used to store names longer than 13 characters. + */ struct dir_slot { - __u8 id; /* Sequence number for slot */ - __u8 name0_4[10]; /* First 5 characters in name */ - __u8 attr; /* Attribute byte */ - __u8 reserved; /* Unused */ - __u8 alias_checksum;/* Checksum for 8.3 alias */ - __u8 name5_10[12]; /* 6 more characters in name */ - __u16 start; /* Unused */ - __u8 name11_12[4]; /* Last 2 characters in name */ + __u8 id; + __u8 name0_4[10]; + __u8 attr; + __u8 reserved; + __u8 alias_checksum; + __u8 name5_10[12]; + __u16 start; + __u8 name11_12[4]; };
-/* - * Private filesystem parameters +/** + * struct fsdata - FAT filesystem instance data + * @fatbuf: buffer for reading/writing FAT (must be 32-bit aligned for FAT32) + * @fatsize: size of FAT in bits (12, 16, or 32) + * @fatlength: length of FAT in sectors + * @fat_sect: starting sector of the FAT + * @fat_dirty: flag indicating if fatbuf has been modified + * @rootdir_sect: starting sector of root directory + * @sect_size: size of sectors in bytes + * @clust_size: size of clusters in sectors + * @data_begin: sector offset of first data cluster (can be negative) + * @fatbufnum: currently buffered FAT sector number (init to -1) + * @rootdir_size: size of root directory in entries (for non-FAT32) + * @root_cluster: first cluster of root directory (FAT32 only) + * @total_sect: total number of sectors + * @fats: number of FAT copies * - * Note: FAT buffer has to be 32 bit aligned - * (see FAT32 accesses) + * This structure holds the runtime state of a mounted FAT filesystem. + * The fatbuf must be 32-bit aligned due to FAT32 sector access requirements. */ struct fsdata { - __u8 *fatbuf; /* Current FAT buffer */ - int fatsize; /* Size of FAT in bits */ - __u32 fatlength; /* Length of FAT in sectors */ - __u16 fat_sect; /* Starting sector of the FAT */ - __u8 fat_dirty; /* Set if fatbuf has been modified */ - __u32 rootdir_sect; /* Start sector of root directory */ - __u16 sect_size; /* Size of sectors in bytes */ - __u16 clust_size; /* Size of clusters in sectors */ - int data_begin; /* The sector of the first cluster, can be negative */ - int fatbufnum; /* Used by get_fatent, init to -1 */ - int rootdir_size; /* Size of root dir for non-FAT32 */ - __u32 root_cluster; /* First cluster of root dir for FAT32 */ - u32 total_sect; /* Number of sectors */ - int fats; /* Number of FATs */ + __u8 *fatbuf; + int fatsize; + __u32 fatlength; + __u16 fat_sect; + __u8 fat_dirty; + __u32 rootdir_sect; + __u16 sect_size; + __u16 clust_size; + int data_begin; + int fatbufnum; + int rootdir_size; + __u32 root_cluster; + u32 total_sect; + int fats; };
struct fat_itr;
+/** + * clust_to_sect() - convert cluster number to sector number + * @fsdata: filesystem instance data + * @clust: cluster number + * + * Return: sector number corresponding to the given cluster + */ static inline u32 clust_to_sect(struct fsdata *fsdata, u32 clust) { return fsdata->data_begin + clust * fsdata->clust_size; }
+/** + * sect_to_clust() - convert sector number to cluster number + * @fsdata: filesystem instance data + * @sect: sector number + * + * Return: cluster number corresponding to the given sector + */ static inline u32 sect_to_clust(struct fsdata *fsdata, int sect) { return (sect - fsdata->data_begin) / fsdata->clust_size; }
+/** + * file_fat_detectfs() - detect and initialize the FAT filesystem + * + * Return: 0 on success, -1 on error + */ int file_fat_detectfs(void); + +/** + * fat_exists() - check if a file exists + * @filename: full path to file + * + * Return: 0 if file exists, -1 if not found or error + */ int fat_exists(const char *filename); + +/** + * fat_size() - get the size of a file + * @filename: full path to file + * @size: pointer to store file size + * + * Return: 0 on success, -1 on error + */ int fat_size(const char *filename, loff_t *size); + +/** + * file_fat_read() - read a file from FAT filesystem + * @filename: full path to file + * @buffer: buffer to read data into + * @maxsize: maximum number of bytes to read + * + * Return: number of bytes read, -1 on error + */ int file_fat_read(const char *filename, void *buffer, int maxsize); + +/** + * fat_set_blk_dev() - set the block device and partition for FAT operations + * @rbdd: block device descriptor + * @info: partition information + * + * Return: 0 on success, -1 on error + */ int fat_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info); + +/** + * fat_register_device() - register a FAT filesystem on a block device + * @dev_desc: block device descriptor + * @part_no: partition number (0 = whole device) + * + * Return: 0 on success, -1 on error + */ int fat_register_device(struct blk_desc *dev_desc, int part_no);
+/** + * file_fat_write() - write to a file on FAT filesystem + * @filename: full path to file + * @buf: buffer containing data to write + * @offset: offset in file to start writing + * @len: number of bytes to write + * @actwrite: pointer to store actual number of bytes written + * + * Return: 0 on success, -1 on error + */ int file_fat_write(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actwrite); + +/** + * fat_read_file() - read from a file on FAT filesystem + * @filename: full path to file + * @buf: buffer to read data into + * @offset: offset in file to start reading + * @len: number of bytes to read + * @actread: pointer to store actual number of bytes read + * + * Return: 0 on success, -1 on error + */ int fat_read_file(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actread); + +/** + * fat_opendir() - open a directory for reading + * @filename: full path to directory + * @dirsp: pointer to store directory stream handle + * + * Return: 0 on success, -1 on error + */ int fat_opendir(const char *filename, struct fs_dir_stream **dirsp); + +/** + * fat_readdir() - read next entry from directory + * @dirs: directory stream handle + * @dentp: pointer to store directory entry + * + * Return: 0 on success, -1 on error or end of directory + */ int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp); + +/** + * fat_closedir() - close a directory stream + * @dirs: directory stream handle + */ void fat_closedir(struct fs_dir_stream *dirs); + +/** + * fat_unlink() - delete a file or empty directory + * @filename: full path to file or directory + * + * Return: 0 on success, -1 on error + */ int fat_unlink(const char *filename); + +/** + * fat_rename() - rename a file or directory + * @old_path: current full path + * @new_path: new full path + * + * Return: 0 on success, -1 on error + */ int fat_rename(const char *old_path, const char *new_path); + +/** + * fat_mkdir() - create a directory + * @dirname: full path to new directory + * + * Return: 0 on success, -1 on error + */ int fat_mkdir(const char *dirname); + +/** + * fat_close() - close FAT filesystem and release resources + */ void fat_close(void); + +/** + * fat_next_cluster() - get the next cluster in a chain + * @itr: directory iterator + * @nbytes: pointer to store number of bytes in cluster + * + * Return: pointer to cluster data buffer + */ void *fat_next_cluster(struct fat_itr *itr, unsigned int *nbytes);
/**
From: Simon Glass <simon.glass@canonical.com> Convert all __u8, __u16, and __u32 types to their u8, u16, u32 equivalents throughout the FAT filesystem code. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/fat/fat.c | 48 +++++++++---------- fs/fat/fat_internal.h | 6 +-- fs/fat/fat_write.c | 104 +++++++++++++++++++++--------------------- include/fat.h | 102 ++++++++++++++++++++--------------------- 4 files changed, 130 insertions(+), 130 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 1ebf9b4c040..bcd55366d7c 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -43,7 +43,7 @@ void downcase(char *str, size_t len) struct blk_desc *cur_dev; struct disk_partition cur_part_info; -int disk_read(__u32 block, __u32 nr_blocks, void *buf) +int disk_read(u32 block, u32 nr_blocks, void *buf) { ulong ret; @@ -157,11 +157,11 @@ int flush_dirty_fat_buffer(struct fsdata *mydata) * Get the entry at index 'entry' in a FAT (12/16/32) table. * On failure 0x00 is returned. */ -__u32 get_fatent(struct fsdata *mydata, __u32 entry) +u32 get_fatent(struct fsdata *mydata, u32 entry) { - __u32 bufnum; - __u32 offset, off8; - __u32 ret = 0x00; + u32 bufnum; + u32 offset, off8; + u32 ret = 0x00; if (CHECK_CLUST(entry, mydata->fatsize)) { log_err("Invalid FAT entry: %#08x\n", entry); @@ -192,10 +192,10 @@ __u32 get_fatent(struct fsdata *mydata, __u32 entry) /* Read a new block of FAT entries into the cache. */ if (bufnum != mydata->fatbufnum) { - __u32 getsize = FATBUFBLOCKS; - __u8 *bufptr = mydata->fatbuf; - __u32 fatlength = mydata->fatlength; - __u32 startblock = bufnum * FATBUFBLOCKS; + u32 getsize = FATBUFBLOCKS; + u8 *bufptr = mydata->fatbuf; + u32 fatlength = mydata->fatlength; + u32 startblock = bufnum * FATBUFBLOCKS; /* Cap length if fatlength is not a multiple of FATBUFBLOCKS */ if (startblock + getsize > fatlength) @@ -217,10 +217,10 @@ __u32 get_fatent(struct fsdata *mydata, __u32 entry) /* Get the actual entry from the table */ switch (mydata->fatsize) { case 32: - ret = FAT2CPU32(((__u32 *) mydata->fatbuf)[offset]); + ret = FAT2CPU32(((u32 *) mydata->fatbuf)[offset]); break; case 16: - ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[offset]); + ret = FAT2CPU16(((u16 *)mydata->fatbuf)[offset]); break; case 12: off8 = (offset * 3) / 2; @@ -242,9 +242,9 @@ __u32 get_fatent(struct fsdata *mydata, __u32 entry) * Return 0 on success, -1 otherwise. */ static int -get_cluster(struct fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size) +get_cluster(struct fsdata *mydata, u32 clustnum, u8 *buffer, unsigned long size) { - __u32 startsect; + u32 startsect; int ret; if (clustnum > 0) { @@ -256,7 +256,7 @@ get_cluster(struct fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long s debug("gc - clustnum: %d, startsect: %d\n", clustnum, startsect); if ((unsigned long)buffer & (ARCH_DMA_MINALIGN - 1)) { - ALLOC_CACHE_ALIGN_BUFFER(__u8, tmpbuf, mydata->sect_size); + ALLOC_CACHE_ALIGN_BUFFER(u8, tmpbuf, mydata->sect_size); debug("FAT: Misaligned buffer address (%p)\n", buffer); @@ -272,8 +272,8 @@ get_cluster(struct fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long s size -= mydata->sect_size; } } else if (size >= mydata->sect_size) { - __u32 bytes_read; - __u32 sect_count = size / mydata->sect_size; + u32 bytes_read; + u32 sect_count = size / mydata->sect_size; ret = disk_read(startsect, sect_count, buffer); if (ret != sect_count) { @@ -286,7 +286,7 @@ get_cluster(struct fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long s size -= bytes_read; } if (size) { - ALLOC_CACHE_ALIGN_BUFFER(__u8, tmpbuf, mydata->sect_size); + ALLOC_CACHE_ALIGN_BUFFER(u8, tmpbuf, mydata->sect_size); ret = disk_read(startsect, 1, tmpbuf); if (ret != 1) { @@ -316,12 +316,12 @@ get_cluster(struct fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long s * Return: -1 on error, otherwise 0 */ static int get_contents(struct fsdata *mydata, struct dir_entry *dentptr, loff_t pos, - __u8 *buffer, loff_t maxsize, loff_t *gotsize) + u8 *buffer, loff_t maxsize, loff_t *gotsize) { loff_t filesize = FAT2CPU32(dentptr->size); unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; - __u32 curclust = START(dentptr); - __u32 endclust, newclust; + u32 curclust = START(dentptr); + u32 endclust, newclust; loff_t actsize; *gotsize = 0; @@ -357,7 +357,7 @@ static int get_contents(struct fsdata *mydata, struct dir_entry *dentptr, loff_t /* align to beginning of next cluster if any */ if (pos) { - __u8 *tmp_buffer; + u8 *tmp_buffer; actsize = min(filesize, (loff_t)bytesperclust); tmp_buffer = malloc_cache_aligned(actsize); @@ -466,12 +466,12 @@ static int slot2str(struct dir_slot *slotptr, char *l_name, int *idx) } /* Calculate short name checksum */ -__u8 mkcksum(struct nameext *nameext) +u8 mkcksum(struct nameext *nameext) { int i; u8 *pos = (void *)nameext; - __u8 ret = 0; + u8 ret = 0; for (i = 0; i < 11; i++) ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + pos[i]; @@ -552,7 +552,7 @@ static int is_bootsector_valid(const struct boot_sector *bs) static int read_bootsectandvi(struct boot_sector *bs, struct volume_info *volinfo, int *fatsize) { - __u8 *block; + u8 *block; struct volume_info *vistart; int ret = 0; diff --git a/fs/fat/fat_internal.h b/fs/fat/fat_internal.h index cefe28c8d00..7063db62a32 100644 --- a/fs/fat/fat_internal.h +++ b/fs/fat/fat_internal.h @@ -104,7 +104,7 @@ struct dir_entry *next_dent(struct fat_itr *itr); * @buf: buffer to read data into * Return: number of blocks read, -1 on error */ -int disk_read(__u32 block, __u32 nr_blocks, void *buf); +int disk_read(u32 block, u32 nr_blocks, void *buf); /** * flush_dirty_fat_buffer() - write fat buffer to disk if dirty @@ -121,14 +121,14 @@ int flush_dirty_fat_buffer(struct fsdata *mydata); * @entry: FAT entry index * Return: FAT entry value, 0x00 on failure */ -__u32 get_fatent(struct fsdata *mydata, __u32 entry); +u32 get_fatent(struct fsdata *mydata, u32 entry); /** * mkcksum() - calculate short name checksum * @nameext: name and extension structure * Return: checksum value */ -__u8 mkcksum(struct nameext *nameext); +u8 mkcksum(struct nameext *nameext); /** * fat_itr_root() - initialize an iterator to start at the root directory diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index be9265be11b..ff6f50998ae 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -193,7 +193,7 @@ out: } static int total_sector; -static int disk_write(__u32 block, __u32 nr_blocks, void *buf) +static int disk_write(u32 block, u32 nr_blocks, void *buf) { ulong ret; @@ -219,9 +219,9 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf) int flush_dirty_fat_buffer(struct fsdata *mydata) { int getsize = FATBUFBLOCKS; - __u32 fatlength = mydata->fatlength; - __u8 *bufptr = mydata->fatbuf; - __u32 startblock = mydata->fatbufnum * FATBUFBLOCKS; + u32 fatlength = mydata->fatlength; + u8 *bufptr = mydata->fatbuf; + u32 startblock = mydata->fatbufnum * FATBUFBLOCKS; debug("debug: evicting %d, dirty: %d\n", mydata->fatbufnum, (int)mydata->fat_dirty); @@ -396,9 +396,9 @@ static int flush_dir(struct fat_itr *itr); static int fill_dir_slot(struct fat_itr *itr, const char *l_name, const char *shortname) { - __u8 temp_dir_slot_buffer[MAX_LFN_SLOT * sizeof(struct dir_slot)]; + u8 temp_dir_slot_buffer[MAX_LFN_SLOT * sizeof(struct dir_slot)]; struct dir_slot *slotptr = (struct dir_slot *)temp_dir_slot_buffer; - __u8 counter = 0, checksum; + u8 counter = 0, checksum; int idx = 0, ret; /* Get short file name checksum value */ @@ -439,10 +439,10 @@ fill_dir_slot(struct fat_itr *itr, const char *l_name, const char *shortname) /* * Set the entry at index 'entry' in a FAT (12/16/32) table. */ -static int set_fatent_value(struct fsdata *mydata, __u32 entry, __u32 entry_value) +static int set_fatent_value(struct fsdata *mydata, u32 entry, u32 entry_value) { - __u32 bufnum, offset, off16; - __u16 val1, val2; + u32 bufnum, offset, off16; + u16 val1, val2; switch (mydata->fatsize) { case 32: @@ -465,9 +465,9 @@ static int set_fatent_value(struct fsdata *mydata, __u32 entry, __u32 entry_valu /* Read a new block of FAT entries into the cache. */ if (bufnum != mydata->fatbufnum) { int getsize = FATBUFBLOCKS; - __u8 *bufptr = mydata->fatbuf; - __u32 fatlength = mydata->fatlength; - __u32 startblock = bufnum * FATBUFBLOCKS; + u8 *bufptr = mydata->fatbuf; + u32 fatlength = mydata->fatlength; + u32 startblock = bufnum * FATBUFBLOCKS; /* Cap length if fatlength is not a multiple of FATBUFBLOCKS */ if (startblock + getsize > fatlength) @@ -491,10 +491,10 @@ static int set_fatent_value(struct fsdata *mydata, __u32 entry, __u32 entry_valu /* Set the actual entry */ switch (mydata->fatsize) { case 32: - ((__u32 *) mydata->fatbuf)[offset] = cpu_to_le32(entry_value); + ((u32 *)mydata->fatbuf)[offset] = cpu_to_le32(entry_value); break; case 16: - ((__u16 *) mydata->fatbuf)[offset] = cpu_to_le16(entry_value); + ((u16 *)mydata->fatbuf)[offset] = cpu_to_le16(entry_value); break; case 12: off16 = (offset * 3) / 4; @@ -502,33 +502,33 @@ static int set_fatent_value(struct fsdata *mydata, __u32 entry, __u32 entry_valu switch (offset & 0x3) { case 0: val1 = cpu_to_le16(entry_value) & 0xfff; - ((__u16 *)mydata->fatbuf)[off16] &= ~0xfff; - ((__u16 *)mydata->fatbuf)[off16] |= val1; + ((u16 *)mydata->fatbuf)[off16] &= ~0xfff; + ((u16 *)mydata->fatbuf)[off16] |= val1; break; case 1: val1 = cpu_to_le16(entry_value) & 0xf; val2 = (cpu_to_le16(entry_value) >> 4) & 0xff; - ((__u16 *)mydata->fatbuf)[off16] &= ~0xf000; - ((__u16 *)mydata->fatbuf)[off16] |= (val1 << 12); + ((u16 *)mydata->fatbuf)[off16] &= ~0xf000; + ((u16 *)mydata->fatbuf)[off16] |= (val1 << 12); - ((__u16 *)mydata->fatbuf)[off16 + 1] &= ~0xff; - ((__u16 *)mydata->fatbuf)[off16 + 1] |= val2; + ((u16 *)mydata->fatbuf)[off16 + 1] &= ~0xff; + ((u16 *)mydata->fatbuf)[off16 + 1] |= val2; break; case 2: val1 = cpu_to_le16(entry_value) & 0xff; val2 = (cpu_to_le16(entry_value) >> 8) & 0xf; - ((__u16 *)mydata->fatbuf)[off16] &= ~0xff00; - ((__u16 *)mydata->fatbuf)[off16] |= (val1 << 8); + ((u16 *)mydata->fatbuf)[off16] &= ~0xff00; + ((u16 *)mydata->fatbuf)[off16] |= (val1 << 8); - ((__u16 *)mydata->fatbuf)[off16 + 1] &= ~0xf; - ((__u16 *)mydata->fatbuf)[off16 + 1] |= val2; + ((u16 *)mydata->fatbuf)[off16 + 1] &= ~0xf; + ((u16 *)mydata->fatbuf)[off16 + 1] |= val2; break; case 3: val1 = cpu_to_le16(entry_value) & 0xfff; - ((__u16 *)mydata->fatbuf)[off16] &= ~0xfff0; - ((__u16 *)mydata->fatbuf)[off16] |= (val1 << 4); + ((u16 *)mydata->fatbuf)[off16] &= ~0xfff0; + ((u16 *)mydata->fatbuf)[off16] |= (val1 << 4); break; default: break; @@ -546,9 +546,9 @@ static int set_fatent_value(struct fsdata *mydata, __u32 entry, __u32 entry_valu * Determine the next free cluster after 'entry' in a FAT (12/16/32) table * and link it to 'entry'. EOC marker is not set on returned entry. */ -static __u32 determine_fatent(struct fsdata *mydata, __u32 entry) +static u32 determine_fatent(struct fsdata *mydata, u32 entry) { - __u32 next_fat, next_entry = entry + 1; + u32 next_fat, next_entry = entry + 1; while (1) { next_fat = get_fatent(mydata, next_entry); @@ -584,7 +584,7 @@ set_sectors(struct fsdata *mydata, u32 startsect, u8 *buffer, u32 size) debug("startsect: %d\n", startsect); if ((unsigned long)buffer & (ARCH_DMA_MINALIGN - 1)) { - ALLOC_CACHE_ALIGN_BUFFER(__u8, tmpbuf, mydata->sect_size); + ALLOC_CACHE_ALIGN_BUFFER(u8, tmpbuf, mydata->sect_size); debug("FAT: Misaligned buffer address (%p)\n", buffer); @@ -615,7 +615,7 @@ set_sectors(struct fsdata *mydata, u32 startsect, u8 *buffer, u32 size) } if (size) { - ALLOC_CACHE_ALIGN_BUFFER(__u8, tmpbuf, mydata->sect_size); + ALLOC_CACHE_ALIGN_BUFFER(u8, tmpbuf, mydata->sect_size); /* Do not leak content of stack */ memset(tmpbuf, 0, mydata->sect_size); memcpy(tmpbuf, buffer, size); @@ -685,12 +685,12 @@ out: * Read and modify data on existing and consecutive cluster blocks */ static int -get_set_cluster(struct fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer, +get_set_cluster(struct fsdata *mydata, u32 clustnum, loff_t pos, u8 *buffer, loff_t size, loff_t *gotsize) { static u8 *tmpbuf_cluster; unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; - __u32 startsect; + u32 startsect; loff_t clustcount, wsize; int i, ret; @@ -805,7 +805,7 @@ get_set_cluster(struct fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer, */ static int find_empty_cluster(struct fsdata *mydata) { - __u32 fat_val, entry = 3; + u32 fat_val, entry = 3; while (1) { fat_val = get_fatent(mydata, entry); @@ -863,9 +863,9 @@ static int new_dir_table(struct fat_itr *itr) /* * Set empty cluster from 'entry' to the end of a file */ -static int clear_fatent(struct fsdata *mydata, __u32 entry) +static int clear_fatent(struct fsdata *mydata, u32 entry) { - __u32 fat_val; + u32 fat_val; while (!CHECK_CLUST(entry, mydata->fatsize)) { fat_val = get_fatent(mydata, entry); @@ -888,7 +888,7 @@ static int clear_fatent(struct fsdata *mydata, __u32 entry) * Set start cluster in directory entry */ static void set_start_cluster(const struct fsdata *mydata, struct dir_entry *dentptr, - __u32 start_cluster) + u32 start_cluster) { if (mydata->fatsize == 32) dentptr->starthi = @@ -901,9 +901,9 @@ static void set_start_cluster(const struct fsdata *mydata, struct dir_entry *den * exceed the size of the block device * Return -1 when overflow occurs, otherwise return 0 */ -static int check_overflow(struct fsdata *mydata, __u32 clustnum, loff_t size) +static int check_overflow(struct fsdata *mydata, u32 clustnum, loff_t size) { - __u32 startsect, sect_num, offset; + u32 startsect, sect_num, offset; if (clustnum > 0) startsect = clust_to_sect(mydata, clustnum); @@ -927,12 +927,12 @@ static int check_overflow(struct fsdata *mydata, __u32 clustnum, loff_t size) * or return -1 on fatal errors. */ static int -set_contents(struct fsdata *mydata, struct dir_entry *dentptr, loff_t pos, __u8 *buffer, +set_contents(struct fsdata *mydata, struct dir_entry *dentptr, loff_t pos, u8 *buffer, loff_t maxsize, loff_t *gotsize) { unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; - __u32 curclust = START(dentptr); - __u32 endclust = 0, newclust = 0; + u32 curclust = START(dentptr); + u32 endclust = 0, newclust = 0; u64 cur_pos, filesize; loff_t offset, actsize, wsize; @@ -1198,8 +1198,8 @@ err: * @attr: file attributes */ static void fill_dentry(struct fsdata *mydata, struct dir_entry *dentptr, - const char *shortname, __u32 start_cluster, __u32 size, - __u8 attr) + const char *shortname, u32 start_cluster, u32 size, + u8 attr) { memset(dentptr, 0, sizeof(*dentptr)); @@ -1252,7 +1252,7 @@ static int update_parent_dir_props(struct fat_itr *dir_itr) struct fat_itr itr; struct fsdata fsdata = { .fatbuf = NULL, }, *mydata = &fsdata; - __u32 target_clust = dir_itr->start_clust; + u32 target_clust = dir_itr->start_clust; /* Short circuit if no RTC because it only updates timestamps */ if (!CONFIG_IS_ENABLED(DM_RTC)) @@ -1308,8 +1308,8 @@ exit: * @attr: file attributes * Return: 0 for success */ -static int create_link(struct fat_itr *itr, char *basename, __u32 clust, __u32 size, - __u8 attr) +static int create_link(struct fat_itr *itr, char *basename, u32 clust, u32 size, + u8 attr) { char shortname[SHORT_NAME_SIZE]; int ndent; @@ -1877,7 +1877,7 @@ int fat_mkdir(const char *dirname) else set_start_cluster(mydata, &dotdent[1], itr->start_clust); - ret = set_contents(mydata, retdent, 0, (__u8 *)dotdent, + ret = set_contents(mydata, retdent, 0, (u8 *)dotdent, bytesperclust, &actwrite); if (ret < 0) { printf("Error: writing contents\n"); @@ -1885,7 +1885,7 @@ int fat_mkdir(const char *dirname) } /* Write twice for "." */ set_start_cluster(mydata, &dotdent[0], START(retdent)); - ret = set_contents(mydata, retdent, 0, (__u8 *)dotdent, + ret = set_contents(mydata, retdent, 0, (u8 *)dotdent, bytesperclust, &actwrite); if (ret < 0) { printf("Error: writing contents\n"); @@ -1996,10 +1996,10 @@ int fat_rename(const char *old_path, const char *new_path) char *old_path_copy, *old_dirname, *old_basename; char *new_path_copy, *new_dirname, *new_basename; char l_new_basename[VFAT_MAXLEN_BYTES]; - __u32 old_clust; + u32 old_clust; struct dir_entry *found_existing; /* only set if found_existing != NULL */ - __u32 new_clust; + u32 new_clust; old_path_copy = strdup(old_path); new_path_copy = strdup(new_path); @@ -2093,7 +2093,7 @@ int fat_rename(const char *old_path, const char *new_path) /* create/update dentry to point to old_path's data cluster */ if (found_existing) { struct nameext new_name = new_itr->dent->nameext; - __u8 lcase = new_itr->dent->lcase; + u8 lcase = new_itr->dent->lcase; if (is_old_dir) { int n_entries = fat_dir_entries(new_itr); @@ -2143,7 +2143,7 @@ int fat_rename(const char *old_path, const char *new_path) /* update moved directory so the parent is new_path */ if (is_old_dir) { - __u32 clust = new_itr->start_clust; + u32 clust = new_itr->start_clust; struct dir_entry *dent; fat_itr_child(new_itr, new_itr); diff --git a/include/fat.h b/include/fat.h index c44f23b0013..aeb35f93872 100644 --- a/include/fat.h +++ b/include/fat.h @@ -109,29 +109,29 @@ struct disk_partition; * @reserved2: unused (FAT32 only) */ struct boot_sector { - __u8 ignored[3]; + u8 ignored[3]; char system_id[8]; - __u8 sector_size[2]; - __u8 cluster_size; - __u16 reserved; - __u8 fats; - __u8 dir_entries[2]; - __u8 sectors[2]; - __u8 media; - __u16 fat_length; - __u16 secs_track; - __u16 heads; - __u32 hidden; - __u32 total_sect; + u8 sector_size[2]; + u8 cluster_size; + u16 reserved; + u8 fats; + u8 dir_entries[2]; + u8 sectors[2]; + u8 media; + u16 fat_length; + u16 secs_track; + u16 heads; + u32 hidden; + u32 total_sect; /* FAT32 only */ - __u32 fat32_length; - __u16 flags; - __u8 version[2]; - __u32 root_cluster; - __u16 info_sector; - __u16 backup_boot; - __u16 reserved2[6]; + u32 fat32_length; + u16 flags; + u8 version[2]; + u32 root_cluster; + u16 info_sector; + u16 backup_boot; + u16 reserved2[6]; }; /** @@ -147,10 +147,10 @@ struct boot_sector { * Boot code follows this structure, with boot signature at the end of sector. */ struct volume_info { - __u8 drive_number; - __u8 reserved; - __u8 ext_boot_sign; - __u8 volume_id[4]; + u8 drive_number; + u8 reserved; + u8 ext_boot_sign; + u8 volume_id[4]; char volume_label[11]; char fs_type[8]; }; @@ -186,17 +186,17 @@ struct nameext { */ struct dir_entry { struct nameext nameext; - __u8 attr; - __u8 lcase; - __u8 ctime_ms; - __u16 ctime; - __u16 cdate; - __u16 adate; - __u16 starthi; - __u16 time - __u16 date; - __u16 start; - __u32 size; + u8 attr; + u8 lcase; + u8 ctime_ms; + u16 ctime; + u16 cdate; + u16 adate; + u16 starthi; + u16 time; + u16 date; + u16 start; + u32 size; }; /** @@ -214,14 +214,14 @@ struct dir_entry { * Multiple entries may be used to store names longer than 13 characters. */ struct dir_slot { - __u8 id; - __u8 name0_4[10]; - __u8 attr; - __u8 reserved; - __u8 alias_checksum; - __u8 name5_10[12]; - __u16 start; - __u8 name11_12[4]; + u8 id; + u8 name0_4[10]; + u8 attr; + u8 reserved; + u8 alias_checksum; + u8 name5_10[12]; + u16 start; + u8 name11_12[4]; }; /** @@ -245,18 +245,18 @@ struct dir_slot { * The fatbuf must be 32-bit aligned due to FAT32 sector access requirements. */ struct fsdata { - __u8 *fatbuf; + u8 *fatbuf; int fatsize; - __u32 fatlength; - __u16 fat_sect; - __u8 fat_dirty; - __u32 rootdir_sect; - __u16 sect_size; - __u16 clust_size; + u32 fatlength; + u16 fat_sect; + u8 fat_dirty; + u32 rootdir_sect; + u16 sect_size; + u16 clust_size; int data_begin; int fatbufnum; int rootdir_size; - __u32 root_cluster; + u32 root_cluster; u32 total_sect; int fats; }; -- 2.43.0
participants (2)
-
Heinrich Schuchardt -
Simon Glass