mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
LocalFileSystem.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #ifndef MBED_LOCALFILESYSTEM_H 00018 #define MBED_LOCALFILESYSTEM_H 00019 00020 #include "platform/platform.h" 00021 00022 #if DEVICE_LOCALFILESYSTEM 00023 00024 #include "platform/FileSystemLike.h" 00025 #include "platform/PlatformMutex.h" 00026 #include "platform/NonCopyable.h" 00027 00028 namespace mbed { 00029 /** \addtogroup platform */ 00030 /** @{*/ 00031 /** 00032 * \defgroup platform_LocalFileSystem LocalFileSystem functions 00033 * @{ 00034 */ 00035 00036 FILEHANDLE local_file_open(const char *name, int flags); 00037 00038 /** 00039 * @class LocalFileHandle 00040 * @ingroup platform 00041 */ 00042 class LocalFileHandle : public FileHandle, private NonCopyable<LocalFileHandle> { 00043 00044 public: 00045 LocalFileHandle(FILEHANDLE fh); 00046 00047 virtual int close(); 00048 00049 virtual ssize_t write(const void *buffer, size_t length); 00050 00051 virtual ssize_t read(void *buffer, size_t length); 00052 00053 virtual int isatty(); 00054 00055 virtual off_t seek(off_t position, int whence); 00056 00057 virtual int sync(); 00058 00059 virtual off_t size(); 00060 00061 protected: 00062 virtual void lock(); 00063 virtual void unlock(); 00064 FILEHANDLE _fh; 00065 int pos; 00066 PlatformMutex _mutex; 00067 }; 00068 00069 /** A filesystem for accessing the local mbed Microcontroller USB disk drive 00070 * 00071 * This allows programs to read and write files on the same disk drive that is used to program the 00072 * mbed Microcontroller. Once created, the standard C file access functions are used to open, 00073 * read and write files. 00074 * 00075 * @note Synchronization level: Thread safe 00076 * 00077 * Example: 00078 * @code 00079 * #include "mbed.h" 00080 * 00081 * LocalFileSystem local("local"); // Create the local filesystem under the name "local" 00082 * 00083 * int main() { 00084 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing 00085 * fprintf(fp, "Hello World!"); 00086 * fclose(fp); 00087 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system 00088 * 00089 * DIR *d = opendir("/local"); // Opens the root directory of the local file system 00090 * struct dirent *p; 00091 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system 00092 * printf("%s\n", p->d_name); // to stdout. 00093 * } 00094 * closedir(d); 00095 * } 00096 * @endcode 00097 * 00098 * @note 00099 * If the microcontroller program makes an access to the local drive, it will be marked as "removed" 00100 * on the Host computer. This means it is no longer accessible from the Host Computer. 00101 * 00102 * The drive will only re-appear when the microcontroller program exists. Note that if the program does 00103 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again! 00104 * @ingroup platform 00105 */ 00106 class LocalFileSystem : public FileSystemLike, private NonCopyable<LocalFileSystem> { 00107 // No modifiable state 00108 00109 public: 00110 LocalFileSystem(const char *n) : FileSystemLike(n) 00111 { 00112 00113 } 00114 00115 virtual int open(FileHandle **file, const char *path, int flags); 00116 virtual int open(DirHandle **dir, const char *name); 00117 virtual int remove(const char *filename); 00118 }; 00119 00120 /**@}*/ 00121 00122 /**@}*/ 00123 00124 } // namespace mbed 00125 00126 #endif 00127 00128 #endif 00129
Generated on Tue Jul 12 2022 20:41:15 by 1.7.2