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 <winreg.h> 21 #include <wincon.h> 22 #include <winioctl.h> 23 24 #include <errno.h> 25 #include <strsafe.h> 26 27 #include <conutils.h> 28 29 /* 30 #define NTOS_MODE_USER 31 #include <ndk/exfuncs.h> 32 #include <ndk/iofuncs.h> 33 #include <ndk/obfuncs.h> 34 #include <ndk/psfuncs.h> 35 #include <ndk/rtlfuncs.h> 36 #include <ndk/umfuncs.h> 37 */ 38 39 #define NTOS_MODE_USER 40 #include <ndk/cmfuncs.h> 41 #include <ndk/exfuncs.h> 42 #include <ndk/iofuncs.h> 43 #include <ndk/kefuncs.h> 44 #include <ndk/mmfuncs.h> 45 #include <ndk/obfuncs.h> 46 #include <ndk/psfuncs.h> 47 #include <ndk/rtlfuncs.h> 48 #include <ndk/setypes.h> 49 #include <ndk/umfuncs.h> 50 51 #include "resource.h" 52 53 /* DEFINES *******************************************************************/ 54 55 typedef struct _COMMAND 56 { 57 PWSTR cmd1; 58 PWSTR cmd2; 59 PWSTR cmd3; 60 BOOL (*func)(INT, WCHAR**); 61 INT help; 62 DWORD help_detail; 63 } COMMAND, *PCOMMAND; 64 65 extern COMMAND cmds[]; 66 67 /* NOERR codes for the program */ 68 //#define ERROR_NONE 0 69 //#define ERROR_FATAL 1 70 //#define ERROR_CMD_ARG 2 71 //#define ERROR_FILE 3 72 //#define ERROR_SERVICE 4 73 //#define ERROR_SYNTAX 5 74 75 #define MAX_STRING_SIZE 1024 76 #define MAX_ARGS_COUNT 256 77 78 79 typedef enum _FORMATSTATE 80 { 81 Unformatted, 82 UnformattedOrDamaged, 83 UnknownFormat, 84 Preformatted, 85 Formatted 86 } FORMATSTATE, *PFORMATSTATE; 87 88 typedef enum _VOLUME_TYPE 89 { 90 VOLUME_TYPE_CDROM, 91 VOLUME_TYPE_PARTITION, 92 VOLUME_TYPE_REMOVABLE, 93 VOLUME_TYPE_UNKNOWN 94 } VOLUME_TYPE, *PVOLUME_TYPE; 95 96 typedef struct _PARTENTRY 97 { 98 LIST_ENTRY ListEntry; 99 100 struct _DISKENTRY *DiskEntry; 101 102 ULARGE_INTEGER StartSector; 103 ULARGE_INTEGER SectorCount; 104 105 BOOLEAN BootIndicator; 106 UCHAR PartitionType; 107 ULONG OnDiskPartitionNumber; 108 ULONG PartitionNumber; 109 ULONG PartitionIndex; 110 111 CHAR DriveLetter; 112 CHAR VolumeLabel[17]; 113 CHAR FileSystemName[9]; 114 FORMATSTATE FormatState; 115 116 BOOLEAN LogicalPartition; 117 118 /* Partition is partitioned disk space */ 119 BOOLEAN IsPartitioned; 120 121 /* Partition is new. Table does not exist on disk yet */ 122 BOOLEAN New; 123 124 /* Partition was created automatically. */ 125 BOOLEAN AutoCreate; 126 127 /* Partition must be checked */ 128 BOOLEAN NeedsCheck; 129 130 struct _FILE_SYSTEM_ITEM *FileSystem; 131 } PARTENTRY, *PPARTENTRY; 132 133 134 typedef struct _BIOSDISKENTRY 135 { 136 LIST_ENTRY ListEntry; 137 ULONG DiskNumber; 138 ULONG Signature; 139 ULONG Checksum; 140 BOOLEAN Recognized; 141 CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry; 142 CM_INT13_DRIVE_PARAMETER Int13DiskData; 143 } BIOSDISKENTRY, *PBIOSDISKENTRY; 144 145 146 typedef struct _DISKENTRY 147 { 148 LIST_ENTRY ListEntry; 149 150 ULONGLONG Cylinders; 151 ULONG TracksPerCylinder; 152 ULONG SectorsPerTrack; 153 ULONG BytesPerSector; 154 155 ULARGE_INTEGER SectorCount; 156 ULONG SectorAlignment; 157 ULONG CylinderAlignment; 158 159 BOOLEAN BiosFound; 160 ULONG BiosDiskNumber; 161 // ULONG Signature; 162 // ULONG Checksum; 163 164 ULONG DiskNumber; 165 USHORT Port; 166 USHORT PathId; 167 USHORT TargetId; 168 USHORT Lun; 169 170 /* Has the partition list been modified? */ 171 BOOLEAN Dirty; 172 173 BOOLEAN NewDisk; 174 BOOLEAN NoMbr; /* MBR is absent */ 175 176 UNICODE_STRING DriverName; 177 178 PDRIVE_LAYOUT_INFORMATION LayoutBuffer; 179 180 PPARTENTRY ExtendedPartition; 181 182 LIST_ENTRY PrimaryPartListHead; 183 LIST_ENTRY LogicalPartListHead; 184 185 } DISKENTRY, *PDISKENTRY; 186 187 typedef struct _VOLENTRY 188 { 189 LIST_ENTRY ListEntry; 190 191 ULONG VolumeNumber; 192 WCHAR VolumeName[MAX_PATH]; 193 WCHAR DeviceName[MAX_PATH]; 194 195 WCHAR DriveLetter; 196 197 PWSTR pszLabel; 198 PWSTR pszFilesystem; 199 VOLUME_TYPE VolumeType; 200 ULARGE_INTEGER Size; 201 202 PVOLUME_DISK_EXTENTS pExtents; 203 204 } VOLENTRY, *PVOLENTRY; 205 206 207 /* GLOBAL VARIABLES ***********************************************************/ 208 209 extern LIST_ENTRY DiskListHead; 210 extern LIST_ENTRY BiosDiskListHead; 211 extern LIST_ENTRY VolumeListHead; 212 213 extern PDISKENTRY CurrentDisk; 214 extern PPARTENTRY CurrentPartition; 215 extern PVOLENTRY CurrentVolume; 216 217 /* PROTOTYPES *****************************************************************/ 218 219 /* active.c */ 220 BOOL active_main(INT argc, LPWSTR *argv); 221 222 /* add.c */ 223 BOOL add_main(INT argc, LPWSTR *argv); 224 225 /* assign.c */ 226 BOOL assign_main(INT argc, LPWSTR *argv); 227 228 /* attach.c */ 229 BOOL attach_main(INT argc, LPWSTR *argv); 230 231 /* attributes.h */ 232 BOOL attributes_main(INT argc, LPWSTR *argv); 233 234 /* automount.c */ 235 BOOL automount_main(INT argc, LPWSTR *argv); 236 237 /* break.c */ 238 BOOL break_main(INT argc, LPWSTR *argv); 239 240 /* clean.c */ 241 BOOL clean_main(INT argc, LPWSTR *argv); 242 243 /* compact.c */ 244 BOOL compact_main(INT argc, LPWSTR *argv); 245 246 /* convert.c */ 247 BOOL convert_main(INT argc, LPWSTR *argv); 248 249 /* create.c */ 250 BOOL 251 CreateExtendedPartition( 252 _In_ INT argc, 253 _In_ PWSTR *argv); 254 255 BOOL 256 CreateLogicalPartition( 257 _In_ INT argc, 258 _In_ PWSTR *argv); 259 260 BOOL 261 CreatePrimaryPartition( 262 _In_ INT argc, 263 _In_ PWSTR *argv); 264 265 /* delete.c */ 266 BOOL 267 DeleteDisk( 268 _In_ INT argc, 269 _In_ PWSTR *argv); 270 271 BOOL 272 DeletePartition( 273 _In_ INT argc, 274 _In_ PWSTR *argv); 275 276 BOOL 277 DeleteVolume( 278 _In_ INT argc, 279 _In_ PWSTR *argv); 280 281 282 /* detach.c */ 283 BOOL detach_main(INT argc, LPWSTR *argv); 284 285 /* detail.c */ 286 BOOL 287 DetailDisk( 288 INT argc, 289 PWSTR *argv); 290 291 BOOL 292 DetailPartition( 293 INT argc, 294 PWSTR *argv); 295 296 BOOL 297 DetailVolume( 298 INT argc, 299 PWSTR *argv); 300 301 /* diskpart.c */ 302 303 /* dump.c */ 304 BOOL 305 DumpDisk( 306 _In_ INT argc, 307 _In_ LPWSTR *argv); 308 309 BOOL 310 DumpPartition( 311 _In_ INT argc, 312 _In_ LPWSTR *argv); 313 314 315 /* expand.c */ 316 BOOL expand_main(INT argc, LPWSTR *argv); 317 318 /* extend.c */ 319 BOOL extend_main(INT argc, LPWSTR *argv); 320 321 /* filesystem.c */ 322 BOOL filesystems_main(INT argc, LPWSTR *argv); 323 324 /* format.c */ 325 BOOL format_main(INT argc, LPWSTR *argv); 326 327 /* gpt.c */ 328 BOOL gpt_main(INT argc, LPWSTR *argv); 329 330 /* help.c */ 331 BOOL help_main(INT argc, LPWSTR *argv); 332 VOID HelpCommandList(VOID); 333 BOOL HelpCommand(PCOMMAND pCommand); 334 335 /* import. c */ 336 BOOL import_main(INT argc, LPWSTR *argv); 337 338 /* inactive.c */ 339 BOOL inactive_main(INT argc, LPWSTR *argv); 340 341 /* interpreter.c */ 342 BOOL InterpretScript(LPWSTR line); 343 BOOL InterpretCmd(INT argc, LPWSTR *argv); 344 VOID InterpretMain(VOID); 345 346 /* list.c */ 347 BOOL 348 ListDisk( 349 INT argc, 350 PWSTR *argv); 351 352 BOOL 353 ListPartition( 354 INT argc, 355 PWSTR *argv); 356 357 BOOL 358 ListVolume( 359 INT argc, 360 PWSTR *argv); 361 362 BOOL 363 ListVirtualDisk( 364 INT argc, 365 PWSTR *argv); 366 367 VOID 368 PrintDisk( 369 _In_ PDISKENTRY DiskEntry); 370 371 VOID 372 PrintVolume( 373 _In_ PVOLENTRY VolumeEntry); 374 375 /* merge.c */ 376 BOOL merge_main(INT argc, LPWSTR *argv); 377 378 /* misc.c */ 379 BOOL 380 IsDecString( 381 _In_ PWSTR pszDecString); 382 383 BOOL 384 IsHexString( 385 _In_ PWSTR pszHexString); 386 387 BOOL 388 HasPrefix( 389 _In_ PWSTR pszString, 390 _In_ PWSTR pszPrefix, 391 _Out_opt_ PWSTR *pszSuffix); 392 393 ULONGLONG 394 RoundingDivide( 395 _In_ ULONGLONG Dividend, 396 _In_ ULONGLONG Divisor); 397 398 PWSTR 399 DuplicateQuotedString( 400 _In_ PWSTR pszInString); 401 402 PWSTR 403 DuplicateString( 404 _In_ PWSTR pszInString); 405 406 /* offline.c */ 407 BOOL offline_main(INT argc, LPWSTR *argv); 408 409 /* online.c */ 410 BOOL online_main(INT argc, LPWSTR *argv); 411 412 /* partlist.c */ 413 ULONGLONG 414 AlignDown( 415 _In_ ULONGLONG Value, 416 _In_ ULONG Alignment); 417 418 NTSTATUS 419 CreatePartitionList(VOID); 420 421 VOID 422 DestroyPartitionList(VOID); 423 424 NTSTATUS 425 CreateVolumeList(VOID); 426 427 VOID 428 DestroyVolumeList(VOID); 429 430 NTSTATUS 431 WritePartitions( 432 _In_ PDISKENTRY DiskEntry); 433 434 VOID 435 UpdateDiskLayout( 436 _In_ PDISKENTRY DiskEntry); 437 438 PPARTENTRY 439 GetPrevUnpartitionedEntry( 440 _In_ PPARTENTRY PartEntry); 441 442 PPARTENTRY 443 GetNextUnpartitionedEntry( 444 _In_ PPARTENTRY PartEntry); 445 446 ULONG 447 GetPrimaryPartitionCount( 448 _In_ PDISKENTRY DiskEntry); 449 450 NTSTATUS 451 DismountVolume( 452 _In_ PPARTENTRY PartEntry); 453 454 PVOLENTRY 455 GetVolumeFromPartition( 456 _In_ PPARTENTRY PartEntry); 457 458 VOID 459 RemoveVolume( 460 _In_ PVOLENTRY VolumeEntry); 461 462 463 /* recover.c */ 464 BOOL recover_main(INT argc, LPWSTR *argv); 465 466 /* remove.c */ 467 BOOL remove_main(INT argc, LPWSTR *argv); 468 469 /* repair.c */ 470 BOOL repair_main(INT argc, LPWSTR *argv); 471 472 /* rescan.c */ 473 BOOL rescan_main(INT argc, LPWSTR *argv); 474 475 /* retain.c */ 476 BOOL retain_main(INT argc, LPWSTR *argv); 477 478 /* san.c */ 479 BOOL san_main(INT argc, LPWSTR *argv); 480 481 /* select.c */ 482 BOOL 483 SelectDisk( 484 INT argc, 485 PWSTR *argv); 486 487 BOOL 488 SelectPartition( 489 INT argc, 490 PWSTR *argv); 491 492 BOOL 493 SelectVolume( 494 INT argc, 495 PWSTR *argv); 496 /* 497 BOOL 498 SelectVirtualDisk( 499 INT argc, 500 PWSTR *argv); 501 */ 502 /* setid.c */ 503 BOOL setid_main(INT argc, LPWSTR *argv); 504 505 /* shrink.c */ 506 BOOL shrink_main(INT argc, LPWSTR *argv); 507 508 /* uniqueid.c */ 509 BOOL 510 UniqueIdDisk( 511 _In_ INT argc, 512 _In_ PWSTR *argv); 513 514 #endif /* DISKPART_H */ 515