17777dab0Sopenharmony_ci/*
27777dab0Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License.
57777dab0Sopenharmony_ci * You may obtain a copy of the License at
67777dab0Sopenharmony_ci *
77777dab0Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
87777dab0Sopenharmony_ci *
97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and
137777dab0Sopenharmony_ci * limitations under the License.
147777dab0Sopenharmony_ci */
157777dab0Sopenharmony_ci
167777dab0Sopenharmony_ci/**
177777dab0Sopenharmony_ci * @addtogroup rawfile
187777dab0Sopenharmony_ci * @{
197777dab0Sopenharmony_ci *
207777dab0Sopenharmony_ci * @brief Provides native functions for the resource manager to operate raw file directories and their raw files.
217777dab0Sopenharmony_ci *
227777dab0Sopenharmony_ci * You can use the resource manager to traverse, open, seek, read, and close raw files.
237777dab0Sopenharmony_ci *
247777dab0Sopenharmony_ci * @since 8
257777dab0Sopenharmony_ci * @version 1.0
267777dab0Sopenharmony_ci */
277777dab0Sopenharmony_ci
287777dab0Sopenharmony_ci/**
297777dab0Sopenharmony_ci * @file raw_file.h
307777dab0Sopenharmony_ci *
317777dab0Sopenharmony_ci * @brief Declares native functions related to raw file.
327777dab0Sopenharmony_ci *
337777dab0Sopenharmony_ci * For example, you can use the functions to search for, read, and close raw files.
347777dab0Sopenharmony_ci * @kit LocalizationKit
357777dab0Sopenharmony_ci * @since 8
367777dab0Sopenharmony_ci * @version 1.0
377777dab0Sopenharmony_ci */
387777dab0Sopenharmony_ci#ifndef GLOBAL_RAW_FILE_H
397777dab0Sopenharmony_ci#define GLOBAL_RAW_FILE_H
407777dab0Sopenharmony_ci
417777dab0Sopenharmony_ci#include <stddef.h>
427777dab0Sopenharmony_ci#include <stdint.h>
437777dab0Sopenharmony_ci#include <stdbool.h>
447777dab0Sopenharmony_ci
457777dab0Sopenharmony_ci#ifdef __cplusplus
467777dab0Sopenharmony_ciextern "C" {
477777dab0Sopenharmony_ci#endif
487777dab0Sopenharmony_ci
497777dab0Sopenharmony_cistruct RawFile;
507777dab0Sopenharmony_ci
517777dab0Sopenharmony_ci/**
527777dab0Sopenharmony_ci * @brief Provides access to a raw file.
537777dab0Sopenharmony_ci *
547777dab0Sopenharmony_ci * @since 11
557777dab0Sopenharmony_ci * @version 1.0
567777dab0Sopenharmony_ci */
577777dab0Sopenharmony_cistruct RawFile64;
587777dab0Sopenharmony_ci
597777dab0Sopenharmony_ci/**
607777dab0Sopenharmony_ci * @brief Provides access to a raw file.
617777dab0Sopenharmony_ci *
627777dab0Sopenharmony_ci *
637777dab0Sopenharmony_ci *
647777dab0Sopenharmony_ci * @since 8
657777dab0Sopenharmony_ci * @version 1.0
667777dab0Sopenharmony_ci */
677777dab0Sopenharmony_citypedef struct RawFile RawFile;
687777dab0Sopenharmony_ci
697777dab0Sopenharmony_ci/**
707777dab0Sopenharmony_ci * @brief Provides access to a raw file.
717777dab0Sopenharmony_ci *
727777dab0Sopenharmony_ci * @since 11
737777dab0Sopenharmony_ci * @version 1.0
747777dab0Sopenharmony_ci */
757777dab0Sopenharmony_citypedef struct RawFile64 RawFile64;
767777dab0Sopenharmony_ci
777777dab0Sopenharmony_ci/**
787777dab0Sopenharmony_ci * @brief Represent the raw file descriptor's info.
797777dab0Sopenharmony_ci *
807777dab0Sopenharmony_ci * The RawFileDescriptor is an output parameter in the {@link OH_ResourceManager_GetRawFileDescriptor},
817777dab0Sopenharmony_ci * and describes the raw file's file descriptor, start position and the length in the HAP.
827777dab0Sopenharmony_ci *
837777dab0Sopenharmony_ci * @since 8
847777dab0Sopenharmony_ci * @version 1.0
857777dab0Sopenharmony_ci */
867777dab0Sopenharmony_citypedef struct {
877777dab0Sopenharmony_ci    /** the raw file fd */
887777dab0Sopenharmony_ci    int fd;
897777dab0Sopenharmony_ci
907777dab0Sopenharmony_ci    /** the offset from where the raw file starts in the HAP */
917777dab0Sopenharmony_ci    long start;
927777dab0Sopenharmony_ci
937777dab0Sopenharmony_ci    /** the length of the raw file in the HAP. */
947777dab0Sopenharmony_ci    long length;
957777dab0Sopenharmony_ci} RawFileDescriptor;
967777dab0Sopenharmony_ci
977777dab0Sopenharmony_ci/**
987777dab0Sopenharmony_ci * @brief Represent the raw file descriptor's info.
997777dab0Sopenharmony_ci *
1007777dab0Sopenharmony_ci * The RawFileDescriptor64 is an output parameter in the {@link OH_ResourceManager_GetRawFileDescriptor64},
1017777dab0Sopenharmony_ci * and describes the raw file's file descriptor, start position and the length in the HAP.
1027777dab0Sopenharmony_ci *
1037777dab0Sopenharmony_ci * @since 11
1047777dab0Sopenharmony_ci * @version 1.0
1057777dab0Sopenharmony_ci */
1067777dab0Sopenharmony_citypedef struct {
1077777dab0Sopenharmony_ci    /** the raw file fd */
1087777dab0Sopenharmony_ci    int fd;
1097777dab0Sopenharmony_ci
1107777dab0Sopenharmony_ci    /** the offset from where the raw file starts in the HAP */
1117777dab0Sopenharmony_ci    int64_t start;
1127777dab0Sopenharmony_ci
1137777dab0Sopenharmony_ci    /** the length of the raw file in the HAP. */
1147777dab0Sopenharmony_ci    int64_t length;
1157777dab0Sopenharmony_ci} RawFileDescriptor64;
1167777dab0Sopenharmony_ci
1177777dab0Sopenharmony_ci/**
1187777dab0Sopenharmony_ci * @brief Reads a raw file.
1197777dab0Sopenharmony_ci *
1207777dab0Sopenharmony_ci * This function attempts to read data of <b>length</b> bytes from the current offset.
1217777dab0Sopenharmony_ci *
1227777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile}.
1237777dab0Sopenharmony_ci * @param buf Indicates the pointer to the buffer for receiving the data read.
1247777dab0Sopenharmony_ci * @param length Indicates the number of bytes to read.
1257777dab0Sopenharmony_ci * @return Returns the number of bytes read if any;
1267777dab0Sopenharmony_ci *         if the number reaches the end of file (EOF) or rawFile is nullptr also returns <b>0</b>
1277777dab0Sopenharmony_ci * @since 8
1287777dab0Sopenharmony_ci * @version 1.0
1297777dab0Sopenharmony_ci */
1307777dab0Sopenharmony_ciint OH_ResourceManager_ReadRawFile(const RawFile *rawFile, void *buf, size_t length);
1317777dab0Sopenharmony_ci
1327777dab0Sopenharmony_ci/**
1337777dab0Sopenharmony_ci * @brief Uses the 32-bit data type to seek a data read position based on the specified offset within a raw file.
1347777dab0Sopenharmony_ci *
1357777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile}.
1367777dab0Sopenharmony_ci * @param offset Indicates the specified offset.
1377777dab0Sopenharmony_ci * @param whence Indicates the new read position, which can be one of the following values: \n
1387777dab0Sopenharmony_ci * <b>0</b>: The new read position is set to <b>offset</b>. \n
1397777dab0Sopenharmony_ci * <b>1</b>: The read position is set to the current position plus <b>offset</b>. \n
1407777dab0Sopenharmony_ci * <b>2</b>: The read position is set to the end of file (EOF) plus <b>offset</b>.
1417777dab0Sopenharmony_ci * @return Returns <b>(int) 0</b> if the operation is successful; returns <b>(int) -1</b> if an error
1427777dab0Sopenharmony_ci * occurs.
1437777dab0Sopenharmony_ci * @since 8
1447777dab0Sopenharmony_ci * @version 1.0
1457777dab0Sopenharmony_ci */
1467777dab0Sopenharmony_ciint OH_ResourceManager_SeekRawFile(const RawFile *rawFile, long offset, int whence);
1477777dab0Sopenharmony_ci
1487777dab0Sopenharmony_ci/**
1497777dab0Sopenharmony_ci * @brief Obtains the raw file length represented by an long.
1507777dab0Sopenharmony_ci *
1517777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile}.
1527777dab0Sopenharmony_ci * @return Returns the total length of the raw file. If rawFile is nullptr also returns 0.
1537777dab0Sopenharmony_ci * @since 8
1547777dab0Sopenharmony_ci * @version 1.0
1557777dab0Sopenharmony_ci */
1567777dab0Sopenharmony_cilong OH_ResourceManager_GetRawFileSize(RawFile *rawFile);
1577777dab0Sopenharmony_ci
1587777dab0Sopenharmony_ci/**
1597777dab0Sopenharmony_ci * @brief Obtains the remaining raw file length represented by an long.
1607777dab0Sopenharmony_ci *
1617777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile}.
1627777dab0Sopenharmony_ci * @return Returns the remaining length of the raw file. If rawFile is nullptr also returns 0.
1637777dab0Sopenharmony_ci * @since 11
1647777dab0Sopenharmony_ci * @version 1.0
1657777dab0Sopenharmony_ci */
1667777dab0Sopenharmony_cilong OH_ResourceManager_GetRawFileRemainingLength(const RawFile *rawFile);
1677777dab0Sopenharmony_ci
1687777dab0Sopenharmony_ci/**
1697777dab0Sopenharmony_ci * @brief Closes an opened {@link RawFile} and releases all associated resources.
1707777dab0Sopenharmony_ci *
1717777dab0Sopenharmony_ci *
1727777dab0Sopenharmony_ci *
1737777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile}.
1747777dab0Sopenharmony_ci * @see OH_ResourceManager_OpenRawFile
1757777dab0Sopenharmony_ci * @since 8
1767777dab0Sopenharmony_ci * @version 1.0
1777777dab0Sopenharmony_ci */
1787777dab0Sopenharmony_civoid OH_ResourceManager_CloseRawFile(RawFile *rawFile);
1797777dab0Sopenharmony_ci
1807777dab0Sopenharmony_ci/**
1817777dab0Sopenharmony_ci * @brief Obtains the current offset of a raw file, represented by an long.
1827777dab0Sopenharmony_ci *
1837777dab0Sopenharmony_ci * The current offset of a raw file.
1847777dab0Sopenharmony_ci *
1857777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile}.
1867777dab0Sopenharmony_ci * @return Returns the current offset of a raw file. If rawFile is nullptr also returns 0.
1877777dab0Sopenharmony_ci * @since 8
1887777dab0Sopenharmony_ci * @version 1.0
1897777dab0Sopenharmony_ci */
1907777dab0Sopenharmony_cilong OH_ResourceManager_GetRawFileOffset(const RawFile *rawFile);
1917777dab0Sopenharmony_ci
1927777dab0Sopenharmony_ci/**
1937777dab0Sopenharmony_ci * @brief Opens the file descriptor of a raw file based on the long offset and file length.
1947777dab0Sopenharmony_ci *
1957777dab0Sopenharmony_ci * The opened raw file descriptor is used to read the raw file.
1967777dab0Sopenharmony_ci *
1977777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile}.
1987777dab0Sopenharmony_ci * @param descriptor Indicates the raw file's file descriptor, start position and the length in the HAP.
1997777dab0Sopenharmony_ci * @return Returns true: open the raw file descriptor successfully, false: the raw file is not allowed to access.
2007777dab0Sopenharmony_ci * @since 8
2017777dab0Sopenharmony_ci * @version 1.0
2027777dab0Sopenharmony_ci * @deprecated since 12
2037777dab0Sopenharmony_ci * @useinstead OH_ResourceManager_GetRawFileDescriptorData
2047777dab0Sopenharmony_ci */
2057777dab0Sopenharmony_cibool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDescriptor &descriptor);
2067777dab0Sopenharmony_ci
2077777dab0Sopenharmony_ci/**
2087777dab0Sopenharmony_ci * @brief Obtains the file descriptor of a raw file based on the long offset and file length.
2097777dab0Sopenharmony_ci *
2107777dab0Sopenharmony_ci * The obtains raw file descriptor is used to read the raw file.
2117777dab0Sopenharmony_ci *
2127777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile}.
2137777dab0Sopenharmony_ci * @param descriptor Indicates the raw file's file descriptor, start position and the length in the HAP.
2147777dab0Sopenharmony_ci * @return Returns true: obtains the raw file descriptor successfully, false: the raw file is not allowed to access.
2157777dab0Sopenharmony_ci * @since 12
2167777dab0Sopenharmony_ci * @version 1.0
2177777dab0Sopenharmony_ci */
2187777dab0Sopenharmony_cibool OH_ResourceManager_GetRawFileDescriptorData(const RawFile *rawFile, RawFileDescriptor *descriptor);
2197777dab0Sopenharmony_ci
2207777dab0Sopenharmony_ci/**
2217777dab0Sopenharmony_ci * @brief Closes the file descriptor of a raw file.
2227777dab0Sopenharmony_ci *
2237777dab0Sopenharmony_ci * The opened raw file descriptor must be released after used to avoid the file descriptor leak.
2247777dab0Sopenharmony_ci *
2257777dab0Sopenharmony_ci * @param descriptor Indicates the raw file's file descriptor, start position and the length in the HAP.
2267777dab0Sopenharmony_ci * @return Returns true: closes the raw file descriptor successfully, false: closes the raw file descriptor failed.
2277777dab0Sopenharmony_ci * @since 8
2287777dab0Sopenharmony_ci * @version 1.0
2297777dab0Sopenharmony_ci * @deprecated since 12
2307777dab0Sopenharmony_ci * @useinstead OH_ResourceManager_ReleaseRawFileDescriptorData
2317777dab0Sopenharmony_ci */
2327777dab0Sopenharmony_cibool OH_ResourceManager_ReleaseRawFileDescriptor(const RawFileDescriptor &descriptor);
2337777dab0Sopenharmony_ci
2347777dab0Sopenharmony_ci/**
2357777dab0Sopenharmony_ci * @brief Release the file descriptor of a raw file.
2367777dab0Sopenharmony_ci *
2377777dab0Sopenharmony_ci * The opened raw file descriptor must be released after used to avoid the file descriptor leak.
2387777dab0Sopenharmony_ci *
2397777dab0Sopenharmony_ci * @param descriptor Indicates the raw file's file descriptor, start position and the length in the HAP.
2407777dab0Sopenharmony_ci * @return Returns true: release the raw file descriptor successfully, false: release the raw file descriptor failed.
2417777dab0Sopenharmony_ci * @since 12
2427777dab0Sopenharmony_ci * @version 1.0
2437777dab0Sopenharmony_ci */
2447777dab0Sopenharmony_cibool OH_ResourceManager_ReleaseRawFileDescriptorData(const RawFileDescriptor *descriptor);
2457777dab0Sopenharmony_ci
2467777dab0Sopenharmony_ci/**
2477777dab0Sopenharmony_ci * @brief Reads a raw file.
2487777dab0Sopenharmony_ci *
2497777dab0Sopenharmony_ci * This function attempts to read data of <b>length</b> bytes from the current offset. using a 64-bit
2507777dab0Sopenharmony_ci *
2517777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile64}.
2527777dab0Sopenharmony_ci * @param buf Indicates the pointer to the buffer for receiving the data read.
2537777dab0Sopenharmony_ci * @param length Indicates the number of bytes to read.
2547777dab0Sopenharmony_ci * @return Returns the number of bytes read if any;
2557777dab0Sopenharmony_ci *         returns <b>0</b> if the number reaches the end of file (EOF). or rawFile is nullptr also returns 0
2567777dab0Sopenharmony_ci * @since 11
2577777dab0Sopenharmony_ci * @version 1.0
2587777dab0Sopenharmony_ci */
2597777dab0Sopenharmony_ciint64_t OH_ResourceManager_ReadRawFile64(const RawFile64 *rawFile, void *buf, int64_t length);
2607777dab0Sopenharmony_ci
2617777dab0Sopenharmony_ci/**
2627777dab0Sopenharmony_ci * @brief Uses the 64-bit data type to seek a data read position based on the specified offset within a raw file.
2637777dab0Sopenharmony_ci *
2647777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile64}.
2657777dab0Sopenharmony_ci * @param offset Indicates the specified offset.
2667777dab0Sopenharmony_ci * @param whence Indicates the new read position, which can be one of the following values: \n
2677777dab0Sopenharmony_ci * <b>0</b>: The new read position is set to <b>offset</b>. \n
2687777dab0Sopenharmony_ci * <b>1</b>: The read position is set to the current position plus <b>offset</b>. \n
2697777dab0Sopenharmony_ci * <b>2</b>: The read position is set to the end of file (EOF) plus <b>offset</b>.
2707777dab0Sopenharmony_ci * @return Returns <b>(int) 0</b> if the operation is successful; returns <b>(int) -1</b> if an error
2717777dab0Sopenharmony_ci * occurs.
2727777dab0Sopenharmony_ci * @since 11
2737777dab0Sopenharmony_ci * @version 1.0
2747777dab0Sopenharmony_ci */
2757777dab0Sopenharmony_ciint OH_ResourceManager_SeekRawFile64(const RawFile64 *rawFile, int64_t offset, int whence);
2767777dab0Sopenharmony_ci
2777777dab0Sopenharmony_ci/**
2787777dab0Sopenharmony_ci * @brief Obtains the raw file length represented by an int64_t.
2797777dab0Sopenharmony_ci *
2807777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile64}.
2817777dab0Sopenharmony_ci * @return Returns the total length of the raw file. If rawFile is nullptr also returns 0.
2827777dab0Sopenharmony_ci * @since 11
2837777dab0Sopenharmony_ci * @version 1.0
2847777dab0Sopenharmony_ci */
2857777dab0Sopenharmony_ciint64_t OH_ResourceManager_GetRawFileSize64(RawFile64 *rawFile);
2867777dab0Sopenharmony_ci
2877777dab0Sopenharmony_ci/**
2887777dab0Sopenharmony_ci * @brief Obtains the remaining raw file length represented by an int64_t.
2897777dab0Sopenharmony_ci *
2907777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile64}.
2917777dab0Sopenharmony_ci * @return Returns the remaining length of the raw file. If rawFile is nullptr also returns 0.
2927777dab0Sopenharmony_ci * @since 11
2937777dab0Sopenharmony_ci * @version 1.0
2947777dab0Sopenharmony_ci */
2957777dab0Sopenharmony_ciint64_t OH_ResourceManager_GetRawFileRemainingLength64(const RawFile64 *rawFile);
2967777dab0Sopenharmony_ci
2977777dab0Sopenharmony_ci/**
2987777dab0Sopenharmony_ci * @brief Closes an opened {@link RawFile64} and releases all associated resources.
2997777dab0Sopenharmony_ci *
3007777dab0Sopenharmony_ci *
3017777dab0Sopenharmony_ci *
3027777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile64}.
3037777dab0Sopenharmony_ci * @see OH_ResourceManager_OpenRawFile64
3047777dab0Sopenharmony_ci * @since 11
3057777dab0Sopenharmony_ci * @version 1.0
3067777dab0Sopenharmony_ci */
3077777dab0Sopenharmony_civoid OH_ResourceManager_CloseRawFile64(RawFile64 *rawFile);
3087777dab0Sopenharmony_ci
3097777dab0Sopenharmony_ci/**
3107777dab0Sopenharmony_ci * @brief Obtains the current offset of a raw file, represented by an int64_t.
3117777dab0Sopenharmony_ci *
3127777dab0Sopenharmony_ci * The current offset of a raw file.
3137777dab0Sopenharmony_ci *
3147777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile64}.
3157777dab0Sopenharmony_ci * @return Returns the current offset of a raw file. If rawFile is nullptr also returns 0.
3167777dab0Sopenharmony_ci * @since 11
3177777dab0Sopenharmony_ci * @version 1.0
3187777dab0Sopenharmony_ci */
3197777dab0Sopenharmony_ciint64_t OH_ResourceManager_GetRawFileOffset64(const RawFile64 *rawFile);
3207777dab0Sopenharmony_ci
3217777dab0Sopenharmony_ci/**
3227777dab0Sopenharmony_ci * @brief Opens the file descriptor of a raw file based on the int64_t offset and file length.
3237777dab0Sopenharmony_ci *
3247777dab0Sopenharmony_ci * The opened raw file descriptor is used to read the raw file.
3257777dab0Sopenharmony_ci *
3267777dab0Sopenharmony_ci * @param rawFile Indicates the pointer to {@link RawFile64}.
3277777dab0Sopenharmony_ci * @param descriptor Indicates the raw file's file descriptor, start position and the length in the HAP.
3287777dab0Sopenharmony_ci * @return Returns true: open the raw file descriptor successfully, false: the raw file is not allowed to access.
3297777dab0Sopenharmony_ci * @since 11
3307777dab0Sopenharmony_ci * @version 1.0
3317777dab0Sopenharmony_ci */
3327777dab0Sopenharmony_cibool OH_ResourceManager_GetRawFileDescriptor64(const RawFile64 *rawFile, RawFileDescriptor64 *descriptor);
3337777dab0Sopenharmony_ci
3347777dab0Sopenharmony_ci/**
3357777dab0Sopenharmony_ci * @brief Closes the file descriptor of a raw file.
3367777dab0Sopenharmony_ci *
3377777dab0Sopenharmony_ci * The opened raw file descriptor must be released after used to avoid the file descriptor leak.
3387777dab0Sopenharmony_ci *
3397777dab0Sopenharmony_ci * @param descriptor Indicates the raw file's file descriptor, start position and the length in the HAP.
3407777dab0Sopenharmony_ci * @return Returns true: closes the raw file descriptor successfully, false: closes the raw file descriptor failed.
3417777dab0Sopenharmony_ci * @since 11
3427777dab0Sopenharmony_ci * @version 1.0
3437777dab0Sopenharmony_ci */
3447777dab0Sopenharmony_cibool OH_ResourceManager_ReleaseRawFileDescriptor64(const RawFileDescriptor64 *descriptor);
3457777dab0Sopenharmony_ci
3467777dab0Sopenharmony_ci#ifdef __cplusplus
3477777dab0Sopenharmony_ci};
3487777dab0Sopenharmony_ci#endif
3497777dab0Sopenharmony_ci
3507777dab0Sopenharmony_ci/** @} */
3517777dab0Sopenharmony_ci#endif // GLOBAL_RAW_FILE_H
352