ReactOS 0.4.16-dev-125-g798ea90
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 82 of file partlist.c.

85{
86 ULONGLONG Temp;
87
88 Temp = Value / Alignment;
89
90 return Temp * Alignment;
91}
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:187
#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:74
#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:2523
#define GetPrimaryPartitionCount(DiskEntry)
Definition: partlist.c:2461
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3525
#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:78
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 1925 of file partlist.c.

1926{
1928 PDISKENTRY SystemDisk;
1932 ULONG ReturnSize;
1934 ULONG DiskNumber;
1938
1940 0,
1941 sizeof(PARTLIST));
1942 if (!List)
1943 return NULL;
1944
1945 List->SystemPartition = NULL;
1946
1947 InitializeListHead(&List->DiskListHead);
1948 InitializeListHead(&List->BiosDiskListHead);
1949 InitializeListHead(&List->VolumesList);
1950
1951 /*
1952 * Enumerate the disks seen by the BIOS; this will be used later
1953 * to map drives seen by NTOS with their corresponding BIOS names.
1954 */
1956
1957 /* Enumerate disks seen by NTOS */
1959 &Sdi,
1960 sizeof(Sdi),
1961 &ReturnSize);
1962 if (!NT_SUCCESS(Status))
1963 {
1964 DPRINT1("NtQuerySystemInformation() failed, Status 0x%08lx\n", Status);
1966 return NULL;
1967 }
1968
1969 for (DiskNumber = 0; DiskNumber < Sdi.NumberOfDisks; DiskNumber++)
1970 {
1972 L"\\Device\\Harddisk%lu\\Partition0",
1973 DiskNumber);
1975
1977 &Name,
1979 NULL,
1980 NULL);
1981
1985 &Iosb,
1988 if (NT_SUCCESS(Status))
1989 {
1990 AddDiskToList(FileHandle, DiskNumber, List);
1992 }
1993 }
1994
1998
1999 /*
2000 * Retrieve the system partition: the active partition on the system
2001 * disk (the one that will be booted by default by the hardware).
2002 */
2003 SystemDisk = GetSystemDisk(List);
2004 List->SystemPartition = (SystemDisk ? GetActiveDiskPartition(SystemDisk) : NULL);
2005
2006 return List;
2007}
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:3952
#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:1795
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:1383
static VOID UpdateDiskSignatures(IN PPARTLIST List)
Definition: partlist.c:1292
static VOID EnumerateBiosDiskEntries(IN PPARTLIST PartList)
Definition: partlist.c:327
static PPARTENTRY GetActiveDiskPartition(IN PDISKENTRY DiskEntry)
Definition: partlist.c:1868
static VOID UpdateHwDiskNumbers(IN PPARTLIST List)
Definition: partlist.c:1322
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 1412 of file partlist.c.

