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