diff options
author | Stefan Brüns <stefan.bruens@rwth-aachen.de> | 2016-12-17 00:27:51 +0100 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2016-12-27 11:24:14 -0500 |
commit | b8948d2aef80717d3d2c4f37ec086ce3ea5ad24f (patch) | |
tree | ec57e27d2654c9f74b72775f78b263401f365174 /fs/fat/fat.c | |
parent | 6c1a808052ba6a875df7aa450b6df4b199f3a281 (diff) | |
download | u-boot-b8948d2aef80717d3d2c4f37ec086ce3ea5ad24f.tar.gz |
fs/fat: merge readwrite get_fatent_value() with readonly get_fatent()
get_fatent_value(...) flushes changed FAT entries to disk when fetching
the next FAT blocks, in every other aspect it is identical to
get_fatent(...).
Provide a stub implementation for flush_dirty_fat_buffer if
CONFIG_FAT_WRITE is not set. Calling flush_dirty_fat_buffer during read
only operation is fine as it checks if any buffers needs flushing.
Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Reviewed-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
Diffstat (limited to 'fs/fat/fat.c')
-rw-r--r-- | fs/fat/fat.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 6319581406..73c3dd7f85 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -162,6 +162,16 @@ static void get_name(dir_entry *dirent, char *s_name) downcase(s_name); } +static int flush_dirty_fat_buffer(fsdata *mydata); +#if !defined(CONFIG_FAT_WRITE) +/* Stub for read only operation */ +int flush_dirty_fat_buffer(fsdata *mydata) +{ + (void)(mydata); + return 0; +} +#endif + /* * Get the entry at index 'entry' in a FAT (12/16/32) table. * On failure 0x00 is returned. @@ -173,6 +183,11 @@ static __u32 get_fatent(fsdata *mydata, __u32 entry) __u32 ret = 0x00; __u16 val1, val2; + if (CHECK_CLUST(entry, mydata->fatsize)) { + printf("Error: Invalid FAT entry: 0x%08x\n", entry); + return ret; + } + switch (mydata->fatsize) { case 32: bufnum = entry / FAT32BUFSIZE; @@ -192,7 +207,7 @@ static __u32 get_fatent(fsdata *mydata, __u32 entry) return ret; } - debug("FAT%d: entry: 0x%04x = %d, offset: 0x%04x = %d\n", + debug("FAT%d: entry: 0x%08x = %d, offset: 0x%04x = %d\n", mydata->fatsize, entry, entry, offset, offset); /* Read a new block of FAT entries into the cache. */ @@ -208,6 +223,10 @@ static __u32 get_fatent(fsdata *mydata, __u32 entry) startblock += mydata->fat_sect; /* Offset from start of disk */ + /* Write back the fatbuf to the disk */ + if (flush_dirty_fat_buffer(mydata) < 0) + return -1; + if (disk_read(startblock, getsize, bufptr) < 0) { debug("Error reading FAT blocks\n"); return ret; @@ -254,8 +273,8 @@ static __u32 get_fatent(fsdata *mydata, __u32 entry) } break; } - debug("FAT%d: ret: %08x, offset: %04x\n", - mydata->fatsize, ret, offset); + debug("FAT%d: ret: 0x%08x, entry: 0x%08x, offset: 0x%04x\n", + mydata->fatsize, ret, entry, offset); return ret; } |