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