TUKS MCU Introductory course / TUKS-COURSE-TIMER
Committer:
elmot
Date:
Fri Feb 24 21:13:56 2017 +0000
Revision:
1:d0dfbce63a89
Ready-to-copy

Who changed what in which revision?

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