46 lines
1007 B
C
46 lines
1007 B
C
/******************************************************************************
|
|
* MiniFFS : Mini Flat File System
|
|
* memory.c: This is the pure memory implementation of the MiniFFS
|
|
*
|
|
* Copyright (c) 2008-2022 986-Studio. All rights reserved.
|
|
*
|
|
******************************************************************************/
|
|
|
|
#define __miniffs_internal
|
|
#include <miniffs.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
/* Public API */
|
|
miniffs_t *miniffs_openfs(uintptr_t address)
|
|
{
|
|
miniffs_t *fs = (miniffs_t *)calloc(1, sizeof(miniffs_t));
|
|
if (fs == NULL)
|
|
{
|
|
miniffs_seterror(MINIFFS_ALLOCATION_ERROR);
|
|
goto exit;
|
|
}
|
|
|
|
fs->header = (miniffs_header_t *)address;
|
|
|
|
if (!miniffs_isvalidfs(fs))
|
|
{
|
|
miniffs_seterror(MINIFFS_INVALID_FS);
|
|
goto free_and_exit;
|
|
}
|
|
|
|
goto exit;
|
|
|
|
free_and_exit:
|
|
free(fs);
|
|
fs = NULL;
|
|
|
|
exit:
|
|
return fs;
|
|
}
|
|
|
|
/* Private API */
|
|
void *miniffs_getfileaddr(miniffs_t *fs, fileentry_t *fent)
|
|
{
|
|
return fs->memoryOffset + fent->offset;
|
|
} |