ReactOS 0.4.16-dev-1990-gfa5cf28
diskpart.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <wincon.h>
#include <winioctl.h>
#include <ntsecapi.h>
#include <errno.h>
#include <strsafe.h>
#include <conutils.h>
#include <ndk/cmfuncs.h>
#include <ndk/exfuncs.h>
#include <ndk/iofuncs.h>
#include <ndk/kefuncs.h>
#include <ndk/mmfuncs.h>
#include <ndk/obfuncs.h>
#include <ndk/psfuncs.h>
#include <ndk/rtlfuncs.h>
#include <ndk/setypes.h>
#include <ndk/umfuncs.h>
#include <fmifs/fmifs.h>
#include <guiddef.h>
#include "guid.h"
#include "resource.h"
Include dependency graph for diskpart.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _COMMAND
 
struct  _MBR_PARTITION_DATA
 
struct  _GPT_PARTITION_DATA
 
struct  _PARTENTRY
 
struct  _BIOSDISKENTRY
 
struct  _DISKENTRY
 
struct  _VOLENTRY
 

Macros

#define WIN32_NO_STATUS
 
#define NTOS_MODE_USER
 
#define MAX_STRING_SIZE   1024
 
#define MAX_ARGS_COUNT   256
 

Typedefs

typedef struct _COMMAND COMMAND
 
typedef struct _COMMANDPCOMMAND
 
typedef enum _FORMATSTATE FORMATSTATE
 
typedef enum _FORMATSTATEPFORMATSTATE
 
typedef enum _VOLUME_TYPE VOLUME_TYPE
 
typedef enum _VOLUME_TYPEPVOLUME_TYPE
 
typedef struct _MBR_PARTITION_DATA MBR_PARTITION_DATA
 
typedef struct _MBR_PARTITION_DATAPMBR_PARTITION_DATA
 
typedef struct _GPT_PARTITION_DATA GPT_PARTITION_DATA
 
typedef struct _GPT_PARTITION_DATAPGPT_PARTITION_DATA
 
typedef struct _PARTENTRY PARTENTRY
 
typedef struct _PARTENTRYPPARTENTRY
 
typedef struct _BIOSDISKENTRY BIOSDISKENTRY
 
typedef struct _BIOSDISKENTRYPBIOSDISKENTRY
 
typedef struct _DISKENTRY DISKENTRY
 
typedef struct _DISKENTRYPDISKENTRY
 
typedef struct _VOLENTRY VOLENTRY
 
typedef struct _VOLENTRYPVOLENTRY
 

Enumerations

enum  _FORMATSTATE {
  Unformatted , UnformattedOrDamaged , UnknownFormat , Formatted ,
  Unformatted , UnformattedOrDamaged , UnknownFormat , Preformatted ,
  Formatted
}
 
enum  _VOLUME_TYPE { VOLUME_TYPE_CDROM , VOLUME_TYPE_PARTITION , VOLUME_TYPE_REMOVABLE , VOLUME_TYPE_UNKNOWN }
 

Functions

BOOL active_main (INT argc, LPWSTR *argv)
 
BOOL add_main (INT argc, LPWSTR *argv)
 
BOOL assign_main (INT argc, LPWSTR *argv)
 
BOOL attach_main (INT argc, LPWSTR *argv)
 
BOOL attributes_main (INT argc, LPWSTR *argv)
 
BOOL automount_main (INT argc, LPWSTR *argv)
 
BOOL break_main (INT argc, LPWSTR *argv)
 
BOOL clean_main (INT argc, LPWSTR *argv)
 
BOOL compact_main (INT argc, LPWSTR *argv)
 
NTSTATUS CreateDisk (_In_ ULONG DiskNumber, _In_ PCREATE_DISK DiskInfo)
 
BOOL ConvertGPT (_In_ INT argc, _In_ PWSTR *argv)
 
BOOL ConvertMBR (_In_ INT argc, _In_ PWSTR *argv)
 
BOOL CreateExtendedPartition (_In_ INT argc, _In_ PWSTR *argv)
 
BOOL CreateLogicalPartition (_In_ INT argc, _In_ PWSTR *argv)
 
BOOL CreatePrimaryPartition (_In_ INT argc, _In_ PWSTR *argv)
 
BOOL DeleteDisk (_In_ INT argc, _In_ PWSTR *argv)
 
BOOL DeletePartition (_In_ INT argc, _In_ PWSTR *argv)
 
BOOL DeleteVolume (_In_ INT argc, _In_ PWSTR *argv)
 
BOOL detach_main (INT argc, LPWSTR *argv)
 
BOOL DetailDisk (INT argc, PWSTR *argv)
 
BOOL DetailPartition (INT argc, PWSTR *argv)
 
BOOL DetailVolume (INT argc, PWSTR *argv)
 
BOOL DumpDisk (_In_ INT argc, _In_ LPWSTR *argv)
 
BOOL DumpPartition (_In_ INT argc, _In_ LPWSTR *argv)
 
BOOL expand_main (INT argc, LPWSTR *argv)
 
BOOL extend_main (INT argc, LPWSTR *argv)
 
BOOL filesystems_main (INT argc, LPWSTR *argv)
 
BOOL format_main (INT argc, LPWSTR *argv)
 
BOOL gpt_main (INT argc, LPWSTR *argv)
 
BOOL help_main (INT argc, LPWSTR *argv)
 
VOID HelpCommandList (VOID)
 
BOOL HelpCommand (PCOMMAND pCommand)
 
BOOL import_main (INT argc, LPWSTR *argv)
 
BOOL inactive_main (INT argc, LPWSTR *argv)
 
BOOL InterpretScript (LPWSTR line)
 
BOOL InterpretCmd (INT argc, LPWSTR *argv)
 
VOID InterpretMain (VOID)
 
BOOL ListDisk (INT argc, PWSTR *argv)
 
BOOL ListPartition (INT argc, PWSTR *argv)
 
BOOL ListVolume (INT argc, PWSTR *argv)
 
BOOL ListVirtualDisk (INT argc, PWSTR *argv)
 
VOID PrintDisk (_In_ PDISKENTRY DiskEntry)
 
VOID PrintVolume (_In_ PVOLENTRY VolumeEntry)
 
BOOL merge_main (INT argc, LPWSTR *argv)
 
BOOL IsDecString (_In_ PWSTR pszDecString)
 
BOOL IsHexString (_In_ PWSTR pszHexString)
 
BOOL HasPrefix (_In_ PWSTR pszString, _In_ PWSTR pszPrefix, _Out_opt_ PWSTR *pszSuffix)
 
ULONGLONG RoundingDivide (_In_ ULONGLONG Dividend, _In_ ULONGLONG Divisor)
 
PWSTR DuplicateQuotedString (_In_ PWSTR pszInString)
 
PWSTR DuplicateString (_In_ PWSTR pszInString)
 
VOID CreateGUID (_Out_ GUID *pGuid)
 
VOID CreateSignature (_Out_ PDWORD pSignature)
 
VOID PrintGUID (_Out_ PWSTR pszBuffer, _In_ GUID *pGuid)
 
BOOL StringToGUID (_Out_ GUID *pGuid, _In_ PWSTR pszString)
 
BOOL offline_main (INT argc, LPWSTR *argv)
 
BOOL online_main (INT argc, LPWSTR *argv)
 
ULONGLONG AlignDown (_In_ ULONGLONG Value, _In_ ULONG Alignment)
 
NTSTATUS CreatePartitionList (VOID)
 
VOID DestroyPartitionList (VOID)
 
NTSTATUS CreateVolumeList (VOID)
 
VOID DestroyVolumeList (VOID)
 
VOID ScanForUnpartitionedMbrDiskSpace (PDISKENTRY DiskEntry)
 
VOID ScanForUnpartitionedGptDiskSpace (PDISKENTRY DiskEntry)
 
VOID ReadLayoutBuffer (_In_ HANDLE FileHandle, _In_ PDISKENTRY DiskEntry)
 
NTSTATUS WriteMbrPartitions (_In_ PDISKENTRY DiskEntry)
 
NTSTATUS WriteGptPartitions (_In_ PDISKENTRY DiskEntry)
 
VOID UpdateMbrDiskLayout (_In_ PDISKENTRY DiskEntry)
 
VOID UpdateGptDiskLayout (_In_ PDISKENTRY DiskEntry, _In_ BOOL DeleteEntry)
 
PPARTENTRY GetPrevUnpartitionedEntry (_In_ PPARTENTRY PartEntry)
 
PPARTENTRY GetNextUnpartitionedEntry (_In_ PPARTENTRY PartEntry)
 
ULONG GetPrimaryPartitionCount (_In_ PDISKENTRY DiskEntry)
 
NTSTATUS DismountVolume (_In_ PPARTENTRY PartEntry)
 
PVOLENTRY GetVolumeFromPartition (_In_ PPARTENTRY PartEntry)
 
VOID RemoveVolume (_In_ PVOLENTRY VolumeEntry)
 
BOOL recover_main (INT argc, LPWSTR *argv)
 
BOOL remove_main (INT argc, LPWSTR *argv)
 
BOOL repair_main (INT argc, LPWSTR *argv)
 
BOOL rescan_main (INT argc, LPWSTR *argv)
 
BOOL retain_main (INT argc, LPWSTR *argv)
 
BOOL san_main (INT argc, LPWSTR *argv)
 
BOOL SelectDisk (INT argc, PWSTR *argv)
 
BOOL SelectPartition (INT argc, PWSTR *argv)
 
BOOL SelectVolume (INT argc, PWSTR *argv)
 
BOOL setid_main (INT argc, LPWSTR *argv)
 
BOOL shrink_main (INT argc, LPWSTR *argv)
 
BOOL UniqueIdDisk (_In_ INT argc, _In_ PWSTR *argv)
 

Variables

COMMAND cmds []
 
LIST_ENTRY DiskListHead
 
LIST_ENTRY BiosDiskListHead
 
LIST_ENTRY VolumeListHead
 
PDISKENTRY CurrentDisk
 
PPARTENTRY CurrentPartition
 
PVOLENTRY CurrentVolume
 

Macro Definition Documentation

◆ MAX_ARGS_COUNT

#define MAX_ARGS_COUNT   256

Definition at line 84 of file diskpart.h.

◆ MAX_STRING_SIZE

#define MAX_STRING_SIZE   1024

Definition at line 83 of file diskpart.h.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 40 of file diskpart.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 17 of file diskpart.h.

Typedef Documentation

◆ BIOSDISKENTRY

◆ COMMAND

◆ DISKENTRY

◆ FORMATSTATE

◆ GPT_PARTITION_DATA

◆ MBR_PARTITION_DATA

◆ PARTENTRY

◆ PBIOSDISKENTRY

◆ PCOMMAND

◆ PDISKENTRY

◆ PFORMATSTATE

◆ PGPT_PARTITION_DATA

◆ PMBR_PARTITION_DATA

◆ PPARTENTRY

◆ PVOLENTRY

◆ PVOLUME_TYPE

◆ VOLENTRY

◆ VOLUME_TYPE

Enumeration Type Documentation

◆ _FORMATSTATE

Enumerator
Unformatted 
UnformattedOrDamaged 
UnknownFormat 
Formatted 
Unformatted 
UnformattedOrDamaged 
UnknownFormat 
Preformatted 
Formatted 

Definition at line 87 of file diskpart.h.

88{
enum _FORMATSTATE FORMATSTATE
enum _FORMATSTATE * PFORMATSTATE
@ UnknownFormat
Definition: diskpart.h:91
@ Preformatted
Definition: diskpart.h:92
@ Formatted
Definition: diskpart.h:93
@ Unformatted
Definition: diskpart.h:89
@ UnformattedOrDamaged
Definition: diskpart.h:90

◆ _VOLUME_TYPE

Enumerator
VOLUME_TYPE_CDROM 
VOLUME_TYPE_PARTITION 
VOLUME_TYPE_REMOVABLE 
VOLUME_TYPE_UNKNOWN 

Definition at line 96 of file diskpart.h.

97{
@ VOLUME_TYPE_UNKNOWN
Definition: diskpart.h:101
@ VOLUME_TYPE_REMOVABLE
Definition: diskpart.h:100
@ VOLUME_TYPE_CDROM
Definition: diskpart.h:98
@ VOLUME_TYPE_PARTITION
Definition: diskpart.h:99
enum _VOLUME_TYPE VOLUME_TYPE
enum _VOLUME_TYPE * PVOLUME_TYPE

Function Documentation

◆ active_main()

BOOL active_main ( INT  argc,
LPWSTR argv 
)

◆ add_main()

BOOL add_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file add.c.

12{
13 return TRUE;
14}
#define TRUE
Definition: types.h:120

◆ AlignDown()

ULONGLONG AlignDown ( _In_ ULONGLONG  Value,
_In_ ULONG  Alignment 
)

Definition at line 191 of file partlist.c.

194{
195 ULONGLONG Temp;
196
197 Temp = Value / Alignment;
198
199 return Temp * Alignment;
200}
union Alignment_ Alignment
uint64_t ULONGLONG
Definition: typedefs.h:67
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

◆ assign_main()

BOOL assign_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file assign.c.

12{
13 return TRUE;
14}

◆ attach_main()

BOOL attach_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file attach.c.

12{
13 return TRUE;
14}

◆ attributes_main()

BOOL attributes_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file attributes.c.

12{
13 return TRUE;
14}

◆ automount_main()

BOOL automount_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file automount.c.

12{
13 ConPuts(StdOut, L"Automount\n");
14 return TRUE;
15}
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define StdOut
Definition: fc.c:14
#define L(x)
Definition: resources.c:13

◆ break_main()

BOOL break_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file break.c.

12{
13 ConPuts(StdOut, L"\nTODO: Add code later since Win 7 Home Premium doesn't have this feature.\n");
14 return TRUE;
15}

◆ clean_main()

BOOL clean_main ( INT  argc,
LPWSTR argv 
)

◆ compact_main()

BOOL compact_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file compact.c.

12{
13 return 0;
14}

◆ ConvertGPT()

BOOL ConvertGPT ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 88 of file convert.c.

91{
92 CREATE_DISK DiskInfo;
94
95 DPRINT("ConvertGPT()\n");
96
97 if (CurrentDisk == NULL)
98 {
100 return TRUE;
101 }
102
104 {
106 return TRUE;
107 }
108
110 {
112 return TRUE;
113 }
114
115#if 0
116 /* Fail if disk size is less than 128MB */
117 if (CurrentDisk->SectorCount.QuadPart * CurrentDisk->BytesPerSector < 128ULL * 1024ULL * 1024ULL)
118 {
119 ConResPuts(StdOut, IDS_CONVERT_GPT_TOO_SMALL);
120 return TRUE;
121 }
122#endif
123
124 DiskInfo.PartitionStyle = PARTITION_STYLE_GPT;
125 CreateGUID(&DiskInfo.Gpt.DiskId);
126 DiskInfo.Gpt.MaxPartitionCount = 128;
127
129 if (!NT_SUCCESS(Status))
130 {
131 DPRINT1("CreateDisk() failed!\n");
132 return TRUE;
133 }
134
139
142
143 return TRUE;
144}
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define IDS_CONVERT_GPT_NOT_EMPTY
Definition: resource.h:31
#define IDS_CONVERT_GPT_SUCCESS
Definition: resource.h:32
#define IDS_SELECT_NO_DISK
Definition: resource.h:95
#define IDS_CONVERT_GPT_ALREADY
Definition: resource.h:30
VOID CreateGUID(_Out_ GUID *pGuid)
Definition: misc.c:152
PDISKENTRY CurrentDisk
Definition: partlist.c:77
VOID ScanForUnpartitionedGptDiskSpace(PDISKENTRY DiskEntry)
Definition: partlist.c:923
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
@ PARTITION_STYLE_GPT
Definition: imports.h:202
ULONGLONG AlignDown(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:67
#define GetPrimaryPartitionCount(DiskEntry)
Definition: partlist.c:2527
#define DPRINT
Definition: sndvol32.h:73
ULARGE_INTEGER EndSector
Definition: diskpart.h:185
ULONG SectorAlignment
Definition: partlist.h:116
ULARGE_INTEGER SectorCount
Definition: partlist.h:115
ULONG DiskNumber
Definition: partlist.h:129
ULONG BytesPerSector
Definition: partlist.h:113
ULARGE_INTEGER StartSector
Definition: diskpart.h:184
DWORD PartitionStyle
Definition: diskpart.h:202
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:143
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
NTSTATUS CreateDisk(_In_ ULONG DiskNumber, _In_ PCREATE_DISK DiskInfo)
Definition: convert.c:15

◆ ConvertMBR()

BOOL ConvertMBR ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 148 of file convert.c.

151{
152 CREATE_DISK DiskInfo;
154
155 DPRINT("ConvertMBR()\n");
156
157 if (CurrentDisk == NULL)
158 {
160 return TRUE;
161 }
162
164 (CurrentDisk->PartitionStyle == PARTITION_STYLE_RAW))
165 {
167 return TRUE;
168 }
169
171 {
173 return TRUE;
174 }
175
176 DiskInfo.PartitionStyle = PARTITION_STYLE_MBR;
177 CreateSignature(&DiskInfo.Mbr.Signature);
178
180 if (!NT_SUCCESS(Status))
181 {
182 DPRINT1("CreateDisk() failed!\n");
183 return TRUE;
184 }
185
188
191
192 return TRUE;
193}
#define IDS_CONVERT_MBR_ALREADY
Definition: resource.h:33
#define IDS_CONVERT_MBR_NOT_EMPTY
Definition: resource.h:34
#define IDS_CONVERT_MBR_SUCCESS
Definition: resource.h:35
VOID ScanForUnpartitionedMbrDiskSpace(PDISKENTRY DiskEntry)
Definition: partlist.c:662
VOID CreateSignature(_Out_ PDWORD pSignature)
Definition: misc.c:168
@ PARTITION_STYLE_MBR
Definition: imports.h:201
#define min(a, b)
Definition: monoChain.cc:55

◆ CreateDisk()

NTSTATUS CreateDisk ( _In_ ULONG  DiskNumber,
_In_ PCREATE_DISK  DiskInfo 
)

Definition at line 15 of file convert.c.

18{
25
26 DPRINT("CreateDisk(%lu %p)\n", DiskNumber, DiskInfo);
27
29 L"\\Device\\Harddisk%lu\\Partition0",
32
34 &Name,
36 NULL,
37 NULL);
38
42 &Iosb,
43 0,
45 if (!NT_SUCCESS(Status))
46 {
47 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
48 goto done;
49 }
50
52 NULL,
53 NULL,
54 NULL,
55 &Iosb,
57 DiskInfo,
58 sizeof(*DiskInfo),
59 NULL,
60 0);
61 if (!NT_SUCCESS(Status))
62 {
63 DPRINT1("NtDeviceIoControlFile() failed (Status %lx)\n", Status);
64 goto done;
65 }
66
67 /* Free the layout buffer */
69 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentDisk->LayoutBuffer);
70
75 CurrentDisk->PartitionStyle = DiskInfo->PartitionStyle;
76
78
79done:
80 if (FileHandle)
82
83 return Status;
84}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
LPWSTR Name
Definition: desk.c:124
VOID ReadLayoutBuffer(_In_ HANDLE FileHandle, _In_ PDISKENTRY DiskEntry)
Definition: partlist.c:1067
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
return Iosb
Definition: create.c:4403
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3953
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define GENERIC_WRITE
Definition: nt_native.h:90
#define IOCTL_DISK_CREATE_DISK
Definition: ntdddisk.h:55
IN HANDLE DstPath
Definition: fsutil.h:81
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
PPARTENTRY ExtendedPartition
Definition: partlist.h:153
BOOLEAN NewDisk
Definition: partlist.h:138
BOOLEAN Dirty
Definition: partlist.h:136
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ConvertGPT(), ConvertMBR(), CreateExtendedPartition(), and CreatePrimaryPartition().

