1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 typedef enum UnitFilePresetMode UnitFilePresetMode
;
5 typedef enum UnitFileChangeType UnitFileChangeType
;
6 typedef enum UnitFileFlags UnitFileFlags
;
7 typedef enum UnitFileType UnitFileType
;
8 typedef struct UnitFileChange UnitFileChange
;
9 typedef struct UnitFileList UnitFileList
;
10 typedef struct UnitFileInstallInfo UnitFileInstallInfo
;
16 #include "path-lookup.h"
18 #include "unit-name.h"
20 enum UnitFilePresetMode
{
21 UNIT_FILE_PRESET_FULL
,
22 UNIT_FILE_PRESET_ENABLE_ONLY
,
23 UNIT_FILE_PRESET_DISABLE_ONLY
,
24 _UNIT_FILE_PRESET_MAX
,
25 _UNIT_FILE_PRESET_INVALID
= -1
28 enum UnitFileChangeType
{
32 UNIT_FILE_IS_DANGLING
,
33 _UNIT_FILE_CHANGE_TYPE_MAX
,
34 _UNIT_FILE_CHANGE_TYPE_INVALID
= INT_MIN
38 UNIT_FILE_RUNTIME
= 1 << 0,
39 UNIT_FILE_FORCE
= 1 << 1,
40 UNIT_FILE_DRY_RUN
= 1 << 2,
43 /* type can either one of the UnitFileChangeTypes listed above, or a negative error.
44 * If source is specified, it should be the contents of the path symlink.
45 * In case of an error, source should be the existing symlink contents or NULL
47 struct UnitFileChange
{
48 int type
; /* UnitFileChangeType or bust */
53 static inline bool unit_file_changes_have_modification(const UnitFileChange
* changes
, size_t n_changes
) {
55 for (i
= 0; i
< n_changes
; i
++)
56 if (IN_SET(changes
[i
].type
, UNIT_FILE_SYMLINK
, UNIT_FILE_UNLINK
))
67 UNIT_FILE_TYPE_REGULAR
,
68 UNIT_FILE_TYPE_SYMLINK
,
69 UNIT_FILE_TYPE_MASKED
,
71 _UNIT_FILE_TYPE_INVALID
= -1,
74 struct UnitFileInstallInfo
{
83 char *default_instance
;
95 UnitFileChange
**changes
,
97 int unit_file_disable(
100 const char *root_dir
,
102 UnitFileChange
**changes
,
104 int unit_file_reenable(
107 const char *root_dir
,
109 UnitFileChange
**changes
,
111 int unit_file_preset(
114 const char *root_dir
,
116 UnitFilePresetMode mode
,
117 UnitFileChange
**changes
,
119 int unit_file_preset_all(
122 const char *root_dir
,
123 UnitFilePresetMode mode
,
124 UnitFileChange
**changes
,
129 const char *root_dir
,
131 UnitFileChange
**changes
,
133 int unit_file_unmask(
136 const char *root_dir
,
138 UnitFileChange
**changes
,
143 const char *root_dir
,
145 UnitFileChange
**changes
,
147 int unit_file_revert(
149 const char *root_dir
,
151 UnitFileChange
**changes
,
153 int unit_file_set_default(
156 const char *root_dir
,
158 UnitFileChange
**changes
,
160 int unit_file_get_default(
162 const char *root_dir
,
164 int unit_file_add_dependency(
167 const char *root_dir
,
171 UnitFileChange
**changes
,
174 int unit_file_lookup_state(
176 const LookupPaths
*paths
,
180 int unit_file_get_state(UnitFileScope scope
, const char *root_dir
, const char *filename
, UnitFileState
*ret
);
181 int unit_file_exists(UnitFileScope scope
, const LookupPaths
*paths
, const char *name
);
183 int unit_file_get_list(UnitFileScope scope
, const char *root_dir
, Hashmap
*h
, char **states
, char **patterns
);
184 Hashmap
* unit_file_list_free(Hashmap
*h
);
186 int unit_file_changes_add(UnitFileChange
**changes
, size_t *n_changes
, UnitFileChangeType type
, const char *path
, const char *source
);
187 void unit_file_changes_free(UnitFileChange
*changes
, size_t n_changes
);
188 void unit_file_dump_changes(int r
, const char *verb
, const UnitFileChange
*changes
, size_t n_changes
, bool quiet
);
190 int unit_file_verify_alias(const UnitFileInstallInfo
*i
, const char *dst
, char **ret_dst
);
192 typedef struct UnitFilePresetRule UnitFilePresetRule
;
195 UnitFilePresetRule
*rules
;
200 void unit_file_presets_freep(UnitFilePresets
*p
);
201 int unit_file_query_preset(UnitFileScope scope
, const char *root_dir
, const char *name
, UnitFilePresets
*cached
);
203 const char *unit_file_state_to_string(UnitFileState s
) _const_
;
204 UnitFileState
unit_file_state_from_string(const char *s
) _pure_
;
205 /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
207 const char *unit_file_change_type_to_string(UnitFileChangeType s
) _const_
;
208 UnitFileChangeType
unit_file_change_type_from_string(const char *s
) _pure_
;
210 const char *unit_file_preset_mode_to_string(UnitFilePresetMode m
) _const_
;
211 UnitFilePresetMode
unit_file_preset_mode_from_string(const char *s
) _pure_
;