Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of gr-peach-opencv-project-sd-card by
FileSystem.h
00001 00002 /* mbed Microcontroller Library 00003 * Copyright (c) 2006-2013 ARM Limited 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #ifndef MBED_FILESYSTEM_H 00018 #define MBED_FILESYSTEM_H 00019 00020 #include "platform/platform.h" 00021 00022 #include "platform/FileBase.h" 00023 #include "platform/FileHandle.h" 00024 #include "platform/DirHandle.h" 00025 #include "platform/FileSystemLike.h" 00026 #include "BlockDevice.h" 00027 00028 namespace mbed { 00029 /** \addtogroup filesystem */ 00030 /** @{*/ 00031 00032 00033 // Opaque pointer representing files and directories 00034 typedef void *fs_file_t; 00035 typedef void *fs_dir_t; 00036 00037 // Predeclared classes 00038 class Dir; 00039 class File; 00040 00041 /** A filesystem object provides filesystem operations and file operations 00042 * for the File and Dir classes on a block device. 00043 * 00044 * Implementations must provide at minimum file operations and mount 00045 * operations for block devices. 00046 * 00047 * @Note Synchronization level: Set by subclass 00048 */ 00049 class FileSystem : public FileSystemLike { 00050 public: 00051 /** FileSystem lifetime 00052 */ 00053 FileSystem(const char *name = NULL); 00054 virtual ~FileSystem() {} 00055 00056 /** Mounts a filesystem to a block device 00057 * 00058 * @param bd BlockDevice to mount to 00059 * @return 0 on success, negative error code on failure 00060 */ 00061 virtual int mount(BlockDevice *bd) = 0; 00062 00063 /** Unmounts a filesystem from the underlying block device 00064 * 00065 * @return 0 on success, negative error code on failure 00066 */ 00067 virtual int unmount() = 0; 00068 00069 /** Remove a file from the filesystem. 00070 * 00071 * @param path The name of the file to remove. 00072 * @return 0 on success, negative error code on failure 00073 */ 00074 virtual int remove(const char *path); 00075 00076 /** Rename a file in the filesystem. 00077 * 00078 * @param path The name of the file to rename. 00079 * @param newpath The name to rename it to 00080 * @return 0 on success, negative error code on failure 00081 */ 00082 virtual int rename(const char *path, const char *newpath); 00083 00084 /** Store information about the file in a stat structure 00085 * 00086 * @param path The name of the file to find information about 00087 * @param st The stat buffer to write to 00088 * @return 0 on success, negative error code on failure 00089 */ 00090 virtual int stat(const char *path, struct stat *st); 00091 00092 /** Create a directory in the filesystem. 00093 * 00094 * @param path The name of the directory to create. 00095 * @param mode The permissions with which to create the directory 00096 * @return 0 on success, negative error code on failure 00097 */ 00098 virtual int mkdir(const char *path, mode_t mode); 00099 00100 protected: 00101 friend class File; 00102 friend class Dir; 00103 00104 /** Open a file on the filesystem 00105 * 00106 * @param file Destination for the handle to a newly created file 00107 * @param path The name of the file to open 00108 * @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR, 00109 * bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND 00110 * @return 0 on success, negative error code on failure 00111 */ 00112 virtual int file_open(fs_file_t *file, const char *path, int flags) = 0; 00113 00114 /** Close a file 00115 * 00116 * @param file File handle 00117 * return 0 on success, negative error code on failure 00118 */ 00119 virtual int file_close(fs_file_t file) = 0; 00120 00121 /** Read the contents of a file into a buffer 00122 * 00123 * @param file File handle 00124 * @param buffer The buffer to read in to 00125 * @param size The number of bytes to read 00126 * @return The number of bytes read, 0 at end of file, negative error on failure 00127 */ 00128 virtual ssize_t file_read(fs_file_t file, void *buffer, size_t size) = 0; 00129 00130 /** Write the contents of a buffer to a file 00131 * 00132 * @param file File handle 00133 * @param buffer The buffer to write from 00134 * @param size The number of bytes to write 00135 * @return The number of bytes written, negative error on failure 00136 */ 00137 virtual ssize_t file_write(fs_file_t file, const void *buffer, size_t size) = 0; 00138 00139 /** Flush any buffers associated with the file 00140 * 00141 * @param file File handle 00142 * @return 0 on success, negative error code on failure 00143 */ 00144 virtual int file_sync(fs_file_t file); 00145 00146 /** Check if the file in an interactive terminal device 00147 * If so, line buffered behaviour is used by default 00148 * 00149 * @param file File handle 00150 * @return True if the file is a terminal 00151 */ 00152 virtual int file_isatty(fs_file_t file); 00153 00154 /** Move the file position to a given offset from from a given location 00155 * 00156 * @param file File handle 00157 * @param offset The offset from whence to move to 00158 * @param whence The start of where to seek 00159 * SEEK_SET to start from beginning of file, 00160 * SEEK_CUR to start from current position in file, 00161 * SEEK_END to start from end of file 00162 * @return The new offset of the file 00163 */ 00164 virtual off_t file_seek(fs_file_t file, off_t offset, int whence) = 0; 00165 00166 /** Get the file position of the file 00167 * 00168 * @param file File handle 00169 * @return The current offset in the file 00170 */ 00171 virtual off_t file_tell(fs_file_t file); 00172 00173 /** Rewind the file position to the beginning of the file 00174 * 00175 * @param file File handle 00176 * @note This is equivalent to file_seek(file, 0, FS_SEEK_SET) 00177 */ 00178 virtual void file_rewind(fs_file_t file); 00179 00180 /** Get the size of the file 00181 * 00182 * @param file File handle 00183 * @return Size of the file in bytes 00184 */ 00185 virtual off_t file_size(fs_file_t file); 00186 00187 /** Open a directory on the filesystem 00188 * 00189 * @param dir Destination for the handle to the directory 00190 * @param path Name of the directory to open 00191 * @return 0 on success, negative error code on failure 00192 */ 00193 virtual int dir_open(fs_dir_t *dir, const char *path); 00194 00195 /** Close a directory 00196 * 00197 * @param dir Dir handle 00198 * return 0 on success, negative error code on failure 00199 */ 00200 virtual int dir_close(fs_dir_t dir); 00201 00202 /** Read the next directory entry 00203 * 00204 * @param dir Dir handle 00205 * @param ent The directory entry to fill out 00206 * @return 1 on reading a filename, 0 at end of directory, negative error on failure 00207 */ 00208 virtual ssize_t dir_read(fs_dir_t dir, struct dirent *ent); 00209 00210 /** Set the current position of the directory 00211 * 00212 * @param dir Dir handle 00213 * @param offset Offset of the location to seek to, 00214 * must be a value returned from dir_tell 00215 */ 00216 virtual void dir_seek(fs_dir_t dir, off_t offset); 00217 00218 /** Get the current position of the directory 00219 * 00220 * @param dir Dir handle 00221 * @return Position of the directory that can be passed to dir_rewind 00222 */ 00223 virtual off_t dir_tell(fs_dir_t dir); 00224 00225 /** Rewind the current position to the beginning of the directory 00226 * 00227 * @param dir Dir handle 00228 */ 00229 virtual void dir_rewind(fs_dir_t dir); 00230 00231 /** Get the sizeof the directory 00232 * 00233 * @param dir Dir handle 00234 * @return Number of files in the directory 00235 */ 00236 virtual size_t dir_size(fs_dir_t dir); 00237 00238 protected: 00239 // Hooks for FileSystemHandle 00240 virtual int open(FileHandle **file, const char *path, int flags); 00241 virtual int open(DirHandle **dir, const char *path); 00242 }; 00243 00244 00245 /** @}*/ 00246 } // namespace mbed 00247 00248 #endif 00249
Generated on Tue Jul 12 2022 14:46:39 by