1413{
1414 HANDLE hVolume = INVALID_HANDLE_VALUE;
1415 WCHAR szVolumeName[MAX_PATH];
1416 ULONG ulVolumeNumber = 0;
1417 BOOL Success;
1418
1420
1422
1423 hVolume = FindFirstVolumeW(szVolumeName, ARRAYSIZE(szVolumeName));
1424 if (hVolume == INVALID_HANDLE_VALUE)
1425 {
1426
1427 return STATUS_UNSUCCESSFUL;
1428 }
1429
1430 AddVolumeToList(ulVolumeNumber++, szVolumeName);
1431
1432 for (;;)
1433 {
1434 Success = FindNextVolumeW(hVolume, szVolumeName, ARRAYSIZE(szVolumeName));
1435 if (!Success)
1436 {
1437 break;
1438 }
1439
1440 AddVolumeToList(ulVolumeNumber++, szVolumeName);
1441 }
1442
1443 FindVolumeClose(hVolume);
1444
1445 return STATUS_SUCCESS;
1446}
#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:72
static VOID AddVolumeToList(ULONG ulVolumeNumber, PWSTR pszVolumeName)
Definition: partlist.c:1296
PVOLENTRY CurrentVolume
Definition: partlist.c:76
#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 /* noerr */
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:88
#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:1901
PPARTENTRY GetNextUnpartitionedEntry(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:1930
#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 1131 of file partlist.c.

1132{
1133 PDISKENTRY DiskEntry;
1134 PBIOSDISKENTRY BiosDiskEntry;
1135 PPARTENTRY PartEntry;
1137
1138 CurrentDisk = NULL;
1140
1141 /* Release disk and partition info */
1142 while (!IsListEmpty(&DiskListHead))
1143 {
1145 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
1146
1147 /* Release driver name */
1148 RtlFreeUnicodeString(&DiskEntry->DriverName);
1149
1150 /* Release primary partition list */
1151 while (!IsListEmpty(&DiskEntry->PrimaryPartListHead))
1152 {
1154 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1155
1156 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1157 }
1158
1159 /* Release logical partition list */
1160 while (!IsListEmpty(&DiskEntry->LogicalPartListHead))
1161 {
1163 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1164
1165 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1166 }
1167
1168 /* Release layout buffer */
1169 if (DiskEntry->LayoutBuffer != NULL)
1170 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry->LayoutBuffer);
1171
1172
1173 /* Release disk entry */
1174 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry);
1175 }
1176
1177 /* Release the bios disk info */
1178 while (!IsListEmpty(&BiosDiskListHead))
1179 {
1181 BiosDiskEntry = CONTAINING_RECORD(Entry, BIOSDISKENTRY, ListEntry);
1182
1183 RtlFreeHeap(RtlGetProcessHeap(), 0, BiosDiskEntry);
1184 }
1185}
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:71
LIST_ENTRY DiskListHead
Definition: partlist.c:70
PPARTENTRY CurrentPartition
Definition: partlist.c:75

◆ DestroyVolumeList()

VOID DestroyVolumeList ( VOID  )

Definition at line 1450 of file partlist.c.

1451{
1453 PVOLENTRY VolumeEntry;
1454
1456
1457 /* Release disk and partition info */
1458 while (!IsListEmpty(&VolumeListHead))
1459 {
1461 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
1462
1463 if (VolumeEntry->pszLabel)
1464 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
1465
1466 if (VolumeEntry->pszFilesystem)
1467 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
1468
1469 if (VolumeEntry->pExtents)
1470 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pExtents);
1471
1472 /* Release disk entry */
1473 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
1474 }
1475}
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 1958 of file partlist.c.

1960{
1962 NTSTATUS LockStatus;
1966 HANDLE PartitionHandle;
1968
1969 /* Check whether the partition is valid and was mounted by the system */
1970 if (!PartEntry->IsPartitioned ||
1971 IsContainerPartition(PartEntry->PartitionType) ||
1972 !IsRecognizedPartition(PartEntry->PartitionType) ||
1973 PartEntry->FormatState == UnknownFormat ||
1974 // NOTE: If FormatState == Unformatted but *FileSystem != 0 this means
1975 // it has been usually mounted with RawFS and thus needs to be dismounted.
1976/* !*PartEntry->FileSystem || */
1977 PartEntry->PartitionNumber == 0)
1978 {
1979 /* The partition is not mounted, so just return success */
1980 return STATUS_SUCCESS;
1981 }
1982
1983 ASSERT(PartEntry->PartitionType != PARTITION_ENTRY_UNUSED);
1984
1985 /* Open the volume */
1987 L"\\Device\\Harddisk%lu\\Partition%lu",
1988 PartEntry->DiskEntry->DiskNumber,
1989 PartEntry->PartitionNumber);
1991
1993 &Name,
1995 NULL,
1996 NULL);
1997
1998 Status = NtOpenFile(&PartitionHandle,
2004 if (!NT_SUCCESS(Status))
2005 {
2006 DPRINT1("ERROR: Cannot open volume %wZ for dismounting! (Status 0x%lx)\n", &Name, Status);
2007 return Status;
2008 }
2009
2010 /* Lock the volume */
2011 LockStatus = NtFsControlFile(PartitionHandle,
2012 NULL,
2013 NULL,
2014 NULL,
2017 NULL,
2018 0,
2019 NULL,
2020 0);
2021 if (!NT_SUCCESS(LockStatus))
2022 {
2023 DPRINT1("WARNING: Failed to lock volume! Operations may fail! (Status 0x%lx)\n", LockStatus);
2024 }
2025
2026 /* Dismount the volume */
2027 Status = NtFsControlFile(PartitionHandle,
2028 NULL,
2029 NULL,
2030 NULL,
2033 NULL,
2034 0,
2035 NULL,
2036 0);
2037 if (!NT_SUCCESS(Status))
2038 {
2039 DPRINT1("Failed to unmount volume (Status 0x%lx)\n", Status);
2040 }
2041
2042 /* Unlock the volume */
2043 LockStatus = NtFsControlFile(PartitionHandle,
2044 NULL,
2045 NULL,
2046 NULL,
2049 NULL,
2050 0,
2051 NULL,
2052 0);
2053 if (!NT_SUCCESS(LockStatus))
2054 {
2055 DPRINT1("Failed to unlock volume (Status 0x%lx)\n", LockStatus);
2056 }
2057
2058 /* Close the volume */
2059 NtClose(PartitionHandle);
2060
2061 return Status;
2062}
#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 1930 of file partlist.c.

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