◆ CreateExtendedPartition()

BOOL CreateExtendedPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 16 of file create.c.

19{
20 PPARTENTRY PartEntry, NewPartEntry;
21 PLIST_ENTRY ListEntry;
22 ULONGLONG ullSize = 0ULL;
23 ULONGLONG ullSectorCount;
24#if 0
25 ULONGLONG ullOffset = 0ULL;
26 BOOL bNoErr = FALSE;
27#endif
28 INT i;
29 PWSTR pszSuffix = NULL;
31
32 if (CurrentDisk == NULL)
33 {
35 return TRUE;
36 }
37
39 {
41 return TRUE;
42 }
43 else if (CurrentDisk->PartitionStyle == PARTITION_STYLE_RAW)
44 {
45 CREATE_DISK DiskInfo;
47
48 DiskInfo.PartitionStyle = PARTITION_STYLE_MBR;
49 CreateSignature(&DiskInfo.Mbr.Signature);
50
52 if (!NT_SUCCESS(Status))
53 {
54 DPRINT1("CreateDisk() failed!\n");
55 return TRUE;
56 }
57
60
62 }
63
64 for (i = 3; i < argc; i++)
65 {
66 if (HasPrefix(argv[i], L"size=", &pszSuffix))
67 {
68 /* size=<N> (MB) */
69 DPRINT("Size : %s\n", pszSuffix);
70
71 ullSize = _wcstoui64(pszSuffix, NULL, 10);
72 if ((ullSize == 0) && (errno == ERANGE))
73 {
75 return TRUE;
76 }
77 }
78 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
79 {
80 /* offset=<N> (KB) */
81 DPRINT("Offset : %s\n", pszSuffix);
82 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
83#if 0
84 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
85 if ((ullOffset == 0) && (errno == ERANGE))
86 {
88 return TRUE;
89 }
90#endif
91 }
92 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
93 {
94 /* align=<N> */
95 DPRINT("Align : %s\n", pszSuffix);
96 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
97#if 0
98 bAlign = TRUE;
99#endif
100 }
101 else if (_wcsicmp(argv[i], L"noerr") == 0)
102 {
103 /* noerr */
104 DPRINT("NoErr\n", pszSuffix);
105 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
106#if 0
107 bNoErr = TRUE;
108#endif
109 }
110 else
111 {
113 return TRUE;
114 }
115 }
116
117 DPRINT1("Size: %I64u\n", ullSize);
118#if 0
119 DPRINT1("Offset: %I64u\n", ullOffset);
120#endif
121
123 {
124 ConPuts(StdOut, L"No space left for an extended partition!\n");
125 return TRUE;
126 }
127
129 {
130 ConPuts(StdOut, L"We already have an extended partition on this disk!\n");
131 return TRUE;
132 }
133
134 if (ullSize != 0)
135 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
136 else
137 ullSectorCount = 0;
138
139 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
140
142
143 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
144 if (PartEntry->IsPartitioned)
145 {
146 ConPuts(StdOut, L"No disk space left for an extended partition!\n");
147 return TRUE;
148 }
149
150 if (ullSectorCount == 0)
151 {
152 PartEntry->IsPartitioned = TRUE;
153 PartEntry->New = TRUE;
155 PartEntry->FormatState = Unformatted;
156 PartEntry->FileSystemName[0] = L'\0';
157
158 CurrentPartition = PartEntry;
160 }
161 else
162 {
163 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
164 {
165 PartEntry->IsPartitioned = TRUE;
166 PartEntry->New = TRUE;
168 PartEntry->FormatState = Unformatted;
169 PartEntry->FileSystemName[0] = L'\0';
170
171 CurrentPartition = PartEntry;
173 }
174 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
175 {
176 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
177 if (NewPartEntry == NULL)
178 {
179 ConPuts(StdOut, L"Memory allocation failed!\n");
180 return TRUE;
181 }
182
183 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
184
185 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
186 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
187
188 NewPartEntry->LogicalPartition = FALSE;
189 NewPartEntry->IsPartitioned = TRUE;
190 NewPartEntry->New = TRUE;
191 NewPartEntry->Mbr.PartitionType = PARTITION_EXTENDED;
192 NewPartEntry->FormatState = Unformatted;
193 NewPartEntry->FileSystemName[0] = L'\0';
194
195 PartEntry->StartSector.QuadPart += ullSectorCount;
196 PartEntry->SectorCount.QuadPart -= ullSectorCount;
197
198 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
199
200 CurrentPartition = NewPartEntry;
202 }
203 }
204
207 if (!NT_SUCCESS(Status))
208 {
211 return TRUE;
212 }
213
215
216 return TRUE;
217}
static int argc
Definition: ServiceArgs.c:12
#define ERANGE
Definition: acclib.h:92
#define StdErr
Definition: fc.c:15
#define IDS_CREATE_PARTITION_INVALID_STYLE
Definition: resource.h:39
#define IDS_CREATE_PARTITION_FAIL
Definition: resource.h:37
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:203
#define IDS_CREATE_PARTITION_SUCCESS
Definition: resource.h:38
#define PARTITION_EXTENDED
Definition: disk.h:76
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
VOID UpdateMbrDiskLayout(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:2167
BOOL HasPrefix(_In_ PWSTR pszString, _In_ PWSTR pszPrefix, _Out_opt_ PWSTR *pszSuffix)
Definition: misc.c:58
NTSTATUS WriteMbrPartitions(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:1839
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define InsertTailList(ListHead, Entry)
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
@ Unformatted
Definition: partlist.h:34
#define ULL(a, b)
Definition: format_msg.c:27
#define argv
Definition: mplay32.c:18
#define errno
Definition: errno.h:18
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
Definition: _wcsicmp_nt.c:13
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:149
Definition: typedefs.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
BOOLEAN IsPartitioned
Definition: partlist.h:82
BOOLEAN New
Definition: partlist.h:85
ULARGE_INTEGER SectorCount
Definition: partlist.h:70
struct _DISKENTRY * DiskEntry
Definition: partlist.h:66
BOOLEAN LogicalPartition
Definition: partlist.h:79
MBR_PARTITION_DATA Mbr
Definition: diskpart.h:128
FORMATSTATE FormatState
Definition: diskpart.h:139
LIST_ENTRY ListEntry
Definition: partlist.h:63
ULARGE_INTEGER StartSector
Definition: partlist.h:69
CHAR FileSystemName[9]
Definition: diskpart.h:138
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static PPARTENTRY CurrentPartition
Definition: usetup.c:78
unsigned __int64 CDECL _wcstoui64(const wchar_t *nptr, wchar_t **endptr, int base)
Definition: wtoi64.c:200

◆ CreateGUID()

VOID CreateGUID ( _Out_ GUID pGuid)

Definition at line 152 of file misc.c.

154{
155 RtlGenRandom(pGuid, sizeof(*pGuid));
156 /* Clear the version bits and set the version (4) */
157 pGuid->Data3 &= 0x0fff;
158 pGuid->Data3 |= (4 << 12);
159 /* Set the topmost bits of Data4 (clock_seq_hi_and_reserved) as
160 * specified in RFC 4122, section 4.4.
161 */
162 pGuid->Data4[0] &= 0x3f;
163 pGuid->Data4[0] |= 0x80;
164}
#define RtlGenRandom
Definition: ntsecapi.h:691

Referenced by ConvertGPT(), and CreatePrimaryGptPartition().

◆ CreateLogicalPartition()

BOOL CreateLogicalPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 221 of file create.c.

224{
225 PPARTENTRY PartEntry, NewPartEntry;
226 PLIST_ENTRY ListEntry;
227 ULONGLONG ullSize = 0ULL;
228 ULONGLONG ullSectorCount;
229#if 0
230 ULONGLONG ullOffset = 0ULL;
231 BOOL bNoErr = FALSE;
232#endif
234 INT i, length;
235 PWSTR pszSuffix = NULL;
237
238 if (CurrentDisk == NULL)
239 {
241 return TRUE;
242 }
243
245 {
247 return TRUE;
248 }
249
250 for (i = 3; i < argc; i++)
251 {
252 if (HasPrefix(argv[i], L"size=", &pszSuffix))
253 {
254 /* size=<N> (MB) */
255 DPRINT("Size : %s\n", pszSuffix);
256
257 ullSize = _wcstoui64(pszSuffix, NULL, 10);
258 if ((ullSize == 0) && (errno == ERANGE))
259 {
261 return TRUE;
262 }
263 }
264 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
265 {
266 /* offset=<N> (KB) */
267 DPRINT("Offset : %s\n", pszSuffix);
268 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
269#if 0
270 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
271 if ((ullOffset == 0) && (errno == ERANGE))
272 {
274 return TRUE;
275 }
276#endif
277 }
278 else if (HasPrefix(argv[i], L"id=", &pszSuffix))
279 {
280 /* id=<Byte> */
281 DPRINT("Id : %s\n", pszSuffix);
282
283 length = wcslen(pszSuffix);
284 if ((length == 1) || (length == 2))
285 {
286 /* Byte */
287 PartitionType = (UCHAR)wcstoul(pszSuffix, NULL, 16);
288 if ((PartitionType == 0) && (errno == ERANGE))
289 {
291 return TRUE;
292 }
293 }
294 else
295 {
297 return TRUE;
298 }
299 }
300 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
301 {
302 /* align=<N> */
303 DPRINT("Align : %s\n", pszSuffix);
304 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
305#if 0
306 bAlign = TRUE;
307#endif
308 }
309 else if (_wcsicmp(argv[i], L"noerr") == 0)
310 {
311 /* noerr */
312 DPRINT("NoErr\n", pszSuffix);
313 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
314#if 0
315 bNoErr = TRUE;
316#endif
317 }
318 else
319 {
321 return TRUE;
322 }
323 }
324
325 DPRINT1("Size: %I64u\n", ullSize);
326#if 0
327 DPRINT1("Offset: %I64u\n", ullOffset);
328#endif
329 DPRINT1("Partition Type: %hx\n", PartitionType);
330
331 if (ullSize != 0)
332 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
333 else
334 ullSectorCount = 0;
335
336 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
337
338 for (ListEntry = CurrentDisk->LogicalPartListHead.Flink;
339 ListEntry != &CurrentDisk->LogicalPartListHead;
340 ListEntry = ListEntry->Flink)
341 {
342 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
343 if (PartEntry->IsPartitioned)
344 continue;
345
346 if (ullSectorCount == 0)
347 {
348 PartEntry->IsPartitioned = TRUE;
349 PartEntry->New = TRUE;
350 PartEntry->Mbr.PartitionType = PartitionType;
351 PartEntry->FormatState = Unformatted;
352 PartEntry->FileSystemName[0] = L'\0';
353
354 CurrentPartition = PartEntry;
356 break;
357 }
358 else
359 {
360 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
361 {
362 PartEntry->IsPartitioned = TRUE;
363 PartEntry->New = TRUE;
364 PartEntry->Mbr.PartitionType = PartitionType;
365 PartEntry->FormatState = Unformatted;
366 PartEntry->FileSystemName[0] = L'\0';
367
368 CurrentPartition = PartEntry;
370 break;
371 }
372 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
373 {
374 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
375 if (NewPartEntry == NULL)
376 {
377 ConPuts(StdOut, L"Memory allocation failed!\n");
378 return TRUE;
379 }
380
381 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
382
383 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
384 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
385
386 NewPartEntry->LogicalPartition = TRUE;
387 NewPartEntry->IsPartitioned = TRUE;
388 NewPartEntry->New = TRUE;
389 NewPartEntry->Mbr.PartitionType = PartitionType;
390 NewPartEntry->FormatState = Unformatted;
391 NewPartEntry->FileSystemName[0] = L'\0';
392
393 PartEntry->StartSector.QuadPart += ullSectorCount;
394 PartEntry->SectorCount.QuadPart -= ullSectorCount;
395
396 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
397
398 CurrentPartition = NewPartEntry;
400 break;
401 }
402 }
403 }
404
407 if (!NT_SUCCESS(Status))
408 {
411 return TRUE;
412 }
413
415
416 return TRUE;
417}
#define PARTITION_HUGE
Definition: disk.h:77
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
CHAR PartitionType
Definition: part_xbox.c:32
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:150
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ CreatePartitionList()

NTSTATUS CreatePartitionList ( VOID  )

Definition at line 1988 of file partlist.c.

1989{
1991 PDISKENTRY SystemDisk;
1995 ULONG ReturnSize;
1997 ULONG DiskNumber;
2001
2003 0,
2004 sizeof(PARTLIST));
2005 if (!List)
2006 return NULL;
2007
2008 List->SystemPartition = NULL;
2009
2010 InitializeListHead(&List->DiskListHead);
2011 InitializeListHead(&List->BiosDiskListHead);
2012 InitializeListHead(&List->VolumesList);
2013
2014 /*
2015 * Enumerate the disks seen by the BIOS; this will be used later
2016 * to map drives seen by NTOS with their corresponding BIOS names.
2017 */
2019
2020 /* Enumerate disks seen by NTOS */
2022 &Sdi,
2023 sizeof(Sdi),
2024 &ReturnSize);
2025 if (!NT_SUCCESS(Status))
2026 {
2027 DPRINT1("NtQuerySystemInformation() failed, Status 0x%08lx\n", Status);
2029 return NULL;
2030 }
2031
2032 for (DiskNumber = 0; DiskNumber < Sdi.NumberOfDisks; DiskNumber++)
2033 {
2035 L"\\Device\\Harddisk%lu\\Partition0",
2036 DiskNumber);
2038
2040 &Name,
2042 NULL,
2043 NULL);
2044
2048 &Iosb,
2051 if (NT_SUCCESS(Status))
2052 {
2053 AddDiskToList(FileHandle, DiskNumber, List);
2055 }
2056 }
2057
2061
2062 /*
2063 * Retrieve the system partition: the active partition on the system
2064 * disk (the one that will be booted by default by the hardware).
2065 */
2066 SystemDisk = GetSystemDisk(List);
2067 List->SystemPartition = (SystemDisk ? GetActiveDiskPartition(SystemDisk) : NULL);
2068
2069 return List;
2070}
HANDLE ProcessHeap
Definition: servman.c:15
Definition: bufpool.h:45
#define FILE_SHARE_READ
Definition: compat.h:136
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
@ SystemDeviceInformation
Definition: ntddk_ex.h:18
struct _PARTLIST * PPARTLIST
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
NTSTRSAFEVAPI RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1110
static PDISKENTRY GetSystemDisk(IN PPARTLIST List)
Definition: partlist.c:1857
static VOID AssignDriveLetters(IN PPARTLIST List)
Definition: partlist.c:138
static VOID AddDiskToList(IN HANDLE FileHandle, IN ULONG DiskNumber, IN PPARTLIST List)
Definition: partlist.c:1445
static VOID UpdateDiskSignatures(IN PPARTLIST List)
Definition: partlist.c:1354
static VOID EnumerateBiosDiskEntries(IN PPARTLIST PartList)
Definition: partlist.c:327
static PPARTENTRY GetActiveDiskPartition(IN PDISKENTRY DiskEntry)
Definition: partlist.c:1930
static VOID UpdateHwDiskNumbers(IN PPARTLIST List)
Definition: partlist.c:1384
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550

