ReactOS 0.4.16-dev-1972-gf20c09f
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 "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  _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 _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 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 ReadLayoutBuffer (_In_ HANDLE FileHandle, _In_ PDISKENTRY DiskEntry)
 
NTSTATUS WritePartitions (_In_ PDISKENTRY DiskEntry)
 
VOID UpdateDiskLayout (_In_ PDISKENTRY DiskEntry)
 
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 81 of file diskpart.h.

◆ MAX_STRING_SIZE

#define MAX_STRING_SIZE   1024

Definition at line 80 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

◆ PARTENTRY

◆ PBIOSDISKENTRY

◆ PCOMMAND

◆ PDISKENTRY

◆ PFORMATSTATE

◆ PPARTENTRY

◆ PVOLENTRY

◆ PVOLUME_TYPE

◆ VOLENTRY

◆ VOLUME_TYPE

Enumeration Type Documentation

◆ _FORMATSTATE

Enumerator
Unformatted 
UnformattedOrDamaged 
UnknownFormat 
Formatted 
Unformatted 
UnformattedOrDamaged 
UnknownFormat 
Preformatted 
Formatted 

Definition at line 84 of file diskpart.h.

85{
enum _FORMATSTATE FORMATSTATE
enum _FORMATSTATE * PFORMATSTATE
@ UnknownFormat
Definition: diskpart.h:88
@ Preformatted
Definition: diskpart.h:89
@ Formatted
Definition: diskpart.h:90
@ Unformatted
Definition: diskpart.h:86
@ UnformattedOrDamaged
Definition: diskpart.h:87

◆ _VOLUME_TYPE

Enumerator
VOLUME_TYPE_CDROM 
VOLUME_TYPE_PARTITION 
VOLUME_TYPE_REMOVABLE 
VOLUME_TYPE_UNKNOWN 

Definition at line 93 of file diskpart.h.

94{
@ VOLUME_TYPE_UNKNOWN
Definition: diskpart.h:98
@ VOLUME_TYPE_REMOVABLE
Definition: diskpart.h:97
@ VOLUME_TYPE_CDROM
Definition: diskpart.h:95
@ VOLUME_TYPE_PARTITION
Definition: diskpart.h:96
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 135 of file partlist.c.

138{
139 ULONGLONG Temp;
140
141 Temp = Value / Alignment;
142
143 return Temp * Alignment;
144}
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 94 of file convert.c.

97{
98 CREATE_DISK DiskInfo;
100
101 DPRINT("ConvertGPT()\n");
102
103 if (CurrentDisk == NULL)
104 {
106 return TRUE;
107 }
108
110 {
112 return TRUE;
113 }
114
116 {
118 return TRUE;
119 }
120
121#if 0
122 /* Fail if disk size is less than 128MB */
123 if (CurrentDisk->SectorCount.QuadPart * CurrentDisk->BytesPerSector < 128ULL * 1024ULL * 1024ULL)
124 {
125 ConResPuts(StdOut, IDS_CONVERT_GPT_TOO_SMALL);
126 return TRUE;
127 }
128#endif
129
130 DiskInfo.PartitionStyle = PARTITION_STYLE_GPT;
131 CreateGUID(&DiskInfo.Gpt.DiskId);
132 DiskInfo.Gpt.MaxPartitionCount = 128;
133
135 if (!NT_SUCCESS(Status))
136 {
137
138 }
139 else
140 {
142 }
143
144 return TRUE;
145}
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
LONG NTSTATUS
Definition: precomp.h:26
#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:94
#define IDS_CONVERT_GPT_ALREADY
Definition: resource.h:30
VOID CreateGUID(_Out_ GUID *pGuid)
Definition: misc.c:152
PDISKENTRY CurrentDisk
Definition: partlist.c:76
#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
#define DPRINT
Definition: sndvol32.h:73
ULARGE_INTEGER SectorCount
Definition: partlist.h:115
ULONG DiskNumber
Definition: partlist.h:129
ULONG BytesPerSector
Definition: partlist.h:113
DWORD PartitionStyle
Definition: diskpart.h:179
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 149 of file convert.c.

152{
153 CREATE_DISK DiskInfo;
155
156 DPRINT("ConvertMBR()\n");
157
158 if (CurrentDisk == NULL)
159 {
161 return TRUE;
162 }
163
165 (CurrentDisk->PartitionStyle == PARTITION_STYLE_RAW))
166 {
168 return TRUE;
169 }
170
172 {
174 return TRUE;
175 }
176
177 DiskInfo.PartitionStyle = PARTITION_STYLE_MBR;
178 CreateSignature(&DiskInfo.Mbr.Signature);
179
181 if (!NT_SUCCESS(Status))
182 {
183
184 }
185 else
186 {
188 }
189
190 return TRUE;
191}
#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 CreateSignature(_Out_ PDWORD pSignature)
Definition: misc.c:168
@ PARTITION_STYLE_MBR
Definition: imports.h:201

◆ CreateDisk()

NTSTATUS CreateDisk ( _In_ ULONG  DiskNumber,
_In_ PCREATE_DISK  DiskInfo 
)

Definition at line 15 of file convert.c.

18{
25
26 DPRINT1("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 CurrentDisk->PartitionStyle = DiskInfo->PartitionStyle;
68
69 /* Free the layout buffer */
71 {
72 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentDisk->LayoutBuffer);
75 }
76
78
79 DPRINT1("PartitionCount: %lu\n", CurrentDisk->LayoutBuffer->PartitionCount);
80
81#ifdef DUMP_PARTITION_TABLE
82 DumpPartitionTable(CurrentDisk);
83#endif
84
85done:
86 if (FileHandle)
88
89 return Status;
90}
#define DPRINT1
Definition: precomp.h:8
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:816
#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
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ConvertGPT(), and ConvertMBR().

◆ 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 /* FIXME: Initialize disk properly! */
47 }
48
49 for (i = 3; i < argc; i++)
50 {
51 if (HasPrefix(argv[i], L"size=", &pszSuffix))
52 {
53 /* size=<N> (MB) */
54 DPRINT("Size : %s\n", pszSuffix);
55
56 ullSize = _wcstoui64(pszSuffix, NULL, 10);
57 if ((ullSize == 0) && (errno == ERANGE))
58 {
60 return TRUE;
61 }
62 }
63 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
64 {
65 /* offset=<N> (KB) */
66 DPRINT("Offset : %s\n", pszSuffix);
67 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
68#if 0
69 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
70 if ((ullOffset == 0) && (errno == ERANGE))
71 {
73 return TRUE;
74 }
75#endif
76 }
77 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
78 {
79 /* align=<N> */
80 DPRINT("Align : %s\n", pszSuffix);
81 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
82#if 0
83 bAlign = TRUE;
84#endif
85 }
86 else if (_wcsicmp(argv[i], L"noerr") == 0)
87 {
88 /* noerr */
89 DPRINT("NoErr\n", pszSuffix);
90 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
91#if 0
92 bNoErr = TRUE;
93#endif
94 }
95 else
96 {
98 return TRUE;
99 }
100 }
101
102 DPRINT1("Size: %I64u\n", ullSize);
103#if 0
104 DPRINT1("Offset: %I64u\n", ullOffset);
105#endif
106
108 {
109 ConPuts(StdOut, L"No space left for an extended partition!\n");
110 return TRUE;
111 }
112
114 {
115 ConPuts(StdOut, L"We already have an extended partition on this disk!\n");
116 return TRUE;
117 }
118
119 if (ullSize != 0)
120 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
121 else
122 ullSectorCount = 0;
123
124 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
125
127
128 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
129 if (PartEntry->IsPartitioned)
130 {
131 ConPuts(StdOut, L"No disk space left for an extended partition!\n");
132 return TRUE;
133 }
134
135 if (ullSectorCount == 0)
136 {
137 PartEntry->IsPartitioned = TRUE;
138 PartEntry->New = TRUE;
140 PartEntry->FormatState = Unformatted;
141 PartEntry->FileSystemName[0] = L'\0';
142
143 CurrentPartition = PartEntry;
145 }
146 else
147 {
148 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
149 {
150 PartEntry->IsPartitioned = TRUE;
151 PartEntry->New = TRUE;
153 PartEntry->FormatState = Unformatted;
154 PartEntry->FileSystemName[0] = L'\0';
155
156 CurrentPartition = PartEntry;
158 }
159 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
160 {
161 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
162 if (NewPartEntry == NULL)
163 {
164 ConPuts(StdOut, L"Memory allocation failed!\n");
165 return TRUE;
166 }
167
168 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
169
170 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
171 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
172
173 NewPartEntry->LogicalPartition = FALSE;
174 NewPartEntry->IsPartitioned = TRUE;
175 NewPartEntry->New = TRUE;
176 NewPartEntry->PartitionType = PARTITION_EXTENDED;
177 NewPartEntry->FormatState = Unformatted;
178 NewPartEntry->FileSystemName[0] = L'\0';
179
180 PartEntry->StartSector.QuadPart += ullSectorCount;
181 PartEntry->SectorCount.QuadPart -= ullSectorCount;
182
183 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
184
185 CurrentPartition = NewPartEntry;
187 }
188 }
189
192 if (!NT_SUCCESS(Status))
193 {
196 return TRUE;
197 }
198
200
201 return TRUE;
202}
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:202
#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
BOOL HasPrefix(_In_ PWSTR pszString, _In_ PWSTR pszPrefix, _Out_opt_ PWSTR *pszSuffix)
Definition: misc.c:58
#define FALSE
Definition: types.h:117
#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
static VOID UpdateDiskLayout(IN PDISKENTRY DiskEntry)
Definition: partlist.c:2589
#define GetPrimaryPartitionCount(DiskEntry)
Definition: partlist.c:2527
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3593
BOOLEAN Dirty
Definition: partlist.h:136
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
UCHAR PartitionType
Definition: partlist.h:73
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
FORMATSTATE FormatState
Definition: diskpart.h:119
LIST_ENTRY ListEntry
Definition: partlist.h:63
ULARGE_INTEGER StartSector
Definition: partlist.h:69
CHAR FileSystemName[9]
Definition: diskpart.h:118
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().

