@@ -300,8 +300,13 @@ static void encrypted_file_internal_close(struct libos_encrypted_file* enc) {
300
300
file_state -> state = PF_FILE_ERROR ;
301
301
pf_set_corrupted (enc -> pf );
302
302
} else {
303
- memcpy (file_state -> last_seen_root_gmac , closing_root_gmac , sizeof (pf_mac_t ));
304
- file_state -> state = PF_FILE_CLOSED ;
303
+ // TODO (MST): Below also has to rule out that our file is stale, i.e., somebody has renamed
304
+ // a file to our own original file name
305
+ if (file_state -> state != PF_FILE_DELETED ) {
306
+ // TODO (MST): omit below if read-only file?
307
+ memcpy (file_state -> last_seen_root_gmac , closing_root_gmac , sizeof (pf_mac_t ));
308
+ file_state -> state = PF_FILE_CLOSED ;
309
+ }
305
310
}
306
311
unlock (& (enc -> volume -> files_state_map_lock ));
307
312
@@ -768,8 +773,8 @@ int encrypted_file_rename(struct libos_encrypted_file* enc, const char* new_uri)
768
773
HASH_ADD_KEYPTR (hh , enc -> volume -> files_state_map , new_file_state -> norm_path ,
769
774
strlen (new_file_state -> norm_path ), new_file_state );
770
775
} else {
771
- free (new_file_state -> norm_path ); // should be same but free old one to simplify below
772
- new_file_state -> norm_path = new_norm_path ;
776
+ free (new_norm_path ); // should be same as old one used during HASH_ADD
777
+ new_norm_path = new_file_state -> norm_path ;
773
778
}
774
779
new_file_state -> state = old_file_state -> state ;
775
780
memcpy (new_file_state -> last_seen_root_gmac , new_root_gmac , sizeof (pf_mac_t ));
@@ -803,6 +808,21 @@ int encrypted_file_rename(struct libos_encrypted_file* enc, const char* new_uri)
803
808
return ret ;
804
809
}
805
810
811
+ int encrypted_file_unlink (struct libos_encrypted_file * enc ) {
812
+ lock (& (enc -> volume -> files_state_map_lock ));
813
+ struct libos_encrypted_volume_state_map * file_state = NULL ;
814
+ HASH_FIND_STR (enc -> volume -> files_state_map , enc -> norm_path , file_state );
815
+ assert (file_state != NULL );
816
+ pf_mac_t root_gmac_before_unlink ;
817
+ memcpy (root_gmac_before_unlink , file_state -> last_seen_root_gmac , sizeof (pf_mac_t ));
818
+ file_state -> state = PF_FILE_DELETED ;
819
+ memset (file_state -> last_seen_root_gmac , 0 , sizeof (pf_mac_t ));
820
+ unlock (& (enc -> volume -> files_state_map_lock ));
821
+ log_debug ("file '%s' unlinked, previously with MAC=" MAC_PRINTF_PATTERN , enc -> norm_path ,
822
+ MAC_PRINTF_ARGS (root_gmac_before_unlink )); // TODO (MST): remove me eventually?
823
+ return 0 ;
824
+ }
825
+
806
826
/* Checkpoint the `g_keys` list. */
807
827
BEGIN_CP_FUNC (all_encrypted_files_keys ) {
808
828
__UNUSED (size );
0 commit comments