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
107
108
109
110
111
112
113
114
115
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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
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
290
291
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
327
333
334
335
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
368
369
370
371
372
373
374
375
...
...
...
#define FX_SOURCE_CODE
#include "fx_api.h"
#include "fx_system.h"
#include "fx_directory.h"
#include "fx_media.h"
#include "fx_utility.h"
5 includes#ifdef FX_ENABLE_EXFAT
#include "fx_directory_exFAT.h"
#endif
...
...
UINT _fx_media_volume_get_extended(FX_MEDIA *media_ptr, CHAR *volume_name, UINT volume_name_buffer_length, UINT volume_source)
{
UINT status, offset;
ULONG i;
INT j;
#ifdef FX_ENABLE_EXFAT
ULONG character_count;
#endif
FX_DIR_ENTRY dir_entry;
volume_name[0] = FX_NULL;
if (media_ptr -> fx_media_id != FX_MEDIA_ID)
{
return(FX_MEDIA_NOT_OPEN);
}if (media_ptr -> fx_media_id != FX_MEDIA_ID) { ... }
FX_TRACE_IN_LINE_INSERT(FX_TRACE_MEDIA_VOLUME_GET, media_ptr, volume_name, volume_source, 0, FX_TRACE_MEDIA_EVENTS, 0, 0)
FX_PROTECT
#ifdef FX_ENABLE_EXFAT
if (media_ptr -> fx_media_FAT_type == FX_exFAT)
{
volume_source = FX_DIRECTORY_SECTOR;
}if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... }
/* ... */#endif
volume_name[0] = FX_NULL;
if (volume_source == FX_DIRECTORY_SECTOR)
{
dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer;
dir_entry.fx_dir_entry_short_name[0] = 0;
i = 0;
do
{
status = _fx_directory_entry_read(media_ptr, FX_NULL, &i, &dir_entry);
if (status != FX_SUCCESS)
{
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
#ifdef FX_ENABLE_EXFAT
if (dir_entry.fx_dir_entry_attributes & FX_VOLUME || dir_entry.fx_dir_entry_type == FX_EXFAT_DIR_ENTRY_TYPE_VOLUME_LABEL)
#else
if (dir_entry.fx_dir_entry_attributes & FX_VOLUME)
#endif
{
break;
...}
i++;
...} while (i < media_ptr -> fx_media_root_directory_entries);
if (i < media_ptr -> fx_media_root_directory_entries)
{
status = _fx_utility_logical_sector_read(media_ptr, (ULONG64) dir_entry.fx_dir_entry_log_sector,
media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_DIRECTORY_SECTOR);
if (status != FX_SUCCESS)
{
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
offset = dir_entry.fx_dir_entry_byte_offset;
#ifdef FX_ENABLE_EXFAT
if (media_ptr -> fx_media_FAT_type == FX_exFAT)
{
character_count = media_ptr -> fx_media_memory_buffer[offset + FX_EXFAT_CHAR_COUNT];
if (character_count >= volume_name_buffer_length)
{
status = FX_BUFFER_ERROR;
character_count = volume_name_buffer_length - 1;
}if (character_count >= volume_name_buffer_length) { ... }
offset += FX_EXFAT_VOLUME_LABEL;
for (i = 0; i < character_count; i++)
{
volume_name[i] = (CHAR)_fx_utility_16_unsigned_read(&media_ptr -> fx_media_memory_buffer[offset]);
offset += 2;
}for (i = 0; i < character_count; i++) { ... }
volume_name[i] = FX_NULL;
}if (media_ptr -> fx_media_FAT_type == FX_exFAT) { ... }
else
{
#endif
for (j = 10; j >= 0; j--)
{
if (media_ptr -> fx_media_memory_buffer[offset + (UINT)j] != (UCHAR)' ')
{
break;
}if (media_ptr -> fx_media_memory_buffer[offset + (UINT)j] != (UCHAR)' ') { ... }
}for (j = 10; j >= 0; j--) { ... }
if (j >= (INT)volume_name_buffer_length - 1)
{
status = FX_BUFFER_ERROR;
j = (INT)volume_name_buffer_length - 2;
}if (j >= (INT)volume_name_buffer_length - 1) { ... }
volume_name[j + 1] = FX_NULL;
for (; j >= 0; j--)
{
volume_name[j] = (CHAR)media_ptr -> fx_media_memory_buffer[offset + (UINT)j];
}for (; j >= 0; j--) { ... }
#ifdef FX_ENABLE_EXFAT
}else { ... }
#endif
FX_UNPROTECT
return(status);
}if (i < media_ptr -> fx_media_root_directory_entries) { ... }
}if (volume_source == FX_DIRECTORY_SECTOR) { ... }
status = _fx_utility_logical_sector_read(media_ptr, ((ULONG64) 0),
media_ptr -> fx_media_memory_buffer, ((ULONG) 1), FX_DATA_SECTOR);
if (status != FX_SUCCESS)
{
FX_UNPROTECT
return(status);
}if (status != FX_SUCCESS) { ... }
#ifndef FX_MEDIA_STATISTICS_DISABLE
media_ptr -> fx_media_driver_boot_read_requests++;/* ... */
#endif
media_ptr -> fx_media_driver_request = FX_DRIVER_BOOT_READ;
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
media_ptr -> fx_media_driver_buffer = media_ptr -> fx_media_memory_buffer;
media_ptr -> fx_media_driver_sectors = 1;
media_ptr -> fx_media_driver_sector_type = FX_BOOT_SECTOR;
FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_IO_DRIVER_BOOT_READ, media_ptr, media_ptr -> fx_media_memory_buffer, 0, 0, FX_TRACE_INTERNAL_EVENTS, 0, 0)
(media_ptr -> fx_media_driver_entry) (media_ptr);
if (media_ptr -> fx_media_driver_status)
{
FX_UNPROTECT
return(media_ptr -> fx_media_driver_status);
}if (media_ptr -> fx_media_driver_status) { ... }
if (media_ptr -> fx_media_32_bit_FAT)
{
offset = FX_VOLUME_LABEL_32;
}if (media_ptr -> fx_media_32_bit_FAT) { ... }
else
{
offset = FX_VOLUME_LABEL;
}else { ... }
for (j = 10; j >= 0; j--)
{
if (media_ptr -> fx_media_memory_buffer[offset + (UINT)j] != (UCHAR)' ')
{
break;
}if (media_ptr -> fx_media_memory_buffer[offset + (UINT)j] != (UCHAR)' ') { ... }
}for (j = 10; j >= 0; j--) { ... }
if (j >= (INT)volume_name_buffer_length - 1)
{
status = FX_BUFFER_ERROR;
j = (INT)volume_name_buffer_length - 2;
}if (j >= (INT)volume_name_buffer_length - 1) { ... }
volume_name[j + 1] = FX_NULL;
for (; j >= 0; j--)
{
volume_name[j] = (CHAR)media_ptr -> fx_media_memory_buffer[offset + (UINT)j];
}for (; j >= 0; j--) { ... }
FX_UNPROTECT
return(status);
}{ ... }