Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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