Pinned to some recent date
drivers/DirHandle.h@0:fb7af294d5d9, 2016-11-17 (annotated)
- Committer:
- Simon Cooksey
- Date:
- Thu Nov 17 16:43:53 2016 +0000
- Revision:
- 0:fb7af294d5d9
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Simon Cooksey |
0:fb7af294d5d9 | 1 | /* mbed Microcontroller Library |
Simon Cooksey |
0:fb7af294d5d9 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Simon Cooksey |
0:fb7af294d5d9 | 3 | * |
Simon Cooksey |
0:fb7af294d5d9 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Simon Cooksey |
0:fb7af294d5d9 | 5 | * you may not use this file except in compliance with the License. |
Simon Cooksey |
0:fb7af294d5d9 | 6 | * You may obtain a copy of the License at |
Simon Cooksey |
0:fb7af294d5d9 | 7 | * |
Simon Cooksey |
0:fb7af294d5d9 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Simon Cooksey |
0:fb7af294d5d9 | 9 | * |
Simon Cooksey |
0:fb7af294d5d9 | 10 | * Unless required by applicable law or agreed to in writing, software |
Simon Cooksey |
0:fb7af294d5d9 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Simon Cooksey |
0:fb7af294d5d9 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Simon Cooksey |
0:fb7af294d5d9 | 13 | * See the License for the specific language governing permissions and |
Simon Cooksey |
0:fb7af294d5d9 | 14 | * limitations under the License. |
Simon Cooksey |
0:fb7af294d5d9 | 15 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 16 | #ifndef MBED_DIRHANDLE_H |
Simon Cooksey |
0:fb7af294d5d9 | 17 | #define MBED_DIRHANDLE_H |
Simon Cooksey |
0:fb7af294d5d9 | 18 | |
Simon Cooksey |
0:fb7af294d5d9 | 19 | #if defined(__ARMCC_VERSION) || defined(__ICCARM__) |
Simon Cooksey |
0:fb7af294d5d9 | 20 | # define NAME_MAX 255 |
Simon Cooksey |
0:fb7af294d5d9 | 21 | typedef int mode_t; |
Simon Cooksey |
0:fb7af294d5d9 | 22 | |
Simon Cooksey |
0:fb7af294d5d9 | 23 | #else |
Simon Cooksey |
0:fb7af294d5d9 | 24 | # include <sys/syslimits.h> |
Simon Cooksey |
0:fb7af294d5d9 | 25 | #endif |
Simon Cooksey |
0:fb7af294d5d9 | 26 | |
Simon Cooksey |
0:fb7af294d5d9 | 27 | #include "FileHandle.h" |
Simon Cooksey |
0:fb7af294d5d9 | 28 | |
Simon Cooksey |
0:fb7af294d5d9 | 29 | struct dirent { |
Simon Cooksey |
0:fb7af294d5d9 | 30 | char d_name[NAME_MAX+1]; |
Simon Cooksey |
0:fb7af294d5d9 | 31 | }; |
Simon Cooksey |
0:fb7af294d5d9 | 32 | |
Simon Cooksey |
0:fb7af294d5d9 | 33 | namespace mbed { |
Simon Cooksey |
0:fb7af294d5d9 | 34 | /** \addtogroup drivers */ |
Simon Cooksey |
0:fb7af294d5d9 | 35 | /** @{*/ |
Simon Cooksey |
0:fb7af294d5d9 | 36 | |
Simon Cooksey |
0:fb7af294d5d9 | 37 | /** Represents a directory stream. Objects of this type are returned |
Simon Cooksey |
0:fb7af294d5d9 | 38 | * by a FileSystemLike's opendir method. Implementations must define |
Simon Cooksey |
0:fb7af294d5d9 | 39 | * at least closedir, readdir and rewinddir. |
Simon Cooksey |
0:fb7af294d5d9 | 40 | * |
Simon Cooksey |
0:fb7af294d5d9 | 41 | * If a FileSystemLike class defines the opendir method, then the |
Simon Cooksey |
0:fb7af294d5d9 | 42 | * directories of an object of that type can be accessed by |
Simon Cooksey |
0:fb7af294d5d9 | 43 | * DIR *d = opendir("/example/directory") (or opendir("/example") |
Simon Cooksey |
0:fb7af294d5d9 | 44 | * to open the root of the filesystem), and then using readdir(d) etc. |
Simon Cooksey |
0:fb7af294d5d9 | 45 | * |
Simon Cooksey |
0:fb7af294d5d9 | 46 | * The root directory is considered to contain all FileLike and |
Simon Cooksey |
0:fb7af294d5d9 | 47 | * FileSystemLike objects, so the DIR* returned by opendir("/") will |
Simon Cooksey |
0:fb7af294d5d9 | 48 | * reflect this. |
Simon Cooksey |
0:fb7af294d5d9 | 49 | * |
Simon Cooksey |
0:fb7af294d5d9 | 50 | * @Note Synchronization level: Set by subclass |
Simon Cooksey |
0:fb7af294d5d9 | 51 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 52 | class DirHandle { |
Simon Cooksey |
0:fb7af294d5d9 | 53 | |
Simon Cooksey |
0:fb7af294d5d9 | 54 | public: |
Simon Cooksey |
0:fb7af294d5d9 | 55 | /** Closes the directory. |
Simon Cooksey |
0:fb7af294d5d9 | 56 | * |
Simon Cooksey |
0:fb7af294d5d9 | 57 | * @returns |
Simon Cooksey |
0:fb7af294d5d9 | 58 | * 0 on success, |
Simon Cooksey |
0:fb7af294d5d9 | 59 | * -1 on error. |
Simon Cooksey |
0:fb7af294d5d9 | 60 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 61 | virtual int closedir()=0; |
Simon Cooksey |
0:fb7af294d5d9 | 62 | |
Simon Cooksey |
0:fb7af294d5d9 | 63 | /** Return the directory entry at the current position, and |
Simon Cooksey |
0:fb7af294d5d9 | 64 | * advances the position to the next entry. |
Simon Cooksey |
0:fb7af294d5d9 | 65 | * |
Simon Cooksey |
0:fb7af294d5d9 | 66 | * @returns |
Simon Cooksey |
0:fb7af294d5d9 | 67 | * A pointer to a dirent structure representing the |
Simon Cooksey |
0:fb7af294d5d9 | 68 | * directory entry at the current position, or NULL on reaching |
Simon Cooksey |
0:fb7af294d5d9 | 69 | * end of directory or error. |
Simon Cooksey |
0:fb7af294d5d9 | 70 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 71 | virtual struct dirent *readdir()=0; |
Simon Cooksey |
0:fb7af294d5d9 | 72 | |
Simon Cooksey |
0:fb7af294d5d9 | 73 | /** Resets the position to the beginning of the directory. |
Simon Cooksey |
0:fb7af294d5d9 | 74 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 75 | virtual void rewinddir()=0; |
Simon Cooksey |
0:fb7af294d5d9 | 76 | |
Simon Cooksey |
0:fb7af294d5d9 | 77 | /** Returns the current position of the DirHandle. |
Simon Cooksey |
0:fb7af294d5d9 | 78 | * |
Simon Cooksey |
0:fb7af294d5d9 | 79 | * @returns |
Simon Cooksey |
0:fb7af294d5d9 | 80 | * the current position, |
Simon Cooksey |
0:fb7af294d5d9 | 81 | * -1 on error. |
Simon Cooksey |
0:fb7af294d5d9 | 82 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 83 | virtual off_t telldir() { return -1; } |
Simon Cooksey |
0:fb7af294d5d9 | 84 | |
Simon Cooksey |
0:fb7af294d5d9 | 85 | /** Sets the position of the DirHandle. |
Simon Cooksey |
0:fb7af294d5d9 | 86 | * |
Simon Cooksey |
0:fb7af294d5d9 | 87 | * @param location The location to seek to. Must be a value returned by telldir. |
Simon Cooksey |
0:fb7af294d5d9 | 88 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 89 | virtual void seekdir(off_t location) { (void)location;} |
Simon Cooksey |
0:fb7af294d5d9 | 90 | |
Simon Cooksey |
0:fb7af294d5d9 | 91 | virtual ~DirHandle() {} |
Simon Cooksey |
0:fb7af294d5d9 | 92 | |
Simon Cooksey |
0:fb7af294d5d9 | 93 | protected: |
Simon Cooksey |
0:fb7af294d5d9 | 94 | |
Simon Cooksey |
0:fb7af294d5d9 | 95 | /** Acquire exclusive access to this object. |
Simon Cooksey |
0:fb7af294d5d9 | 96 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 97 | virtual void lock() { |
Simon Cooksey |
0:fb7af294d5d9 | 98 | // Stub |
Simon Cooksey |
0:fb7af294d5d9 | 99 | } |
Simon Cooksey |
0:fb7af294d5d9 | 100 | |
Simon Cooksey |
0:fb7af294d5d9 | 101 | /** Release exclusive access to this object. |
Simon Cooksey |
0:fb7af294d5d9 | 102 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 103 | virtual void unlock() { |
Simon Cooksey |
0:fb7af294d5d9 | 104 | // Stub |
Simon Cooksey |
0:fb7af294d5d9 | 105 | } |
Simon Cooksey |
0:fb7af294d5d9 | 106 | }; |
Simon Cooksey |
0:fb7af294d5d9 | 107 | |
Simon Cooksey |
0:fb7af294d5d9 | 108 | } // namespace mbed |
Simon Cooksey |
0:fb7af294d5d9 | 109 | |
Simon Cooksey |
0:fb7af294d5d9 | 110 | typedef mbed::DirHandle DIR; |
Simon Cooksey |
0:fb7af294d5d9 | 111 | |
Simon Cooksey |
0:fb7af294d5d9 | 112 | extern "C" { |
Simon Cooksey |
0:fb7af294d5d9 | 113 | DIR *opendir(const char*); |
Simon Cooksey |
0:fb7af294d5d9 | 114 | struct dirent *readdir(DIR *); |
Simon Cooksey |
0:fb7af294d5d9 | 115 | int closedir(DIR*); |
Simon Cooksey |
0:fb7af294d5d9 | 116 | void rewinddir(DIR*); |
Simon Cooksey |
0:fb7af294d5d9 | 117 | long telldir(DIR*); |
Simon Cooksey |
0:fb7af294d5d9 | 118 | void seekdir(DIR*, long); |
Simon Cooksey |
0:fb7af294d5d9 | 119 | int mkdir(const char *name, mode_t n); |
Simon Cooksey |
0:fb7af294d5d9 | 120 | }; |
Simon Cooksey |
0:fb7af294d5d9 | 121 | |
Simon Cooksey |
0:fb7af294d5d9 | 122 | #endif /* MBED_DIRHANDLE_H */ |
Simon Cooksey |
0:fb7af294d5d9 | 123 | |
Simon Cooksey |
0:fb7af294d5d9 | 124 | /** @}*/ |