Debian Codegraph @

src/shared/vpick.h

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