Christian Weiß / Mbed 2 deprecated Diplomarbeit_MW_CW

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FileSystemLike.h Source File

FileSystemLike.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00020  * SOFTWARE.
00021  */
00022 #ifndef MBED_FILESYSTEMLIKE_H
00023 #define MBED_FILESYSTEMLIKE_H
00024 
00025 #include "platform.h"
00026 
00027 #include "FileBase.h"
00028 #include "FileHandle.h"
00029 #include "DirHandle.h"
00030 
00031 namespace mbed {
00032 
00033 /** A filesystem-like object is one that can be used to open files
00034  *  though it by fopen("/name/filename", mode)
00035  *
00036  *  Implementations must define at least open (the default definitions
00037  *  of the rest of the functions just return error values).
00038  */
00039 class FileSystemLike : public FileBase {
00040 
00041 public:
00042     /** FileSystemLike constructor
00043      *
00044      *  @param name The name to use for the filesystem.
00045      */
00046     FileSystemLike(const char *name);
00047 
00048     virtual ~FileSystemLike();
00049 
00050     static DirHandle *opendir();
00051     friend class BaseDirHandle;
00052 
00053     /** Opens a file from the filesystem
00054      *
00055      *  @param filename The name of the file to open.
00056      *  @param flags One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with
00057      *    zero or more of O_CREAT, O_TRUNC, or O_APPEND.
00058      *
00059      *  @returns
00060      *    A pointer to a FileHandle object representing the
00061      *   file on success, or NULL on failure.
00062      */
00063     virtual FileHandle *open(const char *filename, int flags) = 0;
00064 
00065     /** Remove a file from the filesystem.
00066      *
00067      *  @param filename the name of the file to remove.
00068      *  @param returns 0 on success, -1 on failure.
00069      */
00070     virtual int remove(const char *filename) { return -1; };
00071 
00072     /** Rename a file in the filesystem.
00073      *
00074      *  @param oldname the name of the file to rename.
00075      *  @param newname the name to rename it to.
00076      *
00077      *  @returns
00078      *    0 on success,
00079      *   -1 on failure.
00080      */
00081     virtual int rename(const char *oldname, const char *newname) { return -1; };
00082 
00083     /** Opens a directory in the filesystem and returns a DirHandle
00084      *   representing the directory stream.
00085      *
00086      *  @param name The name of the directory to open.
00087      *
00088      *  @returns
00089      *    A DirHandle representing the directory stream, or
00090      *   NULL on failure.
00091      */
00092     virtual DirHandle *opendir(const char *name) { return NULL; };
00093 
00094     /** Creates a directory in the filesystem.
00095      *
00096      *  @param name The name of the directory to create.
00097      *  @param mode The permissions to create the directory with.
00098      *
00099      *  @returns
00100      *    0 on success,
00101      *   -1 on failure.
00102      */
00103     virtual int mkdir(const char *name, mode_t mode) { return -1; }
00104 
00105     // TODO other filesystem functions (mkdir, rm, rn, ls etc)
00106 };
00107 
00108 } // namespace mbed
00109 
00110 #endif
00111