GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_media_write.c Lines: 11 11 100.0 %
Date: 2024-01-10 21:53:23 Branches: 4 4 100.0 %

Line Branch Exec Source
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_write                                     PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    William E. Lamie, Microsoft Corporation                             */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function writes the specified raw logical sector to 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_write      Write logical sector 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
4059
UINT  _fx_media_write(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
4059
    media_ptr -> fx_media_writes++;
91
#endif
92
93
    /* Check the media to make sure it is open.  */
94
4059
    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_WRITE, 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
4058
    FX_PROTECT
106
107
    /* Check for write protect at the media level (set by driver).  */
108
4058
    if (media_ptr -> fx_media_driver_write_protect)
109
    {
110
111
        /* Release media protection.  */
112
1
        FX_UNPROTECT
113
114
        /* Return write protect error.  */
115
1
        return(FX_WRITE_PROTECT);
116
    }
117
118
    /* Write the logical sector.  */
119
4057
    status =  _fx_utility_logical_sector_write(media_ptr, (ULONG64) logical_sector, buffer_ptr, ((ULONG) 1), FX_DATA_SECTOR);
120
121
#ifdef TX_ENABLE_EVENT_TRACE
122
123
    /* Check for successful status.  */
124
    if (status == FX_SUCCESS)
125
    {
126
127
        /* Update the trace event with the bytes written.  */
128
        FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_MEDIA_WRITE, 0, 0, 0, media_ptr -> fx_media_bytes_per_sector)
129
    }
130
#endif
131
132
    /* Release media protection.  */
133
4057
    FX_UNPROTECT
134
135
    /* Return status to the caller.  */
136
4057
    return(status);
137
}
138