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