Reactos
at master 790 lines 13 kB view raw
1/* 2 * PROJECT: ReactOS DiskPart 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: base/system/diskpart/diskpart.h 5 * PURPOSE: Manages all the partitions of the OS in an interactive way. 6 * PROGRAMMERS: Lee Schroeder 7 */ 8 9#ifndef DISKPART_H 10#define DISKPART_H 11 12/* INCLUDES ******************************************************************/ 13 14#include <stdio.h> 15#include <stdlib.h> 16 17#define WIN32_NO_STATUS 18#include <windef.h> 19#include <winbase.h> 20#include <winnls.h> 21#include <winreg.h> 22#include <wincon.h> 23#include <winioctl.h> 24#include <winuser.h> 25#include <ntsecapi.h> 26 27#include <errno.h> 28#include <strsafe.h> 29 30#include <conutils.h> 31 32/* 33#define NTOS_MODE_USER 34#include <ndk/exfuncs.h> 35#include <ndk/iofuncs.h> 36#include <ndk/obfuncs.h> 37#include <ndk/psfuncs.h> 38#include <ndk/rtlfuncs.h> 39#include <ndk/umfuncs.h> 40*/ 41 42#define NTOS_MODE_USER 43#include <ndk/cmfuncs.h> 44#include <ndk/exfuncs.h> 45#include <ndk/iofuncs.h> 46#include <ndk/kefuncs.h> 47#include <ndk/mmfuncs.h> 48#include <ndk/obfuncs.h> 49#include <ndk/psfuncs.h> 50#include <ndk/rtlfuncs.h> 51#include <ndk/setypes.h> 52#include <ndk/umfuncs.h> 53 54#include <ntddscsi.h> 55#include <ntddstor.h> 56#include <mountmgr.h> 57 58#include <fmifs/fmifs.h> 59#include <guiddef.h> 60#include <diskguid.h> 61 62#include "resource.h" 63 64//#define DUMP_PARTITION_TABLE 65//#define DUMP_PARTITION_LIST 66 67/* DEFINES *******************************************************************/ 68 69/* NOERR codes for the program */ 70#undef EXIT_SUCCESS 71#undef EXIT_FAILURE 72 73typedef enum _EXIT_CODE 74{ 75 EXIT_SUCCESS = 0, 76 EXIT_FATAL, 77 EXIT_CMD_ARG, 78 EXIT_FILE, 79 EXIT_SERVICE, 80 EXIT_SYNTAX, 81 EXIT_EXIT /* Only used by the exit command */ 82} EXIT_CODE; 83 84typedef struct _COMMAND 85{ 86 PWSTR cmd1; 87 PWSTR cmd2; 88 PWSTR cmd3; 89 EXIT_CODE (*func)(INT, PWSTR*); 90 INT help; 91 DWORD help_detail; 92} COMMAND, *PCOMMAND; 93 94extern COMMAND cmds[]; 95 96#define MAX_STRING_SIZE 1024 97#define MAX_ARGS_COUNT 256 98 99 100typedef enum _FORMATSTATE 101{ 102 Unformatted, 103 UnformattedOrDamaged, 104 UnknownFormat, 105 Preformatted, 106 Formatted 107} FORMATSTATE, *PFORMATSTATE; 108 109typedef enum _VOLUME_TYPE 110{ 111 VOLUME_TYPE_CDROM, 112 VOLUME_TYPE_PARTITION, 113 VOLUME_TYPE_REMOVABLE, 114 VOLUME_TYPE_UNKNOWN 115} VOLUME_TYPE, *PVOLUME_TYPE; 116 117typedef struct _MBR_PARTITION_DATA 118{ 119 BOOLEAN BootIndicator; 120 UCHAR PartitionType; 121} MBR_PARTITION_DATA, *PMBR_PARTITION_DATA; 122 123typedef struct _GPT_PARTITION_DATA 124{ 125 GUID PartitionType; 126 GUID PartitionId; 127 DWORD64 Attributes; 128} GPT_PARTITION_DATA, *PGPT_PARTITION_DATA; 129 130typedef struct _PARTENTRY 131{ 132 LIST_ENTRY ListEntry; 133 134 struct _DISKENTRY *DiskEntry; 135 136 ULARGE_INTEGER StartSector; 137 ULARGE_INTEGER SectorCount; 138 139 union 140 { 141 MBR_PARTITION_DATA Mbr; 142 GPT_PARTITION_DATA Gpt; 143 }; 144 145 ULONG OnDiskPartitionNumber; 146 ULONG PartitionNumber; 147 ULONG PartitionIndex; 148 149 CHAR DriveLetter; 150 CHAR VolumeLabel[17]; 151 CHAR FileSystemName[9]; 152 FORMATSTATE FormatState; 153 154 BOOLEAN LogicalPartition; 155 156 /* Partition is partitioned disk space */ 157 BOOLEAN IsPartitioned; 158 159 /* Partition is new. Table does not exist on disk yet */ 160 BOOLEAN New; 161 162 /* Partition was created automatically. */ 163 BOOLEAN AutoCreate; 164 165 /* Partition must be checked */ 166 BOOLEAN NeedsCheck; 167 168 struct _FILE_SYSTEM_ITEM *FileSystem; 169 170 BOOL IsSystem; 171 BOOL IsBoot; 172 173} PARTENTRY, *PPARTENTRY; 174 175 176typedef struct _BIOSDISKENTRY 177{ 178 LIST_ENTRY ListEntry; 179 ULONG DiskNumber; 180 ULONG Signature; 181 ULONG Checksum; 182 BOOLEAN Recognized; 183 CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry; 184 CM_INT13_DRIVE_PARAMETER Int13DiskData; 185} BIOSDISKENTRY, *PBIOSDISKENTRY; 186 187 188typedef struct _DISKENTRY 189{ 190 LIST_ENTRY ListEntry; 191 192 PWSTR Description; 193 PWSTR Location; 194 STORAGE_BUS_TYPE BusType; 195 196 ULONGLONG Cylinders; 197 ULONG TracksPerCylinder; 198 ULONG SectorsPerTrack; 199 ULONG BytesPerSector; 200 201 ULARGE_INTEGER SectorCount; 202 ULONG SectorAlignment; 203 ULONG CylinderAlignment; 204 205 ULARGE_INTEGER StartSector; 206 ULARGE_INTEGER EndSector; 207 208 BOOLEAN BiosFound; 209 ULONG BiosDiskNumber; 210// ULONG Signature; 211// ULONG Checksum; 212 213 ULONG DiskNumber; 214 USHORT Port; 215 USHORT PathId; 216 USHORT TargetId; 217 USHORT Lun; 218 219 /* Has the partition list been modified? */ 220 BOOLEAN Dirty; 221 222 BOOLEAN NewDisk; 223 DWORD PartitionStyle; 224 225 UNICODE_STRING DriverName; 226 227 PDRIVE_LAYOUT_INFORMATION_EX LayoutBuffer; 228 229 PPARTENTRY ExtendedPartition; 230 231 LIST_ENTRY PrimaryPartListHead; 232 LIST_ENTRY LogicalPartListHead; 233 234 BOOL IsBoot; 235 236} DISKENTRY, *PDISKENTRY; 237 238typedef struct _VOLENTRY 239{ 240 LIST_ENTRY ListEntry; 241 242 ULONG VolumeNumber; 243 WCHAR VolumeName[MAX_PATH]; 244 WCHAR DeviceName[MAX_PATH]; 245 DWORD SerialNumber; 246 247 WCHAR DriveLetter; 248 249 PWSTR pszLabel; 250 PWSTR pszFilesystem; 251 VOLUME_TYPE VolumeType; 252 ULARGE_INTEGER Size; 253 254 ULARGE_INTEGER TotalAllocationUnits; 255 ULARGE_INTEGER AvailableAllocationUnits; 256 ULONG SectorsPerAllocationUnit; 257 ULONG BytesPerSector; 258 259 BOOL IsSystem; 260 BOOL IsBoot; 261 262 PVOLUME_DISK_EXTENTS pExtents; 263 264} VOLENTRY, *PVOLENTRY; 265 266#define SIZE_1KB (1024ULL) 267#define SIZE_10KB (10ULL * 1024ULL) 268#define SIZE_1MB (1024ULL * 1024ULL) 269#define SIZE_10MB (10ULL * 1024ULL * 1024ULL) 270#define SIZE_1GB (1024ULL * 1024ULL * 1024ULL) 271#define SIZE_10GB (10ULL * 1024ULL * 1024ULL * 1024ULL) 272#define SIZE_1TB (1024ULL * 1024ULL * 1024ULL * 1024ULL) 273#define SIZE_10TB (10ULL * 1024ULL * 1024ULL * 1024ULL * 1024ULL) 274 275 276/* GLOBAL VARIABLES ***********************************************************/ 277 278extern LIST_ENTRY DiskListHead; 279extern LIST_ENTRY BiosDiskListHead; 280extern LIST_ENTRY VolumeListHead; 281 282extern PDISKENTRY CurrentDisk; 283extern PPARTENTRY CurrentPartition; 284extern PVOLENTRY CurrentVolume; 285 286/* PROTOTYPES *****************************************************************/ 287 288/* active.c */ 289EXIT_CODE 290active_main( 291 _In_ INT argc, 292 _In_ PWSTR *argv); 293 294/* add.c */ 295EXIT_CODE 296add_main( 297 _In_ INT argc, 298 _In_ PWSTR *argv); 299 300/* assign.c */ 301EXIT_CODE 302assign_main( 303 _In_ INT argc, 304 _In_ PWSTR *argv); 305 306/* attach.c */ 307EXIT_CODE 308attach_main( 309 _In_ INT argc, 310 _In_ PWSTR *argv); 311 312/* attributes.h */ 313EXIT_CODE 314attributes_main( 315 _In_ INT argc, 316 _In_ PWSTR *argv); 317 318/* automount.c */ 319EXIT_CODE 320automount_main( 321 _In_ INT argc, 322 _In_ PWSTR *argv); 323 324/* break.c */ 325EXIT_CODE 326break_main( 327 _In_ INT argc, 328 _In_ PWSTR *argv); 329 330/* clean.c */ 331EXIT_CODE 332clean_main( 333 _In_ INT argc, 334 _In_ PWSTR *argv); 335 336/* compact.c */ 337EXIT_CODE 338compact_main( 339 _In_ INT argc, 340 _In_ PWSTR *argv); 341 342/* convert.c */ 343NTSTATUS 344CreateDisk( 345 _In_ ULONG DiskNumber, 346 _In_ PCREATE_DISK DiskInfo); 347 348EXIT_CODE 349ConvertGPT( 350 _In_ INT argc, 351 _In_ PWSTR *argv); 352 353EXIT_CODE 354ConvertMBR( 355 _In_ INT argc, 356 _In_ PWSTR *argv); 357 358/* create.c */ 359EXIT_CODE 360CreateEfiPartition( 361 _In_ INT argc, 362 _In_ PWSTR *argv); 363 364EXIT_CODE 365CreateExtendedPartition( 366 _In_ INT argc, 367 _In_ PWSTR *argv); 368 369EXIT_CODE 370CreateLogicalPartition( 371 _In_ INT argc, 372 _In_ PWSTR *argv); 373 374EXIT_CODE 375CreateMsrPartition( 376 _In_ INT argc, 377 _In_ PWSTR *argv); 378 379EXIT_CODE 380CreatePrimaryPartition( 381 _In_ INT argc, 382 _In_ PWSTR *argv); 383 384/* delete.c */ 385EXIT_CODE 386DeleteDisk( 387 _In_ INT argc, 388 _In_ PWSTR *argv); 389 390EXIT_CODE 391DeletePartition( 392 _In_ INT argc, 393 _In_ PWSTR *argv); 394 395EXIT_CODE 396DeleteVolume( 397 _In_ INT argc, 398 _In_ PWSTR *argv); 399 400 401/* detach.c */ 402EXIT_CODE 403detach_main( 404 _In_ INT argc, 405 _In_ PWSTR *argv); 406 407/* detail.c */ 408EXIT_CODE 409DetailDisk( 410 INT argc, 411 PWSTR *argv); 412 413EXIT_CODE 414DetailPartition( 415 INT argc, 416 PWSTR *argv); 417 418EXIT_CODE 419DetailVolume( 420 INT argc, 421 PWSTR *argv); 422 423/* diskpart.c */ 424 425/* dump.c */ 426EXIT_CODE 427DumpDisk( 428 _In_ INT argc, 429 _In_ LPWSTR *argv); 430 431EXIT_CODE 432DumpPartition( 433 _In_ INT argc, 434 _In_ LPWSTR *argv); 435 436 437/* expand.c */ 438EXIT_CODE 439expand_main( 440 _In_ INT argc, 441 _In_ PWSTR *argv); 442 443/* extend.c */ 444EXIT_CODE 445extend_main( 446 _In_ INT argc, 447 _In_ PWSTR *argv); 448 449/* filesystem.c */ 450EXIT_CODE 451filesystems_main( 452 _In_ INT argc, 453 _In_ PWSTR *argv); 454 455/* format.c */ 456EXIT_CODE 457format_main( 458 _In_ INT argc, 459 _In_ PWSTR *argv); 460 461/* gpt.c */ 462EXIT_CODE 463gpt_main( 464 _In_ INT argc, 465 _In_ PWSTR *argv); 466 467/* help.c */ 468EXIT_CODE 469help_main( 470 _In_ INT argc, 471 _In_ PWSTR *argv); 472 473VOID 474HelpCommandList(VOID); 475 476EXIT_CODE 477HelpCommand( 478 _In_ PCOMMAND pCommand); 479 480/* import. c */ 481EXIT_CODE 482import_main( 483 _In_ INT argc, 484 _In_ PWSTR *argv); 485 486/* inactive.c */ 487EXIT_CODE 488inactive_main( 489 _In_ INT argc, 490 _In_ PWSTR *argv); 491 492/* interpreter.c */ 493EXIT_CODE 494InterpretScript( 495 _In_ LPWSTR line); 496 497EXIT_CODE 498InterpretCmd( 499 _In_ INT argc, 500 _In_ PWSTR *argv); 501 502VOID 503InterpretMain(VOID); 504 505/* list.c */ 506EXIT_CODE 507ListDisk( 508 INT argc, 509 PWSTR *argv); 510 511EXIT_CODE 512ListPartition( 513 INT argc, 514 PWSTR *argv); 515 516EXIT_CODE 517ListVolume( 518 INT argc, 519 PWSTR *argv); 520 521EXIT_CODE 522ListVirtualDisk( 523 INT argc, 524 PWSTR *argv); 525 526VOID 527PrintDisk( 528 _In_ PDISKENTRY DiskEntry); 529 530VOID 531PrintVolume( 532 _In_ PVOLENTRY VolumeEntry); 533 534/* merge.c */ 535EXIT_CODE 536merge_main( 537 _In_ INT argc, 538 _In_ PWSTR *argv); 539 540/* misc.c */ 541BOOL 542IsDecString( 543 _In_ PWSTR pszDecString); 544 545BOOL 546IsHexString( 547 _In_ PWSTR pszHexString); 548 549BOOL 550HasPrefix( 551 _In_ PWSTR pszString, 552 _In_ PWSTR pszPrefix, 553 _Out_opt_ PWSTR *pszSuffix); 554 555ULONGLONG 556RoundingDivide( 557 _In_ ULONGLONG Dividend, 558 _In_ ULONGLONG Divisor); 559 560PWSTR 561DuplicateQuotedString( 562 _In_ PWSTR pszInString); 563 564PWSTR 565DuplicateString( 566 _In_ PWSTR pszInString); 567 568VOID 569CreateGUID( 570 _Out_ GUID *pGuid); 571 572VOID 573CreateSignature( 574 _Out_ PDWORD pSignature); 575 576VOID 577PrintGUID( 578 _Out_ PWSTR pszBuffer, 579 _In_ GUID *pGuid); 580 581BOOL 582StringToGUID( 583 _Out_ GUID *pGuid, 584 _In_ PWSTR pszString); 585 586VOID 587PrintBusType( 588 _Out_ PWSTR pszBuffer, 589 _In_ INT cchBufferMax, 590 _In_ STORAGE_BUS_TYPE Bustype); 591 592/* mountmgr.h */ 593BOOL 594GetAutomountState( 595 _Out_ PBOOL State); 596 597BOOL 598SetAutomountState( 599 _In_ BOOL bEnable); 600 601BOOL 602ScrubAutomount(VOID); 603 604BOOL 605AssignDriveLetter( 606 _In_ PWSTR DeviceName, 607 _In_ WCHAR DriveLetter); 608 609BOOL 610AssignNextDriveLetter( 611 _In_ PWSTR DeviceName, 612 _Out_ PWCHAR DriveLetter); 613 614BOOL 615DeleteDriveLetter( 616 _In_ WCHAR DriveLetter); 617 618/* offline.c */ 619EXIT_CODE 620offline_main( 621 _In_ INT argc, 622 _In_ PWSTR *argv); 623 624/* online.c */ 625EXIT_CODE 626online_main( 627 _In_ INT argc, 628 _In_ PWSTR *argv); 629 630/* partlist.c */ 631#ifdef DUMP_PARTITION_TABLE 632VOID 633DumpPartitionTable( 634 _In_ PDISKENTRY DiskEntry); 635#endif 636 637#ifdef DUMP_PARTITION_LIST 638VOID 639DumpPartitionList( 640 _In_ PDISKENTRY DiskEntry); 641#endif 642 643ULONGLONG 644AlignDown( 645 _In_ ULONGLONG Value, 646 _In_ ULONG Alignment); 647 648NTSTATUS 649CreatePartitionList(VOID); 650 651VOID 652DestroyPartitionList(VOID); 653 654NTSTATUS 655CreateVolumeList(VOID); 656 657VOID 658DestroyVolumeList(VOID); 659 660VOID 661ScanForUnpartitionedMbrDiskSpace( 662 PDISKENTRY DiskEntry); 663 664VOID 665ScanForUnpartitionedGptDiskSpace( 666 PDISKENTRY DiskEntry); 667 668VOID 669ReadLayoutBuffer( 670 _In_ HANDLE FileHandle, 671 _In_ PDISKENTRY DiskEntry); 672 673NTSTATUS 674WriteMbrPartitions( 675 _In_ PDISKENTRY DiskEntry); 676 677NTSTATUS 678WriteGptPartitions( 679 _In_ PDISKENTRY DiskEntry); 680 681VOID 682UpdateMbrDiskLayout( 683 _In_ PDISKENTRY DiskEntry); 684 685VOID 686UpdateGptDiskLayout( 687 _In_ PDISKENTRY DiskEntry, 688 _In_ BOOL DeleteEntry); 689 690PPARTENTRY 691GetPrevUnpartitionedEntry( 692 _In_ PPARTENTRY PartEntry); 693 694PPARTENTRY 695GetNextUnpartitionedEntry( 696 _In_ PPARTENTRY PartEntry); 697 698ULONG 699GetPrimaryPartitionCount( 700 _In_ PDISKENTRY DiskEntry); 701 702NTSTATUS 703DismountVolume( 704 _In_ PPARTENTRY PartEntry); 705 706PVOLENTRY 707GetVolumeFromPartition( 708 _In_ PPARTENTRY PartEntry); 709 710VOID 711RemoveVolume( 712 _In_ PVOLENTRY VolumeEntry); 713 714 715/* recover.c */ 716EXIT_CODE 717recover_main( 718 _In_ INT argc, 719 _In_ PWSTR *argv); 720 721/* remove.c */ 722EXIT_CODE 723remove_main( 724 _In_ INT argc, 725 _In_ PWSTR *argv); 726 727/* repair.c */ 728EXIT_CODE 729repair_main( 730 _In_ INT argc, 731 _In_ PWSTR *argv); 732 733/* rescan.c */ 734EXIT_CODE 735rescan_main( 736 _In_ INT argc, 737 _In_ PWSTR *argv); 738 739/* retain.c */ 740EXIT_CODE 741retain_main( 742 _In_ INT argc, 743 _In_ PWSTR *argv); 744 745/* san.c */ 746EXIT_CODE 747san_main( 748 _In_ INT argc, 749 _In_ PWSTR *argv); 750 751/* select.c */ 752EXIT_CODE 753SelectDisk( 754 INT argc, 755 PWSTR *argv); 756 757EXIT_CODE 758SelectPartition( 759 INT argc, 760 PWSTR *argv); 761 762EXIT_CODE 763SelectVolume( 764 INT argc, 765 PWSTR *argv); 766/* 767EXIT_CODE 768SelectVirtualDisk( 769 INT argc, 770 PWSTR *argv); 771*/ 772/* setid.c */ 773EXIT_CODE 774setid_main( 775 _In_ INT argc, 776 _In_ PWSTR *argv); 777 778/* shrink.c */ 779EXIT_CODE 780shrink_main( 781 _In_ INT argc, 782 _In_ PWSTR *argv); 783 784/* uniqueid.c */ 785EXIT_CODE 786UniqueIdDisk( 787 _In_ INT argc, 788 _In_ PWSTR *argv); 789 790#endif /* DISKPART_H */