GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_utility_FAT_sector_get.c Lines: 9 9 100.0 %
Date: 2026-03-06 18:49:02 Branches: 4 4 100.0 %

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
3
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
3
    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
1
        byte_offset =  (((ULONG)cluster << 1) + cluster) >> 1;
77
78
    }
79
2
    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
1
        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
1
        byte_offset =  (((ULONG)cluster) * 4);
94
    }
95
96
    /* Calculate the FAT sector the requested FAT entry resides in.  */
97
3
    FAT_sector =  (byte_offset / media_ptr -> fx_media_bytes_per_sector) +
98
3
        (ULONG)media_ptr -> fx_media_reserved_sectors;
99
100
    /* Return successful status.  */
101
3
    return(FAT_sector);
102
}
103