-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFDISK.PAS
More file actions
1950 lines (1882 loc) · 57.6 KB
/
Copy pathFDISK.PAS
File metadata and controls
1950 lines (1882 loc) · 57.6 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
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2022
@website(https://www.gladir.com/corail)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program FDISK;
{$A-}
Uses Crt,DOS;
Type
{Structure de lecture pour le disque }
SecPosType=Record
Head:Byte;
SectTrack:Word;
End;
{Structure de partition}
PartEntry=Record
Status:Byte;
StartSec:SecPosType;
PartType:Byte;
EndSec:SecPosType;
SecOfs,NumSec:LongInt;
End;
PartSec=Record { d‚crit le secteur de partition }
BootCode:Array[0..$1BD]of Byte; { Code de d‚marrage du disque dur }
PartTable:Array[0..3]of PartEntry; { Table des partitions de disque dur }
IdCode:Word; { Signature: AA55h }
End;
Var
Language:(_French,_English,_Germany,_Italian,_Spain);
TmpLanguage:String;
CurrentDisk:Byte;
IsDisk:Boolean;
FileName:String;
Buffer:Array[0..1023]of Byte;
CliI:Byte;
CliJ,CliCode:Integer;
{ Format d'image detecte : raw, VHD fixe, VHD dynamique ou VMDK sparse. }
VHDKind:(_VHDNone,_VHDFixed,_VHDDynamic,_VMDKSparse);
VHDDiskSec:LongInt; { Taille virtuelle en secteurs }
VHDBlockSizeSec:LongInt; { Sectors per block (VHD dyn) / per grain (VMDK) }
VHDBitmapSecs:LongInt; { Secteurs occupes par le bitmap (VHD dyn) }
VHDBATFileOfs:LongInt; { Offset fichier de la BAT (VHD) / GD (VMDK) }
VMDKGTEsPerGT:LongInt; { Nombre d'entrees par grain table (VMDK) }
FsHint:Byte; { Hint dernier ParsePartType : 0=none 1=NTFS 2=HPFS }
Procedure DiskReset;
{$IFDEF Windows}
Begin
WriteLn('Cette operation n''est pas mise en oeuvre.');
Halt;
End;
{$ElSE}
Var
Regs:Registers;
Begin
Regs.AH:=$00;
Regs.DL:=0;
Intr($13,Regs);
End;
{$ENDIF}
Function ReadTrack(Lecteur,Face,Piste,Start,Nombre:Byte;Var Buffer):Byte;
{$IFDEF Windows}
Begin
WriteLn('Cette operation n''est pas mise en oeuvre.');
Halt;
End;
{$ElSE}
Var
Essais:Byte;
Regs:Registers;
Begin
essais:=5;
Repeat
WriteLn(Essais);
Regs.AH:=$02; { Numero de fonction pour appel interruption }
Regs.AL:=Nombre; { Nombre Secteurs par Piste }
Regs.CH:=Piste; { Numero de Piste }
Regs.CL:=Start; { Commencer par le secteur 1 }
Regs.DL:=Lecteur; { Numero de lecteur }
Regs.DH:=Face; { Numero de la face }
Regs.ES:=Seg(Buffer);{ Adresse pour tampon }
Regs.BX:=Ofs(Buffer);
Intr($13,Regs);
If Regs.flags and fcarry=1Then DiskReset;
Dec(essais);
Until(Regs.flags and fcarry=0)or(Essais=0);
ReadTrack:=Regs.AH;
End;
{$ENDIF}
Function WriteTrack(Lecteur,Face,Piste,Start,Nombre:Byte;Var Buffer):Byte;
{$IFDEF Windows}
Begin
WriteLn('Cette operation n''est pas mise en oeuvre.');
Halt;
End;
{$ElSE}
Var
Essais:Byte;
Regs:Registers;
Begin
essais:=5;
Repeat
Regs.AH:=$03; { Numero de fonction pour appel interruption }
Regs.AL:=Nombre; { Nombre Secteurs par Piste }
Regs.CH:=Piste; { Numero de Piste }
Regs.CL:=Start; { Commencer par le secteur 1 }
Regs.DL:=Lecteur; { Numero de lecteur }
Regs.DH:=Face; { Numero de la face }
Regs.ES:=Seg(Buffer);{ Adresse pour tampon }
Regs.BX:=Ofs(Buffer);
Intr($13,Regs);
If Regs.flags and fcarry=1Then DiskReset;
Dec(essais);
Until(Regs.flags and fcarry=0)or(Essais=0);
WriteTrack:=Regs.AH;
End;
{$ENDIF}
Function StrToUpper(S:String):String;
Var
I:Byte;
Begin
For I:=1 to Length(S)do Begin
If S[I] in['a'..'z']Then S[I]:=Chr(Ord(S[I])-32);
End;
StrToUpper:=S;
End;
Function PadRight(S:String;Space:Byte):String;
Var
I:Byte;
Begin
If Length(S)<Space Then For I:=Length(S)+1 to Space do S:=S+' ';
PadRight:=S;
End;
Procedure WriteLnCenter(S:String);Begin
GotoXY((((Lo(WindMax)-Lo(WindMin))-Length(S))shr 1),WhereY);
WriteLn(S);
End;
{ Detecte le format de l'image (raw, VHD fixe, VHD dynamique, VMDK sparse,
ou VMDK descripteur texte). A appeler apres chaque changement de FileName. }
{$R-}
Procedure DetectImageFormat;
Var
F:File;
Sec:Array[0..511]of Byte;
BR:Word;
Sz,BlockSize,BAToff,CurSize:LongInt;
DiskType:LongInt;
I,J,K:Integer;
S,ExtName,DescDir:String;
ExtSecs,ExtOfs:LongInt;
Code:Integer;
Function ReadLE32(Ofs:Integer):LongInt;
Begin
ReadLE32:=LongInt(Sec[Ofs])
Or(LongInt(Sec[Ofs+1])Shl 8)
Or(LongInt(Sec[Ofs+2])Shl 16)
Or(LongInt(Sec[Ofs+3])Shl 24);
End;
Begin
VHDKind:=_VHDNone;
VHDDiskSec:=0;
VHDBlockSizeSec:=0;
VHDBitmapSecs:=0;
VHDBATFileOfs:=0;
VMDKGTEsPerGT:=0;
If FileName='' Then Exit;
{$I-}Assign(F,FileName);Reset(F,1);{$I+}
If IOResult<>0 Then Exit;
{ Lecture du secteur 0 pour detection VMDK ou descripteur texte. }
FillChar(Sec,SizeOf(Sec),0);
{$I-}BlockRead(F,Sec,512,BR);{$I+}
If IOResult<>0 Then Begin Close(F); Exit; End;
{ Tolere BR<512 pour les fichiers descripteurs courts }
If BR=0 Then Begin Close(F); Exit; End;
{ ===== VMDK sparse : magic 'KDMV' (0x564D444B little-endian) ===== }
If(Sec[0]=$4B)And(Sec[1]=$44)And(Sec[2]=$4D)And(Sec[3]=$56)Then Begin
{ Capacity @ +12 (8 LE, low 32 @ +12..+15) }
VHDDiskSec:=ReadLE32(12);
{ GrainSize @ +20 (8 LE, low 32 @ +20..+23) }
VHDBlockSizeSec:=ReadLE32(20);
If(VHDBlockSizeSec<=0)Then Begin Close(F); Exit; End;
{ NumGTEsPerGT @ +44 (4 LE) }
VMDKGTEsPerGT:=ReadLE32(44);
If(VMDKGTEsPerGT<=0)Then Begin Close(F); Exit; End;
{ GDOffset @ +56 (8 LE) -- offset en SECTEURS }
BAToff:=ReadLE32(56);
If BAToff<=0 Then BAToff:=ReadLE32(48); { fallback : RGDOffset }
If BAToff<=0 Then Begin Close(F); Exit; End;
VHDBATFileOfs:=BAToff*512;
VHDKind:=_VMDKSparse;
Close(F);
Exit;
End;
{ ===== VMDK descripteur texte : commence par '# Disk DescriptorFile'
ou contient 'createType=' et lignes 'RW <N> FLAT "..."' ===== }
If(Sec[0]=$23)Or((Sec[0]>=Ord('A'))And(Sec[0]<=Ord('z')))Then Begin
{ Construire chaine depuis le secteur (jusqu'a 511 chars) }
S:='';
For I:=0 To 511 Do
If(Sec[I]>=32)Or(Sec[I]=10)Or(Sec[I]=13)Or(Sec[I]=9)Then
S:=S+Chr(Sec[I])
Else
S:=S+' ';
{ Cherche un marqueur 'Disk DescriptorFile' ou 'createType' }
I:=Pos('DescriptorFile',S);
If I=0 Then I:=Pos('createType',S);
If I=0 Then I:=Pos('# Disk',S);
If I>0 Then Begin
{ Cherche ligne 'RW <N> FLAT "nom"' }
I:=Pos('RW ',S);
If(I>0)And(Pos('FLAT',S)>I)Then Begin
{ Extraire nombre apres 'RW ' }
K:=I+3;
While(K<=Length(S))And(S[K]=' ')Do Inc(K);
ExtName:='';
While(K<=Length(S))And(S[K] in['0'..'9'])Do Begin
ExtName:=ExtName+S[K]; Inc(K);
End;
Val(ExtName,ExtSecs,Code);
If Code<>0 Then ExtSecs:=0;
{ Trouver '"' ouvrante apres FLAT }
I:=Pos('FLAT',S);
K:=I+4;
While(K<=Length(S))And(S[K]<>'"')Do Inc(K);
If(K<Length(S))And(S[K]='"')Then Begin
Inc(K);
ExtName:='';
While(K<=Length(S))And(S[K]<>'"')Do Begin
ExtName:=ExtName+S[K]; Inc(K);
End;
{ Offset (apres '"') }
If S[K]='"' Then Inc(K);
While(K<=Length(S))And(S[K]=' ')Do Inc(K);
DescDir:='';
While(K<=Length(S))And(S[K] in['0'..'9'])Do Begin
DescDir:=DescDir+S[K]; Inc(K);
End;
Val(DescDir,ExtOfs,Code);
If Code<>0 Then ExtOfs:=0;
Close(F);
{ Resoudre chemin relatif a la position du descripteur }
DescDir:=FileName;
J:=Length(DescDir);
While(J>0)And(DescDir[J]<>'\')And(DescDir[J]<>'/')And(DescDir[J]<>':')Do Dec(J);
DescDir:=Copy(DescDir,1,J);
{ Si ExtName n'a pas de chemin absolu, prefixer }
If(Pos(':',ExtName)=0)And(Length(ExtName)>0)And
(ExtName[1]<>'\')And(ExtName[1]<>'/')Then
ExtName:=DescDir+ExtName;
{ Bascule sur le fichier d'extension brut (raw flat) }
FileName:=ExtName;
VHDDiskSec:=ExtSecs;
{ Re-detection au cas ou l'extension serait elle-meme VHD/VMDK }
DetectImageFormat;
Exit;
End;
End;
Close(F);
Exit;
End;
End;
{ ===== VHD : footer 'conectix' aux 512 derniers octets ===== }
Sz:=FileSize(F);
If(Sz<1024)Or(Sz<0)Then Begin Close(F); Exit; End;
{$I-}Seek(F,Sz-512);{$I+}
If IOResult<>0 Then Begin Close(F); Exit; End;
{$I-}BlockRead(F,Sec,512,BR);{$I+}
If(IOResult<>0)Or(BR<>512)Then Begin Close(F); Exit; End;
{ Cookie 'conectix' }
If(Sec[0]<>$63)Or(Sec[1]<>$6F)Or(Sec[2]<>$6E)Or(Sec[3]<>$65)Or
(Sec[4]<>$63)Or(Sec[5]<>$74)Or(Sec[6]<>$69)Or(Sec[7]<>$78)Then Begin
Close(F); Exit;
End;
{ DiskType (4 BE) @ +60 : 2=fixe, 3=dynamique, 4=differencing }
DiskType:=(LongInt(Sec[60])Shl 24)Or(LongInt(Sec[61])Shl 16)
Or(LongInt(Sec[62])Shl 8)Or LongInt(Sec[63]);
{ CurrentSize (8 BE) @ +48 : on prend les 32 bits bas (offset +52..+55) }
CurSize:=(LongInt(Sec[52])Shl 24)Or(LongInt(Sec[53])Shl 16)
Or(LongInt(Sec[54])Shl 8)Or LongInt(Sec[55]);
VHDDiskSec:=CurSize Div 512;
Case DiskType Of
2:Begin VHDKind:=_VHDFixed; Close(F); Exit; End;
3,4:Begin
{ Dynamic header @ offset 512 }
{$I-}Seek(F,512);{$I+}
If IOResult<>0 Then Begin Close(F); Exit; End;
{$I-}BlockRead(F,Sec,512,BR);{$I+}
If(IOResult<>0)Or(BR<>512)Then Begin Close(F); Exit; End;
{ Cookie 'cxsparse' }
If(Sec[0]<>$63)Or(Sec[1]<>$78)Or(Sec[2]<>$73)Or(Sec[3]<>$70)Or
(Sec[4]<>$61)Or(Sec[5]<>$72)Or(Sec[6]<>$73)Or(Sec[7]<>$65)Then Begin
Close(F); Exit;
End;
{ TableOffset (8 BE) @ +16, low 32 bits @ +20..+23 }
BAToff:=(LongInt(Sec[20])Shl 24)Or(LongInt(Sec[21])Shl 16)
Or(LongInt(Sec[22])Shl 8)Or LongInt(Sec[23]);
{ BlockSize (4 BE) @ +32 (typique : 2 MB = 2097152) }
BlockSize:=(LongInt(Sec[32])Shl 24)Or(LongInt(Sec[33])Shl 16)
Or(LongInt(Sec[34])Shl 8)Or LongInt(Sec[35]);
If(BlockSize=0)Or(BlockSize Mod 512<>0)Then Begin Close(F); Exit; End;
VHDBlockSizeSec:=BlockSize Div 512;
{ Bitmap = block_size/512 bits, rounded up to secteur entier }
VHDBitmapSecs:=((VHDBlockSizeSec Div 8)+511)Div 512;
If VHDBitmapSecs<1 Then VHDBitmapSecs:=1;
VHDBATFileOfs:=BAToff;
VHDKind:=_VHDDynamic;
Close(F); Exit;
End;
End;
Close(F);
End;
{$R+}
{ Traduit un LBA virtuel en offset fichier (octets) selon le format.
Pour un bloc VHD dynamique non alloue : retourne -1 (lecture = zeros). }
Function VHDFileOffset(LBA:LongInt):LongInt;
Var
F:File;
BR:Word;
BlockIdx,OfsInBlock,BATEntry:LongInt;
GrainNum,GTIdx,GTOff,GTSec,GrainSec:LongInt;
BATBuf:Array[0..3]of Byte;
Begin
If(VHDKind=_VHDNone)Or(VHDKind=_VHDFixed)Then Begin
VHDFileOffset:=LBA*512;
Exit;
End;
VHDFileOffset:=-1;
If VHDKind=_VMDKSparse Then Begin
{ Lookup 2-niveaux : GrainDir -> GrainTable -> grain
GrainNum = LBA / GrainSize ; GTIdx = GrainNum / GTEsPerGT
GTOff = GrainNum mod GTEsPerGT. Toutes les entrees sont en
sectors LE 32-bit. 0 = non alloue. }
GrainNum:=LBA Div VHDBlockSizeSec;
GTIdx:=GrainNum Div VMDKGTEsPerGT;
GTOff:=GrainNum Mod VMDKGTEsPerGT;
OfsInBlock:=LBA Mod VHDBlockSizeSec;
{$I-}Assign(F,FileName);Reset(F,1);{$I+}
If IOResult<>0 Then Exit;
{ Lire GD[GTIdx] (4 octets LE) }
{$I-}Seek(F,VHDBATFileOfs+GTIdx*4);{$I+}
If IOResult<>0 Then Begin Close(F); Exit; End;
{$I-}BlockRead(F,BATBuf,4,BR);{$I+}
If(IOResult<>0)Or(BR<>4)Then Begin Close(F); Exit; End;
GTSec:=LongInt(BATBuf[0])Or(LongInt(BATBuf[1])Shl 8)
Or(LongInt(BATBuf[2])Shl 16)Or(LongInt(BATBuf[3])Shl 24);
If GTSec=0 Then Begin Close(F); Exit; End;
{ Lire GT[GTOff] }
{$I-}Seek(F,GTSec*512+GTOff*4);{$I+}
If IOResult<>0 Then Begin Close(F); Exit; End;
{$I-}BlockRead(F,BATBuf,4,BR);{$I+}
Close(F);
If(BR<>4)Then Exit;
GrainSec:=LongInt(BATBuf[0])Or(LongInt(BATBuf[1])Shl 8)
Or(LongInt(BATBuf[2])Shl 16)Or(LongInt(BATBuf[3])Shl 24);
If GrainSec=0 Then Exit;
VHDFileOffset:=GrainSec*512+OfsInBlock*512;
Exit;
End;
{ VHD dynamique }
BlockIdx:=LBA Div VHDBlockSizeSec;
OfsInBlock:=LBA Mod VHDBlockSizeSec;
{$I-}Assign(F,FileName);Reset(F,1);{$I+}
If IOResult<>0 Then Exit;
{$I-}Seek(F,VHDBATFileOfs+BlockIdx*4);{$I+}
If IOResult<>0 Then Begin Close(F); Exit; End;
{$I-}BlockRead(F,BATBuf,4,BR);{$I+}
Close(F);
If(BR<>4)Then Exit;
BATEntry:=(LongInt(BATBuf[0])Shl 24)Or(LongInt(BATBuf[1])Shl 16)
Or(LongInt(BATBuf[2])Shl 8)Or LongInt(BATBuf[3]);
If BATEntry=-1 Then Exit; { bloc non alloue }
VHDFileOffset:=(BATEntry+VHDBitmapSecs)*512+OfsInBlock*512;
End;
{ Lit un secteur (512 octets) depuis l'image fichier.
Retourne True si OK. Buf doit contenir au moins 512 octets. }
Function ReadImgSector(LBA:LongInt;Var Buf):Boolean;
Var
F:File;
BR:Word;
FileOfs:LongInt;
Begin
ReadImgSector:=False;
If FileName='' Then Exit;
FileOfs:=VHDFileOffset(LBA);
If FileOfs=-1 Then Begin
{ VHD dynamique : bloc non alloue, secteur virtuel = zeros }
FillChar(Buf,512,0);
ReadImgSector:=True;
Exit;
End;
{$I-}Assign(F,FileName);Reset(F,1);{$I+}
If IOResult<>0 Then Exit;
{$I-}Seek(F,FileOfs);{$I+}
If IOResult<>0 Then Begin Close(F);Exit;End;
{$I-}BlockRead(F,Buf,512,BR);{$I+}
Close(F);
ReadImgSector:=(IOResult=0)And(BR=512);
End;
{ Ecrit un secteur (512 octets) dans l'image fichier.
Pour VHD dynamique : echoue si le bloc n'est pas alloue (allocation
non implementee). Retourne True si OK. }
Function WriteImgSector(LBA:LongInt;Var Buf):Boolean;
Var
F:File;
BW:Word;
FileOfs:LongInt;
Begin
WriteImgSector:=False;
If FileName='' Then Exit;
FileOfs:=VHDFileOffset(LBA);
If FileOfs=-1 Then Exit; { bloc VHD non alloue : ne pas reecrire }
{$I-}Assign(F,FileName);Reset(F,1);{$I+}
If IOResult<>0 Then Exit;
{$I-}Seek(F,FileOfs);{$I+}
If IOResult<>0 Then Begin Close(F);Exit;End;
{$I-}BlockWrite(F,Buf,512,BW);{$I+}
Close(F);
WriteImgSector:=(IOResult=0)And(BW=512);
End;
Procedure ReadPartitionRecord;
Var
Partition:File;
ByteReaded:Word;
Begin
If(IsDisk)Then Begin
ReadTrack($80+CurrentDisk-1,0,0,1,1,Buffer);
End
Else
If FileName<>''Then Begin
{ VHD ou raw : passer par ReadImgSector qui gere la traduction }
If VHDKind<>_VHDNone Then Begin
ReadImgSector(0,Buffer);
Exit;
End;
{$I-}Assign(Partition,FileName);
Reset(Partition,1);{$I+}
If IOResult=0 Then Begin
BlockRead(Partition,Buffer,512,ByteReaded);
Close(Partition);
End;
End;
End;
Procedure WritePartitionRecord;
Var
Partition:File;
ByteReaded:Word;
Begin
If(IsDisk)Then Begin
WriteTrack($80+CurrentDisk-1,0,0,1,1,Buffer);
End
Else
If FileName<>''Then Begin
{ VHD ou raw : passer par WriteImgSector qui gere la traduction }
If VHDKind<>_VHDNone Then Begin
If Not WriteImgSector(0,Buffer)Then
WriteLn('Erreur : ecriture VHD echouee (bloc non alloue ?).');
Exit;
End;
{$I-}Assign(Partition,FileName);
Reset(Partition,1);{$I+}
If IOResult=0 Then Begin
BlockWrite(Partition,Buffer,512,ByteReaded);
Close(Partition);
End;
End;
End;
{ Geometrie du disque physique courant (caches une fois lue). }
Var
GeoValid:Boolean;
GeoHeads,GeoSPT:Word;
{$IFNDEF Windows}
Procedure FetchGeometry;
Var Regs:Registers;
Begin
If GeoValid Then Exit;
Regs.AH:=$08;
Regs.DL:=$80+CurrentDisk-1;
Intr($13,Regs);
If(Regs.Flags and FCarry)=0 Then Begin
GeoHeads:=Regs.DH+1;
GeoSPT:=Regs.CL and $3F;
If(GeoHeads>0)And(GeoSPT>0)Then GeoValid:=True;
End;
End;
{$ENDIF}
{ Lit un secteur (512 octets) en LBA depuis le disque physique courant.
Retourne True si OK. }
Function ReadDiskLBA(LBA:LongInt;Var Buf):Boolean;
{$IFDEF Windows}
Begin ReadDiskLBA:=False; End;
{$ELSE}
Var
Cyl,Head,Sect:Word;
Tmp:LongInt;
Status:Byte;
Begin
ReadDiskLBA:=False;
FetchGeometry;
If Not GeoValid Then Exit;
{ LBA = ((Cyl*Heads) + Head) * SPT + Sect - 1 }
Sect:=Word(LBA Mod GeoSPT)+1;
Tmp:=LBA Div GeoSPT;
Head:=Word(Tmp Mod GeoHeads);
Cyl:=Word(Tmp Div GeoHeads);
If Cyl>1023 Then Exit; { au-dela de la limite CHS BIOS }
Status:=ReadTrack($80+CurrentDisk-1,Head,Byte(Cyl),Byte(Sect),1,Buf);
ReadDiskLBA:=(Status=0);
End;
{$ENDIF}
{ Lit un secteur depuis l'image OU le disque selon le mode courant. }
Function ReadSector(LBA:LongInt;Var Buf):Boolean;
Begin
If FileName<>'' Then ReadSector:=ReadImgSector(LBA,Buf)
Else ReadSector:=ReadDiskLBA(LBA,Buf);
End;
{ Ecrit un secteur (512 octets) en LBA sur le disque physique courant. }
Function WriteDiskLBA(LBA:LongInt;Var Buf):Boolean;
{$IFDEF Windows}
Begin WriteDiskLBA:=False; End;
{$ELSE}
Var
Cyl,Head,Sect:Word;
Tmp:LongInt;
Status:Byte;
Begin
WriteDiskLBA:=False;
FetchGeometry;
If Not GeoValid Then Exit;
Sect:=Word(LBA Mod GeoSPT)+1;
Tmp:=LBA Div GeoSPT;
Head:=Word(Tmp Mod GeoHeads);
Cyl:=Word(Tmp Div GeoHeads);
If Cyl>1023 Then Exit;
Status:=WriteTrack($80+CurrentDisk-1,Head,Byte(Cyl),Byte(Sect),1,Buf);
WriteDiskLBA:=(Status=0);
End;
{$ENDIF}
{ Ecrit un secteur dans l'image OU sur le disque selon le mode courant. }
Function WriteSector(LBA:LongInt;Var Buf):Boolean;
Begin
If FileName<>'' Then WriteSector:=WriteImgSector(LBA,Buf)
Else WriteSector:=WriteDiskLBA(LBA,Buf);
End;
{ Recupere le nom de volume d'une partition FAT12/16/32, HPFS ou NTFS.
Retourne une chaine vide si introuvable. }
Function GetVolumeLabel(Const PE:PartEntry):String;
Var
Sec:Array[0..511] of Byte;
BytesPerSec,RsvdSec,RootEntCnt,SecPerClus:Word;
SecPerFAT,TotSec:LongInt;
NumFATs:Byte;
FATType:Byte;
DataSec,TotClus,RootStart,RootSecs:LongInt;
RootClus:LongInt;
FirstDataSec:LongInt;
I,J,K,LblOfs:Word;
Lbl:String;
Found:Boolean;
MftLCN,RecSize,MftLBA:LongInt;
ClPerRec:ShortInt;
RecSizeSec:LongInt;
UsaOfs,AttrOfs,ContentOfs,ContentLen:Word;
AttrLen:Word;
AttrType:LongInt;
NonRes,C:Byte;
Begin
GetVolumeLabel:='';
If Not ReadSector(PE.SecOfs,Sec) Then Exit;
{ ----- NTFS : signature 'NTFS ' a l'offset 3 ----- }
If(Sec[3]=$4E)And(Sec[4]=$54)And(Sec[5]=$46)And(Sec[6]=$53)Then Begin
BytesPerSec:=Word(Sec[11])Or(Word(Sec[12])Shl 8);
SecPerClus:=Sec[13];
If(BytesPerSec=0)Or(SecPerClus=0)Then Exit;
{ MFT LCN @ offset 48 (8 octets, on prend les 32 bits bas) }
MftLCN:=LongInt(Sec[48])Or(LongInt(Sec[49])Shl 8)
Or(LongInt(Sec[50])Shl 16)Or(LongInt(Sec[51])Shl 24);
{ Octets/clusters par enregistrement MFT @ offset 64 (octet signe) }
ClPerRec:=ShortInt(Sec[64]);
If ClPerRec>=0 Then
RecSize:=LongInt(ClPerRec)*SecPerClus*BytesPerSec
Else
RecSize:=LongInt(1)Shl(-ClPerRec);
If(RecSize<512)Or(BytesPerSec=0)Then Exit;
RecSizeSec:=RecSize Div BytesPerSec;
{ Enregistrement MFT n3 = $Volume }
MftLBA:=PE.SecOfs+MftLCN*SecPerClus+3*RecSizeSec;
If Not ReadSector(MftLBA,Sec) Then Exit;
{ Magic 'FILE' }
If(Sec[0]<>$46)Or(Sec[1]<>$49)Or(Sec[2]<>$4C)Or(Sec[3]<>$45)Then Exit;
{ Fixup du 1er secteur : USA @ offset 4 (word) ; remplacer les 2 derniers
octets du secteur par USA[1] (les 2 octets juste apres le USN). }
UsaOfs:=Word(Sec[4])Or(Word(Sec[5])Shl 8);
If UsaOfs+4<=510 Then Begin
Sec[510]:=Sec[UsaOfs+2];
Sec[511]:=Sec[UsaOfs+3];
End;
{ Premier attribut @ offset $14 (word) }
AttrOfs:=Word(Sec[$14])Or(Word(Sec[$15])Shl 8);
While AttrOfs+8<512 Do Begin
AttrType:=LongInt(Sec[AttrOfs])Or(LongInt(Sec[AttrOfs+1])Shl 8)
Or(LongInt(Sec[AttrOfs+2])Shl 16)Or(LongInt(Sec[AttrOfs+3])Shl 24);
If AttrType=-1 Then Exit; { fin de la liste d'attributs }
AttrLen:=Word(Sec[AttrOfs+4])Or(Word(Sec[AttrOfs+5])Shl 8);
If AttrLen=0 Then Exit;
If AttrType=$60 Then Begin
{ $VOLUME_NAME : resident attendu }
NonRes:=Sec[AttrOfs+8];
If NonRes=0 Then Begin
ContentLen:=Word(Sec[AttrOfs+16])Or(Word(Sec[AttrOfs+17])Shl 8);
ContentOfs:=Word(Sec[AttrOfs+20])Or(Word(Sec[AttrOfs+21])Shl 8);
{ Contenu = UTF-16LE, on prend seulement le byte bas (ASCII) }
Lbl:='';
I:=0;
While(I<ContentLen)And(AttrOfs+ContentOfs+I+1<512)Do Begin
C:=Sec[AttrOfs+ContentOfs+I];
If C>=32 Then Lbl:=Lbl+Chr(C);
Inc(I,2);
End;
GetVolumeLabel:=Lbl;
End;
Exit;
End;
Inc(AttrOfs,AttrLen);
End;
Exit;
End;
{ ----- HPFS : signature au superbloc, LBA partition + 16 ----- }
If ReadSector(PE.SecOfs+16,Sec) Then Begin
If(Sec[0]=$49)And(Sec[1]=$E8)And(Sec[2]=$95)And(Sec[3]=$F9)Then Begin
{ SuperBlock HPFS, volume name @ offset $0C, 32 octets max, null-term }
Lbl:='';
For I:=$0C To $0C+31 Do Begin
If Sec[I]=0 Then Break;
Lbl:=Lbl+Chr(Sec[I]);
End;
While(Length(Lbl)>0)And(Lbl[Length(Lbl)]=' ')Do
Lbl:=Copy(Lbl,1,Length(Lbl)-1);
GetVolumeLabel:=Lbl;
Exit;
End;
End;
{ Relire le boot sector FAT }
If Not ReadSector(PE.SecOfs,Sec) Then Exit;
If(Sec[510]<>$55)Or(Sec[511]<>$AA)Then Exit;
BytesPerSec:=Word(Sec[11])Or(Word(Sec[12])Shl 8);
SecPerClus:=Sec[13];
RsvdSec:=Word(Sec[14])Or(Word(Sec[15])Shl 8);
NumFATs:=Sec[16];
RootEntCnt:=Word(Sec[17])Or(Word(Sec[18])Shl 8);
TotSec:=Word(Sec[19])Or(Word(Sec[20])Shl 8);
If TotSec=0 Then
TotSec:=LongInt(Sec[32])Or(LongInt(Sec[33])Shl 8)
Or(LongInt(Sec[34])Shl 16)Or(LongInt(Sec[35])Shl 24);
SecPerFAT:=Word(Sec[22])Or(Word(Sec[23])Shl 8);
If SecPerFAT=0 Then
SecPerFAT:=LongInt(Sec[36])Or(LongInt(Sec[37])Shl 8)
Or(LongInt(Sec[38])Shl 16)Or(LongInt(Sec[39])Shl 24);
If(BytesPerSec<>512)Or(SecPerClus=0)Or(NumFATs=0)Or(SecPerFAT=0)Then Exit;
DataSec:=TotSec-(RsvdSec+LongInt(NumFATs)*SecPerFAT
+((LongInt(RootEntCnt)*32+BytesPerSec-1)Div BytesPerSec));
If DataSec<=0 Then Exit;
TotClus:=DataSec Div SecPerClus;
If TotClus<4085 Then FATType:=12
Else If TotClus<65525 Then FATType:=16
Else FATType:=32;
{ 1) Essayer le label de l'extended BPB }
If FATType=32 Then LblOfs:=71 Else LblOfs:=43;
{ Verifier la signature etendue BS_BootSig=$29 }
If((FATType=32)And(Sec[66]=$29))Or
((FATType<>32)And(Sec[38]=$29))Then Begin
Lbl:='';
For I:=LblOfs To LblOfs+10 Do Lbl:=Lbl+Chr(Sec[I]);
While(Length(Lbl)>0)And(Lbl[Length(Lbl)]=' ')Do
Lbl:=Copy(Lbl,1,Length(Lbl)-1);
If(Lbl<>'')And(Lbl<>'NO NAME')Then Begin
GetVolumeLabel:=Lbl;
Exit;
End;
End;
{ 2) Scanner le repertoire racine pour une entree avec attr=$08 }
If FATType=32 Then Begin
RootClus:=LongInt(Sec[44])Or(LongInt(Sec[45])Shl 8)
Or(LongInt(Sec[46])Shl 16)Or(LongInt(Sec[47])Shl 24);
FirstDataSec:=RsvdSec+LongInt(NumFATs)*SecPerFAT;
RootStart:=PE.SecOfs+FirstDataSec+(RootClus-2)*SecPerClus;
RootSecs:=SecPerClus; { un seul cluster suffit pour l'entree volume }
End Else Begin
RootStart:=PE.SecOfs+RsvdSec+LongInt(NumFATs)*SecPerFAT;
RootSecs:=(LongInt(RootEntCnt)*32+BytesPerSec-1)Div BytesPerSec;
End;
Found:=False;
J:=0;
While(J<RootSecs)And Not Found Do Begin
If Not ReadSector(RootStart+J,Sec) Then Exit;
K:=0;
While(K<512)And Not Found Do Begin
If Sec[K]=0 Then Exit; { fin du repertoire }
{ attr=$08 (volume), pas $0F (LFN), pas supprime ($E5) }
If(Sec[K+11]=$08)And(Sec[K]<>$E5)Then Begin
Lbl:='';
For I:=0 To 10 Do Lbl:=Lbl+Chr(Sec[K+I]);
While(Length(Lbl)>0)And(Lbl[Length(Lbl)]=' ')Do
Lbl:=Copy(Lbl,1,Length(Lbl)-1);
If Lbl<>'' Then Begin
GetVolumeLabel:=Lbl;
Found:=True;
End;
End;
Inc(K,32);
End;
Inc(J);
End;
End;
{ Calcule le % UTILISE d'une partition FAT en parcourant sa FAT.
Renvoie -1 si impossible (type non supporte, lecture echouee, etc.). }
Function PartUsagePct(Const PE:PartEntry):Integer;
Var
Sec:Array[0..511] of Byte;
BytesPerSec,RsvdSec,RootEntCnt,SecPerClus:Word;
SecPerFAT,TotSec:LongInt;
NumFATs:Byte;
FATType:Byte; { 12, 16 ou 32 }
DataSec,TotClus:LongInt;
FATStart:LongInt;
BytesInFAT:LongInt;
FATBuf:Array[0..511] of Byte;
CurFATSec:LongInt;
LastFATSec:LongInt;
ClusIdx:LongInt;
Ofs:LongInt;
V12:Word;
V16:Word;
V32:LongInt;
Free:LongInt;
Used:LongInt;
Begin
PartUsagePct:=-1;
If Not ReadSector(PE.SecOfs,Sec) Then Exit;
{ Verifier signature de boot sector }
If(Sec[510]<>$55)Or(Sec[511]<>$AA)Then Exit;
BytesPerSec:=Word(Sec[11])Or(Word(Sec[12])Shl 8);
SecPerClus:=Sec[13];
RsvdSec:=Word(Sec[14])Or(Word(Sec[15])Shl 8);
NumFATs:=Sec[16];
RootEntCnt:=Word(Sec[17])Or(Word(Sec[18])Shl 8);
TotSec:=Word(Sec[19])Or(Word(Sec[20])Shl 8);
If TotSec=0 Then
TotSec:=LongInt(Sec[32])Or(LongInt(Sec[33])Shl 8)
Or(LongInt(Sec[34])Shl 16)Or(LongInt(Sec[35])Shl 24);
SecPerFAT:=Word(Sec[22])Or(Word(Sec[23])Shl 8);
If SecPerFAT=0 Then
SecPerFAT:=LongInt(Sec[36])Or(LongInt(Sec[37])Shl 8)
Or(LongInt(Sec[38])Shl 16)Or(LongInt(Sec[39])Shl 24);
If(BytesPerSec<>512)Or(SecPerClus=0)Or(NumFATs=0)Or(SecPerFAT=0)Then Exit;
{ Calcul du nombre de clusters de donnees }
DataSec:=TotSec-(RsvdSec+LongInt(NumFATs)*SecPerFAT
+((LongInt(RootEntCnt)*32+BytesPerSec-1)Div BytesPerSec));
If DataSec<=0 Then Exit;
TotClus:=DataSec Div SecPerClus;
If TotClus<4085 Then FATType:=12
Else If TotClus<65525 Then FATType:=16
Else FATType:=32;
FATStart:=PE.SecOfs+RsvdSec;
BytesInFAT:=LongInt(SecPerFAT)*BytesPerSec;
{ Scanner FAT, compter clusters libres (entree=0) }
CurFATSec:=-1;
LastFATSec:=-1;
Free:=0;
{ Clusters valides : 2..TotClus+1 }
For ClusIdx:=2 To TotClus+1 Do Begin
Case FATType Of
12:Ofs:=ClusIdx+(ClusIdx Shr 1);
16:Ofs:=ClusIdx Shl 1;
Else Ofs:=ClusIdx Shl 2;
End;
If Ofs>=BytesInFAT Then Break;
CurFATSec:=FATStart+(Ofs Div BytesPerSec);
If CurFATSec<>LastFATSec Then Begin
If Not ReadSector(CurFATSec,FATBuf) Then Exit;
LastFATSec:=CurFATSec;
End;
Ofs:=Ofs Mod BytesPerSec;
Case FATType Of
12:Begin
{ Cas frontiere : entree de 12 bits a cheval sur deux secteurs }
If Ofs=BytesPerSec-1 Then Begin
V12:=FATBuf[Ofs];
If Not ReadSector(CurFATSec+1,FATBuf) Then Exit;
LastFATSec:=CurFATSec+1;
V12:=V12 Or(Word(FATBuf[0])Shl 8);
End Else
V12:=Word(FATBuf[Ofs])Or(Word(FATBuf[Ofs+1])Shl 8);
If(ClusIdx And 1)=0 Then V12:=V12 And $0FFF
Else V12:=V12 Shr 4;
If V12=0 Then Inc(Free);
End;
16:Begin
V16:=Word(FATBuf[Ofs])Or(Word(FATBuf[Ofs+1])Shl 8);
If V16=0 Then Inc(Free);
End;
Else Begin
V32:=LongInt(FATBuf[Ofs])Or(LongInt(FATBuf[Ofs+1])Shl 8)
Or(LongInt(FATBuf[Ofs+2])Shl 16)Or(LongInt(FATBuf[Ofs+3])Shl 24);
V32:=V32 And $0FFFFFFF;
If V32=0 Then Inc(Free);
End;
End;
End;
Used:=TotClus-Free;
If Used<0 Then Used:=0;
If TotClus>0 Then
PartUsagePct:=Integer((Used*100+TotClus Div 2)Div TotClus)
Else
PartUsagePct:=0;
End;
Procedure WriteListPartition;
Var
Partition:PartSec Absolute Buffer;
I:Byte;
Letter:Char;
TypeName:String;
TotSec:LongInt;
Pct:Integer;
Buffer2:Array[0..511]of Byte;
Begin
Write(' ':2,'Lecteur de disque dur en cours : ');
HighVideo;
If FileName<>''Then WriteLn(FileName)
Else WriteLn(CurrentDisk);
LowVideo;
WriteLn;
WriteLn(' ':2,'Partition Etat Type Nom du volume Mo SystŠme Utilis‚');
ReadPartitionRecord;
{ Verifie la signature MBR $55AA. Sinon, image disquette ou secteur non
partitionne : ne rien afficher pour eviter erreurs d'overflow. }
If(Buffer[510]<>$55)Or(Buffer[511]<>$AA)Then Begin
WriteLn;
WriteLn(' ':2,'Aucune table de partition (image disquette ou secteur vide ?).');
Exit;
End;
{ Detection d'un secteur de boot FAT (commence par JMP EB/E9) : ce n'est
pas un MBR meme si la signature $55AA est presente. }
If(Buffer[0]=$EB)Or(Buffer[0]=$E9)Then Begin
WriteLn;
WriteLn(' ':2,'Aucune table de partition (secteur de boot FAT detecte).');
Exit;
End;
{ Total des secteurs occupes par toutes les partitions = taille du disque.
Filtre les entrees aberrantes (PartType inconnu et NumSec absurde). }
TotSec:=0;
For I:=0 to 3 do
If Partition.PartTable[I].PartType<>0Then
Inc(TotSec,Partition.PartTable[I].NumSec);
Letter:='C';
For I:=0 to 3 do If Partition.PartTable[I].PartType<>0Then Begin
Write(' ':3);
If Partition.PartTable[I].PartType in[$04,$05,$06,$07,$0B,$0C]Then Begin
Write(Letter,': ');
Letter:=Succ(Letter);
End
Else
Write(' ':3);
HighVideo;
Write(I+1,' ':9);
LowVideo;
If Partition.PartTable[I].Status=$80 Then Write('A')
Else Write(' ');
Write(' ':4);
{ Colonne Type : PRI/EXT + nature du systeme (DOS, non-DOS ou autre) }
Case Partition.PartTable[I].PartType Of
$05,$0F:Write('EXT '); { Partition etendue }
$01,$04,$06,$0B,$0C,
$0E,$11,$12,$14,$16,
$1B,$1C,$1E,$24:Write('PRI DOS '); { DOS/FAT }
Else Write('PRI '); { Autre OS / non-DOS }
End;
{ Nom de volume : lu via FAT BPB/racine ou HPFS }
TypeName:=GetVolumeLabel(Partition.PartTable[I]);
If TypeName='' Then TypeName:='NOLABEL';
Write(PadRight(TypeName,14));
{ Taille en Mo = NumSec * 512 / (1024*1024) = NumSec / 2048 }
Write((Partition.PartTable[I].NumSec + 1024) Div 2048:6,' ':3);
Case Partition.PartTable[I].PartType of
$00:TypeName:='Entr�e vide';
$01:TypeName:='FAT12';
$02:TypeName:='XENIX root';
$03:TypeName:='XENIX /usr';
$04,$05,$06:TypeName:='FAT16';
$07:Begin
{ Type $07 : NTFS, HPFS, exFAT ou IFS. Distinguer via le boot sector
de la partition (offset +3 : OEM name pour NTFS/exFAT,
ou offset +54 : FileSystemType pour HPFS FAT-like BPB). }
TypeName:='IFS';
If ReadSector(Partition.PartTable[I].SecOfs,Buffer2) Then Begin
{ 'NTFS ' a offset 3 ? }
If(Buffer2[3]=$4E)And(Buffer2[4]=$54)And(Buffer2[5]=$46)And
(Buffer2[6]=$53)Then TypeName:='NTFS' Else
{ 'EXFAT ' a offset 3 ? }
If(Buffer2[3]=$45)And(Buffer2[4]=$58)And(Buffer2[5]=$46)And
(Buffer2[6]=$41)And(Buffer2[7]=$54)Then TypeName:='exFAT' Else
{ 'HPFS ' a offset 54 (BPB FAT-like) ? }
If(Buffer2[54]=$48)And(Buffer2[55]=$50)And(Buffer2[56]=$46)And
(Buffer2[57]=$53)Then TypeName:='HPFS';
End;
End;
$08:TypeName:='D‚marrage AIX';
$09:TypeName:='Donn‚es AIX';
$0A:TypeName:='OS/2 Boot Manager';
$0B,$0C:TypeName:='FAT32';
$0D:TypeName:='SILICON SAFE';
$0E,$0F:TypeName:='FAT16/WIN95';
$11,$14,$16:TypeName:='FAT12 cach‚';
$12:TypeName:='Partition de configuration';
$17:TypeName:='IFS cach‚';
$18:TypeName:='AST SmartSleep';
$1B:TypeName:='FAT32 cach‚';
$1C:TypeName:='FAT32';
$1E:TypeName:='FAT16/WIN95';
$24:TypeName:='NEC DOS';
$27:TypeName:='MirOS';
$2A:TypeName:='AtheOS';
$2B:TypeName:='SylStor';
$32:TypeName:='NOS';
$35:TypeName:='JFS';
Else TypeName:='Inconnu';
End;
Write(PadRight(TypeName,11));
{ % d'occupation reel via scan FAT (image fichier ou disque physique) }
Pct:=PartUsagePct(Partition.PartTable[I]);
If Pct<0 Then
{ Fallback : % du disque physique occupe par cette partition.
NumSec peut etre > 21M (>=10 Go), donc NumSec*100 deborde LongInt.
On divise d'abord par 1024 pour rester dans la plage. }
If TotSec>0 Then
Write(Integer((LongInt(Partition.PartTable[I].NumSec Shr 10)*100
+(TotSec Shr 10)Div 2)
Div(TotSec Shr 10)),'%')
Else
Write(' ? ')
Else
Write(Pct,'%');
WriteLn;
End;
End;
{ ===== Creation de partition ============================================ }
Function HexByteStr(B:Byte):String;
Const HC:Array[0..15]of Char='0123456789ABCDEF';
Begin
HexByteStr:=HC[B Shr 4]+HC[B And $0F];
End;
{ Taille totale (en secteurs) du support : fichier image ou disque physique. }
Function TotalSectors:LongInt;
Var
F:File;
Sz:LongInt;
Begin
TotalSectors:=0;
If FileName<>'' Then Begin
{ VHD : utiliser la taille virtuelle, pas la taille du fichier hote }
If VHDDiskSec>0 Then Begin