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
|
#include <ntos.h>
#include <ntdddisk.h>
#include <arc.h>
#include <arccodes.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
//
// Define special character values.
//
#define ASCI_NUL 0x00
#define ASCI_BEL 0x07
#define ASCI_BS 0x08
#define ASCI_HT 0x09
#define ASCI_LF 0x0A
#define ASCI_VT 0x0B
#define ASCI_FF 0x0C
#define ASCI_CR 0x0D
#define ASCI_CSI 0x9B
#define ASCI_ESC 0x1B
#define ASCI_SYSRQ 0x80
//
// Locally defined error codes
//
#define EBADSYNTAX EMAXIMUM
#define MAX_COMPONENTS 20
ARC_STATUS
AlGetEnvVarComponents (
IN PCHAR EnvValue,
OUT PCHAR **EnvVarComponents,
OUT PULONG PNumComponents
);
ARC_STATUS
AlFreeEnvVarComponents (
IN PCHAR *EnvVarComponents
);
BOOLEAN
AlFindNextMatchComponent(
IN PCHAR EnvValue,
IN PCHAR MatchValue,
IN ULONG StartComponent,
OUT PULONG MatchComponent OPTIONAL
);
ARC_STATUS
AlAddSystemPartition(
IN PCHAR NewSystemPartition
);
ARC_STATUS
AlMemoryInitialize (
ULONG StackPages,
ULONG HeapPages
);
PVOID
AlAllocateHeap (
IN ULONG Size
);
PVOID
AlDeallocateHeap (
IN PVOID HeapAddress
);
PVOID
AlReallocateHeap (
IN PVOID HeapAddress,
IN ULONG NewSize
);
BOOLEAN
AlValidateHeap(
IN BOOLEAN DumpHeap
);
BOOLEAN
AlInitializeMenuPackage(
VOID
);
BOOLEAN
AlNewMenu(
PVOID *MenuID
);
VOID
AlFreeMenu(
PVOID MenuID
);
BOOLEAN // fails if OOM
AlAddMenuItem(
PVOID MenuID,
PCHAR Text,
ULONG AssociatedData,
ULONG Attributes // currently unused
);
BOOLEAN // fails if OOM
AlAddMenuItems(
PVOID MenuID,
PCHAR Text[], // NOTE: associated data for each item is its
ULONG ItemCount // index in the array.
);
BOOLEAN // FALSE if user escaped
AlDisplayMenu(
PVOID MenuID,
BOOLEAN PrintOnly,
ULONG AssociatedDataOfDefaultChoice,
ULONG *AssociatedDataOfChoice,
ULONG Row,
PCHAR MenuName // may be NULL
);
ULONG
AlGetMenuNumberItems(
PVOID MenuID
);
ULONG
AlGetMenuAssociatedData(
PVOID MenuID,
ULONG n
);
ARC_STATUS
AlGetMenuSelection(
IN PCHAR szTitle,
IN PCHAR *rgszSelections,
IN ULONG crgsz,
IN ULONG crow,
IN ULONG irgszDefault,
OUT PULONG pirgsz,
OUT PCHAR *pszSelection
);
VOID
AlWaitKey(
PCHAR Prompt // uses default if NULL
);
VOID
vAlStatusMsg(
IN ULONG Row,
IN BOOLEAN Error,
IN PCHAR FormatString,
IN va_list ArgumentList
);
VOID
AlStatusMsg(
IN ULONG TopRow,
IN ULONG BottomRow,
IN BOOLEAN Error,
IN PCHAR FormatString,
...
);
VOID
AlStatusMsgNoWait(
IN ULONG TopRow,
IN ULONG BottomRow,
IN BOOLEAN Error,
IN PCHAR FormatString,
...
);
VOID
AlClearStatusArea(
IN ULONG TopRow,
IN ULONG BottomRow
);
PCHAR
AlStrDup(
IN PCHAR szString
);
PCHAR
AlCombinePaths (
IN PCHAR szPath1,
IN PCHAR szPath2
);
VOID
AlFreeArray (
IN BOOLEAN fFreeArray,
IN PCHAR *rgsz,
IN ULONG csz
);
ARC_STATUS
AlGetBase (
IN PCHAR szPath,
OUT PCHAR *pszBase
);
//
// Define types of adapters that can be booted from.
//
typedef enum _ADAPTER_TYPES {
AdapterEisa,
AdapterScsi,
AdapterMulti,
AdapterMaximum
} ADAPTER_TYPES;
//
// Define type of controllers that can be booted from.
//
typedef enum _CONTROLLER_TYPES {
ControllerDisk,
ControllerCdrom,
ControllerMaximum
} CONTROLLER_TYPES;
//
// Define type of peripheral that can be booted from.
//
typedef enum _PERIPHERAL_TYPES {
PeripheralRigidDisk,
PeripheralFloppyDisk,
PeripheralMaximum
} PERIPHERAL_TYPES;
//
// Define type of token we are referring to
//
typedef enum _TOKEN_TYPES {
AdaptType,
ControllerType,
PeripheralType
} TOKEN_TYPES;
//
// Define error codes
//
#define INVALID_TOKEN_TYPE ~0L
#define INVALID_TOKEN_VALUE ~1L
//
// token string is searched for next name(unit)
//
PCHAR
AlGetNextArcNameToken (
IN PCHAR TokenString,
OUT PCHAR OutputToken,
OUT PULONG UnitNumber
);
//
// If invalid tokentype or tokenvalue passed in the error codes defined
// above are returned, else the enumeration of the token type is returned
//
ULONG
AlMatchArcNameToken (
IN PCHAR TokenValue,
IN TOKEN_TYPES TokenType
);
ARC_STATUS
FdiskInitialize(
VOID
);
VOID
FdiskCleanUp(
VOID
);
VOID
ConfigureSystemPartitions(
VOID
);
VOID
ConfigureOSPartitions(
VOID
);
ULONG
AlPrint (
PCHAR Format,
...
);
extern char MSGMARGIN[];
#define AlClearScreen() \
AlPrint("%c2J", ASCI_CSI)
#define AlClearLine() \
AlPrint("%c2K", ASCI_CSI)
#define AlSetScreenColor(FgColor, BgColor) \
AlPrint("%c3%dm", ASCI_CSI, (UCHAR)FgColor); \
AlPrint("%c4%dm", ASCI_CSI, (UCHAR)BgColor)
#define AlSetScreenAttributes( HighIntensity, Underscored, ReverseVideo ) \
AlPrint("%c0m", ASCI_CSI); \
if (HighIntensity) { \
AlPrint("%c1m", ASCI_CSI); \
} \
if (Underscored) { \
AlPrint("%c4m", ASCI_CSI); \
} \
if (ReverseVideo) { \
AlPrint("%c7m", ASCI_CSI); \
}
#define AlSetPosition( Row, Column ) \
AlPrint("%c%d;%dH", ASCI_CSI, Row, Column)
BOOLEAN // false if user escaped.
AlGetString(
OUT PCHAR String,
IN ULONG StringLength
);
#define AllocateMemory(size) AlAllocateHeap(size)
#define ReallocateMemory(block,size) AlReallocateHeap(block,size)
#define FreeMemory(block) AlDeallocateHeap(block)
#define OK_STATUS ESUCCESS
#define RETURN_OUT_OF_MEMORY return(ENOMEM)
#define LOWPART(x) ((x).LowPart)
#define ONE_MEG (1024*1024)
ULONG
SIZEMB(
IN LARGE_INTEGER ByteCount
);
#define ENTRIES_PER_BOOTSECTOR 4
/*
This structure is used to hold the information returned by the
get drive geometry call.
*/
typedef struct _tagDISKGEOM {
LARGE_INTEGER Cylinders;
ULONG Heads;
ULONG SectorsPerTrack;
ULONG BytesPerSector;
// These two are not part of drive geometry info, but calculated from it.
ULONG BytesPerCylinder;
ULONG BytesPerTrack;
} DISKGEOM,*PDISKGEOM;
/*
These structures are used in doubly-linked per disk lists that
describe the layout of the disk.
Free spaces are indicated by entries with a SysID of 0 (note that
these entries don't actually appear anywhere on-disk!)
The partition number is the number the system will assign to
the partition in naming it. For free spaces, this is the number
that the system WOULD assign to it if it was a partition.
The number is good only for one transaction (create or delete),
after which partitions must be renumbered.
*/
typedef struct _tagPARTITION {
struct _tagPARTITION *Next;
struct _tagPARTITION *Prev;
LARGE_INTEGER Offset;
LARGE_INTEGER Length;
ULONG Disk;
ULONG OriginalPartitionNumber;
ULONG PartitionNumber;
ULONG PersistentData;
BOOLEAN Update;
BOOLEAN Active;
BOOLEAN Recognized;
UCHAR SysID;
} PARTITION,*PPARTITION;
typedef struct _tagREGION_DATA {
PPARTITION Partition;
LARGE_INTEGER AlignedRegionOffset;
LARGE_INTEGER AlignedRegionSize;
} REGION_DATA,*PREGION_DATA;
#if DBG
#define ASRT(x) if(!(x)) { char c; ULONG n; \
AlPrint("\r\nAssertion failure in %s, line %u\r\n",__FILE__,__LINE__);\
AlPrint("Press return to exit\r\n"); \
ArcRead(ARC_CONSOLE_INPUT,&c,1,&n); \
ArcEnterInteractiveMode(); \
}
#else
#define ASRT(x)
#endif
ARC_STATUS
FmtIsFatPartition(
IN ULONG PartitionId,
IN ULONG SectorSize,
OUT PBOOLEAN IsFatPartition
);
ARC_STATUS
FmtIsFat(
IN PCHAR PartitionPath,
OUT PBOOLEAN IsFatPartition
);
ARC_STATUS
FmtFatFormat(
IN PCHAR PartitionPath,
IN ULONG HiddenSectorCount
);
ARC_STATUS
FmtQueryFatPartitionList(
OUT PCHAR** FatPartitionList,
OUT PULONG ListLength
);
ARC_STATUS
FmtFreeFatPartitionList(
IN OUT PCHAR* FatPartitionList,
IN ULONG ListLength
);
ARC_STATUS
LowOpenDisk(
IN PCHAR DevicePath,
OUT PULONG DiskId
);
ARC_STATUS
LowCloseDisk(
IN ULONG DiskId
);
ARC_STATUS
LowGetDriveGeometry(
IN PCHAR DevicePath,
OUT PULONG TotalSectorCount,
OUT PULONG SectorSize,
OUT PULONG SectorsPerTrack,
OUT PULONG Heads
);
ARC_STATUS
LowGetPartitionGeometry(
IN PCHAR PartitionPath,
OUT PULONG TotalSectorCount,
OUT PULONG SectorSize,
OUT PULONG SectorsPerTrack,
OUT PULONG Heads
);
ARC_STATUS
LowReadSectors(
IN ULONG VolumeId,
IN ULONG SectorSize,
IN ULONG StartingSector,
IN ULONG NumberOfSectors,
OUT PVOID Buffer
);
ARC_STATUS
LowWriteSectors(
IN ULONG VolumeId,
IN ULONG SectorSize,
IN ULONG StartingSector,
IN ULONG NumberOfSectors,
IN PVOID Buffer
);
ARC_STATUS
LowQueryPathFromComponent(
IN PCONFIGURATION_COMPONENT Component,
OUT PCHAR* Path
);
ARC_STATUS
LowQueryComponentList(
IN CONFIGURATION_CLASS* ConfigClass OPTIONAL,
IN CONFIGURATION_TYPE* ConfigType OPTIONAL,
OUT PCONFIGURATION_COMPONENT** ComponentList,
OUT PULONG ListLength
);
ARC_STATUS
LowQueryPathList(
IN CONFIGURATION_CLASS* ConfigClass OPTIONAL,
IN CONFIGURATION_TYPE* ConfigType OPTIONAL,
OUT PCHAR** PathList,
OUT PULONG ListLength
);
ARC_STATUS
LowFreePathList(
IN PCHAR* PathList,
IN ULONG ListLength
);
ARC_STATUS
LowQueryFdiskPathList(
OUT PCHAR** PathList,
OUT PULONG ListLength
);
ARC_STATUS
LowFreeFdiskPathList(
IN OUT PCHAR* PathList,
IN ULONG ListLength
);
ARC_STATUS
LowGetDiskLayout(
IN PCHAR Path,
OUT PDRIVE_LAYOUT_INFORMATION *DriveLayout
);
ARC_STATUS
LowSetDiskLayout(
IN PCHAR Path,
IN PDRIVE_LAYOUT_INFORMATION DriveLayout
);
typedef enum { REGION_PRIMARY,
REGION_EXTENDED,
REGION_LOGICAL
} REGION_TYPE;
enum {
SYSID_UNUSED = 0,
SYSID_EXTENDED = 5,
SYSID_BIGFAT = 6,
SYSID_IFS = 7
};
typedef struct _tagREGION_DESCRIPTOR {
ULONG PersistentData;
ULONG Disk;
ULONG SizeMB;
ULONG PartitionNumber;
ULONG OriginalPartitionNumber;
REGION_TYPE RegionType;
BOOLEAN Active;
BOOLEAN Recognized;
UCHAR SysID;
PVOID Reserved;
} REGION_DESCRIPTOR,*PREGION_DESCRIPTOR;
ULONG
GetDiskCount(
VOID
);
PCHAR
GetDiskName(
ULONG Disk
);
ULONG
DiskSizeMB(
IN ULONG Disk
);
ARC_STATUS
GetDiskRegions(
IN ULONG Disk,
IN BOOLEAN WantUsedRegions,
IN BOOLEAN WantFreeRegions,
IN BOOLEAN WantPrimaryRegions,
IN BOOLEAN WantLogicalRegions,
OUT PREGION_DESCRIPTOR *Region,
OUT ULONG *RegionCount
);
#define GetAllDiskRegions(disk,regions,count) \
GetDiskRegions(disk,TRUE,TRUE,TRUE,TRUE,regions,count)
#define GetFreeDiskRegions(disk,regions,count) \
GetDiskRegions(disk,FALSE,TRUE,TRUE,TRUE,regions,count)
#define GetUsedDiskRegions(disk,regions,count) \
GetDiskRegions(disk,TRUE,FALSE,TRUE,TRUE,regions,count)
#define GetPrimaryDiskRegions(disk,regions,count) \
GetDiskRegions(disk,TRUE,TRUE,TRUE,FALSE,regions,count)
#define GetLogicalDiskRegions(disk,regions,count) \
GetDiskRegions(disk,TRUE,TRUE,FALSE,TRUE,regions,count)
#define GetUsedPrimaryDiskRegions(disk,regions,count) \
GetDiskRegions(disk,TRUE,FALSE,TRUE,FALSE,regions,count)
#define GetUsedLogicalDiskRegions(disk,regions,count) \
GetDiskRegions(disk,TRUE,FALSE,FALSE,TRUE,regions,count)
#define GetFreePrimaryDiskRegions(disk,regions,count) \
GetDiskRegions(disk,FALSE,TRUE,TRUE,FALSE,regions,count)
#define GetFreeLogicalDiskRegions(disk,regions,count) \
GetDiskRegions(disk,FALSE,TRUE,FALSE,TRUE,regions,count)
VOID
FreeRegionArray(
IN PREGION_DESCRIPTOR Region,
IN ULONG RegionCount
);
ARC_STATUS
IsAnyCreationAllowed(
IN ULONG Disk,
IN BOOLEAN AllowMultiplePrimaries,
OUT PBOOLEAN AnyAllowed,
OUT PBOOLEAN PrimaryAllowed,
OUT PBOOLEAN ExtendedAllowed,
OUT PBOOLEAN LogicalAllowed
);
ARC_STATUS
IsCreationOfPrimaryAllowed(
IN ULONG Disk,
IN BOOLEAN AllowMultiplePrimaries,
OUT PBOOLEAN Allowed
);
ARC_STATUS
IsCreationOfExtendedAllowed(
IN ULONG Disk,
OUT PBOOLEAN Allowed
);
ARC_STATUS
IsCreationOfLogicalAllowed(
IN ULONG Disk,
OUT PBOOLEAN Allowed
);
ARC_STATUS
DoesAnyPartitionExist(
IN ULONG Disk,
OUT PBOOLEAN AnyExists,
OUT PBOOLEAN PrimaryExists,
OUT PBOOLEAN ExtendedExists,
OUT PBOOLEAN LogicalExists
);
ARC_STATUS
DoesAnyPrimaryExist(
IN ULONG Disk,
OUT PBOOLEAN Exists
);
ARC_STATUS
DoesExtendedExist(
IN ULONG Disk,
OUT PBOOLEAN Exists
);
ARC_STATUS
DoesAnyLogicalExist(
IN ULONG Disk,
OUT PBOOLEAN Exists
);
BOOLEAN
IsExtended(
IN UCHAR SysID
);
VOID
SetPartitionActiveFlag(
IN PREGION_DESCRIPTOR Region,
IN UCHAR value
);
ARC_STATUS
CreatePartition(
IN PREGION_DESCRIPTOR Region,
IN ULONG CreationSizeMB,
IN REGION_TYPE Type
);
ARC_STATUS
CreatePartitionEx(
IN PREGION_DESCRIPTOR Region,
IN LARGE_INTEGER MinimumSize,
IN ULONG CreationSizeMB,
IN REGION_TYPE Type,
IN UCHAR SysId
);
ARC_STATUS
DeletePartition(
IN PREGION_DESCRIPTOR Region
);
ULONG
GetHiddenSectorCount(
ULONG Disk,
ULONG Partition
);
VOID
SetSysID(
IN ULONG Disk,
IN ULONG Partition,
IN UCHAR SysID
);
VOID
SetSysID2(
IN PREGION_DESCRIPTOR Region,
IN UCHAR SysID
);
PCHAR
GetSysIDName(
UCHAR SysID
);
ARC_STATUS
CommitPartitionChanges(
IN ULONG Disk
);
BOOLEAN
HavePartitionsBeenChanged(
IN ULONG Disk
);
VOID
FdMarkDiskDirty(
IN ULONG Disk
);
VOID
FdSetPersistentData(
IN PREGION_DESCRIPTOR Region,
IN ULONG Data
);
ULONG
FdGetMinimumSizeMB(
IN ULONG Disk
);
ULONG
FdGetMaximumSizeMB(
IN PREGION_DESCRIPTOR Region,
IN REGION_TYPE CreationType
);
LARGE_INTEGER
FdGetExactSize(
IN PREGION_DESCRIPTOR Region,
IN BOOLEAN ForExtended
);
LARGE_INTEGER
FdGetExactOffset(
IN PREGION_DESCRIPTOR Region
);
BOOLEAN
FdCrosses1024Cylinder(
IN PREGION_DESCRIPTOR Region,
IN ULONG CreationSizeMB,
IN REGION_TYPE RegionType
);
ULONG
FdGetDiskSignature(
IN ULONG Disk
);
VOID
FdSetDiskSignature(
IN ULONG Disk,
IN ULONG Signature
);
BOOLEAN
IsDiskOffLine(
IN ULONG Disk
);
typedef enum _BOOT_VARIABLES {
LoadIdentifierVariable,
SystemPartitionVariable,
OsLoaderVariable,
OsLoadPartitionVariable,
OsLoadFilenameVariable,
OsLoadOptionsVariable,
MaximumBootVariable
} BOOT_VARIABLE;
extern PCHAR BootString[];
VOID
JzDeleteVariableSegment (
PCHAR VariableName,
ULONG Selection
);
#define MAXIMUM_ENVIRONMENT_VALUE 256
|