-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
71 lines (58 loc) · 2.63 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
libsysdev introduction
The general purpose is to provide a sysfs-based library that can replace
libudev. This does not mean API/ABI-compatible; rather, it should provide
similar functionality without a daemon, and a program should be able to
link with both libsysdev and libudev at the same time (so libsysdev can
be used as a fallback when udevd is not running).
The --enable-sysfs code in mesa provided inspiration.
If someone wants to write a partial udev-compat shim, I'm open to including it.
The API is based on a quick glance through xf86-input-evdev
and mesa to see where they need udev/what they do instead.
By my reading, sysdev_getsyspath() or sysdev_devfd_to_syspath() should be
enough for evdev, while mesa would need sysdev_getproductids() as well.
Thanks to Karl Hammar for inspiration to do this.
Copyright/license:
See LICENSE and the individual files for license information.
The bulk of the library is copyright
Copyright Isaac Dunham, in the year of our Lord 2015.
No rights reserved, see LICENSE for details.
TODO:
* Handle multiarch and multilib configurations better than
expecting the builder to set LIBDIR.
* (WIP) Get evdev to use this.
A first try, which has *not* been tested beyond compile, is available at
https://github.com/idunham/xf86-input-evdev
(in branch sysdev).
API:
libsysdev uses the sysdev_ namespace for public APIs.
Internal functions are prefixed with sdp_ instead.
See util/devinfo.c for an example of how you could use sysdev_getsyspath()
and sysdev_getproductids().
If you have a device fd (devfd) and want to get the PCI IDs, just use this:
int vendor, device;
...
if (sysdev_devfd_to_pciid(&vendor, &device, devfd)) {
// handle error condition (PCI ids not read)
}
Here are the currently available functions:
/* given fd of syspath, set vendor_id and device_id
* returns 0 for success, nonzero for failure
*/
int sysdev_getproductids(int *vendor_id, int *device_id, int sysfd);
/* given major/minor/type, return the directory in /sys
* returns a calloc'd string (or NULL on failure)
*/
char * sysdev_getsyspath(unsigned int major, unsigned int minor, int ischar);
/* given fd of device, return the directory in /sys
* returns a calloc'd string (or NULL on failure)
* sets errno = EINVAL if devfd is not a device
*/
char *sysdev_devfd_to_syspath(int devfd);
/* given fd of device, return fd of corresponding syspath
* returns -1 on failure, sets errno = EINVAL if devfd is not a device
*/
int sysdev_devfd_to_sysfd(int devfd);
/* given fd of device, read vendor_id and device_id
* returns 0 for success, nonzero for failure
*/
int sysdev_devfd_to_pciid(int *vendor_id, int *device_id, int devfd);