libudev1.h 9.1 KB

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