luat_fs_rtt.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "luat_base.h"
  2. #include "luat_fs.h"
  3. #define LUAT_LOG_TAG "fs.LFS"
  4. #include "luat_log.h"
  5. #include "rtthread.h"
  6. #include <dfs_fs.h>
  7. #ifdef LUAT_USE_FS_VFS
  8. #else
  9. int luat_fs_info(const char* path, luat_fs_info_t *conf) {
  10. struct statfs buff;
  11. if (!dfs_statfs(path, &buff)) {
  12. conf->total_block = buff.f_blocks;
  13. conf->block_used = buff.f_blocks - buff.f_bfree;
  14. conf->block_size = buff.f_bsize;
  15. conf->type = 0; // 位置
  16. memcpy(conf->filesystem, "dfs", 3);
  17. conf->filesystem[4] = 0;
  18. return 0;
  19. }
  20. else {
  21. LLOGW("dfs_statfs return != 0");
  22. }
  23. return -1;
  24. }
  25. // int luat_fs_mkdir(char const* _DirName) {
  26. // return mkdir(_DirName, 0);
  27. // }
  28. // int luat_fs_rmdir(char const* _DirName) {
  29. // return rmdir(_DirName);
  30. // }
  31. int luat_fs_mount(luat_fs_conf_t *conf) {
  32. // SPI Flash, 需要SFUD支持
  33. #ifdef RT_USING_SFUD
  34. if (!rt_strcmp(conf->type, "flash")) {
  35. if (rt_sfud_flash_probe("w25q", conf->busname) == RT_NULL) {
  36. if (!dfs_mount("w25q", conf->mount_point, conf->filesystem, 0, 0)) {
  37. LLOGD("flash mount success");
  38. return 0;
  39. }
  40. else {
  41. LLOGD("flash mount fail");
  42. return -1;
  43. }
  44. }
  45. else {
  46. LLOGD("flash probe fail");
  47. return -1;
  48. }
  49. }
  50. #endif
  51. // SDCard系列
  52. #if defined(RT_USING_SPI_MSD)
  53. if (!rt_strcmp(conf->type, "sd")) {
  54. if (msd_init("sd0", conf->busname) == RT_NULL) {
  55. if (!dfs_mount("sd0", conf->mount_point, conf->filesystem, 0, 0)) {
  56. LLOGD("sdcard mount success");
  57. return 0;
  58. }
  59. else {
  60. LLOGD("sdcard mount fail");
  61. return -1;
  62. }
  63. }
  64. else {
  65. LLOGD("sdcard init fail");
  66. return -1;
  67. }
  68. }
  69. #endif
  70. LLOGD("not support type: %s", conf->type);
  71. return -1;
  72. }
  73. #endif