Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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.h" 00020 00021 #if DEVICE_LOCALFILESYSTEM 00022 00023 #include "FileSystemLike.h" 00024 #include "PlatformMutex.h" 00025 00026 namespace mbed { 00027 00028 FILEHANDLE local_file_open(const char* name, int flags); 00029 00030 class LocalFileHandle : public FileHandle { 00031 00032 public: 00033 LocalFileHandle(FILEHANDLE fh); 00034 00035 virtual int close(); 00036 00037 virtual ssize_t write(const void *buffer, size_t length); 00038 00039 virtual ssize_t read(void *buffer, size_t length); 00040 00041 virtual int isatty(); 00042 00043 virtual off_t lseek(off_t position, int whence); 00044 00045 virtual int fsync(); 00046 00047 virtual off_t flen(); 00048 00049 protected: 00050 virtual void lock(); 00051 virtual void unlock(); 00052 FILEHANDLE _fh; 00053 int pos; 00054 PlatformMutex _mutex; 00055 }; 00056 00057 /** A filesystem for accessing the local mbed Microcontroller USB disk drive 00058 * 00059 * This allows programs to read and write files on the same disk drive that is used to program the 00060 * mbed Microcontroller. Once created, the standard C file access functions are used to open, 00061 * read and write files. 00062 * 00063 * @Note Synchronization level: Thread safe 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 // No modifiable state 00095 00096 public: 00097 LocalFileSystem(const char* n) : FileSystemLike(n) { 00098 00099 } 00100 00101 virtual FileHandle *open(const char* name, int flags); 00102 virtual int remove(const char *filename); 00103 virtual DirHandle *opendir(const char *name); 00104 }; 00105 00106 } // namespace mbed 00107 00108 #endif 00109 00110 #endif
Generated on Tue Jul 12 2022 22:19:20 by
