fx_utility_FAT_sector_get.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 | /** Utility */ | ||
| 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_utility.h" | ||
| 30 | |||
| 31 | |||
| 32 | /**************************************************************************/ | ||
| 33 | /* */ | ||
| 34 | /* FUNCTION RELEASE */ | ||
| 35 | /* */ | ||
| 36 | /* _fx_utility_FAT_sector_get PORTABLE C */ | ||
| 37 | /* 6.1 */ | ||
| 38 | /* AUTHOR */ | ||
| 39 | /* */ | ||
| 40 | /* William E. Lamie, Microsoft Corporation */ | ||
| 41 | /* */ | ||
| 42 | /* DESCRIPTION */ | ||
| 43 | /* */ | ||
| 44 | /* This function gets the sector of supplied FAT entry. */ | ||
| 45 | /* */ | ||
| 46 | /* INPUT */ | ||
| 47 | /* */ | ||
| 48 | /* media_ptr Media control block pointer */ | ||
| 49 | /* cluster Cluster entry number */ | ||
| 50 | /* */ | ||
| 51 | /* OUTPUT */ | ||
| 52 | /* */ | ||
| 53 | /* return sector of FAT entry */ | ||
| 54 | /* */ | ||
| 55 | /* CALLS */ | ||
| 56 | /* */ | ||
| 57 | /* */ | ||
| 58 | /* CALLED BY */ | ||
| 59 | /* */ | ||
| 60 | /* FileX System Functions */ | ||
| 61 | /* */ | ||
| 62 | /**************************************************************************/ | ||
| 63 | 87889091 | ULONG _fx_utility_FAT_sector_get(FX_MEDIA *media_ptr, ULONG cluster) | |
| 64 | { | ||
| 65 | |||
| 66 | ULONG FAT_sector; | ||
| 67 | ULONG byte_offset; | ||
| 68 | |||
| 69 | /* Determine which type of FAT is present. */ | ||
| 70 |
2/2✓ Branch 2 → 3 taken 2192747 times.
✓ Branch 2 → 4 taken 85696344 times.
|
87889091 | if (media_ptr -> fx_media_12_bit_FAT) |
| 71 | { | ||
| 72 | |||
| 73 | /* 12-bit FAT is present. */ | ||
| 74 | |||
| 75 | /* Calculate the byte offset to the cluster entry. */ | ||
| 76 | 2192747 | byte_offset = (((ULONG)cluster << 1) + cluster) >> 1; | |
| 77 | |||
| 78 | } | ||
| 79 |
2/2✓ Branch 4 → 5 taken 6491685 times.
✓ Branch 4 → 6 taken 79204659 times.
|
85696344 | else if (!media_ptr -> fx_media_32_bit_FAT) |
| 80 | { | ||
| 81 | |||
| 82 | /* 16-bit FAT is present. */ | ||
| 83 | |||
| 84 | /* Calculate the byte offset to the cluster entry. */ | ||
| 85 | 6491685 | byte_offset = (((ULONG)cluster) << 1); | |
| 86 | } | ||
| 87 | else | ||
| 88 | { | ||
| 89 | |||
| 90 | /* 32-bit FAT is present. */ | ||
| 91 | |||
| 92 | /* Calculate the byte offset to the cluster entry. */ | ||
| 93 | 79204659 | byte_offset = (((ULONG)cluster) * 4); | |
| 94 | } | ||
| 95 | |||
| 96 | /* Calculate the FAT sector the requested FAT entry resides in. */ | ||
| 97 | 87889091 | FAT_sector = (byte_offset / media_ptr -> fx_media_bytes_per_sector) + | |
| 98 | 87889091 | (ULONG)media_ptr -> fx_media_reserved_sectors; | |
| 99 | |||
| 100 | /* Return successful status. */ | ||
| 101 | 87889091 | return(FAT_sector); | |
| 102 | } | ||
| 103 | |||
| 104 |