]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fs: fat: Refactor dirty flag handling
authorDaniel Palmer <daniel@thingy.jp>
Tue, 10 Mar 2026 22:06:18 +0000 (07:06 +0900)
committerTom Rini <trini@konsulko.com>
Fri, 27 Mar 2026 19:14:18 +0000 (13:14 -0600)
Refactor the dirty flag handling a little bit so an inline
function is called instead of directly stuffing a value into
the variable.

This allows variable that holds the flag to be completely removed
if its not used i.e. CONFIG_FAT_WIRTE=n

Signed-off-by: Daniel Palmer <daniel@thingy.jp>
fs/fat/fat.c
fs/fat/fat_write.c
include/fat.h

index 85b511f75afe6d0ef8ed5459ffa8a9ef1b200cdd..31c136e3b9edff25f3dc51e3d55a6199a96f05ba 100644 (file)
@@ -832,7 +832,7 @@ static int get_fs_info(fsdata *mydata)
        }
 
        mydata->fatbufnum = -1;
-       mydata->fat_dirty = 0;
+       fat_mark_clean(mydata);
        mydata->fatbuf = malloc_cache_aligned(FATBUFSIZE);
        if (mydata->fatbuf == NULL) {
                debug("Error: allocating memory\n");
index 02e006f7c9e612dead7a00105cdefd5a02ba2cb9..c98b530f7477709264084acc3453f572fb768e9b 100644 (file)
@@ -225,9 +225,9 @@ static int flush_dirty_fat_buffer(fsdata *mydata)
        __u32 startblock = mydata->fatbufnum * FATBUFBLOCKS;
 
        debug("debug: evicting %d, dirty: %d\n", mydata->fatbufnum,
-             (int)mydata->fat_dirty);
+             (int)fat_is_dirty(mydata));
 
-       if ((!mydata->fat_dirty) || (mydata->fatbufnum == -1))
+       if (!fat_is_dirty(mydata) || (mydata->fatbufnum == -1))
                return 0;
 
        /* Cap length if fatlength is not a multiple of FATBUFBLOCKS */
@@ -250,7 +250,7 @@ static int flush_dirty_fat_buffer(fsdata *mydata)
                        return -1;
                }
        }
-       mydata->fat_dirty = 0;
+       fat_mark_clean(mydata);
 
        return 0;
 }
@@ -486,8 +486,7 @@ static int set_fatent_value(fsdata *mydata, __u32 entry, __u32 entry_value)
                mydata->fatbufnum = bufnum;
        }
 
-       /* Mark as dirty */
-       mydata->fat_dirty = 1;
+       fat_mark_dirty(mydata);
 
        /* Set the actual entry */
        switch (mydata->fatsize) {
index bdf430f70675a7b070a522dccd4426faa7cf9cfc..40da0370a4442edad872661408c856b7dac0787c 100644 (file)
@@ -165,7 +165,9 @@ typedef struct {
        int     fatsize;        /* Size of FAT in bits */
        __u32   fatlength;      /* Length of FAT in sectors */
        __u16   fat_sect;       /* Starting sector of the FAT */
+#ifdef CONFIG_FAT_WRITE
        __u8    fat_dirty;      /* Set if fatbuf has been modified */
+#endif
        __u32   rootdir_sect;   /* Start sector of root directory */
        __u16   sect_size;      /* Size of sectors in bytes */
        __u16   clust_size;     /* Size of clusters in sectors */
@@ -190,6 +192,30 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect)
        return (sect - fsdata->data_begin) / fsdata->clust_size;
 }
 
+static inline void fat_mark_clean(fsdata *fsdata)
+{
+#ifdef CONFIG_FAT_WRITE
+       fsdata->fat_dirty = 0;
+#endif
+}
+
+static inline void fat_mark_dirty(fsdata *fsdata)
+{
+#ifdef CONFIG_FAT_WRITE
+       fsdata->fat_dirty = 1;
+#endif
+}
+
+static inline bool fat_is_dirty(fsdata *fsdata)
+{
+#ifdef CONFIG_FAT_WRITE
+       if (fsdata->fat_dirty)
+               return true;
+#endif
+
+       return false;
+}
+
 int file_fat_detectfs(void);
 int fat_exists(const char *filename);
 int fat_size(const char *filename, loff_t *size);