oh_file_share.h
Overview
Provides APIs for persisting permissions, activating or deactivating persistent permissions, and checking the persistent permissions on files or directories based on their URIs.
File to include: <filemanagement/fileshare/oh_file_share.h>
Library: libohfileshare.so
System capability: SystemCapability.FileManagement.AppFileService.FolderAuthorization
Since: 12
Related module: fileShare
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| FileShare_PolicyErrorResult | FileShare_PolicyErrorResult | Represents the permission policy error result. |
| FileShare_PolicyInfo | FileShare_PolicyInfo | Represents the permission policy information. |
Enums
| Name | typedef Keyword | Description |
|---|---|---|
| FileShare_OperationMode | FileShare_OperationMode | Enumerates the URI operation mode. |
| FileShare_PolicyErrorCode | FileShare_PolicyErrorCode | Enumerates the error codes for a permission policy. |
Functions
Enum Description
FileShare_OperationMode
enum FileShare_OperationMode
Description
Enumerates the URI operation mode.
Since: 12
| Enum Item | Description |
|---|---|
| READ_MODE = 1 << 0 | Read. |
| WRITE_MODE = 1 << 1 | Write. |
FileShare_PolicyErrorCode
enum FileShare_PolicyErrorCode
Description
Enumerates the error codes for a permission policy.
Since: 12
| Enum Item | Description |
|---|---|
| PERSISTENCE_FORBIDDEN = 1 | The permission on the URI cannot be persisted. |
| INVALID_MODE = 2 | Invalid mode. |
| INVALID_PATH = 3 | Invalid path. |
| PERMISSION_NOT_PERSISTED = 4 | The permission is not persisted. |
Function Description
OH_FileShare_PersistPermission()
FileManagement_ErrCode OH_FileShare_PersistPermission(const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum)
Description
Persists the permissions on files or directories.
Required permissions: ohos.permission.FILE_ACCESS_PERSIST
Since: 12
Parameters
| Name | Description |
|---|---|
| const FileShare_PolicyInfo *policies | Pointer to a FileShare_PolicyInfo instance. |
| unsigned int policyNum | Number of policies in the FileShare_PolicyInfo array. |
| FileShare_PolicyErrorResult **result | Double pointer to the FileShare_PolicyErrorResult array. Use OH_FileShare_ReleasePolicyErrorResult() to release the memory allocated. |
| unsigned int *resultNum | Pointer to the size of the FileShare_PolicyErrorResult array. |
Returns
| Type | Description |
|---|---|
| FileManagement_ErrCode | Returns FileManagement_ErrCode. ERR_INVALID_PARAMETER 401 - The input parameter is invalid. Possible causes: 1. The policies, result, or resultNum parameter is a null pointer. 2. The value of policyNum is 0 or exceeds the maximum length (500). 3. The value of uri in the policies parameter is empty, the value of length is 0, or the value of uri is different from the value of length. ERR_DEVICE_NOT_SUPPORTED 801 - The device does not support this API. ERR_PERMISSION_ERROR 201 - The permission verification fails. ERR_ENOMEM 13900011 - The memory allocation or copy fails. ERR_EPERM 13900001 - The operation is not allowed. ERR_OK 0 - The API is called successfully. |
OH_FileShare_RevokePermission()
FileManagement_ErrCode OH_FileShare_RevokePermission(const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum)
Description
Revokes the permissions from files or directories.
Required permissions: ohos.permission.FILE_ACCESS_PERSIST
Since: 12
Parameters
| Name | Description |
|---|---|
| const FileShare_PolicyInfo *policies | Pointer to a FileShare_PolicyInfo instance. |
| unsigned int policyNum | Number of policies in the FileShare_PolicyInfo array. |
| FileShare_PolicyErrorResult **result | Double pointer to the FileShare_PolicyErrorResult array. Use OH_FileShare_ReleasePolicyErrorResult() to release the memory allocated. |
| unsigned int *resultNum | Pointer to the size of the FileShare_PolicyErrorResult array. |
Returns
| Type | Description |
|---|---|
| FileManagement_ErrCode | Returns FileManagement_ErrCode. ERR_INVALID_PARAMETER 401 - The input parameter is invalid. Possible causes: 1. The policies, result, or resultNum parameter is a null pointer. 2. The value of policyNum is 0 or exceeds the maximum length (500). 3. The value of uri in the policies parameter is empty, the value of length is 0, or the value of uri is different from the value of length. ERR_DEVICE_NOT_SUPPORTED 801 - The device does not support this API. ERR_PERMISSION_ERROR 201 - The permission verification fails. ERR_ENOMEM 13900011 - The memory allocation or copy fails. ERR_EPERM 13900001 - The operation is not allowed. ERR_OK 0 - The API is called successfully. |
OH_FileShare_ActivatePermission()
FileManagement_ErrCode OH_FileShare_ActivatePermission(const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum)
Description
Activates the persistent permissions on files or directories.
Required permissions: ohos.permission.FILE_ACCESS_PERSIST
Since: 12
Parameters
| Name | Description |
|---|---|
| const FileShare_PolicyInfo *policies | Pointer to a FileShare_PolicyInfo instance. |
| unsigned int policyNum | Number of policies in the FileShare_PolicyInfo array. |
| FileShare_PolicyErrorResult **result | Double pointer to the FileShare_PolicyErrorResult array. Use OH_FileShare_ReleasePolicyErrorResult() to release the memory allocated. |
| unsigned int *resultNum | Pointer to the size of the FileShare_PolicyErrorResult array. |
Returns
| Type | Description |
|---|---|
| FileManagement_ErrCode | Returns FileManagement_ErrCode. ERR_INVALID_PARAMETER 401 - The input parameter is invalid. Possible causes: 1. The policies, result, or resultNum parameter is a null pointer. 2. The value of policyNum is 0 or exceeds the maximum length (500). 3. The value of uri in the policies parameter is empty, the value of length is 0, or the value of uri is different from the value of length. ERR_DEVICE_NOT_SUPPORTED 801 - The device does not support this API. ERR_PERMISSION_ERROR 201 - The permission verification fails. ERR_ENOMEM 13900011 - The memory allocation or copy fails. ERR_EPERM 13900001 - The operation is not allowed. ERR_OK 0 - The API is called successfully. |
OH_FileShare_DeactivatePermission()
FileManagement_ErrCode OH_FileShare_DeactivatePermission(const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum)
Description
Deactivates the persistent permissions on files or directories.
Required permissions: ohos.permission.FILE_ACCESS_PERSIST
Since: 12
Parameters
| Name | Description |
|---|---|
| const FileShare_PolicyInfo *policies | Pointer to a FileShare_PolicyInfo instance. |
| unsigned int policyNum | Number of policies in the FileShare_PolicyInfo array. |
| FileShare_PolicyErrorResult **result | Double pointer to the FileShare_PolicyErrorResult array. Use OH_FileShare_ReleasePolicyErrorResult() to release the memory allocated. |
| unsigned int *resultNum | Pointer to the size of the FileShare_PolicyErrorResult array. |
Returns
| Type | Description |
|---|---|
| FileManagement_ErrCode | Returns FileManagement_ErrCode. ERR_INVALID_PARAMETER 401 - The input parameter is invalid. Possible causes: 1. The policies, result, or resultNum parameter is a null pointer. 2. The value of policyNum is 0 or exceeds the maximum length (500). 3. The value of uri in the policies parameter is empty, the value of length is 0, or the value of uri is different from the value of length. ERR_DEVICE_NOT_SUPPORTED 801 - The device does not support this API. ERR_PERMISSION_ERROR 201 - The permission verification fails. ERR_ENOMEM 13900011 - The memory allocation or copy fails. ERR_EPERM 13900001 - The operation is not allowed. ERR_OK 0 - The API is called successfully. |
OH_FileShare_CheckPersistentPermission()
FileManagement_ErrCode OH_FileShare_CheckPersistentPermission(const FileShare_PolicyInfo *policies, unsigned int policyNum, bool **result, unsigned int *resultNum)
Description
Checks the persistent permissions on files or directories.
Required permissions: ohos.permission.FILE_ACCESS_PERSIST
Since: 12
Parameters
| Name | Description |
|---|---|
| const FileShare_PolicyInfo *policies | Pointer to a FileShare_PolicyInfo instance. |
| unsigned int policyNum | Number of policies in the FileShare_PolicyInfo array. |
| bool **result | Double pointer to the check result obtained. The value true means the permission is persistent; the value false means the opposite. You also need to include malloc.h and use free() to release the memory allocated. |
| unsigned int *resultNum | Pointer to the size of the check result array. |
Returns
| Type | Description |
|---|---|
| FileManagement_ErrCode | Returns FileManagement_ErrCode. ERR_INVALID_PARAMETER 401 - The input parameter is invalid. Possible causes: 1. The policies, result, or resultNum parameter is a null pointer. 2. The value of policyNum is 0 or exceeds the maximum length (500). 3. The value of uri in the policies parameter is empty, the value of length is 0, or the value of uri is different from the value of length. ERR_DEVICE_NOT_SUPPORTED 801 - The device does not support this API. ERR_PERMISSION_ERROR 201 - The permission verification fails. ERR_ENOMEM 13900011 - The memory allocation or copy fails. ERR_EPERM 13900001 - The operation is not allowed. All URIs carried in policies do not meet the specifications, or the path converted from the URI does not exist. ERR_OK 0 - The API is called successfully. |
OH_FileShare_ReleasePolicyErrorResult()
void OH_FileShare_ReleasePolicyErrorResult(FileShare_PolicyErrorResult *errorResult, unsigned int resultNum)
Description
Releases the memory, to which FileShare_PolicyErrorResult points.
Since: 12
Parameters
| Name | Description |
|---|---|
| FileShare_PolicyErrorResult *errorResult | Pointer to a FileShare_PolicyErrorResult instance. |
| unsigned int resultNum | Size of the FileShare_PolicyErrorResult array. |
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 js-apis-file-environment-sys
openharmony 鸿蒙 js-apis-file-fs
openharmony 鸿蒙 capi-clouddisk-clouddisk-pathinfo
openharmony 鸿蒙 capi-clouddisk-clouddisk-changesresult
openharmony 鸿蒙 capi-clouddisk-clouddisk-syncfolder
openharmony 鸿蒙 js-apis-fileShare
openharmony 鸿蒙 js-apis-file-storage-statistics-sys