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