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_utility.h"
26 #include "fx_fault_tolerant.h"
27 
28 
29 #ifdef FX_ENABLE_FAULT_TOLERANT
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _fx_fault_tolerant_read_log_file                    PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    William E. Lamie, Microsoft Corporation                             */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This function reads the entire log file from file system into the   */
43 /*    fault tolerant cache.                                               */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    media_ptr                             Media control block pointer   */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    return status                                                       */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    _fx_utility_logical_sector_read       Read a logical sector         */
56 /*                                                                        */
57 /*  CALLED BY                                                             */
58 /*                                                                        */
59 /*    _fx_fault_tolerant_enable                                           */
60 /*                                                                        */
61 /*  RELEASE HISTORY                                                       */
62 /*                                                                        */
63 /*    DATE              NAME                      DESCRIPTION             */
64 /*                                                                        */
65 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
66 /*  09-30-2020     William E. Lamie         Modified comment(s),          */
67 /*                                            resulting in version 6.1    */
68 /*                                                                        */
69 /**************************************************************************/
_fx_fault_tolerant_read_log_file(FX_MEDIA * media_ptr)70 UINT _fx_fault_tolerant_read_log_file(FX_MEDIA *media_ptr)
71 {
72 UINT  status;
73 ULONG sectors;
74 ULONG start_sector;
75 
76     /* Calculate count of sectors to read. */
77     sectors = media_ptr -> fx_media_fault_tolerant_memory_buffer_size / media_ptr -> fx_media_bytes_per_sector;
78 
79     /* Calculate the start sector of log file. */
80     start_sector = (media_ptr -> fx_media_fault_tolerant_start_cluster - FX_FAT_ENTRY_START) *
81                    media_ptr -> fx_media_sectors_per_cluster +
82                    media_ptr -> fx_media_data_sector_start;
83 
84     status =  _fx_utility_logical_sector_read(media_ptr, (ULONG64) start_sector,
85                                               media_ptr -> fx_media_fault_tolerant_memory_buffer,
86                                               sectors, FX_DATA_SECTOR);
87 
88     /* Return the status.  */
89     return(status);
90 }
91 #endif /* FX_ENABLE_FAULT_TOLERANT */
92 
93