SD card interface
mbed-export/DirHandle.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 - DirHandler |
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_DIRHANDLE_H |
lharoon | 0:22612ae617a0 | 6 | #define MBED_DIRHANDLE_H |
lharoon | 0:22612ae617a0 | 7 | |
lharoon | 0:22612ae617a0 | 8 | #ifdef __ARMCC_VERSION |
lharoon | 0:22612ae617a0 | 9 | # define NAME_MAX 255 |
lharoon | 0:22612ae617a0 | 10 | typedef int mode_t; |
lharoon | 0:22612ae617a0 | 11 | #else |
lharoon | 0:22612ae617a0 | 12 | # include <sys/syslimits.h> |
lharoon | 0:22612ae617a0 | 13 | #endif |
lharoon | 0:22612ae617a0 | 14 | #include "FileHandle.h" |
lharoon | 0:22612ae617a0 | 15 | |
lharoon | 0:22612ae617a0 | 16 | struct dirent { |
lharoon | 0:22612ae617a0 | 17 | char d_name[NAME_MAX+1]; |
lharoon | 0:22612ae617a0 | 18 | }; |
lharoon | 0:22612ae617a0 | 19 | |
lharoon | 0:22612ae617a0 | 20 | namespace mbed { |
lharoon | 0:22612ae617a0 | 21 | |
lharoon | 0:22612ae617a0 | 22 | /* Class DirHandle |
lharoon | 0:22612ae617a0 | 23 | * Represents a directory stream. Objects of this type are returned |
lharoon | 0:22612ae617a0 | 24 | * by a FileSystemLike's opendir method. Implementations must define |
lharoon | 0:22612ae617a0 | 25 | * at least closedir, readdir and rewinddir. |
lharoon | 0:22612ae617a0 | 26 | * |
lharoon | 0:22612ae617a0 | 27 | * If a FileSystemLike class defines the opendir method, then the |
lharoon | 0:22612ae617a0 | 28 | * directories of an object of that type can be accessed by |
lharoon | 0:22612ae617a0 | 29 | * DIR *d = opendir("/example/directory") (or opendir("/example") |
lharoon | 0:22612ae617a0 | 30 | * to open the root of the filesystem), and then using readdir(d) etc. |
lharoon | 0:22612ae617a0 | 31 | * |
lharoon | 0:22612ae617a0 | 32 | * The root directory is considered to contain all FileLike and |
lharoon | 0:22612ae617a0 | 33 | * FileSystemLike objects, so the DIR* returned by opendir("/") will |
lharoon | 0:22612ae617a0 | 34 | * reflect this. |
lharoon | 0:22612ae617a0 | 35 | */ |
lharoon | 0:22612ae617a0 | 36 | class DirHandle { |
lharoon | 0:22612ae617a0 | 37 | |
lharoon | 0:22612ae617a0 | 38 | public: |
lharoon | 0:22612ae617a0 | 39 | /* Function closedir |
lharoon | 0:22612ae617a0 | 40 | * Closes the directory. |
lharoon | 0:22612ae617a0 | 41 | * |
lharoon | 0:22612ae617a0 | 42 | * Variables |
lharoon | 0:22612ae617a0 | 43 | * returns - 0 on success, or -1 on error. |
lharoon | 0:22612ae617a0 | 44 | */ |
lharoon | 0:22612ae617a0 | 45 | virtual int closedir()=0; |
lharoon | 0:22612ae617a0 | 46 | |
lharoon | 0:22612ae617a0 | 47 | /* Function readdir |
lharoon | 0:22612ae617a0 | 48 | * Return the directory entry at the current position, and |
lharoon | 0:22612ae617a0 | 49 | * advances the position to the next entry. |
lharoon | 0:22612ae617a0 | 50 | * |
lharoon | 0:22612ae617a0 | 51 | * Returns |
lharoon | 0:22612ae617a0 | 52 | * A pointer to a dirent structure representing the |
lharoon | 0:22612ae617a0 | 53 | * directory entry at the current position, or NULL on reaching |
lharoon | 0:22612ae617a0 | 54 | * end of directory or error. |
lharoon | 0:22612ae617a0 | 55 | */ |
lharoon | 0:22612ae617a0 | 56 | virtual struct dirent *readdir()=0; |
lharoon | 0:22612ae617a0 | 57 | |
lharoon | 0:22612ae617a0 | 58 | /* Function rewinddir |
lharoon | 0:22612ae617a0 | 59 | * Resets the position to the beginning of the directory. |
lharoon | 0:22612ae617a0 | 60 | */ |
lharoon | 0:22612ae617a0 | 61 | virtual void rewinddir()=0; |
lharoon | 0:22612ae617a0 | 62 | |
lharoon | 0:22612ae617a0 | 63 | /* Function telldir |
lharoon | 0:22612ae617a0 | 64 | * Returns the current position of the DirHandle. |
lharoon | 0:22612ae617a0 | 65 | * |
lharoon | 0:22612ae617a0 | 66 | * Returns |
lharoon | 0:22612ae617a0 | 67 | * The current position, or -1 on error. |
lharoon | 0:22612ae617a0 | 68 | */ |
lharoon | 0:22612ae617a0 | 69 | virtual off_t telldir() { return -1; } |
lharoon | 0:22612ae617a0 | 70 | |
lharoon | 0:22612ae617a0 | 71 | /* Function seekdir |
lharoon | 0:22612ae617a0 | 72 | * Sets the position of the DirHandle. |
lharoon | 0:22612ae617a0 | 73 | * |
lharoon | 0:22612ae617a0 | 74 | * Variables |
lharoon | 0:22612ae617a0 | 75 | * location - The location to seek to. Must be a value returned |
lharoon | 0:22612ae617a0 | 76 | * by telldir. |
lharoon | 0:22612ae617a0 | 77 | */ |
lharoon | 0:22612ae617a0 | 78 | virtual void seekdir(off_t location) { } |
lharoon | 0:22612ae617a0 | 79 | |
lharoon | 0:22612ae617a0 | 80 | }; |
lharoon | 0:22612ae617a0 | 81 | |
lharoon | 0:22612ae617a0 | 82 | } // namespace mbed |
lharoon | 0:22612ae617a0 | 83 | |
lharoon | 0:22612ae617a0 | 84 | typedef mbed::DirHandle DIR; |
lharoon | 0:22612ae617a0 | 85 | |
lharoon | 0:22612ae617a0 | 86 | extern "C" { |
lharoon | 0:22612ae617a0 | 87 | DIR *opendir(const char*); |
lharoon | 0:22612ae617a0 | 88 | struct dirent *readdir(DIR *); |
lharoon | 0:22612ae617a0 | 89 | int closedir(DIR*); |
lharoon | 0:22612ae617a0 | 90 | void rewinddir(DIR*); |
lharoon | 0:22612ae617a0 | 91 | long telldir(DIR*); |
lharoon | 0:22612ae617a0 | 92 | void seekdir(DIR*, long); |
lharoon | 0:22612ae617a0 | 93 | int mkdir(const char *name, mode_t n); |
lharoon | 0:22612ae617a0 | 94 | }; |
lharoon | 0:22612ae617a0 | 95 | |
lharoon | 0:22612ae617a0 | 96 | #endif /* MBED_DIRHANDLE_H */ |