Nicolas Borla / Mbed OS ROME2_Robot_Firmware
Committer:
boro
Date:
Mon Mar 16 13:12:31 2020 +0000
Revision:
0:4beb2ea291ec
a

Who changed what in which revision?

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