Referenced by LoadSetupData(), rescan_main(), SelectPartitionPage(), UpgradeRepairPage(), and wmain().

◆ CreatePrimaryPartition()

BOOL CreatePrimaryPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 682 of file create.c.

685{
686 ULONGLONG ullSize = 0ULL;
687#if 0
688 ULONGLONG ullOffset = 0ULL;
689 BOOL bNoErr = FALSE;
690#endif
691 INT i;
692 PWSTR pszSuffix = NULL;
693 PWSTR pszPartitionType = NULL;
694
695 if (CurrentDisk == NULL)
696 {
698 return TRUE;
699 }
700
701 if (CurrentDisk->PartitionStyle == PARTITION_STYLE_RAW)
702 {
703 CREATE_DISK DiskInfo;
705
706 DiskInfo.PartitionStyle = PARTITION_STYLE_MBR;
707 CreateSignature(&DiskInfo.Mbr.Signature);
708
710 if (!NT_SUCCESS(Status))
711 {
712 DPRINT1("CreateDisk() failed!\n");
713 return TRUE;
714 }
715
718
720 }
721
722 for (i = 3; i < argc; i++)
723 {
724 if (HasPrefix(argv[i], L"size=", &pszSuffix))
725 {
726 /* size=<N> (MB) */
727 DPRINT("Size : %s\n", pszSuffix);
728
729 ullSize = _wcstoui64(pszSuffix, NULL, 10);
730 if ((ullSize == 0) && (errno == ERANGE))
731 {
733 return TRUE;
734 }
735 }
736 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
737 {
738 /* offset=<N> (KB) */
739 DPRINT("Offset : %s\n", pszSuffix);
740 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
741#if 0
742 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
743 if ((ullOffset == 0) && (errno == ERANGE))
744 {
746 return TRUE;
747 }
748#endif
749 }
750 else if (HasPrefix(argv[i], L"id=", &pszSuffix))
751 {
752 /* id=<Byte>|<GUID> */
753 DPRINT("Id : %s\n", pszSuffix);
754 pszPartitionType = pszSuffix;
755 }
756 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
757 {
758 /* align=<N> */
759 DPRINT("Align : %s\n", pszSuffix);
760 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
761#if 0
762 bAlign = TRUE;
763#endif
764 }
765 else if (_wcsicmp(argv[i], L"noerr") == 0)
766 {
767 /* noerr */
768 DPRINT("NoErr\n", pszSuffix);
769 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
770#if 0
771 bNoErr = TRUE;
772#endif
773 }
774 else
775 {
777 return TRUE;
778 }
779 }
780
781 DPRINT("Size: %I64u\n", ullSize);
782#if 0
783 DPRINT1("Offset: %I64u\n", ullOffset);
784#endif
785
787 {
788 DPRINT("Partition Type: %s\n", pszPartitionType);
789 CreatePrimaryMbrPartition(ullSize, pszPartitionType);
790 }
792 {
793 CreatePrimaryGptPartition(ullSize, pszPartitionType);
794 }
795
796 return TRUE;
797}
static VOID CreatePrimaryGptPartition(_In_ ULONGLONG ullSize, _In_ PWSTR pszPartitionType)
Definition: create.c:549
static VOID CreatePrimaryMbrPartition(_In_ ULONGLONG ullSize, _In_ PWSTR pszPartitionType)
Definition: create.c:422

◆ CreateSignature()

VOID CreateSignature ( _Out_ PDWORD  pSignature)

Definition at line 168 of file misc.c.

170{
171 LARGE_INTEGER SystemTime;
174
175 NtQuerySystemTime(&SystemTime);
176 RtlTimeToTimeFields(&SystemTime, &TimeFields);
177
178 Buffer = (PUCHAR)pSignature;
179 Buffer[0] = (UCHAR)(TimeFields.Year & 0xFF) + (UCHAR)(TimeFields.Hour & 0xFF);
180 Buffer[1] = (UCHAR)(TimeFields.Year >> 8) + (UCHAR)(TimeFields.Minute & 0xFF);
181 Buffer[2] = (UCHAR)(TimeFields.Month & 0xFF) + (UCHAR)(TimeFields.Second & 0xFF);
182 Buffer[3] = (UCHAR)(TimeFields.Day & 0xFF) + (UCHAR)(TimeFields.Milliseconds & 0xFF);
183}
BOOLEAN RtlTimeToTimeFields(IN PLARGE_INTEGER Time, IN PTIME_FIELDS TimeFields)
static PTIME_FIELDS TimeFields
Definition: time.c:104
NTSTATUS NTAPI NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
Definition: time.c:569
USHORT Milliseconds
Definition: env_spec_w32.h:717
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by ConvertMBR(), CreateExtendedPartition(), and CreatePrimaryPartition().

◆ CreateVolumeList()

NTSTATUS CreateVolumeList ( VOID  )

Definition at line 1772 of file partlist.c.

1773{
1774 HANDLE hVolume = INVALID_HANDLE_VALUE;
1775 WCHAR szVolumeName[MAX_PATH];
1776 ULONG ulVolumeNumber = 0;
1777 BOOL Success;
1778
1780
1782
1783 hVolume = FindFirstVolumeW(szVolumeName, ARRAYSIZE(szVolumeName));
1784 if (hVolume == INVALID_HANDLE_VALUE)
1785 {
1786
1787 return STATUS_UNSUCCESSFUL;
1788 }
1789
1790 AddVolumeToList(ulVolumeNumber++, szVolumeName);
1791
1792 for (;;)
1793 {
1794 Success = FindNextVolumeW(hVolume, szVolumeName, ARRAYSIZE(szVolumeName));
1795 if (!Success)
1796 {
1797 break;
1798 }
1799
1800 AddVolumeToList(ulVolumeNumber++, szVolumeName);
1801 }
1802
1803 FindVolumeClose(hVolume);
1804
1805 return STATUS_SUCCESS;
1806}
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FindNextVolumeW(IN HANDLE handle, IN LPWSTR volume, IN DWORD len)
Definition: volume.c:1082
HANDLE WINAPI FindFirstVolumeW(IN LPWSTR volume, IN DWORD len)
Definition: volume.c:660
BOOL WINAPI FindVolumeClose(IN HANDLE hFindVolume)
Definition: volume.c:741
@ Success
Definition: eventcreate.c:712
#define STATUS_SUCCESS
Definition: shellext.h:65
LIST_ENTRY VolumeListHead
Definition: partlist.c:75
static VOID AddVolumeToList(ULONG ulVolumeNumber, PWSTR pszVolumeName)
Definition: partlist.c:1656
PVOLENTRY CurrentVolume
Definition: partlist.c:79
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by rescan_main(), and wmain().

◆ DeleteDisk()

BOOL DeleteDisk ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 28 of file delete.c.

31{
32 return TRUE;
33}

◆ DeletePartition()

BOOL DeletePartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 273 of file delete.c.

276{
277 INT i;
278 BOOL bOverride = FALSE;
279
280 DPRINT("DeletePartition()\n");
281
282 if (CurrentDisk == NULL)
283 {
285 return TRUE;
286 }
287
288 if (CurrentPartition == NULL)
289 {
291 return TRUE;
292 }
293
294 for (i = 2; i < argc; i++)
295 {
296 if (_wcsicmp(argv[i], L"noerr") == 0)
297 {
298 /* noerr */
299 DPRINT("NOERR\n");
300 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
301#if 0
302 bNoErr = TRUE;
303#endif
304 }
305 else if (_wcsicmp(argv[i], L"override") == 0)
306 {
307 /* override */
308 DPRINT("OVERRIDE\n");
309 bOverride = TRUE;
310 }
311 else
312 {
314 return TRUE;
315 }
316 }
317
319 {
320 DeleteMbrPartition(bOverride);
321 }
323 {
324 DeleteGptPartition(bOverride);
325 }
326
327 return TRUE;
328}
static VOID DeleteGptPartition(_In_ BOOL bOverride)
Definition: delete.c:161
static VOID DeleteMbrPartition(_In_ BOOL bOverride)
Definition: delete.c:38
#define IDS_SELECT_NO_PARTITION
Definition: resource.h:100

◆ DeleteVolume()

BOOL DeleteVolume ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 332 of file delete.c.

335{
336 return TRUE;
337}

◆ DestroyPartitionList()

VOID DestroyPartitionList ( VOID  )

Definition at line 1491 of file partlist.c.

1492{
1493 PDISKENTRY DiskEntry;
1494 PBIOSDISKENTRY BiosDiskEntry;
1495 PPARTENTRY PartEntry;
1497
1498 CurrentDisk = NULL;
1500
1501 /* Release disk and partition info */
1502 while (!IsListEmpty(&DiskListHead))
1503 {
1505 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
1506
1507 /* Release driver name */
1508 RtlFreeUnicodeString(&DiskEntry->DriverName);
1509
1510 /* Release primary partition list */
1511 while (!IsListEmpty(&DiskEntry->PrimaryPartListHead))
1512 {
1514 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1515
1516 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1517 }
1518
1519 /* Release logical partition list */
1520 while (!IsListEmpty(&DiskEntry->LogicalPartListHead))
1521 {
1523 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1524
1525 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1526 }
1527
1528 /* Release layout buffer */
1529 if (DiskEntry->LayoutBuffer != NULL)
1530 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry->LayoutBuffer);
1531
1532
1533 /* Release disk entry */
1534 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry);
1535 }
1536
1537 /* Release the bios disk info */
1538 while (!IsListEmpty(&BiosDiskListHead))
1539 {
1541 BiosDiskEntry = CONTAINING_RECORD(Entry, BIOSDISKENTRY, ListEntry);
1542
1543 RtlFreeHeap(RtlGetProcessHeap(), 0, BiosDiskEntry);
1544 }
1545}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
base of all file and directory entries
Definition: entries.h:83
UNICODE_STRING DriverName
Definition: partlist.h:141
LIST_ENTRY BiosDiskListHead
Definition: partlist.c:74
LIST_ENTRY DiskListHead
Definition: partlist.c:73
PPARTENTRY CurrentPartition
Definition: partlist.c:78

◆ DestroyVolumeList()

VOID DestroyVolumeList ( VOID  )

Definition at line 1810 of file partlist.c.

1811{
1813 PVOLENTRY VolumeEntry;
1814
1816
1817 /* Release disk and partition info */
1818 while (!IsListEmpty(&VolumeListHead))
1819 {
1821 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
1822
1823 if (VolumeEntry->pszLabel)
1824 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
1825
1826 if (VolumeEntry->pszFilesystem)
1827 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
1828
1829 if (VolumeEntry->pExtents)
1830 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pExtents);
1831
1832 /* Release disk entry */
1833 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
1834 }
1835}
PVOLUME_DISK_EXTENTS pExtents
Definition: diskpart.h:230
PWSTR pszFilesystem
Definition: diskpart.h:226
PWSTR pszLabel
Definition: diskpart.h:225

Referenced by rescan_main(), and wmain().

◆ detach_main()

BOOL detach_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file detach.c.

12{
13 return TRUE;
14}

◆ DetailDisk()

BOOL DetailDisk ( INT  argc,
PWSTR argv 
)

◆ DetailPartition()

BOOL DetailPartition ( INT  argc,
PWSTR argv 
)

◆ DetailVolume()

BOOL DetailVolume ( INT  argc,
PWSTR argv 
)

◆ DismountVolume()

NTSTATUS DismountVolume ( _In_ PPARTENTRY  PartEntry)

Definition at line 2490 of file partlist.c.

2492{
2494 NTSTATUS LockStatus;
2498 HANDLE PartitionHandle;
2500
2501 /* Check whether the partition is valid and was mounted by the system */
2502 if (!PartEntry->IsPartitioned ||
2503 IsContainerPartition(PartEntry->Mbr.PartitionType) ||
2504 !IsRecognizedPartition(PartEntry->Mbr.PartitionType) ||
2505 PartEntry->FormatState == UnknownFormat ||
2506 // NOTE: If FormatState == Unformatted but *FileSystem != 0 this means
2507 // it has been usually mounted with RawFS and thus needs to be dismounted.
2508/* !*PartEntry->FileSystem || */
2509 PartEntry->PartitionNumber == 0)
2510 {
2511 /* The partition is not mounted, so just return success */
2512 return STATUS_SUCCESS;
2513 }
2514
2515 ASSERT(PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED);
2516
2517 /* Open the volume */
2519 L"\\Device\\Harddisk%lu\\Partition%lu",
2520 PartEntry->DiskEntry->DiskNumber,
2521 PartEntry->PartitionNumber);
2523
2525 &Name,
2527 NULL,
2528 NULL);
2529
2530 Status = NtOpenFile(&PartitionHandle,
2536 if (!NT_SUCCESS(Status))
2537 {
2538 DPRINT1("ERROR: Cannot open volume %wZ for dismounting! (Status 0x%lx)\n", &Name, Status);
2539 return Status;
2540 }
2541
2542 /* Lock the volume */
2543 LockStatus = NtFsControlFile(PartitionHandle,
2544 NULL,
2545 NULL,
2546 NULL,
2549 NULL,
2550 0,
2551 NULL,
2552 0);
2553 if (!NT_SUCCESS(LockStatus))
2554 {
2555 DPRINT1("WARNING: Failed to lock volume! Operations may fail! (Status 0x%lx)\n", LockStatus);
2556 }
2557
2558 /* Dismount the volume */
2559 Status = NtFsControlFile(PartitionHandle,
2560 NULL,
2561 NULL,
2562 NULL,
2565 NULL,
2566 0,
2567 NULL,
2568 0);
2569 if (!NT_SUCCESS(Status))
2570 {
2571 DPRINT1("Failed to unmount volume (Status 0x%lx)\n", Status);
2572 }
2573
2574 /* Unlock the volume */
2575 LockStatus = NtFsControlFile(PartitionHandle,
2576 NULL,
2577 NULL,
2578 NULL,
2581 NULL,
2582 0,
2583 NULL,
2584 0);
2585 if (!NT_SUCCESS(LockStatus))
2586 {
2587 DPRINT1("Failed to unlock volume (Status 0x%lx)\n", LockStatus);
2588 }
2589
2590 /* Close the volume */
2591 NtClose(PartitionHandle);
2592
2593 return Status;
2594}
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:71
@ UnknownFormat
Definition: partlist.h:36
#define ASSERT(a)
Definition: mode.c:44
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
NTSYSAPI NTSTATUS NTAPI NtFsControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:321
#define IsRecognizedPartition(PartitionType)
Definition: ntdddisk.h:342
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75

