1f2d4f7b0Sopenharmony_ci/*
2f2d4f7b0Sopenharmony_ci * Copyright (c) 2020-2022 Huawei Device Co., Ltd.
3f2d4f7b0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f2d4f7b0Sopenharmony_ci * you may not use this file except in compliance with the License.
5f2d4f7b0Sopenharmony_ci * You may obtain a copy of the License at
6f2d4f7b0Sopenharmony_ci *
7f2d4f7b0Sopenharmony_ci *    http://www.apache.org/licenses/LICENSE-2.0
8f2d4f7b0Sopenharmony_ci *
9f2d4f7b0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f2d4f7b0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f2d4f7b0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f2d4f7b0Sopenharmony_ci * See the License for the specific language governing permissions and
13f2d4f7b0Sopenharmony_ci * limitations under the License.
14f2d4f7b0Sopenharmony_ci */
15f2d4f7b0Sopenharmony_ci
16f2d4f7b0Sopenharmony_ci#ifndef SECURITY_APP_FILE_H
17f2d4f7b0Sopenharmony_ci#define SECURITY_APP_FILE_H
18f2d4f7b0Sopenharmony_ci
19f2d4f7b0Sopenharmony_ci#include <stdint.h>
20f2d4f7b0Sopenharmony_ci
21f2d4f7b0Sopenharmony_ci#ifdef __cplusplus
22f2d4f7b0Sopenharmony_ci#if __cplusplus
23f2d4f7b0Sopenharmony_ciextern "C" {
24f2d4f7b0Sopenharmony_ci#endif
25f2d4f7b0Sopenharmony_ci#endif
26f2d4f7b0Sopenharmony_ci
27f2d4f7b0Sopenharmony_ci#define FILE_OPEN_FAIL_ERROR_NUM (-1)
28f2d4f7b0Sopenharmony_ci
29f2d4f7b0Sopenharmony_cienum ReadFileErrorCode {
30f2d4f7b0Sopenharmony_ci    DEST_BUFFER_IS_NULL = -1,
31f2d4f7b0Sopenharmony_ci    FILE_IS_CLOSE = -2,
32f2d4f7b0Sopenharmony_ci    MMAP_COPY_FAILED = -3,
33f2d4f7b0Sopenharmony_ci    READ_OFFSET_OUT_OF_RANGE = -4,
34f2d4f7b0Sopenharmony_ci    MMAP_FAILED = -5,
35f2d4f7b0Sopenharmony_ci    MMAP_PARAM_INVALID = -6,
36f2d4f7b0Sopenharmony_ci};
37f2d4f7b0Sopenharmony_ci
38f2d4f7b0Sopenharmony_citypedef struct {
39f2d4f7b0Sopenharmony_ci    int32_t mmapPosition;
40f2d4f7b0Sopenharmony_ci    int32_t readMoreLen;
41f2d4f7b0Sopenharmony_ci    int32_t mmapSize;
42f2d4f7b0Sopenharmony_ci    char* mapAddr;
43f2d4f7b0Sopenharmony_ci} MmapInfo;
44f2d4f7b0Sopenharmony_ci
45f2d4f7b0Sopenharmony_citypedef struct {
46f2d4f7b0Sopenharmony_ci    int32_t fp;
47f2d4f7b0Sopenharmony_ci    int32_t offset;
48f2d4f7b0Sopenharmony_ci    int32_t len;
49f2d4f7b0Sopenharmony_ci} FileRead;
50f2d4f7b0Sopenharmony_ci
51f2d4f7b0Sopenharmony_ciint32_t InitVerify(FileRead *file, const char *filePath, int32_t *handle);
52f2d4f7b0Sopenharmony_ciint32_t HapMMap(int32_t bufCapacity, int32_t offset, MmapInfo *mmapInfo, const FileRead *file);
53f2d4f7b0Sopenharmony_civoid HapMUnMap(char *mapAddr, int32_t mmapSize);
54f2d4f7b0Sopenharmony_ci#ifdef __cplusplus
55f2d4f7b0Sopenharmony_ci#if __cplusplus
56f2d4f7b0Sopenharmony_ci}
57f2d4f7b0Sopenharmony_ci#endif
58f2d4f7b0Sopenharmony_ci#endif
59f2d4f7b0Sopenharmony_ci
60f2d4f7b0Sopenharmony_ci#endif
61