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