| 1 | /* mbed Microcontroller Library - FileSystemLike |
|---|
| 2 | * Copyright (c) 2008-2009 ARM Limited. All rights reserved. |
|---|
| 3 | */ |
|---|
| 4 | |
|---|
| 5 | #ifndef MBED_FILESYSTEMLIKE_H |
|---|
| 6 | #define MBED_FILESYSTEMLIKE_H |
|---|
| 7 | |
|---|
| 8 | #ifdef __ARMCC_VERSION |
|---|
| 9 | # define O_RDONLY 0 |
|---|
| 10 | # define O_WRONLY 1 |
|---|
| 11 | # define O_RDWR 2 |
|---|
| 12 | # define O_CREAT 0x0200 |
|---|
| 13 | # define O_TRUNC 0x0400 |
|---|
| 14 | # define O_APPEND 0x0008 |
|---|
| 15 | typedef int mode_t; |
|---|
| 16 | #else |
|---|
| 17 | # include <sys/fcntl.h> |
|---|
| 18 | #endif |
|---|
| 19 | #include "Base.h" |
|---|
| 20 | #include "FileHandle.h" |
|---|
| 21 | #include "DirHandle.h" |
|---|
| 22 | |
|---|
| 23 | namespace mbed { |
|---|
| 24 | |
|---|
| 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) |
|---|
| 28 | * |
|---|
| 29 | * Implementations must define at least open (the default definitions |
|---|
| 30 | * of the rest of the functions just return error values). |
|---|
| 31 | */ |
|---|
| 32 | class FileSystemLike : public Base { |
|---|
| 33 | |
|---|
| 34 | public: |
|---|
| 35 | |
|---|
| 36 | /* Constructor FileSystemLike |
|---|
| 37 | * |
|---|
| 38 | * Variables |
|---|
| 39 | * name - The name to use for the filesystem. |
|---|
| 40 | */ |
|---|
| 41 | FileSystemLike(const char *name) : Base(name) {} |
|---|
| 42 | |
|---|
| 43 | /* Function open |
|---|
| 44 | * |
|---|
| 45 | * Variables |
|---|
| 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. |
|---|
| 51 | */ |
|---|
| 52 | virtual FileHandle *open(const char *filename, int flags) = 0; |
|---|
| 53 | |
|---|
| 54 | /* Function remove |
|---|
| 55 | * Remove a file from the filesystem. |
|---|
| 56 | * |
|---|
| 57 | * Variables |
|---|
| 58 | * filename - the name of the file to remove. |
|---|
| 59 | * returns - 0 on success, -1 on failure. |
|---|
| 60 | */ |
|---|
| 61 | virtual int remove(const char *filename) { return -1; }; |
|---|
| 62 | |
|---|
| 63 | /* Function rename |
|---|
| 64 | * Rename a file in the filesystem. |
|---|
| 65 | * |
|---|
| 66 | * Variables |
|---|
| 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. |
|---|
| 70 | */ |
|---|
| 71 | virtual int rename(const char *oldname, const char *newname) { return -1; }; |
|---|
| 72 | |
|---|
| 73 | /* Function opendir |
|---|
| 74 | * Opens a directory in the filesystem and returns a DirHandle |
|---|
| 75 | * representing the directory stream. |
|---|
| 76 | * |
|---|
| 77 | * Variables |
|---|
| 78 | * name - The name of the directory to open. |
|---|
| 79 | * returns - A DirHandle representing the directory stream, or |
|---|
| 80 | * NULL on failure. |
|---|
| 81 | */ |
|---|
| 82 | virtual DirHandle *opendir(const char *name) { return NULL; }; |
|---|
| 83 | |
|---|
| 84 | /* Function mkdir |
|---|
| 85 | * Creates a directory in the filesystem. |
|---|
| 86 | * |
|---|
| 87 | * Variables |
|---|
| 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. |
|---|
| 91 | */ |
|---|
| 92 | virtual int mkdir(const char *name, mode_t mode) { return -1; } |
|---|
| 93 | |
|---|
| 94 | // TODO other filesystem functions (mkdir, rm, rn, ls etc) |
|---|
| 95 | |
|---|
| 96 | }; |
|---|
| 97 | |
|---|
| 98 | } // namespace mbed |
|---|
| 99 | |
|---|
| 100 | #endif |
|---|