openharmony 鸿蒙 capi-oh-file-share-h

2026-08-25 浏览 (1)

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

Nametypedef KeywordDescription
FileShare_PolicyErrorResultFileShare_PolicyErrorResultRepresents the permission policy error result.
FileShare_PolicyInfoFileShare_PolicyInfoRepresents the permission policy information.

Enums

Nametypedef KeywordDescription
FileShare_OperationModeFileShare_OperationModeEnumerates the URI operation mode.
FileShare_PolicyErrorCodeFileShare_PolicyErrorCodeEnumerates the error codes for a permission policy.

Functions

NameDescription
FileManagement_ErrCode OH_FileShare_PersistPermission(const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum)Persists the permissions on files or directories.
FileManagement_ErrCode OH_FileShare_RevokePermission(const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum)Revokes the permissions from files or directories.
FileManagement_ErrCode OH_FileShare_ActivatePermission(const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum)Activates the persistent permissions on files or directories.
FileManagement_ErrCode OH_FileShare_DeactivatePermission(const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum)Deactivates the persistent permissions on files or directories.
FileManagement_ErrCode OH_FileShare_CheckPersistentPermission(const FileShare_PolicyInfo *policies, unsigned int policyNum, bool **result, unsigned int *resultNum)Checks the persistent permissions on files or directories.
void OH_FileShare_ReleasePolicyErrorResult(FileShare_PolicyErrorResult *errorResult, unsigned int resultNum)Releases the memory, to which FileShare_PolicyErrorResult points.

Enum Description

FileShare_OperationMode

enum FileShare_OperationMode

Description

Enumerates the URI operation mode.

Since: 12

Enum ItemDescription
READ_MODE = 1 << 0Read.
WRITE_MODE = 1 << 1Write.

FileShare_PolicyErrorCode

enum FileShare_PolicyErrorCode

Description

Enumerates the error codes for a permission policy.

Since: 12

Enum ItemDescription
PERSISTENCE_FORBIDDEN = 1The permission on the URI cannot be persisted.
INVALID_MODE = 2Invalid mode.
INVALID_PATH = 3Invalid path.
PERMISSION_NOT_PERSISTED = 4The 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

NameDescription
const FileShare_PolicyInfo *policiesPointer to a FileShare_PolicyInfo instance.
unsigned int policyNumNumber of policies in the FileShare_PolicyInfo array.
FileShare_PolicyErrorResult **resultDouble pointer to the FileShare_PolicyErrorResult array. Use OH_FileShare_ReleasePolicyErrorResult() to release the memory allocated.
unsigned int *resultNumPointer to the size of the FileShare_PolicyErrorResult array.

Returns

TypeDescription
FileManagement_ErrCodeReturns 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

NameDescription
const FileShare_PolicyInfo *policiesPointer to a FileShare_PolicyInfo instance.
unsigned int policyNumNumber of policies in the FileShare_PolicyInfo array.
FileShare_PolicyErrorResult **resultDouble pointer to the FileShare_PolicyErrorResult array. Use OH_FileShare_ReleasePolicyErrorResult() to release the memory allocated.
unsigned int *resultNumPointer to the size of the FileShare_PolicyErrorResult array.

Returns

TypeDescription
FileManagement_ErrCodeReturns 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

NameDescription
const FileShare_PolicyInfo *policiesPointer to a FileShare_PolicyInfo instance.
unsigned int policyNumNumber of policies in the FileShare_PolicyInfo array.
FileShare_PolicyErrorResult **resultDouble pointer to the FileShare_PolicyErrorResult array. Use OH_FileShare_ReleasePolicyErrorResult() to release the memory allocated.
unsigned int *resultNumPointer to the size of the FileShare_PolicyErrorResult array.

Returns

TypeDescription
FileManagement_ErrCodeReturns 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

NameDescription
const FileShare_PolicyInfo *policiesPointer to a FileShare_PolicyInfo instance.
unsigned int policyNumNumber of policies in the FileShare_PolicyInfo array.
FileShare_PolicyErrorResult **resultDouble pointer to the FileShare_PolicyErrorResult array. Use OH_FileShare_ReleasePolicyErrorResult() to release the memory allocated.
unsigned int *resultNumPointer to the size of the FileShare_PolicyErrorResult array.

Returns

TypeDescription
FileManagement_ErrCodeReturns 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

NameDescription
const FileShare_PolicyInfo *policiesPointer to a FileShare_PolicyInfo instance.
unsigned int policyNumNumber of policies in the FileShare_PolicyInfo array.
bool **resultDouble 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 *resultNumPointer to the size of the check result array.

Returns

TypeDescription
FileManagement_ErrCodeReturns 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

NameDescription
FileShare_PolicyErrorResult *errorResultPointer to a FileShare_PolicyErrorResult instance.
unsigned int resultNumSize 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 鸿蒙 capi-fileio

openharmony 鸿蒙 js-apis-file-storage-statistics-sys

openharmony 鸿蒙 js-apis-file-cloudsyncmanager

openharmony 鸿蒙 js-apis-file-environment

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/LcKa12hu