]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/systemd/sd-device.h
sd-ipv4acd: fix assertion triggered when an ARP received in STARTED state
[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
85fce6f4 17 along with systemd; If not, see <https://www.gnu.org/licenses/>.
57fa1d09
TG
18***/
19
a1130022 20#include <errno.h>
04c01369 21#include <inttypes.h>
a1130022 22#include <sys/stat.h>
27d13af7 23#include <sys/sysmacros.h>
71d35b6b 24#include <sys/types.h>
57fa1d09 25
b1c097af 26#include "sd-event.h"
b485fd93 27#include "sd-id128.h"
b1c097af 28
57fa1d09
TG
29#include "_sd-common.h"
30
31_SD_BEGIN_DECLARATIONS;
32
33typedef struct sd_device sd_device;
96df036f 34typedef struct sd_device_enumerator sd_device_enumerator;
b1c097af
YW
35typedef struct sd_device_monitor sd_device_monitor;
36
92100f14 37__extension__ typedef enum _SD_ENUM_TYPE_S64(sd_device_action_t) {
a1130022
LP
38 SD_DEVICE_ADD,
39 SD_DEVICE_REMOVE,
40 SD_DEVICE_CHANGE,
41 SD_DEVICE_MOVE,
42 SD_DEVICE_ONLINE,
43 SD_DEVICE_OFFLINE,
44 SD_DEVICE_BIND,
45 SD_DEVICE_UNBIND,
46 _SD_DEVICE_ACTION_MAX,
47 _SD_DEVICE_ACTION_INVALID = -EINVAL,
5476cb98 48 _SD_ENUM_FORCE_S64(DEVICE_ACTION)
a1130022
LP
49} sd_device_action_t;
50
b1c097af
YW
51/* callback */
52
53typedef int (*sd_device_monitor_handler_t)(sd_device_monitor *m, sd_device *device, void *userdata);
96df036f
TG
54
55/* device */
57fa1d09
TG
56
57sd_device *sd_device_ref(sd_device *device);
58sd_device *sd_device_unref(sd_device *device);
59
60int sd_device_new_from_syspath(sd_device **ret, const char *syspath);
61int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum);
62int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *subsystem, const char *sysname);
63int sd_device_new_from_device_id(sd_device **ret, const char *id);
a1130022 64int sd_device_new_from_stat_rdev(sd_device **ret, const struct stat *st);
e418f965
YW
65int sd_device_new_from_devname(sd_device **ret, const char *devname);
66int sd_device_new_from_path(sd_device **ret, const char *path);
bd44a727
YW
67int sd_device_new_from_ifname(sd_device **ret, const char *ifname);
68int sd_device_new_from_ifindex(sd_device **ret, int ifindex);
57fa1d09 69
68a52f59
YW
70int sd_device_new_child(sd_device **ret, sd_device *device, const char *suffix);
71
57fa1d09
TG
72int sd_device_get_parent(sd_device *child, sd_device **ret);
73int sd_device_get_parent_with_subsystem_devtype(sd_device *child, const char *subsystem, const char *devtype, sd_device **ret);
74
75int sd_device_get_syspath(sd_device *device, const char **ret);
76int sd_device_get_subsystem(sd_device *device, const char **ret);
44bc6f3c 77int sd_device_get_driver_subsystem(sd_device *device, const char **ret);
57fa1d09
TG
78int sd_device_get_devtype(sd_device *device, const char **ret);
79int sd_device_get_devnum(sd_device *device, dev_t *devnum);
80int sd_device_get_ifindex(sd_device *device, int *ifindex);
81int sd_device_get_driver(sd_device *device, const char **ret);
82int sd_device_get_devpath(sd_device *device, const char **ret);
83int sd_device_get_devname(sd_device *device, const char **ret);
84int sd_device_get_sysname(sd_device *device, const char **ret);
85int sd_device_get_sysnum(sd_device *device, const char **ret);
a1130022
LP
86int sd_device_get_action(sd_device *device, sd_device_action_t *ret);
87int sd_device_get_seqnum(sd_device *device, uint64_t *ret);
122adcb2 88int sd_device_get_diskseq(sd_device *device, uint64_t *ret);
1ff0164b 89int sd_device_get_device_id(sd_device *device, const char **ret);
57fa1d09 90
5a937ea2 91int sd_device_get_is_initialized(sd_device *device);
4eb5f1db
YW
92int sd_device_get_usec_initialized(sd_device *device, uint64_t *ret);
93int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *ret);
57fa1d09 94
bfd5a068
ZJS
95const char* sd_device_get_tag_first(sd_device *device);
96const char* sd_device_get_tag_next(sd_device *device);
97const char* sd_device_get_current_tag_first(sd_device *device);
98const char* sd_device_get_current_tag_next(sd_device *device);
99const char* sd_device_get_devlink_first(sd_device *device);
100const char* sd_device_get_devlink_next(sd_device *device);
101const char* sd_device_get_property_first(sd_device *device, const char **value);
102const char* sd_device_get_property_next(sd_device *device, const char **value);
103const char* sd_device_get_sysattr_first(sd_device *device);
104const char* sd_device_get_sysattr_next(sd_device *device);
ec9b4f2b
YW
105sd_device *sd_device_get_child_first(sd_device *device, const char **ret_suffix);
106sd_device *sd_device_get_child_next(sd_device *device, const char **ret_suffix);
57fa1d09
TG
107
108int sd_device_has_tag(sd_device *device, const char *tag);
e77b146f 109int sd_device_has_current_tag(sd_device *device, const char *tag);
57fa1d09 110int sd_device_get_property_value(sd_device *device, const char *key, const char **value);
b485fd93 111int sd_device_get_trigger_uuid(sd_device *device, sd_id128_t *ret);
57fa1d09
TG
112int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **_value);
113
8aae9a66 114int sd_device_set_sysattr_value(sd_device *device, const char *sysattr, const char *value);
ea2bc257 115int sd_device_set_sysattr_valuef(sd_device *device, const char *sysattr, const char *format, ...) _sd_printf_(3, 4);
f4d36efa 116int sd_device_trigger(sd_device *device, sd_device_action_t action);
b485fd93 117int sd_device_trigger_with_uuid(sd_device *device, sd_device_action_t action, sd_id128_t *ret_uuid);
f9a726ab 118int sd_device_open(sd_device *device, int flags);
57fa1d09 119
96df036f
TG
120/* device enumerator */
121
122int sd_device_enumerator_new(sd_device_enumerator **ret);
123sd_device_enumerator *sd_device_enumerator_ref(sd_device_enumerator *enumerator);
124sd_device_enumerator *sd_device_enumerator_unref(sd_device_enumerator *enumerator);
125
96df036f
TG
126sd_device *sd_device_enumerator_get_device_first(sd_device_enumerator *enumerator);
127sd_device *sd_device_enumerator_get_device_next(sd_device_enumerator *enumerator);
128sd_device *sd_device_enumerator_get_subsystem_first(sd_device_enumerator *enumerator);
129sd_device *sd_device_enumerator_get_subsystem_next(sd_device_enumerator *enumerator);
130
131int sd_device_enumerator_add_match_subsystem(sd_device_enumerator *enumerator, const char *subsystem, int match);
132int sd_device_enumerator_add_match_sysattr(sd_device_enumerator *enumerator, const char *sysattr, const char *value, int match);
133int sd_device_enumerator_add_match_property(sd_device_enumerator *enumerator, const char *property, const char *value);
fe2a6dce 134int sd_device_enumerator_add_match_property_required(sd_device_enumerator *enumerator, const char *property, const char *value);
96df036f 135int sd_device_enumerator_add_match_sysname(sd_device_enumerator *enumerator, const char *sysname);
94097100 136int sd_device_enumerator_add_nomatch_sysname(sd_device_enumerator *enumerator, const char *sysname);
96df036f
TG
137int sd_device_enumerator_add_match_tag(sd_device_enumerator *enumerator, const char *tag);
138int sd_device_enumerator_add_match_parent(sd_device_enumerator *enumerator, sd_device *parent);
dee5e0b6 139int sd_device_enumerator_allow_uninitialized(sd_device_enumerator *enumerator);
96df036f 140
b1c097af
YW
141/* device monitor */
142
143int sd_device_monitor_new(sd_device_monitor **ret);
144sd_device_monitor *sd_device_monitor_ref(sd_device_monitor *m);
145sd_device_monitor *sd_device_monitor_unref(sd_device_monitor *m);
146
bab889c5 147int sd_device_monitor_get_fd(sd_device_monitor *m);
5ab12505
YW
148int sd_device_monitor_get_events(sd_device_monitor *m);
149int sd_device_monitor_get_timeout(sd_device_monitor *m, uint64_t *ret);
b1c097af 150int sd_device_monitor_set_receive_buffer_size(sd_device_monitor *m, size_t size);
deb2b734 151int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event);
b1c097af
YW
152int sd_device_monitor_detach_event(sd_device_monitor *m);
153sd_event *sd_device_monitor_get_event(sd_device_monitor *m);
bf7712b6 154sd_event_source *sd_device_monitor_get_event_source(sd_device_monitor *m);
39f11aa4
YW
155int sd_device_monitor_set_description(sd_device_monitor *m, const char *description);
156int sd_device_monitor_get_description(sd_device_monitor *m, const char **ret);
ece1e280 157int sd_device_monitor_is_running(sd_device_monitor *m);
deb2b734 158int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata);
b1c097af 159int sd_device_monitor_stop(sd_device_monitor *m);
bab889c5 160int sd_device_monitor_receive(sd_device_monitor *m, sd_device **ret);
b1c097af
YW
161
162int sd_device_monitor_filter_add_match_subsystem_devtype(sd_device_monitor *m, const char *subsystem, const char *devtype);
163int sd_device_monitor_filter_add_match_tag(sd_device_monitor *m, const char *tag);
d9b030b6 164int sd_device_monitor_filter_add_match_sysattr(sd_device_monitor *m, const char *sysattr, const char *value, int match);
b8a0edbb 165int sd_device_monitor_filter_add_match_parent(sd_device_monitor *m, sd_device *device, int match);
b1c097af
YW
166int sd_device_monitor_filter_update(sd_device_monitor *m);
167int sd_device_monitor_filter_remove(sd_device_monitor *m);
168
4afd3348
LP
169_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_device, sd_device_unref);
170_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_device_enumerator, sd_device_enumerator_unref);
b1c097af 171_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_device_monitor, sd_device_monitor_unref);
4afd3348 172
57fa1d09
TG
173_SD_END_DECLARATIONS;
174
175#endif