FAT: Add an option to force all transfers to be performed indirectly through the FAT file system's internal sector buffers

This commit is contained in:
Gregory Nutt 2016-02-22 16:26:04 -06:00
parent bc0648119e
commit 7c44444883
4 changed files with 48 additions and 6 deletions

View File

@ -11515,4 +11515,12 @@
* sched/pthread: Add pthread_setaffinity() and pthread_getaffinity()
(2016-02-19).
* sched/sched: Add sched_setaffinity() and sched_getaffinity() (2016-02-19).
* drivers/leds/rgbled.c: Add a driver to manage a RGB LED via PWM. From
Alan Carvalho de Assis (2016-02-22).
* arch/arm/src/stm32fcdiscovery: Add PWM support for the onboard RGB LED
From Alan Carvalho de Assis (2016-02-22).
* arch/arm/src/samv7: HSMCI driver can now be configured to handle unaligned
data buffers (2016-02-22).
* fs/fat: Add an option to force all transfers to be performed indirectly
using the FAT file system's internal sector buffers (2016-02-22).

2
arch

@ -1 +1 @@
Subproject commit 1182e9ab34aeefb94d9e502257effb94ea84091e
Subproject commit 7ed1d2eb50bcfc637e21fcf41521e562d4a521a1

View File

@ -13,6 +13,7 @@ config FS_FAT
Enable FAT filesystem support
if FS_FAT
config FAT_LCNAMES
bool "FAT upper/lower names"
default n
@ -49,6 +50,29 @@ config FS_FATTIME
much sense in supporting FAT date and time unless you have a
hardware RTC or other way to get the time and date.
config FAT_FORCE_INDIRECT
bool "Force all in-direct transfers"
default n
---help---
Normally, the default behavior for the FAT file system is to perform
data transfers indirectly though specially allocated sector buffers
or, under certain circumstances, directly through user provided
buffers . These circumstances are: (1) The transfer is being
performed from the beginning of a sector (2) the user-provided
buffer will hold the full sector of data.
Some hardware, however, may require special DMA-capable memory or
specially aligned memory in order to perform the transfers. In this
case, there may be no circumstance where the user buffer can be used.
Selecting this option will disable all attempts to use the user-
provided buffer: All transfers will be force to be performed
indirectly through the FAT file systems sector buffers.
Note: This will have the negative impact of: (1) An extra data
copy to transfer the data between the user buffer and the FAT file
systems internal sector buffers, and (2) A loss of performance
because I/O will be limited to one sector at a time.
config FAT_DMAMEMORY
bool "DMA memory allocator"
default n
@ -66,4 +90,4 @@ config FAT_DMAMEMORY
corresponding function that will be called to free the DMA-capable
memory.
endif
endif # FAT

View File

@ -479,13 +479,16 @@ static ssize_t fat_read(FAR struct file *filep, FAR char *buffer,
FAR struct fat_file_s *ff;
unsigned int bytesread;
unsigned int readsize;
unsigned int nsectors;
size_t bytesleft;
int32_t cluster;
FAR uint8_t *userbuffer = (FAR uint8_t *)buffer;
int sectorindex;
int ret;
#ifndef CONFIG_FAT_FORCE_INDIRECT
unsigned int nsectors;
bool force_indirect = false;
#endif
/* Sanity checks */
@ -590,6 +593,7 @@ static ssize_t fat_read(FAR struct file *filep, FAR char *buffer,
fat_read_restart:
#endif
#ifndef CONFIG_FAT_FORCE_INDIRECT
/* Check if the user has provided a buffer large enough to hold one
* or more complete sectors -AND- the read is aligned to a sector
* boundary.
@ -636,7 +640,7 @@ fat_read_restart:
force_indirect = true;
goto fat_read_restart;
}
#endif
#endif /* CONFIG_FAT_DMAMEMORY */
goto errout_with_semaphore;
}
@ -646,6 +650,7 @@ fat_read_restart:
bytesread = nsectors * fs->fs_hwsectorsize;
}
else
#endif /* CONFIG_FAT_FORCE_INDIRECT */
{
/* We are reading a partial sector, or handling a non-DMA-able
* whole-sector transfer. First, read the whole sector
@ -709,11 +714,14 @@ static ssize_t fat_write(FAR struct file *filep, FAR const char *buffer,
int32_t cluster;
unsigned int byteswritten;
unsigned int writesize;
unsigned int nsectors;
FAR uint8_t *userbuffer = (FAR uint8_t *)buffer;
int sectorindex;
int ret;
#ifndef CONFIG_FAT_FORCE_INDIRECT
unsigned int nsectors;
bool force_indirect = false;
#endif
/* Sanity checks. I have seen the following assertion misfire if
* CONFIG_DEBUG_MM is enabled while re-directing output to a
@ -844,6 +852,7 @@ static ssize_t fat_write(FAR struct file *filep, FAR const char *buffer,
fat_write_restart:
#endif
#ifndef CONFIG_FAT_FORCE_INDIRECT
/* Check if the user has provided a buffer large enough to
* hold one or more complete sectors.
*/
@ -890,7 +899,7 @@ fat_write_restart:
force_indirect = true;
goto fat_write_restart;
}
#endif
#endif /* CONFIG_FAT_DMAMEMORY */
goto errout_with_semaphore;
}
@ -901,6 +910,7 @@ fat_write_restart:
ff->ff_bflags |= FFBUFF_MODIFIED;
}
else
#endif /* CONFIG_FAT_FORCE_INDIRECT */
{
/* Decide whether we are performing a read-modify-write
* operation, in which case we have to read the existing sector