]> git.proxmox.com Git - systemd.git/blob - src/libudev/libudev-device-private.c
Enable seccomp support on powerpc, ppc64el, and s390x
[systemd.git] / src / libudev / libudev-device-private.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
5 Copyright 2015 Tom Gundersen <teg@jklm.no>
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include "libudev.h"
22
23 #include "device-private.h"
24 #include "libudev-device-internal.h"
25 #include "libudev-private.h"
26
27 int udev_device_tag_index(struct udev_device *udev_device, struct udev_device *udev_device_old, bool add) {
28 sd_device *device_old = NULL;
29 int r;
30
31 assert(udev_device);
32
33 if (udev_device_old)
34 device_old = udev_device_old->device;
35
36 r = device_tag_index(udev_device->device, device_old, add);
37 if (r < 0)
38 return r;
39
40 return 0;
41 }
42
43 int udev_device_update_db(struct udev_device *udev_device) {
44 int r;
45
46 assert(udev_device);
47
48 r = device_update_db(udev_device->device);
49 if (r < 0)
50 return r;
51
52 return 0;
53 }
54
55 int udev_device_delete_db(struct udev_device *udev_device) {
56 int r;
57
58 assert(udev_device);
59
60 r = device_delete_db(udev_device->device);
61 if (r < 0)
62 return r;
63
64 return 0;
65 }
66
67 int udev_device_get_ifindex(struct udev_device *udev_device) {
68 int r, ifindex;
69
70 assert(udev_device);
71
72 r = sd_device_get_ifindex(udev_device->device, &ifindex);
73 if (r < 0)
74 return r;
75
76 return ifindex;
77 }
78
79 const char *udev_device_get_devpath_old(struct udev_device *udev_device) {
80 const char *devpath_old = NULL;
81 int r;
82
83 assert(udev_device);
84
85 r = sd_device_get_property_value(udev_device->device, "DEVPATH_OLD", &devpath_old);
86 if (r < 0 && r != -ENOENT) {
87 errno = -r;
88 return NULL;
89 }
90
91 return devpath_old;
92 }
93
94 mode_t udev_device_get_devnode_mode(struct udev_device *udev_device) {
95 mode_t mode;
96 int r;
97
98 assert(udev_device);
99
100 r = device_get_devnode_mode(udev_device->device, &mode);
101 if (r < 0) {
102 errno = -r;
103 return 0;
104 }
105
106 return mode;
107 }
108
109 uid_t udev_device_get_devnode_uid(struct udev_device *udev_device) {
110 uid_t uid;
111 int r;
112
113 assert(udev_device);
114
115 r = device_get_devnode_uid(udev_device->device, &uid);
116 if (r < 0) {
117 errno = -r;
118 return 0;
119 }
120
121 return uid;
122 }
123
124 gid_t udev_device_get_devnode_gid(struct udev_device *udev_device) {
125 gid_t gid;
126 int r;
127
128 assert(udev_device);
129
130 r = device_get_devnode_gid(udev_device->device, &gid);
131 if (r < 0) {
132 errno = -r;
133 return 0;
134 }
135
136 return gid;
137 }
138
139 void udev_device_ensure_usec_initialized(struct udev_device *udev_device, struct udev_device *udev_device_old) {
140 sd_device *device_old = NULL;
141
142 assert(udev_device);
143
144 if (udev_device_old)
145 device_old = udev_device_old->device;
146
147 device_ensure_usec_initialized(udev_device->device, device_old);
148 }
149
150 char **udev_device_get_properties_envp(struct udev_device *udev_device) {
151 char **envp;
152 int r;
153
154 assert(udev_device);
155
156 r = device_get_properties_strv(udev_device->device, &envp);
157 if (r < 0) {
158 errno = -r;
159 return NULL;
160 }
161
162 return envp;
163 }
164
165 ssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device, const char **buf) {
166 const char *nulstr;
167 size_t len;
168 int r;
169
170 assert(udev_device);
171 assert(buf);
172
173 r = device_get_properties_nulstr(udev_device->device, (const uint8_t **)&nulstr, &len);
174 if (r < 0)
175 return r;
176
177 *buf = nulstr;
178
179 return len;
180 }
181
182 int udev_device_get_devlink_priority(struct udev_device *udev_device) {
183 int priority, r;
184
185 assert(udev_device);
186
187 r = device_get_devlink_priority(udev_device->device, &priority);
188 if (r < 0)
189 return r;
190
191 return priority;
192 }
193
194 int udev_device_get_watch_handle(struct udev_device *udev_device) {
195 int handle, r;
196
197 assert(udev_device);
198
199 r = device_get_watch_handle(udev_device->device, &handle);
200 if (r < 0)
201 return r;
202
203 return handle;
204 }
205
206 void udev_device_set_is_initialized(struct udev_device *udev_device) {
207 assert(udev_device);
208
209 device_set_is_initialized(udev_device->device);
210 }
211
212 int udev_device_rename(struct udev_device *udev_device, const char *name) {
213 int r;
214
215 assert(udev_device);
216
217 r = device_rename(udev_device->device, name);
218 if (r < 0)
219 return r;
220
221 return 0;
222 }
223
224 struct udev_device *udev_device_shallow_clone(struct udev_device *old_device) {
225 struct udev_device *device;
226 int r;
227
228 assert(old_device);
229
230 device = udev_device_new(old_device->udev);
231 if (!device)
232 return NULL;
233
234 r = device_shallow_clone(old_device->device, &device->device);
235 if (r < 0) {
236 udev_device_unref(device);
237 errno = -r;
238 return NULL;
239 }
240
241 return device;
242 }
243
244 struct udev_device *udev_device_clone_with_db(struct udev_device *udev_device_old) {
245 struct udev_device *udev_device;
246 int r;
247
248 assert(udev_device_old);
249
250 udev_device = udev_device_new(udev_device_old->udev);
251 if (!udev_device)
252 return NULL;
253
254 r = device_clone_with_db(udev_device_old->device, &udev_device->device);
255 if (r < 0) {
256 udev_device_unref(udev_device);
257 errno = -r;
258 return NULL;
259 }
260
261 return udev_device;
262 }
263
264 struct udev_device *udev_device_new_from_nulstr(struct udev *udev, char *nulstr, ssize_t buflen) {
265 struct udev_device *device;
266 int r;
267
268 device = udev_device_new(udev);
269 if (!device)
270 return NULL;
271
272 r = device_new_from_nulstr(&device->device, (uint8_t*)nulstr, buflen);
273 if (r < 0) {
274 udev_device_unref(device);
275 errno = -r;
276 return NULL;
277 }
278
279 return device;
280 }
281
282 struct udev_device *udev_device_new_from_synthetic_event(struct udev *udev, const char *syspath, const char *action) {
283 struct udev_device *device;
284 int r;
285
286 device = udev_device_new(udev);
287 if (!device)
288 return NULL;
289
290 r = device_new_from_synthetic_event(&device->device, syspath, action);
291 if (r < 0) {
292 udev_device_unref(device);
293 errno = -r;
294 return NULL;
295 }
296
297 return device;
298 }
299
300 int udev_device_copy_properties(struct udev_device *udev_device_dst, struct udev_device *udev_device_src) {
301 int r;
302
303 assert(udev_device_dst);
304 assert(udev_device_src);
305
306 r = device_copy_properties(udev_device_dst->device, udev_device_src->device);
307 if (r < 0)
308 return r;
309
310 return 0;
311 }
312
313 const char *udev_device_get_id_filename(struct udev_device *udev_device) {
314 const char *filename;
315 int r;
316
317 assert(udev_device);
318
319 r = device_get_id_filename(udev_device->device, &filename);
320 if (r < 0) {
321 errno = -r;
322 return NULL;
323 }
324
325 return filename;
326 }
327
328 int udev_device_set_watch_handle(struct udev_device *udev_device, int handle) {
329
330 assert(udev_device);
331
332 device_set_watch_handle(udev_device->device, handle);
333
334 return 0;
335 }
336
337 void udev_device_set_db_persist(struct udev_device *udev_device) {
338 assert(udev_device);
339
340 device_set_db_persist(udev_device->device);
341 }
342
343 int udev_device_set_devlink_priority(struct udev_device *udev_device, int priority) {
344 assert(udev_device);
345
346 device_set_devlink_priority(udev_device->device, priority);
347
348 return 0;
349 }
350
351 int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink) {
352 int r;
353
354 assert(udev_device);
355
356 r = device_add_devlink(udev_device->device, devlink);
357 if (r < 0)
358 return r;
359
360 return 0;
361 }
362
363 int udev_device_add_property(struct udev_device *udev_device, const char *property, const char *value) {
364 int r;
365
366 assert(udev_device);
367
368 r = device_add_property(udev_device->device, property, value);
369 if (r < 0)
370 return r;
371
372 return 0;
373 }
374
375 int udev_device_add_tag(struct udev_device *udev_device, const char *tag) {
376 int r;
377
378 assert(udev_device);
379
380 r = device_add_tag(udev_device->device, tag);
381 if (r < 0)
382 return r;
383
384 return 0;
385 }
386
387 void udev_device_remove_tag(struct udev_device *udev_device, const char *tag) {
388 assert(udev_device);
389
390 device_remove_tag(udev_device->device, tag);
391 }
392
393 void udev_device_cleanup_tags_list(struct udev_device *udev_device) {
394 assert(udev_device);
395
396 device_cleanup_tags(udev_device->device);
397 }
398
399 void udev_device_cleanup_devlinks_list(struct udev_device *udev_device) {
400 assert(udev_device);
401
402 device_cleanup_devlinks(udev_device->device);
403 }
404
405 void udev_device_set_info_loaded(struct udev_device *udev_device) {
406 assert(udev_device);
407
408 device_seal(udev_device->device);
409 }
410
411 void udev_device_read_db(struct udev_device *udev_device) {
412 assert(udev_device);
413
414 device_read_db_force(udev_device->device);
415 }