1
10
13
14
20
21
22
23
24
25
26
27
28
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
115
116
117
118
120
121
122
123
124
130
131
132
137
138
139
140
141
142
143
144
145
146
147
148
149
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
233
234
235
236
241
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
291
292
293
294
295
297
298
299
300
301
302
303
304
305
306
307
308
309
310
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
359
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
692
693
694
695
696
697
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
751
752
753
754
755
756
758
759
760
761
762
763
764
765
766
767
768
769
770
771
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
820
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
925
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
965
966
967
968
969
970
971
972
973
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#include "fx_system.h"
#include "fx_directory.h"
#include "fx_file.h"
#include "fx_utility.h"
5 includes#ifdef FX_ENABLE_FAULT_TOLERANT
#include "fx_fault_tolerant.h"
#endif
...
...
UINT _fx_file_extended_truncate_release(FX_FILE *file_ptr, ULONG64 size)
{
UINT status;
ULONG cluster;
ULONG contents;
ULONG bytes_per_cluster;
ULONG last_cluster;
ULONG cluster_count;
ULONG64 bytes_remaining;
FX_MEDIA *media_ptr;
#ifdef FX_ENABLE_EXFAT
ULONG original_last_physical_cluster;
#endif
#ifndef FX_DONT_UPDATE_OPEN_FILES
ULONG open_count;
FX_FILE *search_ptr;/* ... */
#endif
#ifdef TX_ENABLE_EVENT_TRACE
TX_TRACE_BUFFER_ENTRY *trace_event;
ULONG trace_timestamp;/* ... */
#endif
if (file_ptr -> fx_file_id != FX_FILE_ID)
{
return(FX_NOT_OPEN);
}if (file_ptr -> fx_file_id != FX_FILE_ID) { ... }
#ifndef FX_MEDIA_STATISTICS_DISABLE
media_ptr = file_ptr -> fx_file_media_ptr;
media_ptr -> fx_media_file_truncate_releases++;/* ... */
#endif
media_ptr = file_ptr -> fx_file_media_ptr;
FX_TRACE_IN_LINE_INSERT(FX_TRACE_FILE_TRUNCATE_RELEASE, file_ptr, size, file_ptr -> fx_file_current_file_size, 0, FX_TRACE_FILE_EVENTS, &trace_event, &trace_timestamp)
FX_PROTECT
#ifdef FX_ENABLE_FAULT_TOLERANT
_fx_fault_tolerant_transaction_start(media_ptr);/* ... */
#endif
if (file_ptr -> fx_file_open_mode != FX_OPEN_FOR_WRITE)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
/* ... */
return(FX_ACCESS_ERROR);
}if (file_ptr -> fx_file_open_mode != FX_OPEN_FOR_WRITE) { ... }
if (media_ptr -> fx_media_driver_write_protect)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(FX_WRITE_PROTECT);
}if (media_ptr -> fx_media_driver_write_protect) { ... }
bytes_per_cluster = ((ULONG)media_ptr -> fx_media_bytes_per_sector) *
((ULONG)media_ptr -> fx_media_sectors_per_cluster);
if (bytes_per_cluster == 0)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(FX_MEDIA_INVALID);
}if (bytes_per_cluster == 0) { ... }
if (size < file_ptr -> fx_file_current_available_size)
{
file_ptr -> fx_file_current_available_size = ((size + bytes_per_cluster - 1) / bytes_per_cluster) * bytes_per_cluster;
if (size < file_ptr -> fx_file_current_file_size)
{
file_ptr -> fx_file_current_file_size = size;
file_ptr -> fx_file_modified = FX_TRUE;
file_ptr -> fx_file_dir_entry.fx_dir_entry_file_size = size;
if (size == 0)
{
/* ... */
file_ptr -> fx_file_dir_entry.fx_dir_entry_cluster = FX_NULL;
}if (size == 0) { ... }
#ifdef FX_ENABLE_EXFAT
if (media_ptr -> fx_media_FAT_type == FX_exFAT)
{
status = _fx_directory_exFAT_entry_write(
media_ptr, &(file_ptr -> fx_file_dir_entry), UPDATE_STREAM);
}if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... }
else
{
#endif
status = _fx_directory_entry_write(media_ptr, &(file_ptr -> fx_file_dir_entry));
#ifdef FX_ENABLE_EXFAT
}else { ... }
#endif
if (status != FX_SUCCESS)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
}if (size < file_ptr -> fx_file_current_file_size) { ... }
FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_FILE_TRUNCATE_RELEASE, 0, 0, 0, file_ptr -> fx_file_current_file_size)
}if (size < file_ptr -> fx_file_current_available_size) { ... }
else
{
FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_FILE_TRUNCATE_RELEASE, 0, 0, 0, file_ptr -> fx_file_current_file_size)
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(FX_SUCCESS);
}else { ... }
bytes_per_cluster = ((ULONG)media_ptr -> fx_media_bytes_per_sector) *
((ULONG)media_ptr -> fx_media_sectors_per_cluster);
/* ... */
if (file_ptr -> fx_file_current_file_offset > file_ptr -> fx_file_current_file_size)
{
/* ... */
cluster = file_ptr -> fx_file_first_physical_cluster;
bytes_remaining = size;
last_cluster = 0;
cluster_count = 0;
while ((cluster >= FX_FAT_ENTRY_START) && (cluster < media_ptr -> fx_media_fat_reserved))
{
cluster_count++;
#ifdef FX_ENABLE_EXFAT
if (file_ptr -> fx_file_dir_entry.fx_dir_entry_dont_use_fat & 1)
{
if (cluster >= file_ptr -> fx_file_last_physical_cluster)
{
contents = FX_LAST_CLUSTER_exFAT;
}if (cluster >= file_ptr -> fx_file_last_physical_cluster) { ... }
else
{
contents = cluster + 1;
}else { ... }
}if (file_ptr -> fx_file_dir_entry.fx_dir_entry_dont_use_fat & 1) { ... }
else
{
#endif
status = _fx_utility_FAT_entry_read(media_ptr, cluster, &contents);
if (status != FX_SUCCESS)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
#ifdef FX_ENABLE_EXFAT
}else { ... }
#endif
last_cluster = cluster;
cluster = contents;
if (bytes_remaining >= bytes_per_cluster)
{
bytes_remaining = bytes_remaining - bytes_per_cluster;
}if (bytes_remaining >= bytes_per_cluster) { ... }
else
{
break;
}else { ... }
}while ((cluster >= FX_FAT_ENTRY_START) && (cluster < media_ptr -> fx_media_fat_reserved)) { ... }
if (size > (((ULONG64) bytes_per_cluster) * ((ULONG64) cluster_count)))
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(FX_FILE_CORRUPT);
}if (size > (((ULONG64) bytes_per_cluster) * ((ULONG64) cluster_count))) { ... }
file_ptr -> fx_file_current_physical_cluster = last_cluster;
file_ptr -> fx_file_current_relative_cluster = cluster_count - 1;
file_ptr -> fx_file_current_logical_sector = ((ULONG)media_ptr -> fx_media_data_sector_start) +
(((ULONG64)file_ptr -> fx_file_current_physical_cluster - FX_FAT_ENTRY_START) *
((ULONG)media_ptr -> fx_media_sectors_per_cluster)) +
(bytes_remaining / (ULONG)media_ptr -> fx_media_bytes_per_sector);
file_ptr -> fx_file_current_relative_sector = (UINT)((bytes_remaining / (ULONG)media_ptr -> fx_media_bytes_per_sector));
file_ptr -> fx_file_current_file_offset = size;
file_ptr -> fx_file_current_logical_offset = (ULONG)bytes_remaining % ((ULONG)media_ptr -> fx_media_bytes_per_sector);
}if (file_ptr -> fx_file_current_file_offset > file_ptr -> fx_file_current_file_size) { ... }
cluster_count = (ULONG) (file_ptr -> fx_file_current_available_size + (((ULONG64) bytes_per_cluster) - ((ULONG64) 1)))/bytes_per_cluster;
file_ptr -> fx_file_total_clusters = cluster_count;
/* ... */
cluster = file_ptr -> fx_file_first_physical_cluster;
#ifdef FX_ENABLE_EXFAT
original_last_physical_cluster = file_ptr -> fx_file_last_physical_cluster;
#endif
#ifdef FX_ENABLE_FAULT_TOLERANT
if ((cluster_count == 0) && (media_ptr -> fx_media_fault_tolerant_enabled))
{
#ifdef FX_ENABLE_EXFAT
if (!(file_ptr -> fx_file_dir_entry.fx_dir_entry_dont_use_fat & 1))
{
#endif
status = _fx_fault_tolerant_set_FAT_chain(media_ptr, FX_FALSE, FX_FREE_CLUSTER,
media_ptr -> fx_media_fat_last, cluster, media_ptr -> fx_media_fat_last);
if (status != FX_SUCCESS)
{
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
#ifdef FX_ENABLE_EXFAT
}if (!(file_ptr -> fx_file_dir_entry.fx_dir_entry_dont_use_fat & 1)) { ... }
else
{
status = _fx_fault_tolerant_set_FAT_chain(media_ptr, FX_TRUE, FX_FREE_CLUSTER,
media_ptr -> fx_media_fat_last, cluster, file_ptr -> fx_file_last_physical_cluster + 1);
if (status != FX_SUCCESS)
{
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
}else { ... }
#endif
file_ptr -> fx_file_last_physical_cluster = cluster;
}if ((cluster_count == 0) && (media_ptr -> fx_media_fault_tolerant_enabled)) { ... }
/* ... */#endif
while ((cluster >= FX_FAT_ENTRY_START) && (cluster < media_ptr -> fx_media_fat_reserved))
{
#ifdef FX_ENABLE_EXFAT
if (file_ptr -> fx_file_dir_entry.fx_dir_entry_dont_use_fat & 1)
{
if (cluster >= original_last_physical_cluster)
{
contents = FX_LAST_CLUSTER_exFAT;
}if (cluster >= original_last_physical_cluster) { ... }
else
{
contents = cluster + 1;
}else { ... }
}if (file_ptr -> fx_file_dir_entry.fx_dir_entry_dont_use_fat & 1) { ... }
else
{
#endif
status = _fx_utility_FAT_entry_read(media_ptr, cluster, &contents);
if (status != FX_SUCCESS)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
#ifdef FX_ENABLE_EXFAT
}else { ... }
#endif
if (cluster_count > 0)
{
cluster_count--;
if (cluster_count == 0)
{
#ifdef FX_ENABLE_EXFAT
if (!(file_ptr -> fx_file_dir_entry.fx_dir_entry_dont_use_fat & 1))
#endif
{
#ifdef FX_ENABLE_FAULT_TOLERANT
if (media_ptr -> fx_media_fault_tolerant_enabled)
{
media_ptr -> fx_media_fault_tolerant_state |= FX_FAULT_TOLERANT_STATE_SET_FAT_CHAIN;
status = _fx_utility_FAT_entry_read(media_ptr, cluster, &contents);
if (status != FX_SUCCESS)
{
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
status = _fx_fault_tolerant_set_FAT_chain(media_ptr, FX_FALSE, cluster,
media_ptr -> fx_media_fat_last, contents, media_ptr -> fx_media_fat_last);
if (status != FX_SUCCESS)
{
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
}if (media_ptr -> fx_media_fault_tolerant_enabled) { ... }
/* ... */#endif
status = _fx_utility_FAT_entry_write(media_ptr, cluster, media_ptr -> fx_media_fat_last);
if (status)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(status);
}if (status) { ... }
#ifdef FX_ENABLE_FAULT_TOLERANT
if (media_ptr -> fx_media_fault_tolerant_enabled)
{
media_ptr -> fx_media_fault_tolerant_state &= (UCHAR)(~FX_FAULT_TOLERANT_STATE_SET_FAT_CHAIN & 0xff);
}if (media_ptr -> fx_media_fault_tolerant_enabled) { ... }
/* ... */#endif
...}
#if defined(FX_ENABLE_EXFAT) && defined(FX_ENABLE_FAULT_TOLERANT)
else if (media_ptr -> fx_media_fault_tolerant_enabled)
{
status = _fx_fault_tolerant_set_FAT_chain(media_ptr, FX_TRUE, cluster,
media_ptr -> fx_media_fat_last, contents, file_ptr -> fx_file_last_physical_cluster + 1);
if (status != FX_SUCCESS)
{
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
}else if (media_ptr -> fx_media_fault_tolerant_enabled) { ... }
/* ... */#endif
file_ptr -> fx_file_last_physical_cluster = cluster;
#ifdef FX_FAULT_TOLERANT
status = _fx_utility_FAT_flush(media_ptr);
if (status)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(status);
}if (status) { ... }
/* ... */#endif
}if (cluster_count == 0) { ... }
}if (cluster_count > 0) { ... }
else
{
/* ... */
#ifdef FX_ENABLE_FAULT_TOLERANT
if (media_ptr -> fx_media_fault_tolerant_enabled == FX_FALSE)
{
#endif
#ifdef FX_ENABLE_EXFAT
if (!(file_ptr -> fx_file_dir_entry.fx_dir_entry_dont_use_fat & 1))
{
#endif
status = _fx_utility_FAT_entry_write(media_ptr, cluster, FX_FREE_CLUSTER);
if (status)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(status);
}if (status) { ... }
#ifdef FX_ENABLE_EXFAT
}if (!(file_ptr -> fx_file_dir_entry.fx_dir_entry_dont_use_fat & 1)) { ... }
if (media_ptr -> fx_media_FAT_type == FX_exFAT)
{
_fx_utility_exFAT_cluster_state_set(media_ptr, cluster, FX_EXFAT_BITMAP_CLUSTER_FREE);
}if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... }
#endif
media_ptr -> fx_media_available_clusters++;
#ifdef FX_ENABLE_FAULT_TOLERANT
}if (media_ptr -> fx_media_fault_tolerant_enabled == FX_FALSE) { ... }
#endif
}else { ... }
cluster = contents;
}while ((cluster >= FX_FAT_ENTRY_START) && (cluster < media_ptr -> fx_media_fat_reserved)) { ... }
if (file_ptr -> fx_file_consecutive_cluster > file_ptr -> fx_file_total_clusters)
{
file_ptr -> fx_file_consecutive_cluster = file_ptr -> fx_file_total_clusters;
}if (file_ptr -> fx_file_consecutive_cluster > file_ptr -> fx_file_total_clusters) { ... }
if (file_ptr -> fx_file_current_available_size == 0)
{
/* ... */
file_ptr -> fx_file_last_physical_cluster = 0;
file_ptr -> fx_file_first_physical_cluster = 0;
file_ptr -> fx_file_current_physical_cluster = 0;
file_ptr -> fx_file_current_logical_sector = 0;
file_ptr -> fx_file_current_relative_cluster = 0;
file_ptr -> fx_file_current_relative_sector = 0;
file_ptr -> fx_file_current_available_size = 0;
file_ptr -> fx_file_consecutive_cluster = 1;
}if (file_ptr -> fx_file_current_available_size == 0) { ... }
#ifndef FX_DONT_UPDATE_OPEN_FILES
open_count = media_ptr -> fx_media_opened_file_count;
search_ptr = media_ptr -> fx_media_opened_file_list;
while (open_count)
{
if ((search_ptr != file_ptr) &&
(search_ptr -> fx_file_dir_entry.fx_dir_entry_log_sector ==
file_ptr -> fx_file_dir_entry.fx_dir_entry_log_sector) &&
(search_ptr -> fx_file_dir_entry.fx_dir_entry_byte_offset ==
file_ptr -> fx_file_dir_entry.fx_dir_entry_byte_offset))
{
search_ptr -> fx_file_current_file_size = size;
search_ptr -> fx_file_total_clusters = file_ptr -> fx_file_total_clusters;
search_ptr -> fx_file_dir_entry.fx_dir_entry_cluster = file_ptr -> fx_file_dir_entry.fx_dir_entry_cluster;
search_ptr -> fx_file_dir_entry.fx_dir_entry_file_size = file_ptr -> fx_file_dir_entry.fx_dir_entry_file_size;
search_ptr -> fx_file_dir_entry.fx_dir_entry_log_sector = file_ptr -> fx_file_dir_entry.fx_dir_entry_log_sector;
search_ptr -> fx_file_dir_entry.fx_dir_entry_byte_offset = file_ptr -> fx_file_dir_entry.fx_dir_entry_byte_offset;
search_ptr -> fx_file_last_physical_cluster = file_ptr -> fx_file_last_physical_cluster;
search_ptr -> fx_file_first_physical_cluster = file_ptr -> fx_file_first_physical_cluster;
search_ptr -> fx_file_current_available_size = file_ptr -> fx_file_current_available_size;
search_ptr -> fx_file_consecutive_cluster = file_ptr -> fx_file_consecutive_cluster;
if (search_ptr -> fx_file_current_file_offset > size)
{
/* ... */
bytes_per_cluster = ((ULONG)media_ptr -> fx_media_bytes_per_sector) *
((ULONG)media_ptr -> fx_media_sectors_per_cluster);
/* ... */
cluster = search_ptr -> fx_file_first_physical_cluster;
bytes_remaining = size;
last_cluster = 0;
cluster_count = 0;
while ((cluster >= FX_FAT_ENTRY_START) && (cluster < media_ptr -> fx_media_fat_reserved))
{
cluster_count++;
#ifdef FX_ENABLE_EXFAT
if (file_ptr -> fx_file_dir_entry.fx_dir_entry_dont_use_fat & 1)
{
if (cluster >= file_ptr -> fx_file_last_physical_cluster)
{
contents = FX_LAST_CLUSTER_exFAT;
}if (cluster >= file_ptr -> fx_file_last_physical_cluster) { ... }
else
{
contents = cluster + 1;
}else { ... }
}if (file_ptr -> fx_file_dir_entry.fx_dir_entry_dont_use_fat & 1) { ... }
else
{
#endif
status = _fx_utility_FAT_entry_read(media_ptr, cluster, &contents);
if (status != FX_SUCCESS)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
#ifdef FX_ENABLE_EXFAT
}else { ... }
#endif
last_cluster = cluster;
cluster = contents;
if (bytes_remaining >= bytes_per_cluster)
{
bytes_remaining = bytes_remaining - bytes_per_cluster;
}if (bytes_remaining >= bytes_per_cluster) { ... }
else
{
break;
}else { ... }
}while ((cluster >= FX_FAT_ENTRY_START) && (cluster < media_ptr -> fx_media_fat_reserved)) { ... }
if (size > (((ULONG64) bytes_per_cluster) * ((ULONG64) cluster_count)))
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(FX_FILE_CORRUPT);
}if (size > (((ULONG64) bytes_per_cluster) * ((ULONG64) cluster_count))) { ... }
if (cluster_count)
{
search_ptr -> fx_file_current_physical_cluster = last_cluster;
search_ptr -> fx_file_current_relative_cluster = cluster_count - 1;
search_ptr -> fx_file_current_logical_sector = ((ULONG)media_ptr -> fx_media_data_sector_start) +
(((ULONG64)search_ptr -> fx_file_current_physical_cluster - FX_FAT_ENTRY_START) *
((ULONG)media_ptr -> fx_media_sectors_per_cluster)) +
(bytes_remaining / (ULONG)media_ptr -> fx_media_bytes_per_sector);
search_ptr -> fx_file_current_relative_sector = (UINT)((bytes_remaining / (ULONG)media_ptr -> fx_media_bytes_per_sector));
search_ptr -> fx_file_current_file_offset = size;
search_ptr -> fx_file_current_logical_offset = (ULONG)bytes_remaining % ((ULONG)media_ptr -> fx_media_bytes_per_sector);
}if (cluster_count) { ... }
else
{
search_ptr -> fx_file_current_physical_cluster = 0;
search_ptr -> fx_file_current_relative_cluster = 0;
search_ptr -> fx_file_current_logical_sector = 0;
search_ptr -> fx_file_current_relative_sector = 0;
search_ptr -> fx_file_current_file_offset = 0;
search_ptr -> fx_file_current_logical_offset = 0;
}else { ... }
}if (search_ptr -> fx_file_current_file_offset > size) { ... }
}if ((search_ptr != file_ptr) && (search_ptr -> fx_file_dir_entry.fx_dir_entry_log_sector == file_ptr -> fx_file_dir_entry.fx_dir_entry_log_sector) && (search_ptr -> fx_file_dir_entry.fx_dir_entry_byte_offset == file_ptr -> fx_file_dir_entry.fx_dir_entry_byte_offset)) { ... }
search_ptr = search_ptr -> fx_file_opened_next;
open_count--;
}while (open_count) { ... }
/* ... */#endif
#ifdef FX_FAULT_TOLERANT
status = _fx_utility_FAT_flush(media_ptr);
if (status)
{
#ifdef FX_ENABLE_FAULT_TOLERANT
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
#endif
FX_UNPROTECT
return(status);
}if (status) { ... }
#ifdef FX_ENABLE_EXFAT
if (media_ptr -> fx_media_FAT_type == FX_exFAT)
{
_fx_utility_exFAT_bitmap_flush(media_ptr);
}if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... }
/* ... */#endif
/* ... */
#endif
#ifdef FX_ENABLE_FAULT_TOLERANT
if (media_ptr -> fx_media_fault_tolerant_enabled &&
(media_ptr -> fx_media_fault_tolerant_state & FX_FAULT_TOLERANT_STATE_STARTED))
{
file_ptr -> fx_file_dir_entry.fx_dir_entry_file_size = file_ptr -> fx_file_current_file_size;
}if (media_ptr -> fx_media_fault_tolerant_enabled && (media_ptr -> fx_media_fault_tolerant_state & FX_FAULT_TOLERANT_STATE_STARTED)) { ... }
#ifdef FX_ENABLE_EXFAT
if (media_ptr -> fx_media_FAT_type == FX_exFAT)
{
status = _fx_directory_exFAT_entry_write(media_ptr, &(file_ptr -> fx_file_dir_entry), UPDATE_STREAM);
}if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... }
else
{
#endif
status = _fx_directory_entry_write(media_ptr, &(file_ptr -> fx_file_dir_entry));
#ifdef FX_ENABLE_EXFAT
}else { ... }
#endif
if (status != FX_SUCCESS)
{
FX_FAULT_TOLERANT_TRANSACTION_FAIL(media_ptr);
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
status = _fx_fault_tolerant_transaction_end(media_ptr);
if (status != FX_SUCCESS)
{
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
if (size < file_ptr -> fx_file_maximum_size_used)
{
file_ptr -> fx_file_maximum_size_used = size;
}if (size < file_ptr -> fx_file_maximum_size_used) { ... }
/* ... */#endif
FX_UNPROTECT
return(FX_SUCCESS);
}{ ... }