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