Debian Codegraph @

src/shared/storage-util.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "sd-json.h"
5
6 #include "string-util.h"
7
8 /* This closely follows the kernel's inode type naming, i.e. is supposed to be a subset of what
9 * inode_type_from_string() parses. */
10 typedef enum VolumeType {
11 VOLUME_BLK,
12 VOLUME_REG,
13 VOLUME_DIR,
14 _VOLUME_TYPE_MAX,
15 _VOLUME_TYPE_INVALID = -EINVAL,
16 } VolumeType;
17
18 typedef enum CreateMode {
19 CREATE_ANY,
20 CREATE_NEW,
21 CREATE_OPEN,
22 _CREATE_MODE_MAX,
23 _CREATE_MODE_INVALID = -EINVAL,
24 } CreateMode;
25
26 DECLARE_STRING_TABLE_LOOKUP(volume_type, VolumeType);
27 DECLARE_STRING_TABLE_LOOKUP(create_mode, CreateMode);
28
29 int json_dispatch_volume_type(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
30 int json_dispatch_create_mode(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
31
32 static inline bool storage_volume_name_is_valid(const char *n) {
33 return string_is_safe(n, /* flags= */ 0);
34 }
35
36 static inline bool storage_template_name_is_valid(const char *n) {
37 return string_is_safe(n, /* flags= */ 0);
38 }
39
40 static inline bool storage_provider_name_is_valid(const char *n) {
41 return string_is_safe(n, STRING_FILENAME);
42 }
43
44 typedef struct StorageAcquireReply {
45 int fd;
46 VolumeType type;
47 int read_only;
48 uid_t base_uid;
49 gid_t base_gid;
50 } StorageAcquireReply;
51
52 #define STORAGE_ACQUIRE_REPLY_INIT \
53 (StorageAcquireReply) { \
54 .fd = -EBADF, \
55 .type = _VOLUME_TYPE_INVALID, \
56 .read_only = -1, \
57 .base_uid = UID_INVALID, \
58 .base_gid = GID_INVALID, \
59 }
60
61 void storage_acquire_reply_done(StorageAcquireReply *reply);
62
63 /* On varlink failure, reterr_error_id (if non-NULL) is set to the io.systemd.StorageProvider.*
64 * error name. The reply is untouched on any error. */
65 typedef struct BindVolume BindVolume;
66 int storage_acquire_volume(
67 RuntimeScope scope,
68 const BindVolume *bv,
69 bool allow_interactive_auth,
70 char **reterr_error_id,
71 StorageAcquireReply *ret);