Library

Dependents:   OSCTest_2

Fork of mbed by gokmen ascioglu

Committer:
gokmenascioglu
Date:
Sat Sep 22 10:32:07 2012 +0000
Revision:
0:a8fa94490a0a
alican library

Who changed what in which revision?

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