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