FileSystemHandle.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2006-2013 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MBED_FILESYSTEMHANDLE_H
  17. #define MBED_FILESYSTEMHANDLE_H
  18. #include "platform/platform.h"
  19. #include "platform/FileBase.h"
  20. #include "platform/FileHandle.h"
  21. #include "platform/DirHandle.h"
  22. #include "platform/NonCopyable.h"
  23. namespace mbed {
  24. /** \addtogroup platform */
  25. /** @{*/
  26. /**
  27. * \defgroup platform_FileSystemHandle FileSystemHandle functions
  28. * @{
  29. */
  30. /** A filesystem-like object is one that can be used to open file-like
  31. * objects though it by fopen("/name/filename", mode)
  32. *
  33. * Implementations must define at least open (the default definitions
  34. * of the rest of the functions just return error values).
  35. *
  36. * @note Synchronization level: Set by subclass
  37. */
  38. class FileSystemHandle : private NonCopyable<FileSystemHandle> {
  39. public:
  40. /** FileSystemHandle lifetime
  41. */
  42. virtual ~FileSystemHandle() {}
  43. /** Open a file on the filesystem
  44. *
  45. * @param file Destination for the handle to a newly created file
  46. * @param filename The name of the file to open
  47. * @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR,
  48. * bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
  49. * @return 0 on success, negative error code on failure
  50. */
  51. virtual int open(FileHandle **file, const char *filename, int flags) = 0;
  52. /** Open a directory on the filesystem
  53. *
  54. * @param dir Destination for the handle to the directory
  55. * @param path Name of the directory to open
  56. * @return 0 on success, negative error code on failure
  57. */
  58. virtual int open(DirHandle **dir, const char *path);
  59. /** Remove a file from the filesystem.
  60. *
  61. * @param path The name of the file to remove.
  62. * @return 0 on success, negative error code on failure
  63. */
  64. virtual int remove(const char *path);
  65. /** Rename a file in the filesystem.
  66. *
  67. * @param path The name of the file to rename.
  68. * @param newpath The name to rename it to
  69. * @return 0 on success, negative error code on failure
  70. */
  71. virtual int rename(const char *path, const char *newpath);
  72. /** Store information about the file in a stat structure
  73. *
  74. * @param path The name of the file to find information about
  75. * @param st The stat buffer to write to
  76. * @return 0 on success, negative error code on failure
  77. */
  78. virtual int stat(const char *path, struct stat *st);
  79. /** Create a directory in the filesystem.
  80. *
  81. * @param path The name of the directory to create.
  82. * @param mode The permissions with which to create the directory
  83. * @return 0 on success, negative error code on failure
  84. */
  85. virtual int mkdir(const char *path, mode_t mode);
  86. /** Store information about the mounted filesystem in a statvfs structure
  87. *
  88. * @param path The name of the file to find information about
  89. * @param buf The stat buffer to write to
  90. * @return 0 on success, negative error code on failure
  91. */
  92. virtual int statvfs(const char *path, struct statvfs *buf);
  93. };
  94. /**@}*/
  95. /**@}*/
  96. } // namespace mbed
  97. #endif
  98. /** @}*/