-
Notifications
You must be signed in to change notification settings - Fork 8
/
libudev.vapi
657 lines (647 loc) · 19.8 KB
/
libudev.vapi
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
[CCode (cheader_filename = "libudev.h")]
namespace UDev {
/**
* Reads the udev config and system environment allows custom logging
*/
[CCode (cname = "struct udev", ref_function = "udev_ref", unref_function = "udev_unref", has_type_id = false)]
public class Context {
/**
* Create udev library context.
*
* This reads the udev configuration file, and fills in the default values.
*/
[CCode (cname = "udev_new")]
public Context ();
/**
* The device directory path.
*
* The default value is "/dev", the actual value may be overridden in the
* udev configuration file.
*/
[CCode (cname = "udev_get_dev_path")]
public string dev_path {
get;
}
public int log_priority {
[CCode (cname = "udev_get_log_priority")]
get;
[CCode (cname = "udev_set_log_priority")]
set;
}
/**
* The udev runtime directory path.
*
* The default is "/run/udev".
*/
[CCode (cname = "udev_get_run_path")]
public string run_path {
get;
}
/**
* The sysfs mount point.
*
* The default is "/sys". For testing purposes, it can be overridden with
* udev_sys= in the udev configuration file.
*/
[CCode (cname = "udev_get_sys_path")]
public string sys_path {
get;
}
public void* user_data {
[CCode (cname = "udev_get_userdata")]
get;
[CCode (cname = "udev_set_userdata")]
set;
}
[CCode (cname = "udev_enumerate_new")]
public Enumerate create_enumerate ();
[CCode (cname = "udev_queue_new")]
public Queue? create_queue ();
/**
* Create new udev monitor and connect to a specified event source. Valid
* sources identifiers are "udev" and "kernel".
*
* Applications should usually not connect directly to the "kernel" events,
* because the devices might not be useable at that time, before udev has
* configured them, and created device nodes. Accessing devices at the same
* time as udev, might result in unpredictable behavior. The "udev" events
* are sent out after udev has finished its event processing, all rules
* have been processed, and needed device nodes are created.
*/
[CCode (cname = "udev_monitor_new_from_netlink")]
public Monitor? monitor_from_netlink (string name = "udev");
/**
* Create a new udev monitor and connect to a specified socket.
*
* The path to a socket either points to an existing socket file, or if the
* socket path starts with a '@' character, an abstract namespace socket
* will be used.
*
* A socket file will not be created. If it does not already exist, it will
* fall-back and connect to an abstract namespace socket with the given
* path. The permissions adjustment of a socket file, as well as the later
* cleanup, needs to be done by the caller.
*/
[Deprecated]
[CCode (cname = "udev_monitor_new_from_socket")]
public Monitor? monitor_from_socket (string socket_path);
/**
* Create new udev device, and fill in information from the current process
* environment.
*
* This only works reliable if the process is called from a udev rule. It
* is usually used for tools executed from IMPORT= rules.
*/
[CCode (cname = "udev_device_new_from_environment")]
public Device? new_from_environment ();
/**
* Create new udev device, and fill in information from the sys device and
* the udev database entry by its major/minor number and type.
*
* Character and block device numbers are not unique across the two types.
* @param type 'c' for character devices or 'b' for block devices.
*/
[CCode (cname = "udev_device_new_from_devnum")]
public Device? open_devnum (char type, Posix.dev_t devnum);
/**
* Create new udev device, and fill in information from the sys device
* and the udev database entry. The device is looked up by the subsystem
* and name string of the device, like "mem" / "zero", or "block" / "sda".
*/
[CCode (cname = "udev_device_new_from_subsystem_sysname")]
public Device? open_subsystem_sysname (string subsystem, string sysname);
/**
* Create new udev device, and fill in information from the sys device and
* the udev database entry.
*
* The syspath is the absolute path to the device, including the sys mount
* point.
*/
[CCode (cname = "udev_device_new_from_syspath")]
public Device? open_syspath (string syspath);
/**
* Take a reference of the udev library context.
*/
[CCode (cname = "udev_ref")]
public void ref ();
/**
* The error logging function.
*
* The built-in logging writes to stderr. It can be overridden by a custom
* function, to plug log messages into the users' logging functionality.
*/
[CCode (cname = "udev_set_log_fn")]
public void set_logger (Logger logger);
/**
* Drop a reference of the udev library context.
*/
[CCode (cname = "udev_unref")]
public void unref ();
}
/**
* Kernel sys devices
*
* Representation of kernel sys devices. Devices are uniquely identified by
* their syspath, every device has exactly one path in the kernel sys
* filesystem. Devices usually belong to a kernel subsystem, and and have a
* unique name inside that subsystem.
*/
[CCode (cname = "struct udev_device", ref_function = "udev_device_ref", unref_function = "udev_device_unref", has_type_id = false)]
public class Device {
/**
* The action if the device was received through a monitor.
*
* Devices read from sys do not have an action string. Usual actions are: add, remove, change, online, offline.
*/
public string? action {
[CCode (cname = "udev_device_get_action")]
get;
}
/**
* An indexable collection of sys attrs
*/
public SysAttr attr {
[CCode (cname = "")]
get;
}
/**
* The udev library context with which the device was created.
*/
public Context context {
[CCode (cname = "udev_device_get_udev")]
get;
}
/**
* The list of device links pointing to the device file of the udev device.
*/
public List? devlinks {
[CCode (cname = "udev_device_get_devlinks_list_entry")]
get;
}
/**
* Retrieve the device node file name belonging to the udev device.
*
* The path is an absolute path, and starts with the device directory.
*/
public string? devnode {
[CCode (cname = "udev_device_get_devnode")]
get;
}
/**
* The the device major/minor number
*/
public Posix.dev_t devnum {
[CCode (cname = "udev_device_get_devnum")]
get;
}
/**
* Retrieve the kernel devpath value of the udev device.
*
* The path does not contain the sys mount point, and starts with a '/'.
*/
public string devpath {
[CCode (cname = "udev_device_get_devpath")]
get;
}
/**
* The devtype name of the device, if it can be determined.
*/
public string? devtype {
[CCode (cname = "udev_device_get_devtype")]
get;
}
/**
* Get the name of the driver, if one is attached.
*/
public string? driver {
[CCode (cname = "udev_device_get_driver")]
get;
}
/**
* Has already handled the device and has set up device node permissions
* and context, or has renamed a network device?
*
* This is only implemented for devices with a device node or network
* interfaces. All other devices return true.
*/
public bool is_initialized {
[CCode (cname = "udev_device_get_is_initialized")]
get;
}
/**
* Find the next parent device, and fill in information from the sys device
* and the udev database entry.
*
* It is not necessarily just the upper level directory, empty or not
* recognized sys directories are ignored.
*/
public Device? parent {
[CCode (cname = "udev_device_get_parent")]
get;
}
/**
* The list of key/value device properties of the udev device.
*/
public List? properties {
[CCode (cname = "udev_device_get_properties_list_entry")]
get;
}
/**
* The sequence number
*
* This is only valid if the device was received through a monitor. Devices read from sys do not have a sequence number.
*/
public uint64 seqnum {
[CCode (cname = "udev_device_get_seqnum")]
get;
}
/**
* The subsystem string of the device, if it can be determined.
*
* This string will not contain /.
*/
public string? subsystem {
[CCode (cname = "udev_device_get_subsystem")]
get;
}
/**
* The list of available sysattrs, with value being empty.
*
* This just return all available sysfs attributes for a particular device
* without reading their values.
*/
public List sysattr {
[CCode (cname = "udev_device_get_sysattr_list_entry")]
get;
}
/**
* The sys name of the device device
*/
public string sysname {
[CCode (cname = "udev_device_get_sysname")]
get;
}
/**
* The trailing number of of the device name
*/
public string sysnum {
[CCode (cname = "udev_device_get_sysnum")]
get;
}
/**
* Retrieve the absolute sys path of the udev device starting with the sys mount point.
*/
public string syspath {
[CCode (cname = "udev_device_get_syspath")]
get;
}
/**
* The list of tags attached to the udev device
*/
public List? tags {
[CCode (cname = "udev_device_get_tags_list_entry")]
get;
}
/**
* The number of microseconds passed since udev set up the device for the
* first time.
*
* This is only implemented for devices with need to store properties
* in the udev database. All other devices are 0.
*/
public uint64 usec_since_initialized {
[CCode (cname = "udev_device_get_usec_since_initialized")]
get;
}
/**
* Get the value of a device property, if one exists.
*/
[CCode (cname = "udev_device_get_property_value")]
public unowned string? get (string key);
/**
* Find the next parent device, with a matching subsystem and devtype
* value, and fill in information from the sys device and the udev database
* entry.
*
* @param devtype the type of the device, or null to match any.
*/
[CCode (cname = "udev_device_get_parent_with_subsystem_devtype")]
public unowned Device? get_parent (string subsystem, string? devtype = null);
[CCode (cname = "udev_device_has_tag")]
public bool has_tag (string tag);
/**
* Take a reference of a udev device.
*/
[CCode (cname = "udev_device_ref")]
public void ref ();
/**
* Drop a reference of a udev device.
*/
[CCode (cname = "udev_device_unref")]
public void unref ();
}
/**
* Search sysfs for specific devices and provide a sorted list
*/
[CCode (cname = "struct udev_enumerate", ref_function = "udev_enumerate_ref", unref_function = "udev_enumerate_unref", has_type_id = false)]
public class Enumerate {
/**
* The udev library context.
*/
public Context context {
[CCode (cname = "udev_enumerate_get_udev")]
get;
}
/**
* The sorted list of device paths.
*/
public List? entries {
[CCode (cname = "udev_enumerate_get_list_entry")]
get;
}
/**
* Match only devices which udev has set up already.
*
* This makes sure, that the device node permissions and context are
* properly set and that network devices are fully renamed.
*
* Usually, devices which are found in the kernel but not already handled
* by udev, have still pending events. Services should subscribe to monitor
* events and wait for these devices to become ready, instead of using
* uninitialized devices.
* @return false on success
*/
[CCode (cname = "udev_enumerate_add_match_is_initialized")]
public bool add_match_is_initialized ();
/**
* Return the devices on the subtree of one given device.
*
* The parent itself is included in the list.
* @return false on success
*/
[CCode (cname = "udev_enumerate_add_match_parent")]
public bool add_match_parent (Device parent);
/**
* Filter for a property of the device to include in the list
* @return false on success
*/
[CCode (cname = "udev_enumerate_add_match_property")]
public bool add_match_property (string property, string @value);
/**
* Filter for a subsystem of the device to include in the list
* @return false on success
*/
[CCode (cname = "udev_enumerate_add_match_subsystem")]
public bool add_match_subsystem (string subsystem);
/**
* Filter for a sys attribute at the device to include in the list
* @return false on success
*/
[CCode (cname = "udev_enumerate_add_match_sysattr")]
public bool add_match_sysattr (string sysattr, string @value);
/**
* Filter for the name of the device to include in the list
* @return false on success
*/
[CCode (cname = "udev_enumerate_add_match_sysname")]
public bool add_match_sysname (string sysname);
/**
* Filter for a tag of the device to include in the list
* @return false on success
*/
[CCode (cname = "udev_enumerate_add_match_tag")]
public bool add_match_tag (string tag);
/**
* Filter for a subsystem of the device to exclude from the list
* @return false on success
*/
[CCode (cname = "udev_enumerate_add_nomatch_subsystem")]
public bool add_nomatch_subsystem (string subsystem);
/**
* Filter for a sys attribute at the device to exclude from the list
* @return false on success
*/
[CCode (cname = "udev_enumerate_add_nomatch_sysattr")]
public bool add_nomatch_sysattr (string sysattr, string @value);
/**
* Add a device to the list of devices, to retrieve it back sorted in dependency order.
* @return false on success
*/
[CCode (cname = "udev_enumerate_add_syspath")]
public bool add_syspath (string syspath);
/**
* Take a reference of a enumeration context.
*/
[CCode (cname = "udev_enumerate_ref")]
public void ref ();
/**
* Run enumeration with active filters
* @return false on success
*/
[CCode (cname = "udev_enumerate_scan_devices")]
public bool scan_devices ();
/**
* Run enumeration with active filters
* @return false on success
*/
[CCode (cname = "udev_enumerate_scan_subsystems")]
public bool scan_subsystems ();
/**
* Drop a reference of an enumeration context.
*/
[CCode (cname = "udev_enumerate_unref")]
public void unref ();
}
[CCode (cname = "struct udev_list_entry", free_function = "")]
[Compact]
public class List {
[CCode (cname = "udev_list_entry_get_by_name")]
public List? get (string name);
public string name {
[CCode (cname = "udev_list_entry_get_name")]
get;
}
public List? next {
[CCode (cname = "udev_list_entry_get_next")]
get;
}
public string @value {
[CCode (cname = "udev_list_entry_get_value")]
get;
}
}
/**
* Connection to a device event source.
*/
[CCode (cname = "struct udev_monitor", ref_function = "udev_monitor_ref", unref_function = "udev_monitor_unref", has_type_id = false)]
public class Monitor {
/**
* The udev library context with which the monitor was created.
*/
public Context context {
[CCode (cname = "udev_monitor_get_udev")]
get;
}
/**
* The socket file descriptor associated with the monitor.
*/
public int fd {
[CCode (cname = "udev_monitor_get_fd")]
get;
}
/**
* This filter is efficiently executed inside the kernel, and libudev
* subscribers will usually not be woken up for devices which do not match.
*
* The filter must be installed before the monitor is switched to listening mode.
* @return false on success
*/
[CCode (cname = "udev_monitor_filter_add_match_subsystem_devtype")]
public bool add_match_subsystem_devtype (string subsystem, string? devtype = null);
/**
* This filter is efficiently executed inside the kernel, and libudev
* subscribers will usually not be woken up for devices which do not match.
*
* The filter must be installed before the monitor is switched to listening mode.
* @return false on success
*/
[CCode (cname = "udev_monitor_filter_add_match_tag")]
public bool add_match_tag (string tag);
/**
* Binds the monitor socket to the event source.
* @return false on success
*/
[CCode (cname = "udev_monitor_enable_receiving")]
public bool enable_receiving ();
/**
* Receive data from the udev monitor socket, allocate a new udev device,
* fill in the received data, and return the device.
*
* Only socket connections with uid=0 are accepted.
* @return a new udev device, or null, in case of an error
*/
[CCode (cname = "udev_monitor_receive_device")]
public Device? receive_device ();
/**
* Take a reference of a udev monitor.
*/
[CCode (cname = "udev_monitor_ref")]
public void ref ();
/**
* Remove all filters from monitor.
* @return false on success
*/
[CCode (cname = "udev_monitor_filter_remove")]
public bool remove_filter ();
/**
* Set the size of the kernel socket buffer.
*
* This call needs the appropriate privileges to succeed.
* @return false on success
*/
[CCode (cname = "udev_monitor_set_receive_buffer_size")]
public bool set_receive_buffer_size (int size);
/**
* Drop a reference of a udev monitor.
*/
[CCode (cname = "udev_monitor_unref")]
public void unref ();
/**
* Update the installed socket filter.
*
* This is only needed, if the filter was removed or changed.
* @return false on success
*/
[CCode (cname = "udev_monitor_filter_update")]
public bool update_filter ();
}
/**
* Access to currently active events
*
* The udev daemon processes events asynchronously. All events which do not
* have interdependencies run in parallel. This exports the current state of
* the event processing queue, and the current event sequence numbers from
* the kernel and the udev daemon.
*/
[CCode (cname = "struct udev_queue", ref_function = "udev_queue_ref", unref_function = "udev_queue_unref", has_type_id = false)]
public class Queue {
/**
* The udev library context with which the queue context was created.
*/
public Context context {
[CCode (cname = "udev_queue_get_udev")]
get;
}
/**
* The list of queued events.
*/
public List? events {
[CCode (cname = "udev_queue_get_queued_list_entry")]
get;
}
public bool is_active {
[CCode (cname = "udev_queue_get_udev_is_active")]
get;
}
public bool is_empty {
[CCode (cname = "udev_queue_get_queue_is_empty")]
get;
}
/**
* The current kernel event sequence number.
*/
public uint64 kernel_seqnum {
[CCode (cname = "udev_queue_get_kernel_seqnum")]
get;
}
/**
* The last known udev event sequence number.
*/
public uint64 udev_seqnum {
[CCode (cname = "udev_queue_get_udev_seqnum")]
get;
}
/**
* Indicates whether the given sequence number is currently active.
*/
[CCode (cname = "udev_queue_get_seqnum_is_finished")]
public bool is_finished (uint64 seqnum);
/**
* Indicates if any of the sequence numbers in the given range is currently active.
*/
[CCode (cname = "udev_queue_get_seqnum_sequence_is_finished")]
public bool is_sequence_finished (uint64 start, uint64 end);
/**
* Take a reference of a udev queue context.
*/
[CCode (cname = "udev_queue_ref")]
public void ref ();
/**
* Drop a reference of a udev queue context.
*/
[CCode (cname = "udev_queue_unref")]
public void unref ();
}
/**
* Internal class to make sysattrs easy to access
*/
[CCode (cname = "struct udev_device", ref_function = "udev_device_ref", unref_function = "udev_device_unref", has_type_id = false)]
public class SysAttr {
/**
* The content of a sys attribute file, null if there is a sys attribute value.
*
* The retrieved value is cached in the device. Repeated calls will return the same
* value and not open the attribute again.
*/
[CCode (cname = "udev_device_get_sysattr_value")]
public unowned string? get (string sysattr);
}
public delegate void Logger (Context udev, int priority, string file, int line, string fn, string format, va_list args);
/**
* Encode all potentially unsafe characters of a string to the corresponding 2 char hex value prefixed by '\x'.
* @param buffer the output buffer to store the string which might be four times the length of the input.
* @return true on error
*/
[CCode (cname = "udev_util_encode_string")]
public bool encode_string (string str, char[] buffer);
}