1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MEDIA_PROVIDER_FUSE_READDIR_HELPER_H
18 #define MEDIA_PROVIDER_FUSE_READDIR_HELPER_H
19 
20 #include <dirent.h>
21 #include <string>
22 #include <vector>
23 
24 namespace mediaprovider {
25 namespace fuse {
26 
27 /**
28  * Holds a directory entry.
29  *
30  * DirectoryEntry object holds information about the directory entry such as
31  * name and type of the file or directory.
32  */
33 struct DirectoryEntry {
34     /**
35      * Create a directory entry.
36      *
37      * @param name directory entry name.
38      * @param type directory entry type. Directory entry type corresponds to
39      * d_type of dirent structure defined in dirent.h
40      */
DirectoryEntryDirectoryEntry41     DirectoryEntry(const std::string& name, int type) : d_name(name), d_type(type) {}
42     const std::string d_name;
43     const int d_type;
44 };
45 
46 /**
47  * Adds directory entries from lower file system to the list.
48  *
49  * If a filter is specified, directory entries must satisfy the given filter. If filter is null,
50  * all directory entries(except '.' & '..') are returned.
51  */
52 void addDirectoryEntriesFromLowerFs(DIR* dirp, bool (*const filter)(const dirent&),
53         std::vector<std::shared_ptr<DirectoryEntry>>* directory_entries);
54 
55 /**
56  * Checks if the given dirent is directory.
57  */
58 bool isDirectory(const dirent& entry);
59 
60 }  // namespace fuse
61 }  // namespace mediaprovider
62 #endif
63