forked from jeffpar/pcjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiskinfo.js
More file actions
4068 lines (3844 loc) · 186 KB
/
diskinfo.js
File metadata and controls
4068 lines (3844 loc) · 186 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
/**
* @fileoverview Disk processing module
* @author Jeff Parsons <Jeff@pcjs.org>
* @copyright © 2012-2022 Jeff Parsons
* @license MIT <https://www.pcjs.org/LICENSE.txt>
*
* This file is part of PCjs, a computer emulation software project at <https://www.pcjs.org>.
*/
import CPUx86 from "./cpux86.js";
import Device from "../../modules/device.js";
import FileInfo from "./fileinfo.js";
/**
* VolInfo describes a volume. NOTE: this list of properties may not be
* exhaustive (it may omit certain internal calculations), but at the very least,
* it should include every "volume descriptor" property we export via getVolDesc().
*
* @typedef {Object} VolInfo
* @property {number} iVolume
* @property {number} iPartition
* @property {number} idMedia
* @property {number} lbaStart
* @property {number} lbaTotal
* @property {number} nFATBits
* @property {number} vbaFAT
* @property {number} vbaRoot
* @property {number} nEntries
* @property {number} vbaData
* @property {number} clusSecs
* @property {number} clusMax
* @property {number} clusBad
* @property {number} clusFree
* @property {number} clusTotal
*/
/**
* FileData is an input data structure that callers of buildDiskFromFiles() must provide.
*
* @typedef {Object} FileData
* @property {string} path
* @property {string} name
* @property {number} attr
* @property {Date} date
* @property {number} size
* @property {DataBuffer} data
* @property {number} cluster
* @property {Array.<FileData>} files
*/
/**
* DirInfo is an internal data structure used to help build FileInfo objects.
*
* @typedef {Object} DirInfo
* @property {string} path (filled in by getDir(); the rest are filled in by getDirEntry())
* @property {string} name (null if invalid/deleted entry)
* @property {number} attr
* @property {number} modDate
* @property {number} modTime
* @property {number} size
* @property {number} cluster
* @property {Array.<number>} aLBA (ie, array of logical block addresses)
*/
/**
* Sector describes a sector contained within a disk image. Storing the cylinder and head
* of a sector within the structure is a bit redundant, but I find it helpful for inspection
* and verification purposes.
*
* @typedef {Object} Sector
* @property {number} c (cylinder #)
* @property {number} h (head #)
* @property {number} s (sector ID)
* @property {number} l (length of sector, in bytes)
* @property {Array.<number>} d (array of 32-bit values)
* @property {number} f (index into the disk's file table)
* @property {number} o (offset of this sector within the file's data stream)
* @property {number} dataCRC
* @property {boolean} dataError
* @property {number} dataMark
* @property {number} headCRC
* @property {boolean} headError
* @property {number} iModify (used only with fWritable disk images)
* @property {number} cModify (used only with fWritable disk images)
*/
/**
* @class DiskInfo
* @property {string} diskName
* @property {boolean} fWritable
* @property {Array} aDiskData
* @property {number} cbDiskData
* @property {number} dwChecksum
* @property {number} nCylinders
* @property {number} nHeads
* @property {number} nSectors
* @property {number} cbSector
* @property {Array.<VolInfo>|null} volTable
* @property {Array.<FileInfo>|null} fileTable
*/
export default class DiskInfo {
/**
* DiskInfo(device, diskName, fWritable)
*
* Returns a DiskInfo object used to build a disk images.
*
* @this {DiskInfo}
* @param {Device} device
* @param {string} [diskName]
* @param {boolean} [fWritable]
*/
constructor(device, diskName = "", fWritable = false)
{
this.device = device;
this.printf = device.printf.bind(device);
this.assert = device.assert.bind(device);
this.diskName = diskName;
this.hash = "none";
this.args = "";
this.fWritable = fWritable;
this.volTable = [];
this.fileTable = [];
this.tablesBuilt = false;
}
/**
* buildDiskFromBuffer(dbDisk, hash, forceBPB, sectorIDs, sectorErrors, suppData)
*
* Build a disk image from a DataBuffer.
*
* All callers are now required to convert their data to a DataBuffer first. For example, if the caller
* received an ArrayBuffer from a FileReader object, they must first create a DataBuffer from the ArrayBuffer.
*
* Here's the initial (simplified) version of this function. It got much more complicated over time
* as more diskettes were processed and anomalies were discovered.
*
* let diskFormat = DiskInfo.GEOMETRIES[db.length];
* if (diskFormat) {
* let ib = 0;
* this.cbDiskData = db.length;
* this.nCylinders = diskFormat[0];
* this.nHeads = diskFormat[1];
* this.nSectors = diskFormat[2];
* this.cbSector = (diskFormat[3] || 512);
* this.aDiskData = new Array(this.nCylinders);
* for (let iCylinder = 0; iCylinder < this.aDiskData.length; iCylinder++) {
* let cylinder = this.aDiskData[iCylinder] = new Array(this.nHeads);
* for (let iHead = 0; iHead < cylinder.length; iHead++) {
* let head = cylinder[iHead] = new Array(this.nSectors);
* for (let iSector = 0; iSector < head.length; iSector++) {
* head[iSector] = this.buildSector(iCylinder, iHead, iSector + 1, this.cbSector, db, ib);
* ib += this.cbSector;
* }
* }
* }
* return true;
* }
*
* @this {DiskInfo}
* @param {DataBuffer} dbDisk
* @param {string} [hash]
* @param {fForceBPP} [forceBPB]
* @param {Array|string} [sectorIDs]
* @param {Array|string} [sectorErrors]
* @param {string} [suppData] (eg, supplementary disk data that can be found in such files as: /software/pcx86/app/microsoft/word/1.15/debugger/index.md)
* @returns {boolean} true if successful (aDiskData initialized); false otherwise
*/
buildDiskFromBuffer(dbDisk, hash, forceBPB, sectorIDs, sectorErrors, suppData)
{
this.aDiskData = null;
this.cbDiskData = 0;
this.dwChecksum = 0;
this.fromJSON = false;
let nHeads = 0;
let nCylinders = 0;
let nSectorsPerTrack = 0;
let aTracks = []; // track array (used only for disk images with track tables)
let cbSector = 512; // default sector size
let bMediaID = 0;
let offBootSector = 0;
let cbDiskData = dbDisk.length, cbPartition = cbDiskData;
let dbTrack, dbSector;
let iTrack, cbTrack, offTrack, offSector;
if (cbDiskData >= 3000000) { // arbitrary threshold between diskette image sizes and hard drive image sizes
let wSig = dbDisk.readUInt16LE(DiskInfo.BOOT.SIG_OFFSET);
if (wSig == DiskInfo.BOOT.SIGNATURE) {
/*
* In this case, the first sector should be an MBR; find the active partition entry,
* then read the LBA of the first partition sector to calculate the boot sector offset.
*/
for (let offEntry = 0x1BE; offEntry <= 0x1EE; offEntry += 0x10) {
if (dbDisk.readUInt8(offEntry) >= 0x80) {
offBootSector = dbDisk.readUInt32LE(offEntry + 0x08) * cbSector;
cbPartition = dbDisk.readUInt32LE(offEntry + 0x0C) * cbSector;
break;
}
}
}
/*
* If we failed to find an active entry, we'll fall into the BPB detection code, which
* should fail if the first sector really was an MBR. Otherwise, the BPB should give us
* the geometry info we need to dump the entire disk image, including the MBR and any
* other reserved sectors.
*/
}
let bByte0 = dbDisk.readUInt8(offBootSector + DiskInfo.BPB.OPCODE);
let bByte1 = dbDisk.readUInt8(offBootSector + DiskInfo.BPB.OPCODE + 1);
let cbSectorBPB = dbDisk.readUInt16LE(offBootSector + DiskInfo.BPB.SECBYTES);
/*
* Save the original BPB, in case we need to modify it later.
*/
this.abOrigBPB = [];
this.fBPBModified = false;
this.abOrigBPB.push(offBootSector);
for (let i = DiskInfo.BPB.OPCODE; i < DiskInfo.BPB.LARGESECS+4; i++) {
this.abOrigBPB.push(dbDisk.readUInt8(offBootSector + i));
}
/*
* These checks are not only necessary for DOS 1.x diskette images (and other pre-BPB images),
* but also non-DOS diskette images (eg, CPM-86 diskettes).
*
* And we must perform these tests BEFORE checking for a BPB, because we want the PHYSICAL geometry
* of the disk, whereas any values in the BPB may only be LOGICAL. For example, DOS may only be using
* 8 sectors per track on diskette that's actually formatted with 9 sectors per track.
*
* Checking these common sizes insures we get the proper physical geometry for common disk formats,
* but at some point, we'll need to perform more general calculations to properly deal with ANY disk
* image whose logical format doesn't agree with its physical structure.
*/
let fXDFOutput = false;
let diskFormat = DiskInfo.GEOMETRIES[cbDiskData];
if (!diskFormat) {
/*
* I've come across some disk images that were .IMD files that I had converted to .IMG using HxC,
* and everything was fine except that there was 128 bytes of extra "stuff" af the end of the image,
* defeating our simple geometry check.
*
* Example: Microsoft Macro Assembler 1.10 [Tandy 2000 (r01.00.00)] (5.25-360k)/t2kasm_imd.img
*/
diskFormat = DiskInfo.GEOMETRIES[cbDiskData - 0x80];
}
if (diskFormat) {
nCylinders = diskFormat[0];
nHeads = diskFormat[1];
nSectorsPerTrack = diskFormat[2];
cbSector = diskFormat[3] || cbSector;
bMediaID = diskFormat[4] || bMediaID;
}
/*
* I used to do these BPB tests only if diskFormat was undefined, but now I always do them, because I
* want to make sure they're in agreement (and if not, then figure out why not).
*
* See if the first sector of the image contains a valid DOS BPB. This is tricky, because there are lots
* of variations. For now, the checks are simplistic: the first byte is checked for an Intel JMP opcode
* (0xEB is JMP with a 1-byte displacement, and 0xE9 is JMP with a 2-byte displacement) or an Intel CLD opcode
* (used by BASIC-DOS), and the sector size (word at offset 0x0B) is checked for any power of two >= 128
* (the "standard" IBM sector size was 512, but 128, 256, and 1024 were also possible).
*/
let fBPBExists = false, bMediaIDBPB = 0;
if ((bByte0 == CPUx86.OPCODE.JMP || bByte0 == CPUx86.OPCODE.JMPS || bByte0 == CPUx86.OPCODE.CLD) && cbSectorBPB >= 128 && (cbSectorBPB & (cbSectorBPB - 1)) == 0) {
let nHeadsBPB = dbDisk.readUInt16LE(offBootSector + DiskInfo.BPB.DRIVEHEADS);
let nSectorsPerTrackBPB = dbDisk.readUInt16LE(offBootSector + DiskInfo.BPB.TRACKSECS);
if (nHeadsBPB && nSectorsPerTrackBPB) {
fBPBExists = true;
bMediaIDBPB = dbDisk.readUInt8(offBootSector + DiskInfo.BPB.MEDIA);
let nSectorsTotalBPB = dbDisk.readUInt16LE(offBootSector + DiskInfo.BPB.DISKSECS);
let nSectorsPerCylinderBPB = nSectorsPerTrackBPB * nHeadsBPB;
let nSectorsHiddenBPB = dbDisk.readUInt16LE(offBootSector + DiskInfo.BPB.HIDDENSECS);
let nCylindersBPB = (nSectorsHiddenBPB + nSectorsTotalBPB) / nSectorsPerCylinderBPB;
if (diskFormat) {
if (bMediaID && bMediaID != bMediaIDBPB) {
this.printf(Device.MESSAGE.WARN, "BPB media ID (%#0bx) does not match physical media ID (%#0bx)\n", bMediaIDBPB, bMediaID);
}
if (nCylinders != nCylindersBPB) {
this.printf(Device.MESSAGE.WARN, "BPB cylinders (%d) do not match physical cylinders (%d)\n", nCylindersBPB, nCylinders);
if (nCylinders - nCylindersBPB == 1) {
this.printf(Device.MESSAGE.WARN, "BIOS may have reserved the last cylinder for diagnostics\n");
}
}
if (nHeads != nHeadsBPB) {
this.printf(Device.MESSAGE.WARN, "BPB heads (%d) do not match physical heads (%d)\n", nHeadsBPB, nHeads);
}
if (nSectorsPerTrack != nSectorsPerTrackBPB) {
this.printf(Device.MESSAGE.WARN, "BPB sectors/track (%d) do not match physical sectors/track (%d)\n", nSectorsPerTrackBPB, nSectorsPerTrack);
}
}
else {
nHeads = nHeadsBPB;
nSectorsPerTrack = nSectorsPerTrackBPB;
nCylinders = cbDiskData / (nHeads * nSectorsPerTrack * cbSectorBPB);
if (nCylinders != (nCylinders|0)) {
this.printf(Device.MESSAGE.WARN, "total cylinders (%d) not a multiple of %d sectors per cylinder\n", nCylinders, nHeads * nSectorsPerTrack);
nCylinders |= 0;
}
if (cbSector != cbSectorBPB) {
this.printf(Device.MESSAGE.WARN, "overriding default sector size (%d) with BPB sector size (%d)\n", cbSector, cbSectorBPB);
cbSector = cbSectorBPB;
}
bMediaID = bMediaIDBPB;
}
/*
* OK, great, the disk appears to contain a valid BPB. But so do XDF disk images, which are
* diskette images with tracks containing:
*
* 1 8Kb sector (equivalent of 16 512-byte sectors)
* 1 2Kb sector (equivalent of 4 512-byte sectors)
* 1 1Kb sector (equivalent of 2 512-byte sectors)
* 1 512-byte sector (equivalent of, um, 1 512-byte sector)
*
* for a total of the equivalent of 23 512-byte sectors, or 11776 (0x2E00) bytes per track.
* For an 80-track diskette with 2 sides, that works out to a total of 3680 512-byte sectors,
* or 1884160 bytes, or 1.84Mb, which is the exact size of the (only) XDF diskette images we
* currently (try to) support.
*
* Moreover, the first two tracks (ie, the first cylinder) contain only 19 sectors each,
* rather than 23, but XDF disk images still pads those tracks with 4 unused sectors.
*
* So, data for the first track contains 1 boot sector ending at 512 (0x200), 11 FAT sectors
* ending at 6144 (0x1800), and 7 "micro-disk" sectors ending at 9728 (0x2600). Then there's
* 4 (useless?) sectors that end at 11776 (0x2E00).
*
* Data for the second track contains 7 root directory sectors ending at 15360 (0x3C00), followed
* by disk data.
*
* For more details, check out this helpful article: http://www.os2museum.com/wp/the-xdf-diskette-format/
*/
if (nSectorsTotalBPB == 3680 && this.fXDFSupport) {
this.printf(Device.MESSAGE.WARN, "XDF diskette detected, experimental XDF output enabled\n");
fXDFOutput = true;
}
}
}
/*
* Let's see if we can find a corresponding BPB in our table of default BPBs.
*/
let iBPB = -1;
for (let i = 0; i < DiskInfo.aDefaultBPBs.length; i++) {
if (DiskInfo.aDefaultBPBs[i][DiskInfo.BPB.MEDIA] == bMediaID) {
let cbDiskBPB = (DiskInfo.aDefaultBPBs[i][DiskInfo.BPB.DISKSECS] + (DiskInfo.aDefaultBPBs[i][DiskInfo.BPB.DISKSECS + 1] * 0x100)) * cbSector;
if (cbDiskBPB == cbDiskData) {
/*
* This code was added to deal with variations in sectors/cluster. Most software manufacturers
* were happy with the defaults that FORMAT chooses for a given diskette size, but in a few cases
* (eg, PC DOS 4.00 360K diskettes, PC DOS 4.01 720K diskettes, etc), the manufacturer (IBM) opted
* for a smaller cluster size.
*/
if (!fBPBExists || dbDisk.readUInt8(offBootSector + DiskInfo.BPB.CLUSSECS) == DiskInfo.aDefaultBPBs[i][DiskInfo.BPB.CLUSSECS]) {
iBPB = i;
break;
}
}
}
}
let nLogicalSectorsPerTrack = nSectorsPerTrack;
if (iBPB >= 0) {
/*
* Sometimes we come across a physical 360Kb disk image that contains a logical 320Kb image (and similarly,
* a physical 180Kb disk image that contains a logical 160Kb disk image), presumably because it was possible
* for someone to take a diskette formatted with 9 sectors/track and then use FORMAT or DISKCOPY to create
* a smaller file system on it (ie, using only 8 sectors/track).
*/
if (!bMediaIDBPB) bMediaIDBPB = dbDisk.readUInt8(offBootSector + 512);
if (iBPB >= 2 && bMediaIDBPB == DiskInfo.FAT.MEDIA_320KB && bMediaID == DiskInfo.FAT.MEDIA_360KB || bMediaIDBPB == DiskInfo.FAT.MEDIA_160KB && bMediaID == DiskInfo.FAT.MEDIA_180KB) {
iBPB -= 2;
bMediaID = DiskInfo.aDefaultBPBs[iBPB][DiskInfo.BPB.MEDIA];
nLogicalSectorsPerTrack = DiskInfo.aDefaultBPBs[iBPB][DiskInfo.BPB.TRACKSECS];
this.printf(Device.MESSAGE.WARN, "shrinking track size to %d sectors/track\n", nLogicalSectorsPerTrack);
}
let fBPBWarning = false;
if (fBPBExists) {
/*
* In deference to the PC DOS 2.0 BPB behavior discussed above, we stop our BPB verification after
* the first word of HIDDENSECS.
*/
for (let off = DiskInfo.BPB.SECBYTES; off < DiskInfo.BPB.HIDDENSECS + 2; off++) {
let bDefault = DiskInfo.aDefaultBPBs[iBPB][off];
let bActual = dbDisk.readUInt8(offBootSector + off);
if (bDefault != bActual) {
this.printf(Device.MESSAGE.WARN, "BPB byte %#02bx default (%#02bx) does not match actual byte: %#02bx\n", off, bDefault, bActual);
/*
* Silly me for thinking that a given media ID (eg, 0xF9) AND a given disk size (eg, 720K)
* AND a given number of sectors/cluster (eg, 2) would always map to the same BPB. I had already
* added *two* 720K BPBs -- one for the common case of 2 sectors/cluster and another for 720K
* disks like PC DOS 4.01 which use 1 sector/cluster -- but it turns out there are even more
* variations. For example, the number of root directory entries: I was under the impression that
* the "standard" value was 0x70, but the number used by PC DOS 3.3 is 0xE0 entries (exactly
* twice as many).
*
* And while it doesn't much matter which BPB variation we use when we're *building* a new disk OR
* sprucing up a disk that never had a BPB anyway, it's a much more serious matter when there's
* an existing BPB. So I have narrowed the conditions where fBPBWarning is set, thereby reducing
* the odds of damaging a good BPB versus repairing or replacing a bad one.
*/
if (off != DiskInfo.BPB.FATS && off != DiskInfo.BPB.DIRENTS) fBPBWarning = true;
}
}
}
if (!fBPBExists || fBPBWarning) {
if (bByte0 == CPUx86.OPCODE.JMPS && bByte1 >= 0x22 || forceBPB) {
/*
* I'm going to stick my neck out here and slam a BPB into this disk image, since it doesn't appear
* to have one, which should make it more "mountable" on modern operating systems. PC DOS 1.x (and
* the recently unearthed PC DOS 0.x) are OK with this, because they don't put anything important in
* the BPB byte range (0x00B-0x023), just a 9-byte date string (eg, " 7-May-81") at 0x008-0x010,
* followed by zero bytes at 0x011-0x030.
*
* They DO, however, store important constants in the range later used as the 8-byte OEM string at
* 0x003-0x00A. For example, the word at 0x006 contains the starting segment for where to load
* IBMBIO.COM and IBMDOS.COM. Those same early boot sectors are also missing the traditional 0xAA55
* signature at the end of the boot sector.
*
* However, if --forceBPB is specified, all those concerns go out the window: the goal is assumed to
* be a mountable disk, not a bootable disk. So the BPB copy starts at offset 0 instead of SECBYTES.
*/
for (let i = forceBPB? 0 : DiskInfo.BPB.SECBYTES; i < DiskInfo.BPB.LARGESECS+4; i++) {
dbDisk.writeUInt8(DiskInfo.aDefaultBPBs[iBPB][i] || 0, offBootSector + i);
}
this.printf(Device.MESSAGE.INFO, "BPB has been updated\n");
if (hash) this.fBPBModified = true;
}
else if (bByte0 == 0xF6 && bByte1 == 0xF6 && bMediaIDBPB > 0xF8) {
/*
* WARNING: I've added this "0xF6" hack expressly to fix boot sectors that may have been zapped by an
* inadvertent reformat, or...? However, certain Xenix diskettes get misdetected by this, so we at least
* require the media ID (from the first byte of the first FAT sector) be sensible.
*/
this.printf(Device.MESSAGE.WARN, "repairing damaged boot sector with BPB for media ID %#02bx\n", bMediaID);
for (let i = 0; i < DiskInfo.BPB.LARGESECS+4; i++) {
dbDisk.writeUInt8(DiskInfo.aDefaultBPBs[iBPB][i] || 0, offBootSector + i);
}
}
else {
this.printf(Device.MESSAGE.WARN, "unrecognized boot sector: %#02bx,%#02bx\n", bByte0, bByte1);
}
}
}
if (fBPBExists && dbDisk.readUInt16LE(offBootSector + DiskInfo.BOOT.SIG_OFFSET) == DiskInfo.BOOT.SIGNATURE || forceBPB) {
/*
* Overwrite the OEM string with our own, so that people know how the image originated. We do this
* only for disks with pre-existing BPBs; it's not safe for pre-2.0 disks (and non-DOS disks, obviously).
*
* The signature check is another pre-2.0 disk check, to avoid misinterpreting any BPB that we might have
* previously added ourselves as an original BPB.
*/
let dw = dbDisk.readInt32BE(DiskInfo.BPB.OEM + offBootSector);
if (dw != 0x50434A53) {
dbDisk.write(DiskInfo.PCJS_OEM, DiskInfo.BPB.OEM + offBootSector, DiskInfo.PCJS_OEM.length);
this.printf(Device.MESSAGE.INFO, "OEM string has been updated\n");
if (hash) this.fBPBModified = true;
}
}
if (!nHeads) {
/*
* Next, check for a DSK header (an old private format I used to use, which begins with either
* 0x00 (read-write) or 0x01 (write-protected), followed by 7 more bytes):
*
* 0x01: # heads (1 byte)
* 0x02: # cylinders (2 bytes)
* 0x04: # sectors/track (2 bytes)
* 0x06: # bytes/sector (2 bytes)
*
* which may be followed by an array of track table entries if the words at 0x04 and 0x06 are zero.
* If the track table exists, each entry contains the following:
*
* 0x00: # sectors/track (2 bytes)
* 0x02: # bytes/sector (2 bytes)
* 0x04: file offset of track data (4 bytes)
*
* TODO: Our new JSON disk format should probably include a write-protect indicator. Instead, we
* (used to) include the string "write-protected" as a comment in the first line of the JSON data
* as a work-around, and if the FDC component sees that comment string, it will honor it; however,
* we now prefer that read-only disk images simply include a "-readonly" suffix in the filename.
*/
if (!(bByte0 & 0xFE)) {
let cbSectorDSK = dbDisk.readUInt16LE(offBootSector + 0x06);
if (!(cbSectorDSK & (cbSectorDSK - 1))) {
cbSector = cbSectorDSK;
nHeads = dbDisk.readUInt8(offBootSector + 0x01);
nCylinders = dbDisk.readUInt16LE(offBootSector + 0x02);
nLogicalSectorsPerTrack = nSectorsPerTrack = dbDisk.readUInt16LE(offBootSector + 0x04);
let nTracks = nHeads * nCylinders;
cbTrack = nSectorsPerTrack * cbSector;
offTrack = 0x08;
if (!cbTrack) {
for (iTrack = 0; iTrack < nTracks; iTrack++) {
nLogicalSectorsPerTrack = nSectorsPerTrack = dbDisk.readUInt16LE(offTrack);
cbSectorDSK = dbDisk.readUInt16LE(offTrack+2);
cbTrack = nSectorsPerTrack * cbSectorDSK;
offSector = dbDisk.readUInt32LE(offTrack+4);
dbTrack = dbDisk.slice(offSector, offSector + cbTrack);
aTracks[iTrack] = [nSectorsPerTrack, cbSectorDSK, dbTrack];
offTrack += 8;
}
}
}
}
}
if (nHeads) {
/*
* Output the disk data as an array of cylinders, each containing an array of tracks (one track per head),
* and each track containing an array of sectors.
*/
iTrack = offTrack = 0;
cbTrack = nSectorsPerTrack * cbSector;
let suppObj = this.parseSuppData(suppData);
this.aDiskData = new Array(nCylinders);
if (hash) this.hash = hash;
this.nCylinders = nCylinders;
for (let iCylinder=0; iCylinder < nCylinders; iCylinder++) {
let aHeads = new Array(nHeads);
this.aDiskData[iCylinder] = aHeads;
this.nHeads = nHeads;
let offHead = 0;
for (let iHead=0; iHead < nHeads; iHead++) {
if (aTracks.length) {
let aTrack = aTracks[iTrack++];
nLogicalSectorsPerTrack = nSectorsPerTrack = aTrack[0];
cbSector = aTrack[1];
dbTrack = aTrack[2];
cbTrack = nSectorsPerTrack * cbSector;
} else {
dbTrack = dbDisk.slice(offTrack + offHead, offTrack + offHead + cbTrack);
}
let aSectors = new Array(nLogicalSectorsPerTrack);
aHeads[iHead] = aSectors;
this.nSectors = nLogicalSectorsPerTrack;
/*
* For most disks, the size of every sector and the number of sectors/track are consistent, and the
* sector number encoded in every sector (nSector) matches the 1-based sector index (iSector) we use
* to "track" our progress through the current track. However, for XDF disk images, the above is
* NOT true beyond cylinder 0, which is why we have all these *ThisTrack variables, which would otherwise
* be unnecessary.
*/
let cbSectorThisTrack = cbSector;
let nSectorsThisTrack = nLogicalSectorsPerTrack;
this.cbSector = cbSector;
/*
* Notes regarding XDF track layouts, from http://forum.kryoflux.com/viewtopic.php?f=3&t=234:
*
* Track 0, side 0: 19x512 bytes per sector, with standard numbering for the first 8 sectors, then custom numbering
* Track 0, side 1: 19x512 bytes per sector, with interleaved sector numbering 0x81...0x93
*
* Track 1 and up, side 0, 4 sectors per track:
* 1x1024, 1x512, 1x2048, 1x8192 bytes per sector (0x83, 0x82, 084, 0x86 as sector numbers)
*
* Track 1 and up, side 1, 4 sectors per track:
* 1x2048, 1x512, 1x1024, 1x8192 bytes per sector (0x84, 0x82, 083, 0x86 as sector numbers)
*
* Notes regarding the order in which XDF sectors are read (from http://mail.netbridge.at/cgi-bin/info2www?(fdutils)XDF),
* where each position column represents a (roughly) 128-byte section of the track:
*
* 1 2 3 4
* 1234567890123456789012345678901234567890 (position)
* ----------------------------------------
* 6633332244444446666666666666666666666666 (side 0)
* 6666444444422333366666666666666666666666 (side 1)
*
* where 2's contain a 512-byte sector, 3's contain a 1Kb sector, 4's contains a 2Kb sector, and 6's contain an 8Kb sector.
*
* Reading all the data on an XDF cylinder occurs in the following order, from the specified start to end positions:
*
* sector head start end
* 3 0 3 7
* 4 0 9 16
* 6 1 18 5 (1st wrap around)
* 2 0 7 9
* 2 1 12 14
* 6 0 16 3 (2nd wrap around)
* 4 1 5 12
* 3 1 14 18
*/
if (fXDFOutput) nSectorsThisTrack = (iCylinder? 4 : 19);
let suppTrack = null;
for (let iSector=1, offSector=0; iSector <= nSectorsThisTrack && (offSector < cbTrack || suppTrack); iSector++, offSector += cbSectorThisTrack) {
let sectorID = iSector;
if (fXDFOutput && iCylinder) {
if (!iHead) {
cbSectorThisTrack = (iSector == 1? 1024 : (iSector == 2? 512 : (iSector == 3? 2048 : 8192)));
} else {
cbSectorThisTrack = (iSector == 1? 8192 : (iSector == 2? 2048 : (iSector == 3? 1024 : 512)));
}
sectorID = (cbSectorThisTrack == 512? 2 : (cbSectorThisTrack == 1024? 3 : (cbSectorThisTrack == 2048? 4 : 6)));
}
/*
* Check for any sector ID edits that must be applied to the disk (eg, "--sectorID=C:H:S:ID").
*
* For example, when building the IBM Multiplan 1.00 Program disk, "--sectorID=11:0:8:61" must be specified.
*/
let aParts, n;
if (sectorIDs) {
let aSectorIDs = (typeof sectorIDs == "string")? [sectorIDs] : sectorIDs;
for (let i = 0; i < aSectorIDs.length; i++) {
aParts = aSectorIDs[i].split(":");
if (+aParts[0] === iCylinder && +aParts[1] === iHead && +aParts[2] === sectorID) {
n = +aParts[3];
if (!isNaN(n)) {
sectorID = n;
this.printf(Device.MESSAGE.WARN, "changing %d:%d:%d sectorID to %d\n", +aParts[0], +aParts[1], +aParts[2], sectorID);
}
}
}
}
let sectorError = 0;
if (sectorErrors) {
let aSectorErrors = (typeof sectorErrors == "string")? [sectorErrors] : sectorErrors;
for (let i = 0; i < aSectorErrors.length; i++) {
aParts = aSectorErrors[i].split(":");
if (+aParts[0] === iCylinder && +aParts[1] === iHead && +aParts[2] === sectorID) {
n = +aParts[3] || -1;
if (n) {
sectorError = n;
this.printf(Device.MESSAGE.WARN, "forcing error for sector %d:%d:%d at %d bytes\n", +aParts[0], +aParts[1], +aParts[2], sectorError);
}
}
}
}
dbSector = dbTrack.slice(offSector, offSector + cbSectorThisTrack);
if (bMediaID && !iCylinder && !iHead && iSector == ((offBootSector/cbSector)|0) + 2) {
let bFATID = dbSector.readUInt8(0);
if (bMediaID != bFATID) {
this.printf(Device.MESSAGE.WARN, "FAT ID (%#02bx) does not match physical media ID (%#02bx)\n", bFATID, bMediaID);
}
bMediaID = 0;
}
let sector = this.buildSector(iCylinder, iHead, sectorID, cbSectorThisTrack, dbSector);
let suppSector = null;
if (suppObj[iCylinder]) {
suppTrack = suppObj[iCylinder][iHead];
if (suppTrack) {
suppSector = suppTrack[iSector-1];
nSectorsThisTrack = suppTrack.length;
}
}
if (suppSector) {
sector[DiskInfo.SECTOR.ID] = suppSector['sectorID'];
if (suppSector['length']) sector[DiskInfo.SECTOR.LENGTH] = suppSector['length'];
if (suppSector['headCRC']) sector[DiskInfo.SECTOR.HEAD_CRC] = suppSector['headCRC'];
if (suppSector['headError']) sector[DiskInfo.SECTOR.HEAD_ERROR] = true;
if (suppSector['dataCRC']) sector[DiskInfo.SECTOR.DATA_CRC] = suppSector['dataCRC'];
if (suppSector['dataMark']) sector[DiskInfo.SECTOR.DATA_MARK] = suppSector['dataMark'];
if (!sectorError) sectorError = suppSector['dataError'];
sector[DiskInfo.SECTOR.DATA] = suppSector['data'];
}
if (sectorError) sector[DiskInfo.SECTOR.DATA_ERROR] = sectorError;
aSectors[iSector - 1] = sector;
this.cbDiskData += sector[DiskInfo.SECTOR.LENGTH];
}
offHead += cbTrack; // end of head {iHead}, track {iCylinder}
}
offTrack += offHead; // end of cylinder {iCylinder}
}
return true;
}
// else if (dbDisk.readUInt16BE(0x900) == 0x4357) {
// return this.convertOSIDiskToJSON();
// }
return false;
}
/**
* buildDiskFromFiles(dbDisk, diskName, aFileData, kbTarget)
*
* @this {DiskInfo}
* @param {DataBuffer} dbDisk
* @param {string} diskName
* @param {Array.<FileData>} aFileData
* @param {number} [kbTarget]
* @returns {boolean} true if disk allocation successful, false if not
*/
buildDiskFromFiles(dbDisk, diskName, aFileData, kbTarget = 0)
{
if (!aFileData || !aFileData.length) {
return false;
}
this.diskName = diskName;
this.abOrigBPB = [];
this.fBPBModified = false;
/*
* Put reasonable upper limits on both individual file sizes and the total size of all files.
*/
let cbMax = (kbTarget || 1440) * 1024;
let nTargetSectors = (kbTarget? kbTarget * 2 : 0);
/*
* This initializes cbTotal assuming a "best case scenario" (ie, one sector per cluster); as soon as
* we find a BPB that will support that size, we recalculate cbTotal using that BPB's cluster size, and
* then we re-verify that that BPB will work. If not, then we keep looking.
*/
let cbTotal = this.calcFileSizes(aFileData);
this.printf(Device.MESSAGE.DISK + Device.MESSAGE.INFO, "calculated size for %d files: %d bytes (%#x)\n", aFileData.length, cbTotal);
if (cbTotal >= cbMax) {
this.printf(Device.MESSAGE.DISK + Device.MESSAGE.ERROR, "file(s) too large (%d bytes total, %d bytes maximum)\n", cbTotal, cbMax);
return false;
}
let iBPB, abBoot, cbSector, cSectorsPerCluster, cbCluster, cFATs, cFATSectors;
let cRootEntries, cRootSectors, cTotalSectors, cHiddenSectors, cSectorsPerTrack, cHeads, cDataSectors, cbAvail;
/*
* Find or build a BPB with enough capacity, and at the same time, calculate all the other values we'll need,
* including total number of data sectors (cDataSectors).
*
* TODO: For now, the code that chooses a default BPB starts with entry #3 instead of #0, because Windows 95
* (at least when running under VMware) fails to read the contents of such disks correctly. Whether that's my
* fault or Windows 95's fault is still TBD (although it's probably mine -- perhaps 160Kb diskettes aren't
* supposed to have BPBs?) The simple work-around is to avoid creating 160Kb diskette images used by PC DOS 1.0.
* To play it safe, I also skip the 320Kb format (added for PC DOS 1.1). 360Kb was the most commonly used format
* after PC DOS 2.0 introduced it. PC DOS 2.0 also introduced 180Kb (a single-sided version of the 360Kb
* double-sided format), but it's less commonly used.
*
* UPDATE: I've undone the above change, because when creating a disk image for an old application like:
*
* /apps/pcx86/1983/adventmath ["Adventures in Math (1983)"]
*
* it's important to create a disk image that will work with PC DOS 1.0, which didn't understand 180Kb and 360Kb
* disk images.
*/
for (iBPB = 0; iBPB < DiskInfo.aDefaultBPBs.length; iBPB++) {
/*
* Use slice() to copy the BPB, to ensure we don't alter the original.
*/
abBoot = DiskInfo.aDefaultBPBs[iBPB].slice();
/*
* If this BPB is for a hard drive but a disk size was not specified, skip it.
*/
if ((abBoot[DiskInfo.BPB.MEDIA] == DiskInfo.FAT.MEDIA_FIXED) != (kbTarget >= 10000)) continue;
cRootEntries = abBoot[DiskInfo.BPB.DIRENTS] | (abBoot[DiskInfo.BPB.DIRENTS + 1] << 8);
if (aFileData.length > cRootEntries) continue;
cbSector = abBoot[DiskInfo.BPB.SECBYTES] | (abBoot[DiskInfo.BPB.SECBYTES + 1] << 8);
cSectorsPerCluster = abBoot[DiskInfo.BPB.CLUSSECS];
cbCluster = cbSector * cSectorsPerCluster;
cFATs = abBoot[DiskInfo.BPB.FATS];
cFATSectors = abBoot[DiskInfo.BPB.FATSECS] | (abBoot[DiskInfo.BPB.FATSECS + 1] << 8);
cRootSectors = (((cRootEntries * DiskInfo.DIRENT.LENGTH) + cbSector - 1) / cbSector) | 0;
cTotalSectors = abBoot[DiskInfo.BPB.DISKSECS] | (abBoot[DiskInfo.BPB.DISKSECS + 1] << 8);
cHiddenSectors = abBoot[DiskInfo.BPB.HIDDENSECS] | (abBoot[DiskInfo.BPB.HIDDENSECS + 1] << 8);
cSectorsPerTrack = abBoot[DiskInfo.BPB.TRACKSECS] | (abBoot[DiskInfo.BPB.TRACKSECS + 1] << 8);
cHeads = abBoot[DiskInfo.BPB.DRIVEHEADS] | (abBoot[DiskInfo.BPB.DRIVEHEADS + 1] << 8);
cDataSectors = cTotalSectors - (cRootSectors + cFATs * cFATSectors + 1);
cbAvail = cDataSectors * cbSector;
if (!nTargetSectors || cHiddenSectors) {
if (cbTotal <= cbAvail) {
let cb = this.calcFileSizes(aFileData, cSectorsPerCluster);
if (cb <= cbAvail) {
cbTotal = cb;
break;
}
}
} else {
if (cTotalSectors == nTargetSectors) break;
}
}
if (iBPB == DiskInfo.aDefaultBPBs.length) {
this.printf(Device.MESSAGE.DISK + Device.MESSAGE.ERROR, "too many file(s) for disk image (%d files, %d bytes)\n", aFileData.length, cbTotal);
return false;
}
let abSector;
let offDisk = 0;
let cbDisk = cTotalSectors * cbSector;
/*
* If the disk is actually a partition on a larger drive, calculate how much larger the image should be
* (ie, hidden sectors plus an entire cylinder reserved for diagnostics, head parking, etc).
*/
let cbDrive = (cHiddenSectors? (cHiddenSectors + cSectorsPerTrack * cHeads) * cbSector : 0) + cbDisk;
/*
* TODO: Consider doing what (the old) convertToIMG() did, which was deferring setting dbDisk until the
* buffer is fully (and successfully) initialized. Here, however, the build process relies on worker
* functions that prefer not passing around temporary buffers. In the meantime, perhaps any catastrophic
* failures should set dbDisk back to null?
*/
dbDisk.new(cbDrive);
/*
* WARNING: Buffers are NOT zero-initialized, so we need explicitly fill dbDisk with zeros (this seems
* to be a reversal in the trend to zero buffers, when security concerns would trump performance concerns).
*/
dbDisk.fill(0);
/*
* Output a Master Boot Record (MBR) if this is a hard drive image.
*/
if (cHiddenSectors) {
abSector = this.buildMBR(cHeads, cSectorsPerTrack, cbSector, cTotalSectors);
offDisk += this.copyData(dbDisk, offDisk, abSector) * cHiddenSectors;
}
/*
* Output a boot sector.
*/
abBoot[DiskInfo.BOOT.SIG_OFFSET] = DiskInfo.BOOT.SIGNATURE & 0xff; // 0x55
abBoot[DiskInfo.BOOT.SIG_OFFSET + 1] = (DiskInfo.BOOT.SIGNATURE >> 8) & 0xff; // 0xAA
abSector = this.buildData(cbSector, abBoot);
offDisk += this.copyData(dbDisk, offDisk, abSector);
/*
* Build the FAT, noting the starting cluster number that each file will use along the way.
*
* Also, notice that the first byte of the FAT is the "media ID" byte that's replicated in the
* BPB at offset 0x15. For old BPB-less diskettes, this is where you must look for the media ID.
*/
let abFAT = [];
this.buildFATEntry(abFAT, 0, abBoot[DiskInfo.BPB.MEDIA] | 0xF00);
this.buildFATEntry(abFAT, 1, 0xFFF);
this.buildFAT(abFAT, aFileData, 2, cbCluster);
/*
* Output the FAT sectors; we simplify the logic a bit by writing each FAT table as if it
* were one giant sector.
*/
while (cFATs--) {
abSector = this.buildData(cFATSectors * cbSector, abFAT);
offDisk += this.copyData(dbDisk, offDisk, abSector);
}
/*
* Build the root directory
*/
let abRoot = [];
let cEntries = this.buildDir(abRoot, aFileData);
/*
* PC DOS 1.x requires ALL unused directory entries to start with 0xE5; 0x00 isn't good enough,
* so we must loop through all the remaining directory entries and zap them with 0xE5.
*
* However, we do this ONLY for the first two BPB types (160K and 320K diskettes), since those are
* the only formats PC DOS 1.x understood.
*/
if (iBPB < 2) {
let offRoot = cEntries * DiskInfo.DIRENT.LENGTH;
while (cEntries++ < cRootEntries) {
abRoot[offRoot] = DiskInfo.DIRENT.INVALID; // 0xE5
offRoot += DiskInfo.DIRENT.LENGTH; // 0x20 (32)
}
}
/*
* Output the root directory sectors (as before, as if they were one giant sector)
*/
abSector = this.buildData(cRootSectors * cbSector, abRoot);
offDisk += this.copyData(dbDisk, offDisk, abSector);
/*
* Output the file data clusters, which must be stored sequentially, mirroring the order in which
* we wrote the cluster sequences to the FAT, above.
*/
let cClusters = this.buildClusters(dbDisk, aFileData, offDisk, cbCluster, 0, 0);
offDisk += cClusters * cSectorsPerCluster * cbSector;
this.printf(Device.MESSAGE.DISK + Device.MESSAGE.INFO, "%d bytes written, %d bytes available\n", offDisk, cbDisk);
if (offDisk > cbDisk) {
this.printf(Device.MESSAGE.DISK + Device.MESSAGE.ERROR, "too much data for disk image (%d clusters required)\n", cClusters);
return false;
}
return this.buildDiskFromBuffer(dbDisk);
}
/**
* calcFileSizes(aFileData, cSectorsPerCluster)
*
* @this {DiskInfo}
* @param {Array.<FileData>} aFileData
* @param {number} [cSectorsPerCluster] (default is 1)
* @returns {number} of bytes required for all files, including all subdirectories
*/
calcFileSizes(aFileData, cSectorsPerCluster)
{
let cbTotal = 0;
let cbCluster = (cSectorsPerCluster || 1) * 512;
for (let iFile = 0; iFile < aFileData.length; iFile++) {
let cb = aFileData[iFile].size;
let cbSubTotal = 0;
if (cb < 0) {
cb = (aFileData[iFile].files.length + 2) * 32;
cbSubTotal = this.calcFileSizes(aFileData[iFile].files, cSectorsPerCluster);
}
cbTotal += cb;
if ((cb %= cbCluster)) {
cbTotal += cbCluster - cb;
}
cbTotal += cbSubTotal;
}
return cbTotal;
}
/**
* buildData(cb)
*
* @this {DiskInfo}
* @param {number} cb
* @param {Array.<number>} [abInit]
* @returns {Array.<number>} of bytes, initialized with abInit (or with zero when abInit is empty or exhausted)
*/
buildData(cb, abInit)
{
let ab = new Array(cb);
for (let i = 0; i < cb; i++) {
ab[i] = abInit && abInit[i] || 0;
}
return ab;
}
/**
* copyData(db, offset, ab)
*
* @this {DiskInfo}
* @param {BufferData} db
* @param {number} offset
* @param {Array.<number>} ab
* @returns {number} number of bytes written
*/
copyData(db, offset, ab)
{
db.fill(ab, offset, offset + ab.length);
return ab.length;
}
/**
* buildClusters(dbDisk, aFileData, offDisk, cbCluster, iParentCluster, done)
*
* @this {DiskInfo}
* @param {DataBuffer} dbDisk
* @param {Array.<FileData>} aFileData
* @param {number} offDisk
* @param {number} cbCluster
* @param {number} iParentCluster
* @param {number} iLevel
* @param {function(Error)} done
* @returns {number} number of clusters built
*/
buildClusters(dbDisk, aFileData, offDisk, cbCluster, iParentCluster, iLevel)
{
let cSubDirs = 0;
let cClusters = 0;
for (let iFile = 0; iFile < aFileData.length; iFile++) {
let dbData = aFileData[iFile].data;
let cbData = aFileData[iFile].size;
if (cbData > 0) {
this.assert(cbData == dbData.length);
}
else if (cbData < 0) {
let abData = [];
cbData = this.buildDir(abData, aFileData[iFile].files, aFileData[iFile].date, aFileData[iFile].cluster, iParentCluster) * 32;
dbData.new(cbData);
dbData.fill(abData);
cSubDirs++;
}
if (cbData) {
dbData.copy(dbDisk, offDisk);
if (Device.DEBUG) this.printf(Device.MESSAGE.DISK + Device.MESSAGE.INFO, "%#x: %#x bytes written for %s\n", offDisk, dbData.length, aFileData[iFile].path);
}
offDisk += cbData;
cClusters += ((cbData / cbCluster) | 0);