This fork captures the mbed lib v125 for ease of integration into older projects.
Fork of mbed-dev by
api/FileSystemLike.h@187:92cbb9eec47b, 2018-07-20 (annotated)
- Committer:
- apluscw
- Date:
- Fri Jul 20 21:24:42 2018 +0000
- Revision:
- 187:92cbb9eec47b
Mbed library with source code from mbed lib v125. Posted to ease integration with some older projects.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
apluscw | 187:92cbb9eec47b | 1 | /* mbed Microcontroller Library |
apluscw | 187:92cbb9eec47b | 2 | * Copyright (c) 2006-2013 ARM Limited |
apluscw | 187:92cbb9eec47b | 3 | * |
apluscw | 187:92cbb9eec47b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
apluscw | 187:92cbb9eec47b | 5 | * you may not use this file except in compliance with the License. |
apluscw | 187:92cbb9eec47b | 6 | * You may obtain a copy of the License at |
apluscw | 187:92cbb9eec47b | 7 | * |
apluscw | 187:92cbb9eec47b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
apluscw | 187:92cbb9eec47b | 9 | * |
apluscw | 187:92cbb9eec47b | 10 | * Unless required by applicable law or agreed to in writing, software |
apluscw | 187:92cbb9eec47b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
apluscw | 187:92cbb9eec47b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
apluscw | 187:92cbb9eec47b | 13 | * See the License for the specific language governing permissions and |
apluscw | 187:92cbb9eec47b | 14 | * limitations under the License. |
apluscw | 187:92cbb9eec47b | 15 | */ |
apluscw | 187:92cbb9eec47b | 16 | #ifndef MBED_FILESYSTEMLIKE_H |
apluscw | 187:92cbb9eec47b | 17 | #define MBED_FILESYSTEMLIKE_H |
apluscw | 187:92cbb9eec47b | 18 | |
apluscw | 187:92cbb9eec47b | 19 | #include "platform.h" |
apluscw | 187:92cbb9eec47b | 20 | |
apluscw | 187:92cbb9eec47b | 21 | #include "FileBase.h" |
apluscw | 187:92cbb9eec47b | 22 | #include "FileHandle.h" |
apluscw | 187:92cbb9eec47b | 23 | #include "DirHandle.h" |
apluscw | 187:92cbb9eec47b | 24 | |
apluscw | 187:92cbb9eec47b | 25 | namespace mbed { |
apluscw | 187:92cbb9eec47b | 26 | |
apluscw | 187:92cbb9eec47b | 27 | /** A filesystem-like object is one that can be used to open files |
apluscw | 187:92cbb9eec47b | 28 | * though it by fopen("/name/filename", mode) |
apluscw | 187:92cbb9eec47b | 29 | * |
apluscw | 187:92cbb9eec47b | 30 | * Implementations must define at least open (the default definitions |
apluscw | 187:92cbb9eec47b | 31 | * of the rest of the functions just return error values). |
apluscw | 187:92cbb9eec47b | 32 | * |
apluscw | 187:92cbb9eec47b | 33 | * @Note Synchronization level: Set by subclass |
apluscw | 187:92cbb9eec47b | 34 | */ |
apluscw | 187:92cbb9eec47b | 35 | class FileSystemLike : public FileBase { |
apluscw | 187:92cbb9eec47b | 36 | |
apluscw | 187:92cbb9eec47b | 37 | public: |
apluscw | 187:92cbb9eec47b | 38 | /** FileSystemLike constructor |
apluscw | 187:92cbb9eec47b | 39 | * |
apluscw | 187:92cbb9eec47b | 40 | * @param name The name to use for the filesystem. |
apluscw | 187:92cbb9eec47b | 41 | */ |
apluscw | 187:92cbb9eec47b | 42 | FileSystemLike(const char *name); |
apluscw | 187:92cbb9eec47b | 43 | |
apluscw | 187:92cbb9eec47b | 44 | virtual ~FileSystemLike(); |
apluscw | 187:92cbb9eec47b | 45 | |
apluscw | 187:92cbb9eec47b | 46 | static DirHandle *opendir(); |
apluscw | 187:92cbb9eec47b | 47 | friend class BaseDirHandle; |
apluscw | 187:92cbb9eec47b | 48 | |
apluscw | 187:92cbb9eec47b | 49 | /** Opens a file from the filesystem |
apluscw | 187:92cbb9eec47b | 50 | * |
apluscw | 187:92cbb9eec47b | 51 | * @param filename The name of the file to open. |
apluscw | 187:92cbb9eec47b | 52 | * @param flags One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with |
apluscw | 187:92cbb9eec47b | 53 | * zero or more of O_CREAT, O_TRUNC, or O_APPEND. |
apluscw | 187:92cbb9eec47b | 54 | * |
apluscw | 187:92cbb9eec47b | 55 | * @returns |
apluscw | 187:92cbb9eec47b | 56 | * A pointer to a FileHandle object representing the |
apluscw | 187:92cbb9eec47b | 57 | * file on success, or NULL on failure. |
apluscw | 187:92cbb9eec47b | 58 | */ |
apluscw | 187:92cbb9eec47b | 59 | virtual FileHandle *open(const char *filename, int flags) = 0; |
apluscw | 187:92cbb9eec47b | 60 | |
apluscw | 187:92cbb9eec47b | 61 | /** Remove a file from the filesystem. |
apluscw | 187:92cbb9eec47b | 62 | * |
apluscw | 187:92cbb9eec47b | 63 | * @param filename the name of the file to remove. |
apluscw | 187:92cbb9eec47b | 64 | * @param returns 0 on success, -1 on failure. |
apluscw | 187:92cbb9eec47b | 65 | */ |
apluscw | 187:92cbb9eec47b | 66 | virtual int remove(const char *filename) { (void) filename; return -1; }; |
apluscw | 187:92cbb9eec47b | 67 | |
apluscw | 187:92cbb9eec47b | 68 | /** Rename a file in the filesystem. |
apluscw | 187:92cbb9eec47b | 69 | * |
apluscw | 187:92cbb9eec47b | 70 | * @param oldname the name of the file to rename. |
apluscw | 187:92cbb9eec47b | 71 | * @param newname the name to rename it to. |
apluscw | 187:92cbb9eec47b | 72 | * |
apluscw | 187:92cbb9eec47b | 73 | * @returns |
apluscw | 187:92cbb9eec47b | 74 | * 0 on success, |
apluscw | 187:92cbb9eec47b | 75 | * -1 on failure. |
apluscw | 187:92cbb9eec47b | 76 | */ |
apluscw | 187:92cbb9eec47b | 77 | virtual int rename(const char *oldname, const char *newname) { (void) oldname, (void) newname; return -1; }; |
apluscw | 187:92cbb9eec47b | 78 | |
apluscw | 187:92cbb9eec47b | 79 | /** Opens a directory in the filesystem and returns a DirHandle |
apluscw | 187:92cbb9eec47b | 80 | * representing the directory stream. |
apluscw | 187:92cbb9eec47b | 81 | * |
apluscw | 187:92cbb9eec47b | 82 | * @param name The name of the directory to open. |
apluscw | 187:92cbb9eec47b | 83 | * |
apluscw | 187:92cbb9eec47b | 84 | * @returns |
apluscw | 187:92cbb9eec47b | 85 | * A DirHandle representing the directory stream, or |
apluscw | 187:92cbb9eec47b | 86 | * NULL on failure. |
apluscw | 187:92cbb9eec47b | 87 | */ |
apluscw | 187:92cbb9eec47b | 88 | virtual DirHandle *opendir(const char *name) { (void) name; return NULL; }; |
apluscw | 187:92cbb9eec47b | 89 | |
apluscw | 187:92cbb9eec47b | 90 | /** Creates a directory in the filesystem. |
apluscw | 187:92cbb9eec47b | 91 | * |
apluscw | 187:92cbb9eec47b | 92 | * @param name The name of the directory to create. |
apluscw | 187:92cbb9eec47b | 93 | * @param mode The permissions to create the directory with. |
apluscw | 187:92cbb9eec47b | 94 | * |
apluscw | 187:92cbb9eec47b | 95 | * @returns |
apluscw | 187:92cbb9eec47b | 96 | * 0 on success, |
apluscw | 187:92cbb9eec47b | 97 | * -1 on failure. |
apluscw | 187:92cbb9eec47b | 98 | */ |
apluscw | 187:92cbb9eec47b | 99 | virtual int mkdir(const char *name, mode_t mode) { (void) name, (void) mode; return -1; } |
apluscw | 187:92cbb9eec47b | 100 | |
apluscw | 187:92cbb9eec47b | 101 | // TODO other filesystem functions (mkdir, rm, rn, ls etc) |
apluscw | 187:92cbb9eec47b | 102 | }; |
apluscw | 187:92cbb9eec47b | 103 | |
apluscw | 187:92cbb9eec47b | 104 | } // namespace mbed |
apluscw | 187:92cbb9eec47b | 105 | |
apluscw | 187:92cbb9eec47b | 106 | #endif |