1e41f4b71Sopenharmony_ci# OpenHarmony SELinux APIs 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## Introduction 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciThis topic describes the APIs provided to update the SELinux labels of files or directories, and how to use the APIs. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci## Available APIs 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ciAll the SELinux APIs are native C APIs that provide underlying capabilities only. These APIs are not available to applications. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci| API| Description| Parameter Description| 12e41f4b71Sopenharmony_ci| --------- | ---------- | ---------- | 13e41f4b71Sopenharmony_ci| int **Restorecon**(const char *path); | Updates the label of a single file or directory without recursively traversing subdirectories.<br>If **0** is returned, the operation is successful. Otherwise, the operation fails.| **path** indicates the pointer to the absolute path of the target file or directory.| 14e41f4b71Sopenharmony_ci| int **RestoreconRecurse**(const char *path); | Updates the file or directory label for a single thread, and recursively traverses and updates the labels of subdirectories and their files.<br>If **0** is returned, the operation is successful. Otherwise, the operation fails.| **path** indicates the pointer to the absolute path of the target file or directory.| 15e41f4b71Sopenharmony_ci| int **RestoreconRecurseParallel**(const char *path, unsigned int nthreads); | Updates the file or directory labels for multiple threads, and recursively traverses and updates the labels of subdirectories and their files.<br>If **0** is returned, the operation is successful. Otherwise, the operation fails.| **path** indicates the pointer to the absolute path of the target file or directory.<br>**nthreads** indicates the number of threads. | 16e41f4b71Sopenharmony_ci| int **RestoreconRecurseForce**(const char *path); | Forcibly updates the file or directory label for a single thread, and recursively traverses and updates the labels of subdirectories and their files.<br>If **0** is returned, the operation is successful. Otherwise, the operation fails.| **path** indicates the pointer to the absolute path of the target file or directory.| 17e41f4b71Sopenharmony_ci| int **RestoreconFromParentDir**(const char *path); | Updates the label of the directory based on its parent directory for a single thread, and recursively traverses and updates the entire directory.<br>If **0** is returned, the operation is successful. Otherwise, the operation fails.| **path** indicates the pointer to the absolute path of the parent directory.| 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## How to Develop 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci1. Add the dependency for compilation. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci ```text 24e41f4b71Sopenharmony_ci external_deps += [ "selinux_adapter:librestorecon" ] 25e41f4b71Sopenharmony_ci ``` 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci2. Include the header file. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci ```cpp 30e41f4b71Sopenharmony_ci #include "policycoreutils.h" 31e41f4b71Sopenharmony_ci ``` 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci3. Call the APIs. 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci For example, call **Restorecon** to update the labe of **/data**. 36e41f4b71Sopenharmony_ci ```cpp 37e41f4b71Sopenharmony_ci // Update the label of /data. 38e41f4b71Sopenharmony_ci int ret = Restorecon("/data"); 39e41f4b71Sopenharmony_ci ``` 40e41f4b71Sopenharmony_ci 41