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_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 |
|
|
/* 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 |
|
6359 |
UINT _fx_media_abort(FX_MEDIA *media_ptr) |
77 |
|
|
{ |
78 |
|
|
|
79 |
|
|
FX_INT_SAVE_AREA |
80 |
|
|
ULONG open_count; |
81 |
|
|
FX_FILE *file_ptr; |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
#ifndef FX_MEDIA_STATISTICS_DISABLE |
85 |
|
|
|
86 |
|
|
/* Increment the number of times this service has been called. */ |
87 |
|
6359 |
media_ptr -> fx_media_aborts++; |
88 |
|
|
#endif |
89 |
|
|
|
90 |
|
|
/* Check the media to make sure it is open. */ |
91 |
✓✓ |
6359 |
if (media_ptr -> fx_media_id != FX_MEDIA_ID) |
92 |
|
|
{ |
93 |
|
|
|
94 |
|
|
/* Return the media not opened error. */ |
95 |
|
4016 |
return(FX_MEDIA_NOT_OPEN); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
99 |
|
|
FX_TRACE_IN_LINE_INSERT(FX_TRACE_MEDIA_ABORT, media_ptr, 0, 0, 0, FX_TRACE_MEDIA_EVENTS, 0, 0) |
100 |
|
|
|
101 |
|
|
/* Protect against other threads accessing the media. */ |
102 |
|
2343 |
FX_PROTECT |
103 |
|
|
|
104 |
|
|
/* Loop through the media's open files. */ |
105 |
|
2343 |
open_count = media_ptr -> fx_media_opened_file_count; |
106 |
|
2343 |
file_ptr = media_ptr -> fx_media_opened_file_list; |
107 |
✓✓ |
6224 |
while (open_count) |
108 |
|
|
{ |
109 |
|
|
|
110 |
|
|
/* Mark the file as aborted. */ |
111 |
|
3881 |
file_ptr -> fx_file_id = FX_FILE_ABORTED_ID; |
112 |
|
|
|
113 |
|
|
/* Adjust the pointer and decrement the file opened count. */ |
114 |
|
3881 |
file_ptr = file_ptr -> fx_file_opened_next; |
115 |
|
3881 |
open_count--; |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
/* Build the "abort" I/O driver request. */ |
119 |
|
2343 |
media_ptr -> fx_media_driver_request = FX_DRIVER_ABORT; |
120 |
|
2343 |
media_ptr -> fx_media_driver_status = FX_IO_ERROR; |
121 |
|
|
|
122 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
123 |
|
|
FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_IO_DRIVER_ABORT, media_ptr, 0, 0, 0, FX_TRACE_INTERNAL_EVENTS, 0, 0) |
124 |
|
|
|
125 |
|
|
/* Call the specified I/O driver with the abort request. */ |
126 |
|
2343 |
(media_ptr -> fx_media_driver_entry) (media_ptr); |
127 |
|
|
|
128 |
|
|
/* Now remove this media from the open list. */ |
129 |
|
|
|
130 |
|
|
/* Lockout interrupts for media removal. */ |
131 |
|
2343 |
FX_DISABLE_INTS |
132 |
|
|
|
133 |
|
|
/* See if the media is the only one on the media opened list. */ |
134 |
✓✓ |
2343 |
if (_fx_system_media_opened_count == ((ULONG) 1)) |
135 |
|
|
{ |
136 |
|
|
|
137 |
|
|
/* Only opened media, just set the opened list to NULL. */ |
138 |
|
2341 |
_fx_system_media_opened_ptr = FX_NULL; |
139 |
|
|
} |
140 |
|
|
else |
141 |
|
|
{ |
142 |
|
|
|
143 |
|
|
/* Otherwise, not the only opened media, link-up the neighbors. */ |
144 |
|
2 |
(media_ptr -> fx_media_opened_next) -> fx_media_opened_previous = |
145 |
|
2 |
media_ptr -> fx_media_opened_previous; |
146 |
|
2 |
(media_ptr -> fx_media_opened_previous) -> fx_media_opened_next = |
147 |
|
2 |
media_ptr -> fx_media_opened_next; |
148 |
|
|
|
149 |
|
|
/* See if we have to update the opened list head pointer. */ |
150 |
✓✓ |
2 |
if (_fx_system_media_opened_ptr == media_ptr) |
151 |
|
|
{ |
152 |
|
|
|
153 |
|
|
/* Yes, move the head pointer to the next opened media. */ |
154 |
|
1 |
_fx_system_media_opened_ptr = media_ptr -> fx_media_opened_next; |
155 |
|
|
} |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
/* Decrement the opened media counter. */ |
159 |
|
2343 |
_fx_system_media_opened_count--; |
160 |
|
|
|
161 |
|
|
/* Finally, Indicate that this media is aborted. */ |
162 |
|
2343 |
media_ptr -> fx_media_id = FX_MEDIA_ABORTED_ID; |
163 |
|
|
|
164 |
|
|
/* Restore interrupt posture. */ |
165 |
|
2343 |
FX_RESTORE_INTS |
166 |
|
|
|
167 |
|
|
/* Delete the media protection structure if FX_SINGLE_THREAD is not |
168 |
|
|
defined. */ |
169 |
|
|
#ifndef FX_SINGLE_THREAD |
170 |
|
|
|
171 |
|
|
#ifndef FX_DONT_CREATE_MUTEX |
172 |
|
|
|
173 |
|
|
/* Note that the protection is never released. The mutex delete |
174 |
|
|
service will handle all threads waiting access to this media |
175 |
|
|
control block. */ |
176 |
|
2343 |
tx_mutex_delete(& (media_ptr -> fx_media_protect)); |
177 |
|
|
#endif |
178 |
|
|
#endif |
179 |
|
|
|
180 |
|
|
#ifdef FX_DONT_CREATE_MUTEX |
181 |
|
|
|
182 |
|
|
/* Release media protection. */ |
183 |
|
|
FX_UNPROTECT |
184 |
|
|
#endif |
185 |
|
|
|
186 |
|
|
/* Return status to the caller. */ |
187 |
|
2343 |
return(FX_SUCCESS); |
188 |
|
|
} |
189 |
|
|
|