xref: /optee_os/core/include/tee/fs_dirfile.h (revision ba6d8df98e3cf376aab45d0d958204c498a94123)
1 /*
2  * Copyright (c) 2017, Linaro Limited
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __TEE_FS_DIRFILE_H
29 #define __TEE_FS_DIRFILE_H
30 
31 #include <tee/tee_fs.h>
32 #include <tee/fs_htree.h>
33 
34 struct tee_fs_dirfile_dirh;
35 
36 /**
37  * struct tee_fs_dirfile_fileh - file handle
38  * @file_number:	sequence number of a file
39  * @hash:		hash of file, to be supplied to tee_fs_htree_open()
40  * @idx:		index of the file handle in the dirfile
41  */
42 struct tee_fs_dirfile_fileh {
43 	uint32_t file_number;
44 	uint8_t hash[TEE_FS_HTREE_HASH_SIZE];
45 	int idx;
46 };
47 
48 /**
49  * struct tee_fs_dirfile_operations - file interface supplied by user of this
50  * interface
51  * @open:		opens a file
52  * @close:		closes a file, changes are discarded unless
53  *			@commit_writes is called before
54  * @read:		reads from an open file
55  * @write:		writes to an open file
56  * @commit_writes:	commits changes since the file was opened
57  */
58 struct tee_fs_dirfile_operations {
59 	TEE_Result (*open)(bool create, const TEE_UUID *uuid,
60 			   struct tee_fs_dirfile_fileh *dfh,
61 			   struct tee_file_handle **fh);
62 	void (*close)(struct tee_file_handle *fh);
63 	TEE_Result (*read)(struct tee_file_handle *fh, size_t pos,
64 			   void *buf, size_t *len);
65 	TEE_Result (*write)(struct tee_file_handle *fh, size_t pos,
66 			    const void *buf, size_t len);
67 	TEE_Result (*commit_writes)(struct tee_file_handle *fh, uint8_t *hash);
68 };
69 
70 /**
71  * tee_fs_dirfile_open() - opens a dirfile handle
72  * @fops:	file interface
73  * @dirh:	returned dirfile handle
74  */
75 TEE_Result tee_fs_dirfile_open(const struct tee_fs_dirfile_operations *fops,
76 			       struct tee_fs_dirfile_dirh **dirh);
77 /**
78  * tee_fs_dirfile_close() - closes a dirfile handle
79  * @dirh:	dirfile handle
80  *
81  * All changes since last call to tee_fs_dirfile_commit_writes() are
82  * discarded.
83  */
84 void tee_fs_dirfile_close(struct tee_fs_dirfile_dirh *dirh);
85 
86 /**
87  * tee_fs_dirfile_commit_writes() - commit updates of dirfile
88  * @dirh:	dirfile handle
89  */
90 TEE_Result tee_fs_dirfile_commit_writes(struct tee_fs_dirfile_dirh *dirh);
91 
92 /**
93  * tee_fs_dirfile_get_tmp() - get a temporary file handle
94  * @dirh:	dirfile handle
95  * @dfh:	returned temporary file handle
96  *
97  * Note, nothing is queued up as changes to the dirfile with this function.
98  */
99 TEE_Result tee_fs_dirfile_get_tmp(struct tee_fs_dirfile_dirh *dirh,
100 				  struct tee_fs_dirfile_fileh *dfh);
101 
102 /**
103  * tee_fs_dirfile_find() - find a file handle
104  * @dirh:	dirfile handle
105  * @uuid:	uuid of requesting TA
106  * @oid:	object id
107  * @oidlen:	length of object id
108  * @dfh:	returned file handle
109  */
110 TEE_Result tee_fs_dirfile_find(struct tee_fs_dirfile_dirh *dirh,
111 			       const TEE_UUID *uuid, const void *oid,
112 			       size_t oidlen, struct tee_fs_dirfile_fileh *dfh);
113 
114 /**
115  * tee_fs_dirfile_fileh_to_fname() - get string representation of file handle
116  * @dfh:	file handle
117  * @fname:	buffer
118  * @fnlen:	length of buffer, updated to used length
119  */
120 TEE_Result tee_fs_dirfile_fileh_to_fname(const struct tee_fs_dirfile_fileh *dfh,
121 					 char *fname, size_t *fnlen);
122 
123 /**
124  * tee_fs_dirfile_rename() - changes/supplies file handle object id
125  * @dirh:	dirfile handle
126  * @uuid:	uuid of requesting TA
127  * @dfh:	file handle
128  * @oid:	object id
129  * @oidlen:	length of object id
130  *
131  * If the supplied object id already is used by another file is that file
132  * removed from the dirfile.
133  */
134 TEE_Result tee_fs_dirfile_rename(struct tee_fs_dirfile_dirh *dirh,
135 				 const TEE_UUID *uuid,
136 				 struct tee_fs_dirfile_fileh *dfh,
137 				 const void *oid, size_t oidlen);
138 
139 /**
140  * tee_fs_dirfile_remove() - remove file
141  * @dirh:	dirfile handle
142  * @dfh:	file handle
143  */
144 TEE_Result tee_fs_dirfile_remove(struct tee_fs_dirfile_dirh *dirh,
145 				 const struct tee_fs_dirfile_fileh *dfh);
146 
147 /**
148  * tee_fs_dirfile_update_hash() - update hash of file handle
149  * @dirh:	filefile handle
150  * @dfh:	file handle
151  */
152 TEE_Result tee_fs_dirfile_update_hash(struct tee_fs_dirfile_dirh *dirh,
153 				      const struct tee_fs_dirfile_fileh *dfh);
154 
155 /**
156  * tee_fs_dirfile_get_next() - get object id of next file
157  * @dirh:	dirfile handle
158  * @uuid:	uuid of requesting TA
159  * @idx:	pointer to index
160  * @oid:	object id
161  * @oidlen:	length of object id
162  *
163  * If @idx contains -1 the first object id is returned, *@idx is updated
164  * with the index of the file.
165  */
166 TEE_Result tee_fs_dirfile_get_next(struct tee_fs_dirfile_dirh *dirh,
167 				   const TEE_UUID *uuid, int *idx, void *oid,
168 				   size_t *oidlen);
169 
170 #endif /*__TEE_FS_DIRFILE_H*/
171