ReactOS 0.4.16-dev-456-ga97fcf1
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 <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)
 
BOOL convert_main (INT argc, LPWSTR *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)
 
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)
 
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 78 of file diskpart.h.

◆ MAX_STRING_SIZE

#define MAX_STRING_SIZE   1024

Definition at line 77 of file diskpart.h.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 39 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 81 of file diskpart.h.

82{
enum _FORMATSTATE FORMATSTATE
enum _FORMATSTATE * PFORMATSTATE
@ UnknownFormat
Definition: diskpart.h:85
@ Preformatted
Definition: diskpart.h:86
@ Formatted
Definition: diskpart.h:87
@ Unformatted
Definition: diskpart.h:83
@ UnformattedOrDamaged
Definition: diskpart.h:84

◆ _VOLUME_TYPE

Enumerator
VOLUME_TYPE_CDROM 
VOLUME_TYPE_PARTITION 
VOLUME_TYPE_REMOVABLE 
VOLUME_TYPE_UNKNOWN 

Definition at line 90 of file diskpart.h.

91{
@ VOLUME_TYPE_UNKNOWN
Definition: diskpart.h:95
@ VOLUME_TYPE_REMOVABLE
Definition: diskpart.h:94
@ VOLUME_TYPE_CDROM
Definition: diskpart.h:92
@ VOLUME_TYPE_PARTITION
Definition: diskpart.h:93
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 84 of file partlist.c.

87{
88 ULONGLONG Temp;
89
90 Temp = Value / Alignment;
91
92 return Temp * Alignment;
93}
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: ntvdm.h:50

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

◆ convert_main()

BOOL convert_main ( INT  argc,
LPWSTR argv 
)

Definition at line 11 of file convert.c.

12{
13 return TRUE;
14}

◆ 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
38 for (i = 3; i < argc; i++)
39 {
40 if (HasPrefix(argv[i], L"size=", &pszSuffix))
41 {
42 /* size=<N> (MB) */
43 DPRINT("Size : %s\n", pszSuffix);
44
45 ullSize = _wcstoui64(pszSuffix, NULL, 10);
46 if ((ullSize == 0) && (errno == ERANGE))
47 {
49 return TRUE;
50 }
51 }
52 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
53 {
54 /* offset=<N> (KB) */
55 DPRINT("Offset : %s\n", pszSuffix);
56 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
57#if 0
58 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
59 if ((ullOffset == 0) && (errno == ERANGE))
60 {
62 return TRUE;
63 }
64#endif
65 }
66 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
67 {
68 /* align=<N> */
69 DPRINT("Align : %s\n", pszSuffix);
70 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
71#if 0
72 bAlign = TRUE;
73#endif
74 }
75 else if (_wcsicmp(argv[i], L"noerr") == 0)
76 {
77 /* noerr */
78 DPRINT("NoErr\n", pszSuffix);
79 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
80#if 0
81 bNoErr = TRUE;
82#endif
83 }
84 else
85 {
87 return TRUE;
88 }
89 }
90
91 DPRINT1("Size: %I64u\n", ullSize);
92#if 0
93 DPRINT1("Offset: %I64u\n", ullOffset);
94#endif
95
97 {
98 ConPuts(StdOut, L"No space left for an extended partition!\n");
99 return TRUE;
100 }
101
103 {
104 ConPuts(StdOut, L"We already have an extended partition on this disk!\n");
105 return TRUE;
106 }
107
108 if (ullSize != 0)
109 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
110 else
111 ullSectorCount = 0;
112
113 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
114
116
117 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
118 if (PartEntry->IsPartitioned)
119 {
120 ConPuts(StdOut, L"No disk space left for an extended partition!\n");
121 return TRUE;
122 }
123
124 if (ullSectorCount == 0)
125 {
126 PartEntry->IsPartitioned = TRUE;
127 PartEntry->New = TRUE;
129 PartEntry->FormatState = Unformatted;
130 PartEntry->FileSystemName[0] = L'\0';
131
132 CurrentPartition = PartEntry;
134 }
135 else
136 {
137 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
138 {
139 PartEntry->IsPartitioned = TRUE;
140 PartEntry->New = TRUE;
142 PartEntry->FormatState = Unformatted;
143 PartEntry->FileSystemName[0] = L'\0';
144
145 CurrentPartition = PartEntry;
147 }
148 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
149 {
150 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
151 if (NewPartEntry == NULL)
152 {
153 ConPuts(StdOut, L"Memory allocation failed!\n");
154 return TRUE;
155 }
156
157 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
158
159 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
160 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
161
162 NewPartEntry->LogicalPartition = FALSE;
163 NewPartEntry->IsPartitioned = TRUE;
164 NewPartEntry->New = TRUE;
165 NewPartEntry->PartitionType = PARTITION_EXTENDED;
166 NewPartEntry->FormatState = Unformatted;
167 NewPartEntry->FileSystemName[0] = L'\0';
168
169 PartEntry->StartSector.QuadPart += ullSectorCount;
170 PartEntry->SectorCount.QuadPart -= ullSectorCount;
171
172 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
173
174 CurrentPartition = NewPartEntry;
176 }
177 }
178
181 if (!NT_SUCCESS(Status))
182 {
185 return TRUE;
186 }
187
189
190 return TRUE;
191}
static int argc
Definition: ServiceArgs.c:12
#define ERANGE
Definition: acclib.h:92
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define IDS_CREATE_PARTITION_FAIL
Definition: resource.h:29
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:189
#define IDS_SELECT_NO_DISK
Definition: resource.h:85
#define IDS_CREATE_PARTITION_SUCCESS
Definition: resource.h:30
#define PARTITION_EXTENDED
Definition: disk.h:92
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOL HasPrefix(_In_ PWSTR pszString, _In_ PWSTR pszPrefix, _Out_opt_ PWSTR *pszSuffix)
Definition: misc.c:58
PDISKENTRY CurrentDisk
Definition: partlist.c:76
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define InsertTailList(ListHead, Entry)
unsigned int BOOL
Definition: ntddk_ex.h:94
Status
Definition: gdiplustypes.h:25
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)
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:3590
#define DPRINT
Definition: sndvol32.h:73
PPARTENTRY ExtendedPartition
Definition: partlist.h:153
ULONG BytesPerSector
Definition: partlist.h:113
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:116
LIST_ENTRY ListEntry
Definition: partlist.h:63
ULARGE_INTEGER StartSector
Definition: partlist.h:69
CHAR FileSystemName[9]
Definition: diskpart.h:115
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
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:77
unsigned __int64 CDECL _wcstoui64(const wchar_t *nptr, wchar_t **endptr, int base)
Definition: wtoi64.c:200

