• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HKS_FILE_OPERATOR_H
17 #define HKS_FILE_OPERATOR_H
18 
19 #include "hks_type.h"
20 
21 #define HKS_MAX_FILE_NAME_LEN 512
22 
23 #ifdef L2_STANDARD
24     #define HKS_KEY_STORE_PATH            "/data/service/el1/public/huks_service/maindata"
25     #define HKS_KEY_STORE_BAK_PATH        "/data/service/el1/public/huks_service/bakdata"
26 #else
27     #ifdef _STORAGE_LITE_
28         #define HKS_KEY_STORE_PATH                HKS_CONFIG_KEY_STORE_PATH
29     #else
30         #ifdef HKS_CONFIG_KEY_STORE_PATH
31             #define HKS_KEY_STORE_PATH            HKS_CONFIG_KEY_STORE_PATH "/maindata"
32             #define HKS_KEY_STORE_BAK_PATH        HKS_CONFIG_KEY_STORE_PATH "/bakdata"
33         #else
34             #define HKS_KEY_STORE_PATH            "/storage/maindata"
35             #define HKS_KEY_STORE_BAK_PATH        "/storage/bakdata"
36         #endif
37     #endif
38 #endif
39 #define HKS_KEY_STORE_KEY_PATH        "key"
40 #define HKS_KEY_STORE_CERTCHAIN_PATH  "certchain"
41 #define HKS_KEY_STORE_ROOT_KEY_PATH   "info"
42 
43 #define HKS_PROCESS_INFO_LEN    128
44 #define HKS_MAX_DIRENT_FILE_LEN 128
45 struct HksFileDirentInfo {
46     char fileName[HKS_MAX_DIRENT_FILE_LEN]; /* point to dirent->d_name */
47 };
48 
49 enum HksStoragePathType {
50     HKS_STORAGE_MAIN_PATH,
51     HKS_STORAGE_BACKUP_PATH,
52 };
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 uint32_t HksFileRead(const char *path, const char *fileName, uint32_t offset, uint8_t *buf, uint32_t len);
59 
60 int32_t HksFileWrite(const char *path, const char *fileName, uint32_t offset, const uint8_t *buf, uint32_t len);
61 
62 int32_t HksFileRemove(const char *path, const char *fileName);
63 
64 uint32_t HksFileSize(const char *path, const char *fileName);
65 
66 int32_t HksIsFileExist(const char *path, const char *fileName);
67 
68 int32_t HksIsDirExist(const char *path);
69 
70 int32_t HksMakeDir(const char *path);
71 
72 void *HksOpenDir(const char *path);
73 
74 int32_t HksCloseDir(void *dirp);
75 
76 int32_t HksGetDirFile(void *dirp, struct HksFileDirentInfo *direntInfo);
77 
78 int32_t HksRemoveDir(const char *dirPath);
79 
80 int32_t HksDeleteDir(const char *path);
81 
82 /* return < 0 error; > 0 realFileSize; == 0 no data */
83 int32_t HksOldVersionFileRead(const char *fileName, uint32_t offset, uint8_t *buf, uint32_t len);
84 
85 int32_t HksOldVersionFileRemove(const char *fileName);
86 
87 /* return < 0 error; >= 0 realFileSize */
88 int32_t HksOldVersionFileSize(const char *fileName);
89 
90 /* return true, exist; false not exist */
91 bool HksOldVersionIsFileExist(const char *fileName);
92 
93 int32_t HksGetStoragePath(enum HksStoragePathType pathType, char *path, uint32_t *len);
94 
95 int32_t HksGetFileName(const char *path, const char *fileName, char *fullFileName, uint32_t fullFileNameLen);
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif /* HKS_FILE_OPERATOR_H */
102