GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_utility_FAT_sector_get.c Lines: 9 9 100.0 %
Date: 2024-01-10 21:53:23 Branches: 4 4 100.0 %

Line Branch Exec Source
1
/**************************************************************************/
2
/*                                                                        */
3
/*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4
/*                                                                        */
5
/*       This software is licensed under the Microsoft Software License   */
6
/*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7
/*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8
/*       and in the root directory of this software.                      */
9
/*                                                                        */
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
/*  RELEASE HISTORY                                                       */
63
/*                                                                        */
64
/*    DATE              NAME                      DESCRIPTION             */
65
/*                                                                        */
66
/*  05-19-2020     William E. Lamie         Initial Version 6.0           */
67
/*  09-30-2020     William E. Lamie         Modified comment(s),          */
68
/*                                            resulting in version 6.1    */
69
/*                                                                        */
70
/**************************************************************************/
71
3
ULONG  _fx_utility_FAT_sector_get(FX_MEDIA *media_ptr, ULONG cluster)
72
{
73
74
ULONG  FAT_sector;
75
ULONG  byte_offset;
76
77
    /* Determine which type of FAT is present.  */
78
#ifdef FX_ENABLE_EXFAT
79
    if (media_ptr -> fx_media_FAT_type == FX_FAT12)
80
#else
81
3
    if (media_ptr -> fx_media_12_bit_FAT)
82
#endif /* FX_ENABLE_EXFAT */
83
    {
84
85
        /* 12-bit FAT is present.  */
86
87
        /* Calculate the byte offset to the cluster entry.  */
88
1
        byte_offset =  (((ULONG)cluster << 1) + cluster) >> 1;
89
90
    }
91
#ifdef FX_ENABLE_EXFAT
92
    else if (media_ptr -> fx_media_FAT_type == FX_FAT16)
93
#else
94
2
    else if (!media_ptr -> fx_media_32_bit_FAT)
95
#endif /* FX_ENABLE_EXFAT */
96
    {
97
98
        /* 16-bit FAT is present.  */
99
100
        /* Calculate the byte offset to the cluster entry.  */
101
1
        byte_offset =  (((ULONG)cluster) << 1);
102
    }
103
    else
104
    {
105
106
        /* 32-bit FAT or exFAT are present.  */
107
108
        /* Calculate the byte offset to the cluster entry.  */
109
1
        byte_offset =  (((ULONG)cluster) * 4);
110
    }
111
112
    /* Calculate the FAT sector the requested FAT entry resides in.  */
113
3
    FAT_sector =  (byte_offset / media_ptr -> fx_media_bytes_per_sector) +
114
3
        (ULONG)media_ptr -> fx_media_reserved_sectors;
115
116
    /* Return successful status.  */
117
3
    return(FAT_sector);
118
}
119