libudev.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* SPDX-License-Identifier: LGPL-2.1+ */
  2. /***
  3. This file is part of systemd.
  4. Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
  5. systemd is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU Lesser General Public License as published by
  7. the Free Software Foundation; either version 2.1 of the License, or
  8. (at your option) any later version.
  9. systemd is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with systemd; If not, see <http://www.gnu.org/licenses/>.
  15. ***/
  16. #ifndef _LIBUDEV_H_
  17. #define _LIBUDEV_H_
  18. #include <stdarg.h>
  19. #include <sys/sysmacros.h>
  20. #include <sys/types.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /*
  25. * udev - library context
  26. *
  27. * reads the udev config and system environment
  28. * allows custom logging
  29. */
  30. struct udev;
  31. struct udev *udev_ref(struct udev *udev);
  32. struct udev *udev_unref(struct udev *udev);
  33. struct udev *udev_new(void);
  34. void udev_set_log_fn(struct udev *udev,
  35. void (*log_fn)(struct udev *udev,
  36. int priority, const char *file, int line, const char *fn,
  37. const char *format, va_list args)) __attribute__ ((deprecated));
  38. int udev_get_log_priority(struct udev *udev) __attribute__ ((deprecated));
  39. void udev_set_log_priority(struct udev *udev, int priority) __attribute__ ((deprecated));
  40. void *udev_get_userdata(struct udev *udev);
  41. void udev_set_userdata(struct udev *udev, void *userdata);
  42. /*
  43. * udev_list
  44. *
  45. * access to libudev generated lists
  46. */
  47. struct udev_list_entry;
  48. struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry);
  49. struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name);
  50. const char *udev_list_entry_get_name(struct udev_list_entry *list_entry);
  51. const char *udev_list_entry_get_value(struct udev_list_entry *list_entry);
  52. /**
  53. * udev_list_entry_foreach:
  54. * @list_entry: entry to store the current position
  55. * @first_entry: first entry to start with
  56. *
  57. * Helper to iterate over all entries of a list.
  58. */
  59. #define udev_list_entry_foreach(list_entry, first_entry) \
  60. for (list_entry = first_entry; \
  61. list_entry != NULL; \
  62. list_entry = udev_list_entry_get_next(list_entry))
  63. /*
  64. * udev_device
  65. *
  66. * access to sysfs/kernel devices
  67. */
  68. struct udev_device;
  69. struct udev_device *udev_device_ref(struct udev_device *udev_device);
  70. struct udev_device *udev_device_unref(struct udev_device *udev_device);
  71. struct udev *udev_device_get_udev(struct udev_device *udev_device);
  72. struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath);
  73. struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum);
  74. struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname);
  75. struct udev_device *udev_device_new_from_device_id(struct udev *udev, const char *id);
  76. struct udev_device *udev_device_new_from_environment(struct udev *udev);
  77. /* udev_device_get_parent_*() does not take a reference on the returned device, it is automatically unref'd with the parent */
  78. struct udev_device *udev_device_get_parent(struct udev_device *udev_device);
  79. struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device,
  80. const char *subsystem, const char *devtype);
  81. /* retrieve device properties */
  82. const char *udev_device_get_devpath(struct udev_device *udev_device);
  83. const char *udev_device_get_subsystem(struct udev_device *udev_device);
  84. const char *udev_device_get_devtype(struct udev_device *udev_device);
  85. const char *udev_device_get_syspath(struct udev_device *udev_device);
  86. const char *udev_device_get_sysname(struct udev_device *udev_device);
  87. const char *udev_device_get_sysnum(struct udev_device *udev_device);
  88. const char *udev_device_get_devnode(struct udev_device *udev_device);
  89. int udev_device_get_is_initialized(struct udev_device *udev_device);
  90. struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device);
  91. struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device);
  92. struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device);
  93. struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device);
  94. const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key);
  95. const char *udev_device_get_driver(struct udev_device *udev_device);
  96. dev_t udev_device_get_devnum(struct udev_device *udev_device);
  97. const char *udev_device_get_action(struct udev_device *udev_device);
  98. unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device);
  99. unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device);
  100. const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr);
  101. int udev_device_set_sysattr_value(struct udev_device *udev_device, const char *sysattr, char *value);
  102. int udev_device_has_tag(struct udev_device *udev_device, const char *tag);
  103. /*
  104. * udev_monitor
  105. *
  106. * access to kernel uevents and udev events
  107. */
  108. struct udev_monitor;
  109. struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor);
  110. struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor);
  111. struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor);
  112. /* kernel and udev generated events over netlink */
  113. struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name);
  114. /* bind socket */
  115. int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor);
  116. int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size);
  117. int udev_monitor_get_fd(struct udev_monitor *udev_monitor);
  118. struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor);
  119. /* in-kernel socket filters to select messages that get delivered to a listener */
  120. int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor,
  121. const char *subsystem, const char *devtype);
  122. int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag);
  123. int udev_monitor_filter_update(struct udev_monitor *udev_monitor);
  124. int udev_monitor_filter_remove(struct udev_monitor *udev_monitor);
  125. /*
  126. * udev_enumerate
  127. *
  128. * search sysfs for specific devices and provide a sorted list
  129. */
  130. struct udev_enumerate;
  131. struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate);
  132. struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate);
  133. struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate);
  134. struct udev_enumerate *udev_enumerate_new(struct udev *udev);
  135. /* device properties filter */
  136. int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem);
  137. int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem);
  138. int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value);
  139. int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value);
  140. int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value);
  141. int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname);
  142. int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag);
  143. int udev_enumerate_add_match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *parent);
  144. int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev_enumerate);
  145. int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath);
  146. /* run enumeration with active filters */
  147. int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate);
  148. int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate);
  149. /* return device list */
  150. struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate);
  151. /*
  152. * udev_queue
  153. *
  154. * access to the currently running udev events
  155. */
  156. struct udev_queue;
  157. struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue);
  158. struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue);
  159. struct udev *udev_queue_get_udev(struct udev_queue *udev_queue);
  160. struct udev_queue *udev_queue_new(struct udev *udev);
  161. unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) __attribute__ ((deprecated));
  162. unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) __attribute__ ((deprecated));
  163. int udev_queue_get_udev_is_active(struct udev_queue *udev_queue);
  164. int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue);
  165. int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) __attribute__ ((deprecated));
  166. int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
  167. unsigned long long int start, unsigned long long int end) __attribute__ ((deprecated));
  168. int udev_queue_get_fd(struct udev_queue *udev_queue);
  169. int udev_queue_flush(struct udev_queue *udev_queue);
  170. struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) __attribute__ ((deprecated));
  171. /*
  172. * udev_hwdb
  173. *
  174. * access to the static hardware properties database
  175. */
  176. struct udev_hwdb;
  177. struct udev_hwdb *udev_hwdb_new(struct udev *udev);
  178. struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb);
  179. struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb);
  180. struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned int flags);
  181. /*
  182. * udev_util
  183. *
  184. * udev specific utilities
  185. */
  186. int udev_util_encode_string(const char *str, char *str_enc, size_t len);
  187. #ifdef __cplusplus
  188. } /* extern "C" */
  189. #endif
  190. #endif