1e41f4b71Sopenharmony_ci# ueventd
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciThe **ueventd** module listens for **netlink** events about hot plug of kernel device drivers and dynamically manages the dev node of the corresponding device based on the event type.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci## Configuration Files of ueventd
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci### File Type
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ciThe configuration files of the **ueventd** module are stored in the **/base/startup/init/ueventd/etc/** directory. They are classified into three types: **device**, **sysfs**, and **firmware**.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciCurrently, the **ueventd** module uses configuration files of the **device** type. If needed, set DAC permissions for a created node in such files.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ciFile types are distinguished by the field at the beginning of the file. The following uses **device** as an example:
16e41f4b71Sopenharmony_ci  ```
17e41f4b71Sopenharmony_ci    [device] # File type.
18e41f4b71Sopenharmony_ci    # <device name> <mode> <uid> <gid> <parameter>
19e41f4b71Sopenharmony_ci    /dev/null 0666 0 0
20e41f4b71Sopenharmony_ci  ```
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci### Configuration File Description
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci  - The configuration file of the **ueventd** module is named **ueventd.config**.
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci  - The file consists of five fields, for example:
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci  ```
29e41f4b71Sopenharmony_ci  /dev/null 0666 0 0
30e41f4b71Sopenharmony_ci  /dev/binder 0666 0 0
31e41f4b71Sopenharmony_ci  /dev/hwbinder 0666 0 0
32e41f4b71Sopenharmony_ci  /dev/vndbinder 0666 0 0
33e41f4b71Sopenharmony_ci  /dev/input/event* 0660 0 input
34e41f4b71Sopenharmony_ci  ```
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci  **Fields in the Configuration File**
37e41f4b71Sopenharmony_ci  | Field       | Description            |
38e41f4b71Sopenharmony_ci  | ----------- | ---------------- |
39e41f4b71Sopenharmony_ci  | device name | Device node name.    |
40e41f4b71Sopenharmony_ci  | mode        | Permission granted to a device node in compliance with the UGO model.|
41e41f4b71Sopenharmony_ci  | uid         | UID of a device node.|
42e41f4b71Sopenharmony_ci  | gid         | GID of a device node.|
43e41f4b71Sopenharmony_ci  | parameter   | Device node parameter information, which is similar to a notification. If a device is created, a corresponding parameter is set so that other processes can perform operations on the node based on the parameter information.<br>/dev/null 0666 0 0  device_null<br>Take the **dev/null** node as as example:<br>When the device node is created, this field is set to **startup.uevent.device_null "added"**; when the device node is removed, this field is set to **startup.uevet.device_null "removed"**.|
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci  - Remarks
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci  The nodes of the boot partition may vary according to devices. Therefore, you can configure soft link permissions in the **ueventd.config** file to change the permissions of the corresponding physical device node.
48e41f4b71Sopenharmony_ci  These nodes are stored in the **/dev/block/by-name** directory.
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci  ```
51e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    20 2017-08-10 16:22 boot_linux -> /dev/block/mmcblk0p5
52e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    20 2017-08-10 16:22 bootctrl -> /dev/block/mmcblk0p3
53e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 ueventd ueventd 21 2017-08-10 16:22 chip-prod -> /dev/block/mmcblk0p10
54e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    20 2017-08-10 16:22 misc -> /dev/block/mmcblk0p2
55e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    20 2017-08-10 16:22 ramdisk -> /dev/block/mmcblk0p6
56e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 ueventd ueventd 20 2017-08-10 16:22 resource -> /dev/block/mmcblk0p4
57e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 ueventd ueventd 20 2017-08-10 16:22 sys-prod -> /dev/block/mmcblk0p9
58e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    20 2017-08-10 16:22 system -> /dev/block/mmcblk0p7
59e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    20 2017-08-10 16:22 uboot -> /dev/block/mmcblk0p1
60e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 ueventd ueventd 21 2017-08-10 16:22 updater -> /dev/block/mmcblk0p11
61e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 ueventd ueventd 21 2017-08-10 16:22 userdata -> /dev/block/mmcblk0p12
62e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    20 2017-08-10 16:22 vendor -> /dev/block/mmcblk0p8
63e41f4b71Sopenharmony_ci  ```
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci  Configuration example:
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci  ```
68e41f4b71Sopenharmony_ci  /dev/block/by-name/misc 0660 update update
69e41f4b71Sopenharmony_ci  /dev/block/by-name/bootctrl 0660 update update
70e41f4b71Sopenharmony_ci  ```
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci### Setting the SELinux Tag of a Device Node
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci  The SELinux tags of device nodes are set in the **/base/security/selinux_adapter/sepolicy/base/system/file_contexts** file. If the SELinux tag of a device node is not set, the node inherits the SELinux tag of its parent directory.
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci  - Defining node tags
77e41f4b71Sopenharmony_ci  ```
78e41f4b71Sopenharmony_ci  /dev/block(/.*)?                u:object_r:dev_block_file:s0
79e41f4b71Sopenharmony_ci  /dev/block/zram0                u:object_r:zram_device:s0
80e41f4b71Sopenharmony_ci  ```
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci  - Viewing the SELinux tag of the device node by using the **ls -Zl** command
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci  ```
85e41f4b71Sopenharmony_ci  # ls -Zl
86e41f4b71Sopenharmony_ci  total 0
87e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    u:object_r:dev_block_file:s0  20 2017-08-10 16:22 boot_linux -> /dev/block/mmcblk0p5
88e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    u:object_r:dev_block_file:s0  20 2017-08-10 16:22 bootctrl -> /dev/block/mmcblk0p3
89e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 ueventd ueventd u:object_r:dev_block_file:s0  21 2017-08-10 16:22 chip-prod -> /dev/block/mmcblk0p10
90e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    u:object_r:dev_block_file:s0  20 2017-08-10 16:22 misc -> /dev/block/mmcblk0p2
91e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    u:object_r:dev_block_file:s0  20 2017-08-10 16:22 ramdisk -> /dev/block/mmcblk0p6
92e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 ueventd ueventd u:object_r:dev_block_file:s0  20 2017-08-10 16:22 resource -> /dev/block/mmcblk0p4
93e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 ueventd ueventd u:object_r:dev_block_file:s0  20 2017-08-10 16:22 sys-prod -> /dev/block/mmcblk0p9
94e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    u:object_r:dev_block_file:s0  20 2017-08-10 16:22 system -> /dev/block/mmcblk0p7
95e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    u:object_r:dev_block_file:s0  20 2017-08-10 16:22 uboot -> /dev/block/mmcblk0p1
96e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 ueventd ueventd u:object_r:dev_block_file:s0  21 2017-08-10 16:22 updater -> /dev/block/mmcblk0p11
97e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 ueventd ueventd u:object_r:dev_block_file:s0  21 2017-08-10 16:22 userdata -> /dev/block/mmcblk0p12
98e41f4b71Sopenharmony_ci  lrwxrwxrwx 1 root    root    u:object_r:dev_block_file:s0  20 2017-08-10 16:22 vendor -> /dev/block/mmcblk0p8
99e41f4b71Sopenharmony_ci  ```
100