◆ CreateLogicalPartition()

BOOL CreateLogicalPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 206 of file create.c.

209{
210 PPARTENTRY PartEntry, NewPartEntry;
211 PLIST_ENTRY ListEntry;
212 ULONGLONG ullSize = 0ULL;
213 ULONGLONG ullSectorCount;
214#if 0
215 ULONGLONG ullOffset = 0ULL;
216 BOOL bNoErr = FALSE;
217#endif
219 INT i, length;
220 PWSTR pszSuffix = NULL;
222
223 if (CurrentDisk == NULL)
224 {
226 return TRUE;
227 }
228
230 {
232 return TRUE;
233 }
234
235 for (i = 3; i < argc; i++)
236 {
237 if (HasPrefix(argv[i], L"size=", &pszSuffix))
238 {
239 /* size=<N> (MB) */
240 DPRINT("Size : %s\n", pszSuffix);
241
242 ullSize = _wcstoui64(pszSuffix, NULL, 10);
243 if ((ullSize == 0) && (errno == ERANGE))
244 {
246 return TRUE;
247 }
248 }
249 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
250 {
251 /* offset=<N> (KB) */
252 DPRINT("Offset : %s\n", pszSuffix);
253 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
254#if 0
255 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
256 if ((ullOffset == 0) && (errno == ERANGE))
257 {
259 return TRUE;
260 }
261#endif
262 }
263 else if (HasPrefix(argv[i], L"id=", &pszSuffix))
264 {
265 /* id=<Byte> */
266 DPRINT("Id : %s\n", pszSuffix);
267
268 length = wcslen(pszSuffix);
269 if ((length == 1) || (length == 2))
270 {
271 /* Byte */
272 PartitionType = (UCHAR)wcstoul(pszSuffix, NULL, 16);
273 if ((PartitionType == 0) && (errno == ERANGE))
274 {
276 return TRUE;
277 }
278 }
279 else
280 {
282 return TRUE;
283 }
284 }
285 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
286 {
287 /* align=<N> */
288 DPRINT("Align : %s\n", pszSuffix);
289 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
290#if 0
291 bAlign = TRUE;
292#endif
293 }
294 else if (_wcsicmp(argv[i], L"noerr") == 0)
295 {
296 /* noerr */
297 DPRINT("NoErr\n", pszSuffix);
298 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
299#if 0
300 bNoErr = TRUE;
301#endif
302 }
303 else
304 {
306 return TRUE;
307 }
308 }
309
310 DPRINT1("Size: %I64u\n", ullSize);
311#if 0
312 DPRINT1("Offset: %I64u\n", ullOffset);
313#endif
314 DPRINT1("Partition Type: %hx\n", PartitionType);
315
316 if (ullSize != 0)
317 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
318 else
319 ullSectorCount = 0;
320
321 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
322
323 for (ListEntry = CurrentDisk->LogicalPartListHead.Flink;
324 ListEntry != &CurrentDisk->LogicalPartListHead;
325 ListEntry = ListEntry->Flink)
326 {
327 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
328 if (PartEntry->IsPartitioned)
329 continue;
330
331 if (ullSectorCount == 0)
332 {
333 PartEntry->IsPartitioned = TRUE;
334 PartEntry->New = TRUE;
335 PartEntry->PartitionType = PartitionType;
336 PartEntry->FormatState = Unformatted;
337 PartEntry->FileSystemName[0] = L'\0';
338
339 CurrentPartition = PartEntry;
341 break;
342 }
343 else
344 {
345 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
346 {
347 PartEntry->IsPartitioned = TRUE;
348 PartEntry->New = TRUE;
349 PartEntry->PartitionType = PartitionType;
350 PartEntry->FormatState = Unformatted;
351 PartEntry->FileSystemName[0] = L'\0';
352
353 CurrentPartition = PartEntry;
355 break;
356 }
357 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
358 {
359 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
360 if (NewPartEntry == NULL)
361 {
362 ConPuts(StdOut, L"Memory allocation failed!\n");
363 return TRUE;
364 }
365
366 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
367
368 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
369 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
370
371 NewPartEntry->LogicalPartition = TRUE;
372 NewPartEntry->IsPartitioned = TRUE;
373 NewPartEntry->New = TRUE;
374 NewPartEntry->PartitionType = PartitionType;
375 NewPartEntry->FormatState = Unformatted;
376 NewPartEntry->FileSystemName[0] = L'\0';
377
378 PartEntry->StartSector.QuadPart += ullSectorCount;
379 PartEntry->SectorCount.QuadPart -= ullSectorCount;
380
381 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
382
383 CurrentPartition = NewPartEntry;
385 break;
386 }
387 }
388 }
389
392 if (!NT_SUCCESS(Status))
393 {
396 return TRUE;
397 }
398
400
401 return TRUE;
402}
#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 406 of file create.c.

