Christian Weiß / Mbed 2 deprecated Diplomarbeit_MW_CW

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LocalFileSystem.h Source File

LocalFileSystem.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_LOCALFILESYSTEM_H
00023 #define MBED_LOCALFILESYSTEM_H
00024 
00025 #include "platform.h"
00026 
00027 #if DEVICE_LOCALFILESYSTEM
00028 
00029 #include "FileSystemLike.h"
00030 
00031 namespace mbed {
00032 
00033 FILEHANDLE local_file_open(const char* name, int flags);
00034 
00035 class LocalFileHandle : public FileHandle {
00036 
00037 public:
00038     LocalFileHandle(FILEHANDLE fh);
00039 
00040     virtual int close();
00041 
00042     virtual ssize_t write(const void *buffer, size_t length);
00043 
00044     virtual ssize_t read(void *buffer, size_t length);
00045 
00046     virtual int isatty();
00047 
00048     virtual off_t lseek(off_t position, int whence);
00049 
00050     virtual int fsync();
00051 
00052     virtual off_t flen();
00053 
00054 protected:
00055     FILEHANDLE _fh;
00056     int pos;
00057 };
00058 
00059 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
00060  *
00061  *  This allows programs to read and write files on the same disk drive that is used to program the
00062  *  mbed Microcontroller. Once created, the standard C file access functions are used to open,
00063  *  read and write files.
00064  *
00065  * Example:
00066  * @code
00067  * #include "mbed.h"
00068  *
00069  * LocalFileSystem local("local");               // Create the local filesystem under the name "local"
00070  *
00071  * int main() {
00072  *     FILE *fp = fopen("/local/out.txt", "w");  // Open "out.txt" on the local file system for writing
00073  *     fprintf(fp, "Hello World!");
00074  *     fclose(fp);
00075  *     remove("/local/out.txt");                 // Removes the file "out.txt" from the local file system
00076  *
00077  *     DIR *d = opendir("/local");               // Opens the root directory of the local file system
00078  *     struct dirent *p;
00079  *     while((p = readdir(d)) != NULL) {         // Print the names of the files in the local file system
00080  *       printf("%s\n", p->d_name);              // to stdout.
00081  *     }
00082  *     closedir(d);
00083  * }
00084  * @endcode
00085  *
00086  * @note
00087  *  If the microcontroller program makes an access to the local drive, it will be marked as "removed"
00088  *  on the Host computer. This means it is no longer accessible from the Host Computer.
00089  *
00090  *  The drive will only re-appear when the microcontroller program exists. Note that if the program does
00091  *  not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
00092  */
00093 class LocalFileSystem : public FileSystemLike {
00094 
00095 public:
00096     LocalFileSystem(const char* n) : FileSystemLike(n) {
00097 
00098     }
00099 
00100     virtual FileHandle *open(const char* name, int flags);
00101     virtual int remove(const char *filename);
00102     virtual DirHandle *opendir(const char *name);
00103 };
00104 
00105 } // namespace mbed
00106 
00107 #endif
00108 
00109 #endif
00110