]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-mount.c
relicense to LGPLv2.1 (with exceptions)
[thirdparty/systemd.git] / src / core / dbus-mount.c
CommitLineData
d6c9574f 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4139c1b2
LP
2
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
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
4139c1b2
LP
11 (at your option) any later version.
12
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
5430f7f2 16 Lesser General Public License for more details.
4139c1b2 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
4139c1b2
LP
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
4e85aff4
LP
22#include <errno.h>
23
4139c1b2
LP
24#include "dbus-unit.h"
25#include "dbus-mount.h"
26#include "dbus-execute.h"
bfebab7f 27#include "dbus-common.h"
4139c1b2 28
4288f619
LP
29#define BUS_MOUNT_INTERFACE \
30 " <interface name=\"org.freedesktop.systemd1.Mount\">\n" \
31 " <property name=\"Where\" type=\"s\" access=\"read\"/>\n" \
32 " <property name=\"What\" type=\"s\" access=\"read\"/>\n" \
33 " <property name=\"Options\" type=\"s\" access=\"read\"/>\n" \
34 " <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
35 " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
fe68089d
LP
36 BUS_EXEC_COMMAND_INTERFACE("ExecMount") \
37 BUS_EXEC_COMMAND_INTERFACE("ExecUnmount") \
38 BUS_EXEC_COMMAND_INTERFACE("ExecRemount") \
4288f619 39 BUS_EXEC_CONTEXT_INTERFACE \
4288f619 40 " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
5bd07073 41 " <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
9d2f5178 42 " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
4288f619
LP
43 " </interface>\n"
44
45#define INTROSPECTION \
46 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
47 "<node>\n" \
48 BUS_UNIT_INTERFACE \
49 BUS_MOUNT_INTERFACE \
50 BUS_PROPERTIES_INTERFACE \
c4e2ceae 51 BUS_PEER_INTERFACE \
4288f619
LP
52 BUS_INTROSPECTABLE_INTERFACE \
53 "</node>\n"
54
05feefe0
LP
55#define INTERFACES_LIST \
56 BUS_UNIT_INTERFACES_LIST \
57 "org.freedesktop.systemd1.Mount\0"
58
9a60da28 59const char bus_mount_interface[] _introspect_("Mount") = BUS_MOUNT_INTERFACE;
4139c1b2 60
c4e2ceae
LP
61const char bus_mount_invalidating_properties[] =
62 "What\0"
63 "Options\0"
64 "Type\0"
65 "ExecMount\0"
66 "ExecUnmount\0"
67 "ExecRemount\0"
9d2f5178
LP
68 "ControlPID\0"
69 "Result\0";
c4e2ceae 70
bfebab7f 71static int bus_mount_append_what(DBusMessageIter *i, const char *property, void *data) {
4e85aff4
LP
72 Mount *m = data;
73 const char *d;
74
4e85aff4
LP
75 assert(i);
76 assert(property);
77 assert(m);
78
79 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
80 d = m->parameters_proc_self_mountinfo.what;
81 else if (m->from_fragment && m->parameters_fragment.what)
82 d = m->parameters_fragment.what;
83 else if (m->from_etc_fstab && m->parameters_etc_fstab.what)
84 d = m->parameters_etc_fstab.what;
85 else
86 d = "";
87
88 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
89 return -ENOMEM;
90
91 return 0;
92}
93
bfebab7f 94static int bus_mount_append_options(DBusMessageIter *i, const char *property, void *data) {
4e85aff4
LP
95 Mount *m = data;
96 const char *d;
97
4e85aff4
LP
98 assert(i);
99 assert(property);
100 assert(m);
101
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;
106 else if (m->from_etc_fstab && m->parameters_etc_fstab.options)
107 d = m->parameters_etc_fstab.options;
108 else
109 d = "";
110
111 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
112 return -ENOMEM;
113
114 return 0;
115}
116
bfebab7f 117static int bus_mount_append_type(DBusMessageIter *i, const char *property, void *data) {
4e85aff4
LP
118 Mount *m = data;
119 const char *d;
120
4e85aff4
LP
121 assert(i);
122 assert(property);
123 assert(m);
124
125 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
126 d = m->parameters_proc_self_mountinfo.fstype;
127 else if (m->from_fragment && m->parameters_fragment.fstype)
128 d = m->parameters_fragment.fstype;
129 else if (m->from_etc_fstab && m->parameters_etc_fstab.fstype)
130 d = m->parameters_etc_fstab.fstype;
131 else
132 d = "";
133
134 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
135 return -ENOMEM;
136
137 return 0;
138}
139
9d2f5178
LP
140static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_mount_append_mount_result, mount_result, MountResult);
141
d200735e
MS
142static const BusProperty bus_mount_properties[] = {
143 { "Where", bus_property_append_string, "s", offsetof(Mount, where), true },
144 { "What", bus_mount_append_what, "s", 0 },
145 { "Options", bus_mount_append_options, "s", 0 },
146 { "Type", bus_mount_append_type, "s", 0 },
147 { "TimeoutUSec", bus_property_append_usec, "t", offsetof(Mount, timeout_usec) },
148 BUS_EXEC_COMMAND_PROPERTY("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), false),
149 BUS_EXEC_COMMAND_PROPERTY("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), false),
150 BUS_EXEC_COMMAND_PROPERTY("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), false),
151 { "ControlPID", bus_property_append_pid, "u", offsetof(Mount, control_pid) },
152 { "DirectoryMode", bus_property_append_mode, "u", offsetof(Mount, directory_mode) },
9d2f5178 153 { "Result", bus_mount_append_mount_result, "s", offsetof(Mount, result) },
d200735e
MS
154 { NULL, }
155};
156
5e8d1c9a 157DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
ac155bb8 158 Mount *m = MOUNT(u);
d200735e
MS
159
160 const BusBoundProperties bps[] = {
161 { "org.freedesktop.systemd1.Unit", bus_unit_properties, u },
162 { "org.freedesktop.systemd1.Mount", bus_mount_properties, m },
163 { "org.freedesktop.systemd1.Mount", bus_exec_context_properties, &m->exec_context },
164 { NULL, }
4139c1b2
LP
165 };
166
d200735e 167 return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps );
4139c1b2 168}