◆ DumpDisk()

BOOL DumpDisk ( _In_ INT  argc,
_In_ LPWSTR argv 
)

Definition at line 48 of file dump.c.

51{
58 PUCHAR pSectorBuffer = NULL;
60 LONGLONG Sector;
61 LPWSTR endptr = NULL;
62
63#if 0
64 if (argc == 2)
65 {
66 ConResPuts(StdOut, IDS_HELP_CMD_DUMP_DISK);
67 return TRUE;
68 }
69#endif
70
71 if (CurrentDisk == NULL)
72 {
74 return TRUE;
75 }
76
77 Sector = _wcstoi64(argv[2], &endptr, 0);
78 if (((Sector == 0) && (endptr == argv[2])) ||
79 (Sector < 0))
80 {
82 return TRUE;
83 }
84
85 pSectorBuffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, CurrentDisk->BytesPerSector);
86 if (pSectorBuffer == NULL)
87 {
88 DPRINT1("\n");
89 /* Error message */
90 goto done;
91 }
92
94 L"\\Device\\Harddisk%d\\Partition0",
97 Buffer);
98
100 &Name,
101 0,
102 NULL,
103 NULL);
104
108 &Iosb,
111 if (!NT_SUCCESS(Status))
112 {
113 DPRINT1("\n");
114 goto done;
115 }
116
117 FileOffset.QuadPart = Sector * CurrentDisk->BytesPerSector;
119 NULL,
120 NULL,
121 NULL,
122 &Iosb,
123 (PVOID)pSectorBuffer,
125 &FileOffset,
126 NULL);
127 if (!NT_SUCCESS(Status))
128 {
129 DPRINT1("NtReadFile failed, status=%x\n", Status);
130 goto done;
131 }
132
133 HexDump(pSectorBuffer, CurrentDisk->BytesPerSector);
134
135done:
136 if (FileHandle)
138
139 RtlFreeHeap(RtlGetProcessHeap(), 0, pSectorBuffer);
140
141 return TRUE;
142}
static VOID HexDump(_In_ UCHAR *addr, _In_ int len)
Definition: dump.c:18
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
#define swprintf
Definition: precomp.h:40
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
int64_t LONGLONG
Definition: typedefs.h:68
__int64 CDECL _wcstoi64(const wchar_t *nptr, wchar_t **endptr, int base)
Definition: wtoi64.c:121
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ DumpPartition()

BOOL DumpPartition ( _In_ INT  argc,
_In_ LPWSTR argv 
)

Definition at line 146 of file dump.c.

149{
156 PUCHAR pSectorBuffer = NULL;
158 LONGLONG Sector;
159 LPWSTR endptr = NULL;
160
161
162#if 0
163 if (argc == 2)
164 {
165 ConResPuts(StdOut, IDS_HELP_CMD_DUMP_DISK);
166 return TRUE;
167 }
168#endif
169
170 if (CurrentDisk == NULL)
171 {
173 return TRUE;
174 }
175
176 if (CurrentPartition == NULL)
177 {
179 return TRUE;
180 }
181
182 Sector = _wcstoi64(argv[2], &endptr, 0);
183 if (((Sector == 0) && (endptr == argv[2])) ||
184 (Sector < 0))
185 {
187 return TRUE;
188 }
189
190 pSectorBuffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, CurrentDisk->BytesPerSector);
191 if (pSectorBuffer == NULL)
192 {
193 DPRINT1("\n");
194 /* Error message */
195 goto done;
196 }
197
199 L"\\Device\\Harddisk%d\\Partition%d",
203 Buffer);
204
206 &Name,
207 0,
208 NULL,
209 NULL);
210
214 &Iosb,
217 if (!NT_SUCCESS(Status))
218 {
219 DPRINT1("\n");
220 goto done;
221 }
222
223 FileOffset.QuadPart = Sector * CurrentDisk->BytesPerSector;
225 NULL,
226 NULL,
227 NULL,
228 &Iosb,
229 (PVOID)pSectorBuffer,
231 &FileOffset,
232 NULL);
233 if (!NT_SUCCESS(Status))
234 {
235 DPRINT1("NtReadFile failed, status=%x\n", Status);
236 goto done;
237 }
238
239 HexDump(pSectorBuffer, CurrentDisk->BytesPerSector);
240
241done:
242 if (FileHandle)
244
245 RtlFreeHeap(RtlGetProcessHeap(), 0, pSectorBuffer);
246
247 return TRUE;
248}
ULONG PartitionNumber
Definition: partlist.h:75

◆ DuplicateQuotedString()

PWSTR DuplicateQuotedString ( _In_ PWSTR  pszInString)

Definition at line 84 of file misc.c.

86{
87 PWSTR pszOutString = NULL;
88 PWSTR pStart, pEnd;
90
91 if ((pszInString == NULL) || (pszInString[0] == UNICODE_NULL))
92 return NULL;
93
94 if (pszInString[0] == L'"')
95 {
96 if (pszInString[1] == UNICODE_NULL)
97 return NULL;
98
99 pStart = &pszInString[1];
100 pEnd = wcschr(pStart, '"');
101 if (pEnd == NULL)
102 {
103 nLength = wcslen(pStart);
104 }
105 else
106 {
107 nLength = (pEnd - pStart);
108 }
109 }
110 else
111 {
112 pStart = pszInString;
113 nLength = wcslen(pStart);
114 }
115
116 pszOutString = RtlAllocateHeap(RtlGetProcessHeap(),
118 (nLength + 1) * sizeof(WCHAR));
119 if (pszOutString == NULL)
120 return NULL;
121
122 wcsncpy(pszOutString, pStart, nLength);
123
124 return pszOutString;
125}
wcsncpy
#define wcschr
Definition: compat.h:17
#define UNICODE_NULL
WINBASEAPI _In_ DWORD nLength
Definition: wincon.h:682

◆ DuplicateString()

PWSTR DuplicateString ( _In_ PWSTR  pszInString)

Definition at line 129 of file misc.c.

131{
132 PWSTR pszOutString = NULL;
133 INT nLength;
134
135 if ((pszInString == NULL) || (pszInString[0] == UNICODE_NULL))
136 return NULL;
137
138 nLength = wcslen(pszInString);
139 pszOutString = RtlAllocateHeap(RtlGetProcessHeap(),
141 (nLength + 1) * sizeof(WCHAR));
142 if (pszOutString == NULL)
143 return NULL;
144
145 wcscpy(pszOutString, pszInString);
146
147 return pszOutString;
148}
wcscpy

◆ expand_main()

BOOL expand_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file expand.c.

12{
13 return TRUE;
14}

◆ extend_main()

BOOL extend_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file extend.c.

12{
13 return TRUE;
14}

◆ filesystems_main()

BOOL filesystems_main ( INT  argc,
LPWSTR argv 
)

◆ format_main()

BOOL format_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file format.c.

12{
13 return TRUE;
14}

◆ GetNextUnpartitionedEntry()

PPARTENTRY GetNextUnpartitionedEntry ( _In_ PPARTENTRY  PartEntry)

Definition at line 2461 of file partlist.c.

2463{
2464 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
2465 PPARTENTRY NextPartEntry;
2466 PLIST_ENTRY ListHead;
2467
2468 if (PartEntry->LogicalPartition)
2469 ListHead = &DiskEntry->LogicalPartListHead;
2470 else
2471 ListHead = &DiskEntry->PrimaryPartListHead;
2472
2473 if (PartEntry->ListEntry.Flink != ListHead)
2474 {
2475 NextPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Flink,
2476 PARTENTRY,
2477 ListEntry);
2478 if (!NextPartEntry->IsPartitioned)
2479 {
2481 return NextPartEntry;
2482 }
2483 }
2484
2485 return NULL;
2486}

Referenced by DeleteGptPartition(), and DeleteMbrPartition().

◆ GetPrevUnpartitionedEntry()

PPARTENTRY GetPrevUnpartitionedEntry ( _In_ PPARTENTRY  PartEntry)

Definition at line 2432 of file partlist.c.

2434{
2435 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
2436 PPARTENTRY PrevPartEntry;
2437 PLIST_ENTRY ListHead;
2438
2439 if (PartEntry->LogicalPartition)
2440 ListHead = &DiskEntry->LogicalPartListHead;
2441 else
2442 ListHead = &DiskEntry->PrimaryPartListHead;
2443
2444 if (PartEntry->ListEntry.Blink != ListHead)
2445 {
2446 PrevPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Blink,
2447 PARTENTRY,
2448 ListEntry);
2449 if (!PrevPartEntry->IsPartitioned)
2450 {
2452 return PrevPartEntry;
2453 }
2454 }
2455
2456 return NULL;
2457}

Referenced by DeleteGptPartition(), and DeleteMbrPartition().

◆ GetPrimaryPartitionCount()

ULONG GetPrimaryPartitionCount ( _In_ PDISKENTRY  DiskEntry)

Definition at line 2071 of file partlist.c.

2073{
2075 PPARTENTRY PartEntry;
2076 ULONG Count = 0;
2077
2078 for (Entry = DiskEntry->PrimaryPartListHead.Flink;
2079 Entry != &DiskEntry->PrimaryPartListHead;
2080 Entry = Entry->Flink)
2081 {
2082 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
2083 if (PartEntry->IsPartitioned)
2084 Count++;
2085 }
2086
2087 return Count;
2088}
int Count
Definition: noreturn.cpp:7

◆ GetVolumeFromPartition()

PVOLENTRY GetVolumeFromPartition ( _In_ PPARTENTRY  PartEntry)

Definition at line 2598 of file partlist.c.

2600{
2602 PVOLENTRY VolumeEntry;
2603 ULONG i;
2604
2605 if ((PartEntry == NULL) ||
2606 (PartEntry->DiskEntry == NULL))
2607 return NULL;
2608
2610 while (Entry != &VolumeListHead)
2611 {
2612 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
2613
2614 if (VolumeEntry->pExtents == NULL)
2615 return NULL;
2616
2617 for (i = 0; i < VolumeEntry->pExtents->NumberOfDiskExtents; i++)
2618 {
2619 if (VolumeEntry->pExtents->Extents[i].DiskNumber == PartEntry->DiskEntry->DiskNumber)
2620 {
2621 if ((VolumeEntry->pExtents->Extents[i].StartingOffset.QuadPart == PartEntry->StartSector.QuadPart * PartEntry->DiskEntry->BytesPerSector) &&
2622 (VolumeEntry->pExtents->Extents[i].ExtentLength.QuadPart == PartEntry->SectorCount.QuadPart * PartEntry->DiskEntry->BytesPerSector))
2623 return VolumeEntry;
2624 }
2625 }
2626
2627 Entry = Entry->Flink;
2628 }
2629
2630 return NULL;
2631}
ULONG DiskNumber
Definition: ntddvol.h:48
LARGE_INTEGER StartingOffset
Definition: ntddvol.h:49
LARGE_INTEGER ExtentLength
Definition: ntddvol.h:50
DISK_EXTENT Extents[1]
Definition: ntddvol.h:55
ULONG NumberOfDiskExtents
Definition: ntddvol.h:54
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by clean_main().

◆ gpt_main()

BOOL gpt_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file gpt.c.

12{
13 return TRUE;
14}

◆ HasPrefix()

BOOL HasPrefix ( _In_ PWSTR  pszString,
_In_ PWSTR  pszPrefix,
_Out_opt_ PWSTR pszSuffix 
)

Definition at line 58 of file misc.c.

62{
63 INT nPrefixLength, ret;
64
65 nPrefixLength = wcslen(pszPrefix);
66 ret = _wcsnicmp(pszString, pszPrefix, nPrefixLength);
67 if ((ret == 0) && (ppszSuffix != NULL))
68 *ppszSuffix = &pszString[nPrefixLength];
69
70 return (ret == 0);
71}
return ret
Definition: mutex.c:146
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
Definition: _wcsnicmp_nt.c:13

Referenced by AcpiExGetNameString(), CreateExtendedPartition(), CreateLogicalPartition(), CreatePrimaryPartition(), setid_main(), and UniqueIdDisk().

◆ help_main()

BOOL help_main ( INT  argc,
LPWSTR argv 
)

Definition at line 120 of file help.c.

121{
122 PCOMMAND cmdptr;
123 PCOMMAND cmdptr1 = NULL;
124 PCOMMAND cmdptr2 = NULL;
125 PCOMMAND cmdptr3 = NULL;
126
127 if (argc == 1)
128 {
130 return TRUE;
131 }
132
133 /* Scan internal command table */
134 for (cmdptr = cmds; cmdptr->cmd1; cmdptr++)
135 {
136 if ((cmdptr1 == NULL) &&
137 (cmdptr->cmd1 != NULL && _wcsicmp(argv[1], cmdptr->cmd1) == 0))
138 {
139 cmdptr1 = cmdptr;
140 }
141
142 if ((cmdptr2 == NULL) &&
143 (argc >= 3) &&
144 (cmdptr->cmd1 != NULL && _wcsicmp(argv[1], cmdptr->cmd1) == 0) &&
145 (cmdptr->cmd2 != NULL && _wcsicmp(argv[2], cmdptr->cmd2) == 0))
146 {
147 cmdptr2 = cmdptr;
148 }
149
150 if ((cmdptr3 == NULL) &&
151 (argc >= 4) &&
152 (cmdptr->cmd1 != NULL && _wcsicmp(argv[1], cmdptr->cmd1) == 0) &&
153 (cmdptr->cmd2 != NULL && _wcsicmp(argv[2], cmdptr->cmd2) == 0) &&
154 (cmdptr->cmd3 != NULL && _wcsicmp(argv[3], cmdptr->cmd3) == 0))
155 {
156 cmdptr3 = cmdptr;
157 }
158 }
159
160 if (cmdptr3 != NULL)
161 {
162 return HelpCommand(cmdptr3);
163 }
164 else if (cmdptr2 != NULL)
165 {
166 return HelpCommand(cmdptr2);
167 }
168 else if (cmdptr1 != NULL)
169 {
170 return HelpCommand(cmdptr1);
171 }
172
174
175 return TRUE;
176}
COMMAND cmds[]
Definition: main.c:21
BOOL HelpCommand(PCOMMAND pCommand)
Definition: help.c:46
VOID HelpCommandList(VOID)
Definition: help.c:16
Definition: main.c:15
PWSTR cmd3
Definition: diskpart.h:67
PWSTR cmd2
Definition: diskpart.h:66
PWSTR cmd1
Definition: diskpart.h:65

◆ HelpCommand()

BOOL HelpCommand ( PCOMMAND  pCommand)

Definition at line 46 of file help.c.

48{
49 PCOMMAND cmdptr;
50 BOOL bSubCommands = FALSE;
51 WCHAR szFormat[64];
52 WCHAR szOutput[256];
53
55
56 ConPuts(StdOut, L"\n");
57
58 /* List all the commands and the basic descriptions */
59 for (cmdptr = cmds; cmdptr->cmd1; cmdptr++)
60 {
61 if (pCommand->cmd1 != NULL && pCommand->cmd2 == NULL && pCommand->cmd3 == NULL)
62 {
63 if ((cmdptr->cmd1 != NULL && _wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0) &&
64 (cmdptr->cmd2 != NULL) &&
65 (cmdptr->cmd3 == NULL) &&
66 (cmdptr->help != IDS_NONE))
67 {
68 K32LoadStringW(GetModuleHandle(NULL), cmdptr->help, szOutput, ARRAYSIZE(szOutput));
69 ConPrintf(StdOut, szFormat, cmdptr->cmd2, szOutput);
70 bSubCommands = TRUE;
71 }
72 }
73 else if (pCommand->cmd1 != NULL && pCommand->cmd2 != NULL && pCommand->cmd3 == NULL)
74 {
75 if ((cmdptr->cmd1 != NULL && _wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0) &&
76 (cmdptr->cmd2 != NULL && _wcsicmp(pCommand->cmd2, cmdptr->cmd2) == 0) &&
77 (cmdptr->cmd3 != NULL) &&
78 (cmdptr->help != IDS_NONE))
79 {
80 K32LoadStringW(GetModuleHandle(NULL), cmdptr->help, szOutput, ARRAYSIZE(szOutput));
81 ConPrintf(StdOut, szFormat, cmdptr->cmd3, szOutput);
82 bSubCommands = TRUE;
83 }
84 }
85 else if (pCommand->cmd1 != NULL && pCommand->cmd2 != NULL && pCommand->cmd3 != NULL)
86 {
87 if ((cmdptr->cmd1 != NULL && _wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0) &&
88 (cmdptr->cmd2 != NULL && _wcsicmp(pCommand->cmd2, cmdptr->cmd2) == 0) &&
89 (cmdptr->cmd3 != NULL && _wcsicmp(pCommand->cmd3, cmdptr->cmd3) == 0) &&
90 (cmdptr->help_detail != MSG_NONE))
91 {
94 NULL,
95 cmdptr->help_detail,
97 bSubCommands = TRUE;
98 }
99 }
100 }
101
102 if ((bSubCommands == FALSE) && (pCommand->help_detail != MSG_NONE))
103 {
106 NULL,
107 pCommand->help_detail,
109 }
110
111 ConPuts(StdOut, L"\n");
112
113 return TRUE;
114}
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define IDS_NONE
Definition: resource.h:144
#define MSG_NONE
Definition: resource.h:12
#define IDS_HELP_FORMAT_STRING
Definition: resource.h:74
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:837
INT WINAPI K32LoadStringW(IN HINSTANCE hInstance OPTIONAL, IN UINT uID, OUT LPWSTR lpBuffer, IN INT nBufferMax)
Definition: utils.c:173
INT help
Definition: diskpart.h:69
DWORD help_detail
Definition: diskpart.h:70
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define GetModuleHandle
Definition: winbase.h:3576
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:399

