]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/vpick.h
shared/vpick: also align function params in header
[thirdparty/systemd.git] / src / shared / vpick.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <sys/types.h>
5
6 #include "architecture.h"
7
8 typedef enum PickFlags {
9 PICK_ARCHITECTURE = 1 << 0, /* Look for an architecture suffix */
10 PICK_TRIES = 1 << 1, /* Look for tries left/tries done counters */
11 PICK_RESOLVE = 1 << 2, /* Return the fully resolved (chased) path, rather than the path to the entry */
12 } PickFlags;
13
14 typedef struct PickFilter {
15 uint32_t type_mask; /* A mask of 1U << DT_REG, 1U << DT_DIR, … */
16 const char *basename; /* Can be overridden by search pattern */
17 const char *version;
18 Architecture architecture;
19 const char *suffix; /* Can be overridden by search pattern */
20 } PickFilter;
21
22 typedef struct PickResult {
23 char *path;
24 int fd; /* O_PATH */
25 struct stat st;
26 char *version;
27 Architecture architecture;
28 unsigned tries_left;
29 unsigned tries_done;
30 } PickResult;
31
32 #define PICK_RESULT_NULL \
33 (const PickResult) { \
34 .fd = -EBADF, \
35 .st.st_mode = MODE_INVALID, \
36 .architecture = _ARCHITECTURE_INVALID, \
37 .tries_left = UINT_MAX, \
38 .tries_done = UINT_MAX, \
39 }
40
41 #define TAKE_PICK_RESULT(pick) TAKE_GENERIC(pick, PickResult, PICK_RESULT_NULL)
42
43 void pick_result_done(PickResult *p);
44
45 int path_pick(
46 const char *toplevel_path,
47 int toplevel_fd,
48 const char *path,
49 const PickFilter *filter,
50 PickFlags flags,
51 PickResult *ret);
52
53 int path_pick_update_warn(
54 char **path,
55 const PickFilter *filter,
56 PickFlags flags,
57 PickResult *ret);
58
59 extern const PickFilter pick_filter_image_raw;
60 extern const PickFilter pick_filter_image_dir;