mnt.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * 2017-04-03 Urey the first version
  9. * 2022-06-01 Meco Man improve the init process
  10. */
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. #define DBG_TAG "FileSystem"
  14. #define DBG_LVL DBG_INFO
  15. #include <rtdbg.h>
  16. #ifdef RT_USING_DFS
  17. #include <dfs_fs.h>
  18. static int mnt_init(void)
  19. {
  20. #ifdef RT_USING_DFS_WINSHAREDIR
  21. extern int dfs_win32_init(void);
  22. extern rt_err_t rt_win_sharedir_init(const char *name);
  23. dfs_win32_init();
  24. rt_win_sharedir_init("wshare");
  25. if (dfs_mount("wshare", "/", "wdir", 0, 0) == 0)
  26. {
  27. LOG_I("[wshare] File System on root ('wshare') initialized!");
  28. }
  29. else
  30. {
  31. LOG_E("[wshare] File System on root ('wshare') initialization failed!");
  32. }
  33. if (dfs_mount("sd0", "/sd", "elm", 0, 0) == 0)
  34. #else
  35. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  36. #endif /* RT_USING_DFS_WINSHAREDIR */
  37. {
  38. LOG_I("[sd0] File System on SD ('sd0') initialized!");
  39. }
  40. else
  41. {
  42. LOG_W("[sd0] File System on SD ('sd0') initialization failed!");
  43. LOG_W("[sd0] Try to format and re-mount...");
  44. if (dfs_mkfs("elm", "sd0") == 0)
  45. {
  46. #ifdef RT_USING_DFS_WINSHAREDIR
  47. if (dfs_mount("sd0", "/sd", "elm", 0, 0) == 0)
  48. #else
  49. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  50. #endif /* RT_USING_DFS_WINSHAREDIR */
  51. {
  52. LOG_I("[sd0] File System on SD ('sd0') initialized!");
  53. return 0;
  54. }
  55. }
  56. LOG_E("[sd0] File System on SD ('sd0') initialization failed!");
  57. }
  58. return 0;
  59. }
  60. INIT_ENV_EXPORT(mnt_init);
  61. #endif /* RT_USING_DFS */