summaryrefslogtreecommitdiffstats
path: root/src/shared/vpick.h
blob: 38251c84e8576706012b1d829332bba12809eb1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once

#include <sys/types.h>

#include "architecture.h"

typedef enum PickFlags {
        PICK_ARCHITECTURE = 1 << 0,   /* Look for an architecture suffix */
        PICK_TRIES        = 1 << 1,   /* Look for tries left/tries done counters */
        PICK_RESOLVE      = 1 << 2,   /* Return the fully resolved (chased) path, rather than the path to the entry */
} PickFlags;

typedef struct PickFilter {
        uint32_t type_mask;           /* A mask of 1U << DT_REG, 1U << DT_DIR, … */
        const char *basename;         /* Can be overridden by search pattern */
        const char *version;
        Architecture architecture;
        char * const *suffix;         /* Can be overridden by search pattern */
} PickFilter;

typedef struct PickResult {
        char *path;
        int fd; /* O_PATH */
        struct stat st;
        char *version;
        Architecture architecture;
        unsigned tries_left;
        unsigned tries_done;
} PickResult;

#define PICK_RESULT_NULL                                \
        (const PickResult) {                            \
                .fd = -EBADF,                           \
                .st.st_mode = MODE_INVALID,             \
                .architecture = _ARCHITECTURE_INVALID,  \
                .tries_left = UINT_MAX,                 \
                .tries_done = UINT_MAX,                 \
        }

#define TAKE_PICK_RESULT(pick) TAKE_GENERIC(pick, PickResult, PICK_RESULT_NULL)

void pick_result_done(PickResult *p);

int path_pick(
                const char *toplevel_path,
                int toplevel_fd,
                const char *path,
                const PickFilter *filter,
                PickFlags flags,
                PickResult *ret);

int path_pick_update_warn(
                char **path,
                const PickFilter *filter,
                PickFlags flags,
                PickResult *ret);

extern const PickFilter pick_filter_image_raw;
extern const PickFilter pick_filter_image_dir;
extern const PickFilter pick_filter_image_any;