diff --git a/ff_fat.c b/ff_fat.c index 5be55ea..b849689 100755 --- a/ff_fat.c +++ b/ff_fat.c @@ -1060,7 +1060,7 @@ FF_Error_t FF_putFATEntry( FF_IOManager_t * pxIOManager, { /* There is no free cluster any more. */ ulCluster = 0; - xError = FF_FINDFREECLUSTER | FF_ERR_IOMAN_NOT_ENOUGH_FREE_SPACE; + xError = ( FF_Error_t ) ( FF_FINDFREECLUSTER | FF_ERR_IOMAN_NOT_ENOUGH_FREE_SPACE ); } *pxError = xError; diff --git a/ff_format.c b/ff_format.c index ca96af2..cac3127 100755 --- a/ff_format.c +++ b/ff_format.c @@ -807,8 +807,10 @@ static FF_Error_t prvPartitionExtended( struct xPartitionSet * pxSet, unsigned extendedLBA = pParams->ulHiddenSectors; /* Where to write the table */ uint32_t ulLBA = 0; - /* Contents of the table */ - FF_Part_t writeParts[ 4 ]; + + /* Contents of the table. There must be space for 4 primary, + * and 4 logical partitions. */ + FF_Part_t writeParts[ 8 ]; BaseType_t xPartitionNumber; FF_Buffer_t * pxSectorBuffer; uint8_t * pucBuffer; @@ -916,11 +918,11 @@ FF_Error_t FF_Partition( FF_Disk_t * pxDisk, { FF_Error_t xReturn = FF_ERR_NONE; struct xPartitionSet xSet; - BaseType_t xNeedExtended; /* When more than 4 partitions are requested, extended partitions are needed. */ - uint32_t ulAvailable; /* The number of sectors available. */ + BaseType_t xNeedExtended; /* When more than 4 partitions are requested, extended partitions are needed. */ + uint32_t ulAvailable; /* The number of sectors available. */ BaseType_t xPartitionNumber; - uint32_t ulSummedSizes; /* Summed sizes as a percentage or as number of sectors. */ - uint32_t ulReservedSpace; /**< Space needed for the extended partitions. */ + uint32_t ulSummedSizes = 0U; /* Summed sizes as a percentage or as number of sectors. */ + uint32_t ulReservedSpace; /**< Space needed for the extended partitions. */ memset( &( xSet ), 0, sizeof( xSet ) ); diff --git a/ff_ioman.c b/ff_ioman.c index 709994d..5cc094c 100755 --- a/ff_ioman.c +++ b/ff_ioman.c @@ -605,8 +605,9 @@ int32_t FF_BlockRead( FF_IOManager_t * pxIOManager, } /* Do not use 'FF_GETERROR()' here because FF_ERR_DRIVER_BUSY - * is a full 32-bit error code. */ - if( slRetVal != FF_ERR_DRIVER_BUSY ) + * is a full 32-bit error code, containing module, function and + * the actual error code. See 'ff_error.h' for definitions. */ + if( slRetVal != ( int32_t ) FF_ERR_DRIVER_BUSY ) { break; } @@ -656,8 +657,9 @@ int32_t FF_BlockWrite( FF_IOManager_t * pxIOManager, } /* Do not use 'FF_GETERROR()' here because FF_ERR_DRIVER_BUSY - * is a full 32-bit error code. */ - if( slRetVal != FF_ERR_DRIVER_BUSY ) + * is a full 32-bit error code, containing module, function and + * the actual error code. See 'ff_error.h' for definitions. */ + if( slRetVal != ( int32_t ) FF_ERR_DRIVER_BUSY ) { break; } @@ -840,7 +842,7 @@ static BaseType_t prvIsValidMedia( uint8_t media ) BaseType_t xResult; /* - * 0xF8 is the standard value for “fixed” (non-removable) media. For + * 0xF8 is the standard value for “fixed” (non-removable) media. For * removable media, 0xF0 is frequently used. The legal values for this * field are 0xF0, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, and * 0xFF. The only other important point is that whatever value is put diff --git a/include/FreeRTOSFATConfigDefaults.h b/include/FreeRTOSFATConfigDefaults.h index 2ce3af5..942a047 100755 --- a/include/FreeRTOSFATConfigDefaults.h +++ b/include/FreeRTOSFATConfigDefaults.h @@ -347,6 +347,10 @@ #define ffconfigMAX_PARTITIONS 4 #endif +#if ( ffconfigMAX_PARTITIONS < 1 ) || ( ffconfigMAX_PARTITIONS > 8 ) + #error ffconfigMAX_PARTITIONS must be between 1 and 8 +#endif + #if !defined( ffconfigMAX_FILE_SYS ) /* Defines how many drives can be combined in total. Should be set to at @@ -460,4 +464,49 @@ } #endif +#ifndef ffconfigFAT_USES_STAT + /* When enabled, the library keeps statistics about the use of cache + * buffers. This can be useful while configuring or optimising the + * cache size. */ + #define ffconfigFAT_USES_STAT 0 +#endif + +#ifndef ffconfigUSE_NOTIFY + +/* When defined, the driver will call a user hook "callFileEvents()" + * for certain events: creation, change, and deletion of a file or + * directory. + * For instance: it can be useful to get an event as soon as a set-up + * file has changed, or when a lock-file has been placed or removed. + */ + #define ffconfigUSE_NOTIFY 0 +#endif + +#ifndef ffconfigDEV_SUPPORT + +/* A rarely used feature of FreeRTOS+FAT which lets files behave + * as 'devices'. */ + #define ffconfigDEV_SUPPORT 0 +#endif + +#ifndef USE_SOFT_WDT + +/* When true. a user-provided function `clearWDT()` will be called + * during a long action. */ + #define USE_SOFT_WDT 0 +#endif + +#ifndef ffconfigNOT_USED_FOR_NOW + +/* This macro was once used for debugging. + * When defined as 1, the function 'FF_Utf16ctoUtf32c()' + * will be compiled */ + #define ffconfigNOT_USED_FOR_NOW 0 +#endif + +#ifndef FF_NOSTRCASECMP + /* When zero, the function 'strcasecmp()' will be dfined. */ + #define FF_NOSTRCASECMP 0 +#endif + #endif /* ifndef FF_DEFAULTCONFIG_H */ diff --git a/include/ff_stdio.h b/include/ff_stdio.h index 33606ca..12af285 100755 --- a/include/ff_stdio.h +++ b/include/ff_stdio.h @@ -128,7 +128,14 @@ /* The errno is stored in a thread local buffer. */ static portINLINE void stdioSET_ERRNO( int iErrno ) { - vTaskSetThreadLocalStoragePointer( NULL, ffconfigCWD_THREAD_LOCAL_INDEX, ( void * ) ( iErrno ) ); + /* Local storage pointers can only store pointers. This function + * wants to store a signed errno value, which needs a cast. */ + /* Cast from an integer to a signed value of a pointer size. */ + intptr_t xErrno = ( intptr_t ) iErrno; + /* Cast from a numeric value to a pointer. */ + void * pvValue = ( void * ) ( xErrno ); + + vTaskSetThreadLocalStoragePointer( NULL, ffconfigCWD_THREAD_LOCAL_INDEX, pvValue ); } static portINLINE int stdioGET_ERRNO( void ) @@ -136,7 +143,12 @@ void * pvResult; pvResult = pvTaskGetThreadLocalStoragePointer( ( TaskHandle_t ) NULL, ffconfigCWD_THREAD_LOCAL_INDEX ); - return ( int ) pvResult; + /* Cast from a pointer to a number of the same size. */ + intptr_t xErrno = ( intptr_t ) pvResult; + /* Cast it to an integer. */ + int iValue = ( int ) ( xErrno ); + + return iValue; } #if ( ( configNUM_THREAD_LOCAL_STORAGE_POINTERS - ffconfigCWD_THREAD_LOCAL_INDEX ) < 3 ) @@ -148,7 +160,14 @@ */ static portINLINE void stdioSET_FF_ERROR( FF_Error_t iFF_ERROR ) { - vTaskSetThreadLocalStoragePointer( NULL, stdioFF_ERROR_THREAD_LOCAL_OFFSET, ( void * ) ( iFF_ERROR ) ); + /* Cast it to an unsigned long. */ + uint32_t ulError = ( uint32_t ) iFF_ERROR; + /* Cast it to a number with the size of a pointer. */ + uintptr_t uxErrno = ( uintptr_t ) ulError; + /* Cast it to a void pointer. */ + void * pvValue = ( void * ) ( uxErrno ); + + vTaskSetThreadLocalStoragePointer( NULL, stdioFF_ERROR_THREAD_LOCAL_OFFSET, pvValue ); } /* @@ -160,7 +179,12 @@ void * pvResult; pvResult = pvTaskGetThreadLocalStoragePointer( NULL, stdioFF_ERROR_THREAD_LOCAL_OFFSET ); - return ( FF_Error_t ) pvResult; + /* Cast it to an integer with the same size as a pointer. */ + intptr_t uxErrno = ( intptr_t ) pvResult; + /* Cast it to a int32_t. */ + FF_Error_t xError = ( FF_Error_t ) uxErrno; + + return xError; } /*-----------------------------------------------------------