hal_filesystem.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * filesystem_hal.h
  3. *
  4. * Copyright 2013-2021 Michael Zillgith
  5. *
  6. * This file is part of Platform Abstraction Layer (libpal)
  7. * for libiec61850, libmms, and lib60870.
  8. */
  9. #ifndef FILESYSTEM_HAL_H_
  10. #define FILESYSTEM_HAL_H_
  11. #include "hal_base.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /*! \addtogroup hal
  16. *
  17. * @{
  18. */
  19. /**
  20. * @defgroup HAL_FILESYSTEM Interface to the native file system (optional)
  21. *
  22. * @{
  23. */
  24. typedef void* FileHandle;
  25. typedef struct sDirectoryHandle* DirectoryHandle;
  26. #ifndef CONFIG_SYSTEM_FILE_SEPARATOR
  27. #define CONFIG_SYSTEM_FILE_SEPARATOR '/'
  28. #endif
  29. /**
  30. * \brief open a file
  31. *
  32. * \param pathName full name (path + filename) of the file
  33. * \param readWrite true opens the file with read and write access - false opens for read access only
  34. *
  35. * \return a handle for the file. Has to be used by subsequent calls to file functions to identify the file or
  36. * NULL if opening fails
  37. */
  38. PAL_API FileHandle
  39. FileSystem_openFile(char* pathName, bool readWrite);
  40. /**
  41. * \brief read from an open file
  42. *
  43. * This function will read the next block of the file. The maximum number of bytes to read
  44. * is given. A call to this function will move the file position by the number of bytes read.
  45. * If the file position reaches the end of file then subsequent calls of this function shall
  46. * return 0.
  47. *
  48. * \param handle the file handle to identify the file
  49. * \param buffer the buffer to write the read data
  50. * \param maxSize maximum number of bytes to read
  51. *
  52. * \return the number of bytes actually read
  53. */
  54. PAL_API int
  55. FileSystem_readFile(FileHandle handle, uint8_t* buffer, int maxSize);
  56. /**
  57. * \brief write to an open file
  58. *
  59. * \param handle the file handle to identify the file
  60. * \param buffer the buffer with the data to write
  61. * \param size the number of bytes to write
  62. *
  63. * \return the number of bytes actually written
  64. */
  65. PAL_API int
  66. FileSystem_writeFile(FileHandle handle, uint8_t* buffer, int size);
  67. /**
  68. * \brief close an open file
  69. *
  70. * \param handle the file handle to identify the file
  71. */
  72. PAL_API void
  73. FileSystem_closeFile(FileHandle handle);
  74. /**
  75. * \brief return attributes of the given file
  76. *
  77. * This function is used by the MMS layer to determine basic file attributes.
  78. * The size of the file has to be returned in bytes. The timestamp of the last modification has
  79. * to be returned as milliseconds since Unix epoch - or 0 if this function is not supported.
  80. *
  81. * \param pathName full name (path + filename) of the file
  82. * \param fileSize a pointer where to store the file size
  83. * \param lastModificationTimestamp is used to store the timestamp of last modification of the file
  84. *
  85. * \return true if file exists, false if not
  86. */
  87. PAL_API bool
  88. FileSystem_getFileInfo(char* filename, uint32_t* fileSize, uint64_t* lastModificationTimestamp);
  89. /**
  90. * \brief delete a file
  91. *
  92. * \param pathName full name (path + filename) of the file
  93. *
  94. * \return true on success, false on error
  95. */
  96. PAL_API bool
  97. FileSystem_deleteFile(char* filename);
  98. /**
  99. * \brief rename a file
  100. *
  101. * \param oldFileName current full name (path + filename) of the file
  102. * \param newFileName new full name (path + filename) of the file
  103. *
  104. * \return true on success, false on error
  105. */
  106. PAL_API bool
  107. FileSystem_renameFile(char* oldFilename, char* newFilename);
  108. /**
  109. * \brief open the directoy with the specified name
  110. *
  111. * \param directoryName
  112. *
  113. * \return a handle for the opened directory to be used in subsequent calls to identify the directory
  114. */
  115. PAL_API DirectoryHandle
  116. FileSystem_openDirectory(char* directoryName);
  117. /**
  118. * \brief read the next directory entry
  119. *
  120. * This function returns the next directory entry. The entry is only a valid pointer as long as the
  121. * FileSystem_closeDirectory or another FileSystem_readDirectory function is not called for the given
  122. * DirectoryHandle.
  123. *
  124. * \param directory the handle to identify the directory
  125. * \param isDirectory return value that indicates if the directory entry is itself a directory (true)
  126. *
  127. * \return the name of the directory entry
  128. */
  129. PAL_API char*
  130. FileSystem_readDirectory(DirectoryHandle directory, bool* isDirectory);
  131. /**
  132. * \brief close a directory
  133. *
  134. * \param directory the handle to identify the directory
  135. */
  136. PAL_API void
  137. FileSystem_closeDirectory(DirectoryHandle directory);
  138. /*! @} */
  139. /*! @} */
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif /* FILESYSTEM_HAL_H_ */