Referenced by help_main(), InterpretCmd(), and main().

◆ HelpCommandList()

VOID HelpCommandList ( VOID  )

Definition at line 16 of file help.c.

17{
18 PCOMMAND cmdptr;
19 WCHAR szFormat[64];
20 WCHAR szOutput[256];
21
23
24 /* Print the header information */
26 ConPuts(StdOut, L"\n");
27
28 /* List all the commands and the basic descriptions */
29 for (cmdptr = cmds; cmdptr->cmd1; cmdptr++)
30 {
31 if ((cmdptr->cmd1 != NULL) &&
32 (cmdptr->cmd2 == NULL) &&
33 (cmdptr->cmd3 == NULL) &&
34 (cmdptr->help != IDS_NONE))
35 {
36 K32LoadStringW(GetModuleHandle(NULL), cmdptr->help, szOutput, ARRAYSIZE(szOutput));
37 ConPrintf(StdOut, szFormat, cmdptr->cmd1, szOutput);
38 }
39 }
40
41 ConPuts(StdOut, L"\n");
42}
#define IDS_APP_HEADER
Definition: resource.h:14

Referenced by help_main(), and InterpretCmd().

◆ import_main()

BOOL import_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file import.c.

12{
13 return TRUE;
14}

◆ inactive_main()

BOOL inactive_main ( INT  argc,
LPWSTR argv 
)

◆ InterpretCmd()

BOOL InterpretCmd ( INT  argc,
LPWSTR argv 
)

◆ InterpretMain()

VOID InterpretMain ( VOID  )

Definition at line 234 of file interpreter.c.

235{
236 WCHAR input_line[MAX_STRING_SIZE];
237 LPWSTR args_vector[MAX_ARGS_COUNT];
238 INT args_count = 0;
239 BOOL bWhiteSpace = TRUE;
240 BOOL bQuote = FALSE;
241 BOOL bRun = TRUE;
242 LPWSTR ptr;
243
244 while (bRun != FALSE)
245 {
246 args_count = 0;
247 memset(args_vector, 0, sizeof(args_vector));
248
249 /* Shown just before the input where the user places commands */
251
252 /* Get input from the user. */
253 fgetws(input_line, MAX_STRING_SIZE, stdin);
254
255 bQuote = FALSE;
256 ptr = input_line;
257 while (*ptr != 0)
258 {
259 if (*ptr == L'"')
260 bQuote = !bQuote;
261
262 if ((iswspace(*ptr) && (bQuote == FALSE))|| *ptr == L'\n')
263 {
264 *ptr = 0;
265 bWhiteSpace = TRUE;
266 }
267 else
268 {
269 if ((bWhiteSpace != FALSE) && (bQuote == FALSE) && (args_count < MAX_ARGS_COUNT))
270 {
271 args_vector[args_count] = ptr;
272 args_count++;
273 }
274 bWhiteSpace = FALSE;
275 }
276 ptr++;
277 }
278
279 /* Send the string to find the command */
280 bRun = InterpretCmd(args_count, args_vector);
281 }
282}
#define MAX_STRING_SIZE
Definition: precomp.h:40
#define MAX_ARGS_COUNT
Definition: precomp.h:41
#define IDS_APP_PROMPT
Definition: resource.h:13
BOOL InterpretCmd(int argc, LPWSTR *argv)
Definition: interpreter.c:111
#define iswspace(_c)
Definition: ctype.h:669
#define stdin
Definition: stdio.h:98
static PVOID ptr
Definition: dispmode.c:27
#define memset(x, y, z)
Definition: compat.h:39
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22

Referenced by wmain().

◆ InterpretScript()

BOOL InterpretScript ( LPWSTR  line)

Definition at line 186 of file interpreter.c.

187{
188 LPWSTR args_vector[MAX_ARGS_COUNT];
189 INT args_count = 0;
190 BOOL bWhiteSpace = TRUE;
191 BOOL bQuote = FALSE;
192 LPWSTR ptr;
193
194 memset(args_vector, 0, sizeof(args_vector));
195
196 bQuote = FALSE;
197 ptr = input_line;
198 while (*ptr != 0)
199 {
200 if (*ptr == L'"')
201 bQuote = !bQuote;
202
203 if ((iswspace(*ptr) && (bQuote == FALSE))|| *ptr == L'\n')
204 {
205 *ptr = 0;
206 bWhiteSpace = TRUE;
207 }
208 else
209 {
210 if ((bWhiteSpace != FALSE) && (bQuote == FALSE) && (args_count < MAX_ARGS_COUNT))
211 {
212 args_vector[args_count] = ptr;
213 args_count++;
214 }
215
216 bWhiteSpace = FALSE;
217 }
218
219 ptr++;
220 }
221
222 /* sends the string to find the command */
223 return InterpretCmd(args_count, args_vector);
224}

Referenced by RunScript().

◆ IsDecString()

BOOL IsDecString ( _In_ PWSTR  pszDecString)

Definition at line 14 of file misc.c.

16{
17 PWSTR ptr;
18
19 if ((pszDecString == NULL) || (*pszDecString == UNICODE_NULL))
20 return FALSE;
21
22 ptr = pszDecString;
23 while (*ptr != UNICODE_NULL)
24 {
25 if (!iswdigit(*ptr))
26 return FALSE;
27
28 ptr++;
29 }
30
31 return TRUE;
32}
#define iswdigit(_c)
Definition: ctype.h:667

Referenced by SelectDisk(), SelectPartition(), and SelectVolume().

◆ IsHexString()

BOOL IsHexString ( _In_ PWSTR  pszHexString)

Definition at line 36 of file misc.c.

38{
39 PWSTR ptr;
40
41 if ((pszHexString == NULL) || (*pszHexString == UNICODE_NULL))
42 return FALSE;
43
44 ptr = pszHexString;
45 while (*ptr != UNICODE_NULL)
46 {
47 if (!iswxdigit(*ptr))
48 return FALSE;
49
50 ptr++;
51 }
52
53 return TRUE;
54}
#define iswxdigit(_c)
Definition: ctype.h:668

Referenced by UniqueIdDisk().

◆ ListDisk()

BOOL ListDisk ( INT  argc,
PWSTR argv 
)

Definition at line 59 of file list.c.

62{
64 PDISKENTRY DiskEntry;
65
66 /* Header labels */
67 ConPuts(StdOut, L"\n");
70
72 while (Entry != &DiskListHead)
73 {
74 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
75
76 PrintDisk(DiskEntry);
77
78 Entry = Entry->Flink;
79 }
80
81 ConPuts(StdOut, L"\n\n");
82
83 return TRUE;
84}
VOID PrintDisk(_In_ PDISKENTRY DiskEntry)
Definition: list.c:17
#define IDS_LIST_DISK_LINE
Definition: resource.h:82
#define IDS_LIST_DISK_HEAD
Definition: resource.h:81
LIST_ENTRY DiskListHead
Definition: partlist.c:73

◆ ListPartition()

BOOL ListPartition ( INT  argc,
PWSTR argv 
)

Definition at line 88 of file list.c.

91{
93 PPARTENTRY PartEntry;
94 ULONGLONG PartSize;
95 ULONGLONG PartOffset;
96 LPWSTR lpSizeUnit;
97 LPWSTR lpOffsetUnit;
98 ULONG PartNumber = 1;
99
100 if (CurrentDisk == NULL)
101 {
103 return TRUE;
104 }
105
106 /* Header labels */
107 ConPuts(StdOut, L"\n");
110
112 {
115 {
116 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
117
118 if (PartEntry->Mbr.PartitionType != 0)
119 {
120 PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector;
121
122 if (PartSize >= 10737418240) /* 10 GB */
123 {
124 PartSize = RoundingDivide(PartSize, 1073741824);
125 lpSizeUnit = L"GB";
126 }
127 else if (PartSize >= 10485760) /* 10 MB */
128 {
129 PartSize = RoundingDivide(PartSize, 1048576);
130 lpSizeUnit = L"MB";
131 }
132 else
133 {
134 PartSize = RoundingDivide(PartSize, 1024);
135 lpSizeUnit = L"KB";
136 }
137
138 PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector;
139
140 if (PartOffset >= 10737418240) /* 10 GB */
141 {
142 PartOffset = RoundingDivide(PartOffset, 1073741824);
143 lpOffsetUnit = L"GB";
144 }
145 else if (PartOffset >= 10485760) /* 10 MB */
146 {
147 PartOffset = RoundingDivide(PartOffset, 1048576);
148 lpOffsetUnit = L"MB";
149 }
150 else
151 {
152 PartOffset = RoundingDivide(PartOffset, 1024);
153 lpOffsetUnit = L"KB";
154 }
155
157 (CurrentPartition == PartEntry) ? L'*' : L' ',
158 PartNumber++,
159 IsContainerPartition(PartEntry->Mbr.PartitionType) ? L"Extended" : L"Primary",
160 PartSize,
161 lpSizeUnit,
162 PartOffset,
163 lpOffsetUnit);
164 }
165
166 Entry = Entry->Flink;
167 }
168
171 {
172 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
173
174 if (PartEntry->Mbr.PartitionType != 0)
175 {
176 PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector;
177
178 if (PartSize >= 10737418240) /* 10 GB */
179 {
180 PartSize = RoundingDivide(PartSize, 1073741824);
181 lpSizeUnit = L"GB";
182 }
183 else if (PartSize >= 10485760) /* 10 MB */
184 {
185 PartSize = RoundingDivide(PartSize, 1048576);
186 lpSizeUnit = L"MB";
187 }
188 else
189 {
190 PartSize = RoundingDivide(PartSize, 1024);
191 lpSizeUnit = L"KB";
192 }
193
194 PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector;
195
196 if (PartOffset >= 10737418240) /* 10 GB */
197 {
198 PartOffset = RoundingDivide(PartOffset, 1073741824);
199 lpOffsetUnit = L"GB";
200 }
201 else if (PartOffset >= 10485760) /* 10 MB */
202 {
203 PartOffset = RoundingDivide(PartOffset, 1048576);
204 lpOffsetUnit = L"MB";
205 }
206 else
207 {
208 PartOffset = RoundingDivide(PartOffset, 1024);
209 lpOffsetUnit = L"KB";
210 }
211
213 (CurrentPartition == PartEntry) ? L'*' : L' ',
214 PartNumber++,
215 L"Logical",
216 PartSize,
217 lpSizeUnit,
218 PartOffset,
219 lpOffsetUnit);
220 }
221
222 Entry = Entry->Flink;
223 }
224 }
226 {
227 LPWSTR lpPartitionType;
228
231 {
232 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
233
234 if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID))
235 {
236 PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector;
237
238 if (PartSize >= 10737418240) /* 10 GB */
239 {
240 PartSize = RoundingDivide(PartSize, 1073741824);
241 lpSizeUnit = L"GB";
242 }
243 else if (PartSize >= 10485760) /* 10 MB */
244 {
245 PartSize = RoundingDivide(PartSize, 1048576);
246 lpSizeUnit = L"MB";
247 }
248 else
249 {
250 PartSize = RoundingDivide(PartSize, 1024);
251 lpSizeUnit = L"KB";
252 }
253
254 PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector;
255
256 if (PartOffset >= 10737418240) /* 10 GB */
257 {
258 PartOffset = RoundingDivide(PartOffset, 1073741824);
259 lpOffsetUnit = L"GB";
260 }
261 else if (PartOffset >= 10485760) /* 10 MB */
262 {
263 PartOffset = RoundingDivide(PartOffset, 1048576);
264 lpOffsetUnit = L"MB";
265 }
266 else
267 {
268 PartOffset = RoundingDivide(PartOffset, 1024);
269 lpOffsetUnit = L"KB";
270 }
271
272 if (IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID))
273 {
274 lpPartitionType = L"Unused";
275 }
276 else if (IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_BASIC_DATA_GUID))
277 {
278 lpPartitionType = L"Primary";
279 }
280 else if (IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_SYSTEM_GUID))
281 {
282 lpPartitionType = L"System";
283 }
284 else if (IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_MSFT_RESERVED_GUID))
285 {
286 lpPartitionType = L"Reserved";
287 }
288 else
289 {
290 lpPartitionType = L"Other"; /* ??? */
291 }
292
294 (CurrentPartition == PartEntry) ? L'*' : L' ',
295 PartNumber++,
296 lpPartitionType,
297 PartSize,
298 lpSizeUnit,
299 PartOffset,
300 lpOffsetUnit);
301 }
302
303 Entry = Entry->Flink;
304 }
305 }
306
307 ConPuts(StdOut, L"\n");
308
309 return TRUE;
310}
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define IDS_LIST_PARTITION_NO_DISK
Definition: resource.h:87
#define IDS_LIST_PARTITION_HEAD
Definition: resource.h:84
#define IDS_LIST_PARTITION_LINE
Definition: resource.h:85
#define IDS_LIST_PARTITION_FORMAT
Definition: resource.h:86
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
ULONGLONG RoundingDivide(IN ULONGLONG Dividend, IN ULONGLONG Divisor)
Definition: partlist.c:95
GPT_PARTITION_DATA Gpt
Definition: diskpart.h:129

◆ ListVirtualDisk()

BOOL ListVirtualDisk ( INT  argc,
PWSTR argv 
)

Definition at line 394 of file list.c.

397{
398 ConPuts(StdOut, L"ListVirtualDisk()!\n");
399 return TRUE;
400}

◆ ListVolume()

BOOL ListVolume ( INT  argc,
PWSTR argv 
)

Definition at line 366 of file list.c.

369{
371 PVOLENTRY VolumeEntry;
372
373 ConPuts(StdOut, L"\n");
376
378 while (Entry != &VolumeListHead)
379 {
380 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
381
382 PrintVolume(VolumeEntry);
383
384 Entry = Entry->Flink;
385 }
386
387 ConPuts(StdOut, L"\n");
388
389 return TRUE;
390}
VOID PrintVolume(_In_ PVOLENTRY VolumeEntry)
Definition: list.c:314
#define IDS_LIST_VOLUME_LINE
Definition: resource.h:89
#define IDS_LIST_VOLUME_HEAD
Definition: resource.h:88
LIST_ENTRY VolumeListHead
Definition: partlist.c:75

◆ merge_main()

BOOL merge_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file merge.c.

12{
13 return TRUE;
14}

◆ offline_main()

BOOL offline_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file offline.c.

12{
13 return TRUE;
14}

◆ online_main()

BOOL online_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file online.c.

12{
13 return TRUE;
14}

◆ PrintDisk()

VOID PrintDisk ( _In_ PDISKENTRY  DiskEntry)

Definition at line 17 of file list.c.

