AP_Filesystem.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. /*
  14. ArduPilot filesystem interface. This offsets a minimal subset of
  15. full functionality offered by posix type interfaces, meeting the
  16. needs of ArduPilot
  17. */
  18. #pragma once
  19. #include <stdint.h>
  20. #include <AP_HAL/AP_HAL_Boards.h>
  21. #if HAL_OS_POSIX_IO || HAL_OS_FATFS_IO
  22. #define HAVE_FILESYSTEM_SUPPORT 1
  23. #else
  24. #define HAVE_FILESYSTEM_SUPPORT 0
  25. #endif
  26. #if HAVE_FILESYSTEM_SUPPORT
  27. #if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
  28. #include "AP_Filesystem_FATFS.h"
  29. #endif
  30. #if CONFIG_HAL_BOARD == HAL_BOARD_LINUX || CONFIG_HAL_BOARD == HAL_BOARD_SITL
  31. #include "AP_Filesystem_posix.h"
  32. #endif
  33. class AP_Filesystem {
  34. public:
  35. AP_Filesystem() {}
  36. // functions that closely match the equivalent posix calls
  37. int open(const char *fname, int flags);
  38. int close(int fd);
  39. ssize_t read(int fd, void *buf, size_t count);
  40. ssize_t write(int fd, const void *buf, size_t count);
  41. int fsync(int fd);
  42. off_t lseek(int fd, off_t offset, int whence);
  43. int stat(const char *pathname, struct stat *stbuf);
  44. int unlink(const char *pathname);
  45. int mkdir(const char *pathname);
  46. DIR *opendir(const char *pathname);
  47. struct dirent *readdir(DIR *dirp);
  48. int closedir(DIR *dirp);
  49. // return free disk space in bytes, -1 on error
  50. int64_t disk_free(const char *path);
  51. // return total disk space in bytes, -1 on error
  52. int64_t disk_space(const char *path);
  53. // set modification time on a file
  54. bool set_mtime(const char *filename, const time_t mtime_sec);
  55. };
  56. namespace AP {
  57. AP_Filesystem &FS();
  58. };
  59. #endif // HAVE_FILESYSTEM_SUPPORT