◆ CreateLogicalPartition()

BOOL CreateLogicalPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 195 of file create.c.

198{
199 PPARTENTRY PartEntry, NewPartEntry;
200 PLIST_ENTRY ListEntry;
201 ULONGLONG ullSize = 0ULL;
202 ULONGLONG ullSectorCount;
203#if 0
204 ULONGLONG ullOffset = 0ULL;
205 BOOL bNoErr = FALSE;
206#endif
208 INT i, length;
209 PWSTR pszSuffix = NULL;
211
212 if (CurrentDisk == NULL)
213 {
215 return TRUE;
216 }
217
218 for (i = 3; i < argc; i++)
219 {
220 if (HasPrefix(argv[i], L"size=", &pszSuffix))
221 {
222 /* size=<N> (MB) */
223 DPRINT("Size : %s\n", pszSuffix);
224
225 ullSize = _wcstoui64(pszSuffix, NULL, 10);
226 if ((ullSize == 0) && (errno == ERANGE))
227 {
229 return TRUE;
230 }
231 }
232 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
233 {
234 /* offset=<N> (KB) */
235 DPRINT("Offset : %s\n", pszSuffix);
236 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
237#if 0
238 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
239 if ((ullOffset == 0) && (errno == ERANGE))
240 {
242 return TRUE;
243 }
244#endif
245 }
246 else if (HasPrefix(argv[i], L"id=", &pszSuffix))
247 {
248 /* id=<Byte>|<GUID> */
249 DPRINT("Id : %s\n", pszSuffix);
250
251 length = wcslen(pszSuffix);
252 if ((length == 1) || (length == 2))
253 {
254 /* Byte */
255 PartitionType = (UCHAR)wcstoul(pszSuffix, NULL, 16);
256 if ((PartitionType == 0) && (errno == ERANGE))
257 {
259 return TRUE;
260 }
261 }
262#if 0
263 else if ()
264 {
265 /* GUID */
266 }
267#endif
268 else
269 {
271 return TRUE;
272 }
273 }
274 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
275 {
276 /* align=<N> */
277 DPRINT("Align : %s\n", pszSuffix);
278 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
279#if 0
280 bAlign = TRUE;
281#endif
282 }
283 else if (_wcsicmp(argv[i], L"noerr") == 0)
284 {
285 /* noerr */
286 DPRINT("NoErr\n", pszSuffix);
287 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
288#if 0
289 bNoErr = TRUE;
290#endif
291 }
292 else
293 {
295 return TRUE;
296 }
297 }
298
299 DPRINT1("Size: %I64u\n", ullSize);
300#if 0
301 DPRINT1("Offset: %I64u\n", ullOffset);
302#endif
303 DPRINT1("Partition Type: %hx\n", PartitionType);
304
305 if (ullSize != 0)
306 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
307 else
308 ullSectorCount = 0;
309
310 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
311
312 for (ListEntry = CurrentDisk->LogicalPartListHead.Flink;
313 ListEntry != &CurrentDisk->LogicalPartListHead;
314 ListEntry = ListEntry->Flink)
315 {
316 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
317 if (PartEntry->IsPartitioned)
318 continue;
319
320 if (ullSectorCount == 0)
321 {
322 PartEntry->IsPartitioned = TRUE;
323 PartEntry->New = TRUE;
324 PartEntry->PartitionType = PartitionType;
325 PartEntry->FormatState = Unformatted;
326 PartEntry->FileSystemName[0] = L'\0';
327
328 CurrentPartition = PartEntry;
330 break;
331 }
332 else
333 {
334 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
335 {
336 PartEntry->IsPartitioned = TRUE;
337 PartEntry->New = TRUE;
338 PartEntry->PartitionType = PartitionType;
339 PartEntry->FormatState = Unformatted;
340 PartEntry->FileSystemName[0] = L'\0';
341
342 CurrentPartition = PartEntry;
344 break;
345 }
346 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
347 {
348 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
349 if (NewPartEntry == NULL)
350 {
351 ConPuts(StdOut, L"Memory allocation failed!\n");
352 return TRUE;
353 }
354
355 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
356
357 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
358 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
359
360 NewPartEntry->LogicalPartition = TRUE;
361 NewPartEntry->IsPartitioned = TRUE;
362 NewPartEntry->New = TRUE;
363 NewPartEntry->PartitionType = PartitionType;
364 NewPartEntry->FormatState = Unformatted;
365 NewPartEntry->FileSystemName[0] = L'\0';
366
367 PartEntry->StartSector.QuadPart += ullSectorCount;
368 PartEntry->SectorCount.QuadPart -= ullSectorCount;
369
370 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
371
372 CurrentPartition = NewPartEntry;
374 break;
375 }
376 }
377 }
378
381 if (!NT_SUCCESS(Status))
382 {
385 return TRUE;
386 }
387
389
390 return TRUE;
391}
#define PARTITION_HUGE
Definition: disk.h:93
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
CHAR PartitionType
Definition: part_xbox.c:32
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}
struct NameRec_ * Name
Definition: cdprocs.h:460
HANDLE ProcessHeap
Definition: servman.c:15
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define MAX_PATH
Definition: compat.h:34
#define FILE_SHARE_READ
Definition: compat.h:136
return Iosb
Definition: create.c:4402
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
@ SystemDeviceInformation
Definition: ntddk_ex.h:18
_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
struct _PARTLIST * PPARTLIST
#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 FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
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
__wchar_t WCHAR
Definition: xmlstorage.h:180

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

