Dataloger

Committer:
jhon309
Date:
Thu Aug 20 00:37:14 2015 +0000
Revision:
0:666850d06c9f
ok

Who changed what in which revision?

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