1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef MBED_LOCALFILESYSTEM_H
17 #define MBED_LOCALFILESYSTEM_H
21 #if DEVICE_LOCALFILESYSTEM
23 #include "FileSystemLike.h"
27 FILEHANDLE local_file_open(const char* name, int flags);
29 class LocalFileHandle : public FileHandle {
32 LocalFileHandle(FILEHANDLE fh);
36 virtual ssize_t write(const void *buffer, size_t length);
38 virtual ssize_t read(void *buffer, size_t length);
42 virtual off_t lseek(off_t position, int whence);
53 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
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.
63 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
66 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
67 * fprintf(fp, "Hello World!");
69 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
71 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
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.
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.
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!
87 class LocalFileSystem : public FileSystemLike {
90 LocalFileSystem(const char* n) : FileSystemLike(n) {
94 virtual FileHandle *open(const char* name, int flags);
95 virtual int remove(const char *filename);
96 virtual DirHandle *opendir(const char *name);