memory.c 1007 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 = (miniffs_t *)calloc(1, sizeof(miniffs_t));
  15. if (fs == NULL)
  16. {
  17. miniffs_seterror(MINIFFS_ALLOCATION_ERROR);
  18. goto exit;
  19. }
  20. fs->header = (miniffs_header_t *)address;
  21. if (!miniffs_isvalidfs(fs))
  22. {
  23. miniffs_seterror(MINIFFS_INVALID_FS);
  24. goto free_and_exit;
  25. }
  26. goto exit;
  27. free_and_exit:
  28. free(fs);
  29. fs = NULL;
  30. exit:
  31. return fs;
  32. }
  33. /* Private API */
  34. void *miniffs_getfileaddr(miniffs_t *fs, fileentry_t *fent)
  35. {
  36. return fs->memoryOffset + fent->offset;
  37. }