GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_media_read.c Lines: 8 8 100.0 %
Date: 2026-03-06 18:49:02 Branches: 2 2 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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
/**************************************************************************/
68
4061
UINT  _fx_media_read(FX_MEDIA *media_ptr, ULONG logical_sector, VOID *buffer_ptr)
69
{
70
71
UINT                   status;
72
73
#ifdef TX_ENABLE_EVENT_TRACE
74
TX_TRACE_BUFFER_ENTRY *trace_event;
75
ULONG                  trace_timestamp;
76
#endif
77
78
79
#ifndef FX_MEDIA_STATISTICS_DISABLE
80
81
    /* Increment the number of times this service has been called.  */
82
4061
    media_ptr -> fx_media_reads++;
83
#endif
84
85
    /* Check the media to make sure it is open.  */
86
4061
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
87
    {
88
89
        /* Return the media not opened error.  */
90
1
        return(FX_MEDIA_NOT_OPEN);
91
    }
92
93
    /* If trace is enabled, insert this event into the trace buffer.  */
94
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_MEDIA_READ, media_ptr, logical_sector, buffer_ptr, 0, FX_TRACE_MEDIA_EVENTS, &trace_event, &trace_timestamp)
95
96
    /* Protect against other threads accessing the media.  */
97
4060
    FX_PROTECT
98
99
    /* Read the logical sector.  */
100
4060
    status =  _fx_utility_logical_sector_read(media_ptr, (ULONG64) logical_sector, buffer_ptr, ((ULONG) 1), FX_DATA_SECTOR);
101
102
#ifdef TX_ENABLE_EVENT_TRACE
103
104
    /* Check for successful status.  */
105
    if (status == FX_SUCCESS)
106
    {
107
108
        /* Update the trace event with the bytes read.  */
109
        FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_MEDIA_READ, 0, 0, 0, media_ptr -> fx_media_bytes_per_sector)
110
    }
111
#endif
112
113
    /* Release media protection.  */
114
4060
    FX_UNPROTECT
115
116
    /* Return status to the caller.  */
117
4060
    return(status);
118
}
119