re-enabling serial
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / .svn / text-base / FileSystemLike.h.svn-base
1 /* mbed Microcontroller Library - FileSystemLike
2 * Copyright (c) 2008-2009 ARM Limited. All rights reserved.
3 * sford
4 */
5
6 #ifndef MBED_FILESYSTEMLIKE_H
7 #define MBED_FILESYSTEMLIKE_H
8
9 #ifdef __ARMCC_VERSION
10 # define O_RDONLY 0
11 # define O_WRONLY 1
12 # define O_RDWR 2
13 # define O_CREAT 0x0200
14 # define O_TRUNC 0x0400
15 # define O_APPEND 0x0008
16 typedef int mode_t;
17 #else
18 # include <sys/fcntl.h>
19 #endif
20 #include "Base.h"
21 #include "FileHandle.h"
22 #include "DirHandle.h"
23
24 namespace mbed {
25
26 /* Class FileSystemLike
27 * A filesystem-like object is one that can be used to open files
28 * though it by fopen("/name/filename", mode)
29 *
30 * Implementations must define at least open (the default definitions
31 * of the rest of the functions just return error values).
32 */
33 class FileSystemLike : public Base {
34
35 public:
36
37 /* Constructor FileSystemLike
38 *
39 * Variables
40 * name - The name to use for the filesystem.
41 */
42 FileSystemLike(const char *name) : Base(name) {}
43
44 /* Function open
45 *
46 * Variables
47 * filename - The name of the file to open.
48 * flags - One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with
49 * zero or more of O_CREAT, O_TRUNC, or O_APPEND.
50 * returns - A pointer to a FileHandle object representing the
51 * file on success, or NULL on failure.
52 */
53 virtual FileHandle *open(const char *filename, int flags) = 0;
54
55 /* Function remove
56 * Remove a file from the filesystem.
57 *
58 * Variables
59 * filename - the name of the file to remove.
60 * returns - 0 on success, -1 on failure.
61 */
62 virtual int remove(const char *filename) { return -1; };
63
64 /* Function rename
65 * Rename a file in the filesystem.
66 *
67 * Variables
68 * oldname - the name of the file to rename.
69 * newname - the name to rename it to.
70 * returns - 0 on success, -1 on failure.
71 */
72 virtual int rename(const char *oldname, const char *newname) { return -1; };
73
74 /* Function opendir
75 * Opens a directory in the filesystem and returns a DirHandle
76 * representing the directory stream.
77 *
78 * Variables
79 * name - The name of the directory to open.
80 * returns - A DirHandle representing the directory stream, or
81 * NULL on failure.
82 */
83 virtual DirHandle *opendir(const char *name) { return NULL; };
84
85 /* Function mkdir
86 * Creates a directory in the filesystem.
87 *
88 * Variables
89 * name - The name of the directory to create.
90 * mode - The permissions to create the directory with.
91 * returns - 0 on success, -1 on failure.
92 */
93 virtual int mkdir(const char *name, mode_t mode) { return -1; }
94
95 // TODO other filesystem functions (mkdir, rm, rn, ls etc)
96
97 };
98
99 } // namespace mbed
100
101 #endif