GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_media_extended_space_available.c Lines: 10 10 100.0 %
Date: 2026-03-06 18:49:02 Branches: 2 2 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
/**   Media                                                               */
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_system.h"
30
#include "fx_media.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _fx_media_extended_space_available                  PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    William E. Lamie, Microsoft Corporation                             */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function returns the number of bytes available in the          */
46
/*    specified media.                                                    */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    media_ptr                             Media control block pointer   */
51
/*    available_bytes_ptr                   Pointer to available bytes    */
52
/*                                            destination                 */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    return status                                                       */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    None                                                                */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    Application Code                                                    */
65
/*                                                                        */
66
/**************************************************************************/
67
299
UINT  _fx_media_extended_space_available(FX_MEDIA *media_ptr, ULONG64 *available_bytes_ptr)
68
{
69
70
ULONG64 available_bytes;
71
ULONG   bytes_per_cluster;
72
ULONG   available_clusters;
73
74
75
    /* Check the media to make sure it is open.  */
76
299
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
77
    {
78
79
        /* Return the media not opened error.  */
80
273
        return(FX_MEDIA_NOT_OPEN);
81
    }
82
83
    /* If trace is enabled, insert this event into the trace buffer.  */
84
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_MEDIA_SPACE_AVAILABLE, media_ptr, available_bytes_ptr, media_ptr -> fx_media_available_clusters, 0, FX_TRACE_MEDIA_EVENTS, 0, 0)
85
86
    /* Protect against other threads accessing the media.  */
87
26
    FX_PROTECT
88
89
    /* Pickup the number of free clusters.  */
90
26
    available_clusters =  media_ptr -> fx_media_available_clusters;
91
92
    /* Derive the bytes per cluster.  */
93
26
    bytes_per_cluster =  media_ptr -> fx_media_bytes_per_sector * media_ptr -> fx_media_sectors_per_cluster;
94
95
    /* Calculate the free space.  */
96
26
    available_bytes =  ((ULONG64)available_clusters) * ((ULONG64)bytes_per_cluster);
97
98
    /* Return the value.  */
99
26
    *available_bytes_ptr =  available_bytes;
100
101
    /* Release media protection.  */
102
26
    FX_UNPROTECT
103
104
    /* Return a successful status to the caller.  */
105
26
    return(FX_SUCCESS);
106
}
107