BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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