409{
410 PPARTENTRY PartEntry, NewPartEntry;
411 PLIST_ENTRY ListEntry;
412 ULONGLONG ullSize = 0ULL;
413 ULONGLONG ullSectorCount;
414#if 0
415 ULONGLONG ullOffset = 0ULL;
416 BOOL bNoErr = FALSE;
417#endif
419 INT i, length;
420 PWSTR pszSuffix = NULL;
422
423 if (CurrentDisk == NULL)
424 {
426 return TRUE;
427 }
428
430 {
431 ConPuts(StdOut, L"GPT Partitions are not supported yet!\n");
432 return TRUE;
433 }
434 else if (CurrentDisk->PartitionStyle == PARTITION_STYLE_RAW)
435 {
436 /* FIXME: Initialize disk properly! */
438 }
439
440 for (i = 3; i < argc; i++)
441 {
442 if (HasPrefix(argv[i], L"size=", &pszSuffix))
443 {
444 /* size=<N> (MB) */
445 DPRINT("Size : %s\n", pszSuffix);
446
447 ullSize = _wcstoui64(pszSuffix, NULL, 10);
448 if ((ullSize == 0) && (errno == ERANGE))
449 {
451 return TRUE;
452 }
453 }
454 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
455 {
456 /* offset=<N> (KB) */
457 DPRINT("Offset : %s\n", pszSuffix);
458 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
459#if 0
460 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
461 if ((ullOffset == 0) && (errno == ERANGE))
462 {
464 return TRUE;
465 }
466#endif
467 }
468 else if (HasPrefix(argv[i], L"id=", &pszSuffix))
469 {
470 /* id=<Byte>|<GUID> */
471 DPRINT("Id : %s\n", pszSuffix);
472
473 length = wcslen(pszSuffix);
474 if ((length == 1) || (length == 2))
475 {
476 /* Byte */
477 PartitionType = (UCHAR)wcstoul(pszSuffix, NULL, 16);
478 if ((PartitionType == 0) && (errno == ERANGE))
479 {
481 return TRUE;
482 }
483 }
484#if 0
485 else if ()
486 {
487 /* GUID */
488 }
489#endif
490 else
491 {
493 return TRUE;
494 }
495 }
496 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
497 {
498 /* align=<N> */
499 DPRINT("Align : %s\n", pszSuffix);
500 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
501#if 0
502 bAlign = TRUE;
503#endif
504 }
505 else if (_wcsicmp(argv[i], L"noerr") == 0)
506 {
507 /* noerr */
508 DPRINT("NoErr\n", pszSuffix);
509 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
510#if 0
511 bNoErr = TRUE;
512#endif
513 }
514 else
515 {
517 return TRUE;
518 }
519 }
520
521 DPRINT1("Size: %I64u\n", ullSize);
522#if 0
523 DPRINT1("Offset: %I64u\n", ullOffset);
524#endif
525 DPRINT1("Partition Type: %hx\n", PartitionType);
526
528 {
529 ConPuts(StdOut, L"No space left for another primary partition!\n");
530 return TRUE;
531 }
532
533 if (ullSize != 0)
534 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
535 else
536 ullSectorCount = 0;
537
538 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
539
540 for (ListEntry = CurrentDisk->PrimaryPartListHead.Flink;
541 ListEntry != &CurrentDisk->PrimaryPartListHead;
542 ListEntry = ListEntry->Flink)
543 {
544 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
545 if (PartEntry->IsPartitioned)
546 continue;
547
548 if (ullSectorCount == 0)
549 {
550 PartEntry->IsPartitioned = TRUE;
551 PartEntry->New = TRUE;
552 PartEntry->PartitionType = PartitionType;
553 PartEntry->FormatState = Unformatted;
554 PartEntry->FileSystemName[0] = L'\0';
555
556 CurrentPartition = PartEntry;
558 break;
559 }
560 else
561 {
562 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
563 {
564 PartEntry->IsPartitioned = TRUE;
565 PartEntry->New = TRUE;
566 PartEntry->PartitionType = PartitionType;
567 PartEntry->FormatState = Unformatted;
568 PartEntry->FileSystemName[0] = L'\0';
569
570 CurrentPartition = PartEntry;
572 break;
573 }
574 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
575 {
576 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
577 if (NewPartEntry == NULL)
578 {
579 ConPuts(StdOut, L"Memory allocation failed!\n");
580 return TRUE;
581 }
582
583 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
584
585 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
586 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
587
588 NewPartEntry->LogicalPartition = FALSE;
589 NewPartEntry->IsPartitioned = TRUE;
590 NewPartEntry->New = TRUE;
591 NewPartEntry->PartitionType = PartitionType;
592 NewPartEntry->FormatState = Unformatted;
593 NewPartEntry->FileSystemName[0] = L'\0';
594
595 PartEntry->StartSector.QuadPart += ullSectorCount;
596 PartEntry->SectorCount.QuadPart -= ullSectorCount;
597
598 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
599
600 CurrentPartition = NewPartEntry;
602 break;
603 }
604 }
605 }
606
609 if (!NT_SUCCESS(Status))
610 {
613 return TRUE;
614 }
615
617
618 return TRUE;
619}

◆ 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().

◆ CreateVolumeList()

NTSTATUS CreateVolumeList ( VOID  )

Definition at line 1491 of file partlist.c.

1492{
1493 HANDLE hVolume = INVALID_HANDLE_VALUE;
1494 WCHAR szVolumeName[MAX_PATH];
1495 ULONG ulVolumeNumber = 0;
1496 BOOL Success;
1497
1499
1501
1502 hVolume = FindFirstVolumeW(szVolumeName, ARRAYSIZE(szVolumeName));
1503 if (hVolume == INVALID_HANDLE_VALUE)
1504 {
1505
1506 return STATUS_UNSUCCESSFUL;
1507 }
1508
1509 AddVolumeToList(ulVolumeNumber++, szVolumeName);
1510
1511 for (;;)
1512 {
1513 Success = FindNextVolumeW(hVolume, szVolumeName, ARRAYSIZE(szVolumeName));
1514 if (!Success)
1515 {
1516 break;
1517 }
1518
1519 AddVolumeToList(ulVolumeNumber++, szVolumeName);
1520 }
1521
1522 FindVolumeClose(hVolume);
1523
1524 return STATUS_SUCCESS;
1525}
#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:74
static VOID AddVolumeToList(ULONG ulVolumeNumber, PWSTR pszVolumeName)
Definition: partlist.c:1375
PVOLENTRY CurrentVolume
Definition: partlist.c:78
#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 37 of file delete.c.

