Opencv 3.1 project on GR-PEACH board
Fork of gr-peach-opencv-project by
features/filesystem/FileSystem.h@170:54ff26da7eb6, 2017-07-04 (annotated)
- Committer:
- thedo
- Date:
- Tue Jul 04 06:23:13 2017 +0000
- Revision:
- 170:54ff26da7eb6
- Parent:
- 166:3a9487d57a5c
project opencv 3.1 on GR PEACH board, no use SD card.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thedo | 166:3a9487d57a5c | 1 | |
thedo | 166:3a9487d57a5c | 2 | /* mbed Microcontroller Library |
thedo | 166:3a9487d57a5c | 3 | * Copyright (c) 2006-2013 ARM Limited |
thedo | 166:3a9487d57a5c | 4 | * |
thedo | 166:3a9487d57a5c | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
thedo | 166:3a9487d57a5c | 6 | * you may not use this file except in compliance with the License. |
thedo | 166:3a9487d57a5c | 7 | * You may obtain a copy of the License at |
thedo | 166:3a9487d57a5c | 8 | * |
thedo | 166:3a9487d57a5c | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
thedo | 166:3a9487d57a5c | 10 | * |
thedo | 166:3a9487d57a5c | 11 | * Unless required by applicable law or agreed to in writing, software |
thedo | 166:3a9487d57a5c | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
thedo | 166:3a9487d57a5c | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
thedo | 166:3a9487d57a5c | 14 | * See the License for the specific language governing permissions and |
thedo | 166:3a9487d57a5c | 15 | * limitations under the License. |
thedo | 166:3a9487d57a5c | 16 | */ |
thedo | 166:3a9487d57a5c | 17 | #ifndef MBED_FILESYSTEM_H |
thedo | 166:3a9487d57a5c | 18 | #define MBED_FILESYSTEM_H |
thedo | 166:3a9487d57a5c | 19 | |
thedo | 166:3a9487d57a5c | 20 | #include "platform/platform.h" |
thedo | 166:3a9487d57a5c | 21 | |
thedo | 166:3a9487d57a5c | 22 | #include "platform/FileBase.h" |
thedo | 166:3a9487d57a5c | 23 | #include "platform/FileHandle.h" |
thedo | 166:3a9487d57a5c | 24 | #include "platform/DirHandle.h" |
thedo | 166:3a9487d57a5c | 25 | #include "platform/FileSystemLike.h" |
thedo | 166:3a9487d57a5c | 26 | #include "BlockDevice.h" |
thedo | 166:3a9487d57a5c | 27 | |
thedo | 166:3a9487d57a5c | 28 | namespace mbed { |
thedo | 166:3a9487d57a5c | 29 | /** \addtogroup filesystem */ |
thedo | 166:3a9487d57a5c | 30 | /** @{*/ |
thedo | 166:3a9487d57a5c | 31 | |
thedo | 166:3a9487d57a5c | 32 | |
thedo | 166:3a9487d57a5c | 33 | // Opaque pointer representing files and directories |
thedo | 166:3a9487d57a5c | 34 | typedef void *fs_file_t; |
thedo | 166:3a9487d57a5c | 35 | typedef void *fs_dir_t; |
thedo | 166:3a9487d57a5c | 36 | |
thedo | 166:3a9487d57a5c | 37 | // Predeclared classes |
thedo | 166:3a9487d57a5c | 38 | class Dir; |
thedo | 166:3a9487d57a5c | 39 | class File; |
thedo | 166:3a9487d57a5c | 40 | |
thedo | 166:3a9487d57a5c | 41 | /** A filesystem object provides filesystem operations and file operations |
thedo | 166:3a9487d57a5c | 42 | * for the File and Dir classes on a block device. |
thedo | 166:3a9487d57a5c | 43 | * |
thedo | 166:3a9487d57a5c | 44 | * Implementations must provide at minimum file operations and mount |
thedo | 166:3a9487d57a5c | 45 | * operations for block devices. |
thedo | 166:3a9487d57a5c | 46 | * |
thedo | 166:3a9487d57a5c | 47 | * @Note Synchronization level: Set by subclass |
thedo | 166:3a9487d57a5c | 48 | */ |
thedo | 166:3a9487d57a5c | 49 | class FileSystem : public FileSystemLike { |
thedo | 166:3a9487d57a5c | 50 | public: |
thedo | 166:3a9487d57a5c | 51 | /** FileSystem lifetime |
thedo | 166:3a9487d57a5c | 52 | */ |
thedo | 166:3a9487d57a5c | 53 | FileSystem(const char *name = NULL); |
thedo | 166:3a9487d57a5c | 54 | virtual ~FileSystem() {} |
thedo | 166:3a9487d57a5c | 55 | |
thedo | 166:3a9487d57a5c | 56 | /** Mounts a filesystem to a block device |
thedo | 166:3a9487d57a5c | 57 | * |
thedo | 166:3a9487d57a5c | 58 | * @param bd BlockDevice to mount to |
thedo | 166:3a9487d57a5c | 59 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 60 | */ |
thedo | 166:3a9487d57a5c | 61 | virtual int mount(BlockDevice *bd) = 0; |
thedo | 166:3a9487d57a5c | 62 | |
thedo | 166:3a9487d57a5c | 63 | /** Unmounts a filesystem from the underlying block device |
thedo | 166:3a9487d57a5c | 64 | * |
thedo | 166:3a9487d57a5c | 65 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 66 | */ |
thedo | 166:3a9487d57a5c | 67 | virtual int unmount() = 0; |
thedo | 166:3a9487d57a5c | 68 | |
thedo | 166:3a9487d57a5c | 69 | /** Remove a file from the filesystem. |
thedo | 166:3a9487d57a5c | 70 | * |
thedo | 166:3a9487d57a5c | 71 | * @param path The name of the file to remove. |
thedo | 166:3a9487d57a5c | 72 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 73 | */ |
thedo | 166:3a9487d57a5c | 74 | virtual int remove(const char *path); |
thedo | 166:3a9487d57a5c | 75 | |
thedo | 166:3a9487d57a5c | 76 | /** Rename a file in the filesystem. |
thedo | 166:3a9487d57a5c | 77 | * |
thedo | 166:3a9487d57a5c | 78 | * @param path The name of the file to rename. |
thedo | 166:3a9487d57a5c | 79 | * @param newpath The name to rename it to |
thedo | 166:3a9487d57a5c | 80 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 81 | */ |
thedo | 166:3a9487d57a5c | 82 | virtual int rename(const char *path, const char *newpath); |
thedo | 166:3a9487d57a5c | 83 | |
thedo | 166:3a9487d57a5c | 84 | /** Store information about the file in a stat structure |
thedo | 166:3a9487d57a5c | 85 | * |
thedo | 166:3a9487d57a5c | 86 | * @param path The name of the file to find information about |
thedo | 166:3a9487d57a5c | 87 | * @param st The stat buffer to write to |
thedo | 166:3a9487d57a5c | 88 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 89 | */ |
thedo | 166:3a9487d57a5c | 90 | virtual int stat(const char *path, struct stat *st); |
thedo | 166:3a9487d57a5c | 91 | |
thedo | 166:3a9487d57a5c | 92 | /** Create a directory in the filesystem. |
thedo | 166:3a9487d57a5c | 93 | * |
thedo | 166:3a9487d57a5c | 94 | * @param path The name of the directory to create. |
thedo | 166:3a9487d57a5c | 95 | * @param mode The permissions with which to create the directory |
thedo | 166:3a9487d57a5c | 96 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 97 | */ |
thedo | 166:3a9487d57a5c | 98 | virtual int mkdir(const char *path, mode_t mode); |
thedo | 166:3a9487d57a5c | 99 | |
thedo | 166:3a9487d57a5c | 100 | protected: |
thedo | 166:3a9487d57a5c | 101 | friend class File; |
thedo | 166:3a9487d57a5c | 102 | friend class Dir; |
thedo | 166:3a9487d57a5c | 103 | |
thedo | 166:3a9487d57a5c | 104 | /** Open a file on the filesystem |
thedo | 166:3a9487d57a5c | 105 | * |
thedo | 166:3a9487d57a5c | 106 | * @param file Destination for the handle to a newly created file |
thedo | 166:3a9487d57a5c | 107 | * @param path The name of the file to open |
thedo | 166:3a9487d57a5c | 108 | * @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR, |
thedo | 166:3a9487d57a5c | 109 | * bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND |
thedo | 166:3a9487d57a5c | 110 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 111 | */ |
thedo | 166:3a9487d57a5c | 112 | virtual int file_open(fs_file_t *file, const char *path, int flags) = 0; |
thedo | 166:3a9487d57a5c | 113 | |
thedo | 166:3a9487d57a5c | 114 | /** Close a file |
thedo | 166:3a9487d57a5c | 115 | * |
thedo | 166:3a9487d57a5c | 116 | * @param file File handle |
thedo | 166:3a9487d57a5c | 117 | * return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 118 | */ |
thedo | 166:3a9487d57a5c | 119 | virtual int file_close(fs_file_t file) = 0; |
thedo | 166:3a9487d57a5c | 120 | |
thedo | 166:3a9487d57a5c | 121 | /** Read the contents of a file into a buffer |
thedo | 166:3a9487d57a5c | 122 | * |
thedo | 166:3a9487d57a5c | 123 | * @param file File handle |
thedo | 166:3a9487d57a5c | 124 | * @param buffer The buffer to read in to |
thedo | 166:3a9487d57a5c | 125 | * @param size The number of bytes to read |
thedo | 166:3a9487d57a5c | 126 | * @return The number of bytes read, 0 at end of file, negative error on failure |
thedo | 166:3a9487d57a5c | 127 | */ |
thedo | 166:3a9487d57a5c | 128 | virtual ssize_t file_read(fs_file_t file, void *buffer, size_t size) = 0; |
thedo | 166:3a9487d57a5c | 129 | |
thedo | 166:3a9487d57a5c | 130 | /** Write the contents of a buffer to a file |
thedo | 166:3a9487d57a5c | 131 | * |
thedo | 166:3a9487d57a5c | 132 | * @param file File handle |
thedo | 166:3a9487d57a5c | 133 | * @param buffer The buffer to write from |
thedo | 166:3a9487d57a5c | 134 | * @param size The number of bytes to write |
thedo | 166:3a9487d57a5c | 135 | * @return The number of bytes written, negative error on failure |
thedo | 166:3a9487d57a5c | 136 | */ |
thedo | 166:3a9487d57a5c | 137 | virtual ssize_t file_write(fs_file_t file, const void *buffer, size_t size) = 0; |
thedo | 166:3a9487d57a5c | 138 | |
thedo | 166:3a9487d57a5c | 139 | /** Flush any buffers associated with the file |
thedo | 166:3a9487d57a5c | 140 | * |
thedo | 166:3a9487d57a5c | 141 | * @param file File handle |
thedo | 166:3a9487d57a5c | 142 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 143 | */ |
thedo | 166:3a9487d57a5c | 144 | virtual int file_sync(fs_file_t file); |
thedo | 166:3a9487d57a5c | 145 | |
thedo | 166:3a9487d57a5c | 146 | /** Check if the file in an interactive terminal device |
thedo | 166:3a9487d57a5c | 147 | * If so, line buffered behaviour is used by default |
thedo | 166:3a9487d57a5c | 148 | * |
thedo | 166:3a9487d57a5c | 149 | * @param file File handle |
thedo | 166:3a9487d57a5c | 150 | * @return True if the file is a terminal |
thedo | 166:3a9487d57a5c | 151 | */ |
thedo | 166:3a9487d57a5c | 152 | virtual int file_isatty(fs_file_t file); |
thedo | 166:3a9487d57a5c | 153 | |
thedo | 166:3a9487d57a5c | 154 | /** Move the file position to a given offset from from a given location |
thedo | 166:3a9487d57a5c | 155 | * |
thedo | 166:3a9487d57a5c | 156 | * @param file File handle |
thedo | 166:3a9487d57a5c | 157 | * @param offset The offset from whence to move to |
thedo | 166:3a9487d57a5c | 158 | * @param whence The start of where to seek |
thedo | 166:3a9487d57a5c | 159 | * SEEK_SET to start from beginning of file, |
thedo | 166:3a9487d57a5c | 160 | * SEEK_CUR to start from current position in file, |
thedo | 166:3a9487d57a5c | 161 | * SEEK_END to start from end of file |
thedo | 166:3a9487d57a5c | 162 | * @return The new offset of the file |
thedo | 166:3a9487d57a5c | 163 | */ |
thedo | 166:3a9487d57a5c | 164 | virtual off_t file_seek(fs_file_t file, off_t offset, int whence) = 0; |
thedo | 166:3a9487d57a5c | 165 | |
thedo | 166:3a9487d57a5c | 166 | /** Get the file position of the file |
thedo | 166:3a9487d57a5c | 167 | * |
thedo | 166:3a9487d57a5c | 168 | * @param file File handle |
thedo | 166:3a9487d57a5c | 169 | * @return The current offset in the file |
thedo | 166:3a9487d57a5c | 170 | */ |
thedo | 166:3a9487d57a5c | 171 | virtual off_t file_tell(fs_file_t file); |
thedo | 166:3a9487d57a5c | 172 | |
thedo | 166:3a9487d57a5c | 173 | /** Rewind the file position to the beginning of the file |
thedo | 166:3a9487d57a5c | 174 | * |
thedo | 166:3a9487d57a5c | 175 | * @param file File handle |
thedo | 166:3a9487d57a5c | 176 | * @note This is equivalent to file_seek(file, 0, FS_SEEK_SET) |
thedo | 166:3a9487d57a5c | 177 | */ |
thedo | 166:3a9487d57a5c | 178 | virtual void file_rewind(fs_file_t file); |
thedo | 166:3a9487d57a5c | 179 | |
thedo | 166:3a9487d57a5c | 180 | /** Get the size of the file |
thedo | 166:3a9487d57a5c | 181 | * |
thedo | 166:3a9487d57a5c | 182 | * @param file File handle |
thedo | 166:3a9487d57a5c | 183 | * @return Size of the file in bytes |
thedo | 166:3a9487d57a5c | 184 | */ |
thedo | 166:3a9487d57a5c | 185 | virtual off_t file_size(fs_file_t file); |
thedo | 166:3a9487d57a5c | 186 | |
thedo | 166:3a9487d57a5c | 187 | /** Open a directory on the filesystem |
thedo | 166:3a9487d57a5c | 188 | * |
thedo | 166:3a9487d57a5c | 189 | * @param dir Destination for the handle to the directory |
thedo | 166:3a9487d57a5c | 190 | * @param path Name of the directory to open |
thedo | 166:3a9487d57a5c | 191 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 192 | */ |
thedo | 166:3a9487d57a5c | 193 | virtual int dir_open(fs_dir_t *dir, const char *path); |
thedo | 166:3a9487d57a5c | 194 | |
thedo | 166:3a9487d57a5c | 195 | /** Close a directory |
thedo | 166:3a9487d57a5c | 196 | * |
thedo | 166:3a9487d57a5c | 197 | * @param dir Dir handle |
thedo | 166:3a9487d57a5c | 198 | * return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 199 | */ |
thedo | 166:3a9487d57a5c | 200 | virtual int dir_close(fs_dir_t dir); |
thedo | 166:3a9487d57a5c | 201 | |
thedo | 166:3a9487d57a5c | 202 | /** Read the next directory entry |
thedo | 166:3a9487d57a5c | 203 | * |
thedo | 166:3a9487d57a5c | 204 | * @param dir Dir handle |
thedo | 166:3a9487d57a5c | 205 | * @param ent The directory entry to fill out |
thedo | 166:3a9487d57a5c | 206 | * @return 1 on reading a filename, 0 at end of directory, negative error on failure |
thedo | 166:3a9487d57a5c | 207 | */ |
thedo | 166:3a9487d57a5c | 208 | virtual ssize_t dir_read(fs_dir_t dir, struct dirent *ent); |
thedo | 166:3a9487d57a5c | 209 | |
thedo | 166:3a9487d57a5c | 210 | /** Set the current position of the directory |
thedo | 166:3a9487d57a5c | 211 | * |
thedo | 166:3a9487d57a5c | 212 | * @param dir Dir handle |
thedo | 166:3a9487d57a5c | 213 | * @param offset Offset of the location to seek to, |
thedo | 166:3a9487d57a5c | 214 | * must be a value returned from dir_tell |
thedo | 166:3a9487d57a5c | 215 | */ |
thedo | 166:3a9487d57a5c | 216 | virtual void dir_seek(fs_dir_t dir, off_t offset); |
thedo | 166:3a9487d57a5c | 217 | |
thedo | 166:3a9487d57a5c | 218 | /** Get the current position of the directory |
thedo | 166:3a9487d57a5c | 219 | * |
thedo | 166:3a9487d57a5c | 220 | * @param dir Dir handle |
thedo | 166:3a9487d57a5c | 221 | * @return Position of the directory that can be passed to dir_rewind |
thedo | 166:3a9487d57a5c | 222 | */ |
thedo | 166:3a9487d57a5c | 223 | virtual off_t dir_tell(fs_dir_t dir); |
thedo | 166:3a9487d57a5c | 224 | |
thedo | 166:3a9487d57a5c | 225 | /** Rewind the current position to the beginning of the directory |
thedo | 166:3a9487d57a5c | 226 | * |
thedo | 166:3a9487d57a5c | 227 | * @param dir Dir handle |
thedo | 166:3a9487d57a5c | 228 | */ |
thedo | 166:3a9487d57a5c | 229 | virtual void dir_rewind(fs_dir_t dir); |
thedo | 166:3a9487d57a5c | 230 | |
thedo | 166:3a9487d57a5c | 231 | /** Get the sizeof the directory |
thedo | 166:3a9487d57a5c | 232 | * |
thedo | 166:3a9487d57a5c | 233 | * @param dir Dir handle |
thedo | 166:3a9487d57a5c | 234 | * @return Number of files in the directory |
thedo | 166:3a9487d57a5c | 235 | */ |
thedo | 166:3a9487d57a5c | 236 | virtual size_t dir_size(fs_dir_t dir); |
thedo | 166:3a9487d57a5c | 237 | |
thedo | 166:3a9487d57a5c | 238 | protected: |
thedo | 166:3a9487d57a5c | 239 | // Hooks for FileSystemHandle |
thedo | 166:3a9487d57a5c | 240 | virtual int open(FileHandle **file, const char *path, int flags); |
thedo | 166:3a9487d57a5c | 241 | virtual int open(DirHandle **dir, const char *path); |
thedo | 166:3a9487d57a5c | 242 | }; |
thedo | 166:3a9487d57a5c | 243 | |
thedo | 166:3a9487d57a5c | 244 | |
thedo | 166:3a9487d57a5c | 245 | /** @}*/ |
thedo | 166:3a9487d57a5c | 246 | } // namespace mbed |
thedo | 166:3a9487d57a5c | 247 | |
thedo | 166:3a9487d57a5c | 248 | #endif |
thedo | 166:3a9487d57a5c | 249 |