fx_fault_tolerant_add_FAT_log.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 | /** Fault Tolerant */ | ||
| 19 | /** */ | ||
| 20 | /**************************************************************************/ | ||
| 21 | /**************************************************************************/ | ||
| 22 | |||
| 23 | #define FX_SOURCE_CODE | ||
| 24 | |||
| 25 | #include "fx_api.h" | ||
| 26 | #include "fx_utility.h" | ||
| 27 | #include "fx_fault_tolerant.h" | ||
| 28 | |||
| 29 | |||
| 30 | #ifdef FX_ENABLE_FAULT_TOLERANT | ||
| 31 | /**************************************************************************/ | ||
| 32 | /* */ | ||
| 33 | /* FUNCTION RELEASE */ | ||
| 34 | /* */ | ||
| 35 | /* _fx_fault_tolerant_add_FAT_log PORTABLE C */ | ||
| 36 | /* 6.1 */ | ||
| 37 | /* AUTHOR */ | ||
| 38 | /* */ | ||
| 39 | /* William E. Lamie, Microsoft Corporation */ | ||
| 40 | /* */ | ||
| 41 | /* DESCRIPTION */ | ||
| 42 | /* */ | ||
| 43 | /* This function converts FAT write into log entry and add it into */ | ||
| 44 | /* log file. */ | ||
| 45 | /* */ | ||
| 46 | /* INPUT */ | ||
| 47 | /* */ | ||
| 48 | /* media_ptr Media control block pointer */ | ||
| 49 | /* cluster Cluster entry number */ | ||
| 50 | /* value Next cluster value */ | ||
| 51 | /* */ | ||
| 52 | /* OUTPUT */ | ||
| 53 | /* */ | ||
| 54 | /* return status */ | ||
| 55 | /* */ | ||
| 56 | /* CALLS */ | ||
| 57 | /* */ | ||
| 58 | /* _fx_utility_16_unsigned_write Write a USHORT from memory */ | ||
| 59 | /* _fx_utility_32_unsigned_write Write a UINT from memory */ | ||
| 60 | /* */ | ||
| 61 | /* CALLED BY */ | ||
| 62 | /* */ | ||
| 63 | /* _fx_utility_FAT_entry_write */ | ||
| 64 | /* */ | ||
| 65 | /**************************************************************************/ | ||
| 66 | 4190 | UINT _fx_fault_tolerant_add_FAT_log(FX_MEDIA *media_ptr, ULONG cluster, ULONG value) | |
| 67 | { | ||
| 68 | ULONG file_size; | ||
| 69 | FX_FAULT_TOLERANT_FAT_LOG *fat_log; | ||
| 70 | |||
| 71 | /* Increment the size of the log file. */ | ||
| 72 | 4190 | file_size = media_ptr -> fx_media_fault_tolerant_file_size + FX_FAULT_TOLERANT_FAT_LOG_ENTRY_SIZE; | |
| 73 | |||
| 74 | /* Check whether log file exceeds the buffer. */ | ||
| 75 |
2/2✓ Branch 2 → 3 taken 12 times.
✓ Branch 2 → 4 taken 4178 times.
|
4190 | if (file_size > media_ptr -> fx_media_fault_tolerant_memory_buffer_size) |
| 76 | { | ||
| 77 | |||
| 78 | /* Log file exceeds the size of the log buffer. This is a failure. */ | ||
| 79 | 12 | return(FX_NO_MORE_SPACE); | |
| 80 | } | ||
| 81 | |||
| 82 | /* Set log pointer. */ | ||
| 83 | 4178 | fat_log = (FX_FAULT_TOLERANT_FAT_LOG *)(media_ptr -> fx_media_fault_tolerant_memory_buffer + | |
| 84 | 4178 | media_ptr -> fx_media_fault_tolerant_file_size); | |
| 85 | |||
| 86 | /* Set log type. */ | ||
| 87 | 4178 | _fx_utility_16_unsigned_write((UCHAR *)&fat_log -> fx_fault_tolerant_FAT_log_type, | |
| 88 | FX_FAULT_TOLERANT_FAT_LOG_TYPE); | ||
| 89 | |||
| 90 | /* Size of log. */ | ||
| 91 | 4178 | _fx_utility_16_unsigned_write((UCHAR *)&fat_log -> fx_fault_tolerant_FAT_log_size, | |
| 92 | FX_FAULT_TOLERANT_FAT_LOG_ENTRY_SIZE); | ||
| 93 | |||
| 94 | /* Set cluster and value. */ | ||
| 95 | 4178 | _fx_utility_32_unsigned_write((UCHAR *)&fat_log -> fx_fault_tolerant_FAT_log_cluster, cluster); | |
| 96 | 4178 | _fx_utility_32_unsigned_write((UCHAR *)&fat_log -> fx_fault_tolerant_FAT_log_value, value); | |
| 97 | |||
| 98 | /* Update log information. */ | ||
| 99 | 4178 | media_ptr -> fx_media_fault_tolerant_file_size = (USHORT)file_size; | |
| 100 | 4178 | media_ptr -> fx_media_fault_tolerant_total_logs += 1; | |
| 101 | |||
| 102 | 4178 | return(FX_SUCCESS); | |
| 103 | } | ||
| 104 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 105 | |||
| 106 |