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 #ifdef HKS_CONFIG_FILE 22 #include HKS_CONFIG_FILE 23 #else 24 #include "hks_config.h" 25 #endif 26 27 #define HKS_MAX_FILE_NAME_LEN 512 28 29 #ifdef L2_STANDARD 30 #define HKS_KEY_STORE_PATH HKS_CONFIG_KEY_STORE_PATH "/maindata" 31 #define HKS_KEY_STORE_BAK_PATH HKS_CONFIG_KEY_STORE_PATH "/bakdata" 32 #ifdef HUKS_ENABLE_SKIP_UPGRADE_KEY_STORAGE_SECURE_LEVEL 33 #define HKS_KEY_STORE_TMP_PATH HKS_CONFIG_KEY_STORE_PATH "/tmp" 34 #endif 35 #define HKS_CE_ROOT_PATH "/data/service/el2" 36 #define HKS_ECE_ROOT_PATH "/data/service/el4" 37 #define HKS_STORE_SERVICE_PATH "huks_service/maindata" 38 #define HKS_STORE_SERVICE_BAK_PATH "huks_service/bakdata" 39 #ifdef HKS_USE_RKC_IN_STANDARD 40 #define HKS_KEY_RKC_PATH HKS_CONFIG_RKC_STORE_PATH "/maindata" 41 #endif 42 #else 43 #ifdef HKS_L1_SMALL 44 #define HKS_KEY_STORE_PATH "/storage/data/service/el1/public/huks_service/maindata" 45 #define HKS_KEY_STORE_BAK_PATH "/storage/data/service/el1/public/huks_service/bakdata" 46 #else 47 #ifdef _STORAGE_LITE_ 48 #define HKS_KEY_STORE_PATH HKS_CONFIG_KEY_STORE_PATH 49 #else 50 #ifdef HKS_ENABLE_LITE_HAP 51 #define HKS_KEY_STORE_LITE_HAP HKS_CONFIG_LITE_HAP_STORE_PATH 52 #endif 53 #ifdef HKS_CONFIG_KEY_STORE_PATH 54 #define HKS_KEY_STORE_PATH HKS_CONFIG_KEY_STORE_PATH "/maindata" 55 #define HKS_KEY_STORE_BAK_PATH HKS_CONFIG_KEY_STORE_PATH "/bakdata" 56 #else 57 #define HKS_KEY_STORE_PATH "/storage/maindata" 58 #define HKS_KEY_STORE_BAK_PATH "/storage/bakdata" 59 #endif 60 #endif 61 #endif 62 #endif 63 #define HKS_KEY_STORE_KEY_PATH "key" 64 #define HKS_KEY_STORE_ROOT_KEY_PATH "info" 65 66 #define HKS_PROCESS_INFO_LEN 128 67 #define HKS_MAX_DIRENT_FILE_LEN 128 68 struct HksFileDirentInfo { 69 char fileName[HKS_MAX_DIRENT_FILE_LEN]; /* point to dirent->d_name */ 70 }; 71 72 #ifdef __cplusplus 73 extern "C" { 74 #endif 75 76 int32_t HksFileRead(const char *path, const char *fileName, uint32_t offset, struct HksBlob *blob, uint32_t *size); 77 78 int32_t HksFileWrite(const char *path, const char *fileName, uint32_t offset, const uint8_t *buf, uint32_t len); 79 80 int32_t HksFileRemove(const char *path, const char *fileName); 81 82 uint32_t HksFileSize(const char *path, const char *fileName); 83 84 int32_t HksIsFileExist(const char *path, const char *fileName); 85 86 int32_t HksIsDirExist(const char *path); 87 88 int32_t HksMakeDir(const char *path); 89 90 void *HksOpenDir(const char *path); 91 92 int32_t HksCloseDir(void *dirp); 93 94 int32_t HksGetDirFile(void *dirp, struct HksFileDirentInfo *direntInfo); 95 96 int32_t HksRemoveDir(const char *dirPath); 97 98 int32_t HksDeleteDir(const char *path); 99 100 int32_t HksGetFileName(const char *path, const char *fileName, char *fullFileName, uint32_t fullFileNameLen); 101 102 #ifdef __cplusplus 103 } 104 #endif 105 106 #endif /* HKS_FILE_OPERATOR_H */ 107