19{
20 ULONGLONG DiskSize;
21 ULONGLONG FreeSize;
22 LPWSTR lpSizeUnit;
23 LPWSTR lpFreeUnit;
24
25 DiskSize = DiskEntry->SectorCount.QuadPart *
26 (ULONGLONG)DiskEntry->BytesPerSector;
27
28 if (DiskSize >= 10737418240) /* 10 GB */
29 {
30 DiskSize = RoundingDivide(DiskSize, 1073741824);
31 lpSizeUnit = L"GB";
32 }
33 else
34 {
35 DiskSize = RoundingDivide(DiskSize, 1048576);
36 if (DiskSize == 0)
37 DiskSize = 1;
38 lpSizeUnit = L"MB";
39 }
40
41 /* FIXME */
42 FreeSize = 0;
43 lpFreeUnit = L"B";
44
46 (CurrentDisk == DiskEntry) ? L'*' : L' ',
47 DiskEntry->DiskNumber,
48 L"Online",
49 DiskSize,
50 lpSizeUnit,
51 FreeSize,
52 lpFreeUnit,
53 L" ",
54 (DiskEntry->PartitionStyle == PARTITION_STYLE_GPT) ? L"*" : L" ");
55}
#define IDS_LIST_DISK_FORMAT
Definition: resource.h:83
if(dx< 0)
Definition: linetemp.h:194

Referenced by DetailVolume(), and ListDisk().

◆ PrintGUID()

VOID PrintGUID ( _Out_ PWSTR  pszBuffer,
_In_ GUID pGuid 
)

Definition at line 187 of file misc.c.

190{
191 swprintf(pszBuffer,
192 L"%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
193 pGuid->Data1,
194 pGuid->Data2,
195 pGuid->Data3,
196 pGuid->Data4[0],
197 pGuid->Data4[1],
198 pGuid->Data4[2],
199 pGuid->Data4[3],
200 pGuid->Data4[4],
201 pGuid->Data4[5],
202 pGuid->Data4[6],
203 pGuid->Data4[7]);
204}

Referenced by DetailDisk(), DetailPartition(), and UniqueIdDisk().

◆ PrintVolume()

VOID PrintVolume ( _In_ PVOLENTRY  VolumeEntry)

Definition at line 314 of file list.c.

316{
317 ULONGLONG VolumeSize;
318 PWSTR pszSizeUnit;
319 PWSTR pszVolumeType;
320
321 VolumeSize = VolumeEntry->Size.QuadPart;
322 if (VolumeSize >= 10737418240) /* 10 GB */
323 {
324 VolumeSize = RoundingDivide(VolumeSize, 1073741824);
325 pszSizeUnit = L"GB";
326 }
327 else if (VolumeSize >= 10485760) /* 10 MB */
328 {
329 VolumeSize = RoundingDivide(VolumeSize, 1048576);
330 pszSizeUnit = L"MB";
331 }
332 else
333 {
334 VolumeSize = RoundingDivide(VolumeSize, 1024);
335 pszSizeUnit = L"KB";
336 }
337 switch (VolumeEntry->VolumeType)
338 {
340 pszVolumeType = L"DVD";
341 break;
343 pszVolumeType = L"Partition";
344 break;
346 pszVolumeType = L"Removable";
347 break;
349 default:
350 pszVolumeType = L"Unknown";
351 break;
352 }
353
355 (CurrentVolume == VolumeEntry) ? L'*' : L' ',
356 VolumeEntry->VolumeNumber,
357 VolumeEntry->DriveLetter,
358 (VolumeEntry->pszLabel) ? VolumeEntry->pszLabel : L"",
359 (VolumeEntry->pszFilesystem) ? VolumeEntry->pszFilesystem : L"",
360 pszVolumeType,
361 VolumeSize, pszSizeUnit);
362}
#define IDS_LIST_VOLUME_FORMAT
Definition: resource.h:90
PVOLENTRY CurrentVolume
Definition: partlist.c:79

Referenced by DetailDisk(), DetailPartition(), and ListVolume().

◆ ReadLayoutBuffer()

VOID ReadLayoutBuffer ( _In_ HANDLE  FileHandle,
_In_ PDISKENTRY  DiskEntry 
)

Definition at line 1067 of file partlist.c.

1070{
1071 ULONG LayoutBufferSize;
1072 PDRIVE_LAYOUT_INFORMATION_EX NewLayoutBuffer;
1075
1076 /* Allocate a layout buffer with 4 partition entries first */
1077 LayoutBufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
1078 ((4 - ANYSIZE_ARRAY) * sizeof(PARTITION_INFORMATION_EX));
1079 DiskEntry->LayoutBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
1081 LayoutBufferSize);
1082 if (DiskEntry->LayoutBuffer == NULL)
1083 {
1084 DPRINT1("Failed to allocate the disk layout buffer!\n");
1085 return;
1086 }
1087
1088 for (;;)
1089 {
1090 DPRINT1("Buffer size: %lu\n", LayoutBufferSize);
1092 NULL,
1093 NULL,
1094 NULL,
1095 &Iosb,
1097 NULL,
1098 0,
1099 DiskEntry->LayoutBuffer,
1100 LayoutBufferSize);
1101 if (NT_SUCCESS(Status))
1102 break;
1103
1105 {
1106 DPRINT1("NtDeviceIoControlFile() failed (Status: 0x%08lx)\n", Status);
1107 return;
1108 }
1109
1110 LayoutBufferSize += 4 * sizeof(PARTITION_INFORMATION_EX);
1111 NewLayoutBuffer = RtlReAllocateHeap(RtlGetProcessHeap(),
1113 DiskEntry->LayoutBuffer,
1114 LayoutBufferSize);
1115 if (NewLayoutBuffer == NULL)
1116 {
1117 DPRINT1("Failed to reallocate the disk layout buffer!\n");
1118 return;
1119 }
1120
1121 DiskEntry->LayoutBuffer = NewLayoutBuffer;
1122 }
1123
1124}
#define IOCTL_DISK_GET_DRIVE_LAYOUT_EX
Definition: ntddk_ex.h:207
NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE, ULONG, PVOID, SIZE_T) __WINE_ALLOC_SIZE(4) __WINE_DEALLOC(RtlFreeHeap
struct _PARTITION_INFORMATION_EX PARTITION_INFORMATION_EX
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define ANYSIZE_ARRAY
Definition: typedefs.h:46

Referenced by AddDiskToList(), and CreateDisk().

◆ recover_main()

BOOL recover_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file recover.c.

12{
13 return TRUE;
14}

◆ remove_main()

BOOL remove_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file remove.c.

12{
13 return TRUE;
14}

◆ RemoveVolume()

VOID RemoveVolume ( _In_ PVOLENTRY  VolumeEntry)

Definition at line 2635 of file partlist.c.

2637{
2638 if (VolumeEntry == NULL)
2639 return;
2640
2641 if (VolumeEntry == CurrentVolume)
2643
2644 RemoveEntryList(&VolumeEntry->ListEntry);
2645
2646 if (VolumeEntry->pszLabel)
2647 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
2648
2649 if (VolumeEntry->pszFilesystem)
2650 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
2651
2652 if (VolumeEntry->pExtents)
2653 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pExtents);
2654
2655 /* Release disk entry */
2656 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
2657}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986

Referenced by clean_main().

◆ repair_main()

BOOL repair_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file repair.c.

12{
13 ConPuts(StdOut, L"\nTODO: Add code later since Win 7 Home Premium doesn't have this feature.\n");
14 return TRUE;
15}

◆ rescan_main()

BOOL rescan_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file rescan.c.

12{
19
20 return TRUE;
21}
#define IDS_RESCAN_START
Definition: resource.h:92
#define IDS_RESCAN_END
Definition: resource.h:93
VOID DestroyVolumeList(VOID)
Definition: partlist.c:1810
NTSTATUS CreateVolumeList(VOID)
Definition: partlist.c:1772
VOID NTAPI DestroyPartitionList(IN PPARTLIST List)
Definition: partlist.c:2074
PPARTLIST NTAPI CreatePartitionList(VOID)
Definition: partlist.c:1988

◆ retain_main()

BOOL retain_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file retain.c.

12{
13 return TRUE;
14}

◆ RoundingDivide()

ULONGLONG RoundingDivide ( _In_ ULONGLONG  Dividend,
_In_ ULONGLONG  Divisor 
)

Definition at line 75 of file misc.c.

78{
79 return (Dividend + Divisor / 2) / Divisor;
80}
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3061

◆ san_main()

BOOL san_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file san.c.

12{
13 return TRUE;
14}

◆ ScanForUnpartitionedGptDiskSpace()

VOID ScanForUnpartitionedGptDiskSpace ( PDISKENTRY  DiskEntry)

Definition at line 923 of file partlist.c.

925{
926 ULONGLONG LastStartSector;
927 ULONGLONG LastSectorCount;
928 ULONGLONG LastUnusedSectorCount;
929 PPARTENTRY PartEntry;
930 PPARTENTRY NewPartEntry;
932
933 DPRINT("ScanForUnpartitionedGptDiskSpace()\n");
934
935#ifdef DUMP_PARTITION_LIST
936 DumpPartitionList(DiskEntry);
937#endif
938
939 if (IsListEmpty(&DiskEntry->PrimaryPartListHead))
940 {
941 DPRINT("No partitions!\n");
942
943 /* Create a partition table that represents the empty disk */
944 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
946 sizeof(PARTENTRY));
947 if (NewPartEntry == NULL)
948 return;
949
950 NewPartEntry->DiskEntry = DiskEntry;
951
952 NewPartEntry->IsPartitioned = FALSE;
953 NewPartEntry->StartSector.QuadPart = DiskEntry->StartSector.QuadPart;
954 NewPartEntry->SectorCount.QuadPart = DiskEntry->EndSector.QuadPart - DiskEntry->StartSector.QuadPart + 1;
955
956 DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
957 DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
958 DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
959
960 NewPartEntry->FormatState = Unformatted;
961
963 &NewPartEntry->ListEntry);
964
965#ifdef DUMP_PARTITION_LIST
966 DumpPartitionList(DiskEntry);
967#endif
968
969 return;
970 }
971
972 /* Start at the first usable sector */
973 LastStartSector = DiskEntry->StartSector.QuadPart;
974 LastSectorCount = 0ULL;
975 LastUnusedSectorCount = 0ULL;
976
977 Entry = DiskEntry->PrimaryPartListHead.Flink;
978 while (Entry != &DiskEntry->PrimaryPartListHead)
979 {
980 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
981
982 if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID) ||
983 PartEntry->SectorCount.QuadPart != 0ULL)
984 {
985 LastUnusedSectorCount =
986 PartEntry->StartSector.QuadPart - (LastStartSector + LastSectorCount);
987
988 if (PartEntry->StartSector.QuadPart > (LastStartSector + LastSectorCount) &&
989 LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
990 {
991 DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount);
992
993 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
995 sizeof(PARTENTRY));
996 if (NewPartEntry == NULL)
997 return;
998
999 NewPartEntry->DiskEntry = DiskEntry;
1000
1001 NewPartEntry->IsPartitioned = FALSE;
1002 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
1003 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
1004 NewPartEntry->StartSector.QuadPart;
1005
1006 DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
1007 DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
1008 DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
1009
1010 NewPartEntry->FormatState = Unformatted;
1011
1012 /* Insert the table into the list */
1013 InsertTailList(&PartEntry->ListEntry,
1014 &NewPartEntry->ListEntry);
1015 }
1016
1017 LastStartSector = PartEntry->StartSector.QuadPart;
1018 LastSectorCount = PartEntry->SectorCount.QuadPart;
1019 }
1020
1021 Entry = Entry->Flink;
1022 }
1023
1024 /* Check for trailing unpartitioned disk space */
1025 if ((LastStartSector + LastSectorCount) < DiskEntry->EndSector.QuadPart + 1)
1026 {
1027 LastUnusedSectorCount = AlignDown(DiskEntry->EndSector.QuadPart + 1 - (LastStartSector + LastSectorCount), DiskEntry->SectorAlignment);
1028
1029 if (LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
1030 {
1031 DPRINT("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount);
1032
1033 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
1035 sizeof(PARTENTRY));
1036 if (NewPartEntry == NULL)
1037 return;
1038
1039 NewPartEntry->DiskEntry = DiskEntry;
1040
1041 NewPartEntry->IsPartitioned = FALSE;
1042 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
1043 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
1044 NewPartEntry->StartSector.QuadPart;
1045
1046 DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
1047 DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
1048 DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
1049
1050 NewPartEntry->FormatState = Unformatted;
1051
1052 /* Append the table to the list */
1054 &NewPartEntry->ListEntry);
1055 }
1056 }
1057
1058#ifdef DUMP_PARTITION_LIST
1059 DumpPartitionList(DiskEntry);
1060#endif
1061
1062 DPRINT("ScanForUnpartitionedGptDiskSpace() done\n");
1063}
ULONGLONG AlignDown(_In_ ULONGLONG Value, _In_ ULONG Alignment)
Definition: partlist.c:191

Referenced by AddDiskToList(), and ConvertGPT().

◆ ScanForUnpartitionedMbrDiskSpace()

VOID ScanForUnpartitionedMbrDiskSpace ( PDISKENTRY  DiskEntry)

Definition at line 662 of file partlist.c.

