Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#include "fx_system.h"
#include "fx_directory.h"
#include "fx_utility.h"
#include "fx_directory_exFAT.h"
...
Files
loading...
SourceVuSTM32 Libraries and Samplesfilexcommon/src/fx_utility_exFAT_allocate_new_cluster.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* 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 */ /** */ /** Directory */ /** */... /**************************************************************************/ /**************************************************************************/ #define FX_SOURCE_CODE /* Include necessary system files. */ #include "fx_api.h" #include "fx_system.h" #include "fx_directory.h" #include "fx_utility.h" #ifdef FX_ENABLE_EXFAT #include "fx_directory_exFAT.h" /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _fx_utility_exFAT_allocate_new_cluster PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function allocates new cluster media for a free */ /* directory entry. */ /* */ /* INPUT */ /* */ /* media_ptr Media control block pointer */ /* directory_ptr Pointer to directory to */ /* search in */ /* last_cluster Last cluster of entry */ /* cluster Allocated cluster */ /* */ /* OUTPUT */ /* */ /* return status */ /* */ /* CALLS */ /* */ /* _fx_directory_exFAT_entry_read Read exFAT entries */ /* _fx_utility_exFAT_bitmap_flush Flush exFAT allocation bitmap */ /* _fx_utility_exFAT_bitmap_free_cluster_find */ /* Find free cluster */ /* _fx_utility_exFAT_cluster_state_get Get cluster state */ /* _fx_utility_FAT_entry_read Read FAT entry */ /* _fx_utility_FAT_entry_write Write FAT entry */ /* */ /* CALLED BY */ /* */ /* _fx_directory_exFAT_free_search */ /* */ /* 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_allocate_new_cluster(FX_MEDIA *media_ptr, FX_DIR_ENTRY *directory_ptr, ULONG *last_cluster, ULONG *cluster) { UINT status = FX_SUCCESS; ULONG cluster_count; ULONG bytes_per_cluster; ULONG i; ULONG FAT_value = 0; UCHAR cluster_state = FX_EXFAT_BITMAP_CLUSTER_OCCUPIED; /* Clear the last cluster number. */ *last_cluster = 0; /* Check if we have any already allocated clusters. */ if (!directory_ptr || (directory_ptr -> fx_dir_entry_available_file_size > 0)) { /* Calculate bytes per cluster. */ bytes_per_cluster = ((ULONG)media_ptr -> fx_media_bytes_per_sector) * ((ULONG)media_ptr -> fx_media_sectors_per_cluster); /* Check if FAT table is not used. */ if (directory_ptr && (directory_ptr -> fx_dir_entry_dont_use_fat & 1)) { /* Calculate the cluster count associated with the directory. */ cluster_count = (ULONG)((directory_ptr -> fx_dir_entry_available_file_size + bytes_per_cluster - 1) / bytes_per_cluster); /* Calculate the next cluster and the last cluster. */ *cluster = directory_ptr -> fx_dir_entry_cluster + cluster_count; *last_cluster = *cluster - 1; /* Make sure the next cluster number don't exceed the total cluster number. */ if (*cluster < media_ptr -> fx_media_total_clusters + FX_FAT_ENTRY_START) { /* Get cluster state. */ status = _fx_utility_exFAT_cluster_state_get(media_ptr, *cluster, &cluster_state); if (status != FX_SUCCESS) { /* Return the bad status. */ return(status); }if (status != FX_SUCCESS) { ... } }if (*cluster < media_ptr -> fx_media_total_clusters + FX_FAT_ENTRY_START) { ... } /* Is the next cluster free? */ if (cluster_state == FX_EXFAT_BITMAP_CLUSTER_FREE) { /* Yes, so we still don't need to use FAT. */ return(FX_SUCCESS); }if (cluster_state == FX_EXFAT_BITMAP_CLUSTER_FREE) { ... } /* Now we should use FAT. Clear the bit 0. */ directory_ptr -> fx_dir_entry_dont_use_fat &= (CHAR)0xfe; /* Loop to build FAT chain. */ for (i = directory_ptr -> fx_dir_entry_cluster; i < *last_cluster; ++i) { /* Write the FAT entry. */ status = _fx_utility_FAT_entry_write(media_ptr, i, i + 1); if (status != FX_SUCCESS) { /* Return the bad status. */ return(status); }if (status != FX_SUCCESS) { ... } }for (i = directory_ptr -> fx_dir_entry_cluster; i < *last_cluster; ++i) { ... } /* Write last cluster entry. */ status = _fx_utility_FAT_entry_write(media_ptr, *last_cluster, FX_LAST_CLUSTER_exFAT); if (status != FX_SUCCESS) { /* Return the bad status. */ return(status); }if (status != FX_SUCCESS) { ... } }if (directory_ptr && (directory_ptr -> fx_dir_entry_dont_use_fat & 1)) { ... } else { /* Find last cluster by walk through the FAT chain. */ /* See if we are in sub directory or the root directory. And set the start cluster. */ if (directory_ptr) { *cluster = directory_ptr -> fx_dir_entry_cluster; }if (directory_ptr) { ... } else { *cluster = media_ptr -> fx_media_root_cluster_32; }else { ... } /* Initialize loop variables. */ *last_cluster = 0; i = 0; /* Follow the link of FAT entries. */ while ((*cluster >= FX_FAT_ENTRY_START) && (*cluster < FX_RESERVED_1_exFAT)) { /* Read the current cluster entry from the FAT. */ status = _fx_utility_FAT_entry_read(media_ptr, *cluster, &FAT_value); i++; /* Check the return value. */ if (status != FX_SUCCESS) { /* Return the error status. */ return(status); }if (status != FX_SUCCESS) { ... } /* Determine if the FAT read was invalid. */ if ((*cluster == FAT_value) || (i > media_ptr -> fx_media_total_clusters)) { /* Return the bad status. */ return(FX_FAT_READ_ERROR); }if ((*cluster == FAT_value) || (i > media_ptr -> fx_media_total_clusters)) { ... } /* Save the last valid cluster. */ *last_cluster = *cluster; /* Setup for the next cluster. */ *cluster = FAT_value; }while ((*cluster >= FX_FAT_ENTRY_START) && (*cluster < FX_RESERVED_1_exFAT)) { ... } }else { ... } }if (!directory_ptr || (directory_ptr -> fx_dir_entry_available_file_size > 0)) { ... } /* Find free cluster from exFAT media. */ status = _fx_utility_exFAT_bitmap_free_cluster_find(media_ptr, media_ptr -> fx_media_cluster_search_start, cluster); return(status); }_fx_utility_exFAT_allocate_new_cluster (FX_MEDIA *media_ptr, FX_DIR_ENTRY *directory_ptr, ULONG *last_cluster, ULONG *cluster) { ... } /* ... */ #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.