◆ CreatePrimaryPartition()

BOOL CreatePrimaryPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 395 of file create.c.

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

◆ CreateVolumeList()

NTSTATUS CreateVolumeList ( VOID  )

Definition at line 1414 of file partlist.c.

1415{
1416 HANDLE hVolume = INVALID_HANDLE_VALUE;
1417 WCHAR szVolumeName[MAX_PATH];
1418 ULONG ulVolumeNumber = 0;
1419 BOOL Success;
1420
1422
1424
1425 hVolume = FindFirstVolumeW(szVolumeName, ARRAYSIZE(szVolumeName));
1426 if (hVolume == INVALID_HANDLE_VALUE)
1427 {
1428
1429 return STATUS_UNSUCCESSFUL;
1430 }
1431
1432 AddVolumeToList(ulVolumeNumber++, szVolumeName);
1433
1434 for (;;)
1435 {
1436 Success = FindNextVolumeW(hVolume, szVolumeName, ARRAYSIZE(szVolumeName));
1437 if (!Success)
1438 {
1439 break;
1440 }
1441
1442 AddVolumeToList(ulVolumeNumber++, szVolumeName);
1443 }
1444
1445 FindVolumeClose(hVolume);
1446
1447 return STATUS_SUCCESS;
1448}
#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:1298
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:90
#define IDS_DELETE_PARTITION_SUCCESS
Definition: resource.h:33
#define IDS_DELETE_PARTITION_FAIL
Definition: resource.h:32
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:87
PPARTENTRY GetPrevUnpartitionedEntry(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:1903
PPARTENTRY GetNextUnpartitionedEntry(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:1932
#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:114
CHAR DriveLetter
Definition: diskpart.h:113
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 1133 of file partlist.c.

1134{
1135 PDISKENTRY DiskEntry;
1136 PBIOSDISKENTRY BiosDiskEntry;
1137 PPARTENTRY PartEntry;
1139
1140 CurrentDisk = NULL;
1142
1143 /* Release disk and partition info */
1144 while (!IsListEmpty(&DiskListHead))
1145 {
1147 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
1148
1149 /* Release driver name */
1150 RtlFreeUnicodeString(&DiskEntry->DriverName);
1151
1152 /* Release primary partition list */
1153 while (!IsListEmpty(&DiskEntry->PrimaryPartListHead))
1154 {
1156 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1157
1158 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1159 }
1160
1161 /* Release logical partition list */
1162 while (!IsListEmpty(&DiskEntry->LogicalPartListHead))
1163 {
1165 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1166
1167 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1168 }
1169
1170 /* Release layout buffer */
1171 if (DiskEntry->LayoutBuffer != NULL)
1172 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry->LayoutBuffer);
1173
1174
1175 /* Release disk entry */
1176 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry);
1177 }
1178
1179 /* Release the bios disk info */
1180 while (!IsListEmpty(&BiosDiskListHead))
1181 {
1183 BiosDiskEntry = CONTAINING_RECORD(Entry, BIOSDISKENTRY, ListEntry);
1184
1185 RtlFreeHeap(RtlGetProcessHeap(), 0, BiosDiskEntry);
1186 }
1187}
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
UNICODE_STRING DriverName
Definition: partlist.h:141
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:143
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 1452 of file partlist.c.