664{
665 ULONGLONG StartSector, EndSector;
666 ULONGLONG LastStartSector;
667 ULONGLONG LastSectorCount;
668 ULONGLONG LastUnusedSectorCount;
669 PPARTENTRY PartEntry;
670 PPARTENTRY NewPartEntry;
672
673 DPRINT("ScanForUnpartitionedMbrDiskSpace()\n");
674
675 /* Calculate the disk sector limits */
676 /* Limit the SectorCount to 2^32 sectors for MBR disks */
677 StartSector = (ULONGLONG)DiskEntry->SectorAlignment;
678 EndSector = min(DiskEntry->SectorCount.QuadPart, 0x100000000) - 1;
679
680 if (IsListEmpty(&DiskEntry->PrimaryPartListHead))
681 {
682 DPRINT1("No primary partition!\n");
683
684 /* Create a partition table that represents the empty disk */
685 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
687 sizeof(PARTENTRY));
688 if (NewPartEntry == NULL)
689 return;
690
691 NewPartEntry->DiskEntry = DiskEntry;
692
693 NewPartEntry->IsPartitioned = FALSE;
694 NewPartEntry->StartSector.QuadPart = StartSector;
695 NewPartEntry->SectorCount.QuadPart = AlignDown(EndSector + 1, DiskEntry->SectorAlignment) -
696 NewPartEntry->StartSector.QuadPart;
697
698 DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
699 DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
700 DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
701
702 NewPartEntry->FormatState = Unformatted;
703
705 &NewPartEntry->ListEntry);
706
707 return;
708 }
709
710 /* Start at the first usable sector */
711 LastStartSector = StartSector;
712 LastSectorCount = 0ULL;
713 LastUnusedSectorCount = 0ULL;
714
715 Entry = DiskEntry->PrimaryPartListHead.Flink;
716 while (Entry != &DiskEntry->PrimaryPartListHead)
717 {
718 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
719
720 if (PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED ||
721 PartEntry->SectorCount.QuadPart != 0ULL)
722 {
723 LastUnusedSectorCount =
724 PartEntry->StartSector.QuadPart - (LastStartSector + LastSectorCount);
725
726 if (PartEntry->StartSector.QuadPart > (LastStartSector + LastSectorCount) &&
727 LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
728 {
729 DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount);
730
731 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
733 sizeof(PARTENTRY));
734 if (NewPartEntry == NULL)
735 return;
736
737 NewPartEntry->DiskEntry = DiskEntry;
738
739 NewPartEntry->IsPartitioned = FALSE;
740 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
741 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
742 NewPartEntry->StartSector.QuadPart;
743
744 DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
745 DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
746 DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
747
748 NewPartEntry->FormatState = Unformatted;
749
750 /* Insert the table into the list */
751 InsertTailList(&PartEntry->ListEntry,
752 &NewPartEntry->ListEntry);
753 }
754
755 LastStartSector = PartEntry->StartSector.QuadPart;
756 LastSectorCount = PartEntry->SectorCount.QuadPart;
757 }
758
759 Entry = Entry->Flink;
760 }
761
762 /* Check for trailing unpartitioned disk space */
763 if ((LastStartSector + LastSectorCount) < (EndSector + 1))
764 {
765 LastUnusedSectorCount = AlignDown((EndSector + 1) - (LastStartSector + LastSectorCount), DiskEntry->SectorAlignment);
766
767 if (LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
768 {
769 DPRINT1("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount);
770
771 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
773 sizeof(PARTENTRY));
774 if (NewPartEntry == NULL)
775 return;
776
777 NewPartEntry->DiskEntry = DiskEntry;
778
779 NewPartEntry->IsPartitioned = FALSE;
780 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
781 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
782 NewPartEntry->StartSector.QuadPart;
783
784 DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
785 DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
786 DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
787
788 NewPartEntry->FormatState = Unformatted;
789
790 /* Append the table to the list */
792 &NewPartEntry->ListEntry);
793 }
794 }
795
796 if (DiskEntry->ExtendedPartition != NULL)
797 {
798 if (IsListEmpty(&DiskEntry->LogicalPartListHead))
799 {
800 DPRINT1("No logical partition!\n");
801
802 /* Create a partition table entry that represents the empty extended partition */
803 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
805 sizeof(PARTENTRY));
806 if (NewPartEntry == NULL)
807 return;
808
809 NewPartEntry->DiskEntry = DiskEntry;
810 NewPartEntry->LogicalPartition = TRUE;
811
812 NewPartEntry->IsPartitioned = FALSE;
813 NewPartEntry->StartSector.QuadPart = DiskEntry->ExtendedPartition->StartSector.QuadPart + (ULONGLONG)DiskEntry->SectorAlignment;
814 NewPartEntry->SectorCount.QuadPart = DiskEntry->ExtendedPartition->SectorCount.QuadPart - (ULONGLONG)DiskEntry->SectorAlignment;
815
816 DPRINT1("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
817 DPRINT1("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
818 DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
819
820 NewPartEntry->FormatState = Unformatted;
821
823 &NewPartEntry->ListEntry);
824
825 return;
826 }
827
828 /* Start partition at head 1, cylinder 0 */
829 LastStartSector = DiskEntry->ExtendedPartition->StartSector.QuadPart + (ULONGLONG)DiskEntry->SectorAlignment;
830 LastSectorCount = 0ULL;
831 LastUnusedSectorCount = 0ULL;
832
833 Entry = DiskEntry->LogicalPartListHead.Flink;
834 while (Entry != &DiskEntry->LogicalPartListHead)
835 {
836 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
837
838 if (PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED ||
839 PartEntry->SectorCount.QuadPart != 0ULL)
840 {
841 LastUnusedSectorCount =
842 PartEntry->StartSector.QuadPart - (ULONGLONG)DiskEntry->SectorAlignment - (LastStartSector + LastSectorCount);
843
844 if ((PartEntry->StartSector.QuadPart - (ULONGLONG)DiskEntry->SectorAlignment) > (LastStartSector + LastSectorCount) &&
845 LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
846 {
847 DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount);
848
849 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
851 sizeof(PARTENTRY));
852 if (NewPartEntry == NULL)
853 return;
854
855 NewPartEntry->DiskEntry = DiskEntry;
856 NewPartEntry->LogicalPartition = TRUE;
857
858 NewPartEntry->IsPartitioned = FALSE;
859 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
860 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
861 NewPartEntry->StartSector.QuadPart;
862
863 DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
864 DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
865 DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
866
867 NewPartEntry->FormatState = Unformatted;
868
869 /* Insert the table into the list */
870 InsertTailList(&PartEntry->ListEntry,
871 &NewPartEntry->ListEntry);
872 }
873
874 LastStartSector = PartEntry->StartSector.QuadPart;
875 LastSectorCount = PartEntry->SectorCount.QuadPart;
876 }
877
878 Entry = Entry->Flink;
879 }
880
881 /* Check for trailing unpartitioned disk space */
882 if ((LastStartSector + LastSectorCount) < DiskEntry->ExtendedPartition->StartSector.QuadPart + DiskEntry->ExtendedPartition->SectorCount.QuadPart)
883 {
884 LastUnusedSectorCount = AlignDown(DiskEntry->ExtendedPartition->StartSector.QuadPart + DiskEntry->ExtendedPartition->SectorCount.QuadPart - (LastStartSector + LastSectorCount),
885 DiskEntry->SectorAlignment);
886
887 if (LastUnusedSectorCount >= (ULONGLONG)DiskEntry->SectorAlignment)
888 {
889 DPRINT("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount);
890
891 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(),
893 sizeof(PARTENTRY));
894 if (NewPartEntry == NULL)
895 return;
896
897 NewPartEntry->DiskEntry = DiskEntry;
898 NewPartEntry->LogicalPartition = TRUE;
899
900 NewPartEntry->IsPartitioned = FALSE;
901 NewPartEntry->StartSector.QuadPart = LastStartSector + LastSectorCount;
902 NewPartEntry->SectorCount.QuadPart = AlignDown(NewPartEntry->StartSector.QuadPart + LastUnusedSectorCount, DiskEntry->SectorAlignment) -
903 NewPartEntry->StartSector.QuadPart;
904
905 DPRINT("First Sector: %I64u\n", NewPartEntry->StartSector.QuadPart);
906 DPRINT("Last Sector: %I64u\n", NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart - 1);
907 DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
908
909 NewPartEntry->FormatState = Unformatted;
910
911 /* Append the table to the list */
913 &NewPartEntry->ListEntry);
914 }
915 }
916 }
917
918 DPRINT("ScanForUnpartitionedMbrDiskSpace() done\n");
919}
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))

Referenced by AddDiskToList(), ConvertMBR(), CreateExtendedPartition(), and CreatePrimaryPartition().

◆ SelectDisk()

BOOL SelectDisk ( INT  argc,
PWSTR argv 
)

Definition at line 17 of file select.c.

20{
22 PDISKENTRY DiskEntry;
23 ULONG ulValue;
24
25 DPRINT("Select Disk()\n");
26
27 if (argc > 3)
28 {
30 return TRUE;
31 }
32
33 if (argc == 2)
34 {
35 if (CurrentDisk == NULL)
37 else
39 return TRUE;
40 }
41
42 if (!_wcsicmp(argv[2], L"system"))
43 {
45
47 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
48
49 CurrentDisk = DiskEntry;
52 return TRUE;
53 }
54 else if (!_wcsicmp(argv[2], L"next"))
55 {
56 if (CurrentDisk == NULL)
57 {
60 return TRUE;
61 }
62
64 {
68 return TRUE;
69 }
70
72
73 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
74
75 CurrentDisk = DiskEntry;
78 return TRUE;
79 }
80 else if (IsDecString(argv[2]))
81 {
82 ulValue = wcstoul(argv[2], NULL, 10);
83 if ((ulValue == 0) && (errno == ERANGE))
84 {
86 return TRUE;
87 }
88
90
92 while (Entry != &DiskListHead)
93 {
94 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
95
96 if (DiskEntry->DiskNumber == ulValue)
97 {
98 CurrentDisk = DiskEntry;
101 return TRUE;
102 }
103
104 Entry = Entry->Flink;
105 }
106 }
107 else
108 {
110 return TRUE;
111 }
112
114 return TRUE;
115}
#define IDS_SELECT_DISK_INVALID
Definition: resource.h:97
#define IDS_SELECT_DISK_ENUM_NO_START
Definition: resource.h:98
#define IDS_SELECT_DISK
Definition: resource.h:96
#define IDS_SELECT_DISK_ENUM_FINISHED
Definition: resource.h:99
BOOL IsDecString(_In_ PWSTR pszDecString)
Definition: misc.c:14
LIST_ENTRY ListEntry
Definition: partlist.h:101

◆ SelectPartition()

BOOL SelectPartition ( INT  argc,
PWSTR argv 
)

Definition at line 119 of file select.c.

122{
124 PPARTENTRY PartEntry;
125 ULONG ulValue;
126 ULONG PartNumber = 1;
127
128 DPRINT("Select Partition()\n");
129
130 if (argc > 3)
131 {
133 return TRUE;
134 }
135
136 if (CurrentDisk == NULL)
137 {
139 return TRUE;
140 }
141
142 if (argc == 2)
143 {
144 if (CurrentPartition == NULL)
146 else
148 return TRUE;
149 }
150
151 if (!IsDecString(argv[2]))
152 {
154 return TRUE;
155 }
156
157 ulValue = wcstoul(argv[2], NULL, 10);
158 if ((ulValue == 0) && (errno == ERANGE))
159 {
161 return TRUE;
162 }
163
165 {
168 {
169 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
170
171 if (PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED)
172 {
173 if (PartNumber == ulValue)
174 {
175 CurrentPartition = PartEntry;
177 return TRUE;
178 }
179
180 PartNumber++;
181 }
182
183 Entry = Entry->Flink;
184 }
185
188 {
189 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
190
191 if (PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED)
192 {
193 if (PartNumber == ulValue)
194 {
195 CurrentPartition = PartEntry;
197 return TRUE;
198 }
199
200 PartNumber++;
201 }
202 Entry = Entry->Flink;
203 }
204 }
206 {
209 {
210 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
211
212 if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID))
213 {
214 if (PartNumber == ulValue)
215 {
216 CurrentPartition = PartEntry;
218 return TRUE;
219 }
220
221 PartNumber++;
222 }
223
224 Entry = Entry->Flink;
225 }
226 }
227
229 return TRUE;
230}
#define IDS_SELECT_PARTITION_NO_DISK
Definition: resource.h:102
#define IDS_SELECT_PARTITION_INVALID
Definition: resource.h:103
#define IDS_SELECT_PARTITION
Definition: resource.h:101

◆ SelectVolume()

BOOL SelectVolume ( INT  argc,
PWSTR argv 
)

Definition at line 234 of file select.c.

237{
239 PVOLENTRY VolumeEntry;
240 ULONG ulValue;
241
242 DPRINT("SelectVolume()\n");
243
244 if (argc > 3)
245 {
247 return TRUE;
248 }
249
250 if (argc == 2)
251 {
252 if (CurrentDisk == NULL)
254 else
256 return TRUE;
257 }
258
259 if (!IsDecString(argv[2]))
260 {
262 return TRUE;
263 }
264
265 ulValue = wcstoul(argv[2], NULL, 10);
266 if ((ulValue == 0) && (errno == ERANGE))
267 {
269 return TRUE;
270 }
271
273
275 while (Entry != &VolumeListHead)
276 {
277 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
278
279 if (VolumeEntry->VolumeNumber == ulValue)
280 {
281 CurrentVolume = VolumeEntry;
283 return TRUE;
284 }
285
286 Entry = Entry->Flink;
287 }
288
290 return TRUE;
291}
#define IDS_SELECT_NO_VOLUME
Definition: resource.h:104
#define IDS_SELECT_VOLUME
Definition: resource.h:105
#define IDS_SELECT_VOLUME_INVALID
Definition: resource.h:106
ULONG VolumeNumber
Definition: diskpart.h:219

◆ setid_main()

BOOL setid_main ( INT  argc,
LPWSTR argv 
)

◆ shrink_main()

BOOL shrink_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file shrink.c.

12{
13 return TRUE;
14}

◆ StringToGUID()

BOOL StringToGUID ( _Out_ GUID pGuid,
_In_ PWSTR  pszString 
)

Definition at line 227 of file misc.c.

230{
231 INT i;
232
233 if (pszString == NULL)
234 return FALSE;
235
236 pGuid->Data1 = 0;
237 for (i = 0; i < 8; i++)
238 {
239 if (!iswxdigit(pszString[i]))
240 return FALSE;
241
242 pGuid->Data1 = (pGuid->Data1 << 4) | CharToByte(pszString[i]);
243 }
244
245 if (pszString[8] != L'-')
246 return FALSE;
247
248 pGuid->Data2 = 0;
249 for (i = 9; i < 13; i++)
250 {
251 if (!iswxdigit(pszString[i]))
252 return FALSE;
253
254 pGuid->Data2 = (pGuid->Data2 << 4) | CharToByte(pszString[i]);
255 }
256
257 if (pszString[13] != L'-')
258 return FALSE;
259
260 pGuid->Data3 = 0;
261 for (i = 14; i < 18; i++)
262 {
263 if (!iswxdigit(pszString[i]))
264 return FALSE;
265
266 pGuid->Data3 = (pGuid->Data3 << 4) | CharToByte(pszString[i]);
267 }
268
269 if (pszString[18] != L'-')
270 return FALSE;
271
272 for (i = 19; i < 36; i += 2)
273 {
274 if (i == 23)
275 {
276 if (pszString[i] != L'-')
277 return FALSE;
278 i++;
279 }
280
281 if (!iswxdigit(pszString[i]) || !iswxdigit(pszString[i + 1]))
282 return FALSE;
283
284 pGuid->Data4[(i - 19) / 2] = CharToByte(pszString[i]) << 4 | CharToByte(pszString[i + 1]);
285 }
286
287 if (pszString[36] == L'\0')
288 return TRUE;
289
290 return FALSE;
291}
static BYTE CharToByte(WCHAR Char)
Definition: misc.c:208

Referenced by CreatePrimaryGptPartition(), setid_main(), and UniqueIdDisk().

◆ UniqueIdDisk()

BOOL UniqueIdDisk ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 17 of file uniqueid.c.

20{
21 WCHAR szBuffer[40];
22 PWSTR pszSuffix, pszId = NULL;
23 INT i;
24 ULONG ulValue;
25
26 if (CurrentDisk == NULL)
27 {
29 return TRUE;
30 }
31
32 if (argc == 2)
33 {
34 ConPuts(StdOut, L"\n");
35 if (CurrentDisk->LayoutBuffer->PartitionStyle == PARTITION_STYLE_GPT)
36 PrintGUID(szBuffer, &CurrentDisk->LayoutBuffer->Gpt.DiskId);
37 else if (CurrentDisk->LayoutBuffer->PartitionStyle == PARTITION_STYLE_MBR)
38 swprintf(szBuffer, L"%08lx", CurrentDisk->LayoutBuffer->Mbr.Signature);
39 else
40 wcscpy(szBuffer, L"00000000");
41 ConPrintf(StdOut, L"Disk ID: %s\n", szBuffer);
42 ConPuts(StdOut, L"\n");
43 return TRUE;
44 }
45
46 if (argc != 3)
47 {
49 return TRUE;
50 }
51
52 for (i = 1; i < argc; i++)
53 {
54 if (HasPrefix(argv[2], L"id=", &pszSuffix))
55 {
56 /* id=<Byte>|<GUID> */
57 DPRINT("ID : %s\n", pszSuffix);
58 pszId = pszSuffix;
59 }
60 else if (_wcsicmp(argv[i], L"noerr") == 0)
61 {
62 /* noerr */
63 DPRINT("NOERR\n");
64 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
65 }
66 else
67 {
69 return TRUE;
70 }
71 }
72
74 {
75 if (!StringToGUID(&CurrentDisk->LayoutBuffer->Gpt.DiskId, pszId))
76 {
78 return TRUE;
79 }
80
84 }
86 {
87 if ((pszId == NULL) ||
88 (wcslen(pszId) != 8) ||
89 (IsHexString(pszId) == FALSE))
90 {
92 return TRUE;
93 }
94
95 ulValue = wcstoul(pszId, NULL, 16);
96 if ((ulValue == 0) && (errno == ERANGE))
97 {
99 return TRUE;
100 }
101
102 DPRINT("New Signature: 0x%08lx\n", ulValue);
103 CurrentDisk->LayoutBuffer->Mbr.Signature = ulValue;
107 }
108 else
109 {
111 }
112
113 return TRUE;
114}
#define IDS_UNIQUID_DISK_INVALID_STYLE
Definition: resource.h:113
VOID PrintGUID(_Out_ PWSTR pszBuffer, _In_ GUID *pGuid)
Definition: misc.c:187
VOID UpdateGptDiskLayout(_In_ PDISKENTRY DiskEntry, _In_ BOOL DeleteEntry)
Definition: partlist.c:2344
NTSTATUS WriteGptPartitions(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:1963
BOOL IsHexString(_In_ PWSTR pszHexString)
Definition: misc.c:36
BOOL StringToGUID(_Out_ GUID *pGuid, _In_ PWSTR pszString)
Definition: misc.c:227

◆ UpdateGptDiskLayout()

VOID UpdateGptDiskLayout ( _In_ PDISKENTRY  DiskEntry,
_In_ BOOL  DeleteEntry 
)

Definition at line 2344 of file partlist.c.

2347{
2348 PLIST_ENTRY ListEntry;
2349 PPARTENTRY PartEntry;
2351 ULONG Count, Index;
2352
2353 DPRINT("UpdateGptDiskLayout()\n");
2354
2355 /* Count used partition entries */
2356 Count = 0;
2357 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
2358 ListEntry != &DiskEntry->PrimaryPartListHead;
2359 ListEntry = ListEntry->Flink)
2360 {
2361 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2362
2363 if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID))
2364 Count++;
2365 }
2366
2367 DPRINT("Used partition entries: %lu\n", Count);
2368
2369 if (DeleteEntry)
2370 Count++;
2371
2372 /* Reallocate the layout buffer */
2373 if (Count != DiskEntry->LayoutBuffer->PartitionCount)
2374 {
2375 PDRIVE_LAYOUT_INFORMATION_EX NewLayoutBuffer;
2376 ULONG NewLayoutBufferSize;
2377
2378 NewLayoutBufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
2380 NewLayoutBuffer = RtlReAllocateHeap(RtlGetProcessHeap(),
2382 DiskEntry->LayoutBuffer,
2383 NewLayoutBufferSize);
2384 if (NewLayoutBuffer == NULL)
2385 {
2386 DPRINT1("Failed to allocate the new layout buffer (size: %lu)\n", NewLayoutBufferSize);
2387 return;
2388 }
2389
2390 NewLayoutBuffer->PartitionCount = Count;
2391 DiskEntry->LayoutBuffer = NewLayoutBuffer;
2392 }
2393
2394 /* Fill the new layout buffer */
2395 Index = 0;
2396 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
2397 ListEntry != &DiskEntry->PrimaryPartListHead;
2398 ListEntry = ListEntry->Flink)
2399 {
2400 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2401
2402 if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID))
2403 {
2404 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2405 PartEntry->PartitionIndex = Index;
2406
2407 DPRINT("Updating primary partition entry %lu\n", Index);
2408 PartitionInfo->PartitionStyle = PARTITION_STYLE_GPT;
2409 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
2410 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2411 PartitionInfo->PartitionNumber = Index + 1;
2412 PartitionInfo->RewritePartition = TRUE;
2413 CopyMemory(&PartitionInfo->Gpt.PartitionType, &PartEntry->Gpt.PartitionType, sizeof(GUID));
2414 CopyMemory(&PartitionInfo->Gpt.PartitionId, &PartEntry->Gpt.PartitionId, sizeof(GUID));
2415 PartitionInfo->Gpt.Attributes = PartEntry->Gpt.Attributes;
2416 ZeroMemory(&PartitionInfo->Gpt.Name, 36 * sizeof(WCHAR)); /* ??? */
2417
2418 Index++;
2419 }
2420 }
2421
2422 if (DeleteEntry)
2423 {
2424 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2426 PartitionInfo->RewritePartition = TRUE;
2427 }
2428}
#define ZeroMemory
Definition: minwinbase.h:31
#define CopyMemory
Definition: minwinbase.h:29
DWORD64 Attributes
Definition: diskpart.h:114
ULONG PartitionIndex
Definition: partlist.h:76
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2105

