t

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Wed Jun 21 17:46:44 2017 +0100
Revision:
168:e84263d55307
Child:
169:9672193075cf
This updates the lib to the mbed lib v 145

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 168:e84263d55307 1 /* mbed Microcontroller Library
AnnaBridge 168:e84263d55307 2 * Copyright (c) 2006-2013 ARM Limited
AnnaBridge 168:e84263d55307 3 *
AnnaBridge 168:e84263d55307 4 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 168:e84263d55307 5 * you may not use this file except in compliance with the License.
AnnaBridge 168:e84263d55307 6 * You may obtain a copy of the License at
AnnaBridge 168:e84263d55307 7 *
AnnaBridge 168:e84263d55307 8 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 168:e84263d55307 9 *
AnnaBridge 168:e84263d55307 10 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 168:e84263d55307 11 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 168:e84263d55307 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 168:e84263d55307 13 * See the License for the specific language governing permissions and
AnnaBridge 168:e84263d55307 14 * limitations under the License.
AnnaBridge 168:e84263d55307 15 */
AnnaBridge 168:e84263d55307 16 #ifndef MBED_LOCALFILESYSTEM_H
AnnaBridge 168:e84263d55307 17 #define MBED_LOCALFILESYSTEM_H
AnnaBridge 168:e84263d55307 18
AnnaBridge 168:e84263d55307 19 #include "platform/platform.h"
AnnaBridge 168:e84263d55307 20
AnnaBridge 168:e84263d55307 21 #if DEVICE_LOCALFILESYSTEM
AnnaBridge 168:e84263d55307 22
AnnaBridge 168:e84263d55307 23 #include "platform/FileSystemLike.h"
AnnaBridge 168:e84263d55307 24 #include "platform/PlatformMutex.h"
AnnaBridge 168:e84263d55307 25
AnnaBridge 168:e84263d55307 26 namespace mbed {
AnnaBridge 168:e84263d55307 27 /** \addtogroup platform */
AnnaBridge 168:e84263d55307 28 /** @{*/
AnnaBridge 168:e84263d55307 29
AnnaBridge 168:e84263d55307 30 FILEHANDLE local_file_open(const char* name, int flags);
AnnaBridge 168:e84263d55307 31 /** @}*/
AnnaBridge 168:e84263d55307 32
AnnaBridge 168:e84263d55307 33 /**
AnnaBridge 168:e84263d55307 34 * @class LocalFileHandle
AnnaBridge 168:e84263d55307 35 * @ingroup platform
AnnaBridge 168:e84263d55307 36 */
AnnaBridge 168:e84263d55307 37 class LocalFileHandle : public FileHandle {
AnnaBridge 168:e84263d55307 38
AnnaBridge 168:e84263d55307 39 public:
AnnaBridge 168:e84263d55307 40 LocalFileHandle(FILEHANDLE fh);
AnnaBridge 168:e84263d55307 41
AnnaBridge 168:e84263d55307 42 virtual int close();
AnnaBridge 168:e84263d55307 43
AnnaBridge 168:e84263d55307 44 virtual ssize_t write(const void *buffer, size_t length);
AnnaBridge 168:e84263d55307 45
AnnaBridge 168:e84263d55307 46 virtual ssize_t read(void *buffer, size_t length);
AnnaBridge 168:e84263d55307 47
AnnaBridge 168:e84263d55307 48 virtual int isatty();
AnnaBridge 168:e84263d55307 49
AnnaBridge 168:e84263d55307 50 virtual off_t seek(off_t position, int whence);
AnnaBridge 168:e84263d55307 51
AnnaBridge 168:e84263d55307 52 virtual int sync();
AnnaBridge 168:e84263d55307 53
AnnaBridge 168:e84263d55307 54 virtual off_t size();
AnnaBridge 168:e84263d55307 55
AnnaBridge 168:e84263d55307 56 protected:
AnnaBridge 168:e84263d55307 57 virtual void lock();
AnnaBridge 168:e84263d55307 58 virtual void unlock();
AnnaBridge 168:e84263d55307 59 FILEHANDLE _fh;
AnnaBridge 168:e84263d55307 60 int pos;
AnnaBridge 168:e84263d55307 61 PlatformMutex _mutex;
AnnaBridge 168:e84263d55307 62 };
AnnaBridge 168:e84263d55307 63
AnnaBridge 168:e84263d55307 64 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
AnnaBridge 168:e84263d55307 65 *
AnnaBridge 168:e84263d55307 66 * This allows programs to read and write files on the same disk drive that is used to program the
AnnaBridge 168:e84263d55307 67 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
AnnaBridge 168:e84263d55307 68 * read and write files.
AnnaBridge 168:e84263d55307 69 *
AnnaBridge 168:e84263d55307 70 * @note Synchronization level: Thread safe
AnnaBridge 168:e84263d55307 71 *
AnnaBridge 168:e84263d55307 72 * Example:
AnnaBridge 168:e84263d55307 73 * @code
AnnaBridge 168:e84263d55307 74 * #include "mbed.h"
AnnaBridge 168:e84263d55307 75 *
AnnaBridge 168:e84263d55307 76 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
AnnaBridge 168:e84263d55307 77 *
AnnaBridge 168:e84263d55307 78 * int main() {
AnnaBridge 168:e84263d55307 79 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
AnnaBridge 168:e84263d55307 80 * fprintf(fp, "Hello World!");
AnnaBridge 168:e84263d55307 81 * fclose(fp);
AnnaBridge 168:e84263d55307 82 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
AnnaBridge 168:e84263d55307 83 *
AnnaBridge 168:e84263d55307 84 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
AnnaBridge 168:e84263d55307 85 * struct dirent *p;
AnnaBridge 168:e84263d55307 86 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
AnnaBridge 168:e84263d55307 87 * printf("%s\n", p->d_name); // to stdout.
AnnaBridge 168:e84263d55307 88 * }
AnnaBridge 168:e84263d55307 89 * closedir(d);
AnnaBridge 168:e84263d55307 90 * }
AnnaBridge 168:e84263d55307 91 * @endcode
AnnaBridge 168:e84263d55307 92 *
AnnaBridge 168:e84263d55307 93 * @note
AnnaBridge 168:e84263d55307 94 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
AnnaBridge 168:e84263d55307 95 * on the Host computer. This means it is no longer accessible from the Host Computer.
AnnaBridge 168:e84263d55307 96 *
AnnaBridge 168:e84263d55307 97 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
AnnaBridge 168:e84263d55307 98 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
AnnaBridge 168:e84263d55307 99 * @ingroup platform
AnnaBridge 168:e84263d55307 100 */
AnnaBridge 168:e84263d55307 101 class LocalFileSystem : public FileSystemLike {
AnnaBridge 168:e84263d55307 102 // No modifiable state
AnnaBridge 168:e84263d55307 103
AnnaBridge 168:e84263d55307 104 public:
AnnaBridge 168:e84263d55307 105 LocalFileSystem(const char* n) : FileSystemLike(n) {
AnnaBridge 168:e84263d55307 106
AnnaBridge 168:e84263d55307 107 }
AnnaBridge 168:e84263d55307 108
AnnaBridge 168:e84263d55307 109 virtual int open(FileHandle **file, const char *path, int flags);
AnnaBridge 168:e84263d55307 110 virtual int open(DirHandle **dir, const char *name);
AnnaBridge 168:e84263d55307 111 virtual int remove(const char *filename);
AnnaBridge 168:e84263d55307 112 };
AnnaBridge 168:e84263d55307 113
AnnaBridge 168:e84263d55307 114 } // namespace mbed
AnnaBridge 168:e84263d55307 115
AnnaBridge 168:e84263d55307 116 #endif
AnnaBridge 168:e84263d55307 117
AnnaBridge 168:e84263d55307 118 #endif
AnnaBridge 168:e84263d55307 119