1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2017, Linaro Limited 4 * All rights reserved. 5 */ 6 7 #ifndef __TEE_FS_DIRFILE_H 8 #define __TEE_FS_DIRFILE_H 9 10 #include <tee/tee_fs.h> 11 #include <tee/fs_htree.h> 12 13 struct tee_fs_dirfile_dirh; 14 15 /** 16 * struct tee_fs_dirfile_fileh - file handle 17 * @file_number: sequence number of a file 18 * @hash: hash of file, to be supplied to tee_fs_htree_open() 19 * @idx: index of the file handle in the dirfile 20 */ 21 struct tee_fs_dirfile_fileh { 22 uint32_t file_number; 23 uint8_t hash[TEE_FS_HTREE_HASH_SIZE]; 24 int idx; 25 }; 26 27 /** 28 * struct tee_fs_dirfile_operations - file interface supplied by user of this 29 * interface 30 * @open: opens a file 31 * @close: closes a file, changes are discarded unless 32 * @commit_writes is called before 33 * @read: reads from an open file 34 * @write: writes to an open file 35 * @commit_writes: commits changes since the file was opened 36 */ 37 struct tee_fs_dirfile_operations { 38 TEE_Result (*open)(bool create, uint8_t *hash, const TEE_UUID *uuid, 39 struct tee_fs_dirfile_fileh *dfh, 40 struct tee_file_handle **fh); 41 void (*close)(struct tee_file_handle *fh); 42 TEE_Result (*read)(struct tee_file_handle *fh, size_t pos, 43 void *buf, size_t *len); 44 TEE_Result (*write)(struct tee_file_handle *fh, size_t pos, 45 const void *buf, size_t len); 46 TEE_Result (*commit_writes)(struct tee_file_handle *fh, uint8_t *hash); 47 }; 48 49 /** 50 * tee_fs_dirfile_open() - opens a dirfile handle 51 * @create: true if a new dirfile is to be created, else the dirfile 52 * is read opened and verified 53 * @hash: hash of underlying file 54 * @fops: file interface 55 * @dirh: returned dirfile handle 56 */ 57 TEE_Result tee_fs_dirfile_open(bool create, uint8_t *hash, 58 const struct tee_fs_dirfile_operations *fops, 59 struct tee_fs_dirfile_dirh **dirh); 60 /** 61 * tee_fs_dirfile_close() - closes a dirfile handle 62 * @dirh: dirfile handle 63 * 64 * All changes since last call to tee_fs_dirfile_commit_writes() are 65 * discarded. 66 */ 67 void tee_fs_dirfile_close(struct tee_fs_dirfile_dirh *dirh); 68 69 /** 70 * tee_fs_dirfile_commit_writes() - commit updates of dirfile 71 * @dirh: dirfile handle 72 * @hash: hash of underlying file is copied here if not NULL 73 */ 74 TEE_Result tee_fs_dirfile_commit_writes(struct tee_fs_dirfile_dirh *dirh, 75 uint8_t *hash); 76 77 /** 78 * tee_fs_dirfile_get_tmp() - get a temporary file handle 79 * @dirh: dirfile handle 80 * @dfh: returned temporary file handle 81 * 82 * Note, nothing is queued up as changes to the dirfile with this function. 83 */ 84 TEE_Result tee_fs_dirfile_get_tmp(struct tee_fs_dirfile_dirh *dirh, 85 struct tee_fs_dirfile_fileh *dfh); 86 87 /** 88 * tee_fs_dirfile_find() - find a file handle 89 * @dirh: dirfile handle 90 * @uuid: uuid of requesting TA 91 * @oid: object id 92 * @oidlen: length of object id 93 * @dfh: returned file handle 94 */ 95 TEE_Result tee_fs_dirfile_find(struct tee_fs_dirfile_dirh *dirh, 96 const TEE_UUID *uuid, const void *oid, 97 size_t oidlen, struct tee_fs_dirfile_fileh *dfh); 98 99 /** 100 * tee_fs_dirfile_fileh_to_fname() - get string representation of file handle 101 * @dfh: file handle 102 * @fname: buffer 103 * @fnlen: length of buffer, updated to used length 104 */ 105 TEE_Result tee_fs_dirfile_fileh_to_fname(const struct tee_fs_dirfile_fileh *dfh, 106 char *fname, size_t *fnlen); 107 108 /** 109 * tee_fs_dirfile_rename() - changes/supplies file handle object id 110 * @dirh: dirfile handle 111 * @uuid: uuid of requesting TA 112 * @dfh: file handle 113 * @oid: object id 114 * @oidlen: length of object id 115 * 116 * If the supplied object id already is used by another file is that file 117 * removed from the dirfile. 118 */ 119 TEE_Result tee_fs_dirfile_rename(struct tee_fs_dirfile_dirh *dirh, 120 const TEE_UUID *uuid, 121 struct tee_fs_dirfile_fileh *dfh, 122 const void *oid, size_t oidlen); 123 124 /** 125 * tee_fs_dirfile_remove() - remove file 126 * @dirh: dirfile handle 127 * @dfh: file handle 128 */ 129 TEE_Result tee_fs_dirfile_remove(struct tee_fs_dirfile_dirh *dirh, 130 const struct tee_fs_dirfile_fileh *dfh); 131 132 /** 133 * tee_fs_dirfile_update_hash() - update hash of file handle 134 * @dirh: filefile handle 135 * @dfh: file handle 136 */ 137 TEE_Result tee_fs_dirfile_update_hash(struct tee_fs_dirfile_dirh *dirh, 138 const struct tee_fs_dirfile_fileh *dfh); 139 140 /** 141 * tee_fs_dirfile_get_next() - get object id of next file 142 * @dirh: dirfile handle 143 * @uuid: uuid of requesting TA 144 * @idx: pointer to index 145 * @oid: object id 146 * @oidlen: length of object id 147 * 148 * If @idx contains -1 the first object id is returned, *@idx is updated 149 * with the index of the file. 150 */ 151 TEE_Result tee_fs_dirfile_get_next(struct tee_fs_dirfile_dirh *dirh, 152 const TEE_UUID *uuid, int *idx, void *oid, 153 size_t *oidlen); 154 155 #endif /*__TEE_FS_DIRFILE_H*/ 156