40{
41 PPARTENTRY PrevPartEntry;
42 PPARTENTRY NextPartEntry;
43 PPARTENTRY LogicalPartEntry;
45 INT i;
46 BOOL bOverride = FALSE;
48
49 DPRINT("DeletePartition()\n");
50
51 if (CurrentDisk == NULL)
52 {
54 return TRUE;
55 }
56
58 {
60 return TRUE;
61 }
62
64
65 for (i = 2; i < argc; i++)
66 {
67 if (_wcsicmp(argv[i], L"noerr") == 0)
68 {
69 /* noerr */
70 DPRINT("NOERR\n");
71 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
72#if 0
73 bNoErr = TRUE;
74#endif
75 }
76 else if (_wcsicmp(argv[i], L"override") == 0)
77 {
78 /* override */
79 DPRINT("OVERRIDE\n");
80 bOverride = TRUE;
81 }
82 else
83 {
85 return TRUE;
86 }
87 }
88
89
90 /* Clear the system partition if it is being deleted */
91#if 0
92 if (List->SystemPartition == PartEntry)
93 {
94 ASSERT(List->SystemPartition);
95 List->SystemPartition = NULL;
96 }
97#endif
98
99 if ((bOverride == FALSE) && (IsKnownPartition(CurrentPartition) == FALSE))
100 {
102 return FALSE;
103 }
104
105 /* Check which type of partition (primary/logical or extended) is being deleted */
107 {
108 /* An extended partition is being deleted: delete all logical partition entries */
110 {
112 LogicalPartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
113
114 /* Dismount the logical partition */
115 DismountVolume(LogicalPartEntry);
116
117 /* Delete it */
118 RtlFreeHeap(RtlGetProcessHeap(), 0, LogicalPartEntry);
119 }
120
122 }
123 else
124 {
125 /* A primary partition is being deleted: dismount it */
127 }
128
129 /* Adjust the unpartitioned disk space entries */
130
131 /* Get pointer to previous and next unpartitioned entries */
134
135 if (PrevPartEntry != NULL && NextPartEntry != NULL)
136 {
137 /* Merge the previous, current and next unpartitioned entries */
138
139 /* Adjust the previous entry length */
140 PrevPartEntry->SectorCount.QuadPart += (CurrentPartition->SectorCount.QuadPart + NextPartEntry->SectorCount.QuadPart);
141
142 /* Remove the current and next entries */
144 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
145 RemoveEntryList(&NextPartEntry->ListEntry);
146 RtlFreeHeap(RtlGetProcessHeap(), 0, NextPartEntry);
147 }
148 else if (PrevPartEntry != NULL && NextPartEntry == NULL)
149 {
150 /* Merge the current and the previous unpartitioned entries */
151
152 /* Adjust the previous entry length */
154
155 /* Remove the current entry */
157 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
158 }
159 else if (PrevPartEntry == NULL && NextPartEntry != NULL)
160 {
161 /* Merge the current and the next unpartitioned entries */
162
163 /* Adjust the next entry offset and length */
166
167 /* Remove the current entry */
169 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentPartition);
170 }
171 else
172 {
173 /* Nothing to merge but change the current entry */
177 // CurrentPartition->PartitionIndex = 0;
184 }
185
187
190 if (!NT_SUCCESS(Status))
191 {
193 return TRUE;
194 }
195
197
198 return TRUE;
199}
static BOOL IsKnownPartition(_In_ PPARTENTRY PartEntry)
Definition: delete.c:16
#define IDS_SELECT_NO_PARTITION
Definition: resource.h:99
#define IDS_DELETE_PARTITION_SUCCESS
Definition: resource.h:42
#define IDS_DELETE_PARTITION_FAIL
Definition: resource.h:41
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:71
PPARTENTRY GetPrevUnpartitionedEntry(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:1987
PPARTENTRY GetNextUnpartitionedEntry(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:2016
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define ASSERT(a)
Definition: mode.c:44
base of all file and directory entries
Definition: entries.h:83
BOOLEAN BootIndicator
Definition: partlist.h:72
CHAR VolumeLabel[17]
Definition: diskpart.h:117
CHAR DriveLetter
Definition: diskpart.h:116
ULONG OnDiskPartitionNumber
Definition: partlist.h:74
ULONG PartitionNumber
Definition: partlist.h:75
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
NTSTATUS DismountVolume(_Inout_ PVOLINFO Volume, _In_ BOOLEAN Force)
Attempts to dismount the designated volume.
Definition: volutil.c:152

◆ DeleteVolume()

BOOL DeleteVolume ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 203 of file delete.c.

206{
207 return TRUE;
208}

◆ DestroyPartitionList()

VOID DestroyPartitionList ( VOID  )

Definition at line 1210 of file partlist.c.

1211{
1212 PDISKENTRY DiskEntry;
1213 PBIOSDISKENTRY BiosDiskEntry;
1214 PPARTENTRY PartEntry;
1216
1217 CurrentDisk = NULL;
1219
1220 /* Release disk and partition info */
1221 while (!IsListEmpty(&DiskListHead))
1222 {
1224 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
1225
1226 /* Release driver name */
1227 RtlFreeUnicodeString(&DiskEntry->DriverName);
1228
1229 /* Release primary partition list */
1230 while (!IsListEmpty(&DiskEntry->PrimaryPartListHead))
1231 {
1233 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1234
1235 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1236 }
1237
1238 /* Release logical partition list */
1239 while (!IsListEmpty(&DiskEntry->LogicalPartListHead))
1240 {
1242 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1243
1244 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1245 }
1246
1247 /* Release layout buffer */
1248 if (DiskEntry->LayoutBuffer != NULL)
1249 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry->LayoutBuffer);
1250
1251
1252 /* Release disk entry */
1253 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry);
1254 }
1255
1256 /* Release the bios disk info */
1257 while (!IsListEmpty(&BiosDiskListHead))
1258 {
1260 BiosDiskEntry = CONTAINING_RECORD(Entry, BIOSDISKENTRY, ListEntry);
1261
1262 RtlFreeHeap(RtlGetProcessHeap(), 0, BiosDiskEntry);
1263 }
1264}
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
UNICODE_STRING DriverName
Definition: partlist.h:141
LIST_ENTRY BiosDiskListHead
Definition: partlist.c:73
LIST_ENTRY DiskListHead
Definition: partlist.c:72
PPARTENTRY CurrentPartition
Definition: partlist.c:77

◆ DestroyVolumeList()

VOID DestroyVolumeList ( VOID  )

Definition at line 1529 of file partlist.c.

1530{
1532 PVOLENTRY VolumeEntry;
1533
1535
1536 /* Release disk and partition info */
1537 while (!IsListEmpty(&VolumeListHead))
1538 {
1540 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
1541
1542 if (VolumeEntry->pszLabel)
1543 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
1544
1545 if (VolumeEntry->pszFilesystem)
1546 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
1547
1548 if (VolumeEntry->pExtents)
1549 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pExtents);
1550
1551 /* Release disk entry */
1552 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
1553 }
1554}
PVOLUME_DISK_EXTENTS pExtents
Definition: diskpart.h:207
PWSTR pszFilesystem
Definition: diskpart.h:203
PWSTR pszLabel
Definition: diskpart.h:202

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 2045 of file partlist.c.

