FileSystem.hpp 2.2 KB

  1. #ifndef _FileSystem_hpp_
  2. #define _FileSystem_hpp_
  3. #include <FpConfig.hpp>
  4. #include <Fw/Types/String.hpp>
  5. #define FILE_SYSTEM_CHUNK_SIZE (256u)
  6. namespace Os {
  7. // This namespace encapsulates a very simple file system interface that has the most often-used features.
  8. namespace FileSystem {
  9. typedef enum {
  10. OP_OK, //!< Operation was successful
  11. ALREADY_EXISTS, //!< File already exists
  12. NO_SPACE, //!< No space left
  13. NO_PERMISSION, //!< No permission to write
  14. NOT_DIR, //!< Path is not a directory
  15. IS_DIR, //!< Path is a directory
  16. NOT_EMPTY, //!< directory is not empty
  17. INVALID_PATH, //!< Path is too long, too many sym links, doesn't exist, ect
  18. FILE_LIMIT, //!< Too many files or links
  19. BUSY, //!< Operand is in use by the system or by a process
  20. OTHER_ERROR, //!< other OS-specific error
  21. } Status;
  22. Status createDirectory(const char* path); //!< create a new directory at location path
  23. Status removeDirectory(const char* path); //!< remove a directory at location path
  24. Status readDirectory(const char* path, const U32 maxNum, Fw::String fileArray[], U32& numFiles); //!< read the contents of a directory. Size of fileArray should be maxNum. Cleaner implementation found in Directory.hpp
  25. Status removeFile(const char* path); //!< removes a file at location path
  26. Status moveFile(const char* originPath, const char* destPath); //! moves a file from origin to destination
  27. Status copyFile(const char* originPath, const char* destPath); //! copies a file from origin to destination
  28. Status appendFile(const char* originPath, const char* destPath, bool createMissingDest=false); //! append file origin to destination file. If boolean true, creates a brand new file if the destination doesn't exist.
  29. Status getFileSize(const char* path, FwSizeType& size); //!< gets the size of the file (in bytes) at location path
  30. Status getFileCount(const char* directory, U32& fileCount); //!< counts the number of files in the given directory
  31. Status changeWorkingDirectory(const char* path); //!< move current directory to path
  32. Status getFreeSpace(const char* path, FwSizeType& totalBytes, FwSizeType& freeBytes); //!< get FS free and total space in bytes on filesystem containing path
  33. }
  34. }
  35. #endif