1 // Copyright © Tavian Barnes <tavianator@tavianator.com>
2 // SPDX-License-Identifier: 0BSD
5 * Directories and their contents.
13 #include <sys/types.h>
16 * Whether the implementation uses the getdents() syscall directly, rather than
19 #ifndef BFS_USE_GETDENTS
20 # define BFS_USE_GETDENTS (__linux__ || __FreeBSD__)
32 /** An error occurred for this file. */
38 /** Character device. */
48 /** Solaris event port. */
59 * Convert a bfs_stat() mode to a bfs_type.
61 enum bfs_type bfs_mode_to_type(mode_t mode);
67 /** The type of this file (possibly unknown). */
69 /** The name of this file. */
74 * Allocate space for a directory.
77 * An allocated, unopen directory, or NULL on failure.
79 struct bfs_dir *bfs_allocdir(void);
82 * Initialize an arena for directories.
85 * The arena to initialize.
87 void bfs_dir_arena(struct arena *arena);
90 * bfs_opendir() flags.
93 /** Include whiteouts in the results. */
94 BFS_DIR_WHITEOUTS = 1 << 0,
95 /** @internal Start of private flags. */
96 BFS_DIR_PRIVATE = 1 << 1,
103 * The allocated directory.
105 * The base directory for path resolution.
107 * The path of the directory to open, relative to at_fd. Pass NULL to
110 * Flags that control which directory entries are listed.
112 * 0 on success, or -1 on failure.
114 int bfs_opendir(struct bfs_dir *dir, int at_fd, const char *at_path, enum bfs_dir_flags flags);
117 * Get the file descriptor for a directory.
119 int bfs_dirfd(const struct bfs_dir *dir);
122 * Performs any I/O necessary for the next bfs_readdir() call.
125 * The directory to poll.
127 * 1 on success, 0 on EOF, or -1 on failure.
129 int bfs_polldir(struct bfs_dir *dir);
132 * Read a directory entry.
135 * The directory to read.
137 * The directory entry to populate.
139 * 1 on success, 0 on EOF, or -1 on failure.
141 int bfs_readdir(struct bfs_dir *dir, struct bfs_dirent *de);
147 * 0 on success, -1 on failure.
149 int bfs_closedir(struct bfs_dir *dir);
152 * Whether the bfs_unwrapdir() function is supported.
154 #ifndef BFS_USE_UNWRAPDIR
155 # define BFS_USE_UNWRAPDIR (BFS_USE_GETDENTS || __FreeBSD__)
158 #if BFS_USE_UNWRAPDIR
160 * Detach the file descriptor from an open directory.
163 * The directory to detach.
165 * The file descriptor of the directory.
167 int bfs_unwrapdir(struct bfs_dir *dir);