-
Notifications
You must be signed in to change notification settings - Fork 3
/
FDISK.PAS
517 lines (494 loc) · 11.5 KB
/
FDISK.PAS
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
{ @author: Sylvain Maltais ([email protected])
@created: 2022
@website(https://www.gladir.com/msdos0)
@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;
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}
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
{$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
{$I-}Assign(Partition,FileName);
Reset(Partition,1);{$I+}
If IOResult=0 Then Begin
BlockWrite(Partition,Buffer,512,ByteReaded);
Close(Partition);
End;
End;
End;
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;
Procedure WriteListPartition;
Var
Partition:PartSec Absolute Buffer;
I:Byte;
Letter:Char;
TypeName:String;
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;
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);
Write('PRI DOS',' ':2);
Write('NOLABEL',' ':7);
Write(2048,' ':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:TypeName:='NTFS ou HPFS';
$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));
Write(100,'%');
WriteLn;
End;
End;
Procedure CreatePartition;Begin
ClrScr;
WriteLn('Cette fonctionnalit‚ n''est pas implement‚ !');
ReadKey;
End;
Procedure ActivePartition;
Var
Partition:PartSec Absolute Buffer;
CurrActive,I,ActiveX,ActiveY:Byte;
Begin
ClrScr;
WriteLn;
WriteLn;
WriteLn;
WriteLnCenter('Activation de la partition de la partition');
WriteLn;
WriteListPartition;
WriteLn;
WriteLn;
WriteLn;
Write(' ':2,'Entrez le num‚ro de la partition que vous voulez activer...: ');
HighVideo;
CurrActive:=0;
For I:=0 to 3 do Begin
If Partition.PartTable[I].Status=$80 Then CurrActive:=I+1;
End;
Write('[');
ActiveX:=WhereX;
ActiveY:=WhereY;
WriteLn(CurrActive,']');
GotoXY(1,25);
LowVideo;
Write(' ':2,'Appuyez sur ');
HighVideo;
Write('ECHAP');
LowVideo;
Write(' pour quitter FDISK');
Repeat
HighVideo;
GotoXY(ActiveX,ActiveY);
Write(CurrActive);
GotoXY(ActiveX,ActiveY);
LowVideo;
Case ReadKey of
'1':If Partition.PartTable[0].PartType<>0Then CurrActive:=1;
'2':If Partition.PartTable[1].PartType<>0Then CurrActive:=2;
'3':If Partition.PartTable[2].PartType<>0Then CurrActive:=3;
'4':If Partition.PartTable[3].PartType<>0Then CurrActive:=4;
#13:Begin
Partition.PartTable[0].Status:=0;
Partition.PartTable[1].Status:=0;
Partition.PartTable[2].Status:=0;
Partition.PartTable[3].Status:=0;
Partition.PartTable[CurrActive-1].Status:=$80;
WritePartitionRecord;
Exit;
End;
#27:Exit;
End;
Until False;
End;
Procedure DeletePartition;Begin
ClrScr;
WriteLn('Cette fonctionnalit‚ n''est pas implement‚ !');
Write(' ':2,'Appuyez sur ');
HighVideo;
Write('ECHAP');
LowVideo;
Write(' pour quitter FDISK');
ReadKey;
End;
Procedure ShowPartition;Begin
ClrScr;
WriteLn;
WriteLn;
WriteLn;
WriteLnCenter('Affichage des informations sur les partitions');
WriteLn;
WriteListPartition;
GotoXY(1,25);
Write(' ':2,'Appuyez sur ');
HighVideo;
Write('ECHAP');
LowVideo;
Write(' pour quitter FDISK');
ReadKey;
End;
Procedure SelectFixedDisk;Begin
ClrScr;
WriteLn('Cette fonctionnalit‚ n''est pas implement‚ !');
Write(' ':2,'Appuyez sur ');
HighVideo;
Write('ECHAP');
LowVideo;
Write(' pour quitter FDISK');
ReadKey;
End;
Function ShowMainMenu:Byte;
Var
Choice:Char;
Begin
ShowMainMenu:=0;
Choice:='4';
TextBackground(0);
TextColor(7);
ClrScr;
WriteLnCenter('Ensemble Corail');
WriteLnCenter('FDISK');
WriteLnCenter('Gladir.com licence MIT 2022');
WriteLn;
HighVideo;
Case Language of
_English: WriteLnCenter('Fixed Disk Setup Program');
Else WriteLnCenter('Options de FDISK');
End;
WriteLn;
LowVideo;
Case Language of
_English:Write(' ':4,'Current Fixed Disk Drive: ');
Else Write(' ':4,'Lecteur de disque dur en cours : ');
End;
HighVideo;
If FileName<>''Then WriteLn(FileName)
Else WriteLn(CurrentDisk);
LowVideo;
WriteLn;
Case Language of
_English:WriteLn(' ':4,'Choose one of the following: ');
Else WriteLn(' ':4,'Choisissez parmi ce qui suit : ');
End;
WriteLn;
HighVideo;
Write(' ':4,'1. ');
LowVideo;
Case Language of
_English: WriteLn('Create DOS Partition');
Else WriteLn('Cr‚ation d''une partition ou lecteur logique DOS');
End;
HighVideo;
Write(' ':4,'2. ');
LowVideo;
Case Language of
_English:WriteLn('Change Active partition');
Else WriteLn('Activation d''une partition');
End;
HighVideo;
Write(' ':4,'3. ');
LowVideo;
Case Language of
_English:WriteLn('Delete DOS partition');
Else WriteLn('Suppression d''une partition ou lecteur logique DOS');
End;
HighVideo;
Write(' ':4,'4. ');
LowVideo;
Case Language of
_English:WriteLn('Display Partition Data');
Else WriteLn('Affichage des informations sur les partitions');
End;
HighVideo;
Write(' ':4,'5. ');
LowVideo;
Case Language of
_English:WriteLn('Select Next Fixed Disk Drive');
Else WriteLn('S‚lectionne le prochain unit‚ de disque dur');
End;
WriteLn;
WriteLn;
WriteLn;
Case Language of
_English:Write(' ':4,'Entrer choice: ');
Else Write(' ':4,'Entrez votre choix : ');
End;
HighVideo;
WriteLn('[',Choice,']');
LowVideo;
WriteLn;
WriteLn;
WriteLn;
Case Language of
_English:Begin
Write(' ':4,'Press ');
HighVideo;
Write('Esc');
LowVideo;
Write(' to return to DOS');
End;
Else Begin
Write(' ':4,'Appuyez sur ');
HighVideo;
Write('ECHAP');
LowVideo;
Write(' pour quitter FDISK');
End;
End;
Repeat
GotoXY(27,19);
Write(Choice);
GotoXY(27,19);
Case ReadKey of
#0:ReadKey;
#13:Begin
Case Choice of
'1':ShowMainMenu:=1;
'2':ShowMainMenu:=2;
'3':ShowMainMenu:=3;
'4':ShowMainMenu:=4;
'5':ShowMainMenu:=5;
End;
Exit;
End;
#27:Exit;
'1':Choice:='1';
'2':Choice:='2';
'3':Choice:='3';
'4':Choice:='4';
'5':Choice:='5';
End;
Until False;
End;
BEGIN
{$IFDEF FPC}
{$IFDEF WINDOWS}
SetUseACP(False);
{$ENDIF}
{$ENDIF}
Language:=_French;
TmpLanguage:=GetEnv('LANGUAGE');
If TmpLanguage<>''Then Begin
If TmpLanguage[1]='"'Then TmpLanguage:=Copy(TmpLanguage,2,255);
If StrToUpper(Copy(TmpLanguage,1,2))='EN'Then Language:=_English Else
If StrToUpper(Copy(TmpLanguage,1,2))='GR'Then Language:=_Germany Else
If StrToUpper(Copy(TmpLanguage,1,2))='IT'Then Language:=_Italian Else
If StrToUpper(Copy(TmpLanguage,1,2))='SP'Then Language:=_Spain;
End;
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')Then Begin
WriteLn('FDISK : Cette commande permet d''effectuer la gestion d''un disque dur.');
WriteLn;
WriteLn('Syntaxe : FDISK [fichier]');
End
Else
Begin
If SizeOf(PartSec)<>512 Then Begin
WriteLn('Mauvaise directive de compilation. Les enregistrements ne doivent pas ˆtre align‚s');
Halt;
End;
FileName:='';
CurrentDisk:=1;
IsDisk:=True;
If ParamStr(1)<>''Then Begin
FileName:=ParamStr(1);
IsDisk:=False;
End;
Repeat
Case ShowMainMenu of
0:Break;
1:CreatePartition;
2:ActivePartition;
3:DeletePartition;
4:ShowPartition;
5:SelectFixedDisk;
End;
Until False;
ClrScr;
End;
END.