Home | History | Annotate | Download | only in libudev
      1 /*
      2  * libudev - interface to udev device information
      3  *
      4  * Copyright (C) 2008-2010 Kay Sievers <kay.sievers (at) 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 
     12 #ifndef _LIBUDEV_H_
     13 #define _LIBUDEV_H_
     14 
     15 #include <stdarg.h>
     16 #include <sys/types.h>
     17 #include <sys/stat.h>
     18 
     19 #ifdef __cplusplus
     20 extern "C" {
     21 #endif
     22 
     23 /*
     24  * udev - library context
     25  *
     26  * reads the udev config and system environment
     27  * allows custom logging
     28  */
     29 struct udev;
     30 struct udev *udev_ref(struct udev *udev);
     31 void udev_unref(struct udev *udev);
     32 struct udev *udev_new(void);
     33 void udev_set_log_fn(struct udev *udev,
     34 			    void (*log_fn)(struct udev *udev,
     35 					   int priority, const char *file, int line, const char *fn,
     36 					   const char *format, va_list args));
     37 int udev_get_log_priority(struct udev *udev);
     38 void udev_set_log_priority(struct udev *udev, int priority);
     39 const char *udev_get_sys_path(struct udev *udev);
     40 const char *udev_get_dev_path(struct udev *udev);
     41 void *udev_get_userdata(struct udev *udev);
     42 void udev_set_userdata(struct udev *udev, void *userdata);
     43 
     44 /*
     45  * udev_list
     46  *
     47  * access to libudev generated lists
     48  */
     49 struct udev_list_entry;
     50 struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry);
     51 struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name);
     52 const char *udev_list_entry_get_name(struct udev_list_entry *list_entry);
     53 const char *udev_list_entry_get_value(struct udev_list_entry *list_entry);
     54 /**
     55  * udev_list_entry_foreach:
     56  * @list_entry: entry to store the current position
     57  * @first_entry: first entry to start with
     58  *
     59  * Helper to iterate over all entries of a list.
     60  */
     61 #define udev_list_entry_foreach(list_entry, first_entry) \
     62 	for (list_entry = first_entry; \
     63 	     list_entry != NULL; \
     64 	     list_entry = udev_list_entry_get_next(list_entry))
     65 
     66 /*
     67  * udev_device
     68  *
     69  * access to sysfs/kernel devices
     70  */
     71 struct udev_device;
     72 struct udev_device *udev_device_ref(struct udev_device *udev_device);
     73 void udev_device_unref(struct udev_device *udev_device);
     74 struct udev *udev_device_get_udev(struct udev_device *udev_device);
     75 struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath);
     76 struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum);
     77 struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname);
     78 struct udev_device *udev_device_new_from_environment(struct udev *udev);
     79 /* udev_device_get_parent_*() does not take a reference on the returned device, it is automatically unref'd with the parent */
     80 struct udev_device *udev_device_get_parent(struct udev_device *udev_device);
     81 struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device,
     82 								  const char *subsystem, const char *devtype);
     83 /* retrieve device properties */
     84 const char *udev_device_get_devpath(struct udev_device *udev_device);
     85 const char *udev_device_get_subsystem(struct udev_device *udev_device);
     86 const char *udev_device_get_devtype(struct udev_device *udev_device);
     87 const char *udev_device_get_syspath(struct udev_device *udev_device);
     88 const char *udev_device_get_sysname(struct udev_device *udev_device);
     89 const char *udev_device_get_sysnum(struct udev_device *udev_device);
     90 const char *udev_device_get_devnode(struct udev_device *udev_device);
     91 struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device);
     92 struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device);
     93 struct udev_list_entry *udev_device_get_tags_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 const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr);
    100 
    101 /*
    102  * udev_monitor
    103  *
    104  * access to kernel uevents and udev events
    105  */
    106 struct udev_monitor;
    107 struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor);
    108 void udev_monitor_unref(struct udev_monitor *udev_monitor);
    109 struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor);
    110 /* kernel and udev generated events over netlink */
    111 struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name);
    112 /* custom socket (use netlink and filters instead) */
    113 struct udev_monitor *udev_monitor_new_from_socket(struct udev *udev, const char *socket_path);
    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 /*
    127  * udev_enumerate
    128  *
    129  * search sysfs for specific devices and provide a sorted list
    130  */
    131 struct udev_enumerate;
    132 struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate);
    133 void udev_enumerate_unref(struct udev_enumerate *udev_enumerate);
    134 struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate);
    135 struct udev_enumerate *udev_enumerate_new(struct udev *udev);
    136 /* device properties filter */
    137 int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem);
    138 int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem);
    139 int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value);
    140 int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value);
    141 int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value);
    142 int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname);
    143 int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag);
    144 int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath);
    145 /* run enumeration with active filters */
    146 int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate);
    147 int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate);
    148 /* return device list */
    149 struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate);
    150 
    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 void 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);
    162 unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue);
    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);
    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);
    168 struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue);
    169 struct udev_list_entry *udev_queue_get_failed_list_entry(struct udev_queue *udev_queue);
    170 
    171 #ifdef __cplusplus
    172 } /* extern "C" */
    173 #endif
    174 
    175 #endif
    176