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 |
|
|
/** 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 |
|
|
/* RELEASE HISTORY */ |
67 |
|
|
/* */ |
68 |
|
|
/* DATE NAME DESCRIPTION */ |
69 |
|
|
/* */ |
70 |
|
|
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ |
71 |
|
|
/* 09-30-2020 William E. Lamie Modified comment(s), */ |
72 |
|
|
/* resulting in version 6.1 */ |
73 |
|
|
/* */ |
74 |
|
|
/**************************************************************************/ |
75 |
|
299 |
UINT _fx_media_extended_space_available(FX_MEDIA *media_ptr, ULONG64 *available_bytes_ptr) |
76 |
|
|
{ |
77 |
|
|
|
78 |
|
|
ULONG64 available_bytes; |
79 |
|
|
ULONG bytes_per_cluster; |
80 |
|
|
ULONG available_clusters; |
81 |
|
|
|
82 |
|
|
|
83 |
|
|
/* Check the media to make sure it is open. */ |
84 |
✓✓ |
299 |
if (media_ptr -> fx_media_id != FX_MEDIA_ID) |
85 |
|
|
{ |
86 |
|
|
|
87 |
|
|
/* Return the media not opened error. */ |
88 |
|
273 |
return(FX_MEDIA_NOT_OPEN); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
92 |
|
|
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) |
93 |
|
|
|
94 |
|
|
/* Protect against other threads accessing the media. */ |
95 |
|
26 |
FX_PROTECT |
96 |
|
|
|
97 |
|
|
/* Pickup the number of free clusters. */ |
98 |
|
26 |
available_clusters = media_ptr -> fx_media_available_clusters; |
99 |
|
|
|
100 |
|
|
/* Derive the bytes per cluster. */ |
101 |
|
26 |
bytes_per_cluster = media_ptr -> fx_media_bytes_per_sector * media_ptr -> fx_media_sectors_per_cluster; |
102 |
|
|
|
103 |
|
|
/* Calculate the free space. */ |
104 |
|
26 |
available_bytes = ((ULONG64)available_clusters) * ((ULONG64)bytes_per_cluster); |
105 |
|
|
|
106 |
|
|
/* Return the value. */ |
107 |
|
26 |
*available_bytes_ptr = available_bytes; |
108 |
|
|
|
109 |
|
|
/* Release media protection. */ |
110 |
|
26 |
FX_UNPROTECT |
111 |
|
|
|
112 |
|
|
/* Return a successful status to the caller. */ |
113 |
|
26 |
return(FX_SUCCESS); |
114 |
|
|
} |
115 |
|
|
|