Referenced by CreatePrimaryGptPartition(), DeleteGptPartition(), setid_main(), and UniqueIdDisk().

◆ UpdateMbrDiskLayout()

VOID UpdateMbrDiskLayout ( _In_ PDISKENTRY  DiskEntry)

Definition at line 2167 of file partlist.c.

2169{
2172 PLIST_ENTRY ListEntry;
2173 PPARTENTRY PartEntry;
2174 LARGE_INTEGER HiddenSectors64;
2175 ULONG Index;
2177
2178 DPRINT("UpdateMbrDiskLayout()\n");
2179
2180 /* Resize the layout buffer if necessary */
2181 if (ReAllocateLayoutBuffer(DiskEntry) == FALSE)
2182 {
2183 DPRINT("ReAllocateLayoutBuffer() failed.\n");
2184 return;
2185 }
2186
2187 DiskEntry->LayoutBuffer->PartitionStyle = PARTITION_STYLE_MBR;
2188
2189 /* Update the primary partition table */
2190 Index = 0;
2191 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
2192 ListEntry != &DiskEntry->PrimaryPartListHead;
2193 ListEntry = ListEntry->Flink)
2194 {
2195 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2196
2197 if (PartEntry->IsPartitioned)
2198 {
2200
2201 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2202 PartEntry->PartitionIndex = Index;
2203
2204 /* Reset the current partition number only for newly-created (unmounted) partitions */
2205 if (PartEntry->New)
2206 PartEntry->PartitionNumber = 0;
2207
2209
2210 if (!IsSamePrimaryLayoutEntry(PartitionInfo, DiskEntry, PartEntry))
2211 {
2212 DPRINT1("Updating primary partition entry %lu\n", Index);
2213
2214 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2215 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
2216 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2217 PartitionInfo->Mbr.HiddenSectors = PartEntry->StartSector.LowPart;
2218 PartitionInfo->PartitionNumber = PartEntry->PartitionNumber;
2219 PartitionInfo->Mbr.PartitionType = PartEntry->Mbr.PartitionType;
2220 PartitionInfo->Mbr.BootIndicator = PartEntry->Mbr.BootIndicator;
2221 PartitionInfo->Mbr.RecognizedPartition = IsRecognizedPartition(PartEntry->Mbr.PartitionType);
2222 PartitionInfo->RewritePartition = TRUE;
2223 }
2224
2225 if (!IsContainerPartition(PartEntry->Mbr.PartitionType))
2227
2228 Index++;
2229 }
2230 }
2231
2232 ASSERT(Index <= 4);
2233
2234 /* Update the logical partition table */
2235 Index = 4;
2236 for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
2237 ListEntry != &DiskEntry->LogicalPartListHead;
2238 ListEntry = ListEntry->Flink)
2239 {
2240 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2241
2242 if (PartEntry->IsPartitioned)
2243 {
2245
2246 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2247 PartEntry->PartitionIndex = Index;
2248
2249 /* Reset the current partition number only for newly-created (unmounted) partitions */
2250 if (PartEntry->New)
2251 PartEntry->PartitionNumber = 0;
2252
2254
2255 DPRINT1("Updating logical partition entry %lu\n", Index);
2256
2257 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2258 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
2259 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2260 PartitionInfo->Mbr.HiddenSectors = DiskEntry->SectorAlignment;
2261 PartitionInfo->PartitionNumber = PartEntry->PartitionNumber;
2262 PartitionInfo->Mbr.PartitionType = PartEntry->Mbr.PartitionType;
2263 PartitionInfo->Mbr.BootIndicator = FALSE;
2264 PartitionInfo->Mbr.RecognizedPartition = IsRecognizedPartition(PartEntry->Mbr.PartitionType);
2265 PartitionInfo->RewritePartition = TRUE;
2266
2267 /* Fill the link entry of the previous partition entry */
2268 if (LinkInfo != NULL)
2269 {
2271 LinkInfo->StartingOffset.QuadPart = (PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector;
2272 LinkInfo->PartitionLength.QuadPart = (PartEntry->StartSector.QuadPart + DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector;
2273 HiddenSectors64.QuadPart = PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment - DiskEntry->ExtendedPartition->StartSector.QuadPart;
2274 LinkInfo->Mbr.HiddenSectors = HiddenSectors64.LowPart;
2275 LinkInfo->PartitionNumber = 0;
2277 LinkInfo->Mbr.BootIndicator = FALSE;
2278 LinkInfo->Mbr.RecognizedPartition = FALSE;
2279 LinkInfo->RewritePartition = TRUE;
2280 }
2281
2282 /* Save a pointer to the link entry of the current partition entry */
2283 LinkInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index + 1];
2284
2286 Index += 4;
2287 }
2288 }
2289
2290 /* Wipe unused primary partition entries */
2291 for (Index = GetPrimaryPartitionCount(DiskEntry); Index < 4; Index++)
2292 {
2293 DPRINT1("Primary partition entry %lu\n", Index);
2294
2295 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2296
2298 {
2299 DPRINT1("Wiping primary partition entry %lu\n", Index);
2300
2301 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2302 PartitionInfo->StartingOffset.QuadPart = 0;
2303 PartitionInfo->PartitionLength.QuadPart = 0;
2304 PartitionInfo->Mbr.HiddenSectors = 0;
2305 PartitionInfo->PartitionNumber = 0;
2306 PartitionInfo->Mbr.PartitionType = PARTITION_ENTRY_UNUSED;
2307 PartitionInfo->Mbr.BootIndicator = FALSE;
2308 PartitionInfo->Mbr.RecognizedPartition = FALSE;
2309 PartitionInfo->RewritePartition = TRUE;
2310 }
2311 }
2312
2313 /* Wipe unused logical partition entries */
2314 for (Index = 4; Index < DiskEntry->LayoutBuffer->PartitionCount; Index++)
2315 {
2316 if (Index % 4 >= 2)
2317 {
2318 DPRINT1("Logical partition entry %lu\n", Index);
2319
2320 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2321
2323 {
2324 DPRINT1("Wiping partition entry %lu\n", Index);
2325
2326 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2327 PartitionInfo->StartingOffset.QuadPart = 0;
2328 PartitionInfo->PartitionLength.QuadPart = 0;
2329 PartitionInfo->Mbr.HiddenSectors = 0;
2330 PartitionInfo->PartitionNumber = 0;
2331 PartitionInfo->Mbr.PartitionType = PARTITION_ENTRY_UNUSED;
2332 PartitionInfo->Mbr.BootIndicator = FALSE;
2333 PartitionInfo->Mbr.RecognizedPartition = FALSE;
2334 PartitionInfo->RewritePartition = TRUE;
2335 }
2336 }
2337 }
2338
2339 DiskEntry->Dirty = TRUE;
2340}
BOOLEAN BootIndicator
Definition: diskpart.h:106
ULONG OnDiskPartitionNumber
Definition: partlist.h:74
LARGE_INTEGER StartingOffset
Definition: imports.h:221
PARTITION_STYLE PartitionStyle
Definition: imports.h:220
PARTITION_INFORMATION_MBR Mbr
Definition: imports.h:226
LARGE_INTEGER PartitionLength
Definition: imports.h:222
$ULONG LowPart
Definition: ntbasedef.h:581
static BOOLEAN IsSamePrimaryLayoutEntry(IN PPARTITION_INFORMATION_EX PartitionInfo, IN PDISKENTRY DiskEntry, IN PPARTENTRY PartEntry)
Definition: partlist.c:2055
static BOOLEAN IsEmptyLayoutEntry(IN PPARTITION_INFORMATION_EX PartitionInfo)
Definition: partlist.c:2040
static BOOLEAN ReAllocateLayoutBuffer(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:2115
ULONG LowPart
Definition: typedefs.h:106
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061

Referenced by active_main(), CreateExtendedPartition(), CreateLogicalPartition(), CreatePrimaryMbrPartition(), DeleteMbrPartition(), inactive_main(), setid_main(), and UniqueIdDisk().

◆ WriteGptPartitions()

NTSTATUS WriteGptPartitions ( _In_ PDISKENTRY  DiskEntry)

Definition at line 1963 of file partlist.c.

1965{
1973
1974 DPRINT("WriteGptPartitions() Disk: %lu\n", DiskEntry->DiskNumber);
1975
1976 /* If the disk is not dirty, there is nothing to do */
1977 if (!DiskEntry->Dirty)
1978 return STATUS_SUCCESS;
1979
1981 L"\\Device\\Harddisk%lu\\Partition0",
1982 DiskEntry->DiskNumber);
1984
1986 &Name,
1988 NULL,
1989 NULL);
1990
1994 &Iosb,
1995 0,
1997 if (!NT_SUCCESS(Status))
1998 {
1999 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
2000 return Status;
2001 }
2002
2003 //
2004 // FIXME: We first *MUST* use IOCTL_DISK_CREATE_DISK to initialize
2005 // the disk in MBR or GPT format in case the disk was not initialized!!
2006 // For this we must ask the user which format to use.
2007 //
2008
2009 /* Set the new disk layout and retrieve its updated version with possibly modified partition numbers */
2010 BufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
2011 ((DiskEntry->LayoutBuffer->PartitionCount - 1) * sizeof(PARTITION_INFORMATION_EX));
2013 NULL,
2014 NULL,
2015 NULL,
2016 &Iosb,
2018 DiskEntry->LayoutBuffer,
2019 BufferSize,
2020 DiskEntry->LayoutBuffer,
2021 BufferSize);
2023
2024 /* Check whether the IOCTL_DISK_SET_DRIVE_LAYOUT_EX call succeeded */
2025 if (!NT_SUCCESS(Status))
2026 {
2027 DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT_EX failed (Status 0x%08lx)\n", Status);
2028 return Status;
2029 }
2030
2031 /* The layout has been successfully updated, the disk is not dirty anymore */
2032 DiskEntry->Dirty = FALSE;
2033
2034 return Status;
2035}
#define BufferSize
Definition: mmc.h:75
#define IOCTL_DISK_SET_DRIVE_LAYOUT_EX
Definition: ntdddisk.h:208
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by CreatePrimaryGptPartition(), DeleteGptPartition(), setid_main(), and UniqueIdDisk().

◆ WriteMbrPartitions()

NTSTATUS WriteMbrPartitions ( _In_ PDISKENTRY  DiskEntry)

Definition at line 1839 of file partlist.c.

1841{
1849 ULONG PartitionCount;
1850 PLIST_ENTRY ListEntry;
1851 PPARTENTRY PartEntry;
1853
1854 DPRINT("WriteMbrPartitions() Disk: %lu\n", DiskEntry->DiskNumber);
1855
1856 /* If the disk is not dirty, there is nothing to do */
1857 if (!DiskEntry->Dirty)
1858 return STATUS_SUCCESS;
1859
1861 L"\\Device\\Harddisk%lu\\Partition0",
1862 DiskEntry->DiskNumber);
1864
1866 &Name,
1868 NULL,
1869 NULL);
1870
1874 &Iosb,
1875 0,
1877 if (!NT_SUCCESS(Status))
1878 {
1879 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
1880 return Status;
1881 }
1882
1883 //
1884 // FIXME: We first *MUST* use IOCTL_DISK_CREATE_DISK to initialize
1885 // the disk in MBR or GPT format in case the disk was not initialized!!
1886 // For this we must ask the user which format to use.
1887 //
1888
1889 /* Save the original partition count to be restored later (see comment below) */
1890 PartitionCount = DiskEntry->LayoutBuffer->PartitionCount;
1891
1892 /* Set the new disk layout and retrieve its updated version with possibly modified partition numbers */
1893 BufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
1894 ((PartitionCount - 1) * sizeof(PARTITION_INFORMATION_EX));
1896 NULL,
1897 NULL,
1898 NULL,
1899 &Iosb,
1901 DiskEntry->LayoutBuffer,
1902 BufferSize,
1903 DiskEntry->LayoutBuffer,
1904 BufferSize);
1906
1907 /*
1908 * IOCTL_DISK_SET_DRIVE_LAYOUT calls IoWritePartitionTable(), which converts
1909 * DiskEntry->LayoutBuffer->PartitionCount into a partition *table* count,
1910 * where such a table is expected to enumerate up to 4 partitions:
1911 * partition *table* count == ROUND_UP(PartitionCount, 4) / 4 .
1912 * Due to this we need to restore the original PartitionCount number.
1913 */
1914 DiskEntry->LayoutBuffer->PartitionCount = PartitionCount;
1915
1916 /* Check whether the IOCTL_DISK_SET_DRIVE_LAYOUT call succeeded */
1917 if (!NT_SUCCESS(Status))
1918 {
1919 DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT failed (Status 0x%08lx)\n", Status);
1920 return Status;
1921 }
1922
1923 /* Update the partition numbers */
1924
1925 /* Update the primary partition table */
1926 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
1927 ListEntry != &DiskEntry->PrimaryPartListHead;
1928 ListEntry = ListEntry->Flink)
1929 {
1930 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
1931
1932 if (PartEntry->IsPartitioned)
1933 {
1935 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
1936 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
1937 }
1938 }
1939
1940 /* Update the logical partition table */
1941 for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
1942 ListEntry != &DiskEntry->LogicalPartListHead;
1943 ListEntry = ListEntry->Flink)
1944 {
1945 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
1946
1947 if (PartEntry->IsPartitioned)
1948 {
1950 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
1951 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
1952 }
1953 }
1954
1955 /* The layout has been successfully updated, the disk is not dirty anymore */
1956 DiskEntry->Dirty = FALSE;
1957
1958 return Status;
1959}

Referenced by active_main(), CreateExtendedPartition(), CreateLogicalPartition(), CreatePrimaryMbrPartition(), DeleteMbrPartition(), inactive_main(), setid_main(), and UniqueIdDisk().

Variable Documentation

◆ BiosDiskListHead

LIST_ENTRY BiosDiskListHead
extern

◆ cmds

◆ CurrentDisk

◆ CurrentPartition

PPARTENTRY CurrentPartition
extern

Definition at line 78 of file partlist.c.

Referenced by CreatePartitionList(), and DestroyPartitionList().

◆ CurrentVolume

◆ DiskListHead

LIST_ENTRY DiskListHead
extern

◆ VolumeListHead