]> git.ipfire.org Git - thirdparty/systemd.git/blame - 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
CommitLineData
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>
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
57fa1d09
TG
24#include "hashmap.h"
25#include "set.h"
26
27struct 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
13e785f7 38 /* the subset of the properties that should be written to the db */
57fa1d09
TG
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 */
de7e983e
TG
80 char *driver_subsystem; /* only set for the 'drivers' subsystem */
81 bool driver_subsystem_set; /* don't reread subsystem */
57fa1d09
TG
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
101typedef 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,
9a39e1ce
LP
108 DEVICE_ACTION_BIND,
109 DEVICE_ACTION_UNBIND,
57fa1d09
TG
110 _DEVICE_ACTION_MAX,
111 _DEVICE_ACTION_INVALID = -1,
112} DeviceAction;
113
114int device_new_aux(sd_device **ret);
115int device_add_property_aux(sd_device *device, const char *key, const char *value, bool db);
116int device_add_property_internal(sd_device *device, const char *key, const char *value);
117int device_read_uevent_file(sd_device *device);
107f2e25 118int device_read_db_aux(sd_device *device, bool force);
57fa1d09
TG
119
120int device_set_syspath(sd_device *device, const char *_syspath, bool verify);
121int device_set_ifindex(sd_device *device, const char *ifindex);
122int device_set_devmode(sd_device *device, const char *devmode);
123int device_set_devname(sd_device *device, const char *_devname);
124int device_set_devtype(sd_device *device, const char *_devtype);
125int device_set_devnum(sd_device *device, const char *major, const char *minor);
126int device_set_subsystem(sd_device *device, const char *_subsystem);
127int device_set_driver(sd_device *device, const char *_driver);
128int device_set_usec_initialized(sd_device *device, const char *initialized);
129
130DeviceAction device_action_from_string(const char *s) _pure_;
131const char *device_action_to_string(DeviceAction a) _const_;