mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Nov 09 11:33:53 2012 +0000
Revision:
8:c14af7958ef5
Parent:
2:e9a661555b58
Child:
9:663789d7729f
SPI driver; ADC driver; DAC driver; microlib support; general bugfixing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 2:e9a661555b58 1 /* mbed Microcontroller Library - FileSystemLike
emilmont 2:e9a661555b58 2 * Copyright (c) 2008-2009 ARM Limited. All rights reserved.
emilmont 2:e9a661555b58 3 */
emilmont 2:e9a661555b58 4 #ifndef MBED_FILESYSTEMLIKE_H
emilmont 2:e9a661555b58 5 #define MBED_FILESYSTEMLIKE_H
emilmont 2:e9a661555b58 6
emilmont 2:e9a661555b58 7 #ifdef __ARMCC_VERSION
emilmont 8:c14af7958ef5 8 # define O_RDONLY 0
emilmont 8:c14af7958ef5 9 # define O_WRONLY 1
emilmont 8:c14af7958ef5 10 # define O_RDWR 2
emilmont 8:c14af7958ef5 11 # define O_CREAT 0x0200
emilmont 8:c14af7958ef5 12 # define O_TRUNC 0x0400
emilmont 8:c14af7958ef5 13 # define O_APPEND 0x0008
emilmont 2:e9a661555b58 14 typedef int mode_t;
emilmont 8:c14af7958ef5 15
emilmont 2:e9a661555b58 16 #else
emilmont 8:c14af7958ef5 17 # include <sys/fcntl.h>
emilmont 2:e9a661555b58 18 #endif
emilmont 8:c14af7958ef5 19
emilmont 8:c14af7958ef5 20 #include "platform.h"
emilmont 8:c14af7958ef5 21
emilmont 2:e9a661555b58 22 #include "FileHandle.h"
emilmont 2:e9a661555b58 23 #include "DirHandle.h"
emilmont 2:e9a661555b58 24
emilmont 2:e9a661555b58 25 namespace mbed {
emilmont 2:e9a661555b58 26
emilmont 8:c14af7958ef5 27 /** A filesystem-like object is one that can be used to open files
emilmont 2:e9a661555b58 28 * though it by fopen("/name/filename", mode)
emilmont 2:e9a661555b58 29 *
emilmont 2:e9a661555b58 30 * Implementations must define at least open (the default definitions
emilmont 2:e9a661555b58 31 * of the rest of the functions just return error values).
emilmont 2:e9a661555b58 32 */
emilmont 8:c14af7958ef5 33 class FileSystemLike {
emilmont 2:e9a661555b58 34
emilmont 8:c14af7958ef5 35 public:
emilmont 8:c14af7958ef5 36 /** FileSystemLike constructor
emilmont 8:c14af7958ef5 37 *
emilmont 8:c14af7958ef5 38 * @param name The name to use for the filesystem.
emilmont 8:c14af7958ef5 39 */
emilmont 8:c14af7958ef5 40 FileSystemLike(const char *name);
emilmont 8:c14af7958ef5 41
emilmont 8:c14af7958ef5 42 virtual ~FileSystemLike();
emilmont 8:c14af7958ef5 43
emilmont 8:c14af7958ef5 44 /* Function lookup
emilmont 8:c14af7958ef5 45 * Lookup and return the object that has the given name.
emilmont 2:e9a661555b58 46 *
emilmont 2:e9a661555b58 47 * Variables
emilmont 8:c14af7958ef5 48 * name - the name to lookup.
emilmont 8:c14af7958ef5 49 * len - the length of name.
emilmont 2:e9a661555b58 50 */
emilmont 8:c14af7958ef5 51 static FileSystemLike *lookup(const char *name, unsigned int len);
emilmont 8:c14af7958ef5 52
emilmont 8:c14af7958ef5 53 static DirHandle *opendir();
emilmont 8:c14af7958ef5 54 friend class BaseDirHandle;
emilmont 8:c14af7958ef5 55
emilmont 8:c14af7958ef5 56 /** Opens a file from the filesystem
emilmont 2:e9a661555b58 57 *
emilmont 8:c14af7958ef5 58 * @param filename The name of the file to open.
emilmont 8:c14af7958ef5 59 * @param flags One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with
emilmont 2:e9a661555b58 60 * zero or more of O_CREAT, O_TRUNC, or O_APPEND.
emilmont 8:c14af7958ef5 61 *
emilmont 8:c14af7958ef5 62 * @returns
emilmont 8:c14af7958ef5 63 * A pointer to a FileHandle object representing the
emilmont 2:e9a661555b58 64 * file on success, or NULL on failure.
emilmont 2:e9a661555b58 65 */
emilmont 2:e9a661555b58 66 virtual FileHandle *open(const char *filename, int flags) = 0;
emilmont 2:e9a661555b58 67
emilmont 8:c14af7958ef5 68 /** Remove a file from the filesystem.
emilmont 2:e9a661555b58 69 *
emilmont 8:c14af7958ef5 70 * @param filename the name of the file to remove.
emilmont 8:c14af7958ef5 71 * @param returns 0 on success, -1 on failure.
emilmont 2:e9a661555b58 72 */
emilmont 2:e9a661555b58 73 virtual int remove(const char *filename) { return -1; };
emilmont 2:e9a661555b58 74
emilmont 8:c14af7958ef5 75 /** Rename a file in the filesystem.
emilmont 2:e9a661555b58 76 *
emilmont 8:c14af7958ef5 77 * @param oldname the name of the file to rename.
emilmont 8:c14af7958ef5 78 * @param newname the name to rename it to.
emilmont 8:c14af7958ef5 79 *
emilmont 8:c14af7958ef5 80 * @returns
emilmont 8:c14af7958ef5 81 * 0 on success,
emilmont 8:c14af7958ef5 82 * -1 on failure.
emilmont 2:e9a661555b58 83 */
emilmont 2:e9a661555b58 84 virtual int rename(const char *oldname, const char *newname) { return -1; };
emilmont 2:e9a661555b58 85
emilmont 8:c14af7958ef5 86 /** Opens a directory in the filesystem and returns a DirHandle
emilmont 2:e9a661555b58 87 * representing the directory stream.
emilmont 2:e9a661555b58 88 *
emilmont 8:c14af7958ef5 89 * @param name The name of the directory to open.
emilmont 8:c14af7958ef5 90 *
emilmont 8:c14af7958ef5 91 * @returns
emilmont 8:c14af7958ef5 92 * A DirHandle representing the directory stream, or
emilmont 2:e9a661555b58 93 * NULL on failure.
emilmont 2:e9a661555b58 94 */
emilmont 2:e9a661555b58 95 virtual DirHandle *opendir(const char *name) { return NULL; };
emilmont 2:e9a661555b58 96
emilmont 8:c14af7958ef5 97 /** Creates a directory in the filesystem.
emilmont 2:e9a661555b58 98 *
emilmont 8:c14af7958ef5 99 * @param name The name of the directory to create.
emilmont 8:c14af7958ef5 100 * @param mode The permissions to create the directory with.
emilmont 8:c14af7958ef5 101 *
emilmont 8:c14af7958ef5 102 * @returns
emilmont 8:c14af7958ef5 103 * 0 on success,
emilmont 8:c14af7958ef5 104 * -1 on failure.
emilmont 2:e9a661555b58 105 */
emilmont 2:e9a661555b58 106 virtual int mkdir(const char *name, mode_t mode) { return -1; }
emilmont 2:e9a661555b58 107
emilmont 2:e9a661555b58 108 // TODO other filesystem functions (mkdir, rm, rn, ls etc)
emilmont 8:c14af7958ef5 109
emilmont 8:c14af7958ef5 110 protected:
emilmont 8:c14af7958ef5 111 static FileSystemLike *_head;
emilmont 8:c14af7958ef5 112 FileSystemLike *_next;
emilmont 8:c14af7958ef5 113 const char *_name;
emilmont 8:c14af7958ef5 114 };
emilmont 8:c14af7958ef5 115
emilmont 8:c14af7958ef5 116 class FilePath {
emilmont 8:c14af7958ef5 117 public:
emilmont 8:c14af7958ef5 118 FilePath(const char* file_path);
emilmont 2:e9a661555b58 119
emilmont 8:c14af7958ef5 120 const char* fileName(void);
emilmont 8:c14af7958ef5 121 FileSystemLike* fileSystem(void);
emilmont 8:c14af7958ef5 122
emilmont 8:c14af7958ef5 123 static FileSystemLike* getFileSystem(const char* path);
emilmont 8:c14af7958ef5 124
emilmont 8:c14af7958ef5 125 private:
emilmont 8:c14af7958ef5 126 const char* file_name;
emilmont 8:c14af7958ef5 127 FileSystemLike* fs;
emilmont 2:e9a661555b58 128 };
emilmont 2:e9a661555b58 129
emilmont 2:e9a661555b58 130 } // namespace mbed
emilmont 2:e9a661555b58 131
emilmont 2:e9a661555b58 132 #endif