]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/systemd/sd-device.h
license: LGPL-2.1+ -> LGPL-2.1-or-later
[thirdparty/systemd.git] / src / systemd / sd-device.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
57fa1d09
TG
2#ifndef foosddevicehfoo
3#define foosddevicehfoo
4
5/***
57fa1d09
TG
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18***/
19
04c01369 20#include <inttypes.h>
27d13af7 21#include <sys/sysmacros.h>
71d35b6b 22#include <sys/types.h>
57fa1d09 23
b1c097af
YW
24#include "sd-event.h"
25
57fa1d09
TG
26#include "_sd-common.h"
27
28_SD_BEGIN_DECLARATIONS;
29
30typedef struct sd_device sd_device;
96df036f 31typedef struct sd_device_enumerator sd_device_enumerator;
b1c097af
YW
32typedef struct sd_device_monitor sd_device_monitor;
33
34/* callback */
35
36typedef int (*sd_device_monitor_handler_t)(sd_device_monitor *m, sd_device *device, void *userdata);
96df036f
TG
37
38/* device */
57fa1d09
TG
39
40sd_device *sd_device_ref(sd_device *device);
41sd_device *sd_device_unref(sd_device *device);
42
43int sd_device_new_from_syspath(sd_device **ret, const char *syspath);
44int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum);
45int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *subsystem, const char *sysname);
46int sd_device_new_from_device_id(sd_device **ret, const char *id);
47
48int sd_device_get_parent(sd_device *child, sd_device **ret);
49int sd_device_get_parent_with_subsystem_devtype(sd_device *child, const char *subsystem, const char *devtype, sd_device **ret);
50
51int sd_device_get_syspath(sd_device *device, const char **ret);
52int sd_device_get_subsystem(sd_device *device, const char **ret);
53int sd_device_get_devtype(sd_device *device, const char **ret);
54int sd_device_get_devnum(sd_device *device, dev_t *devnum);
55int sd_device_get_ifindex(sd_device *device, int *ifindex);
56int sd_device_get_driver(sd_device *device, const char **ret);
57int sd_device_get_devpath(sd_device *device, const char **ret);
58int sd_device_get_devname(sd_device *device, const char **ret);
59int sd_device_get_sysname(sd_device *device, const char **ret);
60int sd_device_get_sysnum(sd_device *device, const char **ret);
61
5a937ea2 62int sd_device_get_is_initialized(sd_device *device);
57fa1d09
TG
63int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *usec);
64
65const char *sd_device_get_tag_first(sd_device *device);
66const char *sd_device_get_tag_next(sd_device *device);
e77b146f
LP
67const char *sd_device_get_current_tag_first(sd_device *device);
68const char *sd_device_get_current_tag_next(sd_device *device);
57fa1d09
TG
69const char *sd_device_get_devlink_first(sd_device *device);
70const char *sd_device_get_devlink_next(sd_device *device);
71const char *sd_device_get_property_first(sd_device *device, const char **value);
72const char *sd_device_get_property_next(sd_device *device, const char **value);
73const char *sd_device_get_sysattr_first(sd_device *device);
74const char *sd_device_get_sysattr_next(sd_device *device);
75
76int sd_device_has_tag(sd_device *device, const char *tag);
e77b146f 77int sd_device_has_current_tag(sd_device *device, const char *tag);
57fa1d09
TG
78int sd_device_get_property_value(sd_device *device, const char *key, const char **value);
79int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **_value);
80
8aae9a66 81int sd_device_set_sysattr_value(sd_device *device, const char *sysattr, const char *value);
ea2bc257 82int sd_device_set_sysattr_valuef(sd_device *device, const char *sysattr, const char *format, ...) _sd_printf_(3, 4);
57fa1d09 83
96df036f
TG
84/* device enumerator */
85
86int sd_device_enumerator_new(sd_device_enumerator **ret);
87sd_device_enumerator *sd_device_enumerator_ref(sd_device_enumerator *enumerator);
88sd_device_enumerator *sd_device_enumerator_unref(sd_device_enumerator *enumerator);
89
96df036f
TG
90sd_device *sd_device_enumerator_get_device_first(sd_device_enumerator *enumerator);
91sd_device *sd_device_enumerator_get_device_next(sd_device_enumerator *enumerator);
92sd_device *sd_device_enumerator_get_subsystem_first(sd_device_enumerator *enumerator);
93sd_device *sd_device_enumerator_get_subsystem_next(sd_device_enumerator *enumerator);
94
95int sd_device_enumerator_add_match_subsystem(sd_device_enumerator *enumerator, const char *subsystem, int match);
96int sd_device_enumerator_add_match_sysattr(sd_device_enumerator *enumerator, const char *sysattr, const char *value, int match);
97int sd_device_enumerator_add_match_property(sd_device_enumerator *enumerator, const char *property, const char *value);
98int sd_device_enumerator_add_match_sysname(sd_device_enumerator *enumerator, const char *sysname);
99int sd_device_enumerator_add_match_tag(sd_device_enumerator *enumerator, const char *tag);
100int sd_device_enumerator_add_match_parent(sd_device_enumerator *enumerator, sd_device *parent);
dee5e0b6 101int sd_device_enumerator_allow_uninitialized(sd_device_enumerator *enumerator);
96df036f 102
b1c097af
YW
103/* device monitor */
104
105int sd_device_monitor_new(sd_device_monitor **ret);
106sd_device_monitor *sd_device_monitor_ref(sd_device_monitor *m);
107sd_device_monitor *sd_device_monitor_unref(sd_device_monitor *m);
108
109int sd_device_monitor_set_receive_buffer_size(sd_device_monitor *m, size_t size);
deb2b734 110int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event);
b1c097af
YW
111int sd_device_monitor_detach_event(sd_device_monitor *m);
112sd_event *sd_device_monitor_get_event(sd_device_monitor *m);
bf7712b6 113sd_event_source *sd_device_monitor_get_event_source(sd_device_monitor *m);
deb2b734 114int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata);
b1c097af
YW
115int sd_device_monitor_stop(sd_device_monitor *m);
116
117int sd_device_monitor_filter_add_match_subsystem_devtype(sd_device_monitor *m, const char *subsystem, const char *devtype);
118int sd_device_monitor_filter_add_match_tag(sd_device_monitor *m, const char *tag);
119int sd_device_monitor_filter_update(sd_device_monitor *m);
120int sd_device_monitor_filter_remove(sd_device_monitor *m);
121
4afd3348
LP
122_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_device, sd_device_unref);
123_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_device_enumerator, sd_device_enumerator_unref);
b1c097af 124_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_device_monitor, sd_device_monitor_unref);
4afd3348 125
57fa1d09
TG
126_SD_END_DECLARATIONS;
127
128#endif