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