2047{
2049 NTSTATUS LockStatus;
2053 HANDLE PartitionHandle;
2055
2056 /* Check whether the partition is valid and was mounted by the system */
2057 if (!PartEntry->IsPartitioned ||
2058 IsContainerPartition(PartEntry->PartitionType) ||
2059 !IsRecognizedPartition(PartEntry->PartitionType) ||
2060 PartEntry->FormatState == UnknownFormat ||
2061 // NOTE: If FormatState == Unformatted but *FileSystem != 0 this means
2062 // it has been usually mounted with RawFS and thus needs to be dismounted.
2063/* !*PartEntry->FileSystem || */
2064 PartEntry->PartitionNumber == 0)
2065 {
2066 /* The partition is not mounted, so just return success */
2067 return STATUS_SUCCESS;
2068 }
2069
2070 ASSERT(PartEntry->PartitionType != PARTITION_ENTRY_UNUSED);
2071
2072 /* Open the volume */
2074 L"\\Device\\Harddisk%lu\\Partition%lu",
2075 PartEntry->DiskEntry->DiskNumber,
2076 PartEntry->PartitionNumber);
2078
2080 &Name,
2082 NULL,
2083 NULL);
2084
2085 Status = NtOpenFile(&PartitionHandle,
2091 if (!NT_SUCCESS(Status))
2092 {
2093 DPRINT1("ERROR: Cannot open volume %wZ for dismounting! (Status 0x%lx)\n", &Name, Status);
2094 return Status;
2095 }
2096
2097 /* Lock the volume */
2098 LockStatus = NtFsControlFile(PartitionHandle,
2099 NULL,
2100 NULL,
2101 NULL,
2104 NULL,
2105 0,
2106 NULL,
2107 0);
2108 if (!NT_SUCCESS(LockStatus))
2109 {
2110 DPRINT1("WARNING: Failed to lock volume! Operations may fail! (Status 0x%lx)\n", LockStatus);
2111 }
2112
2113 /* Dismount the volume */
2114 Status = NtFsControlFile(PartitionHandle,
2115 NULL,
2116 NULL,
2117 NULL,
2120 NULL,
2121 0,
2122 NULL,
2123 0);
2124 if (!NT_SUCCESS(Status))
2125 {
2126 DPRINT1("Failed to unmount volume (Status 0x%lx)\n", Status);
2127 }
2128
2129 /* Unlock the volume */
2130 LockStatus = NtFsControlFile(PartitionHandle,
2131 NULL,
2132 NULL,
2133 NULL,
2136 NULL,
2137 0,
2138 NULL,
2139 0);
2140 if (!NT_SUCCESS(LockStatus))
2141 {
2142 DPRINT1("Failed to unlock volume (Status 0x%lx)\n", LockStatus);
2143 }
2144
2145 /* Close the volume */
2146 NtClose(PartitionHandle);
2147
2148 return Status;
2149}
@ UnknownFormat
Definition: partlist.h:36
#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}

◆ 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 2016 of file partlist.c.

2018{
2019 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
2020 PPARTENTRY NextPartEntry;
2021 PLIST_ENTRY ListHead;
2022
2023 if (PartEntry->LogicalPartition)
2024 ListHead = &DiskEntry->LogicalPartListHead;
2025 else
2026 ListHead = &DiskEntry->PrimaryPartListHead;
2027
2028 if (PartEntry->ListEntry.Flink != ListHead)
2029 {
2030 NextPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Flink,
2031 PARTENTRY,
2032 ListEntry);
2033 if (!NextPartEntry->IsPartitioned)
2034 {
2035 ASSERT(NextPartEntry->PartitionType == PARTITION_ENTRY_UNUSED);
2036 return NextPartEntry;
2037 }
2038 }
2039
2040 return NULL;
2041}

Referenced by DeletePartition().

◆ GetPrevUnpartitionedEntry()

PPARTENTRY GetPrevUnpartitionedEntry ( _In_ PPARTENTRY  PartEntry)

Definition at line 1987 of file partlist.c.

1989{
1990 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
1991 PPARTENTRY PrevPartEntry;
1992 PLIST_ENTRY ListHead;
1993
1994 if (PartEntry->LogicalPartition)
1995 ListHead = &DiskEntry->LogicalPartListHead;
1996 else
1997 ListHead = &DiskEntry->PrimaryPartListHead;
1998
1999 if (PartEntry->ListEntry.Blink != ListHead)
2000 {
2001 PrevPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Blink,
2002 PARTENTRY,
2003 ListEntry);
2004 if (!PrevPartEntry->IsPartitioned)
2005 {
2006 ASSERT(PrevPartEntry->PartitionType == PARTITION_ENTRY_UNUSED);
2007 return PrevPartEntry;
2008 }
2009 }
2010
2011 return NULL;
2012}

Referenced by DeletePartition().

◆ GetPrimaryPartitionCount()

ULONG GetPrimaryPartitionCount ( _In_ PDISKENTRY  DiskEntry)

Definition at line 1714 of file partlist.c.

1716{
1718 PPARTENTRY PartEntry;
1719 ULONG Count = 0;
1720
1721 for (Entry = DiskEntry->PrimaryPartListHead.Flink;
1722 Entry != &DiskEntry->PrimaryPartListHead;
1723 Entry = Entry->Flink)
1724 {
1725 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1726 if (PartEntry->IsPartitioned)
1727 Count++;
1728 }
1729
1730 return Count;
1731}
int Count
Definition: noreturn.cpp:7

◆ GetVolumeFromPartition()

PVOLENTRY GetVolumeFromPartition ( _In_ PPARTENTRY  PartEntry)

Definition at line 2153 of file partlist.c.

2155{
2157 PVOLENTRY VolumeEntry;
2158 ULONG i;
2159
2160 if ((PartEntry == NULL) ||
2161 (PartEntry->DiskEntry == NULL))
2162 return NULL;
2163
2165 while (Entry != &VolumeListHead)
2166 {
2167 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
2168
2169 if (VolumeEntry->pExtents == NULL)
2170 return NULL;
2171
2172 for (i = 0; i < VolumeEntry->pExtents->NumberOfDiskExtents; i++)
2173 {
2174 if (VolumeEntry->pExtents->Extents[i].DiskNumber == PartEntry->DiskEntry->DiskNumber)
2175 {
2176 if ((VolumeEntry->pExtents->Extents[i].StartingOffset.QuadPart == PartEntry->StartSector.QuadPart * PartEntry->DiskEntry->BytesPerSector) &&
2177 (VolumeEntry->pExtents->Extents[i].ExtentLength.QuadPart == PartEntry->SectorCount.QuadPart * PartEntry->DiskEntry->BytesPerSector))
2178 return VolumeEntry;
2179 }
2180 }
2181
2182 Entry = Entry->Flink;
2183 }
2184
2185 return NULL;
2186}
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:64
PWSTR cmd2
Definition: diskpart.h:63
PWSTR cmd1
Definition: diskpart.h:62

◆ 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:73
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:66
DWORD help_detail
Definition: diskpart.h:67
#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:81
#define IDS_LIST_DISK_HEAD
Definition: resource.h:80
LIST_ENTRY DiskListHead
Definition: partlist.c:72