Referenced by DeletePartition().

◆ GetPrevUnpartitionedEntry()

PPARTENTRY GetPrevUnpartitionedEntry ( _In_ PPARTENTRY  PartEntry)

Definition at line 1901 of file partlist.c.

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

Referenced by DeletePartition().

◆ GetPrimaryPartitionCount()

ULONG GetPrimaryPartitionCount ( _In_ PDISKENTRY  DiskEntry)

Definition at line 1635 of file partlist.c.

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

◆ GetVolumeFromPartition()

PVOLENTRY GetVolumeFromPartition ( _In_ PPARTENTRY  PartEntry)

Definition at line 2066 of file partlist.c.

2068{
2070 PVOLENTRY VolumeEntry;
2071 ULONG i;
2072
2073 if ((PartEntry == NULL) ||
2074 (PartEntry->DiskEntry == NULL))
2075 return NULL;
2076
2078 while (Entry != &VolumeListHead)
2079 {
2080 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
2081
2082 if (VolumeEntry->pExtents == NULL)
2083 return NULL;
2084
2085 for (i = 0; i < VolumeEntry->pExtents->NumberOfDiskExtents; i++)
2086 {
2087 if (VolumeEntry->pExtents->Extents[i].DiskNumber == PartEntry->DiskEntry->DiskNumber)
2088 {
2089 if ((VolumeEntry->pExtents->Extents[i].StartingOffset.QuadPart == PartEntry->StartSector.QuadPart * PartEntry->DiskEntry->BytesPerSector) &&
2090 (VolumeEntry->pExtents->Extents[i].ExtentLength.QuadPart == PartEntry->SectorCount.QuadPart * PartEntry->DiskEntry->BytesPerSector))
2091 return VolumeEntry;
2092 }
2093 }
2094
2095 Entry = Entry->Flink;
2096 }
2097
2098 return NULL;
2099}
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
#define wcsicmp
Definition: compat.h:15
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:3827
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:422

◆ 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:70

◆ 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:72

◆ 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:76

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

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

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:1450
NTSTATUS CreateVolumeList(VOID)
Definition: partlist.c:1412
VOID DestroyPartitionList(IN PPARTLIST List)
Definition: partlist.c:2010
PPARTLIST CreatePartitionList(VOID)
Definition: partlist.c:1925

◆ 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:3058

