fx_fault_tolerant_set_FAT_chain.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_set_FAT_chain PORTABLE C */ | ||
| 36 | /* 6.1 */ | ||
| 37 | /* AUTHOR */ | ||
| 38 | /* */ | ||
| 39 | /* William E. Lamie, Microsoft Corporation */ | ||
| 40 | /* */ | ||
| 41 | /* DESCRIPTION */ | ||
| 42 | /* */ | ||
| 43 | /* This function sets data of FAT chain. */ | ||
| 44 | /* */ | ||
| 45 | /* INPUT */ | ||
| 46 | /* */ | ||
| 47 | /* media_ptr Media control block pointer */ | ||
| 48 | /* use_bitmap Whether or not the orignal */ | ||
| 49 | /* FAT chain uses bitmap */ | ||
| 50 | /* insertion_front Previous cluster of head */ | ||
| 51 | /* new_head_cluster Head cluster of new chain */ | ||
| 52 | /* origianl_head_cluster Head cluster of the original */ | ||
| 53 | /* chain */ | ||
| 54 | /* insertion_back next cluster of chain tail */ | ||
| 55 | /* */ | ||
| 56 | /* OUTPUT */ | ||
| 57 | /* */ | ||
| 58 | /* return status */ | ||
| 59 | /* */ | ||
| 60 | /* CALLS */ | ||
| 61 | /* */ | ||
| 62 | /* _fx_utility_16_unsigned_write Write a USHORT from memory */ | ||
| 63 | /* _fx_utility_32_unsigned_write Write a ULONG from memory */ | ||
| 64 | /* _fx_fault_tolerant_calculate_checksum Compute Checksum of data */ | ||
| 65 | /* _fx_fault_tolerant_write_log_file Write log file */ | ||
| 66 | /* */ | ||
| 67 | /* CALLED BY */ | ||
| 68 | /* */ | ||
| 69 | /* _fx_file_allocate */ | ||
| 70 | /* _fx_file_best_effort_allocate */ | ||
| 71 | /* _fx_file_delete */ | ||
| 72 | /* _fx_file_truncate_release */ | ||
| 73 | /* _fx_file_write */ | ||
| 74 | /* */ | ||
| 75 | /**************************************************************************/ | ||
| 76 | 8413775 | UINT _fx_fault_tolerant_set_FAT_chain(FX_MEDIA *media_ptr, UINT use_bitmap, ULONG insertion_front, | |
| 77 | ULONG new_head_cluster, ULONG original_head_cluster, | ||
| 78 | ULONG insertion_back) | ||
| 79 | { | ||
| 80 | UINT status; | ||
| 81 | USHORT checksum; | ||
| 82 | 8413775 | UCHAR flag = FX_FAULT_TOLERANT_FLAG_FAT_CHAIN_VALID; | |
| 83 | FX_FAULT_TOLERANT_FAT_CHAIN *FAT_chain; | ||
| 84 | |||
| 85 | /* Set FAT chain pointer. */ | ||
| 86 | 8413775 | FAT_chain = (FX_FAULT_TOLERANT_FAT_CHAIN *)(media_ptr -> fx_media_fault_tolerant_memory_buffer + FX_FAULT_TOLERANT_FAT_CHAIN_OFFSET); | |
| 87 | |||
| 88 | /* Parameters not used. Avoid compiler warnings. */ | ||
| 89 | FX_PARAMETER_NOT_USED(use_bitmap); | ||
| 90 | |||
| 91 | |||
| 92 | /* Reset checksum first. */ | ||
| 93 | 8413775 | _fx_utility_16_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_checksumm, 0); | |
| 94 | |||
| 95 | /* Set clusters. */ | ||
| 96 | 8413775 | _fx_utility_32_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_insertion_front, insertion_front); | |
| 97 | 8413775 | _fx_utility_32_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_head_new, new_head_cluster); | |
| 98 | 8413775 | _fx_utility_32_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_head_original, original_head_cluster); | |
| 99 | 8413775 | _fx_utility_32_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_insertion_back, insertion_back); | |
| 100 | 8413775 | _fx_utility_32_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_next_deletion, FX_FREE_CLUSTER); | |
| 101 | |||
| 102 | /* Set flag and reserved. */ | ||
| 103 | 8413775 | FAT_chain -> fx_fault_tolerant_FAT_chain_flag = flag; | |
| 104 | 8413775 | FAT_chain -> fx_fault_tolerant_FAT_chain_reserved = (UCHAR)0; | |
| 105 | |||
| 106 | /* Calculate checksum. */ | ||
| 107 | 8413775 | checksum = _fx_fault_tolerant_calculate_checksum((UCHAR *)FAT_chain, FX_FAULT_TOLERANT_FAT_CHAIN_SIZE); | |
| 108 | 8413775 | _fx_utility_16_unsigned_write((UCHAR *)&FAT_chain -> fx_fault_tolerant_FAT_chain_checksumm, checksum); | |
| 109 | |||
| 110 | /* Write the log header and FAT chain. */ | ||
| 111 | 8413775 | status = _fx_fault_tolerant_write_log_file(media_ptr, 0); | |
| 112 | |||
| 113 | /* Return the status. */ | ||
| 114 | 8413667 | return(status); | |
| 115 | } | ||
| 116 | #endif /* FX_ENABLE_FAULT_TOLERANT */ | ||
| 117 | |||
| 118 |