• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# raw_file.h
2
3## Overview
4
5Provides functions related to rawfiles, including searching for, reading, and closing rawfiles.
6
7**File to include**: <rawfile/raw_file.h>
8
9**Library**: librawfile.z.so
10
11**System capability**: SystemCapability.Global.ResourceManager
12
13**Since**: 8
14
15**Related module**: [rawfile](capi-rawfile.md)
16
17## Summary
18
19### Structs
20
21| Name| typedef Keyword| Description                                                                                                                                                                     |
22| -- | -- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
23| [RawFileDescriptor](capi-rawfile-rawfiledescriptor.md) | RawFileDescriptor | Defines the file descriptor information of a file in the **rawfile** directory. **RawFileDescriptor** is an output parameter of [OH_ResourceManager_GetRawFileDescriptor](#oh_resourcemanager_getrawfiledescriptor). It contains the file descriptor of a rawfile and the start position and length of the rawfile in the HAP.        |
24| [RawFileDescriptor64](capi-rawfile-rawfiledescriptor64.md) | RawFileDescriptor64 | Defines the file descriptor of a large rawfile. **RawFileDescriptor64** is an output parameter of [OH_ResourceManager_GetRawFileDescriptor64](#oh_resourcemanager_getrawfiledescriptor64). It contains the file descriptor of a rawfile and the start position and length of the rawfile in the HAP.|
25| [RawFile](capi-rawfile-rawfile.md) | RawFile | Provides access to rawfiles.                                                                                                                                                       |
26| [RawFile64](capi-rawfile-rawfile64.md) | RawFile64 | Provides access to large rawfiles.                                                                                                                                                     |
27
28### Functions
29
30| Name| Description                                                                           |
31| -- |-------------------------------------------------------------------------------|
32| [int OH_ResourceManager_ReadRawFile(const RawFile *rawFile, void *buf, size_t length)](#oh_resourcemanager_readrawfile) | Reads data of the specified length from the current position in a rawfile.                                                  |
33| [int OH_ResourceManager_SeekRawFile(const RawFile *rawFile, long offset, int whence)](#oh_resourcemanager_seekrawfile) | Searches for the data read/write position in a rawfile based on the specified offset.                                               |
34| [long OH_ResourceManager_GetRawFileSize(RawFile *rawFile)](#oh_resourcemanager_getrawfilesize) | Obtains the length of the rawfile, in long.                                                         |
35| [long OH_ResourceManager_GetRawFileRemainingLength(const RawFile *rawFile)](#oh_resourcemanager_getrawfileremaininglength) | Obtains the remaining length of the rawfile, in long.                                                      |
36| [void OH_ResourceManager_CloseRawFile(RawFile *rawFile)](#oh_resourcemanager_closerawfile) | Closes a [RawFile](capi-rawfile-rawfile.md) and releases all associated resources.                       |
37| [long OH_ResourceManager_GetRawFileOffset(const RawFile *rawFile)](#oh_resourcemanager_getrawfileoffset) | Obtains the current offset of a rawfile, in long. Current offset of the rawfile.                                       |
38| [bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDescriptor &descriptor)](#oh_resourcemanager_getrawfiledescriptor) | Opens a rawfile based on the specified offset (in long) and file length (in long) and obtains the file descriptor. The file descriptor obtained can be used to read the file.  |
39| [bool OH_ResourceManager_ReleaseRawFileDescriptor(const RawFileDescriptor &descriptor)](#oh_resourcemanager_releaserawfiledescriptor) | Releases the file descriptor of a rawfile. To prevent file descriptor leakage, you are advised to release a rawfile descriptor immediately after use.                                |
40| [bool OH_ResourceManager_ReleaseRawFileDescriptorData(const RawFileDescriptor *descriptor)](#oh_resourcemanager_releaserawfiledescriptordata) | Releases the file descriptor of a rawfile. To prevent file descriptor leakage, you are advised to release a rawfile descriptor immediately after use.                                |
41| [int64_t OH_ResourceManager_ReadRawFile64(const RawFile64 *rawFile, void *buf, int64_t length)](#oh_resourcemanager_readrawfile64) | Reads data of the specified length from the current position in a large rawfile.                                             |
42| [int OH_ResourceManager_SeekRawFile64(const RawFile64 *rawFile, int64_t offset, int whence)](#oh_resourcemanager_seekrawfile64) | Searches for the data read/write position in a large rawfile based on the specified offset.                                            |
43| [int64_t OH_ResourceManager_GetRawFileSize64(RawFile64 *rawFile)](#oh_resourcemanager_getrawfilesize64) | Obtains the length of a large rawfile, in int64_t.                                                 |
44| [int64_t OH_ResourceManager_GetRawFileRemainingLength64(const RawFile64 *rawFile)](#oh_resourcemanager_getrawfileremaininglength64) | Obtains the remaining length of a large rawfile, in int64_t.                                                 |
45| [void OH_ResourceManager_CloseRawFile64(RawFile64 *rawFile)](#oh_resourcemanager_closerawfile64) | Closes an opened [RawFile64](capi-rawfile-rawfile64.md) and releases all associated resources.                                     |
46| [int64_t OH_ResourceManager_GetRawFileOffset64(const RawFile64 *rawFile)](#oh_resourcemanager_getrawfileoffset64) | Obtains the offset of a large rawfile, in int64_t.                                                |
47| [bool OH_ResourceManager_GetRawFileDescriptor64(const RawFile64 *rawFile, RawFileDescriptor64 *descriptor)](#oh_resourcemanager_getrawfiledescriptor64) | Opens a large rawfile based on the specified offset (in int64_t) and file length (in int64_t) and obtains the file descriptor. The file descriptor obtained can be used to read the file.|
48| [bool OH_ResourceManager_ReleaseRawFileDescriptor64(const RawFileDescriptor64 *descriptor)](#oh_resourcemanager_releaserawfiledescriptor64) | Releases the file descriptor of a rawfile. To prevent file descriptor leakage, you are advised to release a rawfile descriptor immediately after use.                                |
49
50## Function Description
51
52### OH_ResourceManager_ReadRawFile()
53
54```
55int OH_ResourceManager_ReadRawFile(const RawFile *rawFile, void *buf, size_t length)
56```
57
58**Description**
59
60Reads data of the specified length from the current position in a rawfile.
61
62**Since**: 8
63
64
65**Parameters**
66
67| Name| Description|
68| -- | -- |
69| const [RawFile](capi-rawfile-rawfile.md) *rawFile | Pointer to [RawFile](capi-rawfile-rawfile.md).|
70| void *buf | Pointer to the buffer for receiving the read data.|
71| size_t length | Length of the data to read.|
72
73**Returns**
74
75| Type| Description|
76| -- | -- |
77| int | Number of read bytes. If the read length exceeds the length of the file end or rawfile is empty, **0** is returned.|
78
79### OH_ResourceManager_SeekRawFile()
80
81```
82int OH_ResourceManager_SeekRawFile(const RawFile *rawFile, long offset, int whence)
83```
84
85**Description**
86
87Searches for the data read/write position in a rawfile based on the specified offset.
88
89**Since**: 8
90
91
92**Parameters**
93
94| Name| Description|
95| -- | -- |
96| const [RawFile](capi-rawfile-rawfile.md) *rawFile | Pointer to [RawFile](capi-rawfile-rawfile.md).|
97| long offset | Specified offset.|
98| int whence | Read/Write position. The options are as follows:<br> **0**: The read/write position is the start position of the file plus the offset.<br> **1**: The read/write position is the current position plus the offset.<br> **2**: The read/write position is the end position of the file plus the offset.|
99
100**Returns**
101
102| Type| Description|
103| -- | -- |
104| int | **0** if the search is successful; **-1** otherwise.|
105
106### OH_ResourceManager_GetRawFileSize()
107
108```
109long OH_ResourceManager_GetRawFileSize(RawFile *rawFile)
110```
111
112**Description**
113
114Obtains the length of the rawfile, in long.
115
116**Since**: 8
117
118
119**Parameters**
120
121| Name| Description|
122| -- | -- |
123| [RawFile](capi-rawfile-rawfile.md) *rawFile | Pointer to [RawFile](capi-rawfile-rawfile.md).|
124
125**Returns**
126
127| Type| Description|
128| -- | -- |
129| long | Overall length of the rawfile. If the rawfile is empty, **0** is returned.|
130
131### OH_ResourceManager_GetRawFileRemainingLength()
132
133```
134long OH_ResourceManager_GetRawFileRemainingLength(const RawFile *rawFile)
135```
136
137**Description**
138
139Obtains the remaining length of the rawfile, in long.
140
141**Since**: 11
142
143
144**Parameters**
145
146| Name| Description|
147| -- | -- |
148| const [RawFile](capi-rawfile-rawfile.md) *rawFile | Pointer to [RawFile](capi-rawfile-rawfile.md).|
149
150**Returns**
151
152| Type| Description|
153| -- | -- |
154| long | Remaining length of the rawfile. If the rawfile is empty, **0** is returned.|
155
156### OH_ResourceManager_CloseRawFile()
157
158```
159void OH_ResourceManager_CloseRawFile(RawFile *rawFile)
160```
161
162**Description**
163
164Closes a [RawFile](capi-rawfile-rawfile.md) and releases all associated resources.
165
166**Since**: 8
167
168
169**Parameters**
170
171| Name| Description|
172| -- | -- |
173| [RawFile](capi-rawfile-rawfile.md) *rawFile | Pointer to [RawFile](capi-rawfile-rawfile.md).|
174
175**Reference**
176
177[OH_ResourceManager_OpenRawFile](capi-raw-file-manager-h.md#oh_resourcemanager_openrawfile)
178
179### OH_ResourceManager_GetRawFileOffset()
180
181```
182long OH_ResourceManager_GetRawFileOffset(const RawFile *rawFile)
183```
184
185**Description**
186
187Obtains the current offset of a rawfile, in long. Current offset of the rawfile.
188
189**Since**: 8
190
191
192**Parameters**
193
194| Name| Description|
195| -- | -- |
196| const [RawFile](capi-rawfile-rawfile.md) *rawFile | Pointer to [RawFile](capi-rawfile-rawfile.md).|
197
198**Returns**
199
200| Type| Description|
201| -- | -- |
202| long | Current offset of the rawfile. If the rawfile is empty, **0** is returned.|
203
204### OH_ResourceManager_GetRawFileDescriptor()
205
206```
207bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDescriptor &descriptor)
208```
209
210**Description**
211
212Opens a rawfile based on the specified offset (in long) and file length (in long) and obtains the file descriptor. The file descriptor obtained can be used to read the file.
213
214**Since**: 8
215
216
217**Parameters**
218
219| Name                                              | Description|
220|---------------------------------------------------| -- |
221| const [RawFile](capi-rawfile-rawfile.md) *rawFile | Pointer to [RawFile](capi-rawfile-rawfile.md).|
222| [RawFileDescriptor](capi-rawfile-rawfiledescriptor.md) &descriptor                 | File descriptor of the rawfile, start position of the rawfile in the HAP, and length of the rawfile.|
223
224**Returns**
225
226| Type| Description|
227| -- | -- |
228| bool | <b>true</b> if the file is opened; returns <b>false</b> if the access to the file is rejected.|
229
230### OH_ResourceManager_ReleaseRawFileDescriptor()
231
232```
233bool OH_ResourceManager_ReleaseRawFileDescriptor(const RawFileDescriptor &descriptor)
234```
235
236**Description**
237
238Releases the file descriptor of a rawfile. To prevent file descriptor leakage, you are advised to release a rawfile descriptor immediately after use.
239
240**Since**: 8
241
242
243**Parameters**
244
245| Name| Description|
246| -- | -- |
247| const [RawFileDescriptor](capi-rawfile-rawfiledescriptor.md) &descriptor | File descriptor of the rawfile. It contains the file descriptor, start position in the HAP, and file length.|
248
249**Returns**
250
251| Type| Description|
252| -- | -- |
253| bool | Returns <b>true</b> if the file descriptor is released; returns <b>false</b> otherwise.|
254
255### OH_ResourceManager_ReleaseRawFileDescriptorData()
256
257```
258bool OH_ResourceManager_ReleaseRawFileDescriptorData(const RawFileDescriptor *descriptor)
259```
260
261**Description**
262
263Releases the file descriptor of a rawfile. To prevent file descriptor leakage, you are advised to release a rawfile descriptor immediately after use.
264
265**Since**: 12
266
267
268**Parameters**
269
270| Name| Description|
271| -- | -- |
272| [const RawFileDescriptor](capi-rawfile-rawfiledescriptor.md) *descriptor | File descriptor of the rawfile. It contains the file descriptor, start position in the HAP, and file length.|
273
274**Returns**
275
276| Type| Description|
277| -- | -- |
278| bool | Returns <b>true</b> if the file descriptor is released; returns <b>false</b> otherwise.|
279
280### OH_ResourceManager_ReadRawFile64()
281
282```
283int64_t OH_ResourceManager_ReadRawFile64(const RawFile64 *rawFile, void *buf, int64_t length)
284```
285
286**Description**
287
288Reads data of the specified length from the current position in a large rawfile.
289
290**Since**: 11
291
292
293**Parameters**
294
295| Name| Description|
296| -- | -- |
297| const [RawFile64](capi-rawfile-rawfile64.md) *rawFile | Pointer to [RawFile64](capi-rawfile-rawfile64.md).|
298| void *buf | Pointer to the buffer for receiving the read data.|
299| int64_t length | Length of the data to read.|
300
301**Returns**
302
303| Type| Description|
304| -- | -- |
305| int64_t | Number of read bytes. If the read length exceeds the length of the file end or rawfile is empty, **0** is returned.|
306
307### OH_ResourceManager_SeekRawFile64()
308
309```
310int OH_ResourceManager_SeekRawFile64(const RawFile64 *rawFile, int64_t offset, int whence)
311```
312
313**Description**
314
315Searches for the data read/write position in a large rawfile based on the specified offset.
316
317**Since**: 11
318
319
320**Parameters**
321
322| Name| Description|
323| -- | -- |
324| const [RawFile64](capi-rawfile-rawfile64.md) *rawFile | Pointer to [RawFile64](capi-rawfile-rawfile64.md).|
325| int64_t offset | Specified offset.|
326| int whence | Read/Write position. The options are as follows:<br> **0**: The read/write position is the start position of the file plus the offset.<br> **1**: The read/write position is the current position plus the offset.<br> **2**: The read/write position is the end position of the file plus the offset.|
327
328**Returns**
329
330| Type| Description|
331| -- | -- |
332| int | **0** if the search is successful; **-1** otherwise.|
333
334### OH_ResourceManager_GetRawFileSize64()
335
336```
337int64_t OH_ResourceManager_GetRawFileSize64(RawFile64 *rawFile)
338```
339
340**Description**
341
342Obtains the length of a large rawfile, in int64_t.
343
344**Since**: 11
345
346
347**Parameters**
348
349| Name| Description|
350| -- | -- |
351| [RawFile64](capi-rawfile-rawfile64.md) *rawFile | Pointer to [RawFile64](capi-rawfile-rawfile64.md).|
352
353**Returns**
354
355| Type| Description|
356| -- | -- |
357| int64_t | Overall length of the rawfile. If the rawfile is empty, **0** is returned.|
358
359### OH_ResourceManager_GetRawFileRemainingLength64()
360
361```
362int64_t OH_ResourceManager_GetRawFileRemainingLength64(const RawFile64 *rawFile)
363```
364
365**Description**
366
367Obtains the remaining length of a large rawfile, in int64_t.
368
369**Since**: 11
370
371
372**Parameters**
373
374| Name| Description|
375| -- | -- |
376| const [RawFile64](capi-rawfile-rawfile64.md) *rawFile | Pointer to [RawFile64](capi-rawfile-rawfile64.md).|
377
378**Returns**
379
380| Type| Description|
381| -- | -- |
382| int64_t | Remaining length of the rawfile. If the rawfile is empty, **0** is returned.|
383
384### OH_ResourceManager_CloseRawFile64()
385
386```
387void OH_ResourceManager_CloseRawFile64(RawFile64 *rawFile)
388```
389
390**Description**
391
392Closes an opened [RawFile64](capi-rawfile-rawfile64.md) and releases all associated resources.
393
394**Since**: 11
395
396
397**Parameters**
398
399| Name| Description|
400| -- | -- |
401| [RawFile64](capi-rawfile-rawfile64.md) *rawFile | Pointer to [RawFile64](capi-rawfile-rawfile64.md).|
402
403**Reference**
404
405[OH_ResourceManager_OpenRawFile64](capi-raw-file-manager-h.md#oh_resourcemanager_openrawfile64)
406
407### OH_ResourceManager_GetRawFileOffset64()
408
409```
410int64_t OH_ResourceManager_GetRawFileOffset64(const RawFile64 *rawFile)
411```
412
413**Description**
414
415Obtains the offset of a large rawfile, in int64_t.
416
417**Since**: 11
418
419
420**Parameters**
421
422| Name| Description|
423| -- | -- |
424| const [RawFile64](capi-rawfile-rawfile64.md) *rawFile | Pointer to [RawFile64](capi-rawfile-rawfile64.md).|
425
426**Returns**
427
428| Type| Description|
429| -- | -- |
430| int64_t | Current offset of the rawfile. If the rawfile is empty, **0** is returned.|
431
432### OH_ResourceManager_GetRawFileDescriptor64()
433
434```
435bool OH_ResourceManager_GetRawFileDescriptor64(const RawFile64 *rawFile, RawFileDescriptor64 *descriptor)
436```
437
438**Description**
439
440Opens a large rawfile based on the specified offset (in int64_t) and file length (in int64_t) and obtains the file descriptor. The file descriptor obtained can be used to read the file.
441
442**Since**: 11
443
444
445**Parameters**
446
447| Name| Description|
448| -- | -- |
449| const [RawFile64](capi-rawfile-rawfile64.md) *rawFile | Pointer to [RawFile64](capi-rawfile-rawfile64.md).|
450| [RawFileDescriptor64](capi-rawfile-rawfiledescriptor64.md) *descriptor | File descriptor of the rawfile, start position of the rawfile in the HAP, and length of the rawfile.|
451
452**Returns**
453
454| Type| Description|
455| -- | -- |
456| bool | <b>true</b> if the file is opened; returns <b>false</b> if the access to the file is rejected.|
457
458### OH_ResourceManager_ReleaseRawFileDescriptor64()
459
460```
461bool OH_ResourceManager_ReleaseRawFileDescriptor64(const RawFileDescriptor64 *descriptor)
462```
463
464**Description**
465
466Releases the file descriptor of a rawfile. To prevent file descriptor leakage, you are advised to release a rawfile descriptor immediately after use.
467
468**Since**: 11
469
470
471**Parameters**
472
473| Name| Description|
474| -- | -- |
475| [const RawFileDescriptor64](capi-rawfile-rawfiledescriptor64.md) *descriptor | File descriptor of the rawfile. It contains the file descriptor, start position in the HAP, and file length.|
476
477**Returns**
478
479| Type| Description|
480| -- | -- |
481| bool | Returns <b>true</b> if the file descriptor is released; returns <b>false</b> otherwise.|
482