| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "sd-device.h" |
| 5 |
|
| 6 |
#include "sd-forward.h" |
| 7 |
#include "iterator.h" |
| 8 |
|
| 9 |
#define OLDEST_UDEV_DATABASE_VERSION 1 |
| 10 |
#define LATEST_UDEV_DATABASE_VERSION 1 |
| 11 |
|
| 12 |
struct sd_device { |
| 13 |
unsigned n_ref; |
| 14 |
|
| 15 |
/* syspath */ |
| 16 |
char *syspath; |
| 17 |
const char *devpath; |
| 18 |
const char *sysnum; |
| 19 |
char *sysname; |
| 20 |
|
| 21 |
/* only set when device is passed through netlink */ |
| 22 |
sd_device_action_t action; |
| 23 |
uint64_t seqnum; |
| 24 |
|
| 25 |
/* basic kernel properties */ |
| 26 |
char *subsystem; |
| 27 |
char *driver_subsystem; /* only set for the 'drivers' subsystem */ |
| 28 |
char *driver; |
| 29 |
char *devtype; |
| 30 |
|
| 31 |
/* device node properties */ |
| 32 |
char *devname; |
| 33 |
dev_t devnum; |
| 34 |
mode_t devmode; |
| 35 |
uid_t devuid; |
| 36 |
gid_t devgid; |
| 37 |
|
| 38 |
/* block device properties */ |
| 39 |
uint64_t diskseq; /* Block device sequence number, monothonically incremented by the kernel on create/attach */ |
| 40 |
|
| 41 |
/* network interface properties */ |
| 42 |
int ifindex; |
| 43 |
|
| 44 |
/* determined by devnnum, ifindex, subsystem, and sysname */ |
| 45 |
char *device_id; |
| 46 |
|
| 47 |
/* sysfs attributes */ |
| 48 |
Hashmap *sysattr_values; /* cached sysattr values */ |
| 49 |
Set *sysattrs; /* names of sysattrs */ |
| 50 |
Iterator sysattrs_iterator; |
| 51 |
|
| 52 |
/* The database version indicates the supported features by the udev database. |
| 53 |
* This is saved and parsed in V field. |
| 54 |
* |
| 55 |
* 0: None of the following features are supported (systemd version <= 246), unsupported since v261. |
| 56 |
* 1: The current tags (Q) and the database version (V) features are implemented (>= 247). |
| 57 |
*/ |
| 58 |
unsigned database_version; |
| 59 |
|
| 60 |
/* when device is initialized by udevd */ |
| 61 |
usec_t usec_initialized; |
| 62 |
|
| 63 |
/* properties */ |
| 64 |
OrderedHashmap *properties; /* all properties set from uevent and by udevd */ |
| 65 |
Iterator properties_iterator; |
| 66 |
uint64_t properties_generation; /* changes whenever the properties are changed */ |
| 67 |
uint64_t properties_iterator_generation; /* generation when iteration was started */ |
| 68 |
OrderedHashmap *properties_db; /* the subset of the properties that should be written to the db */ |
| 69 |
char **properties_strv; /* the properties hashmap as a strv */ |
| 70 |
char *properties_nulstr; /* the same as a nulstr */ |
| 71 |
size_t properties_nulstr_len; |
| 72 |
|
| 73 |
/* TAG keyword */ |
| 74 |
Set *all_tags, *current_tags; |
| 75 |
Iterator all_tags_iterator, current_tags_iterator; |
| 76 |
uint64_t all_tags_iterator_generation, current_tags_iterator_generation; /* generation when iteration was started */ |
| 77 |
uint64_t tags_generation; /* changes whenever the tags are changed */ |
| 78 |
|
| 79 |
/* SYMLINK keyword */ |
| 80 |
Set *devlinks; |
| 81 |
Iterator devlinks_iterator; |
| 82 |
uint64_t devlinks_generation; /* changes whenever the devlinks are changed */ |
| 83 |
uint64_t devlinks_iterator_generation; /* generation when iteration was started */ |
| 84 |
int devlink_priority; |
| 85 |
|
| 86 |
/* parent and child devices */ |
| 87 |
sd_device *parent; |
| 88 |
Hashmap *children; |
| 89 |
Iterator children_iterator; |
| 90 |
bool children_enumerated; |
| 91 |
|
| 92 |
bool parent_set:1; /* no need to try to reload parent */ |
| 93 |
bool sysattrs_read:1; /* don't try to re-read sysattrs once read */ |
| 94 |
bool property_tags_outdated:1; /* need to update TAGS= or CURRENT_TAGS= property */ |
| 95 |
bool property_devlinks_outdated:1; /* need to update DEVLINKS= property */ |
| 96 |
bool properties_buf_outdated:1; /* need to reread hashmap */ |
| 97 |
bool subsystem_set:1; /* don't reread subsystem */ |
| 98 |
bool driver_set:1; /* don't reread driver */ |
| 99 |
bool uevent_loaded:1; /* don't reread uevent */ |
| 100 |
bool db_loaded; /* don't reread db */ |
| 101 |
bool is_initialized:1; |
| 102 |
bool sealed:1; /* don't read more information from uevent/db */ |
| 103 |
bool db_persist:1; /* don't clean up the db when switching from initrd to real root */ |
| 104 |
}; |
| 105 |
|
| 106 |
int device_new_aux(sd_device **ret); |
| 107 |
int device_add_property_aux(sd_device *device, const char *key, const char *value, bool db); |
| 108 |
static inline int device_add_property_internal(sd_device *device, const char *key, const char *value) { |
| 109 |
return device_add_property_aux(device, key, value, false); |
| 110 |
} |
| 111 |
|
| 112 |
int device_set_syspath(sd_device *device, const char *_syspath, bool verify); |
| 113 |
int device_set_ifindex(sd_device *device, const char *name); |
| 114 |
int device_set_devuid(sd_device *device, const char *uid); |
| 115 |
int device_set_devgid(sd_device *device, const char *gid); |
| 116 |
int device_set_devmode(sd_device *device, const char *devmode); |
| 117 |
int device_set_devname(sd_device *device, const char *devname); |
| 118 |
int device_set_devtype(sd_device *device, const char *devtype); |
| 119 |
int device_set_devnum(sd_device *device, const char *major, const char *minor); |
| 120 |
int device_set_subsystem(sd_device *device, const char *subsystem); |
| 121 |
int device_set_diskseq(sd_device *device, const char *str); |
| 122 |
int device_set_drivers_subsystem(sd_device *device); |
| 123 |
int device_set_driver(sd_device *device, const char *driver); |
| 124 |
int device_set_usec_initialized(sd_device *device, usec_t when); |