◆ 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
113 {
114 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
115
116 if (PartEntry->PartitionType != 0)
117 {
118 PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector;
119
120 if (PartSize >= 10737418240) /* 10 GB */
121 {
122 PartSize = RoundingDivide(PartSize, 1073741824);
123 lpSizeUnit = L"GB";
124 }
125 else if (PartSize >= 10485760) /* 10 MB */
126 {
127 PartSize = RoundingDivide(PartSize, 1048576);
128 lpSizeUnit = L"MB";
129 }
130 else
131 {
132 PartSize = RoundingDivide(PartSize, 1024);
133 lpSizeUnit = L"KB";
134 }
135
136 PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector;
137
138 if (PartOffset >= 10737418240) /* 10 GB */
139 {
140 PartOffset = RoundingDivide(PartOffset, 1073741824);
141 lpOffsetUnit = L"GB";
142 }
143 else if (PartOffset >= 10485760) /* 10 MB */
144 {
145 PartOffset = RoundingDivide(PartOffset, 1048576);
146 lpOffsetUnit = L"MB";
147 }
148 else
149 {
150 PartOffset = RoundingDivide(PartOffset, 1024);
151 lpOffsetUnit = L"KB";
152 }
153
155 (CurrentPartition == PartEntry) ? L'*' : L' ',
156 PartNumber++,
157 IsContainerPartition(PartEntry->PartitionType) ? L"Extended" : L"Primary",
158 PartSize,
159 lpSizeUnit,
160 PartOffset,
161 lpOffsetUnit);
162 }
163
164 Entry = Entry->Flink;
165 }
166
169 {
170 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
171
172 if (PartEntry->PartitionType != 0)
173 {
174 PartSize = PartEntry->SectorCount.QuadPart * CurrentDisk->BytesPerSector;
175
176 if (PartSize >= 10737418240) /* 10 GB */
177 {
178 PartSize = RoundingDivide(PartSize, 1073741824);
179 lpSizeUnit = L"GB";
180 }
181 else if (PartSize >= 10485760) /* 10 MB */
182 {
183 PartSize = RoundingDivide(PartSize, 1048576);
184 lpSizeUnit = L"MB";
185 }
186 else
187 {
188 PartSize = RoundingDivide(PartSize, 1024);
189 lpSizeUnit = L"KB";
190 }
191
192 PartOffset = PartEntry->StartSector.QuadPart * CurrentDisk->BytesPerSector;
193
194 if (PartOffset >= 10737418240) /* 10 GB */
195 {
196 PartOffset = RoundingDivide(PartOffset, 1073741824);
197 lpOffsetUnit = L"GB";
198 }
199 else if (PartOffset >= 10485760) /* 10 MB */
200 {
201 PartOffset = RoundingDivide(PartOffset, 1048576);
202 lpOffsetUnit = L"MB";
203 }
204 else
205 {
206 PartOffset = RoundingDivide(PartOffset, 1024);
207 lpOffsetUnit = L"KB";
208 }
209
211 (CurrentPartition == PartEntry) ? L'*' : L' ',
212 PartNumber++,
213 L"Logical",
214 PartSize,
215 lpSizeUnit,
216 PartOffset,
217 lpOffsetUnit);
218 }
219
220 Entry = Entry->Flink;
221 }
222
223 ConPuts(StdOut, L"\n");
224
225 return TRUE;
226}
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define IDS_LIST_PARTITION_NO_DISK
Definition: resource.h:86
#define IDS_LIST_PARTITION_HEAD
Definition: resource.h:83
#define IDS_LIST_PARTITION_LINE
Definition: resource.h:84
#define IDS_LIST_PARTITION_FORMAT
Definition: resource.h:85
ULONGLONG RoundingDivide(IN ULONGLONG Dividend, IN ULONGLONG Divisor)
Definition: partlist.c:95

◆ ListVirtualDisk()

BOOL ListVirtualDisk ( INT  argc,
PWSTR argv 
)

Definition at line 310 of file list.c.

313{
314 ConPuts(StdOut, L"ListVirtualDisk()!\n");
315 return TRUE;
316}

◆ ListVolume()

BOOL ListVolume ( INT  argc,
PWSTR argv 
)

Definition at line 282 of file list.c.

285{
287 PVOLENTRY VolumeEntry;
288
289 ConPuts(StdOut, L"\n");
292
294 while (Entry != &VolumeListHead)
295 {
296 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
297
298 PrintVolume(VolumeEntry);
299
300 Entry = Entry->Flink;
301 }
302
303 ConPuts(StdOut, L"\n");
304
305 return TRUE;
306}
VOID PrintVolume(_In_ PVOLENTRY VolumeEntry)
Definition: list.c:230
#define IDS_LIST_VOLUME_LINE
Definition: resource.h:88
#define IDS_LIST_VOLUME_HEAD
Definition: resource.h:87
LIST_ENTRY VolumeListHead
Definition: partlist.c:74

◆ 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:82
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(), and UniqueIdDisk().

◆ PrintVolume()

VOID PrintVolume ( _In_ PVOLENTRY  VolumeEntry)

Definition at line 230 of file list.c.

232{
233 ULONGLONG VolumeSize;
234 PWSTR pszSizeUnit;
235 PWSTR pszVolumeType;
236
237 VolumeSize = VolumeEntry->Size.QuadPart;
238 if (VolumeSize >= 10737418240) /* 10 GB */
239 {
240 VolumeSize = RoundingDivide(VolumeSize, 1073741824);
241 pszSizeUnit = L"GB";
242 }
243 else if (VolumeSize >= 10485760) /* 10 MB */
244 {
245 VolumeSize = RoundingDivide(VolumeSize, 1048576);
246 pszSizeUnit = L"MB";
247 }
248 else
249 {
250 VolumeSize = RoundingDivide(VolumeSize, 1024);
251 pszSizeUnit = L"KB";
252 }
253 switch (VolumeEntry->VolumeType)
254 {
256 pszVolumeType = L"DVD";
257 break;
259 pszVolumeType = L"Partition";
260 break;
262 pszVolumeType = L"Removable";
263 break;
265 default:
266 pszVolumeType = L"Unknown";
267 break;
268 }
269
271 (CurrentVolume == VolumeEntry) ? L'*' : L' ',
272 VolumeEntry->VolumeNumber,
273 VolumeEntry->DriveLetter,
274 (VolumeEntry->pszLabel) ? VolumeEntry->pszLabel : L"",
275 (VolumeEntry->pszFilesystem) ? VolumeEntry->pszFilesystem : L"",
276 pszVolumeType,
277 VolumeSize, pszSizeUnit);
278}
#define IDS_LIST_VOLUME_FORMAT
Definition: resource.h:89
PVOLENTRY CurrentVolume
Definition: partlist.c:78

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

◆ ReadLayoutBuffer()

VOID ReadLayoutBuffer ( _In_ HANDLE  FileHandle,
_In_ PDISKENTRY  DiskEntry 
)

Definition at line 816 of file partlist.c.

819{
820 ULONG LayoutBufferSize;
821 PDRIVE_LAYOUT_INFORMATION_EX NewLayoutBuffer;
824
825 /* Allocate a layout buffer with 4 partition entries first */
826 LayoutBufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
827 ((4 - ANYSIZE_ARRAY) * sizeof(PARTITION_INFORMATION_EX));
828 DiskEntry->LayoutBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
830 LayoutBufferSize);
831 if (DiskEntry->LayoutBuffer == NULL)
832 {
833 DPRINT1("Failed to allocate the disk layout buffer!\n");
834 return;
835 }
836
837 for (;;)
838 {
839 DPRINT1("Buffer size: %lu\n", LayoutBufferSize);
841 NULL,
842 NULL,
843 NULL,
844 &Iosb,
846 NULL,
847 0,
848 DiskEntry->LayoutBuffer,
849 LayoutBufferSize);
850 if (NT_SUCCESS(Status))
851 break;
852
854 {
855 DPRINT1("NtDeviceIoControlFile() failed (Status: 0x%08lx)\n", Status);
856 return;
857 }
858
859 LayoutBufferSize += 4 * sizeof(PARTITION_INFORMATION_EX);
860 NewLayoutBuffer = RtlReAllocateHeap(RtlGetProcessHeap(),
862 DiskEntry->LayoutBuffer,
863 LayoutBufferSize);
864 if (NewLayoutBuffer == NULL)
865 {
866 DPRINT1("Failed to reallocate the disk layout buffer!\n");
867 return;
868 }
869
870 DiskEntry->LayoutBuffer = NewLayoutBuffer;
871 }
872}
#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 2190 of file partlist.c.

