mbed source development branch
Fork of mbed-dev by
Embed:
(wiki syntax)
Show/hide line numbers
LocalFileSystem.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef MBED_LOCALFILESYSTEM_H 00017 #define MBED_LOCALFILESYSTEM_H 00018 00019 #include "platform/platform.h" 00020 00021 #if DEVICE_LOCALFILESYSTEM 00022 00023 #include "drivers/FileSystemLike.h" 00024 #include "platform/PlatformMutex.h" 00025 00026 namespace mbed { 00027 /** \addtogroup drivers */ 00028 /** @{*/ 00029 00030 FILEHANDLE local_file_open(const char* name, int flags); 00031 00032 class LocalFileHandle : public FileHandle { 00033 00034 public: 00035 LocalFileHandle(FILEHANDLE fh); 00036 00037 virtual int close(); 00038 00039 virtual ssize_t write(const void *buffer, size_t length); 00040 00041 virtual ssize_t read(void *buffer, size_t length); 00042 00043 virtual int isatty(); 00044 00045 virtual off_t lseek(off_t position, int whence); 00046 00047 virtual int fsync(); 00048 00049 virtual off_t flen(); 00050 00051 protected: 00052 virtual void lock(); 00053 virtual void unlock(); 00054 FILEHANDLE _fh; 00055 int pos; 00056 PlatformMutex _mutex; 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 * @Note Synchronization level: Thread safe 00066 * 00067 * Example: 00068 * @code 00069 * #include "mbed.h" 00070 * 00071 * LocalFileSystem local("local"); // Create the local filesystem under the name "local" 00072 * 00073 * int main() { 00074 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing 00075 * fprintf(fp, "Hello World!"); 00076 * fclose(fp); 00077 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system 00078 * 00079 * DIR *d = opendir("/local"); // Opens the root directory of the local file system 00080 * struct dirent *p; 00081 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system 00082 * printf("%s\n", p->d_name); // to stdout. 00083 * } 00084 * closedir(d); 00085 * } 00086 * @endcode 00087 * 00088 * @note 00089 * If the microcontroller program makes an access to the local drive, it will be marked as "removed" 00090 * on the Host computer. This means it is no longer accessible from the Host Computer. 00091 * 00092 * The drive will only re-appear when the microcontroller program exists. Note that if the program does 00093 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again! 00094 */ 00095 class LocalFileSystem : public FileSystemLike { 00096 // No modifiable state 00097 00098 public: 00099 LocalFileSystem(const char* n) : FileSystemLike(n) { 00100 00101 } 00102 00103 virtual FileHandle *open(const char* name, int flags); 00104 virtual int remove(const char *filename); 00105 virtual DirHandle *opendir(const char *name); 00106 }; 00107 00108 } // namespace mbed 00109 00110 #endif 00111 00112 #endif 00113 00114 /** @}*/
Generated on Tue Jul 12 2022 19:34:53 by 1.7.2