1453{
1455 PVOLENTRY VolumeEntry;
1456
1458
1459 /* Release disk and partition info */
1460 while (!IsListEmpty(&VolumeListHead))
1461 {
1463 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
1464
1465 if (VolumeEntry->pszLabel)
1466 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
1467
1468 if (VolumeEntry->pszFilesystem)
1469 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
1470
1471 if (VolumeEntry->pExtents)
1472 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pExtents);
1473
1474 /* Release disk entry */
1475 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
1476 }
1477}
PVOLUME_DISK_EXTENTS pExtents
Definition: diskpart.h:204
PWSTR pszFilesystem
Definition: diskpart.h:200
PWSTR pszLabel
Definition: diskpart.h:199

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

1962{
1964 NTSTATUS LockStatus;
1968 HANDLE PartitionHandle;
1970
1971 /* Check whether the partition is valid and was mounted by the system */
1972 if (!PartEntry->IsPartitioned ||
1973 IsContainerPartition(PartEntry->PartitionType) ||
1974 !IsRecognizedPartition(PartEntry->PartitionType) ||
1975 PartEntry->FormatState == UnknownFormat ||
1976 // NOTE: If FormatState == Unformatted but *FileSystem != 0 this means
1977 // it has been usually mounted with RawFS and thus needs to be dismounted.
1978/* !*PartEntry->FileSystem || */
1979 PartEntry->PartitionNumber == 0)
1980 {
1981 /* The partition is not mounted, so just return success */
1982 return STATUS_SUCCESS;
1983 }
1984
1985 ASSERT(PartEntry->PartitionType != PARTITION_ENTRY_UNUSED);
1986
1987 /* Open the volume */
1989 L"\\Device\\Harddisk%lu\\Partition%lu",
1990 PartEntry->DiskEntry->DiskNumber,
1991 PartEntry->PartitionNumber);
1993
1995 &Name,
1997 NULL,
1998 NULL);
1999
2000 Status = NtOpenFile(&PartitionHandle,
2006 if (!NT_SUCCESS(Status))
2007 {
2008 DPRINT1("ERROR: Cannot open volume %wZ for dismounting! (Status 0x%lx)\n", &Name, Status);
2009 return Status;
2010 }
2011
2012 /* Lock the volume */
2013 LockStatus = NtFsControlFile(PartitionHandle,
2014 NULL,
2015 NULL,
2016 NULL,
2019 NULL,
2020 0,
2021 NULL,
2022 0);
2023 if (!NT_SUCCESS(LockStatus))
2024 {
2025 DPRINT1("WARNING: Failed to lock volume! Operations may fail! (Status 0x%lx)\n", LockStatus);
2026 }
2027
2028 /* Dismount the volume */
2029 Status = NtFsControlFile(PartitionHandle,
2030 NULL,
2031 NULL,
2032 NULL,
2035 NULL,
2036 0,
2037 NULL,
2038 0);
2039 if (!NT_SUCCESS(Status))
2040 {
2041 DPRINT1("Failed to unmount volume (Status 0x%lx)\n", Status);
2042 }
2043
2044 /* Unlock the volume */
2045 LockStatus = NtFsControlFile(PartitionHandle,
2046 NULL,
2047 NULL,
2048 NULL,
2051 NULL,
2052 0,
2053 NULL,
2054 0);
2055 if (!NT_SUCCESS(LockStatus))
2056 {
2057 DPRINT1("Failed to unlock volume (Status 0x%lx)\n", LockStatus);
2058 }
2059
2060 /* Close the volume */
2061 NtClose(PartitionHandle);
2062
2063 return Status;
2064}
#define GENERIC_READ
Definition: compat.h:135
@ UnknownFormat
Definition: partlist.h:36
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#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
#define GENERIC_WRITE
Definition: nt_native.h:90
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
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530

◆ 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)
ULONG DiskNumber
Definition: partlist.h:129
int64_t LONGLONG
Definition: typedefs.h:68
unsigned char * PUCHAR
Definition: typedefs.h:53
__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}
#define wcschr
Definition: compat.h:17
#define UNICODE_NULL
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
_In_ DWORD nLength
Definition: wincon.h:473

◆ 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}
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)

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

1934{
1935 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
1936 PPARTENTRY NextPartEntry;
1937 PLIST_ENTRY ListHead;
1938
1939 if (PartEntry->LogicalPartition)
1940 ListHead = &DiskEntry->LogicalPartListHead;
1941 else
1942 ListHead = &DiskEntry->PrimaryPartListHead;
1943
1944 if (PartEntry->ListEntry.Flink != ListHead)
1945 {
1946 NextPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Flink,
1947 PARTENTRY,
1948 ListEntry);
1949 if (!NextPartEntry->IsPartitioned)
1950 {
1951 ASSERT(NextPartEntry->PartitionType == PARTITION_ENTRY_UNUSED);
1952 return NextPartEntry;
1953 }
1954 }
1955
1956 return NULL;
1957}

