memory.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. goto exit;
  33. free_and_exit:
  34. free(fs);
  35. fs = NULL;
  36. exit:
  37. return fs;
  38. }
  39. /* Private API */
  40. void *miniffs_getfileaddr(miniffs_t *fs, fileentry_t *fent)
  41. {
  42. return fs->memoryOffset + fent->offset;
  43. }