1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "bus-get-properties.h"
4 #include "dbus-cgroup.h"
5 #include "dbus-execute.h"
7 #include "dbus-mount.h"
10 #include "string-util.h"
13 static const char *mount_get_what(const Mount
*m
) {
14 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.what
)
15 return m
->parameters_proc_self_mountinfo
.what
;
16 if (m
->from_fragment
&& m
->parameters_fragment
.what
)
17 return m
->parameters_fragment
.what
;
21 static const char *mount_get_options(const Mount
*m
) {
22 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.options
)
23 return m
->parameters_proc_self_mountinfo
.options
;
24 if (m
->from_fragment
&& m
->parameters_fragment
.options
)
25 return m
->parameters_fragment
.options
;
29 static const char *mount_get_fstype(const Mount
*m
) {
30 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.fstype
)
31 return m
->parameters_proc_self_mountinfo
.fstype
;
32 else if (m
->from_fragment
&& m
->parameters_fragment
.fstype
)
33 return m
->parameters_fragment
.fstype
;
37 static BUS_DEFINE_PROPERTY_GET(property_get_what
, "s", Mount
, mount_get_what
);
38 static BUS_DEFINE_PROPERTY_GET(property_get_options
, "s", Mount
, mount_get_options
);
39 static BUS_DEFINE_PROPERTY_GET(property_get_type
, "s", Mount
, mount_get_fstype
);
40 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result
, mount_result
, MountResult
);
42 const sd_bus_vtable bus_mount_vtable
[] = {
43 SD_BUS_VTABLE_START(0),
44 SD_BUS_PROPERTY("Where", "s", NULL
, offsetof(Mount
, where
), SD_BUS_VTABLE_PROPERTY_CONST
),
45 SD_BUS_PROPERTY("What", "s", property_get_what
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
46 SD_BUS_PROPERTY("Options","s", property_get_options
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
47 SD_BUS_PROPERTY("Type", "s", property_get_type
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
48 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec
, offsetof(Mount
, timeout_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
49 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid
, offsetof(Mount
, control_pid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
50 SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode
, offsetof(Mount
, directory_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
51 SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool
, offsetof(Mount
, sloppy_options
), SD_BUS_VTABLE_PROPERTY_CONST
),
52 SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool
, offsetof(Mount
, lazy_unmount
), SD_BUS_VTABLE_PROPERTY_CONST
),
53 SD_BUS_PROPERTY("ForceUnmount", "b", bus_property_get_bool
, offsetof(Mount
, force_unmount
), SD_BUS_VTABLE_PROPERTY_CONST
),
54 SD_BUS_PROPERTY("ReadWriteOnly", "b", bus_property_get_bool
, offsetof(Mount
, read_write_only
), SD_BUS_VTABLE_PROPERTY_CONST
),
55 SD_BUS_PROPERTY("Result", "s", property_get_result
, offsetof(Mount
, result
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
56 SD_BUS_PROPERTY("UID", "u", bus_property_get_uid
, offsetof(Unit
, ref_uid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
57 SD_BUS_PROPERTY("GID", "u", bus_property_get_gid
, offsetof(Unit
, ref_gid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
58 BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount
, exec_command
[MOUNT_EXEC_MOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
59 BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount
, exec_command
[MOUNT_EXEC_UNMOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
60 BUS_EXEC_COMMAND_VTABLE("ExecRemount", offsetof(Mount
, exec_command
[MOUNT_EXEC_REMOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
64 static int bus_mount_set_transient_property(
67 sd_bus_message
*message
,
69 sd_bus_error
*error
) {
77 flags
|= UNIT_PRIVATE
;
79 if (streq(name
, "Where"))
80 return bus_set_transient_path(u
, name
, &m
->where
, message
, flags
, error
);
82 if (streq(name
, "What"))
83 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.what
, message
, flags
, error
);
85 if (streq(name
, "Options"))
86 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.options
, message
, flags
, error
);
88 if (streq(name
, "Type"))
89 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.fstype
, message
, flags
, error
);
91 if (streq(name
, "TimeoutUSec"))
92 return bus_set_transient_usec_fix_0(u
, name
, &m
->timeout_usec
, message
, flags
, error
);
94 if (streq(name
, "DirectoryMode"))
95 return bus_set_transient_mode_t(u
, name
, &m
->directory_mode
, message
, flags
, error
);
97 if (streq(name
, "SloppyOptions"))
98 return bus_set_transient_bool(u
, name
, &m
->sloppy_options
, message
, flags
, error
);
100 if (streq(name
, "LazyUnmount"))
101 return bus_set_transient_bool(u
, name
, &m
->lazy_unmount
, message
, flags
, error
);
103 if (streq(name
, "ForceUnmount"))
104 return bus_set_transient_bool(u
, name
, &m
->force_unmount
, message
, flags
, error
);
106 if (streq(name
, "ReadWriteOnly"))
107 return bus_set_transient_bool(u
, name
, &m
->read_write_only
, message
, flags
, error
);
112 int bus_mount_set_property(
115 sd_bus_message
*message
,
116 UnitWriteFlags flags
,
117 sd_bus_error
*error
) {
126 r
= bus_cgroup_set_property(u
, &m
->cgroup_context
, name
, message
, flags
, error
);
130 if (u
->transient
&& u
->load_state
== UNIT_STUB
) {
131 /* This is a transient unit, let's load a little more */
133 r
= bus_mount_set_transient_property(m
, name
, message
, flags
, error
);
137 r
= bus_exec_context_set_transient_property(u
, &m
->exec_context
, name
, message
, flags
, error
);
141 r
= bus_kill_context_set_transient_property(u
, &m
->kill_context
, name
, message
, flags
, error
);
149 int bus_mount_commit_properties(Unit
*u
) {
152 unit_realize_cgroup(u
);