1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** FileX Component */ 16 /** */ 17 /** Fault Tolerant */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 #define FX_SOURCE_CODE 23 24 #include "fx_api.h" 25 #include "fx_fault_tolerant.h" 26 27 28 #ifdef FX_ENABLE_FAULT_TOLERANT 29 /**************************************************************************/ 30 /* */ 31 /* FUNCTION RELEASE */ 32 /* */ 33 /* _fx_fault_tolerant_transaction_start PORTABLE C */ 34 /* 6.1 */ 35 /* AUTHOR */ 36 /* */ 37 /* William E. Lamie, Microsoft Corporation */ 38 /* */ 39 /* DESCRIPTION */ 40 /* */ 41 /* This function is called at the beginning of an update to FileX */ 42 /* file, directory entry, or FAT table. It resets fault tolerant */ 43 /* internal state information. */ 44 /* */ 45 /* INPUT */ 46 /* */ 47 /* media_ptr Media control block pointer */ 48 /* */ 49 /* OUTPUT */ 50 /* */ 51 /* return status */ 52 /* */ 53 /* CALLS */ 54 /* */ 55 /* None */ 56 /* */ 57 /* CALLED BY */ 58 /* */ 59 /* _fx_directory_attributes_set */ 60 /* _fx_directory_create */ 61 /* _fx_directory_delete */ 62 /* _fx_directory_rename */ 63 /* _fx_file_allocate */ 64 /* _fx_file_attributes_set */ 65 /* _fx_file_best_effort_allocate */ 66 /* _fx_file_create */ 67 /* _fx_file_delete */ 68 /* _fx_file_rename */ 69 /* _fx_file_truncate */ 70 /* _fx_file_truncate_release */ 71 /* _fx_file_write */ 72 /* _fx_unicode_directory_create */ 73 /* _fx_unicode_file_create */ 74 /* */ 75 /* RELEASE HISTORY */ 76 /* */ 77 /* DATE NAME DESCRIPTION */ 78 /* */ 79 /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 80 /* 09-30-2020 William E. Lamie Modified comment(s), */ 81 /* resulting in version 6.1 */ 82 /* */ 83 /**************************************************************************/ _fx_fault_tolerant_transaction_start(FX_MEDIA * media_ptr)84UINT _fx_fault_tolerant_transaction_start(FX_MEDIA *media_ptr) 85 { 86 87 /* Is fault tolerant enabled? */ 88 if (media_ptr -> fx_media_fault_tolerant_enabled == FX_TRUE) 89 { 90 91 /* Is this a new transaction? */ 92 if (media_ptr -> fx_media_fault_tolerant_transaction_count == 0) 93 { 94 95 /* Yes. Initialize data. */ 96 media_ptr -> fx_media_fault_tolerant_file_size = FX_FAULT_TOLERANT_LOG_HEADER_SIZE + 97 FX_FAULT_TOLERANT_FAT_CHAIN_SIZE + 98 FX_FAULT_TOLERANT_LOG_CONTENT_HEADER_SIZE; 99 100 /* Reset total logs. */ 101 media_ptr -> fx_media_fault_tolerant_total_logs = 0; 102 103 /* Set state of fault tolerant. */ 104 media_ptr -> fx_media_fault_tolerant_state = FX_FAULT_TOLERANT_STATE_STARTED; 105 } 106 107 /* Increase the transaction. */ 108 media_ptr -> fx_media_fault_tolerant_transaction_count++; 109 } 110 111 return(FX_SUCCESS); 112 } 113 #endif /* FX_ENABLE_FAULT_TOLERANT */ 114 115