memory.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /******************************************************************************
  2. * MiniFFS : Mini Flat File System
  3. * memory.c: This is the pure memory implementation of the MiniFFS
  4. *
  5. * Copyright (c) 2008-2022 986-Studio. All rights reserved.
  6. *
  7. ******************************************************************************/
  8. #define __miniffs_internal
  9. #include <miniffs.h>
  10. #include <stdlib.h>
  11. /* Public API */
  12. miniffs_t *miniffs_openfs(uintptr_t address)
  13. {
  14. miniffs_t *fs = NULL;
  15. if (address == 0)
  16. {
  17. miniffs_seterror(MINIFFS_INVALID_FS);
  18. goto exit;
  19. }
  20. fs = (miniffs_t *)calloc(1, sizeof(miniffs_t));
  21. if (fs == NULL)
  22. {
  23. miniffs_seterror(MINIFFS_ALLOCATION_ERROR);
  24. goto exit;
  25. }
  26. fs->header = (miniffs_header_t *)address;
  27. if (!miniffs_isvalidfs(fs))
  28. {
  29. miniffs_seterror(MINIFFS_INVALID_FS);
  30. goto free_and_exit;
  31. }
  32. fs->memoryOffset = (void *)address;
  33. goto exit;
  34. free_and_exit:
  35. free(fs);
  36. fs = NULL;
  37. exit:
  38. return fs;
  39. }
  40. /* Private API */
  41. void *miniffs_getfileaddr(miniffs_t *fs, fileentry_t *fent)
  42. {
  43. return fs->memoryOffset + fent->offset;
  44. }