1# FileShare
2
3
4## Overview
5
6The **fileShare** module provides APIs for granting permissions on a user file to another application based on the file Uniform Resource Identifier (URI).
7
8**Since**: 12
9
10
11## Summary
12
13
14### Files
15
16| Name| Description|
17| -------- | -------- |
18| [oh_file_share.h](oh__file__share_8h.md) | Provides APIs for persisting permissions, activating or deactivating permissions, and obtaining permissions on files based on their URI.|
19
20
21### Structs
22
23| Name| Description|
24| -------- | -------- |
25| struct  [FileShare_PolicyErrorResult](_file_share___policy_error_result.md) | Defines a struct for the permission policy error information.|
26| struct  [FileShare_PolicyInfo](_file_share___policy_info.md) | Defines a struct for the permission policy information.|
27
28
29### Types
30
31| Name| Description|
32| -------- | -------- |
33| typedef enum [FileShare_OperationMode](#fileshare_operationmode-1) [FileShare_OperationMode](#fileshare_operationmode) | Defines an enum for the permissions on a URI.|
34| typedef enum [FileShare_PolicyErrorCode](#fileshare_policyerrorcode-1) [FileShare_PolicyErrorCode](#fileshare_policyerrorcode) | Defines an enum for the permission policy error codes.|
35| typedef struct [FileShare_PolicyErrorResult](_file_share___policy_error_result.md) [FileShare_PolicyErrorResult](#fileshare_policyerrorresult) | Defines a struct for the permission policy error information.|
36| typedef struct [FileShare_PolicyInfo](_file_share___policy_info.md) [FileShare_PolicyInfo](#fileshare_policyinfo) | Defines a struct for the permission policy information.|
37
38
39### Enums
40
41| Name| Description|
42| -------- | -------- |
43| [FileShare_OperationMode](#fileshare_operationmode) {<br>READ_MODE = 1 &lt;&lt; 0,<br>WRITE_MODE = 1 &lt;&lt; 1<br>} | Enumerates the permissions on a URI.|
44| [FileShare_PolicyErrorCode](#fileshare_policyerrorcode) {<br>PERSISTENCE_FORBIDDEN = 1,<br>INVALID_MODE = 2,<br>INVALID_PATH = 3,<br>PERMISSION_NOT_PERSISTED = 4<br>} | Enumerates the permission policy error codes.|
45
46
47### Functions
48
49| Name| Description|
50| -------- | -------- |
51| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileShare_PersistPermission](#oh_fileshare_persistpermission) (const [FileShare_PolicyInfo](_file_share___policy_info.md) \*policies, unsigned int policyNum, [FileShare_PolicyErrorResult](_file_share___policy_error_result.md) \*\*result, unsigned int \*resultNum) | Persists the permissions on files or folders.|
52| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileShare_RevokePermission](#oh_fileshare_revokepermission) (const [FileShare_PolicyInfo](_file_share___policy_info.md) \*policies, unsigned int policyNum, [FileShare_PolicyErrorResult](_file_share___policy_error_result.md) \*\*result, unsigned int \*resultNum) | Revokes the permissions from files or folders.|
53| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileShare_ActivatePermission](#oh_fileshare_activatepermission) (const [FileShare_PolicyInfo](_file_share___policy_info.md) \*policies, unsigned int policyNum, [FileShare_PolicyErrorResult](_file_share___policy_error_result.md) \*\*result, unsigned int \*resultNum) | Activates the persistent permissions on files or folders.|
54| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileShare_DeactivatePermission](#oh_fileshare_deactivatepermission) (const [FileShare_PolicyInfo](_file_share___policy_info.md) \*policies, unsigned int policyNum, [FileShare_PolicyErrorResult](_file_share___policy_error_result.md) \*\*result, unsigned int \*resultNum) | Deactivates the persistent permissions on files or folders.|
55| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileShare_CheckPersistentPermission](#oh_fileshare_checkpersistentpermission) (const [FileShare_PolicyInfo](_file_share___policy_info.md) \*policies, unsigned int policyNum, bool \*\*result, unsigned int \*resultNum) | Checks the persistent permissions on files or folders.|
56| void [OH_FileShare_ReleasePolicyErrorResult](#oh_fileshare_releasepolicyerrorresult) ([FileShare_PolicyErrorResult](_file_share___policy_error_result.md) \*errorResult, unsigned int resultNum) | Releases the memory used by **FileShare_PolicyErrorResult**.|
57
58
59## Type Description
60
61
62### FileShare_OperationMode
63
64```
65typedef enum FileShare_OperationMode FileShare_OperationMode
66```
67
68**Description**
69
70Defines an enum for the permissions on a URI.
71
72**Since**: 12
73
74
75### FileShare_PolicyErrorCode
76
77```
78typedef enum FileShare_PolicyErrorCode FileShare_PolicyErrorCode
79```
80
81**Description**
82
83Defines an enum for the permission policy error codes.
84
85**Since**: 12
86
87
88### FileShare_PolicyErrorResult
89
90```
91typedef struct FileShare_PolicyErrorResult FileShare_PolicyErrorResult
92```
93
94**Description**
95
96Defines a struct for the permission policy error information.
97
98**Since**: 12
99
100
101### FileShare_PolicyInfo
102
103```
104typedef struct FileShare_PolicyInfo FileShare_PolicyInfo
105```
106
107**Description**
108
109Represents a permission policy, that is, a policy for granting or activating the permission on a file.
110
111**Since**: 12
112
113
114## Enum Description
115
116
117### FileShare_OperationMode
118
119```
120enum FileShare_OperationMode
121```
122
123**Description**
124
125Enumerates the permissions on a URI.
126
127**Since**: 12
128
129| Value| Description|
130| -------- | -------- |
131| READ_MODE | Read.|
132| WRITE_MODE | Write.|
133
134
135### FileShare_PolicyErrorCode
136
137```
138enum FileShare_PolicyErrorCode
139```
140
141**Description**
142
143Enumerates the permission policy error codes.
144
145**Since**: 12
146
147| Value| Description|
148| -------- | -------- |
149| PERSISTENCE_FORBIDDEN | The permission on the URI cannot be persisted.|
150| INVALID_MODE | Invalid mode.|
151| INVALID_PATH | Invalid path.|
152| PERMISSION_NOT_PERSISTED | The permission is not persisted.|
153
154
155## Function Description
156
157
158### OH_FileShare_ActivatePermission()
159
160```
161FileManagement_ErrCode OH_FileShare_ActivatePermission (const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum )
162```
163
164**Description**
165
166Activates the persistent permissions on files or folders.
167
168**Since**: 12
169
170**Parameters**
171
172| Name| Description|
173| -------- | -------- |
174| policies | Pointer to a **FileShare_PolicyInfo** instance.|
175| policyNum | Number of policies in the **FileShare_PolicyInfo** array.|
176| result | Double pointer to the **FileShare_PolicyErrorResult** array obtained. Use **OH_FileShare_ReleasePolicyErrorResult()** to release the memory allocated.|
177| resultNum | Pointer to the size of the **FileShare_PolicyErrorResult** array.|
178
179**Required permissions**
180
181ohos.permission.FILE_ACCESS_PERSIST
182
183**Returns**
184
185Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode-1).
186
187
188### OH_FileShare_CheckPersistentPermission()
189
190```
191FileManagement_ErrCode OH_FileShare_CheckPersistentPermission (const FileShare_PolicyInfo *policies, unsigned int policyNum, bool **result, unsigned int *resultNum )
192```
193
194**Description**
195
196Checks the persistent permissions on files or folders.
197
198**Since**: 12
199
200**Parameters**
201
202| Name| Description|
203| -------- | -------- |
204| policies | Pointer to a **FileShare_PolicyInfo** instance.|
205| policyNum | Number of policies in the **FileShare_PolicyInfo** array.|
206| result | Double pointer to the check result obtained. You also need to include **malloc.h** and use **free()** to release the memory allocated.|
207| resultNum | Pointer to the size of the check result array.|
208
209**Required permissions**
210
211ohos.permission.FILE_ACCESS_PERSIST
212
213**Returns**
214
215Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode-1).
216
217
218### OH_FileShare_DeactivatePermission()
219
220```
221FileManagement_ErrCode OH_FileShare_DeactivatePermission (const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum )
222```
223
224**Description**
225
226Deactivates the persistent permissions on files or folders.
227
228**Since**: 12
229
230**Parameters**
231
232| Name| Description|
233| -------- | -------- |
234| policies | Pointer to a **FileShare_PolicyInfo** instance.|
235| policyNum | Number of policies in the **FileShare_PolicyInfo** array.|
236| result | Double pointer to the **FileShare_PolicyErrorResult** array obtained. Use **OH_FileShare_ReleasePolicyErrorResult()** to release the memory allocated.|
237| resultNum | Pointer to the size of the **FileShare_PolicyErrorResult** array.|
238
239**Required permissions**
240
241ohos.permission.FILE_ACCESS_PERSIST
242
243**Returns**
244
245Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode-1).
246
247
248### OH_FileShare_PersistPermission()
249
250```
251FileManagement_ErrCode OH_FileShare_PersistPermission (const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum )
252```
253
254**Description**
255
256Persists the permissions on files or folders.
257
258**Since**: 12
259
260**Parameters**
261
262| Name| Description|
263| -------- | -------- |
264| policies | Pointer to a **FileShare_PolicyInfo** instance.|
265| policyNum | Number of policies in the **FileShare_PolicyInfo** array.|
266| result | Double pointer to the **FileShare_PolicyErrorResult** array obtained. Use **OH_FileShare_ReleasePolicyErrorResult()** to release the memory allocated.|
267| resultNum | Pointer to the size of the **FileShare_PolicyErrorResult** array.|
268
269**Required permissions**
270
271ohos.permission.FILE_ACCESS_PERSIST
272
273**Returns**
274
275Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode-1).
276
277
278### OH_FileShare_ReleasePolicyErrorResult()
279
280```
281void OH_FileShare_ReleasePolicyErrorResult (FileShare_PolicyErrorResult *errorResult, unsigned int resultNum )
282```
283
284**Description**
285
286Releases the memory used by **FileShare_PolicyErrorResult**.
287
288**Since**: 12
289
290**Parameters**
291
292| Name| Description|
293| -------- | -------- |
294| errorResult | Pointer to a **FileShare_PolicyErrorResult** instance.|
295| resultNum | Size of the **FileShare_PolicyErrorResult** array.|
296
297
298### OH_FileShare_RevokePermission()
299
300```
301FileManagement_ErrCode OH_FileShare_RevokePermission (const FileShare_PolicyInfo *policies, unsigned int policyNum, FileShare_PolicyErrorResult **result, unsigned int *resultNum )
302```
303
304**Description**
305
306Revokes the permissions from files or folders.
307
308**Since**: 12
309
310**Parameters**
311
312| Name| Description|
313| -------- | -------- |
314| policies | Pointer to a **FileShare_PolicyInfo** instance.|
315| policyNum | Number of policies in the **FileShare_PolicyInfo** array.|
316| result | Double pointer to the **FileShare_PolicyErrorResult** array obtained. Use **OH_FileShare_ReleasePolicyErrorResult()** to release the memory allocated.|
317| resultNum | Pointer to the size of the **FileShare_PolicyErrorResult** array.|
318
319**Required permissions**
320
321ohos.permission.FILE_ACCESS_PERSIST
322
323**Returns**
324
325Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode-1).
326