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.
inc/FileSystemLike.h@1:dfa0f59e8d2c, 2018-11-15 (annotated)
- Committer:
- Wizo
- Date:
- Thu Nov 15 17:57:01 2018 +0000
- Revision:
- 1:dfa0f59e8d2c
- Parent:
- 0:afeca64a6543
Diplomarbeit_MW_CW
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
martwerl | 0:afeca64a6543 | 1 | /* mbed Microcontroller Library |
martwerl | 0:afeca64a6543 | 2 | * Copyright (c) 2006-2013 ARM Limited |
martwerl | 0:afeca64a6543 | 3 | * |
martwerl | 0:afeca64a6543 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
martwerl | 0:afeca64a6543 | 5 | * of this software and associated documentation files (the "Software"), to deal |
martwerl | 0:afeca64a6543 | 6 | * in the Software without restriction, including without limitation the rights |
martwerl | 0:afeca64a6543 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
martwerl | 0:afeca64a6543 | 8 | * copies of the Software, and to permit persons to whom the Software is |
martwerl | 0:afeca64a6543 | 9 | * furnished to do so, subject to the following conditions: |
martwerl | 0:afeca64a6543 | 10 | * |
martwerl | 0:afeca64a6543 | 11 | * The above copyright notice and this permission notice shall be included in |
martwerl | 0:afeca64a6543 | 12 | * all copies or substantial portions of the Software. |
martwerl | 0:afeca64a6543 | 13 | * |
martwerl | 0:afeca64a6543 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
martwerl | 0:afeca64a6543 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
martwerl | 0:afeca64a6543 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
martwerl | 0:afeca64a6543 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
martwerl | 0:afeca64a6543 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
martwerl | 0:afeca64a6543 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
martwerl | 0:afeca64a6543 | 20 | * SOFTWARE. |
martwerl | 0:afeca64a6543 | 21 | */ |
martwerl | 0:afeca64a6543 | 22 | #ifndef MBED_FILESYSTEMLIKE_H |
martwerl | 0:afeca64a6543 | 23 | #define MBED_FILESYSTEMLIKE_H |
martwerl | 0:afeca64a6543 | 24 | |
martwerl | 0:afeca64a6543 | 25 | #include "platform.h" |
martwerl | 0:afeca64a6543 | 26 | |
martwerl | 0:afeca64a6543 | 27 | #include "FileBase.h" |
martwerl | 0:afeca64a6543 | 28 | #include "FileHandle.h" |
martwerl | 0:afeca64a6543 | 29 | #include "DirHandle.h" |
martwerl | 0:afeca64a6543 | 30 | |
martwerl | 0:afeca64a6543 | 31 | namespace mbed { |
martwerl | 0:afeca64a6543 | 32 | |
martwerl | 0:afeca64a6543 | 33 | /** A filesystem-like object is one that can be used to open files |
martwerl | 0:afeca64a6543 | 34 | * though it by fopen("/name/filename", mode) |
martwerl | 0:afeca64a6543 | 35 | * |
martwerl | 0:afeca64a6543 | 36 | * Implementations must define at least open (the default definitions |
martwerl | 0:afeca64a6543 | 37 | * of the rest of the functions just return error values). |
martwerl | 0:afeca64a6543 | 38 | */ |
martwerl | 0:afeca64a6543 | 39 | class FileSystemLike : public FileBase { |
martwerl | 0:afeca64a6543 | 40 | |
martwerl | 0:afeca64a6543 | 41 | public: |
martwerl | 0:afeca64a6543 | 42 | /** FileSystemLike constructor |
martwerl | 0:afeca64a6543 | 43 | * |
martwerl | 0:afeca64a6543 | 44 | * @param name The name to use for the filesystem. |
martwerl | 0:afeca64a6543 | 45 | */ |
martwerl | 0:afeca64a6543 | 46 | FileSystemLike(const char *name); |
martwerl | 0:afeca64a6543 | 47 | |
martwerl | 0:afeca64a6543 | 48 | virtual ~FileSystemLike(); |
martwerl | 0:afeca64a6543 | 49 | |
martwerl | 0:afeca64a6543 | 50 | static DirHandle *opendir(); |
martwerl | 0:afeca64a6543 | 51 | friend class BaseDirHandle; |
martwerl | 0:afeca64a6543 | 52 | |
martwerl | 0:afeca64a6543 | 53 | /** Opens a file from the filesystem |
martwerl | 0:afeca64a6543 | 54 | * |
martwerl | 0:afeca64a6543 | 55 | * @param filename The name of the file to open. |
martwerl | 0:afeca64a6543 | 56 | * @param flags One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with |
martwerl | 0:afeca64a6543 | 57 | * zero or more of O_CREAT, O_TRUNC, or O_APPEND. |
martwerl | 0:afeca64a6543 | 58 | * |
martwerl | 0:afeca64a6543 | 59 | * @returns |
martwerl | 0:afeca64a6543 | 60 | * A pointer to a FileHandle object representing the |
martwerl | 0:afeca64a6543 | 61 | * file on success, or NULL on failure. |
martwerl | 0:afeca64a6543 | 62 | */ |
martwerl | 0:afeca64a6543 | 63 | virtual FileHandle *open(const char *filename, int flags) = 0; |
martwerl | 0:afeca64a6543 | 64 | |
martwerl | 0:afeca64a6543 | 65 | /** Remove a file from the filesystem. |
martwerl | 0:afeca64a6543 | 66 | * |
martwerl | 0:afeca64a6543 | 67 | * @param filename the name of the file to remove. |
martwerl | 0:afeca64a6543 | 68 | * @param returns 0 on success, -1 on failure. |
martwerl | 0:afeca64a6543 | 69 | */ |
martwerl | 0:afeca64a6543 | 70 | virtual int remove(const char *filename) { return -1; }; |
martwerl | 0:afeca64a6543 | 71 | |
martwerl | 0:afeca64a6543 | 72 | /** Rename a file in the filesystem. |
martwerl | 0:afeca64a6543 | 73 | * |
martwerl | 0:afeca64a6543 | 74 | * @param oldname the name of the file to rename. |
martwerl | 0:afeca64a6543 | 75 | * @param newname the name to rename it to. |
martwerl | 0:afeca64a6543 | 76 | * |
martwerl | 0:afeca64a6543 | 77 | * @returns |
martwerl | 0:afeca64a6543 | 78 | * 0 on success, |
martwerl | 0:afeca64a6543 | 79 | * -1 on failure. |
martwerl | 0:afeca64a6543 | 80 | */ |
martwerl | 0:afeca64a6543 | 81 | virtual int rename(const char *oldname, const char *newname) { return -1; }; |
martwerl | 0:afeca64a6543 | 82 | |
martwerl | 0:afeca64a6543 | 83 | /** Opens a directory in the filesystem and returns a DirHandle |
martwerl | 0:afeca64a6543 | 84 | * representing the directory stream. |
martwerl | 0:afeca64a6543 | 85 | * |
martwerl | 0:afeca64a6543 | 86 | * @param name The name of the directory to open. |
martwerl | 0:afeca64a6543 | 87 | * |
martwerl | 0:afeca64a6543 | 88 | * @returns |
martwerl | 0:afeca64a6543 | 89 | * A DirHandle representing the directory stream, or |
martwerl | 0:afeca64a6543 | 90 | * NULL on failure. |
martwerl | 0:afeca64a6543 | 91 | */ |
martwerl | 0:afeca64a6543 | 92 | virtual DirHandle *opendir(const char *name) { return NULL; }; |
martwerl | 0:afeca64a6543 | 93 | |
martwerl | 0:afeca64a6543 | 94 | /** Creates a directory in the filesystem. |
martwerl | 0:afeca64a6543 | 95 | * |
martwerl | 0:afeca64a6543 | 96 | * @param name The name of the directory to create. |
martwerl | 0:afeca64a6543 | 97 | * @param mode The permissions to create the directory with. |
martwerl | 0:afeca64a6543 | 98 | * |
martwerl | 0:afeca64a6543 | 99 | * @returns |
martwerl | 0:afeca64a6543 | 100 | * 0 on success, |
martwerl | 0:afeca64a6543 | 101 | * -1 on failure. |
martwerl | 0:afeca64a6543 | 102 | */ |
martwerl | 0:afeca64a6543 | 103 | virtual int mkdir(const char *name, mode_t mode) { return -1; } |
martwerl | 0:afeca64a6543 | 104 | |
martwerl | 0:afeca64a6543 | 105 | // TODO other filesystem functions (mkdir, rm, rn, ls etc) |
martwerl | 0:afeca64a6543 | 106 | }; |
martwerl | 0:afeca64a6543 | 107 | |
martwerl | 0:afeca64a6543 | 108 | } // namespace mbed |
martwerl | 0:afeca64a6543 | 109 | |
martwerl | 0:afeca64a6543 | 110 | #endif |
martwerl | 0:afeca64a6543 | 111 |