Referenced by DeletePartition().

◆ GetPrevUnpartitionedEntry()

PPARTENTRY GetPrevUnpartitionedEntry ( _In_ PPARTENTRY  PartEntry)

Definition at line 1903 of file partlist.c.

1905{
1906 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
1907 PPARTENTRY PrevPartEntry;
1908 PLIST_ENTRY ListHead;
1909
1910 if (PartEntry->LogicalPartition)
1911 ListHead = &DiskEntry->LogicalPartListHead;
1912 else
1913 ListHead = &DiskEntry->PrimaryPartListHead;
1914
1915 if (PartEntry->ListEntry.Blink != ListHead)
1916 {
1917 PrevPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Blink,
1918 PARTENTRY,
1919 ListEntry);
1920 if (!PrevPartEntry->IsPartitioned)
1921 {
1922 ASSERT(PrevPartEntry->PartitionType == PARTITION_ENTRY_UNUSED);
1923 return PrevPartEntry;
1924 }
1925 }
1926
1927 return NULL;
1928}

Referenced by DeletePartition().

◆ GetPrimaryPartitionCount()

ULONG GetPrimaryPartitionCount ( _In_ PDISKENTRY  DiskEntry)

Definition at line 1637 of file partlist.c.

1639{
1641 PPARTENTRY PartEntry;
1642 ULONG Count = 0;
1643
1644 for (Entry = DiskEntry->PrimaryPartListHead.Flink;
1645 Entry != &DiskEntry->PrimaryPartListHead;
1646 Entry = Entry->Flink)
1647 {
1648 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1649 if (PartEntry->IsPartitioned)
1650 Count++;
1651 }
1652
1653 return Count;
1654}
int Count
Definition: noreturn.cpp:7

◆ GetVolumeFromPartition()

PVOLENTRY GetVolumeFromPartition ( _In_ PPARTENTRY  PartEntry)

Definition at line 2068 of file partlist.c.

2070{
2072 PVOLENTRY VolumeEntry;
2073 ULONG i;
2074
2075 if ((PartEntry == NULL) ||
2076 (PartEntry->DiskEntry == NULL))
2077 return NULL;
2078
2080 while (Entry != &VolumeListHead)
2081 {
2082 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
2083
2084 if (VolumeEntry->pExtents == NULL)
2085 return NULL;
2086
2087 for (i = 0; i < VolumeEntry->pExtents->NumberOfDiskExtents; i++)
2088 {
2089 if (VolumeEntry->pExtents->Extents[i].DiskNumber == PartEntry->DiskEntry->DiskNumber)
2090 {
2091 if ((VolumeEntry->pExtents->Extents[i].StartingOffset.QuadPart == PartEntry->StartSector.QuadPart * PartEntry->DiskEntry->BytesPerSector) &&
2092 (VolumeEntry->pExtents->Extents[i].ExtentLength.QuadPart == PartEntry->SectorCount.QuadPart * PartEntry->DiskEntry->BytesPerSector))
2093 return VolumeEntry;
2094 }
2095 }
2096
2097 Entry = Entry->Flink;
2098 }
2099
2100 return NULL;
2101}
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}
_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)
int ret
_In_ DWORD _In_ DWORD _Out_writes_to_opt_ pcchString LPSTR pszString
Definition: wincrypt.h:4505

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:61
PWSTR cmd2
Definition: diskpart.h:60
PWSTR cmd1
Definition: diskpart.h:59

◆ 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:133
#define MSG_NONE
Definition: resource.h:12
#define IDS_HELP_FORMAT_STRING
Definition: resource.h:64
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:63
DWORD help_detail
Definition: diskpart.h:64
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define GetModuleHandle
Definition: winbase.h:3852
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:448

◆ 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 231 of file interpreter.c.

232{
233 WCHAR input_line[MAX_STRING_SIZE];
234 LPWSTR args_vector[MAX_ARGS_COUNT];
235 INT args_count = 0;
236 BOOL bWhiteSpace = TRUE;
237 BOOL bQuote = FALSE;
238 BOOL bRun = TRUE;
239 LPWSTR ptr;
240
241 while (bRun != FALSE)
242 {
243 args_count = 0;
244 memset(args_vector, 0, sizeof(args_vector));
245
246 /* Shown just before the input where the user places commands */
248
249 /* Get input from the user. */
250 fgetws(input_line, MAX_STRING_SIZE, stdin);
251
252 bQuote = FALSE;
253 ptr = input_line;
254 while (*ptr != 0)
255 {
256 if (*ptr == L'"')
257 bQuote = !bQuote;
258
259 if ((iswspace(*ptr) && (bQuote == FALSE))|| *ptr == L'\n')
260 {
261 *ptr = 0;
262 bWhiteSpace = TRUE;
263 }
264 else
265 {
266 if ((bWhiteSpace != FALSE) && (bQuote == FALSE) && (args_count < MAX_ARGS_COUNT))
267 {
268 args_vector[args_count] = ptr;
269 args_count++;
270 }
271 bWhiteSpace = FALSE;
272 }
273 ptr++;
274 }
275
276 /* Send the string to find the command */
277 bRun = InterpretCmd(args_count, args_vector);
278 }
279}
#define MAX_STRING_SIZE
Definition: precomp.h:34
#define MAX_ARGS_COUNT
Definition: precomp.h:35
#define IDS_APP_PROMPT
Definition: resource.h:13
#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
BOOL InterpretCmd(int argc, LPWSTR *argv)
Definition: interpreter.c:108
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 183 of file interpreter.c.

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

