Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#include "fx_directory_exFAT.h"
#include "fx_utility.h"
...
Files
loading...
SourceVuSTM32 Libraries and Samplesfilexcommon/src/fx_utility_exFAT_cluster_free.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** FileX Component */ /** */ /** Utility */ /** */... /**************************************************************************/ /**************************************************************************/ #define FX_SOURCE_CODE /* Include necessary system files. */ #include "fx_api.h" #ifdef FX_ENABLE_EXFAT #include "fx_directory_exFAT.h" #include "fx_utility.h" /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _fx_utility_exFAT_cluster_free PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function deallocates clusters deleted unknown type */ /* directory entry. */ /* */ /* INPUT */ /* */ /* media_ptr Media control block pointer */ /* work_ptr Pointer to directory to */ /* unknown directory entry */ /* */ /* OUTPUT */ /* */ /* return status */ /* */ /* CALLS */ /* */ /* _fx_utility_32_unsigned_read Read 32-bit value */ /* _fx_utility_64_unsigned_read Read 64-bit value */ /* _fx_utility_FAT_entry_read Read FAT entry */ /* _fx_utility_FAT_entry_write Write FAT entry */ /* _fx_utility_exFAT_cluster_state_set Set cluster state */ /* */ /* CALLED BY */ /* */ /* _fx_directory_exFAT_unicode_entry_write */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* 09-30-2020 William E. Lamie Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ UINT _fx_utility_exFAT_cluster_free(FX_MEDIA *media_ptr, UCHAR *work_ptr) { ULONG cluster; ULONG64 data_length; ULONG clusters_released; ULONG clusters_count; ULONG bytes_per_cluster; ULONG contents = 0; UCHAR dont_use_fat; UINT status; /* Pickup the cluster to release. */ cluster = _fx_utility_32_unsigned_read(&(work_ptr[FX_EXFAT_FIRST_CLUSTER])); /* Pickup the data length. */ data_length = _fx_utility_64_unsigned_read(&(work_ptr[FX_EXFAT_DATA_LENGTH])); /* Pickup the flag that determines if the FAT should be used. */ dont_use_fat = (work_ptr[FX_EXFAT_SECOND_FLAG] >> 1) & 1; /* Default status to success. */ status = FX_SUCCESS; /* Is the allocation possible flag cleared? Is there any allocated cluster for this entry? */ if (((work_ptr[FX_EXFAT_SECOND_FLAG] & FX_EXFAT_SECOND_FLAG_ALLOCATION_POSSIBLE_MASK) == 0) || (cluster == 0) || (data_length == 0)) { /* No cluster allocated to this entry, nothing to deallocate. */ return(FX_SUCCESS); }if (((work_ptr[FX_EXFAT_SECOND_FLAG] & FX_EXFAT_SECOND_FLAG_ALLOCATION_POSSIBLE_MASK) == 0) || (cluster == 0) || (data_length == 0)) { ... } /* Calculate the number of bytes per cluster. */ bytes_per_cluster = ((ULONG)media_ptr -> fx_media_bytes_per_sector) * ((ULONG)media_ptr -> fx_media_sectors_per_cluster); /* Determine how many clusters. */ clusters_count = (ULONG)((data_length + bytes_per_cluster - 1) / bytes_per_cluster - 1); /* Initialize released cluster count to 0. */ clusters_released = 0; /* Follow the link of FAT entries. */ while ((cluster >= FX_FAT_ENTRY_START) && (cluster < FX_RESERVED_1_exFAT)) { /* Increment the number of clusters released. */ clusters_released++; /* Determine if the FAT chain is to be used. */ if (dont_use_fat) { /* Yes, don't use the FAT chain. */ /* Check for file size range. */ if (clusters_released - 1 >= clusters_count) { /* Set the next cluster to LAST to indicate it is the last cluster. */ contents = FX_LAST_CLUSTER_exFAT; }if (clusters_released - 1 >= clusters_count) { ... } else { /* The next cluster is just after the current cluster. */ contents = cluster + 1; }else { ... } }if (dont_use_fat) { ... } else { /* Read the current cluster entry from the FAT. */ status = _fx_utility_FAT_entry_read(media_ptr, cluster, &contents); /* Check the return value. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } }else { ... } /* Check for data corruption. */ if ((cluster == contents) || (clusters_released > media_ptr -> fx_media_total_clusters)) { /* Return the bad status. */ return(FX_FAT_READ_ERROR); }if ((cluster == contents) || (clusters_released > media_ptr -> fx_media_total_clusters)) { ... } /* Make the current cluster available. */ if (!dont_use_fat) { /* Write the FAT to free the cluster. */ status = _fx_utility_FAT_entry_write(media_ptr, cluster, FX_FREE_CLUSTER); /* Check the return value. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } }if (!dont_use_fat) { ... } /* Set cluster state in the bitmap. */ status = _fx_utility_exFAT_cluster_state_set(media_ptr, cluster, FX_EXFAT_BITMAP_CLUSTER_FREE); /* Check the return status. */ if (status != FX_SUCCESS) { /* Return the bad status. */ return(status); }if (status != FX_SUCCESS) { ... } /* Setup for the next cluster. */ cluster = contents; }while ((cluster >= FX_FAT_ENTRY_START) && (cluster < FX_RESERVED_1_exFAT)) { ... } /* Update the free clusters in the media control block. */ media_ptr -> fx_media_available_clusters = media_ptr -> fx_media_available_clusters + clusters_released; /* Return success. */ return(FX_SUCCESS); }_fx_utility_exFAT_cluster_free (FX_MEDIA *media_ptr, UCHAR *work_ptr) { ... } /* ... */ #endif /* FX_ENABLE_EXFAT */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.