1# OpenHarmony SELinux对外接口说明
2
3## 概述
4
5SELinux对外提供更新文件或目录SELinux标签的接口。
6
7## 接口说明
8
9所有接口均为Native C内部接口,仅提供底层能力,不对应用开放。相关接口列表如下:
10
11| 接口名 | 接口说明 | 参数说明 |
12| --------- | ---------- | ---------- |
13| int **Restorecon**(const char *path); | **接口功能**:更新单个文件或者目录的标签,不递归遍历子目录。<br/>**返回值**:0表示成功,其他返回值表示失败。 | path表示绝对路径。 |
14| int **RestoreconRecurse**(const char *path); | **接口功能**:单线程更新文件或者目录的标签,递归遍历更新子目录和文件标签。<br/>**返回值**:0表示成功,其他返回值表示失败。 | path表示绝对路径。 |
15| int **RestoreconRecurseParallel**(const char *path, unsigned int nthreads); | **接口功能**:多线程更新文件或者目录的标签,递归遍历更新子目录和文件标签。<br/>**返回值**:0表示成功,其他返回值表示失败。 | path表示绝对路径。<br/>nthreads表示线程个数。 |
16| int **RestoreconRecurseForce**(const char *path); | **接口功能**:单线程强制更新文件或者目录的标签,递归遍历更新子目录和文件标签。<br/>**返回值**:0表示成功,其他返回值表示失败。 | path表示绝对路径。 |
17| int **RestoreconFromParentDir**(const char *path); | **接口功能**:根据当前路径的父目录标签,单线程更新当前路径的标签,递归遍历更新整个目录。<br/>**返回值**:0表示成功,其他返回值表示失败。 | path表示绝对路径。 |
18
19## 开发步骤
20
211. 编译依赖添加
22
23    ```text
24    external_deps += [ "selinux_adapter:librestorecon" ]
25    ```
26
272. 头文件依赖添加
28
29    ```cpp
30    #include "policycoreutils.h"
31    ```
32
333. 接口调用
34
35    以Restorecon接口为例:
36    ```cpp
37    // 更新/data路径标签:
38    int ret = Restorecon("/data");
39    ```
40