1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include <inttypes.h>
5 #include <stdbool.h>
6 #include <sys/stat.h>
7 #include <sys/types.h>
8 
9 #include "sd-device.h"
10 
11 #include "macro.h"
12 
13 int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len);
14 int device_new_from_strv(sd_device **ret, char **strv);
15 int device_new_from_watch_handle_at(sd_device **ret, int dirfd, int wd);
device_new_from_watch_handle(sd_device ** ret,int wd)16 static inline int device_new_from_watch_handle(sd_device **ret, int wd) {
17         return device_new_from_watch_handle_at(ret, -1, wd);
18 }
19 
20 int device_get_property_bool(sd_device *device, const char *key);
21 int device_get_device_id(sd_device *device, const char **ret);
22 int device_get_devlink_priority(sd_device *device, int *ret);
23 int device_get_watch_handle(sd_device *device);
24 int device_get_devnode_mode(sd_device *device, mode_t *ret);
25 int device_get_devnode_uid(sd_device *device, uid_t *ret);
26 int device_get_devnode_gid(sd_device *device, gid_t *ret);
27 
28 int device_cache_sysattr_value(sd_device *device, const char *key, char *value);
29 int device_get_cached_sysattr_value(sd_device *device, const char *key, const char **ret_value);
30 
31 void device_seal(sd_device *device);
32 void device_set_is_initialized(sd_device *device);
33 int device_set_watch_handle(sd_device *device, int wd);
34 void device_set_db_persist(sd_device *device);
35 void device_set_devlink_priority(sd_device *device, int priority);
36 int device_ensure_usec_initialized(sd_device *device, sd_device *device_old);
37 int device_add_devlink(sd_device *device, const char *devlink);
38 bool device_has_devlink(sd_device *device, const char *devlink);
39 int device_add_property(sd_device *device, const char *property, const char *value);
40 int device_add_propertyf(sd_device *device, const char *key, const char *format, ...) _printf_(3, 4);
41 int device_add_tag(sd_device *device, const char *tag, bool both);
42 void device_remove_tag(sd_device *device, const char *tag);
43 void device_cleanup_tags(sd_device *device);
44 void device_cleanup_devlinks(sd_device *device);
45 
46 uint64_t device_get_properties_generation(sd_device *device);
47 uint64_t device_get_tags_generation(sd_device *device);
48 uint64_t device_get_devlinks_generation(sd_device *device);
49 
50 int device_properties_prepare(sd_device *device);
51 int device_get_properties_nulstr(sd_device *device, const uint8_t **nulstr, size_t *len);
52 int device_get_properties_strv(sd_device *device, char ***strv);
53 
54 int device_rename(sd_device *device, const char *name);
55 int device_shallow_clone(sd_device *device, sd_device **ret);
56 int device_clone_with_db(sd_device *device, sd_device **ret);
57 int device_copy_properties(sd_device *device_dst, sd_device *device_src);
58 
59 int device_tag_index(sd_device *dev, sd_device *dev_old, bool add);
60 int device_update_db(sd_device *device);
61 int device_delete_db(sd_device *device);
62 int device_read_db_internal_filename(sd_device *device, const char *filename); /* For fuzzer */
63 int device_read_db_internal(sd_device *device, bool force);
device_read_db(sd_device * device)64 static inline int device_read_db(sd_device *device) {
65         return device_read_db_internal(device, false);
66 }
67 
68 int device_read_uevent_file(sd_device *device);
69 
70 int device_set_action(sd_device *device, sd_device_action_t a);
71 sd_device_action_t device_action_from_string(const char *s) _pure_;
72 const char *device_action_to_string(sd_device_action_t a) _const_;
73 void dump_device_action_table(void);
74