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