00001
#include <ntos.h>
00002
#include <ntdddisk.h>
00003
#include <arc.h>
00004
#include <arccodes.h>
00005
#include <stdarg.h>
00006
#include <stdio.h>
00007
#include <stdlib.h>
00008
#include <ctype.h>
00009
#include <string.h>
00010
00011
00012
00013
00014 #define ASCI_NUL 0x00
00015 #define ASCI_BEL 0x07
00016 #define ASCI_BS 0x08
00017 #define ASCI_HT 0x09
00018 #define ASCI_LF 0x0A
00019 #define ASCI_VT 0x0B
00020 #define ASCI_FF 0x0C
00021 #define ASCI_CR 0x0D
00022 #define ASCI_CSI 0x9B
00023 #define ASCI_ESC 0x1B
00024 #define ASCI_SYSRQ 0x80
00025
00026
00027
00028
00029 #define EBADSYNTAX EMAXIMUM
00030
00031 #define MAX_COMPONENTS 20
00032
00033
ARC_STATUS
00034
AlGetEnvVarComponents (
00035 IN PCHAR EnvValue,
00036 OUT PCHAR **EnvVarComponents,
00037 OUT PULONG PNumComponents
00038 );
00039
00040
ARC_STATUS
00041
AlFreeEnvVarComponents (
00042 IN PCHAR *EnvVarComponents
00043 );
00044
00045 BOOLEAN
00046
AlFindNextMatchComponent(
00047 IN PCHAR EnvValue,
00048 IN PCHAR MatchValue,
00049 IN ULONG StartComponent,
00050 OUT PULONG MatchComponent OPTIONAL
00051 );
00052
00053
ARC_STATUS
00054
AlAddSystemPartition(
00055 IN PCHAR NewSystemPartition
00056 );
00057
00058
ARC_STATUS
00059
AlMemoryInitialize (
00060 ULONG StackPages,
00061 ULONG HeapPages
00062 );
00063
00064 PVOID
00065
AlAllocateHeap (
00066 IN ULONG Size
00067 );
00068
00069 PVOID
00070
AlDeallocateHeap (
00071 IN PVOID HeapAddress
00072 );
00073
00074 PVOID
00075
AlReallocateHeap (
00076 IN PVOID HeapAddress,
00077 IN ULONG NewSize
00078 );
00079
00080 BOOLEAN
00081
AlValidateHeap(
00082 IN BOOLEAN DumpHeap
00083 );
00084
00085 BOOLEAN
00086
AlInitializeMenuPackage(
00087 VOID
00088 );
00089
00090 BOOLEAN
00091
AlNewMenu(
00092 PVOID *MenuID
00093 );
00094
00095
VOID
00096
AlFreeMenu(
00097 PVOID MenuID
00098 );
00099
00100 BOOLEAN
00101
AlAddMenuItem(
00102 PVOID MenuID,
00103 PCHAR Text,
00104 ULONG AssociatedData,
00105 ULONG Attributes
00106 );
00107
00108 BOOLEAN
00109
AlAddMenuItems(
00110 PVOID MenuID,
00111 PCHAR Text[],
00112 ULONG ItemCount
00113 );
00114
00115 BOOLEAN
00116
AlDisplayMenu(
00117 PVOID MenuID,
00118 BOOLEAN PrintOnly,
00119 ULONG AssociatedDataOfDefaultChoice,
00120 ULONG *AssociatedDataOfChoice,
00121 ULONG Row,
00122 PCHAR MenuName
00123 );
00124
00125 ULONG
00126
AlGetMenuNumberItems(
00127 PVOID MenuID
00128 );
00129
00130 ULONG
00131
AlGetMenuAssociatedData(
00132 PVOID MenuID,
00133 ULONG n
00134 );
00135
00136
ARC_STATUS
00137
AlGetMenuSelection(
00138 IN PCHAR szTitle,
00139 IN PCHAR *rgszSelections,
00140 IN ULONG crgsz,
00141 IN ULONG crow,
00142 IN ULONG irgszDefault,
00143 OUT PULONG pirgsz,
00144 OUT PCHAR *pszSelection
00145 );
00146
00147
VOID
00148
AlWaitKey(
00149 PCHAR Prompt
00150 );
00151
00152
VOID
00153
vAlStatusMsg(
00154 IN ULONG Row,
00155 IN BOOLEAN Error,
00156 IN PCHAR FormatString,
00157 IN va_list ArgumentList
00158 );
00159
00160
VOID
00161
AlStatusMsg(
00162 IN ULONG TopRow,
00163 IN ULONG BottomRow,
00164 IN BOOLEAN Error,
00165 IN PCHAR FormatString,
00166 ...
00167 );
00168
00169
VOID
00170
AlStatusMsgNoWait(
00171 IN ULONG TopRow,
00172 IN ULONG BottomRow,
00173 IN BOOLEAN Error,
00174 IN PCHAR FormatString,
00175 ...
00176 );
00177
00178
VOID
00179
AlClearStatusArea(
00180 IN ULONG TopRow,
00181 IN ULONG BottomRow
00182 );
00183
00184 PCHAR
00185
AlStrDup(
00186 IN PCHAR szString
00187 );
00188
00189 PCHAR
00190
AlCombinePaths (
00191 IN PCHAR szPath1,
00192 IN PCHAR szPath2
00193 );
00194
00195
VOID
00196
AlFreeArray (
00197 IN BOOLEAN fFreeArray,
00198 IN PCHAR *rgsz,
00199 IN ULONG csz
00200 );
00201
00202
ARC_STATUS
00203
AlGetBase (
00204 IN PCHAR szPath,
00205 OUT PCHAR *pszBase
00206 );
00207
00208
00209
00210
00211 typedef enum _ADAPTER_TYPES {
00212
AdapterEisa,
00213
AdapterScsi,
00214
AdapterMulti,
00215
AdapterMaximum
00216 }
ADAPTER_TYPES;
00217
00218
00219
00220
00221 typedef enum _CONTROLLER_TYPES {
00222
ControllerDisk,
00223
ControllerCdrom,
00224
ControllerMaximum
00225 }
CONTROLLER_TYPES;
00226
00227
00228
00229
00230 typedef enum _PERIPHERAL_TYPES {
00231
PeripheralRigidDisk,
00232
PeripheralFloppyDisk,
00233
PeripheralMaximum
00234 }
PERIPHERAL_TYPES;
00235
00236
00237
00238
00239 typedef enum _TOKEN_TYPES {
00240
AdaptType,
00241
ControllerType,
00242
PeripheralType
00243 }
TOKEN_TYPES;
00244
00245
00246
00247
00248 #define INVALID_TOKEN_TYPE ~0L
00249 #define INVALID_TOKEN_VALUE ~1L
00250
00251
00252
00253
00254 PCHAR
00255
AlGetNextArcNameToken (
00256 IN PCHAR TokenString,
00257 OUT PCHAR OutputToken,
00258 OUT PULONG UnitNumber
00259 );
00260
00261
00262
00263
00264
00265 ULONG
00266
AlMatchArcNameToken (
00267 IN PCHAR TokenValue,
00268 IN TOKEN_TYPES TokenType
00269 );
00270
00271
ARC_STATUS
00272
FdiskInitialize(
00273 VOID
00274 );
00275
00276
VOID
00277
FdiskCleanUp(
00278 VOID
00279 );
00280
00281
VOID
00282
ConfigureSystemPartitions(
00283 VOID
00284 );
00285
00286
VOID
00287
ConfigureOSPartitions(
00288 VOID
00289 );
00290
00291 ULONG
00292
AlPrint (
00293 PCHAR Format,
00294 ...
00295 );
00296
00297 extern char MSGMARGIN[];
00298
00299 #define AlClearScreen() \
00300
AlPrint("%c2J", ASCI_CSI)
00301
00302 #define AlClearLine() \
00303
AlPrint("%c2K", ASCI_CSI)
00304
00305 #define AlSetScreenColor(FgColor, BgColor) \
00306
AlPrint("%c3%dm", ASCI_CSI, (UCHAR)FgColor); \
00307
AlPrint("%c4%dm", ASCI_CSI, (UCHAR)BgColor)
00308
00309 #define AlSetScreenAttributes( HighIntensity, Underscored, ReverseVideo ) \
00310
AlPrint("%c0m", ASCI_CSI); \
00311
if (HighIntensity) { \
00312
AlPrint("%c1m", ASCI_CSI); \
00313
} \
00314
if (Underscored) { \
00315
AlPrint("%c4m", ASCI_CSI); \
00316
} \
00317
if (ReverseVideo) { \
00318
AlPrint("%c7m", ASCI_CSI); \
00319
}
00320
00321 #define AlSetPosition( Row, Column ) \
00322
AlPrint("%c%d;%dH", ASCI_CSI, Row, Column)
00323
00324 BOOLEAN
00325
AlGetString(
00326 OUT PCHAR String,
00327 IN ULONG StringLength
00328 );
00329
00330 #define AllocateMemory(size) AlAllocateHeap(size)
00331 #define ReallocateMemory(block,size) AlReallocateHeap(block,size)
00332 #define FreeMemory(block) AlDeallocateHeap(block)
00333
00334 #define OK_STATUS ESUCCESS
00335 #define RETURN_OUT_OF_MEMORY return(ENOMEM)
00336
00337 #define LOWPART(x) ((x).LowPart)
00338
00339 #define ONE_MEG (1024*1024)
00340
00341 ULONG
00342
SIZEMB(
00343 IN LARGE_INTEGER ByteCount
00344 );
00345
00346 #define ENTRIES_PER_BOOTSECTOR 4
00347
00348
00349
00350
00351
00352 typedef struct _tagDISKGEOM {
00353 LARGE_INTEGER
Cylinders;
00354 ULONG
Heads;
00355 ULONG
SectorsPerTrack;
00356 ULONG
BytesPerSector;
00357
00358 ULONG
BytesPerCylinder;
00359 ULONG
BytesPerTrack;
00360 }
DISKGEOM,*
PDISKGEOM;
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 typedef struct _tagPARTITION {
00379 struct _tagPARTITION *
Next;
00380 struct _tagPARTITION *
Prev;
00381 LARGE_INTEGER
Offset;
00382 LARGE_INTEGER
Length;
00383 ULONG
Disk;
00384 ULONG
OriginalPartitionNumber;
00385 ULONG
PartitionNumber;
00386 ULONG
PersistentData;
00387 BOOLEAN
Update;
00388 BOOLEAN
Active;
00389 BOOLEAN
Recognized;
00390 UCHAR
SysID;
00391 }
PARTITION,*
PPARTITION;
00392
00393 typedef struct _tagREGION_DATA {
00394 PPARTITION Partition;
00395 LARGE_INTEGER
AlignedRegionOffset;
00396 LARGE_INTEGER
AlignedRegionSize;
00397 }
REGION_DATA,*
PREGION_DATA;
00398
00399
00400
#if DBG
00401
00402
#define ASRT(x) if(!(x)) { char c; ULONG n; \
00403
AlPrint("\r\nAssertion failure in %s, line %u\r\n",__FILE__,__LINE__);\
00404
AlPrint("Press return to exit\r\n"); \
00405
ArcRead(ARC_CONSOLE_INPUT,&c,1,&n); \
00406
ArcEnterInteractiveMode(); \
00407
}
00408
00409
#else
00410
00411 #define ASRT(x)
00412
00413
#endif
00414
00415
ARC_STATUS
00416
FmtIsFatPartition(
00417 IN ULONG PartitionId,
00418 IN ULONG SectorSize,
00419 OUT PBOOLEAN IsFatPartition
00420 );
00421
00422
ARC_STATUS
00423
FmtIsFat(
00424 IN PCHAR PartitionPath,
00425 OUT PBOOLEAN IsFatPartition
00426 );
00427
00428
ARC_STATUS
00429
FmtFatFormat(
00430 IN PCHAR PartitionPath,
00431 IN ULONG HiddenSectorCount
00432 );
00433
00434
ARC_STATUS
00435
FmtQueryFatPartitionList(
00436 OUT PCHAR** FatPartitionList,
00437 OUT PULONG ListLength
00438 );
00439
00440
ARC_STATUS
00441
FmtFreeFatPartitionList(
00442 IN OUT PCHAR* FatPartitionList,
00443 IN ULONG ListLength
00444 );
00445
00446
ARC_STATUS
00447
LowOpenDisk(
00448 IN PCHAR DevicePath,
00449 OUT PULONG DiskId
00450 );
00451
00452
ARC_STATUS
00453
LowCloseDisk(
00454 IN ULONG DiskId
00455 );
00456
00457
ARC_STATUS
00458
LowGetDriveGeometry(
00459 IN PCHAR DevicePath,
00460 OUT PULONG TotalSectorCount,
00461 OUT PULONG SectorSize,
00462 OUT PULONG SectorsPerTrack,
00463 OUT PULONG Heads
00464 );
00465
00466
ARC_STATUS
00467
LowGetPartitionGeometry(
00468 IN PCHAR PartitionPath,
00469 OUT PULONG TotalSectorCount,
00470 OUT PULONG SectorSize,
00471 OUT PULONG SectorsPerTrack,
00472 OUT PULONG Heads
00473 );
00474
00475
ARC_STATUS
00476
LowReadSectors(
00477 IN ULONG VolumeId,
00478 IN ULONG SectorSize,
00479 IN ULONG StartingSector,
00480 IN ULONG NumberOfSectors,
00481 OUT PVOID Buffer
00482 );
00483
00484
ARC_STATUS
00485
LowWriteSectors(
00486 IN ULONG VolumeId,
00487 IN ULONG SectorSize,
00488 IN ULONG StartingSector,
00489 IN ULONG NumberOfSectors,
00490 IN PVOID Buffer
00491 );
00492
00493
ARC_STATUS
00494
LowQueryPathFromComponent(
00495 IN
PCONFIGURATION_COMPONENT Component,
00496 OUT PCHAR* Path
00497 );
00498
00499
ARC_STATUS
00500
LowQueryComponentList(
00501 IN CONFIGURATION_CLASS* ConfigClass OPTIONAL,
00502 IN CONFIGURATION_TYPE* ConfigType OPTIONAL,
00503 OUT
PCONFIGURATION_COMPONENT** ComponentList,
00504 OUT PULONG ListLength
00505 );
00506
00507
ARC_STATUS
00508
LowQueryPathList(
00509 IN CONFIGURATION_CLASS* ConfigClass OPTIONAL,
00510 IN CONFIGURATION_TYPE* ConfigType OPTIONAL,
00511 OUT PCHAR** PathList,
00512 OUT PULONG ListLength
00513 );
00514
00515
ARC_STATUS
00516
LowFreePathList(
00517 IN PCHAR* PathList,
00518 IN ULONG ListLength
00519 );
00520
00521
ARC_STATUS
00522
LowQueryFdiskPathList(
00523 OUT PCHAR** PathList,
00524 OUT PULONG ListLength
00525 );
00526
00527
ARC_STATUS
00528
LowFreeFdiskPathList(
00529 IN OUT PCHAR* PathList,
00530 IN ULONG ListLength
00531 );
00532
00533
ARC_STATUS
00534
LowGetDiskLayout(
00535 IN PCHAR Path,
00536 OUT PDRIVE_LAYOUT_INFORMATION *DriveLayout
00537 );
00538
00539
ARC_STATUS
00540
LowSetDiskLayout(
00541 IN PCHAR Path,
00542 IN PDRIVE_LAYOUT_INFORMATION DriveLayout
00543 );
00544
00545 typedef enum {
REGION_PRIMARY,
00546
REGION_EXTENDED,
00547
REGION_LOGICAL
00548 }
REGION_TYPE;
00549
00550
enum {
00551
SYSID_UNUSED = 0,
00552
SYSID_EXTENDED = 5,
00553
SYSID_BIGFAT = 6,
00554
SYSID_IFS = 7
00555 };
00556
00557 typedef struct _tagREGION_DESCRIPTOR {
00558 ULONG
PersistentData;
00559 ULONG
Disk;
00560 ULONG
SizeMB;
00561 ULONG
PartitionNumber;
00562 ULONG
OriginalPartitionNumber;
00563 REGION_TYPE RegionType;
00564 BOOLEAN
Active;
00565 BOOLEAN
Recognized;
00566 UCHAR
SysID;
00567 PVOID
Reserved;
00568 }
REGION_DESCRIPTOR,*
PREGION_DESCRIPTOR;
00569
00570 ULONG
00571
GetDiskCount(
00572 VOID
00573 );
00574
00575 PCHAR
00576
GetDiskName(
00577 ULONG Disk
00578 );
00579
00580 ULONG
00581
DiskSizeMB(
00582 IN ULONG Disk
00583 );
00584
00585
ARC_STATUS
00586
GetDiskRegions(
00587 IN ULONG Disk,
00588 IN BOOLEAN WantUsedRegions,
00589 IN BOOLEAN WantFreeRegions,
00590 IN BOOLEAN WantPrimaryRegions,
00591 IN BOOLEAN WantLogicalRegions,
00592 OUT PREGION_DESCRIPTOR *Region,
00593 OUT ULONG *RegionCount
00594 );
00595
00596 #define GetAllDiskRegions(disk,regions,count) \
00597
GetDiskRegions(disk,TRUE,TRUE,TRUE,TRUE,regions,count)
00598
00599 #define GetFreeDiskRegions(disk,regions,count) \
00600
GetDiskRegions(disk,FALSE,TRUE,TRUE,TRUE,regions,count)
00601
00602 #define GetUsedDiskRegions(disk,regions,count) \
00603
GetDiskRegions(disk,TRUE,FALSE,TRUE,TRUE,regions,count)
00604
00605 #define GetPrimaryDiskRegions(disk,regions,count) \
00606
GetDiskRegions(disk,TRUE,TRUE,TRUE,FALSE,regions,count)
00607
00608 #define GetLogicalDiskRegions(disk,regions,count) \
00609
GetDiskRegions(disk,TRUE,TRUE,FALSE,TRUE,regions,count)
00610
00611 #define GetUsedPrimaryDiskRegions(disk,regions,count) \
00612
GetDiskRegions(disk,TRUE,FALSE,TRUE,FALSE,regions,count)
00613
00614 #define GetUsedLogicalDiskRegions(disk,regions,count) \
00615
GetDiskRegions(disk,TRUE,FALSE,FALSE,TRUE,regions,count)
00616
00617 #define GetFreePrimaryDiskRegions(disk,regions,count) \
00618
GetDiskRegions(disk,FALSE,TRUE,TRUE,FALSE,regions,count)
00619
00620 #define GetFreeLogicalDiskRegions(disk,regions,count) \
00621
GetDiskRegions(disk,FALSE,TRUE,FALSE,TRUE,regions,count)
00622
00623
VOID
00624
FreeRegionArray(
00625 IN PREGION_DESCRIPTOR Region,
00626 IN ULONG RegionCount
00627 );
00628
00629
ARC_STATUS
00630
IsAnyCreationAllowed(
00631 IN ULONG Disk,
00632 IN BOOLEAN AllowMultiplePrimaries,
00633 OUT PBOOLEAN AnyAllowed,
00634 OUT PBOOLEAN PrimaryAllowed,
00635 OUT PBOOLEAN ExtendedAllowed,
00636 OUT PBOOLEAN LogicalAllowed
00637 );
00638
00639
ARC_STATUS
00640
IsCreationOfPrimaryAllowed(
00641 IN ULONG Disk,
00642 IN BOOLEAN AllowMultiplePrimaries,
00643 OUT PBOOLEAN Allowed
00644 );
00645
00646
ARC_STATUS
00647
IsCreationOfExtendedAllowed(
00648 IN ULONG Disk,
00649 OUT PBOOLEAN Allowed
00650 );
00651
00652
ARC_STATUS
00653
IsCreationOfLogicalAllowed(
00654 IN ULONG Disk,
00655 OUT PBOOLEAN Allowed
00656 );
00657
00658
ARC_STATUS
00659
DoesAnyPartitionExist(
00660 IN ULONG Disk,
00661 OUT PBOOLEAN AnyExists,
00662 OUT PBOOLEAN PrimaryExists,
00663 OUT PBOOLEAN ExtendedExists,
00664 OUT PBOOLEAN LogicalExists
00665 );
00666
00667
ARC_STATUS
00668
DoesAnyPrimaryExist(
00669 IN ULONG Disk,
00670 OUT PBOOLEAN Exists
00671 );
00672
00673
ARC_STATUS
00674
DoesExtendedExist(
00675 IN ULONG Disk,
00676 OUT PBOOLEAN Exists
00677 );
00678
00679
ARC_STATUS
00680
DoesAnyLogicalExist(
00681 IN ULONG Disk,
00682 OUT PBOOLEAN Exists
00683 );
00684
00685 BOOLEAN
00686
IsExtended(
00687 IN UCHAR SysID
00688 );
00689
00690
VOID
00691
SetPartitionActiveFlag(
00692 IN PREGION_DESCRIPTOR Region,
00693 IN UCHAR value
00694 );
00695
00696
ARC_STATUS
00697
CreatePartition(
00698 IN PREGION_DESCRIPTOR Region,
00699 IN ULONG CreationSizeMB,
00700 IN REGION_TYPE Type
00701 );
00702
00703
ARC_STATUS
00704
CreatePartitionEx(
00705 IN PREGION_DESCRIPTOR Region,
00706 IN LARGE_INTEGER MinimumSize,
00707 IN ULONG CreationSizeMB,
00708 IN REGION_TYPE Type,
00709 IN UCHAR SysId
00710 );
00711
00712
ARC_STATUS
00713
DeletePartition(
00714 IN PREGION_DESCRIPTOR Region
00715 );
00716
00717 ULONG
00718
GetHiddenSectorCount(
00719 ULONG Disk,
00720 ULONG Partition
00721 );
00722
00723
VOID
00724
SetSysID(
00725 IN ULONG Disk,
00726 IN ULONG Partition,
00727 IN UCHAR SysID
00728 );
00729
00730
VOID
00731
SetSysID2(
00732 IN PREGION_DESCRIPTOR Region,
00733 IN UCHAR SysID
00734 );
00735
00736 PCHAR
00737
GetSysIDName(
00738 UCHAR SysID
00739 );
00740
00741
ARC_STATUS
00742
CommitPartitionChanges(
00743 IN ULONG Disk
00744 );
00745
00746 BOOLEAN
00747
HavePartitionsBeenChanged(
00748 IN ULONG Disk
00749 );
00750
00751
VOID
00752
FdMarkDiskDirty(
00753 IN ULONG Disk
00754 );
00755
00756
VOID
00757
FdSetPersistentData(
00758 IN PREGION_DESCRIPTOR Region,
00759 IN ULONG Data
00760 );
00761
00762 ULONG
00763
FdGetMinimumSizeMB(
00764 IN ULONG Disk
00765 );
00766
00767 ULONG
00768
FdGetMaximumSizeMB(
00769 IN PREGION_DESCRIPTOR Region,
00770 IN REGION_TYPE CreationType
00771 );
00772
00773 LARGE_INTEGER
00774
FdGetExactSize(
00775 IN PREGION_DESCRIPTOR Region,
00776 IN BOOLEAN ForExtended
00777 );
00778
00779 LARGE_INTEGER
00780
FdGetExactOffset(
00781 IN PREGION_DESCRIPTOR Region
00782 );
00783
00784 BOOLEAN
00785
FdCrosses1024Cylinder(
00786 IN PREGION_DESCRIPTOR Region,
00787 IN ULONG CreationSizeMB,
00788 IN REGION_TYPE RegionType
00789 );
00790
00791 ULONG
00792
FdGetDiskSignature(
00793 IN ULONG Disk
00794 );
00795
00796
VOID
00797
FdSetDiskSignature(
00798 IN ULONG Disk,
00799 IN ULONG Signature
00800 );
00801
00802 BOOLEAN
00803
IsDiskOffLine(
00804 IN ULONG Disk
00805 );
00806
00807
00808
00809 typedef enum _BOOT_VARIABLES {
00810
LoadIdentifierVariable,
00811
SystemPartitionVariable,
00812
OsLoaderVariable,
00813
OsLoadPartitionVariable,
00814
OsLoadFilenameVariable,
00815
OsLoadOptionsVariable,
00816
MaximumBootVariable
00817 }
BOOT_VARIABLE;
00818
00819 extern PCHAR
BootString[];
00820
00821
VOID
00822
JzDeleteVariableSegment (
00823 PCHAR VariableName,
00824 ULONG Selection
00825 );
00826
00827 #define MAXIMUM_ENVIRONMENT_VALUE 256