1 /* mbed Microcontroller Library - LocalFileSystem
2 * Copyright (c) 2008-2009 ARM Limited. All rights reserved.
5 #ifndef MBED_LOCALFILESYSTEM_H
6 #define MBED_LOCALFILESYSTEM_H
8 #include "FileSystemLike.h"
12 FILEHANDLE
local_file_open(const char* name
, int flags
);
14 class LocalFileHandle
: public FileHandle
{
17 LocalFileHandle(FILEHANDLE fh
);
21 virtual ssize_t
write(const void *buffer
, size_t length
);
23 virtual ssize_t
read(void *buffer
, size_t length
);
27 virtual off_t
lseek(off_t position
, int whence
);
38 /* Class: LocalFileSystem
39 * A filesystem for accessing the local mbed Microcontroller USB disk drive
41 * This allows programs to read and write files on the same disk drive that is used to program the
42 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
43 * read and write files.
48 * > LocalFileSystem local("local"); // Create the local filesystem under the name "local"
51 * > FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
52 * > fprintf(fp, "Hello World!");
54 * > remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
56 * > DIR *d = opendir("/local"); // Opens the root directory of the local file system
58 * > while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
59 * > printf("%s\n", p->d_name); // to stdout.
64 * Implementation Notes:
65 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
66 * on the Host computer. This means it is no longer accessible from the Host Computer.
68 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
69 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
71 class LocalFileSystem
: public FileSystemLike
{
75 LocalFileSystem(const char* n
) : FileSystemLike(n
) {
79 virtual FileHandle
*open(const char* name
, int flags
);
80 virtual int remove(const char *filename
);
81 virtual DirHandle
*opendir(const char *name
);