◆ 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 (!IsDecString(argv[2]))
43 {
45 return TRUE;
46 }
47
48 ulValue = wcstoul(argv[2], NULL, 10);
49 if ((ulValue == 0) && (errno == ERANGE))
50 {
52 return TRUE;
53 }
54
56
58 while (Entry != &DiskListHead)
59 {
60 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
61
62 if (DiskEntry->DiskNumber == ulValue)
63 {
64 CurrentDisk = DiskEntry;
67 return TRUE;
68 }
69
70 Entry = Entry->Flink;
71 }
72
74 return TRUE;
75}
#define IDS_SELECT_DISK_INVALID
Definition: resource.h:87
#define IDS_SELECT_DISK
Definition: resource.h:86
BOOL IsDecString(_In_ PWSTR pszDecString)
Definition: misc.c:14

◆ SelectPartition()

BOOL SelectPartition ( INT  argc,
PWSTR argv 
)

Definition at line 79 of file select.c.

82{
84 PPARTENTRY PartEntry;
85 ULONG ulValue;
86 ULONG PartNumber = 1;
87
88 DPRINT("Select Partition()\n");
89
90 if (argc > 3)
91 {
93 return TRUE;
94 }
95
96 if (CurrentDisk == NULL)
97 {
99 return TRUE;
100 }
101
102 if (argc == 2)
103 {
104 if (CurrentPartition == NULL)
106 else
108 return TRUE;
109 }
110
111 if (!IsDecString(argv[2]))
112 {
114 return TRUE;
115 }
116
117 ulValue = wcstoul(argv[2], NULL, 10);
118 if ((ulValue == 0) && (errno == ERANGE))
119 {
121 return TRUE;
122 }
123
126 {
127 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
128
129 if (PartEntry->PartitionType != 0)
130 {
131 if (PartNumber == ulValue)
132 {
133 CurrentPartition = PartEntry;
135 return TRUE;
136 }
137
138 PartNumber++;
139 }
140
141 Entry = Entry->Flink;
142 }
143
146 {
147 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
148
149 if (PartEntry->PartitionType != 0)
150 {
151 if (PartNumber == ulValue)
152 {
153 CurrentPartition = PartEntry;
155 return TRUE;
156 }
157
158 PartNumber++;
159 }
160 Entry = Entry->Flink;
161 }
162
164 return TRUE;
165}
#define IDS_SELECT_PARTITION_NO_DISK
Definition: resource.h:90
#define IDS_SELECT_PARTITION_INVALID
Definition: resource.h:91
#define IDS_SELECT_PARTITION
Definition: resource.h:89

◆ SelectVolume()

BOOL SelectVolume ( INT  argc,
PWSTR argv 
)

Definition at line 169 of file select.c.

172{
174 PVOLENTRY VolumeEntry;
175 ULONG ulValue;
176
177 DPRINT("SelectVolume()\n");
178
179 if (argc > 3)
180 {
182 return TRUE;
183 }
184
185 if (argc == 2)
186 {
187 if (CurrentDisk == NULL)
189 else
191 return TRUE;
192 }
193
194 if (!IsDecString(argv[2]))
195 {
197 return TRUE;
198 }
199
200 ulValue = wcstoul(argv[2], NULL, 10);
201 if ((ulValue == 0) && (errno == ERANGE))
202 {
204 return TRUE;
205 }
206
208
210 while (Entry != &VolumeListHead)
211 {
212 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
213
214 if (VolumeEntry->VolumeNumber == ulValue)
215 {
216 CurrentVolume = VolumeEntry;
218 return TRUE;
219 }
220
221 Entry = Entry->Flink;
222 }
223
225 return TRUE;
226}
#define IDS_SELECT_NO_VOLUME
Definition: resource.h:92
#define IDS_SELECT_VOLUME
Definition: resource.h:93
#define IDS_SELECT_VOLUME_INVALID
Definition: resource.h:94
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 1731 of file partlist.c.

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

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

Referenced by CreatePartitionList(), and DestroyPartitionList().

◆ CurrentVolume

◆ DiskListHead

LIST_ENTRY DiskListHead
extern

◆ VolumeListHead