fx_media_write.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_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 | /**************************************************************************/ | ||
| 68 | 36529 | UINT _fx_media_write(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 | 36529 | media_ptr -> fx_media_writes++; | |
| 83 | #endif | ||
| 84 | |||
| 85 | /* Check the media to make sure it is open. */ | ||
| 86 |
2/2✓ Branch 2 → 3 taken 7 times.
✓ Branch 2 → 4 taken 36522 times.
|
36529 | if (media_ptr -> fx_media_id != FX_MEDIA_ID) |
| 87 | { | ||
| 88 | |||
| 89 | /* Return the media not opened error. */ | ||
| 90 | 7 | 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_WRITE, 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 | 20290 | FX_PROTECT | |
| 98 | |||
| 99 | /* Check for write protect at the media level (set by driver). */ | ||
| 100 |
4/4✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 16229 times.
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 8 taken 20286 times.
|
36522 | if (media_ptr -> fx_media_driver_write_protect) |
| 101 | { | ||
| 102 | |||
| 103 | /* Release media protection. */ | ||
| 104 | 4 | FX_UNPROTECT | |
| 105 | |||
| 106 | /* Return write protect error. */ | ||
| 107 | 7 | return(FX_WRITE_PROTECT); | |
| 108 | } | ||
| 109 | |||
| 110 | /* Write the logical sector. */ | ||
| 111 | 36515 | status = _fx_utility_logical_sector_write(media_ptr, (ULONG64) logical_sector, buffer_ptr, ((ULONG) 1), FX_DATA_SECTOR); | |
| 112 | |||
| 113 | #ifdef TX_ENABLE_EVENT_TRACE | ||
| 114 | |||
| 115 | /* Check for successful status. */ | ||
| 116 | if (status == FX_SUCCESS) | ||
| 117 | { | ||
| 118 | |||
| 119 | /* Update the trace event with the bytes written. */ | ||
| 120 | FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_MEDIA_WRITE, 0, 0, 0, media_ptr -> fx_media_bytes_per_sector) | ||
| 121 | } | ||
| 122 | #endif | ||
| 123 | |||
| 124 | /* Release media protection. */ | ||
| 125 | 20286 | FX_UNPROTECT | |
| 126 | |||
| 127 | /* Return status to the caller. */ | ||
| 128 | 36515 | return(status); | |
| 129 | } | ||
| 130 | |||
| 131 |