]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/unit-name.h
systemctl: be smarter when mangling snapshot names
[thirdparty/systemd.git] / src / shared / unit-name.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6 This file is part of systemd.
7
8 Copyright 2010 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <stdbool.h>
25
26 #define UNIT_NAME_MAX 256
27
28 typedef enum UnitType UnitType;
29 typedef enum UnitLoadState UnitLoadState;
30
31 enum UnitType {
32 UNIT_SERVICE = 0,
33 UNIT_SOCKET,
34 UNIT_TARGET,
35 UNIT_DEVICE,
36 UNIT_MOUNT,
37 UNIT_AUTOMOUNT,
38 UNIT_SNAPSHOT,
39 UNIT_TIMER,
40 UNIT_SWAP,
41 UNIT_PATH,
42 _UNIT_TYPE_MAX,
43 _UNIT_TYPE_INVALID = -1
44 };
45
46 enum UnitLoadState {
47 UNIT_STUB = 0,
48 UNIT_LOADED,
49 UNIT_ERROR,
50 UNIT_MERGED,
51 UNIT_MASKED,
52 _UNIT_LOAD_STATE_MAX,
53 _UNIT_LOAD_STATE_INVALID = -1
54 };
55
56 extern const char* const unit_type_table[];
57 const char *unit_type_to_string(UnitType i);
58 UnitType unit_type_from_string(const char *s);
59
60 extern const char* const unit_load_state_table[];
61 const char *unit_load_state_to_string(UnitLoadState i);
62 UnitLoadState unit_load_state_from_string(const char *s);
63
64 int unit_name_to_instance(const char *n, char **instance);
65 char* unit_name_to_prefix(const char *n);
66 char* unit_name_to_prefix_and_instance(const char *n);
67
68 bool unit_name_is_valid(const char *n, bool template_ok);
69 bool unit_prefix_is_valid(const char *p);
70 bool unit_instance_is_valid(const char *i);
71
72 UnitType unit_name_to_type(const char *n);
73
74 char *unit_name_change_suffix(const char *n, const char *suffix);
75
76 char *unit_name_build(const char *prefix, const char *instance, const char *suffix);
77
78 char *unit_name_escape(const char *f);
79 char *unit_name_unescape(const char *f);
80 char *unit_name_path_escape(const char *f);
81 char *unit_name_path_unescape(const char *f);
82
83 bool unit_name_is_template(const char *n);
84 bool unit_name_is_instance(const char *n);
85
86 char *unit_name_replace_instance(const char *f, const char *i);
87
88 char *unit_name_template(const char *f);
89
90 char *unit_name_from_path(const char *path, const char *suffix);
91 char *unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix);
92 char *unit_name_to_path(const char *name);
93
94 char *unit_dbus_path_from_name(const char *name);
95
96 char *unit_name_mangle(const char *name);
97 char *snapshot_name_mangle(const char *name);