
Erste version der Software für der Prototyp
mbed-os/features/filesystem/Dir.h@4:75df35ef4fb6, 2018-03-30 (annotated)
- Committer:
- borlanic
- Date:
- Fri Mar 30 14:07:05 2018 +0000
- Revision:
- 4:75df35ef4fb6
- Parent:
- 0:380207fcb5c1
commentar
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:380207fcb5c1 | 1 | /* mbed Microcontroller Library |
borlanic | 0:380207fcb5c1 | 2 | * Copyright (c) 2015 ARM Limited |
borlanic | 0:380207fcb5c1 | 3 | * |
borlanic | 0:380207fcb5c1 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:380207fcb5c1 | 5 | * you may not use this file except in compliance with the License. |
borlanic | 0:380207fcb5c1 | 6 | * You may obtain a copy of the License at |
borlanic | 0:380207fcb5c1 | 7 | * |
borlanic | 0:380207fcb5c1 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:380207fcb5c1 | 9 | * |
borlanic | 0:380207fcb5c1 | 10 | * Unless required by applicable law or agreed to in writing, software |
borlanic | 0:380207fcb5c1 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:380207fcb5c1 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:380207fcb5c1 | 13 | * See the License for the specific language governing permissions and |
borlanic | 0:380207fcb5c1 | 14 | * limitations under the License. |
borlanic | 0:380207fcb5c1 | 15 | */ |
borlanic | 0:380207fcb5c1 | 16 | |
borlanic | 0:380207fcb5c1 | 17 | #ifndef DIR_H |
borlanic | 0:380207fcb5c1 | 18 | #define DIR_H |
borlanic | 0:380207fcb5c1 | 19 | |
borlanic | 0:380207fcb5c1 | 20 | #include "filesystem/FileSystem.h" |
borlanic | 0:380207fcb5c1 | 21 | #include "platform/DirHandle.h" |
borlanic | 0:380207fcb5c1 | 22 | |
borlanic | 0:380207fcb5c1 | 23 | namespace mbed { |
borlanic | 0:380207fcb5c1 | 24 | /** \addtogroup filesystem */ |
borlanic | 0:380207fcb5c1 | 25 | /** @{*/ |
borlanic | 0:380207fcb5c1 | 26 | |
borlanic | 0:380207fcb5c1 | 27 | |
borlanic | 0:380207fcb5c1 | 28 | /** Dir class |
borlanic | 0:380207fcb5c1 | 29 | */ |
borlanic | 0:380207fcb5c1 | 30 | class Dir : public DirHandle { |
borlanic | 0:380207fcb5c1 | 31 | public: |
borlanic | 0:380207fcb5c1 | 32 | /** Create an uninitialized directory |
borlanic | 0:380207fcb5c1 | 33 | * |
borlanic | 0:380207fcb5c1 | 34 | * Must call open to initialize the directory on a file system |
borlanic | 0:380207fcb5c1 | 35 | */ |
borlanic | 0:380207fcb5c1 | 36 | Dir(); |
borlanic | 0:380207fcb5c1 | 37 | |
borlanic | 0:380207fcb5c1 | 38 | /** Open a directory on a filesystem |
borlanic | 0:380207fcb5c1 | 39 | * |
borlanic | 0:380207fcb5c1 | 40 | * @param fs Filesystem as target for a directory |
borlanic | 0:380207fcb5c1 | 41 | * @param path Name of the directory to open |
borlanic | 0:380207fcb5c1 | 42 | */ |
borlanic | 0:380207fcb5c1 | 43 | Dir(FileSystem *fs, const char *path); |
borlanic | 0:380207fcb5c1 | 44 | |
borlanic | 0:380207fcb5c1 | 45 | /** Destroy a file |
borlanic | 0:380207fcb5c1 | 46 | * |
borlanic | 0:380207fcb5c1 | 47 | * Closes file if the file is still open |
borlanic | 0:380207fcb5c1 | 48 | */ |
borlanic | 0:380207fcb5c1 | 49 | virtual ~Dir(); |
borlanic | 0:380207fcb5c1 | 50 | |
borlanic | 0:380207fcb5c1 | 51 | /** Open a directory on the filesystem |
borlanic | 0:380207fcb5c1 | 52 | * |
borlanic | 0:380207fcb5c1 | 53 | * @param fs Filesystem as target for a directory |
borlanic | 0:380207fcb5c1 | 54 | * @param path Name of the directory to open |
borlanic | 0:380207fcb5c1 | 55 | * @return 0 on success, negative error code on failure |
borlanic | 0:380207fcb5c1 | 56 | */ |
borlanic | 0:380207fcb5c1 | 57 | virtual int open(FileSystem *fs, const char *path); |
borlanic | 0:380207fcb5c1 | 58 | |
borlanic | 0:380207fcb5c1 | 59 | /** Close a directory |
borlanic | 0:380207fcb5c1 | 60 | * |
borlanic | 0:380207fcb5c1 | 61 | * @return 0 on success, negative error code on failure |
borlanic | 0:380207fcb5c1 | 62 | */ |
borlanic | 0:380207fcb5c1 | 63 | virtual int close(); |
borlanic | 0:380207fcb5c1 | 64 | |
borlanic | 0:380207fcb5c1 | 65 | /** Read the next directory entry |
borlanic | 0:380207fcb5c1 | 66 | * |
borlanic | 0:380207fcb5c1 | 67 | * @param ent The directory entry to fill out |
borlanic | 0:380207fcb5c1 | 68 | * @return 1 on reading a filename, 0 at end of directory, negative error on failure |
borlanic | 0:380207fcb5c1 | 69 | */ |
borlanic | 0:380207fcb5c1 | 70 | virtual ssize_t read(struct dirent *ent); |
borlanic | 0:380207fcb5c1 | 71 | |
borlanic | 0:380207fcb5c1 | 72 | /** Set the current position of the directory |
borlanic | 0:380207fcb5c1 | 73 | * |
borlanic | 0:380207fcb5c1 | 74 | * @param offset Offset of the location to seek to, |
borlanic | 0:380207fcb5c1 | 75 | * must be a value returned from tell |
borlanic | 0:380207fcb5c1 | 76 | */ |
borlanic | 0:380207fcb5c1 | 77 | virtual void seek(off_t offset); |
borlanic | 0:380207fcb5c1 | 78 | |
borlanic | 0:380207fcb5c1 | 79 | /** Get the current position of the directory |
borlanic | 0:380207fcb5c1 | 80 | * |
borlanic | 0:380207fcb5c1 | 81 | * @return Position of the directory that can be passed to rewind |
borlanic | 0:380207fcb5c1 | 82 | */ |
borlanic | 0:380207fcb5c1 | 83 | virtual off_t tell(); |
borlanic | 0:380207fcb5c1 | 84 | |
borlanic | 0:380207fcb5c1 | 85 | /** Rewind the current position to the beginning of the directory |
borlanic | 0:380207fcb5c1 | 86 | */ |
borlanic | 0:380207fcb5c1 | 87 | virtual void rewind(); |
borlanic | 0:380207fcb5c1 | 88 | |
borlanic | 0:380207fcb5c1 | 89 | /** Get the sizeof the directory |
borlanic | 0:380207fcb5c1 | 90 | * |
borlanic | 0:380207fcb5c1 | 91 | * @return Number of files in the directory |
borlanic | 0:380207fcb5c1 | 92 | */ |
borlanic | 0:380207fcb5c1 | 93 | virtual size_t size(); |
borlanic | 0:380207fcb5c1 | 94 | |
borlanic | 0:380207fcb5c1 | 95 | private: |
borlanic | 0:380207fcb5c1 | 96 | FileSystem *_fs; |
borlanic | 0:380207fcb5c1 | 97 | fs_dir_t _dir; |
borlanic | 0:380207fcb5c1 | 98 | }; |
borlanic | 0:380207fcb5c1 | 99 | |
borlanic | 0:380207fcb5c1 | 100 | |
borlanic | 0:380207fcb5c1 | 101 | /** @}*/ |
borlanic | 0:380207fcb5c1 | 102 | } // namespace mbed |
borlanic | 0:380207fcb5c1 | 103 | |
borlanic | 0:380207fcb5c1 | 104 | #endif |