drv_filesystem.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-12-13 balanceTWK add sdcard port file
  9. * 2021-05-10 Meco Man fix a bug that cannot use fatfs in the main thread at starting up
  10. * 2021-07-28 Meco Man implement romfs as the root filesystem
  11. */
  12. #include <rtthread.h>
  13. #include <dfs_fs.h>
  14. #include <dfs_file.h>
  15. #define DBG_TAG "app.filesystem"
  16. #define DBG_LVL DBG_INFO
  17. #include <rtdbg.h>
  18. static int littlefs_mount(void)
  19. {
  20. if (rt_device_find("mflash") == RT_NULL)
  21. {
  22. LOG_E("mflash device not find!!");
  23. return -RT_EIO;
  24. }
  25. int ret = dfs_mount("mflash", "/", "lfs", 0, 0);
  26. if (ret != 0)
  27. {
  28. LOG_E("mflash mount to '/' failed!");
  29. ret = dfs_mkfs("lfs", "mflash");
  30. if (ret != 0)
  31. return ret;
  32. ret = dfs_mount("mflash", "/", "lfs", 0, 0);
  33. if (ret != 0)
  34. return ret;
  35. }
  36. LOG_D("mflash mount to '/' successed");
  37. return RT_EOK;
  38. }
  39. INIT_APP_EXPORT(littlefs_mount);