1
10
13
14
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
146
152
153
154
155
156
157
158
159
160
166
167
168
169
175
176
177
178
179
180
181
182
183
184
190
191
192
193
194
195
196
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#ifdef FX_ENABLE_EXFAT
#include "fx_directory_exFAT.h"
#include "fx_utility.h"
...
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;
cluster = _fx_utility_32_unsigned_read(&(work_ptr[FX_EXFAT_FIRST_CLUSTER]));
data_length = _fx_utility_64_unsigned_read(&(work_ptr[FX_EXFAT_DATA_LENGTH]));
dont_use_fat = (work_ptr[FX_EXFAT_SECOND_FLAG] >> 1) & 1;
status = FX_SUCCESS;
if (((work_ptr[FX_EXFAT_SECOND_FLAG] & FX_EXFAT_SECOND_FLAG_ALLOCATION_POSSIBLE_MASK) == 0) ||
(cluster == 0) ||
(data_length == 0))
{
return(FX_SUCCESS);
}if (((work_ptr[FX_EXFAT_SECOND_FLAG] & FX_EXFAT_SECOND_FLAG_ALLOCATION_POSSIBLE_MASK) == 0) || (cluster == 0) || (data_length == 0)) { ... }
bytes_per_cluster = ((ULONG)media_ptr -> fx_media_bytes_per_sector) *
((ULONG)media_ptr -> fx_media_sectors_per_cluster);
clusters_count = (ULONG)((data_length + bytes_per_cluster - 1) / bytes_per_cluster - 1);
clusters_released = 0;
while ((cluster >= FX_FAT_ENTRY_START) && (cluster < FX_RESERVED_1_exFAT))
{
clusters_released++;
if (dont_use_fat)
{
if (clusters_released - 1 >= clusters_count)
{
contents = FX_LAST_CLUSTER_exFAT;
}if (clusters_released - 1 >= clusters_count) { ... }
else
{
contents = cluster + 1;
}else { ... }
}if (dont_use_fat) { ... }
else
{
status = _fx_utility_FAT_entry_read(media_ptr, cluster, &contents);
if (status != FX_SUCCESS)
{
return(status);
}if (status != FX_SUCCESS) { ... }
}else { ... }
if ((cluster == contents) || (clusters_released > media_ptr -> fx_media_total_clusters))
{
return(FX_FAT_READ_ERROR);
}if ((cluster == contents) || (clusters_released > media_ptr -> fx_media_total_clusters)) { ... }
if (!dont_use_fat)
{
status = _fx_utility_FAT_entry_write(media_ptr, cluster, FX_FREE_CLUSTER);
if (status != FX_SUCCESS)
{
return(status);
}if (status != FX_SUCCESS) { ... }
}if (!dont_use_fat) { ... }
status = _fx_utility_exFAT_cluster_state_set(media_ptr, cluster, FX_EXFAT_BITMAP_CLUSTER_FREE);
if (status != FX_SUCCESS)
{
return(status);
}if (status != FX_SUCCESS) { ... }
cluster = contents;
}while ((cluster >= FX_FAT_ENTRY_START) && (cluster < FX_RESERVED_1_exFAT)) { ... }
media_ptr -> fx_media_available_clusters = media_ptr -> fx_media_available_clusters + clusters_released;
return(FX_SUCCESS);
}_fx_utility_exFAT_cluster_free (FX_MEDIA *media_ptr, UCHAR *work_ptr) { ... }
/* ... */
#endif