Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

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