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 /** Media */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define FX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "fx_api.h"
28 #include "fx_system.h"
29 #include "fx_media.h"
30 #include "fx_utility.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _fx_media_read PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* William E. Lamie, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function reads the specified raw logical sector from the */
46 /* specified media. */
47 /* */
48 /* INPUT */
49 /* */
50 /* media_ptr Media control block pointer */
51 /* logical_sector Logical sector to read */
52 /* buffer_ptr Pointer to caller's buffer */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* return status */
57 /* */
58 /* CALLS */
59 /* */
60 /* _fx_utility_logical_sector_read Logical sector read utility */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* Application Code */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
71 /* 09-30-2020 William E. Lamie Modified comment(s), */
72 /* resulting in version 6.1 */
73 /* */
74 /**************************************************************************/
_fx_media_read(FX_MEDIA * media_ptr,ULONG logical_sector,VOID * buffer_ptr)75 UINT _fx_media_read(FX_MEDIA *media_ptr, ULONG logical_sector, VOID *buffer_ptr)
76 {
77
78 UINT status;
79
80 #ifdef TX_ENABLE_EVENT_TRACE
81 TX_TRACE_BUFFER_ENTRY *trace_event;
82 ULONG trace_timestamp;
83 #endif
84
85
86 #ifndef FX_MEDIA_STATISTICS_DISABLE
87
88 /* Increment the number of times this service has been called. */
89 media_ptr -> fx_media_reads++;
90 #endif
91
92 /* Check the media to make sure it is open. */
93 if (media_ptr -> fx_media_id != FX_MEDIA_ID)
94 {
95
96 /* Return the media not opened error. */
97 return(FX_MEDIA_NOT_OPEN);
98 }
99
100 /* If trace is enabled, insert this event into the trace buffer. */
101 FX_TRACE_IN_LINE_INSERT(FX_TRACE_MEDIA_READ, media_ptr, logical_sector, buffer_ptr, 0, FX_TRACE_MEDIA_EVENTS, &trace_event, &trace_timestamp)
102
103 /* Protect against other threads accessing the media. */
104 FX_PROTECT
105
106 /* Read the logical sector. */
107 status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) logical_sector, buffer_ptr, ((ULONG) 1), FX_DATA_SECTOR);
108
109 #ifdef TX_ENABLE_EVENT_TRACE
110
111 /* Check for successful status. */
112 if (status == FX_SUCCESS)
113 {
114
115 /* Update the trace event with the bytes read. */
116 FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_MEDIA_READ, 0, 0, 0, media_ptr -> fx_media_bytes_per_sector)
117 }
118 #endif
119
120 /* Release media protection. */
121 FX_UNPROTECT
122
123 /* Return status to the caller. */
124 return(status);
125 }
126
127