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
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
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#ifdef FX_ENABLE_EXFAT
#include "fx_system.h"
#include "fx_media.h"
#include "fx_utility.h"
#include "fx_directory_exFAT.h"
...
VOID _fx_utility_exFAT_size_calculate(UINT bytes_per_sector, ULONG boundary_unit, ULONG64 size_in_sectors, ULONG sectors_per_cluster,
ULONG *sectors_per_fat_ptr, ULONG *fat_offset_ptr, ULONG *cluster_heap_offset_ptr)
{
ULONG system_area_sectors = 0;
ULONG64 total_cluster_heap_sectors;
boundary_unit = ALIGN_UP(boundary_unit, 128);
while (system_area_sectors < (EXFAT_BOOT_REGION_SIZE + EXFAT_MIN_NUM_OF_RESERVED_SECTORS))
{
system_area_sectors += boundary_unit;
}while (system_area_sectors < (EXFAT_BOOT_REGION_SIZE + EXFAT_MIN_NUM_OF_RESERVED_SECTORS)) { ... }
*fat_offset_ptr = system_area_sectors;
*cluster_heap_offset_ptr = *fat_offset_ptr;
total_cluster_heap_sectors = size_in_sectors - system_area_sectors;
*sectors_per_fat_ptr = (ULONG)DIVIDE_TO_CEILING(((total_cluster_heap_sectors / sectors_per_cluster) * EXFAT_FAT_BITS),
(bytes_per_sector * BITS_PER_BYTE));
*sectors_per_fat_ptr = ALIGN_UP(*sectors_per_fat_ptr, boundary_unit >> 1);
if (system_area_sectors >
(EXFAT_BOOT_REGION_SIZE +
EXFAT_MIN_NUM_OF_RESERVED_SECTORS + *sectors_per_fat_ptr))
{
*fat_offset_ptr -= *sectors_per_fat_ptr;
}if (system_area_sectors > (EXFAT_BOOT_REGION_SIZE + EXFAT_MIN_NUM_OF_RESERVED_SECTORS + *sectors_per_fat_ptr)) { ... }
else
{
do
{
system_area_sectors = *fat_offset_ptr + *sectors_per_fat_ptr;
total_cluster_heap_sectors = size_in_sectors - system_area_sectors;
*sectors_per_fat_ptr = (ULONG)DIVIDE_TO_CEILING(((total_cluster_heap_sectors / sectors_per_cluster) * EXFAT_FAT_BITS),
(bytes_per_sector * BITS_PER_BYTE));
*sectors_per_fat_ptr = ALIGN_UP(*sectors_per_fat_ptr, boundary_unit >> 1);
*cluster_heap_offset_ptr = *fat_offset_ptr + *sectors_per_fat_ptr;
...}while (*sectors_per_fat_ptr * bytes_per_sector * BITS_PER_BYTE / EXFAT_FAT_BITS < ((size_in_sectors - *cluster_heap_offset_ptr) / sectors_per_cluster));
}else { ... }
}_fx_utility_exFAT_size_calculate (UINT bytes_per_sector, ULONG boundary_unit, ULONG64 size_in_sectors, ULONG sectors_per_cluster, ULONG *sectors_per_fat_ptr, ULONG *fat_offset_ptr, ULONG *cluster_heap_offset_ptr) { ... }
/* ... */
#endif