1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2014, STMicroelectronics International N.V. 4 */ 5 6 #ifndef TEE_FS_H 7 #define TEE_FS_H 8 9 #include <stddef.h> 10 #include <stdint.h> 11 #include <tee_api_defines_extensions.h> 12 #include <tee_api_types.h> 13 14 #define TEE_FS_NAME_MAX U(350) 15 16 typedef int64_t tee_fs_off_t; 17 typedef uint32_t tee_fs_mode_t; 18 19 struct tee_fs_dirent { 20 uint8_t oid[TEE_OBJECT_ID_MAX_LEN]; 21 size_t oidlen; 22 }; 23 24 struct tee_fs_dir; 25 struct tee_file_handle; 26 struct tee_pobj; 27 28 /* 29 * tee_fs implements a POSIX like secure file system with GP extension 30 */ 31 struct tee_file_operations { 32 TEE_Result (*open)(struct tee_pobj *po, size_t *size, 33 struct tee_file_handle **fh); 34 TEE_Result (*create)(struct tee_pobj *po, bool overwrite, 35 const void *head, size_t head_size, 36 const void *attr, size_t attr_size, 37 const void *data, size_t data_size, 38 struct tee_file_handle **fh); 39 void (*close)(struct tee_file_handle **fh); 40 TEE_Result (*read)(struct tee_file_handle *fh, size_t pos, 41 void *buf, size_t *len); 42 TEE_Result (*write)(struct tee_file_handle *fh, size_t pos, 43 const void *buf, size_t len); 44 TEE_Result (*rename)(struct tee_pobj *old_po, struct tee_pobj *new_po, 45 bool overwrite); 46 TEE_Result (*remove)(struct tee_pobj *po); 47 TEE_Result (*truncate)(struct tee_file_handle *fh, size_t size); 48 49 TEE_Result (*opendir)(const TEE_UUID *uuid, struct tee_fs_dir **d); 50 TEE_Result (*readdir)(struct tee_fs_dir *d, struct tee_fs_dirent **ent); 51 void (*closedir)(struct tee_fs_dir *d); 52 }; 53 54 #ifdef CFG_REE_FS 55 extern const struct tee_file_operations ree_fs_ops; 56 #endif 57 #ifdef CFG_RPMB_FS 58 extern const struct tee_file_operations rpmb_fs_ops; 59 60 TEE_Result tee_rpmb_fs_raw_open(const char *fname, bool create, 61 struct tee_file_handle **fh); 62 63 /** 64 * Weak function which can be overridden by platforms to indicate that the RPMB 65 * key is ready to be written. Defaults to true, platforms can return false to 66 * prevent a RPMB key write in the wrong state. 67 */ 68 bool plat_rpmb_key_is_ready(void); 69 #endif 70 71 /* 72 * Returns the appropriate tee_file_operations for the specified storage ID. 73 * The value TEE_STORAGE_PRIVATE will select the REE FS if available, otherwise 74 * RPMB. 75 */ 76 static inline const struct tee_file_operations * 77 tee_svc_storage_file_ops(uint32_t storage_id) 78 { 79 switch (storage_id) { 80 case TEE_STORAGE_PRIVATE: 81 #if defined(CFG_REE_FS) 82 return &ree_fs_ops; 83 #elif defined(CFG_RPMB_FS) 84 return &rpmb_fs_ops; 85 #else 86 return NULL; 87 #endif 88 #ifdef CFG_REE_FS 89 case TEE_STORAGE_PRIVATE_REE: 90 return &ree_fs_ops; 91 #endif 92 #ifdef CFG_RPMB_FS 93 case TEE_STORAGE_PRIVATE_RPMB: 94 return &rpmb_fs_ops; 95 #endif 96 default: 97 return NULL; 98 } 99 } 100 101 #endif /*TEE_FS_H*/ 102