1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "dbus-unit.h"
25 #include "dbus-mount.h"
26 #include "dbus-kill.h"
27 #include "dbus-execute.h"
28 #include "dbus-common.h"
30 #define BUS_MOUNT_INTERFACE \
31 " <interface name=\"org.freedesktop.systemd1.Mount\">\n" \
32 " <property name=\"Where\" type=\"s\" access=\"read\"/>\n" \
33 " <property name=\"What\" type=\"s\" access=\"read\"/>\n" \
34 " <property name=\"Options\" type=\"s\" access=\"read\"/>\n" \
35 " <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
36 " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
37 BUS_EXEC_COMMAND_INTERFACE("ExecMount") \
38 BUS_EXEC_COMMAND_INTERFACE("ExecUnmount") \
39 BUS_EXEC_COMMAND_INTERFACE("ExecRemount") \
40 BUS_EXEC_CONTEXT_INTERFACE \
41 BUS_KILL_CONTEXT_INTERFACE \
42 " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
43 " <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
44 " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
47 #define INTROSPECTION \
48 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
52 BUS_PROPERTIES_INTERFACE \
54 BUS_INTROSPECTABLE_INTERFACE \
57 #define INTERFACES_LIST \
58 BUS_UNIT_INTERFACES_LIST \
59 "org.freedesktop.systemd1.Mount\0"
61 const char bus_mount_interface[] _introspect_("Mount") = BUS_MOUNT_INTERFACE;
63 const char bus_mount_invalidating_properties[] =
73 static int bus_mount_append_what(DBusMessageIter *i, const char *property, void *data) {
81 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
82 d = m->parameters_proc_self_mountinfo.what;
83 else if (m->from_fragment && m->parameters_fragment.what)
84 d = m->parameters_fragment.what;
88 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
94 static int bus_mount_append_options(DBusMessageIter *i, const char *property, void *data) {
102 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
103 d = m->parameters_proc_self_mountinfo.options;
104 else if (m->from_fragment && m->parameters_fragment.options)
105 d = m->parameters_fragment.options;
109 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
115 static int bus_mount_append_type(DBusMessageIter *i, const char *property, void *data) {
123 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
124 d = m->parameters_proc_self_mountinfo.fstype;
125 else if (m->from_fragment && m->parameters_fragment.fstype)
126 d = m->parameters_fragment.fstype;
130 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
136 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_mount_append_mount_result, mount_result, MountResult);
138 static const BusProperty bus_mount_properties[] = {
139 { "Where", bus_property_append_string, "s", offsetof(Mount, where), true },
140 { "What", bus_mount_append_what, "s", 0 },
141 { "Options", bus_mount_append_options, "s", 0 },
142 { "Type", bus_mount_append_type, "s", 0 },
143 { "TimeoutUSec", bus_property_append_usec, "t", offsetof(Mount, timeout_usec) },
144 BUS_EXEC_COMMAND_PROPERTY("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), false),
145 BUS_EXEC_COMMAND_PROPERTY("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), false),
146 BUS_EXEC_COMMAND_PROPERTY("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), false),
147 { "ControlPID", bus_property_append_pid, "u", offsetof(Mount, control_pid) },
148 { "DirectoryMode", bus_property_append_mode, "u", offsetof(Mount, directory_mode) },
149 { "Result", bus_mount_append_mount_result, "s", offsetof(Mount, result) },
153 DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
156 const BusBoundProperties bps[] = {
157 { "org.freedesktop.systemd1.Unit", bus_unit_properties, u },
158 { "org.freedesktop.systemd1.Mount", bus_mount_properties, m },
159 { "org.freedesktop.systemd1.Mount", bus_exec_context_properties, &m->exec_context },
160 { "org.freedesktop.systemd1.Mount", bus_kill_context_properties, &m->kill_context },
164 return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps );