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