◆ 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:72
#define IDS_LIST_DISK_HEAD
Definition: resource.h:71
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:77
#define IDS_LIST_PARTITION_HEAD
Definition: resource.h:74
#define IDS_LIST_PARTITION_LINE
Definition: resource.h:75
#define IDS_LIST_PARTITION_FORMAT
Definition: resource.h:76
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:79
#define IDS_LIST_VOLUME_HEAD
Definition: resource.h:78
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 L" ");
55}
#define IDS_LIST_DISK_FORMAT
Definition: resource.h:73
if(dx< 0)
Definition: linetemp.h:194

Referenced by DetailVolume(), and ListDisk().

◆ 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:80
PVOLENTRY CurrentVolume
Definition: partlist.c:78

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

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

2107{
2108 if (VolumeEntry == NULL)
2109 return;
2110
2111 if (VolumeEntry == CurrentVolume)
2113
2114 RemoveEntryList(&VolumeEntry->ListEntry);
2115
2116 if (VolumeEntry->pszLabel)
2117 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
2118
2119 if (VolumeEntry->pszFilesystem)
2120 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
2121
2122 if (VolumeEntry->pExtents)
2123 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pExtents);
2124
2125 /* Release disk entry */
2126 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
2127}

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:82
#define IDS_RESCAN_END
Definition: resource.h:83
VOID DestroyVolumeList(VOID)
Definition: partlist.c:1452
NTSTATUS CreateVolumeList(VOID)
Definition: partlist.c:1414
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:87
#define IDS_SELECT_DISK_ENUM_NO_START
Definition: resource.h:88
#define IDS_SELECT_DISK
Definition: resource.h:86
#define IDS_SELECT_DISK_ENUM_FINISHED
Definition: resource.h:89
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:92
#define IDS_SELECT_PARTITION_INVALID
Definition: resource.h:93
#define IDS_SELECT_PARTITION
Definition: resource.h:91

◆ 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:94
#define IDS_SELECT_VOLUME
Definition: resource.h:95
#define IDS_SELECT_VOLUME_INVALID
Definition: resource.h:96
ULONG VolumeNumber
Definition: diskpart.h:193

◆ 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 PWSTR pszSuffix = NULL;
22 ULONG ulValue;
23
24 if (CurrentDisk == NULL)
25 {
27 return TRUE;
28 }
29
30 if (argc == 2)
31 {
32 ConPuts(StdOut, L"\n");
33 ConPrintf(StdOut, L"Disk ID: %08lx\n", CurrentDisk->LayoutBuffer->Signature);
34 ConPuts(StdOut, L"\n");
35 return TRUE;
36 }
37
38 if (argc != 3)
39 {
41 return TRUE;
42 }
43
44 if (!HasPrefix(argv[2], L"ID=", &pszSuffix))
45 {
47 return TRUE;
48 }
49
50 if ((pszSuffix == NULL) ||
51 (wcslen(pszSuffix) != 8) ||
52 (IsHexString(pszSuffix) == FALSE))
53 {
55 return TRUE;
56 }
57
58 ulValue = wcstoul(pszSuffix, NULL, 16);
59 if ((ulValue == 0) && (errno == ERANGE))
60 {
62 return TRUE;
63 }
64
65 DPRINT("New Signature: 0x%08lx\n", ulValue);
70
71 return TRUE;
72}
BOOL IsHexString(_In_ PWSTR pszHexString)
Definition: misc.c:36

◆ UpdateDiskLayout()

VOID UpdateDiskLayout ( _In_ PDISKENTRY  DiskEntry)

Definition at line 1733 of file partlist.c.

