CDY version that shares functionality with Counter

Dependencies:   SDFileSystem_HelloWorld mbed FATFileSystem

Committer:
Charles David Young
Date:
Sun Nov 04 18:44:51 2018 -0700
Revision:
0:aa13e1c335cd
create new repo for show2me

Who changed what in which revision?

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