]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd/sd-device/device-internal.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / libsystemd / sd-device / device-internal.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
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>
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include "hashmap.h"
25 #include "set.h"
26
27 struct sd_device {
28 uint64_t n_ref;
29
30 sd_device *parent;
31 bool parent_set; /* no need to try to reload parent */
32
33 OrderedHashmap *properties;
34 Iterator properties_iterator;
35 uint64_t properties_generation; /* changes whenever the properties are changed */
36 uint64_t properties_iterator_generation; /* generation when iteration was started */
37
38 /* the subset of the properties that should be written to the db */
39 OrderedHashmap *properties_db;
40
41 Hashmap *sysattr_values; /* cached sysattr values */
42
43 Set *sysattrs; /* names of sysattrs */
44 Iterator sysattrs_iterator;
45 bool sysattrs_read; /* don't try to re-read sysattrs once read */
46
47 Set *tags;
48 Iterator tags_iterator;
49 uint64_t tags_generation; /* changes whenever the tags are changed */
50 uint64_t tags_iterator_generation; /* generation when iteration was started */
51 bool property_tags_outdated; /* need to update TAGS= property */
52
53 Set *devlinks;
54 Iterator devlinks_iterator;
55 uint64_t devlinks_generation; /* changes whenever the devlinks are changed */
56 uint64_t devlinks_iterator_generation; /* generation when iteration was started */
57 bool property_devlinks_outdated; /* need to update DEVLINKS= property */
58 int devlink_priority;
59
60 char **properties_strv; /* the properties hashmap as a strv */
61 uint8_t *properties_nulstr; /* the same as a nulstr */
62 size_t properties_nulstr_len;
63 bool properties_buf_outdated; /* need to reread hashmap */
64
65 int watch_handle;
66
67 char *syspath;
68 const char *devpath;
69 const char *sysnum;
70 char *sysname;
71 bool sysname_set; /* don't reread sysname */
72
73 char *devtype;
74 int ifindex;
75 char *devname;
76 dev_t devnum;
77
78 char *subsystem;
79 bool subsystem_set; /* don't reread subsystem */
80 char *driver_subsystem; /* only set for the 'drivers' subsystem */
81 bool driver_subsystem_set; /* don't reread subsystem */
82 char *driver;
83 bool driver_set; /* don't reread driver */
84
85 char *id_filename;
86
87 bool is_initialized;
88 uint64_t usec_initialized;
89
90 mode_t devmode;
91 uid_t devuid;
92 gid_t devgid;
93
94 bool uevent_loaded; /* don't reread uevent */
95 bool db_loaded; /* don't reread db */
96
97 bool sealed; /* don't read more information from uevent/db */
98 bool db_persist; /* don't clean up the db when switching from initrd to real root */
99 };
100
101 typedef enum DeviceAction {
102 DEVICE_ACTION_ADD,
103 DEVICE_ACTION_REMOVE,
104 DEVICE_ACTION_CHANGE,
105 DEVICE_ACTION_MOVE,
106 DEVICE_ACTION_ONLINE,
107 DEVICE_ACTION_OFFLINE,
108 DEVICE_ACTION_BIND,
109 DEVICE_ACTION_UNBIND,
110 _DEVICE_ACTION_MAX,
111 _DEVICE_ACTION_INVALID = -1,
112 } DeviceAction;
113
114 int device_new_aux(sd_device **ret);
115 int device_add_property_aux(sd_device *device, const char *key, const char *value, bool db);
116 int device_add_property_internal(sd_device *device, const char *key, const char *value);
117 int device_read_uevent_file(sd_device *device);
118 int device_read_db_aux(sd_device *device, bool force);
119
120 int device_set_syspath(sd_device *device, const char *_syspath, bool verify);
121 int device_set_ifindex(sd_device *device, const char *ifindex);
122 int device_set_devmode(sd_device *device, const char *devmode);
123 int device_set_devname(sd_device *device, const char *_devname);
124 int device_set_devtype(sd_device *device, const char *_devtype);
125 int device_set_devnum(sd_device *device, const char *major, const char *minor);
126 int device_set_subsystem(sd_device *device, const char *_subsystem);
127 int device_set_driver(sd_device *device, const char *_driver);
128 int device_set_usec_initialized(sd_device *device, const char *initialized);
129
130 DeviceAction device_action_from_string(const char *s) _pure_;
131 const char *device_action_to_string(DeviceAction a) _const_;