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