2192{
2193 if (VolumeEntry == NULL)
2194 return;
2195
2196 if (VolumeEntry == CurrentVolume)
2198
2199 RemoveEntryList(&VolumeEntry->ListEntry);
2200
2201 if (VolumeEntry->pszLabel)
2202 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
2203
2204 if (VolumeEntry->pszFilesystem)
2205 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
2206
2207 if (VolumeEntry->pExtents)
2208 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pExtents);
2209
2210 /* Release disk entry */
2211 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
2212}

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:91
#define IDS_RESCAN_END
Definition: resource.h:92
VOID DestroyVolumeList(VOID)
Definition: partlist.c:1529
NTSTATUS CreateVolumeList(VOID)
Definition: partlist.c:1491
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}

◆ 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:96
#define IDS_SELECT_DISK_ENUM_NO_START
Definition: resource.h:97
#define IDS_SELECT_DISK
Definition: resource.h:95
#define IDS_SELECT_DISK_ENUM_FINISHED
Definition: resource.h:98
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
166 {
167 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
168
169 if (PartEntry->PartitionType != 0)
170 {
171 if (PartNumber == ulValue)
172 {
173 CurrentPartition = PartEntry;
175 return TRUE;
176 }
177
178 PartNumber++;
179 }
180
181 Entry = Entry->Flink;
182 }
183
186 {
187 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
188
189 if (PartEntry->PartitionType != 0)
190 {
191 if (PartNumber == ulValue)
192 {
193 CurrentPartition = PartEntry;
195 return TRUE;
196 }
197
198 PartNumber++;
199 }
200 Entry = Entry->Flink;
201 }
202
204 return TRUE;
205}
#define IDS_SELECT_PARTITION_NO_DISK
Definition: resource.h:101
#define IDS_SELECT_PARTITION_INVALID
Definition: resource.h:102
#define IDS_SELECT_PARTITION
Definition: resource.h:100

◆ SelectVolume()

BOOL SelectVolume ( INT  argc,
PWSTR argv 
)

Definition at line 209 of file select.c.

212{
214 PVOLENTRY VolumeEntry;
215 ULONG ulValue;
216
217 DPRINT("SelectVolume()\n");
218
219 if (argc > 3)
220 {
222 return TRUE;
223 }
224
225 if (argc == 2)
226 {
227 if (CurrentDisk == NULL)
229 else
231 return TRUE;
232 }
233
234 if (!IsDecString(argv[2]))
235 {
237 return TRUE;
238 }
239
240 ulValue = wcstoul(argv[2], NULL, 10);
241 if ((ulValue == 0) && (errno == ERANGE))
242 {
244 return TRUE;
245 }
246
248
250 while (Entry != &VolumeListHead)
251 {
252 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
253
254 if (VolumeEntry->VolumeNumber == ulValue)
255 {
256 CurrentVolume = VolumeEntry;
258 return TRUE;
259 }
260
261 Entry = Entry->Flink;
262 }
263
265 return TRUE;
266}
#define IDS_SELECT_NO_VOLUME
Definition: resource.h:103
#define IDS_SELECT_VOLUME
Definition: resource.h:104
#define IDS_SELECT_VOLUME_INVALID
Definition: resource.h:105
ULONG VolumeNumber
Definition: diskpart.h:196

◆ 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}

◆ 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 ConPuts(StdErr, L"The uniqueid disk command does not support GPT disks yet!\n");
76 }
78 {
79 if ((pszId == NULL) ||
80 (wcslen(pszId) != 8) ||
81 (IsHexString(pszId) == FALSE))
82 {
84 return TRUE;
85 }
86
87 ulValue = wcstoul(pszId, NULL, 16);
88 if ((ulValue == 0) && (errno == ERANGE))
89 {
91 return TRUE;
92 }
93
94 DPRINT("New Signature: 0x%08lx\n", ulValue);
95 CurrentDisk->LayoutBuffer->Mbr.Signature = ulValue;
99 }
100 else
101 {
103 }
104
105 return TRUE;
106}
#define IDS_UNIQUID_DISK_INVALID_STYLE
Definition: resource.h:112
VOID PrintGUID(_Out_ PWSTR pszBuffer, _In_ GUID *pGuid)
Definition: misc.c:187
BOOL IsHexString(_In_ PWSTR pszHexString)
Definition: misc.c:36

◆ UpdateDiskLayout()

VOID UpdateDiskLayout ( _In_ PDISKENTRY  DiskEntry)

Definition at line 1810 of file partlist.c.

