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