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_SOUCE_CODE
23 
24 #include "fx_api.h"
25 #include "fx_fault_tolerant.h"
26 
27 #if defined(FX_ENABLE_FAULT_TOLERANT) && defined(FX_FAULT_TOLERANT_TRANSACTION_FAIL_FUNCTION)
28 /**************************************************************************/
29 /*                                                                        */
30 /*  FUNCTION                                               RELEASE        */
31 /*                                                                        */
32 /*    _fx_fault_tolerant_transaction_fail                 PORTABLE C      */
33 /*                                                           6.1          */
34 /*  AUTHOR                                                                */
35 /*                                                                        */
36 /*    William E. Lamie, Microsoft Corporation                             */
37 /*                                                                        */
38 /*  DESCRIPTION                                                           */
39 /*                                                                        */
40 /*    This function cleans up resources created by fault tolerant when    */
41 /*    transaction fails.                                                  */
42 /*                                                                        */
43 /*  INPUT                                                                 */
44 /*                                                                        */
45 /*    media_ptr                             Media control block pointer   */
46 /*                                                                        */
47 /*  OUTPUT                                                                */
48 /*                                                                        */
49 /*    return status                                                       */
50 /*                                                                        */
51 /*  CALLS                                                                 */
52 /*                                                                        */
53 /*    None                                                                */
54 /*                                                                        */
55 /*  CALLED BY                                                             */
56 /*                                                                        */
57 /*    _fx_directory_attributes_set                                        */
58 /*    _fx_directory_create                                                */
59 /*    _fx_directory_delete                                                */
60 /*    _fx_directory_rename                                                */
61 /*    _fx_file_allocate                                                   */
62 /*    _fx_file_attributes_set                                             */
63 /*    _fx_file_best_effort_allocate                                       */
64 /*    _fx_file_create                                                     */
65 /*    _fx_file_delete                                                     */
66 /*    _fx_file_rename                                                     */
67 /*    _fx_file_truncate                                                   */
68 /*    _fx_file_truncate_release                                           */
69 /*    _fx_file_write                                                      */
70 /*    _fx_unicode_directory_create                                        */
71 /*    _fx_unicode_file_create                                             */
72 /*                                                                        */
73 /*  RELEASE HISTORY                                                       */
74 /*                                                                        */
75 /*    DATE              NAME                      DESCRIPTION             */
76 /*                                                                        */
77 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
78 /*  09-30-2020     William E. Lamie         Modified comment(s),          */
79 /*                                            resulting in version 6.1    */
80 /*                                                                        */
81 /**************************************************************************/
_fx_fault_tolerant_transaction_fail(FX_MEDIA * media_ptr)82 UINT _fx_fault_tolerant_transaction_fail(FX_MEDIA *media_ptr)
83 {
84 
85     /* Check whether fault tolerant is enabled or not. */
86     if (media_ptr -> fx_media_fault_tolerant_enabled == FX_TRUE)
87     {
88 
89         /* Yes. Decrease the counter for transaction. */
90         media_ptr -> fx_media_fault_tolerant_transaction_count--;
91 
92         /* Is this the last transaction? */
93         if (media_ptr -> fx_media_fault_tolerant_transaction_count == 0)
94         {
95 
96             /* Yes. Perform recover and reset the log file. */
97             _fx_fault_tolerant_recover(media_ptr);
98             _fx_fault_tolerant_reset_log_file(media_ptr);
99         }
100     }
101 
102     return(FX_SUCCESS);
103 }
104 #endif
105