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