-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfatimg_wcx.cpp
More file actions
2660 lines (2351 loc) · 92.4 KB
/
fatimg_wcx.cpp
File metadata and controls
2660 lines (2351 loc) · 92.4 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
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
290
291
292
293
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
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
354
355
356
357
358
359
360
361
362
363
364
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
401
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
465
466
467
468
469
470
471
472
473
474
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
577
578
579
580
581
582
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
635
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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
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
815
816
817
818
819
820
821
822
823
824
825
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
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
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
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
/*
* Floppy disk images unpack plugin for the Total Commander.
* Copyright (c) 2002, IvGzury ( ivgzury@hotmail.com )
* Copyright (c) 2025, Nataliia Sydor aka NataMontari ( natalya.sydor@gmail.com )
* Copyright (c) 2022-2026, Oleg Farenyuk aka Indrekis ( indrekis@gmail.com )
*
* Oleg Farenyuk's code is released under the MIT License.
*
* Original IvGzury copyright message:
* This program is absolutely free software.
* If you have any remarks or problems, please don't
* hesitate to send me an email.
*/
#include "sysio_winapi.h"
#include "minimal_fixed_string.h"
#include "FAT_definitions.h"
#include "plugin_config.h"
#include "wcxhead.h"
#include <new>
#include <memory>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <optional>
#include <map>
//#include <atomic>
#include <cassert>
#include <sys/stat.h>
#include <sys/types.h>
// #define FLTK_ENABLED_EXPERIMENTAL // Here for the quick tests -- should be defined by the build system
#ifdef FLTK_ENABLED_EXPERIMENTAL
#include <dirent.h>
#include <FL/Fl.H>
#define __MINGW32__ // Dirty hack! Disables conflicting dirent definition for the Fl_Help_View.
// It do could break something, because of the ABI change, but, at last,
// in this header there no other __MINGW32__ usages.
#include <FL/filename.H>
#undef __MINGW32__
#include <FL/Fl_Window.H>
#include <FL/Fl_Choice.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <FL/fl_ask.H>
#include <FL/names.h> // for fl_xid?
#include <FL/x.H> // for fl_xid
#include <FL/Fl_Round_Button.H>
#include <FL/Fl_Spinner.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Check_Button.H>
#include <FL/Fl_Help_View.H>
#include <FL/Fl_File_Input.H>
#include <FL/Fl_File_Chooser.H>
#endif
extern "C" {
#include "ff.h"
#include "diskio.h"
}
using std::nothrow, std::uint8_t;
#ifdef _WIN32
#define WCX_PLUGIN_EXPORTS
#endif
#ifdef WCX_PLUGIN_EXPORTS
#define DLLEXPORT __declspec(dllexport)
#define STDCALL __stdcall
//! Not enough for the Win32 -- exports would be decorated by: _name@XX.
//! This can help but reverting to the def-file is simpler:
//! #pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
#else
#define WCX_API
#define STDCALL
#endif
// The DLL entry point
BOOL APIENTRY DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
) {
#if 0
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
#endif
return TRUE;
}
bool set_file_attributes_ex(const char* filename, FAT_attrib_t attribute) {
/*
DWORD winattr = FILE_ATTRIBUTE_NORMAL;
if (attribute.is_readonly()) winattr |= FILE_ATTRIBUTE_READONLY;
if (attribute.is_archive() ) winattr |= FILE_ATTRIBUTE_ARCHIVE;
if (attribute.is_hidden() ) winattr |= FILE_ATTRIBUTE_HIDDEN;
if (attribute.is_system() ) winattr |= FILE_ATTRIBUTE_SYSTEM;
*/
return set_file_attributes(filename, attribute.get_user_attr()); // Codes are equal
}
struct arc_dir_entry_t
{
minimal_fixed_string_t<MAX_PATH> PathName;
size_t FileSize = 0;
uint32_t FileTime = 0;
FAT_attrib_t FileAttr{};
uint32_t FirstClus = 0;
};
plugin_config_t plugin_config;
std::mutex plugin_config_inuse; // When it is a member of the plugin_config_t, it precludes copy and move operations, so, as QnD solution, it is a global variable
//! Contains archive configuration, so FAT_image_t needs it
struct whole_disk_t;
struct FAT_image_t
{
enum FAT_types { unknown_FS_type, FAT12_type, FAT16_type, FAT32_type, exFAT_type}; // , FAT_DOS100_type, FAT_DOS110_type
const whole_disk_t* whole_disk_ptr = nullptr;
size_t boot_sector_offset = 0;
bool is_processed_m = false; // Useful when unknown FS or empty FAT FS
FAT_types FAT_type = unknown_FS_type;
bool has_OS2_EA = false;
std::vector<uint8_t> fattable;
std::vector<arc_dir_entry_t> arc_dir_entries;
FAT_boot_sector_t bootsec{};
size_t FAT1area_off_m = 0; //number of uint8_t before first FAT area
size_t rootarea_off_m = 0; //number of uint8_t before root area
size_t dataarea_off_m = 0; //number of uint8_t before data area
uint32_t cluster_size_m = 0;
uint32_t counter = 0;
FAT_image_t(const FAT_image_t&) = default;
FAT_image_t& operator=(const FAT_image_t&) = default;
FAT_image_t(const whole_disk_t* ptr) : whole_disk_ptr(ptr)
{
}
~FAT_image_t() = default;
void set_boot_sector_offset(size_t off) {
boot_sector_offset = off;
}
size_t get_boot_sector_offset() const {
return boot_sector_offset;
}
size_t cluster_to_image_off(uint32_t cluster) {
return get_data_area_offset() + static_cast<size_t>(cluster - 2) * get_cluster_size(); //-V104
}
uint32_t get_sectors_per_FAT() const {
if (bootsec.BPB_SectorsPerFAT != 0) {
return bootsec.BPB_SectorsPerFAT;
}
else { // Possibly -- FAT32
return bootsec.EBPB_FAT32.BS_SectorsPerFAT32;
}
}
size_t get_bytes_per_FAT() const;
uint32_t get_root_dir_entry_count() const {
// MS-DOS supports 240 max for FDD and 512 for HDD
return bootsec.BPB_RootEntCnt;
}
size_t get_root_dir_size() const {
return get_data_area_offset() - get_root_area_offset(); //-V110
}
size_t get_FAT1_area_offset() const {
return FAT1area_off_m;
}
size_t get_root_area_offset() const {
return rootarea_off_m;
}
size_t get_data_area_offset() const {
return dataarea_off_m;
}
uint32_t get_cluster_size() const {
return cluster_size_m;
}
size_t get_sector_size() const;
auto get_openmode() const;
size_t get_image_file_size() const;
file_handle_t get_archive_handler() const;
uint64_t get_total_sectors_in_volume() const;
uint64_t get_data_sectors_in_volume() const;
uint64_t get_data_clusters_in_volume() const;
bool is_processed() const {
if (arc_dir_entries.empty())
return is_processed_m;
else
return counter == arc_dir_entries.size(); //-V104
}
void set_processed_for_empty() {
is_processed_m = true;
}
int process_bootsector(bool read_bootsec);
int process_DOS1xx_image();
int search_for_bootsector();
int load_FAT();
FAT_types detect_FAT_type() const;
bool is_known_FS_type() const {
return FAT_type == FAT12_type || FAT_type == FAT16_type || FAT_type == FAT32_type;
}
int extract_to_file(file_handle_t hUnpFile, uint32_t idx);
// root passed by copy to avoid problems while relocating vector
int load_file_list_recursively(minimal_fixed_string_t<MAX_PATH> root, uint32_t firstclus, uint32_t depth); //-V813
uint32_t get_first_cluster(const FATxx_dir_entry_t& dir_entry) const;
uint32_t next_cluster_FAT12(uint32_t firstclus) const;
uint32_t next_cluster_FAT16(uint32_t firstclus) const;
uint32_t next_cluster_FAT32(uint32_t firstclus) const;
uint32_t next_cluster_FAT(uint32_t firstclus) const;
uint32_t max_cluster_FAT(FAT_types type) const; // For FAT detect
uint32_t max_cluster_FAT() const;
uint32_t max_normal_cluster_FAT(FAT_types type) const;
uint32_t max_normal_cluster_FAT() const;
uint32_t min_end_of_chain_FAT() const;
bool is_end_of_chain_FAT(uint32_t) const;
struct LFN_accumulator_t {
minimal_fixed_string_t<MAX_PATH> cur_LFN_name{};
uint8_t cur_LFN_CRC = 0;
int cur_LFN_record_index = 0;
void start_processing(const VFAT_LFN_dir_entry_t* LFN_record) {
cur_LFN_CRC = LFN_record->LFN_DOS_name_CRC;
cur_LFN_record_index = 1;
cur_LFN_name.clear();
LFN_record->dir_LFN_entry_to_ASCII_str(cur_LFN_name);
}
void append_LFN_part(const VFAT_LFN_dir_entry_t* LFN_record) {
++cur_LFN_record_index;
minimal_fixed_string_t<MAX_PATH> next_LFN_part;
LFN_record->dir_LFN_entry_to_ASCII_str(next_LFN_part);
next_LFN_part.push_back(cur_LFN_name);
cur_LFN_name = next_LFN_part;
}
void abort_processing() {
cur_LFN_CRC = 0;
cur_LFN_record_index = 0;
cur_LFN_name.clear();
}
bool are_processing() {
return cur_LFN_record_index > 0;
}
void process_LFN_record(const FATxx_dir_entry_t* entry);
};
};
struct partition_info_t {
uint32_t first_sector = 0;
uint32_t last_sector = 0;
uint8_t partition_id = 0;
};
struct whole_disk_t {
static constexpr uint32_t sector_size = 512;
minimal_fixed_string_t<MAX_PATH> archname; // Should be saved for the TCmd API
file_handle_t hArchFile = file_handle_t(); //opened file handles
int openmode_m = PK_OM_LIST;
size_t image_file_size = 0;
static tChangeVolProc pLocChangeVol;
static tProcessDataProc pLocProcessData;
whole_disk_t(const char* archname_in, size_t vol_size, file_handle_t fh, int openmode):
hArchFile{ fh }, openmode_m(openmode), image_file_size(vol_size)
{
archname.push_back(archname_in);
// First disk represents also non-partitioned image -- so, initially, it's size = whole image size.
disks.emplace_back(this);
}
// Note that disks, partition_info, mbrs are not synchronized.
std::vector<FAT_image_t> disks;
std::vector<MBR_t> mbrs{ 1 };
std::vector<partition_info_t> partition_info;
uint32_t disc_counter = 0;
int detect_MBR();
int process_MBR();
int detect_GPT();
static minimal_fixed_string_t<MAX_PATH> get_disk_prefix(uint32_t idx) {
minimal_fixed_string_t<MAX_PATH> res{ "C\\" };
if (idx > 'Z' - 'C') { // Quick and dirty
res[1] = 'P';
while (idx != 0) {
res.push_back( static_cast<char>(idx % 10 + '0') );
idx /= 10;
}
res.push_back('\\');
}
else {
res[0] += idx;
}
return res;
}
~whole_disk_t() {
if (hArchFile)
close_file(hArchFile);
}
//! Process boot record if it is a single-disk volume or process all known volumes from the MBR
int process_volumes();
//! Error handler for safe functions:
_invalid_parameter_handler oldHandler = nullptr;
};
tChangeVolProc whole_disk_t::pLocChangeVol = nullptr;
tProcessDataProc whole_disk_t::pLocProcessData = nullptr;
//------- FAT_image_t implementation -----------------------------
// Though using methods of the whole_disk_t would be more OOP-style, code verbosity becomes too large for me (Indrekis)
size_t FAT_image_t::get_sector_size() const {
return whole_disk_ptr->sector_size; //-V109
}
size_t FAT_image_t::get_bytes_per_FAT() const {
return get_sectors_per_FAT() * get_sector_size(); //-V104 //-V109
}
auto FAT_image_t::get_openmode() const {
return whole_disk_ptr->openmode_m;
}
file_handle_t FAT_image_t::get_archive_handler() const {
return whole_disk_ptr->hArchFile;
}
size_t FAT_image_t::get_image_file_size() const {
return whole_disk_ptr->image_file_size;
}
int FAT_image_t::process_bootsector(bool read_bootsec) {
if(read_bootsec){
set_file_pointer(get_archive_handler(), boot_sector_offset);
auto result = read_file(get_archive_handler(), &bootsec, get_sector_size());
if (result != get_sector_size()) {
return E_EREAD;
}
}
// if read_bootsec == false -- user preread bootsector
if (bootsec.BPB_bytesPerSec != get_sector_size()) {
return E_UNKNOWN_FORMAT;
}
if (bootsec.signature != 0xAA55) {
plugin_config.log_print_dbg("Warning# Wrong boot signature: 0x%04X", bootsec.signature);
if (!plugin_config.ignore_boot_signature) {
if (plugin_config.allow_dialogs) {
#ifdef FLTK_ENABLED_EXPERIMENTAL
if (get_openmode() == PK_OM_LIST) {
auto res = fl_choice("Wrong boot signature: %04x", "Stop", "OK", "Try MBR", bootsec.signature);
//! Conf would be re-read for the new image
switch (res) {
case 0: // Left btn -- Stop
plugin_config.process_DOS1xx_images = false;
plugin_config.search_for_boot_sector = false;
plugin_config.process_MBR = false;
return E_BAD_ARCHIVE;
break;
case 1: // Middle btn -- OK (default)
break;
case 2: // Right button -- Try MBR (only -- skip DOS1.xx and do not search for bootsector)
plugin_config.process_DOS1xx_images = false;
plugin_config.search_for_boot_sector = false;
return E_BAD_ARCHIVE;
break;
default:;
}
// int res = whole_disk_ptr->on_bad_BPB_callback(this);
}
#endif
}
else {
return E_BAD_ARCHIVE;
}
}
}
cluster_size_m = static_cast<uint32_t>(get_sector_size() * bootsec.BPB_SecPerClus);
FAT1area_off_m = get_boot_sector_offset() + get_sector_size() * bootsec.BPB_RsvdSecCnt;
rootarea_off_m = get_boot_sector_offset() + get_sector_size() * (bootsec.BPB_RsvdSecCnt +
get_sectors_per_FAT() * static_cast<size_t>(bootsec.BPB_NumFATs)); //-V104
dataarea_off_m = get_root_area_offset() + get_root_dir_entry_count() * sizeof(FATxx_dir_entry_t);
plugin_config.log_print("Info# -- Processing bootsector -- ");
plugin_config.log_print("Info# Bytes per sector: %d", bootsec.BPB_bytesPerSec);
plugin_config.log_print("Info# Sectors per cluster: %d", static_cast<int>(bootsec.BPB_SecPerClus));
plugin_config.log_print("Info# Reserved sectors: %d", bootsec.BPB_RsvdSecCnt);
plugin_config.log_print("Info# Number of FATs: %d", static_cast<int>(bootsec.BPB_NumFATs));
plugin_config.log_print("Info# Root entries count: %d", bootsec.BPB_RootEntCnt);
plugin_config.log_print("Info# Total sectors 16-bit: %d", bootsec.BPB_TotSec16);
plugin_config.log_print("Info# Media descriptor: %d", static_cast<int>(bootsec.BPB_MediaDescr));
plugin_config.log_print("Info# Sectors per FAT: %d", bootsec.BPB_SectorsPerFAT);
plugin_config.log_print("Info# Sectors per track: %d", bootsec.BPB_SecPerTrk);
plugin_config.log_print("Info# Heads: %d", bootsec.BPB_NumHeads);
plugin_config.log_print("Info# Bytes in cluster: %d", cluster_size_m);
plugin_config.log_print("Info# FAT1 area offset: 0x%010X", FAT1area_off_m);
plugin_config.log_print("Info# Root area offset: 0x%010X", rootarea_off_m);
plugin_config.log_print("Info# Data area offset: 0x%010X", dataarea_off_m);
plugin_config.log_print("Info# --------- ");
FAT_type = detect_FAT_type();
switch (FAT_type) {
case FAT12_type:
plugin_config.log_print("Info# Preliminary FAT type: FAT12");
if ((get_sectors_per_FAT() < 1) || (get_sectors_per_FAT() > 12)) {
return E_UNKNOWN_FORMAT;
}
break;
case FAT16_type:
plugin_config.log_print("Info# Preliminary FAT type: FAT16");
if ((get_sectors_per_FAT() < 1) || (get_sectors_per_FAT() > 256)) { // get_sectors_per_FAT() < 16 according to standard
return E_UNKNOWN_FORMAT;
}
break;
case FAT32_type:
plugin_config.log_print("Info# Preliminary FAT type: FAT32");
if ((get_sectors_per_FAT() < 1) || (get_sectors_per_FAT() > 2'097'152)) { // get_sectors_per_FAT() < 512 according to standard
return E_UNKNOWN_FORMAT;
}
// There should not be those values in correct FAT32
if (bootsec.EBPB_FAT.BS_BootSig == 0x29 || bootsec.EBPB_FAT.BS_BootSig == 0x28) {
return E_UNKNOWN_FORMAT;
}
// TODO: Support other active FAT tables:
if (!(bootsec.EBPB_FAT32.is_FAT_mirrored() || bootsec.EBPB_FAT32.get_active_FAT() == 0)) {
return E_UNKNOWN_FORMAT; // Not yet implemented;
}
break;
case exFAT_type:
plugin_config.log_print_dbg("Warning# Preliminary FAT type: exFAT. Skipping.");
break;
case unknown_FS_type:
plugin_config.log_print_dbg("Warning# Filesystem type unknown. Skipping.");
return E_UNKNOWN_FORMAT;
default:
plugin_config.log_print_dbg("Warning# Filesystem type unknown. Skipping.");
//! Here also unsupported (yet) formats like exFAT
return E_UNKNOWN_FORMAT;
}
if (FAT_type == FAT32_type) {
plugin_config.log_print("Info# FAT32 hidden sectors: %d", bootsec.EBPB_FAT32.BPB_HiddSec);
plugin_config.log_print("Info# FAT32 total sectors 32-bit: %d", bootsec.EBPB_FAT32.BPB_TotSec32);
plugin_config.log_print("Info# FAT32 sectors per FAT: %d", bootsec.EBPB_FAT32.BS_SectorsPerFAT32);
plugin_config.log_print("Info# FAT32 FAT mirroring: %d", bootsec.EBPB_FAT32.is_FAT_mirrored());
if (!bootsec.EBPB_FAT32.is_FAT_mirrored()) {
plugin_config.log_print("Info# FAT32 active FAT: %d", bootsec.EBPB_FAT32.get_active_FAT());
}
plugin_config.log_print("Info# FAT32 Information Sector: %d", bootsec.EBPB_FAT32.BS_FSInfoSec);
plugin_config.log_print("Info# FAT32 backup of boot sector: %d", bootsec.EBPB_FAT32.BS_KbpBootSec);
plugin_config.log_print("Info# FAT32 Volume ID: 0x%010X", bootsec.EBPB_FAT32.BS_VolID);
char vol_label[12];
bootsec.EBPB_FAT32.get_volume_label(vol_label);
plugin_config.log_print("Info# FAT32 Volume label: %s", vol_label);
}
return 0;
}
//! Used for reading DOS 1.xx images as a bootsector template. Taken from the IBM PC-DOS 2.00 (5.25) Disk01.img
//! See also https://github.com/microsoft/MS-DOS
static uint8_t raw_DOS200_bootsector[] = {
0xEB, 0x2C, 0x90, 0x49, 0x42, 0x4D, 0x20, 0x20, 0x32, 0x2E, 0x30, 0x00,
0x02, 0x01, 0x01, 0x00, 0x02, 0x40, 0x00, 0x68, 0x01, 0xFC, 0x02, 0x00,
0x09, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xDF, 0x02, 0x25,
0x02, 0x09, 0x2A, 0xFF, 0x50, 0xF6, 0x00, 0x02, 0xCD, 0x19, 0xFA, 0x33,
0xC0, 0x8E, 0xD0, 0xBC, 0x00, 0x7C, 0x8E, 0xD8, 0xA3, 0x7A, 0x00, 0xC7,
0x06, 0x78, 0x00, 0x21, 0x7C, 0xFB, 0xCD, 0x13, 0x73, 0x03, 0xE9, 0x95,
0x00, 0x0E, 0x1F, 0xA0, 0x10, 0x7C, 0x98, 0xF7, 0x26, 0x16, 0x7C, 0x03,
0x06, 0x1C, 0x7C, 0x03, 0x06, 0x0E, 0x7C, 0xA3, 0x03, 0x7C, 0xA3, 0x13,
0x7C, 0xB8, 0x20, 0x00, 0xF7, 0x26, 0x11, 0x7C, 0x05, 0xFF, 0x01, 0xBB,
0x00, 0x02, 0xF7, 0xF3, 0x01, 0x06, 0x13, 0x7C, 0xE8, 0x7E, 0x00, 0x72,
0xB3, 0xA1, 0x13, 0x7C, 0xA3, 0x7E, 0x7D, 0xB8, 0x70, 0x00, 0x8E, 0xC0,
0x8E, 0xD8, 0xBB, 0x00, 0x00, 0x2E, 0xA1, 0x13, 0x7C, 0xE8, 0xB6, 0x00,
0x2E, 0xA0, 0x18, 0x7C, 0x2E, 0x2A, 0x06, 0x15, 0x7C, 0xFE, 0xC0, 0x32,
0xE4, 0x50, 0xB4, 0x02, 0xE8, 0xC1, 0x00, 0x58, 0x72, 0x38, 0x2E, 0x28,
0x06, 0x20, 0x7C, 0x76, 0x0E, 0x2E, 0x01, 0x06, 0x13, 0x7C, 0x2E, 0xF7,
0x26, 0x0B, 0x7C, 0x03, 0xD8, 0xEB, 0xCE, 0x0E, 0x1F, 0xCD, 0x11, 0xD0,
0xC0, 0xD0, 0xC0, 0x25, 0x03, 0x00, 0x75, 0x01, 0x40, 0x40, 0x8B, 0xC8,
0xF6, 0x06, 0x1E, 0x7C, 0x80, 0x75, 0x02, 0x33, 0xC0, 0x8B, 0x1E, 0x7E,
0x7D, 0xEA, 0x00, 0x00, 0x70, 0x00, 0xBE, 0xC9, 0x7D, 0xE8, 0x02, 0x00,
0xEB, 0xFE, 0x2E, 0xAC, 0x24, 0x7F, 0x74, 0x4D, 0xB4, 0x0E, 0xBB, 0x07,
0x00, 0xCD, 0x10, 0xEB, 0xF1, 0xB8, 0x50, 0x00, 0x8E, 0xC0, 0x0E, 0x1F,
0x2E, 0xA1, 0x03, 0x7C, 0xE8, 0x43, 0x00, 0xBB, 0x00, 0x00, 0xB8, 0x01,
0x02, 0xE8, 0x58, 0x00, 0x72, 0x2C, 0x33, 0xFF, 0xB9, 0x0B, 0x00, 0x26,
0x80, 0x0D, 0x20, 0x26, 0x80, 0x4D, 0x20, 0x20, 0x47, 0xE2, 0xF4, 0x33,
0xFF, 0xBE, 0xDF, 0x7D, 0xB9, 0x0B, 0x00, 0xFC, 0xF3, 0xA6, 0x75, 0x0E,
0xBF, 0x20, 0x00, 0xBE, 0xEB, 0x7D, 0xB9, 0x0B, 0x00, 0xF3, 0xA6, 0x75,
0x01, 0xC3, 0xBE, 0x80, 0x7D, 0xE8, 0xA6, 0xFF, 0xB4, 0x00, 0xCD, 0x16,
0xF9, 0xC3, 0x1E, 0x0E, 0x1F, 0x33, 0xD2, 0xF7, 0x36, 0x18, 0x7C, 0xFE,
0xC2, 0x88, 0x16, 0x15, 0x7C, 0x33, 0xD2, 0xF7, 0x36, 0x1A, 0x7C, 0x88,
0x16, 0x1F, 0x7C, 0xA3, 0x08, 0x7C, 0x1F, 0xC3, 0x2E, 0x8B, 0x16, 0x08,
0x7C, 0xB1, 0x06, 0xD2, 0xE6, 0x2E, 0x0A, 0x36, 0x15, 0x7C, 0x8B, 0xCA,
0x86, 0xE9, 0x2E, 0x8B, 0x16, 0x1E, 0x7C, 0xCD, 0x13, 0xC3, 0x00, 0x00,
0x0D, 0x0A, 0x4E, 0x6F, 0x6E, 0x2D, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D,
0x20, 0x64, 0x69, 0x73, 0x6B, 0x20, 0x6F, 0x72, 0x20, 0x64, 0x69, 0x73,
0x6B, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x0D, 0x0A, 0x52, 0x65, 0x70,
0x6C, 0x61, 0x63, 0x65, 0x20, 0x61, 0x6E, 0x64, 0x20, 0x73, 0x74, 0x72,
0x69, 0x6B, 0x65, 0x20, 0x61, 0x6E, 0x79, 0x20, 0x6B, 0x65, 0x79, 0x20,
0x77, 0x68, 0x65, 0x6E, 0x20, 0x72, 0x65, 0x61, 0x64, 0x79, 0x0D, 0x0A,
0x00, 0x0D, 0x0A, 0x44, 0x69, 0x73, 0x6B, 0x20, 0x42, 0x6F, 0x6F, 0x74,
0x20, 0x66, 0x61, 0x69, 0x6C, 0x75, 0x72, 0x65, 0x0D, 0x0A, 0x00, 0x69,
0x62, 0x6D, 0x62, 0x69, 0x6F, 0x20, 0x20, 0x63, 0x6F, 0x6D, 0x30, 0x69,
0x62, 0x6D, 0x64, 0x6F, 0x73, 0x20, 0x20, 0x63, 0x6F, 0x6D, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xAA
};
int FAT_image_t::process_DOS1xx_image() {
//! DOS 1.xx disks do not contain BPB so any detection would be a heuristic.
//! But the limited number of image types helps a little
//! So we test media byte and image size. If it looks OK -- recreate BPB and
//! call process_bootsector().
//! 8" disks are not yes supported -- they need 128 bytes sectors,
//! though there are no fundamental problems.
//! One possible source of problems, citing wiki: "Microsoft recommends to distinguish between
//! the two 8-inch formats for FAT ID 0xFE by trying to read of a single-density address mark.
//! If this results in an error, the medium must be double-density."
//! https://jeffpar.github.io/kbarchive/kb/075/Q75131/ -- "Q75131: Standard Floppy Disk Formats Supported by MS-DOS"
//!
//! Examples of 8" images: https://winworldpc.com/product/ms-dos/1x and https://winworldpc.com/product/86-dos/100
//! https://en.wikipedia.org/wiki/Comparison_of_DOS_operating_systems -- 8" FDD for DOS 1.xx formats
//! DOS 1.10 boot sector: https://thestarman.pcministry.com/DOS/ibm110/Boot.htm
//!
//! TODO: DOS 2.0 - DOS 3.2 sometimes wrote wrong BPB. For non DOS 1.xx images -- add check of the media ID
//! http://www.os2museum.com/wp/dos-boot-sector-bpb-and-the-media-descriptor-byte/ -- describes possible heuristics
//! d
uint8_t media_descr = 0;
// Using get_boot_sector_offset() is questionable here -- partitions should have BPB, but it does not harm.
auto res = set_file_pointer( get_archive_handler(), get_boot_sector_offset() + get_sector_size() );
if (!res) {
return E_EREAD;
}
auto rdres = read_file(get_archive_handler(), &media_descr, 1);
if (rdres != 1) {
return E_EREAD;
}
memcpy_s(&bootsec, get_sector_size(), raw_DOS200_bootsector, sizeof(raw_DOS200_bootsector));
switch (media_descr) {
case 0xFE: // 5.25" 160Kb/163'840b img; H:C:S = 1:40:8, DOS 1.00
if (get_image_file_size() != 160 * 1024) {
return E_UNKNOWN_FORMAT;
}
plugin_config.log_print("Info# DOS 1.00 image -- 160Kb");
bootsec.BPB_SecPerClus = 1;
bootsec.BPB_RsvdSecCnt = 1;
bootsec.BPB_NumFATs = 2;
bootsec.BPB_RootEntCnt = static_cast<uint16_t>((get_sector_size()/sizeof(FATxx_dir_entry_t)) * 4); // 4 sectors in root dir
bootsec.BPB_TotSec16 = 320;
bootsec.BPB_MediaDescr = 0xFE;
bootsec.BPB_SectorsPerFAT = 1;
// Free sectors = 313
// Hidden sectors = 0
break;
case 0xFC: // 5.25" 180Kb/184'320b img; H:C:S = 1:40:9, DOS 2.00
if (get_image_file_size() != 180 * 1024) {
return E_UNKNOWN_FORMAT;
}
plugin_config.log_print("Info# DOS 2.00 image -- 180Kb");
bootsec.BPB_SecPerClus = 1;
bootsec.BPB_RsvdSecCnt = 1;
bootsec.BPB_NumFATs = 2;
bootsec.BPB_RootEntCnt = static_cast<uint16_t>((get_sector_size() / sizeof(FATxx_dir_entry_t)) * 4); // 4 sectors in root dir
bootsec.BPB_TotSec16 = 360;
bootsec.BPB_MediaDescr = 0xFC;
bootsec.BPB_SectorsPerFAT = 2;
// Free sectors = 351
// Hidden sectors = 0
break;
case 0xFF: // 5.25" 320Kb/327'680b img; H:C:S = 2:40:8, DOS 1.10
if (get_image_file_size() != 320 * 1024) {
if (plugin_config.process_DOS1xx_exceptions) { // 331792
plugin_config.log_print("Info# Processing DOS 1.xx exceptions");
if (get_image_file_size() != 331'792) {
//! Exception for the "MS-DOS 1.12.ver.1.12 OEM [Compaq]" image, containing
//! 4112 bytes at the end, bracketed by "Skip 8 blocks " text.
return E_UNKNOWN_FORMAT;
}
}
else {
return E_UNKNOWN_FORMAT;
}
}
plugin_config.log_print("Info# DOS 1.10 image -- 320Kb");
bootsec.BPB_SecPerClus = 2;
bootsec.BPB_RsvdSecCnt = 1;
bootsec.BPB_NumFATs = 2;
bootsec.BPB_RootEntCnt = static_cast<uint16_t>((get_sector_size() / sizeof(FATxx_dir_entry_t)) * 7); // 7 sectors in root dir
bootsec.BPB_TotSec16 = 640;
bootsec.BPB_MediaDescr = 0xFF;
bootsec.BPB_SectorsPerFAT = 1;
// Free sectors = 630
// Hidden sectors = 0
break;
case 0xFD: // 5.25" 360Kb/368'640b img; H:C:S = 2:40:8, DOS 1.10
if (get_image_file_size() != 360 * 1024) {
return E_UNKNOWN_FORMAT;
}
plugin_config.log_print("Info# DOS 1.10 image -- 360Kb");
bootsec.BPB_SecPerClus = 2;
bootsec.BPB_RsvdSecCnt = 1;
bootsec.BPB_NumFATs = 2;
bootsec.BPB_RootEntCnt = static_cast<uint16_t>((get_sector_size() / sizeof(FATxx_dir_entry_t)) * 7); // 7 sectors in root dir
bootsec.BPB_TotSec16 = 720;
bootsec.BPB_MediaDescr = 0xFD;
bootsec.BPB_SectorsPerFAT = 2;
// Free sectors = 708
// Hidden sectors = 0
break;
default:
return E_UNKNOWN_FORMAT;
}
return process_bootsector(false);
}
int FAT_image_t::load_FAT() {
const size_t fat_size_bytes = get_bytes_per_FAT();
try {
fattable.reserve(fat_size_bytes); // To minimize overcommit
fattable.resize(fat_size_bytes);
}
catch (std::exception&) { // std::length_error, std::bad_alloc, other can be used by custom allocators
return E_NO_MEMORY;
}
// Read FAT table
set_file_pointer(get_archive_handler(), get_FAT1_area_offset());
auto result = read_file(get_archive_handler(), fattable.data(), fat_size_bytes);
if (result != fat_size_bytes)
{
plugin_config.log_print_dbg("Error# Failed to read FAT from the image: %zd", result);
return E_EREAD;
}
return 0;
}
uint64_t FAT_image_t::get_total_sectors_in_volume() const {
uint64_t sectors = 0;
if (bootsec.BPB_TotSec16 != 0) {
sectors = bootsec.BPB_TotSec16;
//! Formally, FAT12 images can contain DOS 3.31+ BPB and have inconsistent BPB_TotSec32/BPB_TotSec16,
//! but checking this for FAT12 causes too many false warnings -- because of old images
if (FAT_type != FAT12_type && bootsec.EBPB_FAT.BPB_TotSec32 != 0 && bootsec.BPB_TotSec16 != bootsec.EBPB_FAT.BPB_TotSec32) {
plugin_config.log_print_dbg("Warning# Inconsistent BPB_TotSec16 and BPB_TotSec32: %d / %d; or pre DOS 3.31 BPB",
bootsec.BPB_TotSec16, bootsec.EBPB_FAT.BPB_TotSec32);
#ifdef FLTK_ENABLED_EXPERIMENTAL
if (plugin_config.allow_dialogs) {
if (get_openmode() == PK_OM_LIST) {
fl_alert("Inconsistent BPB_TotSec16 and BPB_TotSec32 or pre-DOS 3.31 BPB");
}
}
#endif
}
}
else if (bootsec.EBPB_FAT.BPB_TotSec32 != 0) {
sectors = bootsec.EBPB_FAT.BPB_TotSec32;
}
else if (bootsec.EBPB_FAT32.BS_BootSig == 0x29) {
// Some non-standard systems
const uint64_t* BS_TotSec64 = reinterpret_cast<const uint64_t*>(bootsec.EBPB_FAT32.BS_FilSysType);
sectors = *BS_TotSec64;
}
plugin_config.log_print("Info# Total sectors in FAT: %d", sectors);
return sectors;
}
uint64_t FAT_image_t::get_data_sectors_in_volume() const {
return get_total_sectors_in_volume() -
(get_data_area_offset() - get_boot_sector_offset() )/ bootsec.BPB_bytesPerSec;
}
uint64_t FAT_image_t::get_data_clusters_in_volume() const {
return get_data_sectors_in_volume() / bootsec.BPB_SecPerClus;
}
FAT_image_t::FAT_types FAT_image_t::detect_FAT_type() const {
// See http://jdebp.info/FGA/determining-fat-widths.html
auto bytes_per_sector = bootsec.BPB_bytesPerSec;
if(bytes_per_sector == 0){
return FAT_image_t::exFAT_type;
}
auto clusters = get_data_clusters_in_volume();
if (strncmp(bootsec.EBPB_FAT.BS_FilSysType, "FAT12 ", 8) == 0) {
if (clusters > max_cluster_FAT(FAT12_type)) {
plugin_config.log_print_dbg("Warning# String \"FAT12\" found in boot, "
"but too many clusters: %zd of %d", clusters, max_cluster_FAT(FAT12_type));
return FAT_image_t::unknown_FS_type;
}
if (clusters > max_normal_cluster_FAT(FAT12_type)) {
plugin_config.log_print_dbg("Warning# FAT12 contains unusual "
" clusters number: %zd of %d", clusters, max_normal_cluster_FAT(FAT12_type));
}
return FAT_image_t::FAT12_type;
}
if (strncmp(bootsec.EBPB_FAT.BS_FilSysType, "FAT16 ", 8) == 0) {
if (clusters > 0x0FFF6) {
plugin_config.log_print_dbg("Warning# String \"FAT16\" found in boot, "
"but too many clusters: %zd of %d", clusters, max_cluster_FAT(FAT16_type));
return FAT_image_t::unknown_FS_type;
}
if (clusters > max_normal_cluster_FAT(FAT16_type)) {
plugin_config.log_print_dbg("Warning# FAT16 contains unusual "
" clusters number: %zd of %d", clusters, max_normal_cluster_FAT(FAT16_type));
}
return FAT_image_t::FAT16_type;
}
if (strncmp(bootsec.EBPB_FAT.BS_FilSysType, "FAT32 ", 8) == 0 || // Could contain it
strncmp(bootsec.EBPB_FAT32.BS_FilSysType, "FAT32 ", 8) == 0
) {
return FAT_image_t::FAT32_type;
}
if (clusters >= 0x00000002 && clusters <= max_cluster_FAT(FAT12_type)) { // 2 - 0x00000FF6: 24086
if (clusters > max_normal_cluster_FAT(FAT12_type)) {
plugin_config.log_print_dbg("Warning# FAT12 contains unusual "
" clusters number: %zd of %d", clusters, max_normal_cluster_FAT(FAT12_type));
}
return FAT_image_t::FAT12_type;
}
//! TODO: Possible small FAT32 disks without BS_FilSysType could be misdetected.
if (clusters >= max_cluster_FAT(FAT12_type)+1 &&
clusters <= max_cluster_FAT(FAT16_type)) { // 0x00000FF7 - 0x0000FFF6: 408765526
if (clusters > max_normal_cluster_FAT(FAT16_type)) {
plugin_config.log_print_dbg("Warning# FAT16 contains unusual "
" clusters number: %zd of %d", clusters, max_normal_cluster_FAT(FAT16_type));
}
return FAT_image_t::FAT16_type;
}
if (clusters >= max_cluster_FAT(FAT16_type)+1 &&
clusters <= max_cluster_FAT(FAT32_type)) { // 0x0000FFF7 - 0x0FFFFFF6: 65527268435446
if (clusters > max_normal_cluster_FAT(FAT32_type)) {
plugin_config.log_print_dbg("Warning# FAT32 contains unusual "
" clusters number: %zd of %d", clusters, max_normal_cluster_FAT(FAT32_type));
}
return FAT_image_t::FAT32_type;
}
return FAT_image_t::unknown_FS_type; // Unknown format
}
int FAT_image_t::extract_to_file(file_handle_t hUnpFile, uint32_t idx) {
try { // For bad allocation
const auto& cur_entry = arc_dir_entries[idx];
uint32_t nextclus = cur_entry.FirstClus;
size_t remaining = cur_entry.FileSize;
std::vector<char> buff(get_cluster_size());
while (remaining > 0)
{
if ( (nextclus <= 1) || (nextclus >= min_end_of_chain_FAT()) )
{
plugin_config.log_print_dbg("Error# Wrong cluster number in chain: %d in file: %s",
nextclus, cur_entry.PathName.data());
close_file(hUnpFile);
return E_UNKNOWN_FORMAT;
}
set_file_pointer(get_archive_handler(), cluster_to_image_off(nextclus));
size_t towrite = std::min<size_t>(get_cluster_size(), remaining);
size_t result = read_file(get_archive_handler(), buff.data(), towrite);
if (result != towrite)
{
close_file(hUnpFile);
return E_EREAD;
}
result = write_file(hUnpFile, buff.data(), towrite);
if (result != towrite)
{
close_file(hUnpFile);
return E_EWRITE;
}
if (remaining > get_cluster_size()) { remaining -= get_cluster_size(); } //-V104 //-V101
else { remaining = 0; }
nextclus = next_cluster_FAT(nextclus); // TODO: fix if too large cluster number -- test if fixed
}
return 0;
}
catch (std::bad_alloc&) {
return E_NO_MEMORY;
}
}
void FAT_image_t::LFN_accumulator_t::process_LFN_record(const FATxx_dir_entry_t* entry) {
auto LFN_record = as_LFN_record(entry);
if (!are_processing()) {
if (!LFN_record->is_LFN_record_valid() || !LFN_record->is_first_LFN()) {
return; // No record
}
start_processing(LFN_record);
}
else {
if (!LFN_record->is_LFN_record_valid()) {
abort_processing();
}
else if (LFN_record->is_first_LFN()) { // Should restart processing
start_processing(LFN_record);
}
else if (cur_LFN_CRC != LFN_record->LFN_DOS_name_CRC) {
abort_processing();
}
else {
append_LFN_part(LFN_record);
}
}
}
// root passed by copy to avoid problems while relocating vector
int FAT_image_t::load_file_list_recursively(minimal_fixed_string_t<MAX_PATH> root, uint32_t firstclus, uint32_t depth) //-V813
{
if (root.is_empty()) { // Initial reading
counter = 0;
arc_dir_entries.clear();
}
if (firstclus == 0 && FAT_type == FAT32_type) {
// For exotic implementations, if BS_RootFirstClus == 0, will behave as expected
firstclus = bootsec.EBPB_FAT32.BS_RootFirstClus;
}
size_t portion_size = 0;
if (firstclus == 0)
{ // Read whole FAT12/16 dir at once
set_file_pointer(get_archive_handler(), get_root_area_offset());
portion_size = get_root_dir_size();
}
else {
set_file_pointer(get_archive_handler(), cluster_to_image_off(firstclus));
portion_size = static_cast<size_t>(get_cluster_size());
}
size_t records_number = portion_size / sizeof(FATxx_dir_entry_t);
std::unique_ptr<FATxx_dir_entry_t[]> sector;
try {
sector = std::make_unique<FATxx_dir_entry_t[]>(records_number);
}
catch (std::bad_alloc&) {
return E_NO_MEMORY;
}
if (firstclus >= max_normal_cluster_FAT()) {
plugin_config.log_print_dbg("Warning# Unusual first "
"clusters number: %d of %d", firstclus, max_normal_cluster_FAT());
}
if ( (firstclus == 1) || (firstclus >= max_cluster_FAT()) ) {
plugin_config.log_print_dbg("Error# Wrong first "
"clusters number: %d of 2-%d", firstclus, max_cluster_FAT());
return E_UNKNOWN_FORMAT;
}
size_t result = read_file(get_archive_handler(), sector.get(), portion_size);
if (result != portion_size) {
return E_EREAD;
}
LFN_accumulator_t current_LFN;
do {
size_t entry_in_cluster = 0;
while ((entry_in_cluster < records_number) && (!sector[entry_in_cluster].is_dir_record_free()))
{
if (sector[entry_in_cluster].is_dir_record_longname_part()) {
if (plugin_config.use_VFAT) {
current_LFN.process_LFN_record(§or[entry_in_cluster]);
}
entry_in_cluster++;
continue;
}
if (sector[entry_in_cluster].is_dir_record_volumeID())
{
minimal_fixed_string_t<12> voll;
sector[entry_in_cluster].dir_entry_name_to_str(voll);
plugin_config.log_print_dbg("Info# Volume label: %s", voll.data());
}
if (sector[entry_in_cluster].is_dir_record_deleted() ||
sector[entry_in_cluster].is_dir_record_unknown() ||
sector[entry_in_cluster].is_dir_record_volumeID() ||
sector[entry_in_cluster].is_dir_record_invalid_attr()
)
{
if(current_LFN.are_processing())
current_LFN.abort_processing();
entry_in_cluster++;
continue;
}
arc_dir_entries.emplace_back();
auto& newentryref = arc_dir_entries.back();
newentryref.FileAttr = sector[entry_in_cluster].DIR_Attr;
newentryref.PathName.push_back(root); // Empty root is OK, "\\" OK too
uint32_t invalid_chars = 0;
if (plugin_config.use_VFAT && current_LFN.are_processing()) {
if (current_LFN.cur_LFN_CRC == VFAT_LFN_dir_entry_t::LFN_checksum(sector[entry_in_cluster].DIR_Name)) {
newentryref.PathName.push_back(current_LFN.cur_LFN_name);
}
else {
auto res = sector[entry_in_cluster].process_E5();
if(!res)
plugin_config.log_print_dbg("Warning# E5 occurred at first symbol.");
invalid_chars = sector[entry_in_cluster].dir_entry_name_to_str(newentryref.PathName);
// No OS/2 EA on FAT32
}
current_LFN.abort_processing();
}
else {
auto res = sector[entry_in_cluster].process_E5();
if (!res)
plugin_config.log_print_dbg("Warning# E5 occurred at first symbol.");
invalid_chars = sector[entry_in_cluster].dir_entry_name_to_str(newentryref.PathName);
if (invalid_chars == FATxx_dir_entry_t::LLDE_OS2_EA) {
plugin_config.log_print_dbg("Info# OS/2 Extended attributes found.");
has_OS2_EA = true;
}
}
newentryref.FileTime = sector[entry_in_cluster].get_file_datetime();
newentryref.FileSize = sector[entry_in_cluster].DIR_FileSize;
newentryref.FirstClus = get_first_cluster(sector[entry_in_cluster]);
if (sector[entry_in_cluster].is_dir_record_dir()) {
newentryref.PathName.push_back('\\'); // Neccessery for empty dirs to be "enterable"
}
if (depth > plugin_config.max_depth) {
plugin_config.log_print_dbg("Too many nested directories: %d.", depth);
break;
}
if (sector[entry_in_cluster].is_dir_record_dir() &&
(newentryref.FirstClus < max_cluster_FAT()) && (newentryref.FirstClus > 0x1)
&& (depth <= plugin_config.max_depth)) //-V560 // Always true after the previous if, but leaving it here for clarity
{
if(invalid_chars > plugin_config.max_invalid_chars_in_dir && invalid_chars != FATxx_dir_entry_t::LLDE_OS2_EA) {
plugin_config.log_print_dbg("Warning# Invalid characters in directory name: %s, skipping", newentryref.PathName.data());
}
else {
load_file_list_recursively(newentryref.PathName, newentryref.FirstClus, depth + 1);
}
}
++entry_in_cluster;
}
if (entry_in_cluster < records_number) { return 0; }
if (firstclus == 0)
{
break; // We already processed FAT12/16 root dir
}
else {
firstclus = next_cluster_FAT(firstclus);
if (firstclus >= max_normal_cluster_FAT() && !is_end_of_chain_FAT(firstclus)) {
plugin_config.log_print_dbg("Warning# Unusual next "
"clusters number: %d of %d", firstclus, max_normal_cluster_FAT());