GCC Code Coverage Report


Directory: common/src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 125 / 0 / 125
Functions: 100.0% 1 / 0 / 1
Branches: 100.0% 159 / 0 / 159

fx_file_extended_allocate.c
Line Branch Exec Source
1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 * Copyright (c) 2026-present Eclipse ThreadX contributors
4 *
5 * This program and the accompanying materials are made available under the
6 * terms of the MIT License which is available at
7 * https://opensource.org/licenses/MIT.
8 *
9 * SPDX-License-Identifier: MIT
10 **************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** FileX Component */
17 /** */
18 /** File */
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_file.h"
31 #include "fx_utility.h"
32 #include "fx_directory.h"
33 #ifdef FX_ENABLE_FAULT_TOLERANT
34 #include "fx_fault_tolerant.h"
35 #endif /* FX_ENABLE_FAULT_TOLERANT */
36
37
38 /**************************************************************************/
39 /* */
40 /* FUNCTION RELEASE */
41 /* */
42 /* _fx_file_extended_allocate PORTABLE C */
43 /* 6.1 */
44 /* AUTHOR */
45 /* */
46 /* William E. Lamie, Microsoft Corporation */
47 /* */
48 /* DESCRIPTION */
49 /* */
50 /* This function attempts to allocate the number of consecutive */
51 /* clusters required to satisfy the user's request. If there are */
52 /* enough clusters, the clusters are allocated and linked to the file. */
53 /* Otherwise, if there are not enough consecutive clusters, an error */
54 /* code is returned to the caller. */
55 /* */
56 /* INPUT */
57 /* */
58 /* file_ptr File control block pointer */
59 /* size Number of bytes to allocate */
60 /* */
61 /* OUTPUT */
62 /* */
63 /* return status */
64 /* */
65 /* CALLS */
66 /* */
67 /* _fx_directory_entry_write Update directory entry */
68 /* _fx_utility_FAT_entry_read Read a FAT entry */
69 /* _fx_utility_FAT_entry_write Write a FAT entry */
70 /* _fx_utility_FAT_flush Flush written FAT entries */
71 /* _fx_utility_logical_sector_flush Flush the written log sector */
72 /* _fx_fault_tolerant_transaction_start Start fault tolerant */
73 /* transaction */
74 /* _fx_fault_tolerant_transaction_end End fault tolerant transaction*/
75 /* _fx_fault_tolerant_recover Recover FAT chain */
76 /* _fx_fault_tolerant_reset_log_file Reset the log file */
77 /* _fx_fault_tolerant_set_FAT_chain Set data of FAT chain */
78 /* */
79 /* CALLED BY */
80 /* */
81 /* Application Code */
82 /* */
83 /**************************************************************************/
84 469 UINT _fx_file_extended_allocate(FX_FILE *file_ptr, ULONG64 size)
85 {
86
87 UINT status;
88 ULONG i;
89 UINT found;
90 ULONG bytes_per_cluster;
91 ULONG FAT_index;
92 ULONG FAT_value;
93 ULONG clusters;
94 FX_MEDIA *media_ptr;
95
96 #ifdef TX_ENABLE_EVENT_TRACE
97 TX_TRACE_BUFFER_ENTRY *trace_event;
98 ULONG trace_timestamp;
99 #endif
100
101
102 /* First, determine if the file is still open. */
103
2/2
✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 460 times.
469 if (file_ptr -> fx_file_id != FX_FILE_ID)
104 {
105
106 /* Return the file not open error status. */
107 9 return(FX_NOT_OPEN);
108 }
109
110 /* Setup pointer to media structure. */
111 460 media_ptr = file_ptr -> fx_file_media_ptr;
112
113 #ifndef FX_MEDIA_STATISTICS_DISABLE
114
115 /* Increment the number of times this service has been called. */
116 460 media_ptr -> fx_media_file_allocates++;
117 #endif
118
119 /* Make sure this file is open for writing. */
120
2/2
✓ Branch 4 → 5 taken 8 times.
✓ Branch 4 → 6 taken 452 times.
460 if (file_ptr -> fx_file_open_mode != FX_OPEN_FOR_WRITE)
121 {
122
123 /* Return the access error exception - a write was attempted from
124 a file opened for reading! */
125 8 return(FX_ACCESS_ERROR);
126 }
127
128 /* Determine if the requested allocation is for zero bytes. */
129
2/2
✓ Branch 6 → 7 taken 8 times.
✓ Branch 6 → 8 taken 444 times.
452 if (size == 0)
130 {
131
132 /* Return a successful completion - nothing needs to be done. */
133 8 return(FX_SUCCESS);
134 }
135
136 /* Setup pointer to associated media control block. */
137 444 media_ptr = file_ptr -> fx_file_media_ptr;
138
139 /* If trace is enabled, insert this event into the trace buffer. */
140 FX_TRACE_IN_LINE_INSERT(FX_TRACE_FILE_ALLOCATE, file_ptr, size, file_ptr -> fx_file_current_available_size, 0, FX_TRACE_FILE_EVENTS, &trace_event, &trace_timestamp)
141
142 /* Protect against other threads accessing the media. */
143 233 FX_PROTECT
144
145 #ifdef FX_ENABLE_FAULT_TOLERANT
146 /* Start transaction. */
147 326 _fx_fault_tolerant_transaction_start(media_ptr);
148 #endif /* FX_ENABLE_FAULT_TOLERANT */
149
150 /* Check for write protect at the media level (set by driver). */
151
6/6
✓ Branch 8 → 9 taken 2 times.
✓ Branch 8 → 10 taken 46 times.
✓ Branch 9 → 10 taken 5 times.
✓ Branch 9 → 12 taken 228 times.
✓ Branch 10 → 11 taken 2 times.
✓ Branch 10 → 14 taken 161 times.
444 if (media_ptr -> fx_media_driver_write_protect)
152 {
153
154 #ifdef FX_ENABLE_FAULT_TOLERANT
155 4 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
156 #endif /* FX_ENABLE_FAULT_TOLERANT */
157
158 /* Release media protection. */
159 5 FX_UNPROTECT
160
161 /* Return write protect error. */
162 9 return(FX_WRITE_PROTECT);
163 }
164
165 /* Calculate the number of bytes per cluster. */
166 435 bytes_per_cluster = ((ULONG)media_ptr -> fx_media_bytes_per_sector) *
167 435 ((ULONG)media_ptr -> fx_media_sectors_per_cluster);
168
169 /* Check for invalid value. */
170
6/6
✓ Branch 10 → 11 taken 2 times.
✓ Branch 10 → 12 taken 44 times.
✓ Branch 12 → 13 taken 4 times.
✓ Branch 12 → 15 taken 224 times.
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 18 taken 159 times.
435 if (bytes_per_cluster == 0)
171 {
172
173 #ifdef FX_ENABLE_FAULT_TOLERANT
174 4 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
175 #endif /* FX_ENABLE_FAULT_TOLERANT */
176
177 /* Release media protection. */
178 4 FX_UNPROTECT
179
180 /* Invalid media, return error. */
181 8 return(FX_MEDIA_INVALID);
182 }
183
184 /* Calculate the number of consecutive clusters needed to satisfy this
185 request. */
186 427 clusters = (ULONG)(((size + bytes_per_cluster - 1) / bytes_per_cluster));
187
188 /* Determine if cluster count is 0. */
189
6/6
✓ Branch 12 → 13 taken 2 times.
✓ Branch 12 → 14 taken 42 times.
✓ Branch 15 → 16 taken 4 times.
✓ Branch 15 → 18 taken 220 times.
✓ Branch 18 → 19 taken 2 times.
✓ Branch 18 → 22 taken 157 times.
427 if (clusters == 0)
190 {
191
192 #ifdef FX_ENABLE_FAULT_TOLERANT
193 4 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
194 #endif /* FX_ENABLE_FAULT_TOLERANT */
195
196 /* Release media protection. */
197 4 FX_UNPROTECT
198
199 /* Size overflow when rounding to the next cluster, return an error status. */
200 8 return(FX_NO_MORE_SPACE);
201 }
202
203 /* Determine if there are enough available clusters on the media. */
204
6/6
✓ Branch 14 → 15 taken 2 times.
✓ Branch 14 → 16 taken 40 times.
✓ Branch 18 → 19 taken 5 times.
✓ Branch 18 → 21 taken 215 times.
✓ Branch 22 → 23 taken 2 times.
✓ Branch 22 → 26 taken 155 times.
419 if (clusters > media_ptr -> fx_media_available_clusters)
205 {
206
207 #ifdef FX_ENABLE_FAULT_TOLERANT
208 4 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
209 #endif /* FX_ENABLE_FAULT_TOLERANT */
210
211 /* Release media protection. */
212 5 FX_UNPROTECT
213
214 /* Not enough clusters, return an error status. */
215 9 return(FX_NO_MORE_SPACE);
216 }
217
218 /* Determine if the requested file allocation would exceed the physical limit of the file. */
219
6/6
✓ Branch 16 → 17 taken 38 times.
✓ Branch 16 → 18 taken 2 times.
✓ Branch 21 → 22 taken 210 times.
✓ Branch 21 → 23 taken 5 times.
✓ Branch 26 → 27 taken 153 times.
✓ Branch 26 → 28 taken 2 times.
410 if (((file_ptr -> fx_file_current_available_size + (((ULONG64) clusters) * ((ULONG64) bytes_per_cluster))) < file_ptr -> fx_file_current_available_size) ||
220
6/6
✓ Branch 17 → 18 taken 2 times.
✓ Branch 17 → 19 taken 36 times.
✓ Branch 22 → 23 taken 5 times.
✓ Branch 22 → 25 taken 205 times.
✓ Branch 27 → 28 taken 2 times.
✓ Branch 27 → 31 taken 151 times.
401 ((file_ptr -> fx_file_current_available_size + (((ULONG64) clusters) * ((ULONG64) bytes_per_cluster))) > 0xFFFFFFFFULL))
221 {
222
223 #ifdef FX_ENABLE_FAULT_TOLERANT
224 8 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
225 #endif /* FX_ENABLE_FAULT_TOLERANT */
226
227 /* Release media protection. */
228 10 FX_UNPROTECT
229
230 /* Return the no more space error, since the new file size would be larger than
231 the 32-bit field to represent it in the file's directory entry. */
232 18 return(FX_NO_MORE_SPACE);
233 }
234
235 /* Now we need to find the consecutive clusters. */
236 392 FAT_index = FX_FAT_ENTRY_START;
237 392 found = FX_FALSE;
238
239
240
6/6
✓ Branch 31 → 20 taken 13912 times.
✓ Branch 31 → 32 taken 2 times.
✓ Branch 38 → 26 taken 44742 times.
✓ Branch 38 → 39 taken 5 times.
✓ Branch 45 → 32 taken 23874 times.
✓ Branch 45 → 46 taken 2 times.
82537 while (FAT_index <= (media_ptr -> fx_media_total_clusters - clusters + FX_FAT_ENTRY_START))
241 {
242
243 /* Determine if enough consecutive FAT entries are available. */
244 82528 i = 0;
245
246
247 do
248 {
249
250 /* Read a FAT entry. */
251 121436 status = _fx_utility_FAT_entry_read(media_ptr, (FAT_index + i), &FAT_value);
252
253 /* Check for a successful status. */
254
6/6
✓ Branch 22 → 23 taken 2 times.
✓ Branch 22 → 24 taken 14446 times.
✓ Branch 28 → 29 taken 5 times.
✓ Branch 28 → 31 taken 64325 times.
✓ Branch 34 → 35 taken 2 times.
✓ Branch 34 → 38 taken 42656 times.
121436 if (status != FX_SUCCESS)
255 {
256
257 #ifdef FX_ENABLE_FAULT_TOLERANT
258 4 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
259 #endif /* FX_ENABLE_FAULT_TOLERANT */
260
261 /* Release media protection. */
262 5 FX_UNPROTECT
263
264 /* Return the error status. */
265 9 return(status);
266 }
267
268 /* Determine if the entry is free. */
269
6/6
✓ Branch 24 → 25 taken 13878 times.
✓ Branch 24 → 26 taken 568 times.
✓ Branch 31 → 32 taken 44542 times.
✓ Branch 31 → 33 taken 19783 times.
✓ Branch 38 → 39 taken 23725 times.
✓ Branch 38 → 40 taken 18931 times.
121427 if (FAT_value != FX_FREE_CLUSTER)
270 {
271 82145 break;
272 }
273
274 /* Otherwise, increment the consecutive FAT indices. */
275 39282 i++;
276
6/6
✓ Branch 26 → 27 taken 536 times.
✓ Branch 26 → 28 taken 32 times.
✓ Branch 33 → 34 taken 19588 times.
✓ Branch 33 → 35 taken 195 times.
✓ Branch 40 → 41 taken 18784 times.
✓ Branch 40 → 42 taken 147 times.
39282 } while (i < clusters);
277
278 /* Determine if we found enough FAT entries. */
279
6/6
✓ Branch 28 → 29 taken 32 times.
✓ Branch 28 → 30 taken 13878 times.
✓ Branch 35 → 36 taken 195 times.
✓ Branch 35 → 37 taken 44542 times.
✓ Branch 42 → 43 taken 147 times.
✓ Branch 42 → 44 taken 23725 times.
82519 if (i >= clusters)
280 {
281
282 /* Yes, we have found enough FAT entries - set the found
283 flag and get out of this loop. */
284 374 found = FX_TRUE;
285 374 break;
286 }
287 else
288 {
289 /* Position to the next possibly free FAT entry. */
290 82145 FAT_index = FAT_index + i + 1;
291 }
292 }
293
294 /* Determine if we found enough consecutive clusters to satisfy the
295 request. */
296
7/7
✓ Branch 32 → 33 taken 32 times.
✓ Branch 32 → 53 taken 2 times.
✓ Branch 39 → 40 taken 195 times.
✓ Branch 39 → 64 taken 3 times.
✓ Branch 39 → 69 taken 2 times.
✓ Branch 46 → 47 taken 147 times.
✓ Branch 46 → 80 taken 2 times.
383 if (found)
297 {
298
299 #ifdef FX_ENABLE_FAULT_TOLERANT
300
4/4
✓ Branch 40 → 41 taken 115 times.
✓ Branch 40 → 42 taken 32 times.
✓ Branch 47 → 48 taken 115 times.
✓ Branch 47 → 49 taken 32 times.
294 if (media_ptr -> fx_media_fault_tolerant_enabled)
301 {
302
303 /* Record the action that is about to take place. This information
304 would aid the undo process should fault condition happens. */
305 230 media_ptr -> fx_media_fault_tolerant_state |= FX_FAULT_TOLERANT_STATE_SET_FAT_CHAIN;
306 230 _fx_fault_tolerant_set_FAT_chain(media_ptr, FX_FALSE, file_ptr -> fx_file_last_physical_cluster,
307 FAT_index, media_ptr -> fx_media_fat_last, media_ptr -> fx_media_fat_last);
308 }
309 #endif /* FX_ENABLE_FAULT_TOLERANT */
310
311
312 /* Update the link pointers in the new clusters. */
313
8/8
✓ Branch 38 → 34 taken 530 times.
✓ Branch 38 → 39 taken 30 times.
✓ Branch 46 → 41 taken 795 times.
✓ Branch 46 → 47 taken 45 times.
✓ Branch 48 → 43 taken 18778 times.
✓ Branch 48 → 49 taken 145 times.
✓ Branch 56 → 50 taken 18778 times.
✓ Branch 56 → 57 taken 145 times.
39246 for (i = 0; i < (clusters - 1); i++)
314 {
315
316 /* Update the cluster links. Since the allocation is
317 sequential, we just have to link each FAT entry to the
318 next one. */
319 38881 status = _fx_utility_FAT_entry_write(media_ptr, FAT_index + i, FAT_index + i + 1);
320
321 /* Check for a bad status. */
322
8/8
✓ Branch 35 → 36 taken 2 times.
✓ Branch 35 → 37 taken 528 times.
✓ Branch 42 → 43 taken 3 times.
✓ Branch 42 → 45 taken 792 times.
✓ Branch 44 → 45 taken 2 times.
✓ Branch 44 → 47 taken 18776 times.
✓ Branch 51 → 52 taken 2 times.
✓ Branch 51 → 55 taken 18776 times.
38881 if (status != FX_SUCCESS)
323 {
324
325 #ifdef FX_ENABLE_FAULT_TOLERANT
326 4 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
327 #endif /* FX_ENABLE_FAULT_TOLERANT */
328
329 /* Release media protection. */
330 5 FX_UNPROTECT
331
332 /* Return the error status. */
333 9 return(status);
334 }
335 }
336
337 /* Now place an EOF in the last cluster entry. */
338 365 status = _fx_utility_FAT_entry_write(media_ptr, FAT_index + clusters - 1, media_ptr -> fx_media_fat_last);
339
340 /* Check for a bad status. */
341
8/8
✓ Branch 40 → 41 taken 2 times.
✓ Branch 40 → 42 taken 28 times.
✓ Branch 48 → 49 taken 3 times.
✓ Branch 48 → 51 taken 42 times.
✓ Branch 50 → 51 taken 2 times.
✓ Branch 50 → 53 taken 143 times.
✓ Branch 58 → 59 taken 2 times.
✓ Branch 58 → 62 taken 143 times.
365 if (status != FX_SUCCESS)
342 {
343
344 #ifdef FX_ENABLE_FAULT_TOLERANT
345 4 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
346 #endif /* FX_ENABLE_FAULT_TOLERANT */
347
348 /* Release media protection. */
349 5 FX_UNPROTECT
350
351 /* Return the error status. */
352 9 return(status);
353 }
354
355 #ifdef FX_FAULT_TOLERANT
356
357 /* Flush the cached individual FAT entries */
358 286 _fx_utility_FAT_flush(media_ptr);
359
360 #endif
361
362 /* Actually link up the new clusters to the file. */
363
364 /* Determine if there are already clusters allocated for this file. */
365
8/8
✓ Branch 42 → 43 taken 14 times.
✓ Branch 42 → 49 taken 14 times.
✓ Branch 51 → 52 taken 21 times.
✓ Branch 51 → 59 taken 21 times.
✓ Branch 54 → 55 taken 63 times.
✓ Branch 54 → 62 taken 72 times.
✓ Branch 63 → 64 taken 63 times.
✓ Branch 63 → 72 taken 72 times.
340 if (file_ptr -> fx_file_total_clusters)
366 {
367
368 /* Linkup the last cluster. */
369 161 status = _fx_utility_FAT_entry_write(media_ptr,
370 file_ptr -> fx_file_last_physical_cluster, FAT_index);
371
372 /* Check for a bad status. */
373
8/8
✓ Branch 44 → 45 taken 2 times.
✓ Branch 44 → 46 taken 12 times.
✓ Branch 53 → 54 taken 3 times.
✓ Branch 53 → 56 taken 18 times.
✓ Branch 56 → 57 taken 2 times.
✓ Branch 56 → 59 taken 61 times.
✓ Branch 65 → 66 taken 2 times.
✓ Branch 65 → 69 taken 61 times.
161 if (status != FX_SUCCESS)
374 {
375
376 #ifdef FX_ENABLE_FAULT_TOLERANT
377 4 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
378 #endif /* FX_ENABLE_FAULT_TOLERANT */
379
380 /* Release media protection. */
381 5 FX_UNPROTECT
382
383 /* Return the error status. */
384 9 return(status);
385 }
386
387 /* Determine if we are adding a sector after a write filled the previously
388 allocated cluster exactly. */
389 152 if ((file_ptr -> fx_file_current_relative_sector >=
390
8/8
✓ Branch 46 → 47 taken 10 times.
✓ Branch 46 → 50 taken 2 times.
✓ Branch 56 → 57 taken 15 times.
✓ Branch 56 → 60 taken 3 times.
✓ Branch 59 → 60 taken 26 times.
✓ Branch 59 → 63 taken 35 times.
✓ Branch 69 → 70 taken 26 times.
✓ Branch 69 → 73 taken 35 times.
152 (media_ptr -> fx_media_sectors_per_cluster - 1)) &&
391 77 (file_ptr -> fx_file_current_logical_offset >=
392
8/8
✓ Branch 47 → 48 taken 6 times.
✓ Branch 47 → 50 taken 4 times.
✓ Branch 57 → 58 taken 9 times.
✓ Branch 57 → 60 taken 6 times.
✓ Branch 60 → 61 taken 22 times.
✓ Branch 60 → 63 taken 4 times.
✓ Branch 70 → 71 taken 22 times.
✓ Branch 70 → 73 taken 4 times.
77 media_ptr -> fx_media_bytes_per_sector))
393 {
394
395 /* Yes, we need to adjust all of the pertinent file parameters for
396 access into this newly allocated cluster. */
397 59 file_ptr -> fx_file_current_physical_cluster = FAT_index;
398 59 file_ptr -> fx_file_current_relative_cluster++;
399 59 file_ptr -> fx_file_current_relative_sector = 0;
400 59 file_ptr -> fx_file_current_logical_sector = ((ULONG)media_ptr -> fx_media_data_sector_start) +
401 59 (((ULONG64)(FAT_index - FX_FAT_ENTRY_START)) *
402 59 ((ULONG)media_ptr -> fx_media_sectors_per_cluster));
403 59 file_ptr -> fx_file_current_logical_offset = 0;
404 }
405 }
406 else
407 {
408
409 /* These new clusters are also the first! Setup the initial
410 file parameters. */
411 179 file_ptr -> fx_file_first_physical_cluster = FAT_index;
412 179 file_ptr -> fx_file_current_physical_cluster = file_ptr -> fx_file_first_physical_cluster;
413 179 file_ptr -> fx_file_current_relative_cluster = 0;
414 179 file_ptr -> fx_file_current_logical_sector = ((ULONG)media_ptr -> fx_media_data_sector_start) +
415 179 (((ULONG64)(file_ptr -> fx_file_first_physical_cluster - FX_FAT_ENTRY_START)) *
416 179 ((ULONG)media_ptr -> fx_media_sectors_per_cluster));
417 179 file_ptr -> fx_file_current_logical_offset = 0;
418 179 file_ptr -> fx_file_current_file_offset = 0;
419
420 /* Update the first cluster in the directory entry. */
421 179 file_ptr -> fx_file_dir_entry.fx_dir_entry_cluster = FAT_index;
422 }
423
424 /* Remember the last physical cluster. */
425 331 file_ptr -> fx_file_last_physical_cluster = FAT_index + clusters - 1;
426
427
428 /* Check for wrap-around when updating the available size. */
429 /* Update the available size. */
430 331 file_ptr -> fx_file_current_available_size =
431 331 file_ptr -> fx_file_current_available_size + (bytes_per_cluster * clusters);
432
433
434 /* Increment the total clusters for this file. */
435 331 file_ptr -> fx_file_total_clusters =
436 331 file_ptr -> fx_file_total_clusters + clusters;
437
438 /* Decrease the available clusters on the media. */
439 331 media_ptr -> fx_media_available_clusters =
440 331 media_ptr -> fx_media_available_clusters - clusters;
441
442 #if defined(FX_UPDATE_FILE_SIZE_ON_ALLOCATE) || defined(FX_ENABLE_FAULT_TOLERANT)
443
444 /* Set the file size the current size plus what what was added. */
445 266 file_ptr -> fx_file_current_file_size += size;
446
447 /* Copy the new file size into the directory entry. */
448 266 file_ptr -> fx_file_dir_entry.fx_dir_entry_file_size = file_ptr -> fx_file_current_file_size;
449 #endif
450
451 #ifdef FX_ENABLE_FAULT_TOLERANT
452
4/4
✓ Branch 63 → 64 taken 107 times.
✓ Branch 63 → 65 taken 26 times.
✓ Branch 73 → 74 taken 107 times.
✓ Branch 73 → 75 taken 26 times.
266 if (media_ptr -> fx_media_fault_tolerant_enabled)
453 {
454
455 /* Clear undo phase. */
456 214 media_ptr -> fx_media_fault_tolerant_state &= (UCHAR)(~FX_FAULT_TOLERANT_STATE_SET_FAT_CHAIN & 0xff);
457 }
458 #endif /* FX_ENABLE_FAULT_TOLERANT */
459
460 /* Update the trace event with the new size. */
461 FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_FILE_ALLOCATE, 0, 0, 0, file_ptr -> fx_file_current_file_size);
462
463 /* Write the directory entry to the media. */
464 331 status = _fx_directory_entry_write(media_ptr, &(file_ptr -> fx_file_dir_entry));
465
466 /* Check for a good status. */
467
8/8
✓ Branch 51 → 52 taken 2 times.
✓ Branch 51 → 54 taken 24 times.
✓ Branch 61 → 62 taken 3 times.
✓ Branch 61 → 66 taken 36 times.
✓ Branch 66 → 67 taken 2 times.
✓ Branch 66 → 71 taken 131 times.
✓ Branch 76 → 77 taken 2 times.
✓ Branch 76 → 83 taken 131 times.
331 if (status != FX_SUCCESS)
468 {
469
470 #ifdef FX_ENABLE_FAULT_TOLERANT
471 4 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
472 #endif /* FX_ENABLE_FAULT_TOLERANT */
473
474 /* Release media protection. */
475 5 FX_UNPROTECT
476
477 /* Return the error status. */
478 9 return(status);
479 }
480 }
481 else
482 {
483
484 #ifdef FX_ENABLE_FAULT_TOLERANT
485 4 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
486 #endif /* FX_ENABLE_FAULT_TOLERANT */
487
488 /* Release media protection. */
489 5 FX_UNPROTECT
490
491 /* Not enough contiguous space on the media. Return error status. */
492 9 return(FX_NO_MORE_SPACE);
493 }
494
495 #ifdef FX_FAULT_TOLERANT
496
497 /* Flush the cached individual FAT entries */
498 262 _fx_utility_FAT_flush(media_ptr);
499 #endif
500
501 /* Flush the internal logical sector cache. */
502 322 status = _fx_utility_logical_sector_flush(media_ptr, ((ULONG64) 1), (ULONG64)(media_ptr -> fx_media_sectors_per_FAT), FX_FALSE);
503
504 #ifdef FX_ENABLE_FAULT_TOLERANT
505 /* Check for a bad status. */
506
4/4
✓ Branch 73 → 74 taken 1 time.
✓ Branch 73 → 76 taken 130 times.
✓ Branch 85 → 86 taken 1 time.
✓ Branch 85 → 89 taken 130 times.
262 if (status != FX_SUCCESS)
507 {
508
509 2 FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
510
511 /* Release media protection. */
512 1 FX_UNPROTECT
513
514 /* Return the bad status. */
515 2 return(status);
516 }
517
518
4/4
✓ Branch 76 → 77 taken 104 times.
✓ Branch 76 → 78 taken 26 times.
✓ Branch 89 → 90 taken 104 times.
✓ Branch 89 → 91 taken 26 times.
260 if (media_ptr -> fx_media_fault_tolerant_enabled)
519 {
520
521 /* Copy the new file size into the directory entry. */
522 208 file_ptr -> fx_file_dir_entry.fx_dir_entry_file_size = file_ptr -> fx_file_current_file_size;
523 }
524
525 /* End transaction. */
526 260 status = _fx_fault_tolerant_transaction_end(media_ptr);
527 #endif /* FX_ENABLE_FAULT_TOLERANT */
528
529 /* Release media protection. */
530 148 FX_UNPROTECT
531
532 /* Return status to the caller. */
533 284 return(status);
534 }
535
536