mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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