Upgrade gcc4mbed project used by Smoothie.
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / LocalFileSystem.h
1 /* mbed Microcontroller Library - LocalFileSystem
2 * Copyright (c) 2008-2009 ARM Limited. All rights reserved.
3 */
4
5 #ifndef MBED_LOCALFILESYSTEM_H
6 #define MBED_LOCALFILESYSTEM_H
7
8 #include "FileSystemLike.h"
9
10 namespace mbed {
11
12 FILEHANDLE local_file_open(const char* name, int flags);
13
14 class LocalFileHandle : public FileHandle {
15
16 public:
17 LocalFileHandle(FILEHANDLE fh);
18
19 virtual int close();
20
21 virtual ssize_t write(const void *buffer, size_t length);
22
23 virtual ssize_t read(void *buffer, size_t length);
24
25 virtual int isatty();
26
27 virtual off_t lseek(off_t position, int whence);
28
29 virtual int fsync();
30
31 virtual off_t flen();
32
33 protected:
34 FILEHANDLE _fh;
35 int pos;
36 };
37
38 /* Class: LocalFileSystem
39 * A filesystem for accessing the local mbed Microcontroller USB disk drive
40 *
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.
44 *
45 * Example:
46 * > #include "mbed.h"
47 * >
48 * > LocalFileSystem local("local"); // Create the local filesystem under the name "local"
49 * >
50 * > int main() {
51 * > FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
52 * > fprintf(fp, "Hello World!");
53 * > fclose(fp);
54 * > remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
55 * >
56 * > DIR *d = opendir("/local"); // Opens the root directory of the local file system
57 * > struct dirent *p;
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.
60 * > }
61 * > closedir(d);
62 * > }
63 *
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.
67 *
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!
70 */
71 class LocalFileSystem : public FileSystemLike {
72
73 public:
74
75 LocalFileSystem(const char* n) : FileSystemLike(n) {
76
77 }
78
79 virtual FileHandle *open(const char* name, int flags);
80 virtual int remove(const char *filename);
81 virtual DirHandle *opendir(const char *name);
82 };
83
84 } // namespace mbed
85
86 #endif