1 /* mbed Microcontroller Library - FileSystemLike
2 * Copyright (c) 2008-2009 ARM Limited. All rights reserved.
5 #ifndef MBED_FILESYSTEMLIKE_H
6 #define MBED_FILESYSTEMLIKE_H
12 # define O_CREAT 0x0200
13 # define O_TRUNC 0x0400
14 # define O_APPEND 0x0008
17 # include <sys/fcntl.h>
20 #include "FileHandle.h"
21 #include "DirHandle.h"
25 /* Class FileSystemLike
26 * A filesystem-like object is one that can be used to open files
27 * though it by fopen("/name/filename", mode)
29 * Implementations must define at least open (the default definitions
30 * of the rest of the functions just return error values).
32 class FileSystemLike
: public Base
{
36 /* Constructor FileSystemLike
39 * name - The name to use for the filesystem.
41 FileSystemLike(const char *name
) : Base(name
) {}
46 * filename - The name of the file to open.
47 * flags - One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with
48 * zero or more of O_CREAT, O_TRUNC, or O_APPEND.
49 * returns - A pointer to a FileHandle object representing the
50 * file on success, or NULL on failure.
52 virtual FileHandle
*open(const char *filename
, int flags
) = 0;
55 * Remove a file from the filesystem.
58 * filename - the name of the file to remove.
59 * returns - 0 on success, -1 on failure.
61 virtual int remove(const char *filename
) { return -1; };
64 * Rename a file in the filesystem.
67 * oldname - the name of the file to rename.
68 * newname - the name to rename it to.
69 * returns - 0 on success, -1 on failure.
71 virtual int rename(const char *oldname
, const char *newname
) { return -1; };
74 * Opens a directory in the filesystem and returns a DirHandle
75 * representing the directory stream.
78 * name - The name of the directory to open.
79 * returns - A DirHandle representing the directory stream, or
82 virtual DirHandle
*opendir(const char *name
) { return NULL
; };
85 * Creates a directory in the filesystem.
88 * name - The name of the directory to create.
89 * mode - The permissions to create the directory with.
90 * returns - 0 on success, -1 on failure.
92 virtual int mkdir(const char *name
, mode_t mode
) { return -1; }
94 // TODO other filesystem functions (mkdir, rm, rn, ls etc)