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