GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_media_abort.c Lines: 28 28 100.0 %
Date: 2026-03-06 18:49:02 Branches: 8 8 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_file.h"
32
#include "fx_utility.h"
33
34
35
/**************************************************************************/
36
/*                                                                        */
37
/*  FUNCTION                                               RELEASE        */
38
/*                                                                        */
39
/*    _fx_media_abort                                     PORTABLE C      */
40
/*                                                           6.1          */
41
/*  AUTHOR                                                                */
42
/*                                                                        */
43
/*    William E. Lamie, Microsoft Corporation                             */
44
/*                                                                        */
45
/*  DESCRIPTION                                                           */
46
/*                                                                        */
47
/*    This function marks all open files for the specified media as       */
48
/*    aborted and then removes the media control block from the open      */
49
/*    media list and marks it as aborted as well.                         */
50
/*                                                                        */
51
/*  INPUT                                                                 */
52
/*                                                                        */
53
/*    media_ptr                             Media control block pointer   */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    return status                                                       */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    tx_mutex_delete                       Delete the mutex              */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    Application Code                                                    */
66
/*                                                                        */
67
/**************************************************************************/
68
6359
UINT  _fx_media_abort(FX_MEDIA  *media_ptr)
69
{
70
71
FX_INT_SAVE_AREA
72
ULONG    open_count;
73
FX_FILE *file_ptr;
74
75
76
#ifndef FX_MEDIA_STATISTICS_DISABLE
77
78
    /* Increment the number of times this service has been called.  */
79
6359
    media_ptr -> fx_media_aborts++;
80
#endif
81
82
    /* Check the media to make sure it is open.  */
83
6359
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
84
    {
85
86
        /* Return the media not opened error.  */
87
4016
        return(FX_MEDIA_NOT_OPEN);
88
    }
89
90
    /* If trace is enabled, insert this event into the trace buffer.  */
91
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_MEDIA_ABORT, media_ptr, 0, 0, 0, FX_TRACE_MEDIA_EVENTS, 0, 0)
92
93
    /* Protect against other threads accessing the media.  */
94
2343
    FX_PROTECT
95
96
    /* Loop through the media's open files.  */
97
2343
    open_count =  media_ptr -> fx_media_opened_file_count;
98
2343
    file_ptr =    media_ptr -> fx_media_opened_file_list;
99
6224
    while (open_count)
100
    {
101
102
        /* Mark the file as aborted.  */
103
3881
        file_ptr -> fx_file_id =  FX_FILE_ABORTED_ID;
104
105
        /* Adjust the pointer and decrement the file opened count.  */
106
3881
        file_ptr =  file_ptr -> fx_file_opened_next;
107
3881
        open_count--;
108
    }
109
110
    /* Build the "abort" I/O driver request.  */
111
2343
    media_ptr -> fx_media_driver_request =      FX_DRIVER_ABORT;
112
2343
    media_ptr -> fx_media_driver_status =       FX_IO_ERROR;
113
114
    /* If trace is enabled, insert this event into the trace buffer.  */
115
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_IO_DRIVER_ABORT, media_ptr, 0, 0, 0, FX_TRACE_INTERNAL_EVENTS, 0, 0)
116
117
    /* Call the specified I/O driver with the abort request.  */
118
2343
    (media_ptr -> fx_media_driver_entry) (media_ptr);
119
120
    /* Now remove this media from the open list.  */
121
122
    /* Lockout interrupts for media removal.  */
123
2343
    FX_DISABLE_INTS
124
125
    /* See if the media is the only one on the media opened list.  */
126
2343
    if (_fx_system_media_opened_count == ((ULONG) 1))
127
    {
128
129
        /* Only opened media, just set the opened list to NULL.  */
130
2341
        _fx_system_media_opened_ptr =  FX_NULL;
131
    }
132
    else
133
    {
134
135
        /* Otherwise, not the only opened media, link-up the neighbors.  */
136
2
        (media_ptr -> fx_media_opened_next) -> fx_media_opened_previous =
137
2
            media_ptr -> fx_media_opened_previous;
138
2
        (media_ptr -> fx_media_opened_previous) -> fx_media_opened_next =
139
2
            media_ptr -> fx_media_opened_next;
140
141
        /* See if we have to update the opened list head pointer.  */
142
2
        if (_fx_system_media_opened_ptr == media_ptr)
143
        {
144
145
            /* Yes, move the head pointer to the next opened media. */
146
1
            _fx_system_media_opened_ptr =  media_ptr -> fx_media_opened_next;
147
        }
148
    }
149
150
    /* Decrement the opened media counter.  */
151
2343
    _fx_system_media_opened_count--;
152
153
    /* Finally, Indicate that this media is aborted.  */
154
2343
    media_ptr -> fx_media_id =  FX_MEDIA_ABORTED_ID;
155
156
    /* Restore interrupt posture.  */
157
2343
    FX_RESTORE_INTS
158
159
    /* Delete the media protection structure if FX_SINGLE_THREAD is not
160
       defined.  */
161
#ifndef FX_SINGLE_THREAD
162
163
#ifndef FX_DONT_CREATE_MUTEX
164
165
    /* Note that the protection is never released. The mutex delete
166
       service will handle all threads waiting access to this media
167
       control block.  */
168
2343
    tx_mutex_delete(& (media_ptr -> fx_media_protect));
169
#endif
170
#endif
171
172
#ifdef FX_DONT_CREATE_MUTEX
173
174
    /* Release media protection.  */
175
    FX_UNPROTECT
176
#endif
177
178
    /* Return status to the caller.  */
179
2343
    return(FX_SUCCESS);
180
}
181