14
14
15
15
#include <stddef.h>
16
16
17
+ #include "libos_checkpoint.h" // for include of uthash.h _and_ consistent uthash_fatal macros
17
18
#include "libos_types.h"
18
19
#include "list.h"
19
20
#include "pal.h"
@@ -34,6 +35,40 @@ struct libos_encrypted_files_key {
34
35
LIST_TYPE (libos_encrypted_files_key ) list ;
35
36
};
36
37
38
+ typedef enum {
39
+ PF_FILE_IN_USE_NEW = 0 , // file is currently in-use but did not exist at open time
40
+ PF_FILE_IN_USE_EXISTING = 1 , // file is currently in-use and existed at open time
41
+ PF_FILE_CLOSED = 2 , // file was provisously seend with known (good committed) state
42
+ PF_FILE_DELETED = 3 , // the old path of renames is also considered deleted
43
+ PF_FILE_ERROR = 4 , // file is in non-determined state due to some errors
44
+ } libos_encrypted_file_state_t ;
45
+
46
+ /*
47
+ * Map mapping file URIs to state providing information on files, in particular whether we have seen
48
+ * them before and what the last seen root-hash is. This is necessary to provide rollback
49
+ */
50
+ struct libos_encrypted_volume_state_map {
51
+ char * norm_path ; // assumptions: all paths canonicalized, symlinks are resolved & no hard links
52
+ libos_encrypted_file_state_t state ;
53
+ pf_mac_t last_seen_root_gmac ;
54
+ UT_hash_handle hh ;
55
+ };
56
+
57
+ typedef enum {
58
+ PF_ENCLAVE_LIFE_RB_PROTECTION_NONE = 0 ,
59
+ PF_ENCLAVE_LIFE_RB_PROTECTION_NON_STRICT = 1 ,
60
+ PF_ENCLAVE_LIFE_RB_PROTECTION_STRICT = 2 ,
61
+ } libos_encrypted_files_mode_t ;
62
+
63
+ struct libos_encrypted_volume {
64
+ libos_encrypted_files_mode_t protection_mode ;
65
+
66
+ struct libos_encrypted_volume_state_map * files_state_map ;
67
+ struct libos_lock files_state_map_lock ;
68
+
69
+ struct libos_encrypted_files_key * key ;
70
+ };
71
+
37
72
/*
38
73
* Represents a specific encrypted file. The file is open as long as `use_count` is greater than 0.
39
74
* Note that the file can be open and closed multiple times before it's destroyed.
@@ -44,7 +79,8 @@ struct libos_encrypted_files_key {
44
79
struct libos_encrypted_file {
45
80
size_t use_count ;
46
81
char * uri ;
47
- struct libos_encrypted_files_key * key ;
82
+ char * norm_path ; // normalized path of of uri
83
+ struct libos_encrypted_volume * volume ;
48
84
49
85
/* `pf` and `pal_handle` are non-null as long as `use_count` is greater than 0 */
50
86
pf_context_t * pf ;
@@ -110,29 +146,29 @@ void update_encrypted_files_key(struct libos_encrypted_files_key* key, const pf_
110
146
* \brief Open an existing encrypted file.
111
147
*
112
148
* \param uri PAL URI to open, has to begin with "file:".
113
- * \param key Key , has to be already set.
149
+ * \param volume Volume assocated with file , has to be already set.
114
150
* \param[out] out_enc On success, set to a newly created `libos_encrypted_file` object.
115
151
*
116
152
* `uri` has to correspond to an existing file that can be decrypted with `key`.
117
153
*
118
154
* The newly created `libos_encrypted_file` object will have `use_count` set to 1.
119
155
*/
120
- int encrypted_file_open (const char * uri , struct libos_encrypted_files_key * key ,
156
+ int encrypted_file_open (const char * uri , struct libos_encrypted_volume * volume ,
121
157
struct libos_encrypted_file * * out_enc );
122
158
123
159
/*
124
160
* \brief Create a new encrypted file.
125
161
*
126
162
* \param uri PAL URI to open, has to begin with "file:".
127
163
* \param perm Permissions for the new file.
128
- * \param key Key , has to be already set.
164
+ * \param volume Volume assocated with file , has to be already set.
129
165
* \param[out] out_enc On success, set to a newly created `libos_encrypted_file` object.
130
166
*
131
167
* `uri` must not correspond to an existing file.
132
168
*
133
169
* The newly created `libos_encrypted_file` object will have `use_count` set to 1.
134
170
*/
135
- int encrypted_file_create (const char * uri , mode_t perm , struct libos_encrypted_files_key * key ,
171
+ int encrypted_file_create (const char * uri , mode_t perm , struct libos_encrypted_volume * volume ,
136
172
struct libos_encrypted_file * * out_enc );
137
173
138
174
/*
@@ -154,7 +190,7 @@ int encrypted_file_get(struct libos_encrypted_file* enc);
154
190
*
155
191
* This decreases `use_count`, and closes the file if it reaches 0.
156
192
*/
157
- void encrypted_file_put (struct libos_encrypted_file * enc );
193
+ void encrypted_file_put (struct libos_encrypted_file * enc , bool fs_reachable );
158
194
159
195
/*
160
196
* \brief Flush pending writes to an encrypted file.
@@ -166,6 +202,7 @@ int encrypted_file_read(struct libos_encrypted_file* enc, void* buf, size_t buf_
166
202
int encrypted_file_write (struct libos_encrypted_file * enc , const void * buf , size_t buf_size ,
167
203
file_off_t offset , size_t * out_count );
168
204
int encrypted_file_rename (struct libos_encrypted_file * enc , const char * new_uri );
205
+ int encrypted_file_unlink (struct libos_encrypted_file * enc );
169
206
170
207
int encrypted_file_get_size (struct libos_encrypted_file * enc , file_off_t * out_size );
171
208
int encrypted_file_set_size (struct libos_encrypted_file * enc , file_off_t size );
0 commit comments