1 /* 2 * Copyright (C) 2022 Huawei Technologies Co., Ltd. 3 * Licensed under the Mulan PSL v2. 4 * You can use this software according to the terms and conditions of the Mulan PSL v2. 5 * You may obtain a copy of Mulan PSL v2 at: 6 * http://license.coscl.org.cn/MulanPSL2 7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR 8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR 9 * PURPOSE. 10 * See the Mulan PSL v2 for more details. 11 */ 12 13 #ifndef LIBTEEC_FS_WORK_AGENT_H 14 #define LIBTEEC_FS_WORK_AGENT_H 15 16 #include <stdint.h> 17 #include <stdbool.h> 18 #include <stdio.h> 19 #include <unistd.h> 20 #include "fs_work_agent_define.h" 21 22 #define FILE_NAME_MAX_BUF 256 23 #define FILE_NUM_LIMIT_MAX 1024 24 #define KINDS_OF_SSA_MODE 4 25 26 #define AID_SYSTEM 1000 27 28 #ifdef CONFIG_FSWORK_THREAD_ELEVATE_PRIO 29 #define FS_AGENT_THREAD_PRIO (-20) 30 #endif 31 32 #define SFS_PARTITION_PERSISTENT "sec_storage/" 33 34 #define SFS_PARTITION_USER_SYMLINK "sec_storage_data_users/" 35 36 #define SEC_STORAGE_DATA_USERS USER_DATA_DIR"sec_storage_data_users/" 37 #define SEC_STORAGE_DATA_USER_0 USER_DATA_DIR"sec_storage_data_users/0" 38 #define SEC_STORAGE_DATA_DIR USER_DATA_DIR"sec_storage_data/" 39 40 #define TRANS_BUFF_SIZE (4 * 1024) /* agent transfer share buffer size */ 41 42 #define SEC_STORAGE_ROOT_DIR "/" SFS_PARTITION_PERSISTENT 43 44 /* 0700 only uid:tee can read and write sec_storage folder */ 45 #ifdef CONFIG_SMART_LOCK_PLATFORM 46 #define SFS_DIR_PERM (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) 47 #else 48 #define SFS_DIR_PERM (S_IRUSR | S_IWUSR | S_IXUSR) 49 #endif 50 #define SFS_FILE_PERM (S_IRUSR | S_IWUSR) 51 #define SFS_PARTITION_TRANSIENT "sec_storage_data/" 52 #define SFS_PARTITION_TRANSIENT_PRIVATE "sec_storage_data/_private" 53 #define SFS_PARTITION_TRANSIENT_PERSO "sec_storage_data/_perso" 54 55 #define FILE_NAME_INVALID_STR "../" // file name path must not contain ../ 56 57 #define SEC_STORAGE_DATA_CE "/data/service/el2/" 58 #define SEC_STORAGE_DATA_CE_SUFFIX_DIR "/tee/" SFS_PARTITION_TRANSIENT 59 #define TEE_OBJECT_STORAGE_CE 0x80000002 60 61 62 /* static func declare */ 63 enum FsCmdType { 64 SEC_OPEN, 65 SEC_CLOSE, 66 SEC_READ, 67 SEC_WRITE, 68 SEC_SEEK, 69 SEC_REMOVE, 70 SEC_TRUNCATE, 71 SEC_RENAME, 72 SEC_CREATE, 73 SEC_INFO, 74 SEC_ACCESS, 75 SEC_ACCESS2, 76 SEC_FSYNC, 77 SEC_CP, 78 SEC_DISKUSAGE, 79 SEC_DELETE_ALL, 80 SEC_MAX 81 }; 82 83 enum { 84 SEC_WRITE_SLOG, 85 SEC_WRITE_SSA, 86 }; 87 88 struct SecStorageType { 89 enum FsCmdType cmd; /* for s to n */ 90 int32_t ret; /* fxxx call's return */ 91 int32_t ret2; /* fread: end-of-file or error;fwrite:the sendor is SSA or SLOG */ 92 uint32_t userId; 93 uint32_t storageId; 94 uint32_t magic; 95 uint32_t error; 96 #ifdef CONFIG_BACKUP_PARTITION 97 bool isBackup; 98 bool isBackupExt; 99 #endif 100 union Args1 { 101 struct { 102 char mode[KINDS_OF_SSA_MODE]; 103 uint32_t nameLen; 104 uint32_t name[1]; 105 } open; 106 struct { 107 int32_t fd; 108 } close; 109 struct { 110 int32_t fd; 111 uint32_t count; 112 uint32_t buffer[1]; /* the same as name[0] --> name[1] */ 113 } read; 114 struct { 115 int32_t fd; 116 uint32_t count; 117 uint32_t buffer[1]; 118 } write; 119 struct { 120 int32_t fd; 121 int32_t offset; 122 uint32_t whence; 123 } seek; 124 struct { 125 uint32_t nameLen; 126 uint32_t name[1]; 127 } remove; 128 struct { 129 uint32_t len; 130 uint32_t nameLen; 131 uint32_t name[1]; 132 } truncate; 133 struct { 134 uint32_t oldNameLen; 135 uint32_t newNameLen; 136 uint32_t buffer[1]; /* old_name + new_name */ 137 } rename; 138 struct { 139 uint32_t fromPathLen; 140 uint32_t toPathLen; 141 uint32_t buffer[1]; /* from_path+to_path */ 142 } cp; 143 struct { 144 char mode[KINDS_OF_SSA_MODE]; 145 uint32_t nameLen; 146 uint32_t name[1]; 147 } create; 148 struct { 149 int32_t fd; 150 uint32_t curPos; 151 uint32_t fileLen; 152 } info; 153 struct { 154 int mode; 155 uint32_t nameLen; 156 uint32_t name[1]; 157 } access; 158 struct { 159 int32_t fd; 160 } fsync; 161 struct { 162 uint32_t secStorage; 163 uint32_t data; 164 } diskUsage; 165 struct { 166 uint32_t pathLen; 167 uint32_t path[1]; 168 } deleteAll; 169 } args; 170 }; 171 172 struct OpenedFile { 173 FILE *file; 174 struct OpenedFile *next; 175 struct OpenedFile *prev; 176 }; 177 178 void *FsWorkThread(void *control); 179 void SetFileNumLimit(void); 180 181 #endif 182