|
rpm-build |
07bc2b |
#!/usr/bin/env seed
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
// seed example
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
const GLib = imports.gi.GLib;
|
|
rpm-build |
07bc2b |
const GUdev = imports.gi.GUdev;
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
function print_device (device) {
|
|
rpm-build |
07bc2b |
print (" subsystem: " + device.get_subsystem ());
|
|
rpm-build |
07bc2b |
print (" devtype: " + device.get_devtype ());
|
|
rpm-build |
07bc2b |
print (" name: " + device.get_name ());
|
|
rpm-build |
07bc2b |
print (" number: " + device.get_number ());
|
|
rpm-build |
07bc2b |
print (" sysfs_path: " + device.get_sysfs_path ());
|
|
rpm-build |
07bc2b |
print (" driver: " + device.get_driver ());
|
|
rpm-build |
07bc2b |
print (" action: " + device.get_action ());
|
|
rpm-build |
07bc2b |
print (" seqnum: " + device.get_seqnum ());
|
|
rpm-build |
07bc2b |
print (" device type: " + device.get_device_type ());
|
|
rpm-build |
07bc2b |
print (" device number: " + device.get_device_number ());
|
|
rpm-build |
07bc2b |
print (" device file: " + device.get_device_file ());
|
|
rpm-build |
07bc2b |
print (" device file symlinks: " + device.get_device_file_symlinks ());
|
|
rpm-build |
07bc2b |
print (" foo: " + device.get_sysfs_attr_as_strv ("stat"));
|
|
rpm-build |
07bc2b |
var keys = device.get_property_keys ();
|
|
rpm-build |
07bc2b |
for (var n = 0; n < keys.length; n++) {
|
|
rpm-build |
07bc2b |
print (" " + keys[n] + "=" + device.get_property (keys[n]));
|
|
rpm-build |
07bc2b |
}
|
|
rpm-build |
07bc2b |
}
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
function on_uevent (client, action, device) {
|
|
rpm-build |
07bc2b |
print ("action " + action + " on device " + device.get_sysfs_path());
|
|
rpm-build |
07bc2b |
print_device (device);
|
|
rpm-build |
07bc2b |
print ("");
|
|
rpm-build |
07bc2b |
}
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
var client = new GUdev.Client ({subsystems: ["block", "usb/usb_interface"]});
|
|
rpm-build |
07bc2b |
client.signal.connect ("uevent", on_uevent);
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
var block_devices = client.query_by_subsystem ("block");
|
|
rpm-build |
07bc2b |
for (var n = 0; n < block_devices.length; n++) {
|
|
rpm-build |
07bc2b |
print ("block device: " + block_devices[n].get_device_file ());
|
|
rpm-build |
07bc2b |
}
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
var d;
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
d = client.query_by_device_number (GUdev.DeviceType.BLOCK, 0x0810);
|
|
rpm-build |
07bc2b |
if (d == null) {
|
|
rpm-build |
07bc2b |
print ("query_by_device_number 0x810 -> null");
|
|
rpm-build |
07bc2b |
} else {
|
|
rpm-build |
07bc2b |
print ("query_by_device_number 0x810 -> " + d.get_device_file ());
|
|
rpm-build |
07bc2b |
dd = d.get_parent_with_subsystem ("usb", null);
|
|
rpm-build |
07bc2b |
print_device (dd);
|
|
rpm-build |
07bc2b |
print ("--------------------------------------------------------------------------");
|
|
rpm-build |
07bc2b |
while (d != null) {
|
|
rpm-build |
07bc2b |
print_device (d);
|
|
rpm-build |
07bc2b |
print ("");
|
|
rpm-build |
07bc2b |
d = d.get_parent ();
|
|
rpm-build |
07bc2b |
}
|
|
rpm-build |
07bc2b |
}
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
d = client.query_by_sysfs_path ("/sys/block/sda/sda1");
|
|
rpm-build |
07bc2b |
print ("query_by_sysfs_path (\"/sys/block/sda1\") -> " + d.get_device_file ());
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
d = client.query_by_subsystem_and_name ("block", "sda2");
|
|
rpm-build |
07bc2b |
print ("query_by_subsystem_and_name (\"block\", \"sda2\") -> " + d.get_device_file ());
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
d = client.query_by_device_file ("/dev/sda");
|
|
rpm-build |
07bc2b |
print ("query_by_device_file (\"/dev/sda\") -> " + d.get_device_file ());
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
d = client.query_by_device_file ("/dev/block/8:0");
|
|
rpm-build |
07bc2b |
print ("query_by_device_file (\"/dev/block/8:0\") -> " + d.get_device_file ());
|
|
rpm-build |
07bc2b |
|
|
rpm-build |
07bc2b |
var mainloop = GLib.main_loop_new ();
|
|
rpm-build |
07bc2b |
GLib.main_loop_run (mainloop);
|