printer

Dependents:   Good_Serial_HelloWorld_Mbed

Fork of mbed by gokmen ascioglu

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LocalFileSystem.h Source File

LocalFileSystem.h

00001 /* mbed Microcontroller Library - LocalFileSystem
00002  * Copyright (c) 2008-2009 ARM Limited. All rights reserved.
00003  */ 
00004  
00005 #ifndef MBED_LOCALFILESYSTEM_H
00006 #define MBED_LOCALFILESYSTEM_H
00007 
00008 #include "FileSystemLike.h"
00009 
00010 namespace mbed {
00011 
00012 FILEHANDLE local_file_open(const char* name, int flags);
00013 
00014 class LocalFileHandle : public FileHandle {
00015 
00016 public:
00017     LocalFileHandle(FILEHANDLE fh);
00018     
00019     virtual int close();
00020     
00021     virtual ssize_t write(const void *buffer, size_t length);
00022     
00023     virtual ssize_t read(void *buffer, size_t length);
00024     
00025     virtual int isatty();
00026     
00027     virtual off_t lseek(off_t position, int whence);
00028     
00029     virtual int fsync();
00030     
00031     virtual off_t flen();
00032 
00033 protected:
00034     FILEHANDLE _fh;
00035     int pos;
00036 };
00037 
00038 /* Class: LocalFileSystem
00039  *  A filesystem for accessing the local mbed Microcontroller USB disk drive 
00040  *
00041  *  This allows programs to read and write files on the same disk drive that is used to program the 
00042  *  mbed Microcontroller. Once created, the standard C file access functions are used to open, 
00043  *  read and write files.
00044  *
00045  * Example:
00046  * > #include "mbed.h"
00047  * >
00048  * > LocalFileSystem local("local");             // Create the local filesystem under the name "local"
00049  * >
00050  * > int main() {
00051  * >     FILE *fp = fopen("/local/out.txt", "w");  // Open "out.txt" on the local file system for writing
00052  * >     fprintf(fp, "Hello World!");              
00053  * >     fclose(fp);                               
00054  * >     remove("/local/out.txt");                 // Removes the file "out.txt" from the local file system
00055  * >
00056  * >     DIR *d = opendir("/local");               // Opens the root directory of the local file system
00057  * >     struct dirent *p;
00058  * >     while((p = readdir(d)) != NULL) {         // Print the names of the files in the local file system
00059  * >       printf("%s\n", p->d_name);              // to stdout.
00060  * >     }
00061  * >     closedir(d);
00062  * > }
00063  *
00064  * Implementation Notes:
00065  *  If the microcontroller program makes an access to the local drive, it will be marked as "removed"
00066  *  on the Host computer. This means it is no longer accessible from the Host Computer.
00067  *
00068  *  The drive will only re-appear when the microcontroller program exists. Note that if the program does
00069  *  not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
00070  */
00071 class LocalFileSystem : public FileSystemLike {
00072 
00073 public:
00074 
00075     LocalFileSystem(const char* n) : FileSystemLike(n) {
00076 
00077     }
00078     
00079     virtual FileHandle *open(const char* name, int flags);
00080     virtual int remove(const char *filename);
00081     virtual DirHandle *opendir(const char *name);
00082 };
00083 
00084 } // namespace mbed
00085 
00086 #endif