1735{
1737 PPARTITION_INFORMATION LinkInfo = NULL;
1738 PLIST_ENTRY ListEntry;
1739 PPARTENTRY PartEntry;
1740 LARGE_INTEGER HiddenSectors64;
1741 ULONG Index;
1743
1744 DPRINT1("UpdateDiskLayout()\n");
1745
1746 /* Resize the layout buffer if necessary */
1747 if (ReAllocateLayoutBuffer(DiskEntry) == FALSE)
1748 {
1749 DPRINT("ReAllocateLayoutBuffer() failed.\n");
1750 return;
1751 }
1752
1753 /* Update the primary partition table */
1754 Index = 0;
1755 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
1756 ListEntry != &DiskEntry->PrimaryPartListHead;
1757 ListEntry = ListEntry->Flink)
1758 {
1759 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
1760
1761 if (PartEntry->IsPartitioned)
1762 {
1764
1765 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
1766 PartEntry->PartitionIndex = Index;
1767
1768 /* Reset the current partition number only for newly-created (unmounted) partitions */
1769 if (PartEntry->New)
1770 PartEntry->PartitionNumber = 0;
1771
1773
1774 if (!IsSamePrimaryLayoutEntry(PartitionInfo, DiskEntry, PartEntry))
1775 {
1776 DPRINT1("Updating primary partition entry %lu\n", Index);
1777
1778 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
1779 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
1780 PartitionInfo->HiddenSectors = PartEntry->StartSector.LowPart;
1781 PartitionInfo->PartitionNumber = PartEntry->PartitionNumber;
1782 PartitionInfo->PartitionType = PartEntry->PartitionType;
1783 PartitionInfo->BootIndicator = PartEntry->BootIndicator;
1784 PartitionInfo->RecognizedPartition = IsRecognizedPartition(PartEntry->PartitionType);
1785 PartitionInfo->RewritePartition = TRUE;
1786 }
1787
1788 if (!IsContainerPartition(PartEntry->PartitionType))
1790
1791 Index++;
1792 }
1793 }
1794
1795 ASSERT(Index <= 4);
1796
1797 /* Update the logical partition table */
1798 Index = 4;
1799 for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
1800 ListEntry != &DiskEntry->LogicalPartListHead;
1801 ListEntry = ListEntry->Flink)
1802 {
1803 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
1804
1805 if (PartEntry->IsPartitioned)
1806 {
1808
1809 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
1810 PartEntry->PartitionIndex = Index;
1811
1812 /* Reset the current partition number only for newly-created (unmounted) partitions */
1813 if (PartEntry->New)
1814 PartEntry->PartitionNumber = 0;
1815
1817
1818 DPRINT1("Updating logical partition entry %lu\n", Index);
1819
1820 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
1821 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
1822 PartitionInfo->HiddenSectors = DiskEntry->SectorAlignment;
1823 PartitionInfo->PartitionNumber = PartEntry->PartitionNumber;
1824 PartitionInfo->PartitionType = PartEntry->PartitionType;
1825 PartitionInfo->BootIndicator = FALSE;
1826 PartitionInfo->RecognizedPartition = IsRecognizedPartition(PartEntry->PartitionType);
1827 PartitionInfo->RewritePartition = TRUE;
1828
1829 /* Fill the link entry of the previous partition entry */
1830 if (LinkInfo != NULL)
1831 {
1832 LinkInfo->StartingOffset.QuadPart = (PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector;
1833 LinkInfo->PartitionLength.QuadPart = (PartEntry->StartSector.QuadPart + DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector;
1834 HiddenSectors64.QuadPart = PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment - DiskEntry->ExtendedPartition->StartSector.QuadPart;
1835 LinkInfo->HiddenSectors = HiddenSectors64.LowPart;
1836 LinkInfo->PartitionNumber = 0;
1838 LinkInfo->BootIndicator = FALSE;
1839 LinkInfo->RecognizedPartition = FALSE;
1840 LinkInfo->RewritePartition = TRUE;
1841 }
1842
1843 /* Save a pointer to the link entry of the current partition entry */
1844 LinkInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index + 1];
1845
1847 Index += 4;
1848 }
1849 }
1850
1851 /* Wipe unused primary partition entries */
1852 for (Index = GetPrimaryPartitionCount(DiskEntry); Index < 4; Index++)
1853 {
1854 DPRINT1("Primary partition entry %lu\n", Index);
1855
1856 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
1857
1859 {
1860 DPRINT1("Wiping primary partition entry %lu\n", Index);
1861
1862 PartitionInfo->StartingOffset.QuadPart = 0;
1863 PartitionInfo->PartitionLength.QuadPart = 0;
1864 PartitionInfo->HiddenSectors = 0;
1865 PartitionInfo->PartitionNumber = 0;
1866 PartitionInfo->PartitionType = PARTITION_ENTRY_UNUSED;
1867 PartitionInfo->BootIndicator = FALSE;
1868 PartitionInfo->RecognizedPartition = FALSE;
1869 PartitionInfo->RewritePartition = TRUE;
1870 }
1871 }
1872
1873 /* Wipe unused logical partition entries */
1874 for (Index = 4; Index < DiskEntry->LayoutBuffer->PartitionCount; Index++)
1875 {
1876 if (Index % 4 >= 2)
1877 {
1878 DPRINT1("Logical partition entry %lu\n", Index);
1879
1880 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
1881
1883 {
1884 DPRINT1("Wiping partition entry %lu\n", Index);
1885
1886 PartitionInfo->StartingOffset.QuadPart = 0;
1887 PartitionInfo->PartitionLength.QuadPart = 0;
1888 PartitionInfo->HiddenSectors = 0;
1889 PartitionInfo->PartitionNumber = 0;
1890 PartitionInfo->PartitionType = PARTITION_ENTRY_UNUSED;
1891 PartitionInfo->BootIndicator = FALSE;
1892 PartitionInfo->RecognizedPartition = FALSE;
1893 PartitionInfo->RewritePartition = TRUE;
1894 }
1895 }
1896 }
1897
1898 DiskEntry->Dirty = TRUE;
1899}
ULONG PartitionIndex
Definition: partlist.h:76
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:408
LARGE_INTEGER PartitionLength
Definition: ntdddisk.h:409
BOOLEAN RecognizedPartition
Definition: ntdddisk.h:414
BOOLEAN RewritePartition
Definition: ntdddisk.h:415
$ULONG LowPart
Definition: ntbasedef.h:577
static BOOLEAN IsSamePrimaryLayoutEntry(IN PPARTITION_INFORMATION PartitionInfo, IN PDISKENTRY DiskEntry, IN PPARTENTRY PartEntry)
Definition: partlist.c:1621
static BOOLEAN IsEmptyLayoutEntry(IN PPARTITION_INFORMATION PartitionInfo)
Definition: partlist.c:1606
static BOOLEAN ReAllocateLayoutBuffer(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:1681
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 1481 of file partlist.c.

1483{
1491 ULONG PartitionCount;
1492 PLIST_ENTRY ListEntry;
1493 PPARTENTRY PartEntry;
1495
1496 DPRINT("WritePartitions() Disk: %lu\n", DiskEntry->DiskNumber);
1497
1498 /* If the disk is not dirty, there is nothing to do */
1499 if (!DiskEntry->Dirty)
1500 return STATUS_SUCCESS;
1501
1503 L"\\Device\\Harddisk%lu\\Partition0",
1504 DiskEntry->DiskNumber);
1506
1508 &Name,
1510 NULL,
1511 NULL);
1512
1516 &Iosb,
1517 0,
1519 if (!NT_SUCCESS(Status))
1520 {
1521 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
1522 return Status;
1523 }
1524
1525 //
1526 // FIXME: We first *MUST* use IOCTL_DISK_CREATE_DISK to initialize
1527 // the disk in MBR or GPT format in case the disk was not initialized!!
1528 // For this we must ask the user which format to use.
1529 //
1530
1531 /* Save the original partition count to be restored later (see comment below) */
1532 PartitionCount = DiskEntry->LayoutBuffer->PartitionCount;
1533
1534 /* Set the new disk layout and retrieve its updated version with possibly modified partition numbers */
1536 ((PartitionCount - 1) * sizeof(PARTITION_INFORMATION));
1538 NULL,
1539 NULL,
1540 NULL,
1541 &Iosb,
1543 DiskEntry->LayoutBuffer,
1544 BufferSize,
1545 DiskEntry->LayoutBuffer,
1546 BufferSize);
1548
1549 /*
1550 * IOCTL_DISK_SET_DRIVE_LAYOUT calls IoWritePartitionTable(), which converts
1551 * DiskEntry->LayoutBuffer->PartitionCount into a partition *table* count,
1552 * where such a table is expected to enumerate up to 4 partitions:
1553 * partition *table* count == ROUND_UP(PartitionCount, 4) / 4 .
1554 * Due to this we need to restore the original PartitionCount number.
1555 */
1556 DiskEntry->LayoutBuffer->PartitionCount = PartitionCount;
1557
1558 /* Check whether the IOCTL_DISK_SET_DRIVE_LAYOUT call succeeded */
1559 if (!NT_SUCCESS(Status))
1560 {
1561 DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT failed (Status 0x%08lx)\n", Status);
1562 return Status;
1563 }
1564
1565 /* Update the partition numbers */
1566
1567 /* Update the primary partition table */
1568 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
1569 ListEntry != &DiskEntry->PrimaryPartListHead;
1570 ListEntry = ListEntry->Flink)
1571 {
1572 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
1573
1574 if (PartEntry->IsPartitioned)
1575 {
1577 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
1578 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
1579 }
1580 }
1581
1582 /* Update the logical partition table */
1583 for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
1584 ListEntry != &DiskEntry->LogicalPartListHead;
1585 ListEntry = ListEntry->Flink)
1586 {
1587 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
1588
1589 if (PartEntry->IsPartitioned)
1590 {
1592 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
1593 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
1594 }
1595 }
1596
1597 /* The layout has been successfully updated, the disk is not dirty anymore */
1598 DiskEntry->Dirty = FALSE;
1599
1600 return Status;
1601}
#define BufferSize
Definition: mmc.h:75
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)
#define IOCTL_DISK_SET_DRIVE_LAYOUT
Definition: ntdddisk.h:205
struct _PARTITION_INFORMATION PARTITION_INFORMATION
struct _DRIVE_LAYOUT_INFORMATION DRIVE_LAYOUT_INFORMATION
IN HANDLE DstPath
Definition: fsutil.h:81
_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