1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** FileX Component */
16 /** */
17 /** Media */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define FX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "fx_api.h"
28 #include "fx_system.h"
29 #include "fx_media.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _fx_media_extended_space_available PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* William E. Lamie, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function returns the number of bytes available in the */
45 /* specified media. */
46 /* */
47 /* INPUT */
48 /* */
49 /* media_ptr Media control block pointer */
50 /* available_bytes_ptr Pointer to available bytes */
51 /* destination */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* return status */
56 /* */
57 /* CALLS */
58 /* */
59 /* None */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* Application Code */
64 /* */
65 /* RELEASE HISTORY */
66 /* */
67 /* DATE NAME DESCRIPTION */
68 /* */
69 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
70 /* 09-30-2020 William E. Lamie Modified comment(s), */
71 /* resulting in version 6.1 */
72 /* */
73 /**************************************************************************/
_fx_media_extended_space_available(FX_MEDIA * media_ptr,ULONG64 * available_bytes_ptr)74 UINT _fx_media_extended_space_available(FX_MEDIA *media_ptr, ULONG64 *available_bytes_ptr)
75 {
76
77 ULONG64 available_bytes;
78 ULONG bytes_per_cluster;
79 ULONG available_clusters;
80
81
82 /* Check the media to make sure it is open. */
83 if (media_ptr -> fx_media_id != FX_MEDIA_ID)
84 {
85
86 /* Return the media not opened error. */
87 return(FX_MEDIA_NOT_OPEN);
88 }
89
90 /* If trace is enabled, insert this event into the trace buffer. */
91 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)
92
93 /* Protect against other threads accessing the media. */
94 FX_PROTECT
95
96 /* Pickup the number of free clusters. */
97 available_clusters = media_ptr -> fx_media_available_clusters;
98
99 /* Derive the bytes per cluster. */
100 bytes_per_cluster = media_ptr -> fx_media_bytes_per_sector * media_ptr -> fx_media_sectors_per_cluster;
101
102 /* Calculate the free space. */
103 available_bytes = ((ULONG64)available_clusters) * ((ULONG64)bytes_per_cluster);
104
105 /* Return the value. */
106 *available_bytes_ptr = available_bytes;
107
108 /* Release media protection. */
109 FX_UNPROTECT
110
111 /* Return a successful status to the caller. */
112 return(FX_SUCCESS);
113 }
114
115