fx_media_abort.c
| 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 | 57207 | 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 | 57207 | media_ptr -> fx_media_aborts++; | |
| 80 | #endif | ||
| 81 | |||
| 82 | /* Check the media to make sure it is open. */ | ||
| 83 |
2/2✓ Branch 2 → 3 taken 36140 times.
✓ Branch 2 → 4 taken 21067 times.
|
57207 | if (media_ptr -> fx_media_id != FX_MEDIA_ID) |
| 84 | { | ||
| 85 | |||
| 86 | /* Return the media not opened error. */ | ||
| 87 | 36140 | 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 | 11705 | FX_PROTECT | |
| 95 | |||
| 96 | /* Loop through the media's open files. */ | ||
| 97 | 21067 | open_count = media_ptr -> fx_media_opened_file_count; | |
| 98 | 21067 | file_ptr = media_ptr -> fx_media_opened_file_list; | |
| 99 |
4/4✓ Branch 6 → 5 taken 15522 times.
✓ Branch 6 → 7 taken 9362 times.
✓ Branch 7 → 6 taken 19403 times.
✓ Branch 7 → 8 taken 11705 times.
|
55992 | while (open_count) |
| 100 | { | ||
| 101 | |||
| 102 | /* Mark the file as aborted. */ | ||
| 103 | 34925 | file_ptr -> fx_file_id = FX_FILE_ABORTED_ID; | |
| 104 | |||
| 105 | /* Adjust the pointer and decrement the file opened count. */ | ||
| 106 | 34925 | file_ptr = file_ptr -> fx_file_opened_next; | |
| 107 | 34925 | open_count--; | |
| 108 | } | ||
| 109 | |||
| 110 | /* Build the "abort" I/O driver request. */ | ||
| 111 | 21067 | media_ptr -> fx_media_driver_request = FX_DRIVER_ABORT; | |
| 112 | 21067 | 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 | 21067 | (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 | 11705 | FX_DISABLE_INTS | |
| 124 | |||
| 125 | /* See if the media is the only one on the media opened list. */ | ||
| 126 |
4/4✓ Branch 8 → 9 taken 9358 times.
✓ Branch 8 → 10 taken 4 times.
✓ Branch 10 → 11 taken 11699 times.
✓ Branch 10 → 12 taken 6 times.
|
21067 | if (_fx_system_media_opened_count == ((ULONG) 1)) |
| 127 | { | ||
| 128 | |||
| 129 | /* Only opened media, just set the opened list to NULL. */ | ||
| 130 | 21057 | _fx_system_media_opened_ptr = FX_NULL; | |
| 131 | } | ||
| 132 | else | ||
| 133 | { | ||
| 134 | |||
| 135 | /* Otherwise, not the only opened media, link-up the neighbors. */ | ||
| 136 | 10 | (media_ptr -> fx_media_opened_next) -> fx_media_opened_previous = | |
| 137 | 10 | media_ptr -> fx_media_opened_previous; | |
| 138 | 10 | (media_ptr -> fx_media_opened_previous) -> fx_media_opened_next = | |
| 139 | 10 | media_ptr -> fx_media_opened_next; | |
| 140 | |||
| 141 | /* See if we have to update the opened list head pointer. */ | ||
| 142 |
4/4✓ Branch 10 → 11 taken 2 times.
✓ Branch 10 → 12 taken 2 times.
✓ Branch 12 → 13 taken 3 times.
✓ Branch 12 → 14 taken 3 times.
|
10 | if (_fx_system_media_opened_ptr == media_ptr) |
| 143 | { | ||
| 144 | |||
| 145 | /* Yes, move the head pointer to the next opened media. */ | ||
| 146 | 5 | _fx_system_media_opened_ptr = media_ptr -> fx_media_opened_next; | |
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | /* Decrement the opened media counter. */ | ||
| 151 | 21067 | _fx_system_media_opened_count--; | |
| 152 | |||
| 153 | /* Finally, Indicate that this media is aborted. */ | ||
| 154 | 21067 | media_ptr -> fx_media_id = FX_MEDIA_ABORTED_ID; | |
| 155 | |||
| 156 | /* Restore interrupt posture. */ | ||
| 157 | 11705 | 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 | 11705 | 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 | 21067 | return(FX_SUCCESS); | |
| 180 | } | ||
| 181 | |||
| 182 |