extern "C" {
#endif
+#include <stdint.h>
+typedef unsigned int UINT;
+typedef unsigned char BYTE;
+typedef uint32_t DWORD;
+
#include "diskio.h"
#include "esp_err.h"
* See FatFs documentation for details about these functions
*/
typedef struct {
- DSTATUS (*init) (BYTE pdrv); /*!< disk initialization function */
- DSTATUS (*status) (BYTE pdrv); /*!< disk status check function */
- DRESULT (*read) (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); /*!< sector read function */
- DRESULT (*write) (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); /*!< sector write function */
- DRESULT (*ioctl) (BYTE pdrv, BYTE cmd, void* buff); /*!< function to get info about disk and do some misc operations */
+ DSTATUS (*init) (unsigned char pdrv); /*!< disk initialization function */
+ DSTATUS (*status) (unsigned char pdrv); /*!< disk status check function */
+ DRESULT (*read) (unsigned char pdrv, unsigned char* buff, uint32_t sector, unsigned count); /*!< sector read function */
+ DRESULT (*write) (unsigned char pdrv, const unsigned char* buff, uint32_t sector, unsigned count); /*!< sector write function */
+ DRESULT (*ioctl) (unsigned char pdrv, unsigned char cmd, void* buff); /*!< function to get info about disk and do some misc operations */
} ff_diskio_impl_t;
/**
#include <string.h>
+#include <stdlib.h>
#include "ff.h"
#include "sdkconfig.h"
#ifdef CONFIG_FATFS_ALLOC_EXTRAM_FIRST
/*------------------------------------------------------------------------*/
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on not enough core) */
- UINT msize /* Number of bytes to allocate */
+ unsigned msize /* Number of bytes to allocate */
)
{
#ifdef CONFIG_FATFS_ALLOC_EXTRAM_FIRST
#endif
}
-/*------------------------------------------------------------------------*/
-/* Allocate and zero out memory block */
-/*------------------------------------------------------------------------*/
-
-
-void* ff_memcalloc (UINT num, UINT size)
-{
-#ifdef CONFIG_FATFS_ALLOC_EXTRAM_FIRST
- return heap_caps_calloc_prefer(num, size, 2, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM,
- MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL);
-#else
- return calloc(num, size);
-#endif
-}
-
/*------------------------------------------------------------------------*/
/* Free a memory block */
.utime_p = &vfs_fat_utime,
};
size_t ctx_size = sizeof(vfs_fat_ctx_t) + max_files * sizeof(FIL);
- vfs_fat_ctx_t* fat_ctx = (vfs_fat_ctx_t*) ff_memcalloc(1, ctx_size);
+ vfs_fat_ctx_t* fat_ctx = (vfs_fat_ctx_t*) ff_memalloc(ctx_size);
if (fat_ctx == NULL) {
return ESP_ERR_NO_MEM;
}
+ memset(fat_ctx, 0, ctx_size);
fat_ctx->o_append = ff_memalloc(max_files * sizeof(bool));
if (fat_ctx->o_append == NULL) {
free(fat_ctx);
return ESP_ERR_NO_MEM;
}
+ memset(fat_ctx->o_append, 0, max_files * sizeof(bool));
fat_ctx->max_files = max_files;
strlcpy(fat_ctx->fat_drive, fat_drive, sizeof(fat_ctx->fat_drive) - 1);
strlcpy(fat_ctx->base_path, base_path, sizeof(fat_ctx->base_path) - 1);
prepend_drive_to_path(fat_ctx, &n1, &n2);
const size_t copy_buf_size = fat_ctx->fs.csize;
FRESULT res;
- FIL* pf1 = ff_memcalloc(1, sizeof(FIL));
- FIL* pf2 = ff_memcalloc(1, sizeof(FIL));
+ FIL* pf1 = (FIL*) ff_memalloc(sizeof(FIL));
+ FIL* pf2 = (FIL*) ff_memalloc(sizeof(FIL));
void* buf = ff_memalloc(copy_buf_size);
if (buf == NULL || pf1 == NULL || pf2 == NULL) {
_lock_release(&fat_ctx->lock);
errno = ENOMEM;
return -1;
}
+ memset(pf1, 0, sizeof(*pf1));
+ memset(pf2, 0, sizeof(*pf2));
res = f_open(pf1, n1, FA_READ | FA_OPEN_EXISTING);
if (res != FR_OK) {
_lock_release(&fat_ctx->lock);
vfs_fat_ctx_t* fat_ctx = (vfs_fat_ctx_t*) ctx;
_lock_acquire(&fat_ctx->lock);
prepend_drive_to_path(fat_ctx, &name, NULL);
- vfs_fat_dir_t* fat_dir = ff_memcalloc(1, sizeof(vfs_fat_dir_t));
+ vfs_fat_dir_t* fat_dir = ff_memalloc(sizeof(vfs_fat_dir_t));
if (!fat_dir) {
_lock_release(&fat_ctx->lock);
errno = ENOMEM;
return NULL;
}
+ memset(fat_dir, 0, sizeof(*fat_dir));
+
FRESULT res = f_opendir(&fat_dir->ffdir, name);
_lock_release(&fat_ctx->lock);
if (res != FR_OK) {
_lock_acquire(&fat_ctx->lock);
prepend_drive_to_path(fat_ctx, &path, NULL);
- file = (FIL*) ff_memcalloc(1, sizeof(FIL));
+ file = (FIL*) ff_memalloc(sizeof(FIL));
if (file == NULL) {
_lock_release(&fat_ctx->lock);
ESP_LOGD(TAG, "truncate alloc failed");
ret = -1;
goto out;
}
+ memset(file, 0, sizeof(*file));
res = f_open(file, path, FA_WRITE);