]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd/sd-device/device-internal.h
tree-wide: use unsigned for refcount
[thirdparty/systemd.git] / src / libsystemd / sd-device / device-internal.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include "sd-device.h"
5
6 #include "hashmap.h"
7 #include "set.h"
8
9 struct sd_device {
10 unsigned n_ref;
11
12 sd_device *parent;
13 bool parent_set; /* no need to try to reload parent */
14
15 OrderedHashmap *properties;
16 Iterator properties_iterator;
17 uint64_t properties_generation; /* changes whenever the properties are changed */
18 uint64_t properties_iterator_generation; /* generation when iteration was started */
19
20 /* the subset of the properties that should be written to the db */
21 OrderedHashmap *properties_db;
22
23 Hashmap *sysattr_values; /* cached sysattr values */
24
25 Set *sysattrs; /* names of sysattrs */
26 Iterator sysattrs_iterator;
27 bool sysattrs_read; /* don't try to re-read sysattrs once read */
28
29 Set *tags;
30 Iterator tags_iterator;
31 uint64_t tags_generation; /* changes whenever the tags are changed */
32 uint64_t tags_iterator_generation; /* generation when iteration was started */
33 bool property_tags_outdated; /* need to update TAGS= property */
34
35 Set *devlinks;
36 Iterator devlinks_iterator;
37 uint64_t devlinks_generation; /* changes whenever the devlinks are changed */
38 uint64_t devlinks_iterator_generation; /* generation when iteration was started */
39 bool property_devlinks_outdated; /* need to update DEVLINKS= property */
40 int devlink_priority;
41
42 char **properties_strv; /* the properties hashmap as a strv */
43 uint8_t *properties_nulstr; /* the same as a nulstr */
44 size_t properties_nulstr_len;
45 bool properties_buf_outdated; /* need to reread hashmap */
46
47 int watch_handle;
48
49 char *syspath;
50 const char *devpath;
51 const char *sysnum;
52 char *sysname;
53 bool sysname_set; /* don't reread sysname */
54
55 char *devtype;
56 int ifindex;
57 char *devname;
58 dev_t devnum;
59
60 char *subsystem;
61 bool subsystem_set; /* don't reread subsystem */
62 char *driver_subsystem; /* only set for the 'drivers' subsystem */
63 bool driver_subsystem_set; /* don't reread subsystem */
64 char *driver;
65 bool driver_set; /* don't reread driver */
66
67 char *id_filename;
68
69 bool is_initialized;
70 uint64_t usec_initialized;
71
72 mode_t devmode;
73 uid_t devuid;
74 gid_t devgid;
75
76 bool uevent_loaded; /* don't reread uevent */
77 bool db_loaded; /* don't reread db */
78
79 bool sealed; /* don't read more information from uevent/db */
80 bool db_persist; /* don't clean up the db when switching from initrd to real root */
81 };
82
83 typedef enum DeviceAction {
84 DEVICE_ACTION_ADD,
85 DEVICE_ACTION_REMOVE,
86 DEVICE_ACTION_CHANGE,
87 DEVICE_ACTION_MOVE,
88 DEVICE_ACTION_ONLINE,
89 DEVICE_ACTION_OFFLINE,
90 DEVICE_ACTION_BIND,
91 DEVICE_ACTION_UNBIND,
92 _DEVICE_ACTION_MAX,
93 _DEVICE_ACTION_INVALID = -1,
94 } DeviceAction;
95
96 int device_new_aux(sd_device **ret);
97 int device_add_property_aux(sd_device *device, const char *key, const char *value, bool db);
98 int device_add_property_internal(sd_device *device, const char *key, const char *value);
99 int device_read_uevent_file(sd_device *device);
100 int device_read_db_aux(sd_device *device, bool force);
101
102 int device_set_syspath(sd_device *device, const char *_syspath, bool verify);
103 int device_set_ifindex(sd_device *device, const char *ifindex);
104 int device_set_devmode(sd_device *device, const char *devmode);
105 int device_set_devname(sd_device *device, const char *_devname);
106 int device_set_devtype(sd_device *device, const char *_devtype);
107 int device_set_devnum(sd_device *device, const char *major, const char *minor);
108 int device_set_subsystem(sd_device *device, const char *_subsystem);
109 int device_set_driver(sd_device *device, const char *_driver);
110 int device_set_usec_initialized(sd_device *device, const char *initialized);
111
112 DeviceAction device_action_from_string(const char *s) _pure_;
113 const char *device_action_to_string(DeviceAction a) _const_;