luat_fs_rtt.c 1.9 KB

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