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