{"id":23940169,"url":"https://github.com/ilya33/udev-ffi","last_synced_at":"2025-04-12T12:32:31.562Z","repository":{"id":56839518,"uuid":"95574275","full_name":"Ilya33/udev-ffi","owner":"Ilya33","description":"Perl bindings for libudev using ffi","archived":false,"fork":false,"pushed_at":"2022-11-27T19:41:53.000Z","size":169,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-06T03:12:01.334Z","etag":null,"topics":["libudev","perl","perl-bindings","udev"],"latest_commit_sha":null,"homepage":"https://metacpan.org/pod/Udev::FFI","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ilya33.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-27T15:39:04.000Z","updated_at":"2023-11-07T13:32:03.000Z","dependencies_parsed_at":"2022-08-29T05:01:10.783Z","dependency_job_id":null,"html_url":"https://github.com/Ilya33/udev-ffi","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ilya33%2Fudev-ffi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ilya33%2Fudev-ffi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ilya33%2Fudev-ffi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ilya33%2Fudev-ffi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ilya33","download_url":"https://codeload.github.com/Ilya33/udev-ffi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232666187,"owners_count":18557991,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["libudev","perl","perl-bindings","udev"],"created_at":"2025-01-06T03:12:04.510Z","updated_at":"2025-04-12T12:32:31.555Z","avatar_url":"https://github.com/Ilya33.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nUdev::FFI - Perl bindings for libudev using ffi.\n\n# SYNOPSIS\n\n    use Udev::FFI;\n    use Udev::FFI::Devnum qw(:all); # \u003c- import major, minor and makedev\n    \n    # get udev library version\n    my $udev_version = Udev::FFI::udev_version() or\n        die(\"Can't get udev library version: $@\");\n    \n    \n    # create Udev::FFI object\n    my $udev = Udev::FFI-\u003enew() or\n        die(\"Can't create Udev::FFI object: $@\");\n    \n    \n    # create udev monitor\n    my $monitor = $udev-\u003enew_monitor() or\n        die(\"Can't create udev monitor: $@\");\n    \n    # add filter to monitor\n    unless ($monitor-\u003efilter_by_subsystem_devtype('block')) {\n        warn(\"Ouch!\");\n    }\n    \n    # start monitor\n    if ($monitor-\u003estart()) {\n        for (;;) {\n            # poll devices, now insert or remove your block device\n            my $device = $monitor-\u003epoll(); # blocking read\n            my $action = $device-\u003eget_action();\n    \n            print(\"ACTION: $action\\n\");\n            print('SYSNAME: '.$device-\u003eget_sysname().\"\\n\");\n            print('DEVNODE: '.$device-\u003eget_devnode().\"\\n\");\n    \n            last; # for example\n        }\n    \n        for (;;) {\n            # poll devices, now insert or remove your block device\n            if (defined(my $device = $monitor-\u003epoll(0))) { # non-blocking read like can_read in IO::Select\n                my $action = $device-\u003eget_action();\n    \n                print(\"ACTION: $action\\n\");\n                print('SYSNAME: '.$device-\u003eget_sysname().\"\\n\");\n                print('DEVNODE: '.$device-\u003eget_devnode().\"\\n\");\n            }\n    \n            sleep(1);\n    \n            last; # for example\n        }\n    }\n    \n    \n    # enumerate devices\n    my $enumerate = $udev-\u003enew_enumerate() or\n        die(\"Can't create enumerate context: $@\");\n    \n    $enumerate-\u003eadd_match_subsystem('block');\n    $enumerate-\u003escan_devices();\n    \n    use Data::Dumper; # for dump values in $href and @a\n    \n    # scalar context\n    my $href = $enumerate-\u003eget_list_entries();\n    print(Dumper($href).\"\\n\");\n    \n    # list context\n    my @a = $enumerate-\u003eget_list_entries();\n    print(Dumper(@a).\"\\n\");\n    \n    if (@a) { # we got devices\n        my $device = $udev-\u003enew_device_from_syspath($a[0]);\n    \n        if (defined($device)) {\n            print('Device: '.$device-\u003eget_sysname().\"\\n\");\n    \n            my $devnum = $device-\u003eget_devnum();\n    \n            # major, minor and makedev from Udev::FFI::Devnum\n            my ($ma, $mi) = (major($devnum), minor($devnum));\n    \n            print(\"Major: $ma\\n\");\n            print(\"Minor: $mi\\n\");\n    \n            $devnum = makedev($ma, $mi);\n            print(\"Devnum: $devnum\\n\");\n    \n    \n            # scalar context\n            $href = $device-\u003eget_properties_list_entries();\n            print(Dumper($href).\"\\n\");\n    \n            # list context\n            @a = $device-\u003eget_properties_list_entries();\n            print(Dumper(@a).\"\\n\");\n        }\n    }\n\n# DESCRIPTION\n\nUdev::FFI exposes OO interface to libudev.\n\n# CONSTRUCTOR\n\n- new()\n\n    This is the constructor for a new Udev::FFI object.\n\n    If the constructor fails undef will be returned and an error message will be in\n    $@.\n\n        my $udev = Udev::FFI-\u003enew() or\n            die(\"Can't create Udev::FFI object: $@\");\n\n# METHODS\n\n## new\\_monitor( \\[SOURCE\\] )\n\nCreate new udev monitor and connect to a specified event source. Valid sources\nidentifiers are `'udev'` and `'kernel'`. This argument is optional and\ndefaults to `'udev'`.\n\nReturn new [Udev::FFI::Monitor](https://metacpan.org/pod/Udev%3A%3AFFI%3A%3AMonitor) object on success, undef with the error in $@\non failure.\n\n    my $monitor = $udev-\u003enew_monitor() or\n        die(\"Can't create udev monitor: $@\");\n\n## new\\_enumerate()\n\nCreate an enumeration context to scan /sys.\n\nReturn new [Udev::FFI::Enumerate](https://metacpan.org/pod/Udev%3A%3AFFI%3A%3AEnumerate) object on success, undef with the error in $@\non failure.\n\n    my $enumerate = $udev-\u003enew_enumerate() or\n        die(\"Can't create enumerate context: $@\");\n\n## new\\_device\\_from\\_syspath( SYSPATH )\n\nCreate new udev device, and fill in information from the sys device and the udev\ndatabase entry. The syspath is the absolute path to the device, including the\nsys mount point.\n\nReturn new [Udev::FFI::Device](https://metacpan.org/pod/Udev%3A%3AFFI%3A%3ADevice) object or undef, if device does not exist.\n\n    my $device0 = $udev-\u003enew_device_from_syspath('/sys/class/block/sda1');\n    my $device1 = $udev-\u003enew_device_from_syspath('/sys/class/net/eth0');\n    \n    # ... some code\n    my @devices = $enumerate-\u003eget_list_entries();\n    for (@devices) {\n        my $device = $udev-\u003enew_device_from_syspath($_);\n    # ... some code\n\n## new\\_device\\_from\\_devnum( TYPE, DEVNUM )\n\nCreate new udev device, and fill in information from the sys device and the udev\ndatabase entry. The device is looked-up by its type and major/minor number.\n\nReturn new [Udev::FFI::Device](https://metacpan.org/pod/Udev%3A%3AFFI%3A%3ADevice) object or undef, if device does not exist.\n\n    use Udev::FFI::Devnum qw(makedev);\n    my $device0 = $udev-\u003enew_device_from_devnum('b', makedev(8, 1));\n    my $device1 = $udev-\u003enew_device_from_devnum('c', makedev(189, 515));\n\n## new\\_device\\_from\\_subsystem\\_sysname( SUBSYSTEM, SYSNAME )\n\nCreate new udev device, and fill in information from the sys device and the udev\ndatabase entry. The device is looked up by the subsystem and name string of the\ndevice.\n\nReturn new [Udev::FFI::Device](https://metacpan.org/pod/Udev%3A%3AFFI%3A%3ADevice) object or undef, if device does not exist.\n\n    my $device0 = $udev-\u003enew_device_from_subsystem_sysname('block', 'sda1');\n    my $device1 = $udev-\u003enew_device_from_subsystem_sysname('net', 'lo');\n    my $device2 = $udev-\u003enew_device_from_subsystem_sysname('mem', 'urandom');\n\n## new\\_device\\_from\\_device\\_id( ID )\n\nCreate new udev device, and fill in information from the sys device and the udev\ndatabase entry. The device is looked-up by a special string:\n\n\u003e `'b8:1'` - block device major:minor\n\u003e\n\u003e `'c128:2'` - char device major:minor\n\u003e\n\u003e `'n2'` - network device ifindex\n\u003e\n\u003e `'+sound:card29'` - kernel driver core subsystem:device name\n\nReturn new [Udev::FFI::Device](https://metacpan.org/pod/Udev%3A%3AFFI%3A%3ADevice) object or undef, if device does not exist.\n\n    my $device = $udev-\u003enew_device_from_device_id('b8:1');\n\n## new\\_device\\_from\\_environment()\n\nCreate new udev device, and fill in information from the current process\nenvironment. This only works reliable if the process is called from a udev rule.\n\nReturn new [Udev::FFI::Device](https://metacpan.org/pod/Udev%3A%3AFFI%3A%3ADevice) object or undef, if device does not exist.\n\n    # in udev.rules (for example)\n    # SUBSYSTEM==\"backlight\", ACTION==\"change\", IMPORT{program}=\"/path/script.pl\"\n    \n    # in script\n    my $udev = Udev::FFI-\u003enew() or\n        die(\"Can't create Udev::FFI object: $@\");\n    my $device = $udev-\u003enew_device_from_environment();\n    if (defined($device)) {\n        # $device is the device from the udev rule (backlight in this example)\n        # work with $device\n\n## Udev::FFI::udev\\_version()\n\nReturn the version of the udev library. Because the udev library does not\nprovide a function to get the version number, this function runs the \\`udevadm\\`\nutility.\n\nReturn undef with the error in $@ on failure. Also you can check $! value:\nENOENT (\\`udevadm\\` not found) or EACCES (permission denied).\n\n    # simple\n    my $udev_version = Udev::FFI::udev_version() or\n        die(\"Can't get udev library version: $@\");\n    \n    # or catch the error\n    use Errno qw( :POSIX );\n    my $udev_version = Udev::FFI::udev_version();\n    unless (defined($udev_version)) {\n        if ($!{ENOENT}) {\n            # udevadm not found\n        }\n        elsif ($!{EACCES}) {\n            # permission denied\n        }\n    \n        die(\"Can't get udev library version: $@\");\n    }\n\n# EXAMPLES\n\nExamples are provided with the Udev::FFI distribution in the \"examples\"\ndirectory.\n\n# SEE ALSO\n\nlibudev\n\neudev\n\n[FFI::Platypus](https://metacpan.org/pod/FFI%3A%3APlatypus) (Write Perl bindings to non-Perl libraries without C or XS)\n\n[FFI::CheckLib](https://metacpan.org/pod/FFI%3A%3ACheckLib) (Check that a library is available for FFI)\n\n# BUGS AND LIMITATIONS\n\nUdev::FFI supports libudev 171 or newer. Older versions may work too, but it was\nnot tested.\n\nPlease report any bugs through the web interface at\n[https://github.com/Ilya33/udev-ffi/issues](https://github.com/Ilya33/udev-ffi/issues). Patches are always welcome.\n\n# AUTHOR\n\nIlya Pavlov, \u003cilux@cpan.org\u003e\n\nContributors:\n\nMohammad S Anwar\n\n# COPYRIGHT AND LICENSE\n\nCopyright (C) 2017-2025 by Ilya Pavlov\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language\nsystem itself.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filya33%2Fudev-ffi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filya33%2Fudev-ffi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filya33%2Fudev-ffi/lists"}