1812{
1815 PLIST_ENTRY ListEntry;
1816 PPARTENTRY PartEntry;
1817 LARGE_INTEGER HiddenSectors64;
1818 ULONG Index;
1820
1821 DPRINT1("UpdateDiskLayout()\n");
1822
1823 /* Resize the layout buffer if necessary */
1824 if (ReAllocateLayoutBuffer(DiskEntry) == FALSE)
1825 {
1826 DPRINT("ReAllocateLayoutBuffer() failed.\n");
1827 return;
1828 }
1829
1830 DiskEntry->LayoutBuffer->PartitionStyle = PARTITION_STYLE_MBR;
1831
1832 /* Update the primary partition table */
1833 Index = 0;
1834 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
1835 ListEntry != &DiskEntry->PrimaryPartListHead;
1836 ListEntry = ListEntry->Flink)
1837 {
1838 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
1839
1840 if (PartEntry->IsPartitioned)
1841 {
1843
1844 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
1845 PartEntry->PartitionIndex = Index;
1846
1847 /* Reset the current partition number only for newly-created (unmounted) partitions */
1848 if (PartEntry->New)
1849 PartEntry->PartitionNumber = 0;
1850
1852
1853 if (!IsSamePrimaryLayoutEntry(PartitionInfo, DiskEntry, PartEntry))
1854 {
1855 DPRINT1("Updating primary partition entry %lu\n", Index);
1856
1857 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
1858 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
1859 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
1860 PartitionInfo->Mbr.HiddenSectors = PartEntry->StartSector.LowPart;
1861 PartitionInfo->PartitionNumber = PartEntry->PartitionNumber;
1862 PartitionInfo->Mbr.PartitionType = PartEntry->PartitionType;
1863 PartitionInfo->Mbr.BootIndicator = PartEntry->BootIndicator;
1864 PartitionInfo->Mbr.RecognizedPartition = IsRecognizedPartition(PartEntry->PartitionType);
1865 PartitionInfo->RewritePartition = TRUE;
1866 }
1867
1868 if (!IsContainerPartition(PartEntry->PartitionType))
1870
1871 Index++;
1872 }
1873 }
1874
1875 ASSERT(Index <= 4);
1876
1877 /* Update the logical partition table */
1878 Index = 4;
1879 for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
1880 ListEntry != &DiskEntry->LogicalPartListHead;
1881 ListEntry = ListEntry->Flink)
1882 {
1883 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
1884
1885 if (PartEntry->IsPartitioned)
1886 {
1888
1889 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
1890 PartEntry->PartitionIndex = Index;
1891
1892 /* Reset the current partition number only for newly-created (unmounted) partitions */
1893 if (PartEntry->New)
1894 PartEntry->PartitionNumber = 0;
1895
1897
1898 DPRINT1("Updating logical partition entry %lu\n", Index);
1899
1900 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
1901 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
1902 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
1903 PartitionInfo->Mbr.HiddenSectors = DiskEntry->SectorAlignment;
1904 PartitionInfo->PartitionNumber = PartEntry->PartitionNumber;
1905 PartitionInfo->Mbr.PartitionType = PartEntry->PartitionType;
1906 PartitionInfo->Mbr.BootIndicator = FALSE;
1907 PartitionInfo->Mbr.RecognizedPartition = IsRecognizedPartition(PartEntry->PartitionType);
1908 PartitionInfo->RewritePartition = TRUE;
1909
1910 /* Fill the link entry of the previous partition entry */
1911 if (LinkInfo != NULL)
1912 {
1914 LinkInfo->StartingOffset.QuadPart = (PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector;
1915 LinkInfo->PartitionLength.QuadPart = (PartEntry->StartSector.QuadPart + DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector;
1916 HiddenSectors64.QuadPart = PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment - DiskEntry->ExtendedPartition->StartSector.QuadPart;
1917 LinkInfo->Mbr.HiddenSectors = HiddenSectors64.LowPart;
1918 LinkInfo->PartitionNumber = 0;
1920 LinkInfo->Mbr.BootIndicator = FALSE;
1921 LinkInfo->Mbr.RecognizedPartition = FALSE;
1922 LinkInfo->RewritePartition = TRUE;
1923 }
1924
1925 /* Save a pointer to the link entry of the current partition entry */
1926 LinkInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index + 1];
1927
1929 Index += 4;
1930 }
1931 }
1932
1933 /* Wipe unused primary partition entries */
1934 for (Index = GetPrimaryPartitionCount(DiskEntry); Index < 4; Index++)
1935 {
1936 DPRINT1("Primary partition entry %lu\n", Index);
1937
1938 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
1939
1941 {
1942 DPRINT1("Wiping primary partition entry %lu\n", Index);
1943
1944 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
1945 PartitionInfo->StartingOffset.QuadPart = 0;
1946 PartitionInfo->PartitionLength.QuadPart = 0;
1947 PartitionInfo->Mbr.HiddenSectors = 0;
1948 PartitionInfo->PartitionNumber = 0;
1949 PartitionInfo->Mbr.PartitionType = PARTITION_ENTRY_UNUSED;
1950 PartitionInfo->Mbr.BootIndicator = FALSE;
1951 PartitionInfo->Mbr.RecognizedPartition = FALSE;
1952 PartitionInfo->RewritePartition = TRUE;
1953 }
1954 }
1955
1956 /* Wipe unused logical partition entries */
1957 for (Index = 4; Index < DiskEntry->LayoutBuffer->PartitionCount; Index++)
1958 {
1959 if (Index % 4 >= 2)
1960 {
1961 DPRINT1("Logical partition entry %lu\n", Index);
1962
1963 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
1964
1966 {
1967 DPRINT1("Wiping partition entry %lu\n", Index);
1968
1969 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
1970 PartitionInfo->StartingOffset.QuadPart = 0;
1971 PartitionInfo->PartitionLength.QuadPart = 0;
1972 PartitionInfo->Mbr.HiddenSectors = 0;
1973 PartitionInfo->PartitionNumber = 0;
1974 PartitionInfo->Mbr.PartitionType = PARTITION_ENTRY_UNUSED;
1975 PartitionInfo->Mbr.BootIndicator = FALSE;
1976 PartitionInfo->Mbr.RecognizedPartition = FALSE;
1977 PartitionInfo->RewritePartition = TRUE;
1978 }
1979 }
1980 }
1981
1982 DiskEntry->Dirty = TRUE;
1983}
ULONG PartitionIndex
Definition: partlist.h:76
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:1698
static BOOLEAN IsEmptyLayoutEntry(IN PPARTITION_INFORMATION_EX PartitionInfo)
Definition: partlist.c:1683
static BOOLEAN ReAllocateLayoutBuffer(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:1758
ULONG LowPart
Definition: typedefs.h:106
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2105
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061

◆ WritePartitions()

NTSTATUS WritePartitions ( _In_ PDISKENTRY  DiskEntry)

Definition at line 1558 of file partlist.c.

1560{
1568 ULONG PartitionCount;
1569 PLIST_ENTRY ListEntry;
1570 PPARTENTRY PartEntry;
1572
1573 DPRINT("WritePartitions() Disk: %lu\n", DiskEntry->DiskNumber);
1574
1575 /* If the disk is not dirty, there is nothing to do */
1576 if (!DiskEntry->Dirty)
1577 return STATUS_SUCCESS;
1578
1580 L"\\Device\\Harddisk%lu\\Partition0",
1581 DiskEntry->DiskNumber);
1583
1585 &Name,
1587 NULL,
1588 NULL);
1589
1593 &Iosb,
1594 0,
1596 if (!NT_SUCCESS(Status))
1597 {
1598 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
1599 return Status;
1600 }
1601
1602 //
1603 // FIXME: We first *MUST* use IOCTL_DISK_CREATE_DISK to initialize
1604 // the disk in MBR or GPT format in case the disk was not initialized!!
1605 // For this we must ask the user which format to use.
1606 //
1607
1608 /* Save the original partition count to be restored later (see comment below) */
1609 PartitionCount = DiskEntry->LayoutBuffer->PartitionCount;
1610
1611 /* Set the new disk layout and retrieve its updated version with possibly modified partition numbers */
1612 BufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
1613 ((PartitionCount - 1) * sizeof(PARTITION_INFORMATION_EX));
1615 NULL,
1616 NULL,
1617 NULL,
1618 &Iosb,
1620 DiskEntry->LayoutBuffer,
1621 BufferSize,
1622 DiskEntry->LayoutBuffer,
1623 BufferSize);
1625
1626 /*
1627 * IOCTL_DISK_SET_DRIVE_LAYOUT calls IoWritePartitionTable(), which converts
1628 * DiskEntry->LayoutBuffer->PartitionCount into a partition *table* count,
1629 * where such a table is expected to enumerate up to 4 partitions:
1630 * partition *table* count == ROUND_UP(PartitionCount, 4) / 4 .
1631 * Due to this we need to restore the original PartitionCount number.
1632 */
1633 DiskEntry->LayoutBuffer->PartitionCount = PartitionCount;
1634
1635 /* Check whether the IOCTL_DISK_SET_DRIVE_LAYOUT call succeeded */
1636 if (!NT_SUCCESS(Status))
1637 {
1638 DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT failed (Status 0x%08lx)\n", Status);
1639 return Status;
1640 }
1641
1642 /* Update the partition numbers */
1643
1644 /* Update the primary partition table */
1645 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
1646 ListEntry != &DiskEntry->PrimaryPartListHead;
1647 ListEntry = ListEntry->Flink)
1648 {
1649 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
1650
1651 if (PartEntry->IsPartitioned)
1652 {
1654 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
1655 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
1656 }
1657 }
1658
1659 /* Update the logical partition table */
1660 for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
1661 ListEntry != &DiskEntry->LogicalPartListHead;
1662 ListEntry = ListEntry->Flink)
1663 {
1664 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
1665
1666 if (PartEntry->IsPartitioned)
1667 {
1669 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
1670 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
1671 }
1672 }
1673
1674 /* The layout has been successfully updated, the disk is not dirty anymore */
1675 DiskEntry->Dirty = FALSE;
1676
1677 return Status;
1678}
#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

Variable Documentation

◆ BiosDiskListHead

LIST_ENTRY BiosDiskListHead
extern

◆ cmds

◆ CurrentDisk

◆ CurrentPartition

PPARTENTRY CurrentPartition
extern

Definition at line 77 of file partlist.c.

Referenced by CreatePartitionList(), and DestroyPartitionList().

◆ CurrentVolume

◆ DiskListHead

LIST_ENTRY DiskListHead
extern

◆ VolumeListHead