1 // Copyright © Tavian Barnes <tavianator@tavianator.com>
2 // SPDX-License-Identifier: 0BSD
5 * bfs execution context.
16 #include <sys/resource.h>
20 * The execution context for bfs.
23 /** The number of command line arguments. */
25 /** The unparsed command line arguments. */
28 /** The root paths. */
30 /** The main command line expression. */
31 struct bfs_expr *expr;
32 /** An expression for files to filter out. */
33 struct bfs_expr *exclude;
35 /** -mindepth option. */
37 /** -maxdepth option. */
41 enum bftw_flags flags;
42 /** bftw() search strategy. */
43 enum bftw_strategy strategy;
47 /** Optimization level (-O). */
49 /** Debugging flags (-D). */
50 enum debug_flags debug;
51 /** Whether to ignore deletions that race with bfs (-ignore_readdir_race). */
53 /** Whether to follow POSIXisms more closely ($POSIXLY_CORRECT). */
55 /** Whether to show a status bar (-status). */
57 /** Whether to only return unique files (-unique). */
59 /** Whether to print warnings (-warn/-nowarn). */
61 /** Whether to only handle paths with xargs-safe characters (-X). */
65 struct colors *colors;
66 /** The error that occurred parsing the color table, if any. */
68 /** Colored stdout. */
70 /** Colored stderr. */
74 struct bfs_users *users;
76 struct bfs_groups *groups;
77 /** The error that occurred parsing the group table, if any. */
80 /** Table of mounted file systems. */
81 struct bfs_mtab *mtab;
82 /** The error that occurred parsing the mount table, if any. */
85 /** All the files owned by the context. */
87 /** The number of files owned by the context. */
90 /** The initial RLIMIT_NOFILE soft limit. */
92 /** The initial RLIMIT_NOFILE hard limit. */
95 /** The current time. */
101 * A new bfs context, or NULL on failure.
103 struct bfs_ctx *bfs_ctx_new(void);
106 * Get the mount table.
111 * The cached mount table, or NULL on failure.
113 const struct bfs_mtab *bfs_ctx_mtab(const struct bfs_ctx *ctx);
116 * Deduplicate an opened file.
123 * The path to the opened file (or NULL for standard streams).
125 * If the same file was opened previously, that file is returned. If cfile is a new file,
126 * cfile itself is returned. If an error occurs, NULL is returned.
128 struct CFILE *bfs_ctx_dedup(struct bfs_ctx *ctx, struct CFILE *cfile, const char *path);
131 * Flush any caches for consistency with external processes.
136 void bfs_ctx_flush(const struct bfs_ctx *ctx);
139 * Dump the parsed command line.
144 * The -D flag that triggered the dump.
146 void bfs_ctx_dump(const struct bfs_ctx *ctx, enum debug_flags flag);
149 * Free a bfs context.
152 * The context to free.
154 * 0 on success, -1 if any errors occurred.
156 int bfs_ctx_free(struct bfs_ctx *ctx);