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

Go to the source code of this file.

Classes

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

Macros

#define WIN32_NO_STATUS
 
#define NTOS_MODE_USER
 
#define MAX_STRING_SIZE   1024
 
#define MAX_ARGS_COUNT   256
 
#define SIZE_1KB   (1024ULL)
 
#define SIZE_10KB   (10ULL * 1024ULL)
 
#define SIZE_1MB   (1024ULL * 1024ULL)
 
#define SIZE_10MB   (10ULL * 1024ULL * 1024ULL)
 
#define SIZE_1GB   (1024ULL * 1024ULL * 1024ULL)
 
#define SIZE_10GB   (10ULL * 1024ULL * 1024ULL * 1024ULL)
 
#define SIZE_1TB   (1024ULL * 1024ULL * 1024ULL * 1024ULL)
 
#define SIZE_10TB   (10ULL * 1024ULL * 1024ULL * 1024ULL * 1024ULL)
 

Typedefs

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

Enumerations

enum  _EXIT_CODE {
  EXIT_SUCCESS = 0 , EXIT_FATAL , EXIT_CMD_ARG , EXIT_FILE ,
  EXIT_SERVICE , EXIT_SYNTAX , EXIT_EXIT
}
 
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

EXIT_CODE active_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE add_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE assign_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE attach_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE attributes_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE automount_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE break_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE clean_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE compact_main (_In_ INT argc, _In_ PWSTR *argv)
 
NTSTATUS CreateDisk (_In_ ULONG DiskNumber, _In_ PCREATE_DISK DiskInfo)
 
EXIT_CODE ConvertGPT (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE ConvertMBR (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE CreateEfiPartition (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE CreateExtendedPartition (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE CreateLogicalPartition (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE CreateMsrPartition (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE CreatePrimaryPartition (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE DeleteDisk (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE DeletePartition (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE DeleteVolume (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE detach_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE DetailDisk (INT argc, PWSTR *argv)
 
EXIT_CODE DetailPartition (INT argc, PWSTR *argv)
 
EXIT_CODE DetailVolume (INT argc, PWSTR *argv)
 
EXIT_CODE DumpDisk (_In_ INT argc, _In_ LPWSTR *argv)
 
EXIT_CODE DumpPartition (_In_ INT argc, _In_ LPWSTR *argv)
 
EXIT_CODE expand_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE extend_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE filesystems_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE format_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE gpt_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE help_main (_In_ INT argc, _In_ PWSTR *argv)
 
VOID HelpCommandList (VOID)
 
EXIT_CODE HelpCommand (_In_ PCOMMAND pCommand)
 
EXIT_CODE import_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE inactive_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE InterpretScript (_In_ LPWSTR line)
 
EXIT_CODE InterpretCmd (_In_ INT argc, _In_ PWSTR *argv)
 
VOID InterpretMain (VOID)
 
EXIT_CODE ListDisk (INT argc, PWSTR *argv)
 
EXIT_CODE ListPartition (INT argc, PWSTR *argv)
 
EXIT_CODE ListVolume (INT argc, PWSTR *argv)
 
EXIT_CODE ListVirtualDisk (INT argc, PWSTR *argv)
 
VOID PrintDisk (_In_ PDISKENTRY DiskEntry)
 
VOID PrintVolume (_In_ PVOLENTRY VolumeEntry)
 
EXIT_CODE merge_main (_In_ INT argc, _In_ PWSTR *argv)
 
BOOL IsDecString (_In_ PWSTR pszDecString)
 
BOOL IsHexString (_In_ PWSTR pszHexString)
 
BOOL HasPrefix (_In_ PWSTR pszString, _In_ PWSTR pszPrefix, _Out_opt_ PWSTR *pszSuffix)
 
ULONGLONG RoundingDivide (_In_ ULONGLONG Dividend, _In_ ULONGLONG Divisor)
 
PWSTR DuplicateQuotedString (_In_ PWSTR pszInString)
 
PWSTR DuplicateString (_In_ PWSTR pszInString)
 
VOID CreateGUID (_Out_ GUID *pGuid)
 
VOID CreateSignature (_Out_ PDWORD pSignature)
 
VOID PrintGUID (_Out_ PWSTR pszBuffer, _In_ GUID *pGuid)
 
BOOL StringToGUID (_Out_ GUID *pGuid, _In_ PWSTR pszString)
 
VOID PrintBusType (_Out_ PWSTR pszBuffer, _In_ INT cchBufferMax, _In_ STORAGE_BUS_TYPE Bustype)
 
BOOL GetAutomountState (_Out_ PBOOL State)
 
BOOL SetAutomountState (_In_ BOOL bEnable)
 
BOOL ScrubAutomount (VOID)
 
BOOL AssignDriveLetter (_In_ PWSTR DeviceName, _In_ WCHAR DriveLetter)
 
BOOL AssignNextDriveLetter (_In_ PWSTR DeviceName, _Out_ PWCHAR DriveLetter)
 
BOOL DeleteDriveLetter (_In_ WCHAR DriveLetter)
 
EXIT_CODE offline_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE online_main (_In_ INT argc, _In_ PWSTR *argv)
 
ULONGLONG AlignDown (_In_ ULONGLONG Value, _In_ ULONG Alignment)
 
NTSTATUS CreatePartitionList (VOID)
 
VOID DestroyPartitionList (VOID)
 
NTSTATUS CreateVolumeList (VOID)
 
VOID DestroyVolumeList (VOID)
 
VOID ScanForUnpartitionedMbrDiskSpace (PDISKENTRY DiskEntry)
 
VOID ScanForUnpartitionedGptDiskSpace (PDISKENTRY DiskEntry)
 
VOID ReadLayoutBuffer (_In_ HANDLE FileHandle, _In_ PDISKENTRY DiskEntry)
 
NTSTATUS WriteMbrPartitions (_In_ PDISKENTRY DiskEntry)
 
NTSTATUS WriteGptPartitions (_In_ PDISKENTRY DiskEntry)
 
VOID UpdateMbrDiskLayout (_In_ PDISKENTRY DiskEntry)
 
VOID UpdateGptDiskLayout (_In_ PDISKENTRY DiskEntry, _In_ BOOL DeleteEntry)
 
PPARTENTRY GetPrevUnpartitionedEntry (_In_ PPARTENTRY PartEntry)
 
PPARTENTRY GetNextUnpartitionedEntry (_In_ PPARTENTRY PartEntry)
 
ULONG GetPrimaryPartitionCount (_In_ PDISKENTRY DiskEntry)
 
NTSTATUS DismountVolume (_In_ PPARTENTRY PartEntry)
 
PVOLENTRY GetVolumeFromPartition (_In_ PPARTENTRY PartEntry)
 
VOID RemoveVolume (_In_ PVOLENTRY VolumeEntry)
 
EXIT_CODE recover_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE remove_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE repair_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE rescan_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE retain_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE san_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE SelectDisk (INT argc, PWSTR *argv)
 
EXIT_CODE SelectPartition (INT argc, PWSTR *argv)
 
EXIT_CODE SelectVolume (INT argc, PWSTR *argv)
 
EXIT_CODE setid_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE shrink_main (_In_ INT argc, _In_ PWSTR *argv)
 
EXIT_CODE 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 97 of file diskpart.h.

◆ MAX_STRING_SIZE

#define MAX_STRING_SIZE   1024

Definition at line 96 of file diskpart.h.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 42 of file diskpart.h.

◆ SIZE_10GB

#define SIZE_10GB   (10ULL * 1024ULL * 1024ULL * 1024ULL)

Definition at line 262 of file diskpart.h.

◆ SIZE_10KB

#define SIZE_10KB   (10ULL * 1024ULL)

Definition at line 258 of file diskpart.h.

◆ SIZE_10MB

#define SIZE_10MB   (10ULL * 1024ULL * 1024ULL)

Definition at line 260 of file diskpart.h.

◆ SIZE_10TB

#define SIZE_10TB   (10ULL * 1024ULL * 1024ULL * 1024ULL * 1024ULL)

Definition at line 264 of file diskpart.h.

◆ SIZE_1GB

#define SIZE_1GB   (1024ULL * 1024ULL * 1024ULL)

Definition at line 261 of file diskpart.h.

◆ SIZE_1KB

#define SIZE_1KB   (1024ULL)

Definition at line 257 of file diskpart.h.

◆ SIZE_1MB

#define SIZE_1MB   (1024ULL * 1024ULL)

Definition at line 259 of file diskpart.h.

◆ SIZE_1TB

#define SIZE_1TB   (1024ULL * 1024ULL * 1024ULL * 1024ULL)

Definition at line 263 of file diskpart.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 17 of file diskpart.h.

Typedef Documentation

◆ BIOSDISKENTRY

◆ COMMAND

◆ DISKENTRY

◆ EXIT_CODE

◆ FORMATSTATE

◆ GPT_PARTITION_DATA

◆ MBR_PARTITION_DATA

◆ PARTENTRY

◆ PBIOSDISKENTRY

◆ PCOMMAND

◆ PDISKENTRY

◆ PFORMATSTATE

◆ PGPT_PARTITION_DATA

◆ PMBR_PARTITION_DATA

◆ PPARTENTRY

◆ PVOLENTRY

◆ PVOLUME_TYPE

◆ VOLENTRY

◆ VOLUME_TYPE

Enumeration Type Documentation

◆ _EXIT_CODE

Enumerator
EXIT_SUCCESS 
EXIT_FATAL 
EXIT_CMD_ARG 
EXIT_FILE 
EXIT_SERVICE 
EXIT_SYNTAX 
EXIT_EXIT 

Definition at line 73 of file diskpart.h.

74{
75 EXIT_SUCCESS = 0,
81 EXIT_EXIT /* Only used by the exit command */
82} EXIT_CODE;
enum _EXIT_CODE EXIT_CODE
@ EXIT_SERVICE
Definition: diskpart.h:79
@ EXIT_FATAL
Definition: diskpart.h:76
@ EXIT_EXIT
Definition: diskpart.h:81
@ EXIT_FILE
Definition: diskpart.h:78
@ EXIT_CMD_ARG
Definition: diskpart.h:77
@ EXIT_SUCCESS
Definition: diskpart.h:75
@ EXIT_SYNTAX
Definition: diskpart.h:80

◆ _FORMATSTATE

Enumerator
Unformatted 
UnformattedOrDamaged 
UnknownFormat 
Formatted 
Unformatted 
UnformattedOrDamaged 
UnknownFormat 
Preformatted 
Formatted 

Definition at line 100 of file diskpart.h.

101{
enum _FORMATSTATE FORMATSTATE
enum _FORMATSTATE * PFORMATSTATE
@ UnknownFormat
Definition: diskpart.h:104
@ Preformatted
Definition: diskpart.h:105
@ Formatted
Definition: diskpart.h:106
@ Unformatted
Definition: diskpart.h:102
@ UnformattedOrDamaged
Definition: diskpart.h:103

◆ _VOLUME_TYPE

Enumerator
VOLUME_TYPE_CDROM 
VOLUME_TYPE_PARTITION 
VOLUME_TYPE_REMOVABLE 
VOLUME_TYPE_UNKNOWN 

Definition at line 109 of file diskpart.h.

110{
@ VOLUME_TYPE_UNKNOWN
Definition: diskpart.h:114
@ VOLUME_TYPE_REMOVABLE
Definition: diskpart.h:113
@ VOLUME_TYPE_CDROM
Definition: diskpart.h:111
@ VOLUME_TYPE_PARTITION
Definition: diskpart.h:112
enum _VOLUME_TYPE VOLUME_TYPE
enum _VOLUME_TYPE * PVOLUME_TYPE

Function Documentation

◆ active_main()

EXIT_CODE active_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 16 of file active.c.

19{
21
22 DPRINT("Active()\n");
23
24 if (CurrentDisk == NULL)
25 {
27 return EXIT_SUCCESS;
28 }
29
31 {
33 return EXIT_SUCCESS;
34 }
35
37 {
39 {
41 return EXIT_SUCCESS;
42 }
43
48 if (NT_SUCCESS(Status))
49 {
51 }
52 else
53 {
55 }
56 }
57 else
58 {
60 }
61
62 return EXIT_SUCCESS;
63}
#define StdOut
Definition: fc.c:14
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
LONG NTSTATUS
Definition: precomp.h:26
#define IDS_ACTIVE_FAIL
Definition: resource.h:21
#define IDS_ACTIVE_SUCCESS
Definition: resource.h:22
#define IDS_SELECT_NO_PARTITION
Definition: resource.h:126
#define IDS_ACTIVE_NO_MBR
Definition: resource.h:24
#define IDS_ACTIVE_ALREADY
Definition: resource.h:23
#define IDS_SELECT_NO_DISK
Definition: resource.h:121
VOID UpdateMbrDiskLayout(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:2362
PDISKENTRY CurrentDisk
Definition: partlist.c:75
NTSTATUS WriteMbrPartitions(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:2034
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
@ PARTITION_STYLE_MBR
Definition: imports.h:201
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
#define DPRINT
Definition: sndvol32.h:73
BOOLEAN Dirty
Definition: partlist.h:136
DWORD PartitionStyle
Definition: diskpart.h:219
BOOLEAN BootIndicator
Definition: diskpart.h:119
MBR_PARTITION_DATA Mbr
Definition: diskpart.h:141
static PPARTENTRY CurrentPartition
Definition: usetup.c:78

◆ add_main()

EXIT_CODE add_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file add.c.

15{
16 return EXIT_SUCCESS;
17}

◆ AlignDown()

ULONGLONG AlignDown ( _In_ ULONGLONG  Value,
_In_ ULONG  Alignment 
)

Definition at line 189 of file partlist.c.

192{
193 ULONGLONG Temp;
194
195 Temp = Value / Alignment;
196
197 return Temp * Alignment;
198}
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()

EXIT_CODE assign_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

◆ AssignDriveLetter()

BOOL AssignDriveLetter ( _In_ PWSTR  DeviceName,
_In_ WCHAR  DriveLetter 
)

Definition at line 181 of file mountmgr.c.

184{
186 ULONG DosDeviceNameLength, DeviceNameLength;
189 HANDLE MountMgrHandle = NULL;
192 BOOL Ret = TRUE;
193
194 DPRINT1("AssignDriveLetter(%S %c)\n", DeviceName, DriveLetter);
195
196 DeviceNameLength = wcslen(DeviceName) * sizeof(WCHAR);
197
198 swprintf(DosDeviceName, L"\\DosDevices\\%c:", DriveLetter);
199 DosDeviceNameLength = wcslen(DosDeviceName) * sizeof(WCHAR);
200
201 /* Allocate the input buffer for the MountMgr */
202 InputBufferLength = DosDeviceNameLength + DeviceNameLength + sizeof(MOUNTMGR_CREATE_POINT_INPUT);
204 if (InputBuffer == NULL)
205 {
206 DPRINT1("InputBuffer allocation failed!\n");
207 return FALSE;
208 }
209
210 /* Fill the input buffer */
211 InputBuffer->SymbolicLinkNameOffset = sizeof(MOUNTMGR_CREATE_POINT_INPUT);
212 InputBuffer->SymbolicLinkNameLength = DosDeviceNameLength;
213 InputBuffer->DeviceNameOffset = DosDeviceNameLength + sizeof(MOUNTMGR_CREATE_POINT_INPUT);
214 InputBuffer->DeviceNameLength = DeviceNameLength;
217 DosDeviceNameLength);
218 RtlCopyMemory((PVOID)((ULONG_PTR)InputBuffer + InputBuffer->DeviceNameOffset),
220 DeviceNameLength);
221
222DPRINT1("\n");
224 if (!NT_SUCCESS(Status))
225 {
226 DPRINT1("OpenMountManager() failed (Status 0x%08lx)\n", Status);
227 Ret = FALSE;
228 goto done;
229 }
230
231DPRINT1("\n");
232 Status = NtDeviceIoControlFile(MountMgrHandle,
233 NULL,
234 NULL,
235 NULL,
236 &Iosb,
240 NULL,
241 0);
242 if (!NT_SUCCESS(Status))
243 {
244 DPRINT1("NtDeviceIoControlFile() failed (Status 0x%08lx)\n", Status);
245 Ret = FALSE;
246 goto done;
247 }
248
249DPRINT1("\n");
250done:
251 if (MountMgrHandle)
252 NtClose(MountMgrHandle);
253
254 RtlFreeHeap(RtlGetProcessHeap(), 0, InputBuffer);
255
256 return Ret;
257}
#define DPRINT1
Definition: precomp.h:8
static NTSTATUS OpenMountManager(_Out_ PHANDLE MountMgrHandle, _In_ ACCESS_MASK Access)
Definition: mountmgr.c:20
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
#define FALSE
Definition: types.h:117
#define GENERIC_READ
Definition: compat.h:135
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
#define swprintf
Definition: precomp.h:40
#define L(x)
Definition: resources.c:13
return Iosb
Definition: create.c:4403
unsigned int BOOL
Definition: ntddk_ex.h:94
static char DosDeviceName[DEVICE_SIZE]
Definition: lsdd.c:26
struct _MOUNTMGR_CREATE_POINT_INPUT MOUNTMGR_CREATE_POINT_INPUT
#define IOCTL_MOUNTMGR_CREATE_POINT
Definition: imports.h:116
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define GENERIC_WRITE
Definition: nt_native.h:90
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3281
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:322
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by assign_main().

◆ AssignNextDriveLetter()

BOOL AssignNextDriveLetter ( _In_ PWSTR  DeviceName,
_Out_ PWCHAR  DriveLetter 
)

Definition at line 261 of file mountmgr.c.

264{
267 ULONG DeviceNameLength, InputBufferLength;
268 HANDLE MountMgrHandle = NULL;
271 BOOL Ret = TRUE;
272
273 DPRINT1("AssignNextDriveLetter(%S %p)\n", DeviceName, DriveLetter);
274
275 DeviceNameLength = wcslen(DeviceName) * sizeof(WCHAR);
276
279 if (InputBuffer == NULL)
280 {
281 DPRINT1("InputBuffer allocation failed!\n");
282 return FALSE;
283 }
284
285 /* And fill it with the device hat needs a drive letter */
286 InputBuffer->DeviceNameLength = DeviceNameLength;
287 RtlCopyMemory(&InputBuffer->DeviceName[0],
289 DeviceNameLength);
290
291DPRINT1("\n");
293 if (!NT_SUCCESS(Status))
294 {
295 DPRINT1("OpenMountManager() failed (Status 0x%08lx)\n", Status);
296 Ret = FALSE;
297 goto done;
298 }
299
300DPRINT1("\n");
301 Status = NtDeviceIoControlFile(MountMgrHandle,
302 NULL,
303 NULL,
304 NULL,
305 &Iosb,
309 &LetterInfo,
310 sizeof(LetterInfo));
311 if (!NT_SUCCESS(Status))
312 {
313 DPRINT1("NtDeviceIoControlFile() failed (Status 0x%08lx)\n", Status);
314 Ret = FALSE;
315 goto done;
316 }
317
318DPRINT1("\n");
319done:
320 if (MountMgrHandle)
321 NtClose(MountMgrHandle);
322
323 RtlFreeHeap(RtlGetProcessHeap(), 0, InputBuffer);
324
325 if (Ret)
326 {
327 if (LetterInfo.DriveLetterWasAssigned)
328 *DriveLetter = LetterInfo.CurrentDriveLetter;
329 else
330 *DriveLetter = UNICODE_NULL;
331 }
332
333 return Ret;
334}
#define UNICODE_NULL
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Referenced by assign_main().

◆ attach_main()

EXIT_CODE attach_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file attach.c.

15{
16 return EXIT_SUCCESS;
17}

◆ attributes_main()

EXIT_CODE attributes_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file attributes.c.

15{
16 return EXIT_SUCCESS;
17}

◆ automount_main()

EXIT_CODE automount_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 16 of file automount.c.

19{
20 BOOL bDisable = FALSE, bEnable = FALSE, bScrub = FALSE;
21#if 0
22 BOOL bNoErr = FALSE;
23#endif
24 INT i;
26
27 DPRINT("Automount()\n");
28
29 for (i = 1; i < argc; i++)
30 {
31 if (_wcsicmp(argv[i], L"noerr") == 0)
32 {
33 /* noerr */
34#if 0
35 bNoErr = TRUE;
36#endif
37 }
38 }
39
40 for (i = 1; i < argc; i++)
41 {
42 if (_wcsicmp(argv[i], L"disable") == 0)
43 {
44 /* set automount state */
45 bDisable = TRUE;
46 }
47 else if (_wcsicmp(argv[i], L"enable") == 0)
48 {
49 /* set automount state */
50 bEnable = TRUE;
51 }
52 else if (_wcsicmp(argv[i], L"scrub") == 0)
53 {
54 /* scrub automount */
55 bScrub = TRUE;
56 }
57 else if (_wcsicmp(argv[i], L"noerr") == 0)
58 {
59 /* noerr - Already handled above */
60 }
61 else
62 {
64 return TRUE;
65 }
66 }
67
68 DPRINT("bDisable %u\n", bDisable);
69 DPRINT("bEnable %u\n", bEnable);
70 DPRINT("bScrub %u\n", bScrub);
71
72 if (bDisable && bEnable)
73 {
75 return TRUE;
76 }
77
78 if ((bDisable == FALSE) && (bEnable == FALSE) && (bScrub == FALSE))
79 {
80 DPRINT("Show automount\n");
82 if (Result == FALSE)
83 {
84// ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
85 return TRUE;
86 }
87
88 if (State)
90 else
92 ConPuts(StdOut, L"\n");
93 }
94
95 if (bDisable)
96 {
97 DPRINT("Disable automount\n");
99 if (Result == FALSE)
100 {
101// ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
102 return TRUE;
103 }
104
106 ConPuts(StdOut, L"\n");
107 }
108
109 if (bEnable)
110 {
111 DPRINT("Enable automount\n");
113 if (Result == FALSE)
114 {
115// ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
116 return TRUE;
117 }
118
120 ConPuts(StdOut, L"\n");
121 }
122
123 if (bScrub)
124 {
125 DPRINT("Scrub automount\n");
127 if (Result == FALSE)
128 {
129// ConResPuts(StdErr, IDS_ERROR_INVALID_ARGS);
130 return TRUE;
131 }
132
134 ConPuts(StdOut, L"\n");
135 }
136
137 return EXIT_SUCCESS;
138}
static int argc
Definition: ServiceArgs.c:12
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define StdErr
Definition: fc.c:15
#define IDS_AUTOMOUNT_SCRUBBED
Definition: resource.h:28
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:229
#define IDS_AUTOMOUNT_DISABLED
Definition: resource.h:27
#define IDS_AUTOMOUNT_ENABLED
Definition: resource.h:26
BOOL GetAutomountState(_Out_ PBOOL State)
Definition: mountmgr.c:46
BOOL ScrubAutomount(VOID)
Definition: mountmgr.c:141
BOOL SetAutomountState(_In_ BOOL bEnable)
Definition: mountmgr.c:90
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
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
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:58
_In_ BOOL bEnable
Definition: winddi.h:3426
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

◆ break_main()

EXIT_CODE break_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file break.c.

15{
16 ConPuts(StdOut, L"\nTODO: Add code later since Win 7 Home Premium doesn't have this feature.\n");
17 return EXIT_SUCCESS;
18}

◆ clean_main()

EXIT_CODE clean_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 16 of file clean.c.

19{
21 PPARTENTRY PartEntry;
22 PVOLENTRY VolumeEntry;
23 BOOL bAll = FALSE;
24 PUCHAR SectorsBuffer = NULL;
25 ULONG LayoutBufferSize, Size;
26 INT i;
32 LARGE_INTEGER Offset, Count, MaxCount;
34
35 DPRINT("Clean()\n");
36
37 if (CurrentDisk == NULL)
38 {
40 return EXIT_SUCCESS;
41 }
42
43 /* Do not allow to clean the boot disk */
44 if ((CurrentDisk->BiosFound == TRUE) &&
46 {
48 return EXIT_SUCCESS;
49 }
50
51 for (i = 1; i < argc; i++)
52 {
53 if (_wcsicmp(argv[1], L"all") == 0)
54 {
55 bAll = TRUE;
56 }
57 }
58
59 /* Dismount and remove all logical partitions */
61 {
63 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
64
65 /* Dismount the logical partition */
66 if (PartEntry->Mbr.PartitionType != 0)
67 {
68 DismountVolume(PartEntry);
69 VolumeEntry = GetVolumeFromPartition(PartEntry);
70 if (VolumeEntry)
71 RemoveVolume(VolumeEntry);
72 }
73
74 /* Delete it */
75 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
76 }
77
78 /* Dismount and remove all primary partitions */
80 {
82 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
83
84 /* Dismount the primary partition */
85 if ((PartEntry->Mbr.PartitionType != 0) &&
87 {
88 DismountVolume(PartEntry);
89 VolumeEntry = GetVolumeFromPartition(PartEntry);
90 if (VolumeEntry)
91 RemoveVolume(VolumeEntry);
92 }
93
94 /* Delete it */
95 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
96 }
97
98 /* Initialize the disk entry */
102 CurrentDisk->PartitionStyle = PARTITION_STYLE_RAW;
103
104 /* Wipe the layout buffer */
105 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentDisk->LayoutBuffer);
106
107 LayoutBufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
108 ((4 - ANYSIZE_ARRAY) * sizeof(PARTITION_INFORMATION_EX));
109 CurrentDisk->LayoutBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
111 LayoutBufferSize);
113 {
114 DPRINT1("Failed to allocate the disk layout buffer!\n");
115 return EXIT_SUCCESS;
116 }
117
118 CurrentDisk->LayoutBuffer->PartitionStyle = PARTITION_STYLE_RAW;
119
120 /* Allocate a 1MB sectors buffer */
121 SectorsBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
123 1024 * 1024);
124 if (SectorsBuffer == NULL)
125 {
126 DPRINT1("Failed to allocate the sectors buffer!\n");
127 goto done;
128 }
129
130 /* Open the disk for writing */
132 L"\\Device\\Harddisk%d\\Partition0",
134
136
138 &Name,
140 NULL,
141 NULL);
142
147 0,
149 if (!NT_SUCCESS(Status))
150 {
151 DPRINT1("Failed to open the disk! (Status 0x%08lx)\n", Status);
153 goto done;
154 }
155
156 /* Clean sectors */
157 if (bAll)
158 {
159 MaxCount.QuadPart = (CurrentDisk->SectorCount.QuadPart * CurrentDisk->BytesPerSector) / (1024 * 1024);
160 for (Count.QuadPart = 0; Count.QuadPart < MaxCount.QuadPart; Count.QuadPart++)
161 {
162 Offset.QuadPart = Count.QuadPart * (1024 * 1024);
164 NULL,
165 NULL,
166 NULL,
168 SectorsBuffer,
169 1024 * 1024,
170 &Offset,
171 NULL);
172 if (!NT_SUCCESS(Status))
173 {
174 DPRINT1("Failed to write MB! (Status 0x%08lx)\n", Status);
176 goto done;
177 }
178 }
179
181 if (Size != 0)
182 {
183 Offset.QuadPart += (1024 * 1024);
185 NULL,
186 NULL,
187 NULL,
189 SectorsBuffer,
190 Size,
191 &Offset,
192 NULL);
193 if (!NT_SUCCESS(Status))
194 {
195 DPRINT1("Failed to write the last part! (Status 0x%08lx)\n", Status);
197 goto done;
198 }
199 }
200 }
201 else
202 {
203 /* Clean the first MB */
204 Offset.QuadPart = 0;
206 NULL,
207 NULL,
208 NULL,
210 SectorsBuffer,
211 1024 * 1024,
212 &Offset,
213 NULL);
214 if (!NT_SUCCESS(Status))
215 {
216 DPRINT1("Failed to write the first MB! (Status 0x%08lx)\n", Status);
218 goto done;
219 }
220
221 /* Clean the last MB */
222 Offset.QuadPart = (CurrentDisk->SectorCount.QuadPart * CurrentDisk->BytesPerSector) - (1024 * 1024);
224 NULL,
225 NULL,
226 NULL,
228 SectorsBuffer,
229 1024 * 1024,
230 &Offset,
231 NULL);
232 if (!NT_SUCCESS(Status))
233 {
234 DPRINT1("Failed to write the last MB! (Status 0x%08lx)\n", Status);
236 goto done;
237 }
238 }
239
241
242done:
243 if (FileHandle != NULL)
245
246 if (SectorsBuffer != NULL)
247 RtlFreeHeap(RtlGetProcessHeap(), 0, SectorsBuffer);
248
249 return EXIT_SUCCESS;
250}
#define IDS_CLEAN_FAIL
Definition: resource.h:36
#define IDS_CLEAN_SUCCESS
Definition: resource.h:37
#define IDS_CLEAN_SYSTEM
Definition: resource.h:38
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
LPWSTR Name
Definition: desk.c:124
VOID RemoveVolume(_In_ PVOLENTRY VolumeEntry)
Definition: partlist.c:2832
PVOLENTRY GetVolumeFromPartition(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:2795
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define MAX_PATH
Definition: compat.h:34
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
_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 _PARTITION_INFORMATION_EX PARTITION_INFORMATION_EX
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
int Count
Definition: noreturn.cpp:7
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3953
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI NTSTATUS NTAPI NtWriteFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID WriteBuffer, IN ULONG WriteBufferLength, IN PLARGE_INTEGER FileOffset OPTIONAL, IN PULONG LockOperationKey OPTIONAL)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define IsContainerPartition(PartitionType)
Definition: ntdddisk.h:321
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
base of all file and directory entries
Definition: entries.h:83
ULONG BiosDiskNumber
Definition: diskpart.h:205
ULARGE_INTEGER SectorCount
Definition: partlist.h:115
PPARTENTRY ExtendedPartition
Definition: partlist.h:153
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:150
BOOLEAN NewDisk
Definition: partlist.h:138
ULONG DiskNumber
Definition: partlist.h:129
ULONG BytesPerSector
Definition: partlist.h:113
BOOLEAN BiosFound
Definition: partlist.h:120
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:149
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:143
Definition: typedefs.h:120
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#define ANYSIZE_ARRAY
Definition: typedefs.h:46
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
unsigned char * PUCHAR
Definition: typedefs.h:53
LONGLONG QuadPart
Definition: typedefs.h:114
NTSTATUS DismountVolume(_Inout_ PVOLINFO Volume, _In_ BOOLEAN Force)
Attempts to dismount the designated volume.
Definition: volutil.c:152
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539

◆ compact_main()

EXIT_CODE compact_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file compact.c.

15{
16 return EXIT_SUCCESS;
17}

◆ ConvertGPT()

EXIT_CODE ConvertGPT ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 88 of file convert.c.

91{
92 CREATE_DISK DiskInfo;
94
95 DPRINT("ConvertGPT()\n");
96
97 if (CurrentDisk == NULL)
98 {
100 return EXIT_SUCCESS;
101 }
102
104 {
106 return EXIT_SUCCESS;
107 }
108
110 {
112 return EXIT_SUCCESS;
113 }
114
115#if 0
116 /* Fail if disk size is less than 128MB */
117 if (CurrentDisk->SectorCount.QuadPart * CurrentDisk->BytesPerSector < 128ULL * 1024ULL * 1024ULL)
118 {
119 ConResPuts(StdOut, IDS_CONVERT_GPT_TOO_SMALL);
120 return EXIT_SUCCESS;
121 }
122#endif
123
124 DiskInfo.PartitionStyle = PARTITION_STYLE_GPT;
125 CreateGUID(&DiskInfo.Gpt.DiskId);
126 DiskInfo.Gpt.MaxPartitionCount = 128;
127
129 if (!NT_SUCCESS(Status))
130 {
131 DPRINT1("CreateDisk() failed!\n");
132 return EXIT_SUCCESS;
133 }
134
139
142
143 return EXIT_SUCCESS;
144}
#define IDS_CONVERT_GPT_NOT_EMPTY
Definition: resource.h:41
#define IDS_CONVERT_GPT_SUCCESS
Definition: resource.h:42
#define IDS_CONVERT_GPT_ALREADY
Definition: resource.h:40
VOID CreateGUID(_Out_ GUID *pGuid)
Definition: misc.c:152
VOID ScanForUnpartitionedGptDiskSpace(PDISKENTRY DiskEntry)
Definition: partlist.c:921
@ PARTITION_STYLE_GPT
Definition: imports.h:202
ULONGLONG AlignDown(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:67
#define GetPrimaryPartitionCount(DiskEntry)
Definition: partlist.c:2527
ULARGE_INTEGER EndSector
Definition: diskpart.h:202
ULONG SectorAlignment
Definition: partlist.h:116
ULARGE_INTEGER StartSector
Definition: diskpart.h:201
NTSTATUS CreateDisk(_In_ ULONG DiskNumber, _In_ PCREATE_DISK DiskInfo)
Definition: convert.c:15

◆ ConvertMBR()

EXIT_CODE ConvertMBR ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 148 of file convert.c.

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

◆ CreateDisk()

NTSTATUS CreateDisk ( _In_ ULONG  DiskNumber,
_In_ PCREATE_DISK  DiskInfo 
)

Definition at line 15 of file convert.c.

18{
25
26 DPRINT("CreateDisk(%lu %p)\n", DiskNumber, DiskInfo);
27
29 L"\\Device\\Harddisk%lu\\Partition0",
32
34 &Name,
36 NULL,
37 NULL);
38
42 &Iosb,
43 0,
45 if (!NT_SUCCESS(Status))
46 {
47 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
48 goto done;
49 }
50
52 NULL,
53 NULL,
54 NULL,
55 &Iosb,
57 DiskInfo,
58 sizeof(*DiskInfo),
59 NULL,
60 0);
61 if (!NT_SUCCESS(Status))
62 {
63 DPRINT1("NtDeviceIoControlFile() failed (Status %lx)\n", Status);
64 goto done;
65 }
66
67 /* Free the layout buffer */
69 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentDisk->LayoutBuffer);
70
75 CurrentDisk->PartitionStyle = DiskInfo->PartitionStyle;
76
78
79done:
80 if (FileHandle)
82
83 return Status;
84}
VOID ReadLayoutBuffer(_In_ HANDLE FileHandle, _In_ PDISKENTRY DiskEntry)
Definition: partlist.c:1065
#define IOCTL_DISK_CREATE_DISK
Definition: ntdddisk.h:55
IN HANDLE DstPath
Definition: fsutil.h:81

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

◆ CreateEfiPartition()

EXIT_CODE CreateEfiPartition ( _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 DPRINT1("CreateEfiPartition()\n");
33
34 if (CurrentDisk == NULL)
35 {
37 return EXIT_SUCCESS;
38 }
39
41 {
43 return EXIT_SUCCESS;
44 }
45
46 for (i = 3; i < argc; i++)
47 {
48 if (_wcsicmp(argv[i], L"noerr") == 0)
49 {
50 /* noerr */
51 DPRINT("NoErr\n", pszSuffix);
52 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
53#if 0
54 bNoErr = TRUE;
55#endif
56 }
57 }
58
59 for (i = 3; i < argc; i++)
60 {
61 if (HasPrefix(argv[i], L"size=", &pszSuffix))
62 {
63 /* size=<N> (MB) */
64 DPRINT("Size : %s\n", pszSuffix);
65
66 ullSize = _wcstoui64(pszSuffix, NULL, 10);
67 if ((ullSize == 0) && (errno == ERANGE))
68 {
70 return EXIT_SUCCESS;
71 }
72 }
73 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
74 {
75 /* offset=<N> (KB) */
76 DPRINT("Offset : %s\n", pszSuffix);
77 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
78#if 0
79 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
80 if ((ullOffset == 0) && (errno == ERANGE))
81 {
83 return TRUE;
84 }
85#endif
86 }
87 else if (_wcsicmp(argv[i], L"noerr") == 0)
88 {
89 /* noerr - Already handled above */
90 }
91 else
92 {
94 return EXIT_SUCCESS;
95 }
96 }
97
98 DPRINT1("Size: %I64u\n", ullSize);
99#if 0
100 DPRINT1("Offset: %I64u\n", ullOffset);
101#endif
102
103 /* Size */
104 if (ullSize != 0)
105 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
106 else
107 ullSectorCount = 0;
108
109 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
110
111#ifdef DUMP_PARTITION_LIST
112 DumpPartitionList(CurrentDisk);
113#endif
114
115 for (ListEntry = CurrentDisk->PrimaryPartListHead.Flink;
116 ListEntry != &CurrentDisk->PrimaryPartListHead;
117 ListEntry = ListEntry->Flink)
118 {
119 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
120 if (PartEntry->IsPartitioned)
121 continue;
122
123 if (ullSectorCount == 0)
124 {
125 DPRINT("Claim whole unused space!\n");
126 PartEntry->IsPartitioned = TRUE;
127 PartEntry->New = TRUE;
128 CopyMemory(&PartEntry->Gpt.PartitionType, &PARTITION_SYSTEM_GUID, sizeof(GUID));
129 CreateGUID(&PartEntry->Gpt.PartitionId);
130 PartEntry->Gpt.Attributes = 0ULL;
131 PartEntry->PartitionNumber = 0;
132 PartEntry->FormatState = Unformatted;
133 PartEntry->FileSystemName[0] = L'\0';
134
135 CurrentPartition = PartEntry;
137 break;
138 }
139 else
140 {
141 if (ullSectorCount == PartEntry->SectorCount.QuadPart)
142 {
143 DPRINT("Claim matching unused space!\n");
144 PartEntry->IsPartitioned = TRUE;
145 PartEntry->New = TRUE;
146 CopyMemory(&PartEntry->Gpt.PartitionType, &PARTITION_SYSTEM_GUID, sizeof(GUID));
147 CreateGUID(&PartEntry->Gpt.PartitionId);
148 PartEntry->Gpt.Attributes = 0ULL;
149 PartEntry->PartitionNumber = 0;
150 PartEntry->FormatState = Unformatted;
151 PartEntry->FileSystemName[0] = L'\0';
152
153 CurrentPartition = PartEntry;
155 break;
156 }
157 else if (ullSectorCount < PartEntry->SectorCount.QuadPart)
158 {
159 DPRINT("Claim part of unused space\n");
160 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
161 if (NewPartEntry == NULL)
162 {
163 ConPuts(StdOut, L"Memory allocation failed!\n");
164 return TRUE;
165 }
166
167 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
168
169 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
170 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
171
172 NewPartEntry->LogicalPartition = FALSE;
173 NewPartEntry->IsPartitioned = TRUE;
174 NewPartEntry->New = TRUE;
175 CopyMemory(&NewPartEntry->Gpt.PartitionType, &PARTITION_SYSTEM_GUID, sizeof(GUID));
176 CreateGUID(&NewPartEntry->Gpt.PartitionId);
177 NewPartEntry->Gpt.Attributes = 0ULL;
178 NewPartEntry->PartitionNumber = 0;
179 NewPartEntry->FormatState = Unformatted;
180 NewPartEntry->FileSystemName[0] = L'\0';
181
182 PartEntry->StartSector.QuadPart += ullSectorCount;
183 PartEntry->SectorCount.QuadPart -= ullSectorCount;
184
185 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
186
187 CurrentPartition = NewPartEntry;
189 break;
190 }
191 }
192 }
193
194#ifdef DUMP_PARTITION_LIST
195 DumpPartitionList(CurrentDisk);
196#endif
197
200 if (!NT_SUCCESS(Status))
201 {
204 return EXIT_SUCCESS;
205 }
206
208
209 return EXIT_SUCCESS;
210}
#define IDS_CREATE_PARTITION_INVALID_STYLE
Definition: resource.h:49
#define IDS_CREATE_PARTITION_FAIL
Definition: resource.h:47
#define IDS_CREATE_PARTITION_SUCCESS
Definition: resource.h:48
BOOL HasPrefix(_In_ PWSTR pszString, _In_ PWSTR pszPrefix, _Out_opt_ PWSTR *pszSuffix)
Definition: misc.c:58
VOID UpdateGptDiskLayout(_In_ PDISKENTRY DiskEntry, _In_ BOOL DeleteEntry)
Definition: partlist.c:2539
NTSTATUS WriteGptPartitions(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:2158
_ACRTIMP unsigned __int64 __cdecl _wcstoui64(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2885
#define ERANGE
Definition: errno.h:55
#define errno
Definition: errno.h:120
#define InsertTailList(ListHead, Entry)
@ Unformatted
Definition: partlist.h:34
#define CopyMemory
Definition: minwinbase.h:29
#define ULL(a, b)
Definition: format_msg.c:27
ULONG SectorCount
Definition: part_xbox.c:31
DWORD64 Attributes
Definition: diskpart.h:127
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
BOOLEAN IsPartitioned
Definition: partlist.h:82
BOOLEAN New
Definition: partlist.h:85
ULARGE_INTEGER SectorCount
Definition: partlist.h:70
struct _DISKENTRY * DiskEntry
Definition: partlist.h:66
BOOLEAN LogicalPartition
Definition: partlist.h:79
FORMATSTATE FormatState
Definition: diskpart.h:152
GPT_PARTITION_DATA Gpt
Definition: diskpart.h:142
LIST_ENTRY ListEntry
Definition: partlist.h:63
ULONG PartitionNumber
Definition: partlist.h:75
ULARGE_INTEGER StartSector
Definition: partlist.h:69
CHAR FileSystemName[9]
Definition: diskpart.h:151
uint16_t * PWSTR
Definition: typedefs.h:56

◆ CreateExtendedPartition()

EXIT_CODE CreateExtendedPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 214 of file create.c.

217{
218 PPARTENTRY PartEntry, NewPartEntry;
219 PLIST_ENTRY ListEntry;
220 ULONGLONG ullSize = 0ULL;
221 ULONGLONG ullSectorCount;
222#if 0
223 ULONGLONG ullOffset = 0ULL;
224 BOOL bNoErr = FALSE;
225#endif
226 INT i;
227 PWSTR pszSuffix = NULL;
229
230 if (CurrentDisk == NULL)
231 {
233 return EXIT_SUCCESS;
234 }
235
237 {
239 return EXIT_SUCCESS;
240 }
241 else if (CurrentDisk->PartitionStyle == PARTITION_STYLE_RAW)
242 {
243 CREATE_DISK DiskInfo;
245
246 DiskInfo.PartitionStyle = PARTITION_STYLE_MBR;
247 CreateSignature(&DiskInfo.Mbr.Signature);
248
250 if (!NT_SUCCESS(Status))
251 {
252 DPRINT1("CreateDisk() failed!\n");
253 return EXIT_SUCCESS;
254 }
255
258
260 }
261
262 for (i = 3; i < argc; i++)
263 {
264 if (_wcsicmp(argv[i], L"noerr") == 0)
265 {
266 /* noerr */
267 DPRINT("NoErr\n", pszSuffix);
268 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
269#if 0
270 bNoErr = TRUE;
271#endif
272 }
273 }
274
275 for (i = 3; i < argc; i++)
276 {
277 if (HasPrefix(argv[i], L"size=", &pszSuffix))
278 {
279 /* size=<N> (MB) */
280 DPRINT("Size : %s\n", pszSuffix);
281
282 ullSize = _wcstoui64(pszSuffix, NULL, 10);
283 if ((ullSize == 0) && (errno == ERANGE))
284 {
286 return EXIT_SUCCESS;
287 }
288 }
289 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
290 {
291 /* offset=<N> (KB) */
292 DPRINT("Offset : %s\n", pszSuffix);
293 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
294#if 0
295 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
296 if ((ullOffset == 0) && (errno == ERANGE))
297 {
299 return EXIT_SUCCESS;
300 }
301#endif
302 }
303 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
304 {
305 /* align=<N> */
306 DPRINT("Align : %s\n", pszSuffix);
307 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
308#if 0
309 bAlign = TRUE;
310#endif
311 }
312 else if (_wcsicmp(argv[i], L"noerr") == 0)
313 {
314 /* noerr - Already handled above */
315 }
316 else
317 {
319 return EXIT_SUCCESS;
320 }
321 }
322
323 DPRINT1("Size: %I64u\n", ullSize);
324#if 0
325 DPRINT1("Offset: %I64u\n", ullOffset);
326#endif
327
329 {
330 ConPuts(StdOut, L"No space left for an extended partition!\n");
331 return EXIT_SUCCESS;
332 }
333
335 {
336 ConPuts(StdOut, L"We already have an extended partition on this disk!\n");
337 return EXIT_SUCCESS;
338 }
339
340 if (ullSize != 0)
341 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
342 else
343 ullSectorCount = 0;
344
345 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
346
348
349 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
350 if (PartEntry->IsPartitioned)
351 {
352 ConPuts(StdOut, L"No disk space left for an extended partition!\n");
353 return EXIT_SUCCESS;
354 }
355
356 if (ullSectorCount == 0)
357 {
358 PartEntry->IsPartitioned = TRUE;
359 PartEntry->New = TRUE;
361 PartEntry->FormatState = Unformatted;
362 PartEntry->FileSystemName[0] = L'\0';
363
364 CurrentPartition = PartEntry;
366 }
367 else
368 {
369 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
370 {
371 PartEntry->IsPartitioned = TRUE;
372 PartEntry->New = TRUE;
374 PartEntry->FormatState = Unformatted;
375 PartEntry->FileSystemName[0] = L'\0';
376
377 CurrentPartition = PartEntry;
379 }
380 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
381 {
382 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
383 if (NewPartEntry == NULL)
384 {
385 ConPuts(StdOut, L"Memory allocation failed!\n");
386 return TRUE;
387 }
388
389 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
390
391 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
392 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
393
394 NewPartEntry->LogicalPartition = FALSE;
395 NewPartEntry->IsPartitioned = TRUE;
396 NewPartEntry->New = TRUE;
397 NewPartEntry->Mbr.PartitionType = PARTITION_EXTENDED;
398 NewPartEntry->FormatState = Unformatted;
399 NewPartEntry->FileSystemName[0] = L'\0';
400
401 PartEntry->StartSector.QuadPart += ullSectorCount;
402 PartEntry->SectorCount.QuadPart -= ullSectorCount;
403
404 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
405
406 CurrentPartition = NewPartEntry;
408 }
409 }
410
413 if (!NT_SUCCESS(Status))
414 {
417 return EXIT_SUCCESS;
418 }
419
421
422 return EXIT_SUCCESS;
423}
#define PARTITION_EXTENDED
Definition: disk.h:76
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122

◆ CreateGUID()

VOID CreateGUID ( _Out_ GUID pGuid)

Definition at line 152 of file misc.c.

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

Referenced by ConvertGPT(), CreateEfiPartition(), CreateMsrPartition(), and CreatePrimaryGptPartition().

◆ CreateLogicalPartition()

EXIT_CODE CreateLogicalPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 427 of file create.c.

430{
431 PPARTENTRY PartEntry, NewPartEntry;
432 PLIST_ENTRY ListEntry;
433 ULONGLONG ullSize = 0ULL;
434 ULONGLONG ullSectorCount;
435#if 0
436 ULONGLONG ullOffset = 0ULL;
437 BOOL bNoErr = FALSE;
438#endif
440 INT i, length;
441 PWSTR pszSuffix = NULL;
443
444 if (CurrentDisk == NULL)
445 {
447 return EXIT_SUCCESS;
448 }
449
451 {
453 return EXIT_SUCCESS;
454 }
455
456 for (i = 3; i < argc; i++)
457 {
458 if (_wcsicmp(argv[i], L"noerr") == 0)
459 {
460 /* noerr */
461 DPRINT("NoErr\n", pszSuffix);
462 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
463#if 0
464 bNoErr = TRUE;
465#endif
466 }
467 }
468
469 for (i = 3; i < argc; i++)
470 {
471 if (HasPrefix(argv[i], L"size=", &pszSuffix))
472 {
473 /* size=<N> (MB) */
474 DPRINT("Size : %s\n", pszSuffix);
475
476 ullSize = _wcstoui64(pszSuffix, NULL, 10);
477 if ((ullSize == 0) && (errno == ERANGE))
478 {
480 return EXIT_SUCCESS;
481 }
482 }
483 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
484 {
485 /* offset=<N> (KB) */
486 DPRINT("Offset : %s\n", pszSuffix);
487 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
488#if 0
489 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
490 if ((ullOffset == 0) && (errno == ERANGE))
491 {
493 return EXIT_SUCCESS;
494 }
495#endif
496 }
497 else if (HasPrefix(argv[i], L"id=", &pszSuffix))
498 {
499 /* id=<Byte> */
500 DPRINT("Id : %s\n", pszSuffix);
501
502 length = wcslen(pszSuffix);
503 if ((length == 1) || (length == 2))
504 {
505 /* Byte */
506 PartitionType = (UCHAR)wcstoul(pszSuffix, NULL, 16);
507 if ((PartitionType == 0) && (errno == ERANGE))
508 {
510 return EXIT_SUCCESS;
511 }
512 }
513 else
514 {
516 return EXIT_SUCCESS;
517 }
518 }
519 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
520 {
521 /* align=<N> */
522 DPRINT("Align : %s\n", pszSuffix);
523 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
524#if 0
525 bAlign = TRUE;
526#endif
527 }
528 else if (_wcsicmp(argv[i], L"noerr") == 0)
529 {
530 /* noerr - Already handled above */
531 }
532 else
533 {
535 return EXIT_SUCCESS;
536 }
537 }
538
539 DPRINT1("Size: %I64u\n", ullSize);
540#if 0
541 DPRINT1("Offset: %I64u\n", ullOffset);
542#endif
543 DPRINT1("Partition Type: %hx\n", PartitionType);
544
545 if (ullSize != 0)
546 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
547 else
548 ullSectorCount = 0;
549
550 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
551
552 for (ListEntry = CurrentDisk->LogicalPartListHead.Flink;
553 ListEntry != &CurrentDisk->LogicalPartListHead;
554 ListEntry = ListEntry->Flink)
555 {
556 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
557 if (PartEntry->IsPartitioned)
558 continue;
559
560 if (ullSectorCount == 0)
561 {
562 PartEntry->IsPartitioned = TRUE;
563 PartEntry->New = TRUE;
564 PartEntry->Mbr.PartitionType = PartitionType;
565 PartEntry->FormatState = Unformatted;
566 PartEntry->FileSystemName[0] = L'\0';
567
568 CurrentPartition = PartEntry;
570 break;
571 }
572 else
573 {
574 if (PartEntry->SectorCount.QuadPart == ullSectorCount)
575 {
576 PartEntry->IsPartitioned = TRUE;
577 PartEntry->New = TRUE;
578 PartEntry->Mbr.PartitionType = PartitionType;
579 PartEntry->FormatState = Unformatted;
580 PartEntry->FileSystemName[0] = L'\0';
581
582 CurrentPartition = PartEntry;
584 break;
585 }
586 else if (PartEntry->SectorCount.QuadPart > ullSectorCount)
587 {
588 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
589 if (NewPartEntry == NULL)
590 {
591 ConPuts(StdOut, L"Memory allocation failed!\n");
592 return TRUE;
593 }
594
595 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
596
597 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
598 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
599
600 NewPartEntry->LogicalPartition = TRUE;
601 NewPartEntry->IsPartitioned = TRUE;
602 NewPartEntry->New = TRUE;
603 NewPartEntry->Mbr.PartitionType = PartitionType;
604 NewPartEntry->FormatState = Unformatted;
605 NewPartEntry->FileSystemName[0] = L'\0';
606
607 PartEntry->StartSector.QuadPart += ullSectorCount;
608 PartEntry->SectorCount.QuadPart -= ullSectorCount;
609
610 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
611
612 CurrentPartition = NewPartEntry;
614 break;
615 }
616 }
617 }
618
621 if (!NT_SUCCESS(Status))
622 {
625 return EXIT_SUCCESS;
626 }
627
629
630 return EXIT_SUCCESS;
631}
#define PARTITION_HUGE
Definition: disk.h:77
_ACRTIMP __msvcrt_ulong __cdecl wcstoul(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2912
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
CHAR PartitionType
Definition: part_xbox.c:32
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ CreateMsrPartition()

EXIT_CODE CreateMsrPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 635 of file create.c.

638{
639 PPARTENTRY PartEntry, NewPartEntry;
640 PLIST_ENTRY ListEntry;
641 ULONGLONG ullSize = 0ULL;
642 ULONGLONG ullSectorCount;
643#if 0
644 ULONGLONG ullOffset = 0ULL;
645 BOOL bNoErr = FALSE;
646#endif
647 INT i;
648 PWSTR pszSuffix = NULL;
650
651 DPRINT1("CreateMsrPartition()\n");
652
653 if (CurrentDisk == NULL)
654 {
656 return EXIT_SUCCESS;
657 }
658
660 {
662 return EXIT_SUCCESS;
663 }
664
665 for (i = 3; i < argc; i++)
666 {
667 if (_wcsicmp(argv[i], L"noerr") == 0)
668 {
669 /* noerr */
670 DPRINT("NoErr\n", pszSuffix);
671 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
672#if 0
673 bNoErr = TRUE;
674#endif
675 }
676 }
677
678 for (i = 3; i < argc; i++)
679 {
680 if (HasPrefix(argv[i], L"size=", &pszSuffix))
681 {
682 /* size=<N> (MB) */
683 DPRINT("Size : %s\n", pszSuffix);
684
685 ullSize = _wcstoui64(pszSuffix, NULL, 10);
686 if ((ullSize == 0) && (errno == ERANGE))
687 {
689 return EXIT_SUCCESS;
690 }
691 }
692 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
693 {
694 /* offset=<N> (KB) */
695 DPRINT("Offset : %s\n", pszSuffix);
696 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
697#if 0
698 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
699 if ((ullOffset == 0) && (errno == ERANGE))
700 {
702 return EXIT_SUCCESS;
703 }
704#endif
705 }
706 else if (_wcsicmp(argv[i], L"noerr") == 0)
707 {
708 /* noerr - Already handled above */
709 }
710 else
711 {
713 return EXIT_SUCCESS;
714 }
715 }
716
717 DPRINT1("Size: %I64u\n", ullSize);
718#if 0
719 DPRINT1("Offset: %I64u\n", ullOffset);
720#endif
721
722 /* Size */
723 if (ullSize != 0)
724 ullSectorCount = (ullSize * 1024 * 1024) / CurrentDisk->BytesPerSector;
725 else
726 ullSectorCount = 0;
727
728 DPRINT1("SectorCount: %I64u\n", ullSectorCount);
729
730#ifdef DUMP_PARTITION_LIST
731 DumpPartitionList(CurrentDisk);
732#endif
733
734 for (ListEntry = CurrentDisk->PrimaryPartListHead.Flink;
735 ListEntry != &CurrentDisk->PrimaryPartListHead;
736 ListEntry = ListEntry->Flink)
737 {
738 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
739 if (PartEntry->IsPartitioned)
740 continue;
741
742 if (ullSectorCount == 0)
743 {
744 DPRINT("Claim whole unused space!\n");
745 PartEntry->IsPartitioned = TRUE;
746 PartEntry->New = TRUE;
747 CopyMemory(&PartEntry->Gpt.PartitionType, &PARTITION_MSFT_RESERVED_GUID, sizeof(GUID));
748 CreateGUID(&PartEntry->Gpt.PartitionId);
749 PartEntry->Gpt.Attributes = 0ULL;
750 PartEntry->PartitionNumber = 0;
751 PartEntry->FormatState = Unformatted;
752 PartEntry->FileSystemName[0] = L'\0';
753
754 CurrentPartition = PartEntry;
756 break;
757 }
758 else
759 {
760 if (ullSectorCount == PartEntry->SectorCount.QuadPart)
761 {
762 DPRINT("Claim matching unused space!\n");
763 PartEntry->IsPartitioned = TRUE;
764 PartEntry->New = TRUE;
765 CopyMemory(&PartEntry->Gpt.PartitionType, &PARTITION_MSFT_RESERVED_GUID, sizeof(GUID));
766 CreateGUID(&PartEntry->Gpt.PartitionId);
767 PartEntry->Gpt.Attributes = 0ULL;
768 PartEntry->PartitionNumber = 0;
769 PartEntry->FormatState = Unformatted;
770 PartEntry->FileSystemName[0] = L'\0';
771
772 CurrentPartition = PartEntry;
774 break;
775 }
776 else if (ullSectorCount < PartEntry->SectorCount.QuadPart)
777 {
778 DPRINT("Claim part of unused space\n");
779 NewPartEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PPARTENTRY));
780 if (NewPartEntry == NULL)
781 {
782 ConPuts(StdOut, L"Memory allocation failed!\n");
783 return TRUE;
784 }
785
786 NewPartEntry->DiskEntry = PartEntry->DiskEntry;
787
788 NewPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
789 NewPartEntry->SectorCount.QuadPart = ullSectorCount;
790
791 NewPartEntry->LogicalPartition = FALSE;
792 NewPartEntry->IsPartitioned = TRUE;
793 NewPartEntry->New = TRUE;
794 CopyMemory(&NewPartEntry->Gpt.PartitionType, &PARTITION_MSFT_RESERVED_GUID, sizeof(GUID));
795 CreateGUID(&NewPartEntry->Gpt.PartitionId);
796 NewPartEntry->Gpt.Attributes = 0ULL;
797 NewPartEntry->PartitionNumber = 0;
798 NewPartEntry->FormatState = Unformatted;
799 NewPartEntry->FileSystemName[0] = L'\0';
800
801 PartEntry->StartSector.QuadPart += ullSectorCount;
802 PartEntry->SectorCount.QuadPart -= ullSectorCount;
803
804 InsertTailList(ListEntry, &NewPartEntry->ListEntry);
805
806 CurrentPartition = NewPartEntry;
808 break;
809 }
810 }
811 }
812
813#ifdef DUMP_PARTITION_LIST
814 DumpPartitionList(CurrentDisk);
815#endif
816
819 if (!NT_SUCCESS(Status))
820 {
823 return EXIT_SUCCESS;
824 }
825
827
828 return EXIT_SUCCESS;
829}

◆ CreatePartitionList()

NTSTATUS CreatePartitionList ( VOID  )

Definition at line 1988 of file partlist.c.

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

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

◆ CreatePrimaryPartition()

EXIT_CODE CreatePrimaryPartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 1094 of file create.c.

1097{
1098 ULONGLONG ullSize = 0ULL;
1099#if 0
1100 ULONGLONG ullOffset = 0ULL;
1101 BOOL bNoErr = FALSE;
1102#endif
1103 INT i;
1104 PWSTR pszSuffix = NULL;
1105 PWSTR pszPartitionType = NULL;
1106
1107 if (CurrentDisk == NULL)
1108 {
1110 return EXIT_SUCCESS;
1111 }
1112
1113 if (CurrentDisk->PartitionStyle == PARTITION_STYLE_RAW)
1114 {
1115 CREATE_DISK DiskInfo;
1117
1118 DiskInfo.PartitionStyle = PARTITION_STYLE_MBR;
1119 CreateSignature(&DiskInfo.Mbr.Signature);
1120
1121 Status = CreateDisk(CurrentDisk->DiskNumber, &DiskInfo);
1122 if (!NT_SUCCESS(Status))
1123 {
1124 DPRINT1("CreateDisk() failed!\n");
1125 return EXIT_SUCCESS;
1126 }
1127
1130
1132 }
1133
1134 for (i = 3; i < argc; i++)
1135 {
1136 if (_wcsicmp(argv[i], L"noerr") == 0)
1137 {
1138 /* noerr */
1139 DPRINT("NoErr\n", pszSuffix);
1140 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
1141#if 0
1142 bNoErr = TRUE;
1143#endif
1144 }
1145 }
1146
1147 for (i = 3; i < argc; i++)
1148 {
1149 if (HasPrefix(argv[i], L"size=", &pszSuffix))
1150 {
1151 /* size=<N> (MB) */
1152 DPRINT("Size : %s\n", pszSuffix);
1153
1154 ullSize = _wcstoui64(pszSuffix, NULL, 10);
1155 if ((ullSize == 0) && (errno == ERANGE))
1156 {
1158 return EXIT_SUCCESS;
1159 }
1160 }
1161 else if (HasPrefix(argv[i], L"offset=", &pszSuffix))
1162 {
1163 /* offset=<N> (KB) */
1164 DPRINT("Offset : %s\n", pszSuffix);
1165 ConPuts(StdOut, L"The OFFSET option is not supported yet!\n");
1166#if 0
1167 ullOffset = _wcstoui64(pszSuffix, NULL, 10);
1168 if ((ullOffset == 0) && (errno == ERANGE))
1169 {
1171 return EXIT_SUCCESS;
1172 }
1173#endif
1174 }
1175 else if (HasPrefix(argv[i], L"id=", &pszSuffix))
1176 {
1177 /* id=<Byte>|<GUID> */
1178 DPRINT("Id : %s\n", pszSuffix);
1179 pszPartitionType = pszSuffix;
1180 }
1181 else if (HasPrefix(argv[i], L"align=", &pszSuffix))
1182 {
1183 /* align=<N> */
1184 DPRINT("Align : %s\n", pszSuffix);
1185 ConPuts(StdOut, L"The ALIGN option is not supported yet!\n");
1186#if 0
1187 bAlign = TRUE;
1188#endif
1189 }
1190 else if (_wcsicmp(argv[i], L"noerr") == 0)
1191 {
1192 /* noerr - Alread handled above */
1193 }
1194 else
1195 {
1197 return EXIT_SUCCESS;
1198 }
1199 }
1200
1201 DPRINT("Size: %I64u\n", ullSize);
1202#if 0
1203 DPRINT1("Offset: %I64u\n", ullOffset);
1204#endif
1205
1207 {
1208 DPRINT("Partition Type: %s\n", pszPartitionType);
1209 CreatePrimaryMbrPartition(ullSize, pszPartitionType);
1210 }
1212 {
1213 CreatePrimaryGptPartition(ullSize, pszPartitionType);
1214 }
1215
1216 return EXIT_SUCCESS;
1217}
static VOID CreatePrimaryGptPartition(_In_ ULONGLONG ullSize, _In_ PWSTR pszPartitionType)
Definition: create.c:961
static VOID CreatePrimaryMbrPartition(_In_ ULONGLONG ullSize, _In_ PWSTR pszPartitionType)
Definition: create.c:834

◆ CreateSignature()

VOID CreateSignature ( _Out_ PDWORD  pSignature)

Definition at line 168 of file misc.c.

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

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

◆ CreateVolumeList()

NTSTATUS CreateVolumeList ( VOID  )

Definition at line 1967 of file partlist.c.

1968{
1969 HANDLE hVolume = INVALID_HANDLE_VALUE;
1970 WCHAR szVolumeName[MAX_PATH];
1971 ULONG ulVolumeNumber = 0;
1972 BOOL Success;
1973
1975
1977
1978 hVolume = FindFirstVolumeW(szVolumeName, ARRAYSIZE(szVolumeName));
1979 if (hVolume == INVALID_HANDLE_VALUE)
1980 {
1981
1982 return STATUS_UNSUCCESSFUL;
1983 }
1984
1985 AddVolumeToList(ulVolumeNumber++, szVolumeName);
1986
1987 for (;;)
1988 {
1989 Success = FindNextVolumeW(hVolume, szVolumeName, ARRAYSIZE(szVolumeName));
1990 if (!Success)
1991 {
1992 break;
1993 }
1994
1995 AddVolumeToList(ulVolumeNumber++, szVolumeName);
1996 }
1997
1998 FindVolumeClose(hVolume);
1999
2000 return STATUS_SUCCESS;
2001}
#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:73
static VOID AddVolumeToList(ULONG ulVolumeNumber, PWSTR pszVolumeName)
Definition: partlist.c:1834
PVOLENTRY CurrentVolume
Definition: partlist.c:77
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by rescan_main(), and wmain().

◆ DeleteDisk()

EXIT_CODE DeleteDisk ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 28 of file delete.c.

31{
32 return EXIT_SUCCESS;
33}

◆ DeleteDriveLetter()

BOOL DeleteDriveLetter ( _In_ WCHAR  DriveLetter)

Definition at line 338 of file mountmgr.c.

340{
344 ULONG InputBufferLength, DosDeviceNameLength;
345 HANDLE MountMgrHandle = NULL;
348 BOOL Ret = TRUE;
349
350 DPRINT1("DeleteDriveLetter(%c)\n", DriveLetter);
351
352 /* Setup the device name of the letter to delete */
353 swprintf(DosDeviceName, L"\\DosDevices\\%c:", DriveLetter);
354 DosDeviceNameLength = wcslen(DosDeviceName) * sizeof(WCHAR);
355
356 /* Allocate the input buffer for MountMgr */
357 InputBufferLength = DosDeviceNameLength + sizeof(MOUNTMGR_MOUNT_POINT);
359 if (InputBuffer == NULL)
360 {
361 DPRINT1("InputBuffer allocation failed!\n");
362 return FALSE;
363 }
364
365 /* Fill it in */
366// RtlZeroMemory(InputBuffer, InputBufferLength);
367 InputBuffer->SymbolicLinkNameOffset = sizeof(MOUNTMGR_MOUNT_POINT);
368 InputBuffer->SymbolicLinkNameLength = DosDeviceNameLength;
369 RtlCopyMemory(&InputBuffer[1], DosDeviceName, DosDeviceNameLength);
370
371 /* Allocate big enough output buffer (we don't care about the output) */
373 if (OutputBuffer == NULL)
374 {
375 DPRINT1("OutputBuffer allocation failed!\n");
376 Ret = FALSE;
377 goto done;
378 }
379
380DPRINT1("\n");
382 if (!NT_SUCCESS(Status))
383 {
384 DPRINT1("OpenMountManager() failed (Status 0x%08lx)\n", Status);
385 Ret = FALSE;
386 goto done;
387 }
388
389DPRINT1("\n");
390 Status = NtDeviceIoControlFile(MountMgrHandle,
391 NULL,
392 NULL,
393 NULL,
394 &Iosb,
399 0x1000);
400 if (!NT_SUCCESS(Status))
401 {
402 DPRINT1("NtDeviceIoControlFile() failed (Status 0x%08lx)\n", Status);
403 Ret = FALSE;
404 goto done;
405 }
406
407DPRINT1("\n");
408done:
409 if (MountMgrHandle)
410 NtClose(MountMgrHandle);
411
412 if (InputBuffer)
413 RtlFreeHeap(RtlGetProcessHeap(), 0, InputBuffer);
414
415 if (OutputBuffer)
416 RtlFreeHeap(RtlGetProcessHeap(), 0, OutputBuffer);
417
418 return Ret;
419}
#define GetProcessHeap()
Definition: compat.h:736
#define IOCTL_MOUNTMGR_DELETE_POINTS
Definition: imports.h:122
struct _MOUNTMGR_MOUNT_POINT MOUNTMGR_MOUNT_POINT
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863

Referenced by assign_main(), and remove_main().

◆ DeletePartition()

EXIT_CODE DeletePartition ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 274 of file delete.c.

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

◆ DeleteVolume()

EXIT_CODE DeleteVolume ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 341 of file delete.c.

344{
345 return EXIT_SUCCESS;
346}

◆ DestroyPartitionList()

VOID DestroyPartitionList ( VOID  )

Definition at line 1611 of file partlist.c.

1612{
1613 PDISKENTRY DiskEntry;
1614 PBIOSDISKENTRY BiosDiskEntry;
1615 PPARTENTRY PartEntry;
1617
1618 CurrentDisk = NULL;
1620
1621 /* Release disk and partition info */
1622 while (!IsListEmpty(&DiskListHead))
1623 {
1625 DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
1626
1627 /* Release driver name */
1628 RtlFreeUnicodeString(&DiskEntry->DriverName);
1629
1630 /* Release primary partition list */
1631 while (!IsListEmpty(&DiskEntry->PrimaryPartListHead))
1632 {
1634 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1635
1636 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1637 }
1638
1639 /* Release logical partition list */
1640 while (!IsListEmpty(&DiskEntry->LogicalPartListHead))
1641 {
1643 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
1644
1645 RtlFreeHeap(RtlGetProcessHeap(), 0, PartEntry);
1646 }
1647
1648 /* Release layout buffer */
1649 if (DiskEntry->LayoutBuffer != NULL)
1650 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry->LayoutBuffer);
1651
1652 if (DiskEntry->Description != NULL)
1653 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry->Description);
1654
1655 if (DiskEntry->Location != NULL)
1656 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry->Location);
1657
1658 /* Release disk entry */
1659 RtlFreeHeap(RtlGetProcessHeap(), 0, DiskEntry);
1660 }
1661
1662 /* Release the bios disk info */
1663 while (!IsListEmpty(&BiosDiskListHead))
1664 {
1666 BiosDiskEntry = CONTAINING_RECORD(Entry, BIOSDISKENTRY, ListEntry);
1667
1668 RtlFreeHeap(RtlGetProcessHeap(), 0, BiosDiskEntry);
1669 }
1670}
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
UNICODE_STRING DriverName
Definition: partlist.h:141
PWSTR Location
Definition: diskpart.h:189
PWSTR Description
Definition: diskpart.h:188
LIST_ENTRY BiosDiskListHead
Definition: partlist.c:72
LIST_ENTRY DiskListHead
Definition: partlist.c:71
PPARTENTRY CurrentPartition
Definition: partlist.c:76

◆ DestroyVolumeList()

VOID DestroyVolumeList ( VOID  )

Definition at line 2005 of file partlist.c.

2006{
2008 PVOLENTRY VolumeEntry;
2009
2011
2012 /* Release disk and partition info */
2013 while (!IsListEmpty(&VolumeListHead))
2014 {
2016 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
2017
2018 if (VolumeEntry->pszLabel)
2019 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
2020
2021 if (VolumeEntry->pszFilesystem)
2022 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
2023
2024 if (VolumeEntry->pExtents)
2025 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pExtents);
2026
2027 /* Release disk entry */
2028 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
2029 }
2030}
PVOLUME_DISK_EXTENTS pExtents
Definition: diskpart.h:253
PWSTR pszFilesystem
Definition: diskpart.h:244
PWSTR pszLabel
Definition: diskpart.h:243

Referenced by rescan_main(), and wmain().

◆ detach_main()

EXIT_CODE detach_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file detach.c.

15{
16 return EXIT_SUCCESS;
17}

◆ DetailDisk()

EXIT_CODE DetailDisk ( INT  argc,
PWSTR argv 
)

◆ DetailPartition()

EXIT_CODE DetailPartition ( INT  argc,
PWSTR argv 
)

◆ DetailVolume()

EXIT_CODE DetailVolume ( INT  argc,
PWSTR argv 
)

◆ DismountVolume()

NTSTATUS DismountVolume ( _In_ PPARTENTRY  PartEntry)

Definition at line 2687 of file partlist.c.

2689{
2691 NTSTATUS LockStatus;
2695 HANDLE PartitionHandle;
2697
2698 /* Check whether the partition is valid and was mounted by the system */
2699 if (!PartEntry->IsPartitioned ||
2700 IsContainerPartition(PartEntry->Mbr.PartitionType) ||
2701 !IsRecognizedPartition(PartEntry->Mbr.PartitionType) ||
2702 PartEntry->FormatState == UnknownFormat ||
2703 // NOTE: If FormatState == Unformatted but *FileSystem != 0 this means
2704 // it has been usually mounted with RawFS and thus needs to be dismounted.
2705/* !*PartEntry->FileSystem || */
2706 PartEntry->PartitionNumber == 0)
2707 {
2708 /* The partition is not mounted, so just return success */
2709 return STATUS_SUCCESS;
2710 }
2711
2712 ASSERT(PartEntry->Mbr.PartitionType != PARTITION_ENTRY_UNUSED);
2713
2714 /* Open the volume */
2716 L"\\Device\\Harddisk%lu\\Partition%lu",
2717 PartEntry->DiskEntry->DiskNumber,
2718 PartEntry->PartitionNumber);
2720
2722 &Name,
2724 NULL,
2725 NULL);
2726
2727 Status = NtOpenFile(&PartitionHandle,
2733 if (!NT_SUCCESS(Status))
2734 {
2735 DPRINT1("ERROR: Cannot open volume %wZ for dismounting! (Status 0x%lx)\n", &Name, Status);
2736 return Status;
2737 }
2738
2739 /* Lock the volume */
2740 LockStatus = NtFsControlFile(PartitionHandle,
2741 NULL,
2742 NULL,
2743 NULL,
2746 NULL,
2747 0,
2748 NULL,
2749 0);
2750 if (!NT_SUCCESS(LockStatus))
2751 {
2752 DPRINT1("WARNING: Failed to lock volume! Operations may fail! (Status 0x%lx)\n", LockStatus);
2753 }
2754
2755 /* Dismount the volume */
2756 Status = NtFsControlFile(PartitionHandle,
2757 NULL,
2758 NULL,
2759 NULL,
2762 NULL,
2763 0,
2764 NULL,
2765 0);
2766 if (!NT_SUCCESS(Status))
2767 {
2768 DPRINT1("Failed to unmount volume (Status 0x%lx)\n", Status);
2769 }
2770
2771 /* Unlock the volume */
2772 LockStatus = NtFsControlFile(PartitionHandle,
2773 NULL,
2774 NULL,
2775 NULL,
2778 NULL,
2779 0,
2780 NULL,
2781 0);
2782 if (!NT_SUCCESS(LockStatus))
2783 {
2784 DPRINT1("Failed to unlock volume (Status 0x%lx)\n", LockStatus);
2785 }
2786
2787 /* Close the volume */
2788 NtClose(PartitionHandle);
2789
2790 return Status;
2791}
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:71
@ UnknownFormat
Definition: partlist.h:36
#define ASSERT(a)
Definition: mode.c:44
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
NTSYSAPI NTSTATUS NTAPI NtFsControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define IsRecognizedPartition(PartitionType)
Definition: ntdddisk.h:342

◆ DumpDisk()

EXIT_CODE DumpDisk ( _In_ INT  argc,
_In_ LPWSTR argv 
)

◆ DumpPartition()

EXIT_CODE DumpPartition ( _In_ INT  argc,
_In_ LPWSTR argv 
)

◆ 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
wcsncpy
WINBASEAPI _In_ DWORD nLength
Definition: wincon.h:682

◆ DuplicateString()

PWSTR DuplicateString ( _In_ PWSTR  pszInString)

Definition at line 129 of file misc.c.

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

◆ expand_main()

EXIT_CODE expand_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file expand.c.

15{
16 return EXIT_SUCCESS;
17}

◆ extend_main()

EXIT_CODE extend_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file extend.c.

15{
16 return EXIT_SUCCESS;
17}

◆ filesystems_main()

EXIT_CODE filesystems_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 88 of file filesystems.c.

91{
92 if (CurrentVolume == NULL)
93 {
95 return EXIT_SUCCESS;
96 }
97
98 ConPuts(StdOut, L"\n");
99
102
103 return EXIT_SUCCESS;
104}
#define IDS_SELECT_NO_VOLUME
Definition: resource.h:130
PVOLENTRY CurrentVolume
Definition: partlist.c:77
static VOID ShowInstalledFileSystems(_In_ PVOLENTRY VolumeEntry)
Definition: filesystems.c:49
static VOID ShowFileSystemInfo(_In_ PVOLENTRY VolumeEntry)
Definition: filesystems.c:16

◆ format_main()

EXIT_CODE format_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 95 of file format.c.

98{
99 UNICODE_STRING usDriveRoot;
101 PWSTR pszSuffix = NULL;
102 PWSTR pszFileSystem = NULL;
103 PWSTR pszLabel = NULL;
104 BOOLEAN bQuickFormat = FALSE;
105 ULONG ulClusterSize = 0;
107 PULIB_FORMAT pFormat = NULL;
108// FMIFS_MEDIA_FLAG MediaType = FMIFS_HARDDISK;
109 INT i;
111
112
113 if (CurrentVolume == NULL)
114 {
116 return EXIT_SUCCESS;
117 }
118
119 for (i = 1; i < argc; i++)
120 {
121 if (_wcsicmp(argv[i], L"noerr") == 0)
122 {
123 /* noerr */
124 DPRINT("NoErr\n", pszSuffix);
125 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
126#if 0
127 bNoErr = TRUE;
128#endif
129 }
130 }
131
132 for (i = 1; i < argc; i++)
133 {
134 ConPrintf(StdOut, L"%s\n", argv[i]);
135
136 if (HasPrefix(argv[i], L"fs=", &pszSuffix))
137 {
138 /* fs=<fs> */
139 pszFileSystem = pszSuffix;
140 }
141 else if (HasPrefix(argv[i], L"revision=", &pszSuffix))
142 {
143 /* revision=<X.XX> */
144 ConPuts(StdOut, L"The REVISION option is not supported yet!\n");
145 }
146 else if (HasPrefix(argv[i], L"label=", &pszSuffix))
147 {
148 /* label=<"label"> */
149 pszLabel = pszSuffix;
150 }
151 else if (HasPrefix(argv[i], L"unit=", &pszSuffix))
152 {
153 /* unit=<N> */
154 ulClusterSize = wcstoul(pszSuffix, NULL, 0);
155 if ((ulClusterSize == 0) && (errno == ERANGE))
156 {
158 goto done;
159 }
160 }
161 else if (_wcsicmp(argv[i], L"recommended") == 0)
162 {
163 /* recommended */
164 ConPuts(StdOut, L"The RECOMMENDED option is not supported yet!\n");
165 }
166 else if (_wcsicmp(argv[i], L"quick") == 0)
167 {
168 /* quick */
169 bQuickFormat = TRUE;
170 }
171 else if (_wcsicmp(argv[i], L"compress") == 0)
172 {
173 /* compress */
174 ConPuts(StdOut, L"The COMPRESS option is not supported yet!\n");
175 }
176 else if (_wcsicmp(argv[i], L"override") == 0)
177 {
178 /* override */
179 ConPuts(StdOut, L"The OVERRIDE option is not supported yet!\n");
180 }
181 else if (_wcsicmp(argv[i], L"duplicate") == 0)
182 {
183 /* duplicate */
184 ConPuts(StdOut, L"The DUPLICATE option is not supported yet!\n");
185 }
186 else if (_wcsicmp(argv[i], L"nowait") == 0)
187 {
188 /* nowait */
189 ConPuts(StdOut, L"The NOWAIT option is not supported yet!\n");
190 }
191 else if (_wcsicmp(argv[i], L"noerr") == 0)
192 {
193 /* noerr - Already handled above */
194 }
195 else
196 {
198 return EXIT_SUCCESS;
199 }
200 }
201
202 DPRINT("VolumeName : %S\n", CurrentVolume->VolumeName);
203 DPRINT("DeviceName : %S\n", CurrentVolume->DeviceName);
204 DPRINT("DriveLetter : %C\n", CurrentVolume->DriveLetter);
205#if 0
206 switch (CurrentVolume->VolumeType)
207 {
209 MediaType = FMIFS_REMOVABLE; // ???
210 break;
211
213 MediaType = FMIFS_HARDDISK;
214 break;
215
217 MediaType = FMIFS_REMOVABLE; // ???
218 break;
219
221 default:
222 MediaType = FMIFS_REMOVABLE; // ???
223 break;
224 }
225#endif
226
227 DPRINT("FileSystem: %S\n", pszFileSystem);
228 DPRINT("Label: %S\n", pszLabel);
229 DPRINT("Quick: %d\n", bQuickFormat);
230 DPRINT("ClusterSize: %lu\n", ulClusterSize);
231
233
234 /* Remove trailing backslash */
235 if (usDriveRoot.Buffer[(usDriveRoot.Length / sizeof(WCHAR)) - 1] == L'\\')
236 {
237 usDriveRoot.Buffer[(usDriveRoot.Length / sizeof(WCHAR)) - 1] = UNICODE_NULL;
238 usDriveRoot.Length -= sizeof(WCHAR);
239 }
240
241 DPRINT("DriveRoot: %wZ\n", &usDriveRoot);
242
243 /* Use the FAT filesystem as default */
244 if (pszFileSystem == NULL)
245 pszFileSystem = L"FAT";
246
247 BOOLEAN bBackwardCompatible = FALSE; // Default to latest FS versions.
248 if (_wcsicmp(pszFileSystem, L"FAT") == 0)
249 bBackwardCompatible = TRUE;
250 // else if (wcsicmp(pszFileSystem, L"FAT32") == 0)
251 // bBackwardCompatible = FALSE;
252
253 if (pszLabel == NULL)
254 pszLabel = L"";
255
257
258 if (!GetFsModule(pszFileSystem, &hModule))
259 {
260 DPRINT1("GetFsModule() failed\n");
261 goto done;
262 }
263
264 pFormat = (PULIB_FORMAT)GetProcAddress(hModule, "Format");
265 if (pFormat)
266 {
267 Success = (pFormat)(&usDriveRoot,
269 bQuickFormat,
270 bBackwardCompatible,
271 FMIFS_HARDDISK, //MediaType,
273 ulClusterSize);
274 }
275
276done:
277 ConPuts(StdOut, L"\n");
278 if (Success)
280 else
282
283 if (hModule)
285
286 RtlFreeUnicodeString(&usDriveRoot);
287
288 return EXIT_SUCCESS;
289}
unsigned char BOOLEAN
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
static BOOL GetFsModule(_In_ PWSTR pszFileSystem, _Out_ HMODULE *phModule)
Definition: format.c:18
BOOLEAN WINAPI FormatCallback(CALLBACKCOMMAND Command, ULONG Size, PVOID Argument)
Definition: format.c:68
#define IDS_FORMAT_FAIL
Definition: resource.h:87
#define IDS_FORMAT_SUCCESS
Definition: resource.h:88
WCHAR LabelString[12]
Definition: format.c:75
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
@ FMIFS_REMOVABLE
Definition: fmifs.h:65
@ FMIFS_HARDDISK
Definition: fmifs.h:66
BOOLEAN(NTAPI * PULIB_FORMAT)(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN QuickFormat, IN BOOLEAN BackwardCompatible, IN MEDIA_TYPE MediaType, IN PUNICODE_STRING Label, IN ULONG ClusterSize)
Definition: fmifs.h:233
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
HMODULE hModule
Definition: netsh.c:17
VOLUME_TYPE VolumeType
Definition: diskpart.h:245
WCHAR VolumeName[MAX_PATH]
Definition: diskpart.h:237
WCHAR DeviceName[MAX_PATH]
Definition: diskpart.h:238
WCHAR DriveLetter
Definition: diskpart.h:241

◆ GetAutomountState()

BOOL GetAutomountState ( _Out_ PBOOL  State)

Definition at line 46 of file mountmgr.c.

48{
49 HANDLE MountMgrHandle;
53
54 DPRINT("ShowAutomountState()\n");
55
56 Status = OpenMountManager(&MountMgrHandle, GENERIC_READ);
57 if (!NT_SUCCESS(Status))
58 {
59 DPRINT1("OpenMountManager() Status 0x%08lx\n", Status);
60 return FALSE;
61 }
62
63 Status = NtDeviceIoControlFile(MountMgrHandle,
64 NULL,
65 NULL,
66 NULL,
67 &Iosb,
69 NULL,
70 0,
71 &AutoMount,
72 sizeof(AutoMount));
73
74 NtClose(MountMgrHandle);
75
76 if (!NT_SUCCESS(Status))
77 {
78 DPRINT1("NtDeviceIoControlFile() Status 0x%08lx\n", Status);
79 return FALSE;
80 }
81
82 if (State)
83 *State = (AutoMount.CurrentState == Enabled);
84
85 return TRUE;
86}
@ Enabled
Definition: mountmgr.h:179
#define IOCTL_MOUNTMGR_QUERY_AUTO_MOUNT
Definition: mountmgr.h:172
MOUNTMGR_AUTO_MOUNT_STATE CurrentState
Definition: mountmgr.h:183

Referenced by automount_main().

◆ GetNextUnpartitionedEntry()

PPARTENTRY GetNextUnpartitionedEntry ( _In_ PPARTENTRY  PartEntry)

Definition at line 2658 of file partlist.c.

2660{
2661 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
2662 PPARTENTRY NextPartEntry;
2663 PLIST_ENTRY ListHead;
2664
2665 if (PartEntry->LogicalPartition)
2666 ListHead = &DiskEntry->LogicalPartListHead;
2667 else
2668 ListHead = &DiskEntry->PrimaryPartListHead;
2669
2670 if (PartEntry->ListEntry.Flink != ListHead)
2671 {
2672 NextPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Flink,
2673 PARTENTRY,
2674 ListEntry);
2675 if (!NextPartEntry->IsPartitioned)
2676 {
2678 return NextPartEntry;
2679 }
2680 }
2681
2682 return NULL;
2683}

Referenced by DeleteGptPartition(), and DeleteMbrPartition().

◆ GetPrevUnpartitionedEntry()

PPARTENTRY GetPrevUnpartitionedEntry ( _In_ PPARTENTRY  PartEntry)

Definition at line 2629 of file partlist.c.

2631{
2632 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
2633 PPARTENTRY PrevPartEntry;
2634 PLIST_ENTRY ListHead;
2635
2636 if (PartEntry->LogicalPartition)
2637 ListHead = &DiskEntry->LogicalPartListHead;
2638 else
2639 ListHead = &DiskEntry->PrimaryPartListHead;
2640
2641 if (PartEntry->ListEntry.Blink != ListHead)
2642 {
2643 PrevPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Blink,
2644 PARTENTRY,
2645 ListEntry);
2646 if (!PrevPartEntry->IsPartitioned)
2647 {
2649 return PrevPartEntry;
2650 }
2651 }
2652
2653 return NULL;
2654}

Referenced by DeleteGptPartition(), and DeleteMbrPartition().

◆ GetPrimaryPartitionCount()

ULONG GetPrimaryPartitionCount ( _In_ PDISKENTRY  DiskEntry)

Definition at line 2266 of file partlist.c.

2268{
2270 PPARTENTRY PartEntry;
2271 ULONG Count = 0;
2272
2273 for (Entry = DiskEntry->PrimaryPartListHead.Flink;
2274 Entry != &DiskEntry->PrimaryPartListHead;
2275 Entry = Entry->Flink)
2276 {
2277 PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
2278 if (PartEntry->IsPartitioned)
2279 Count++;
2280 }
2281
2282 return Count;
2283}

◆ GetVolumeFromPartition()

PVOLENTRY GetVolumeFromPartition ( _In_ PPARTENTRY  PartEntry)

Definition at line 2795 of file partlist.c.

2797{
2799 PVOLENTRY VolumeEntry;
2800 ULONG i;
2801
2802 if ((PartEntry == NULL) ||
2803 (PartEntry->DiskEntry == NULL))
2804 return NULL;
2805
2807 while (Entry != &VolumeListHead)
2808 {
2809 VolumeEntry = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
2810
2811 if (VolumeEntry->pExtents == NULL)
2812 return NULL;
2813
2814 for (i = 0; i < VolumeEntry->pExtents->NumberOfDiskExtents; i++)
2815 {
2816 if (VolumeEntry->pExtents->Extents[i].DiskNumber == PartEntry->DiskEntry->DiskNumber)
2817 {
2818 if ((VolumeEntry->pExtents->Extents[i].StartingOffset.QuadPart == PartEntry->StartSector.QuadPart * PartEntry->DiskEntry->BytesPerSector) &&
2819 (VolumeEntry->pExtents->Extents[i].ExtentLength.QuadPart == PartEntry->SectorCount.QuadPart * PartEntry->DiskEntry->BytesPerSector))
2820 return VolumeEntry;
2821 }
2822 }
2823
2824 Entry = Entry->Flink;
2825 }
2826
2827 return NULL;
2828}
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

Referenced by clean_main().

◆ gpt_main()

EXIT_CODE gpt_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 16 of file gpt.c.

19{
20 ULONGLONG ullAttributes = 0ULL;
21 PWSTR pszSuffix = NULL;
22 INT i;
24
25 if (CurrentDisk == NULL)
26 {
28 return EXIT_SUCCESS;
29 }
30
32 {
34 return EXIT_SUCCESS;
35 }
36
38 {
40 return EXIT_SUCCESS;
41 }
42
43 for (i = 1; i < argc; i++)
44 {
45 if (HasPrefix(argv[i], L"attributes=", &pszSuffix))
46 {
47 /* attributes=<N> */
48 DPRINT("Attributes: %s\n", pszSuffix);
49
50 ullAttributes = _wcstoui64(pszSuffix, NULL, 0);
51 if ((ullAttributes == 0) && (errno == ERANGE))
52 {
54 return EXIT_SUCCESS;
55 }
56 }
57 else
58 {
60 return EXIT_SUCCESS;
61 }
62 }
63
64 DPRINT("Attributes: 0x%I64x\n", ullAttributes);
65 CurrentPartition->Gpt.Attributes = ullAttributes;
67
70 if (!NT_SUCCESS(Status))
71 {
73 return EXIT_SUCCESS;
74 }
75
77
78 return EXIT_SUCCESS;
79}
#define IDS_GPT_FAIL
Definition: resource.h:91
#define IDS_GPT_SUCCESS
Definition: resource.h:92

◆ 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}
_ACRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:195
return ret
Definition: mutex.c:146

Referenced by AcpiExGetNameString(), assign_main(), CreateEfiPartition(), CreateExtendedPartition(), CreateLogicalPartition(), CreateMsrPartition(), CreatePrimaryPartition(), format_main(), gpt_main(), remove_main(), setid_main(), and UniqueIdDisk().

◆ help_main()

EXIT_CODE help_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 121 of file help.c.

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

◆ HelpCommand()

EXIT_CODE HelpCommand ( _In_ PCOMMAND  pCommand)

Referenced by InterpretCmd(), and main().

◆ HelpCommandList()

VOID HelpCommandList ( VOID  )

Definition at line 16 of file help.c.

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

Referenced by help_main(), and InterpretCmd().

◆ import_main()

EXIT_CODE import_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file import.c.

15{
16 return EXIT_SUCCESS;
17}

◆ inactive_main()

EXIT_CODE inactive_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 16 of file inactive.c.

19{
21
22 DPRINT("Inactive()\n");
23
24 if (CurrentDisk == NULL)
25 {
27 return EXIT_SUCCESS;
28 }
29
31 {
33 return EXIT_SUCCESS;
34 }
35
37 {
39 {
41 return EXIT_SUCCESS;
42 }
43
48 if (NT_SUCCESS(Status))
49 {
51 }
52 else
53 {
55 }
56 }
57 else
58 {
60 }
61
62 return EXIT_SUCCESS;
63}
#define IDS_INACTIVE_ALREADY
Definition: resource.h:98
#define IDS_INACTIVE_NO_MBR
Definition: resource.h:99
#define IDS_INACTIVE_FAIL
Definition: resource.h:96
#define IDS_INACTIVE_SUCCESS
Definition: resource.h:97

◆ InterpretCmd()

EXIT_CODE InterpretCmd ( _In_ INT  argc,
_In_ PWSTR argv 
)

◆ InterpretMain()

VOID InterpretMain ( VOID  )

Definition at line 232 of file interpreter.c.

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

Referenced by wmain().

◆ InterpretScript()

EXIT_CODE InterpretScript ( _In_ LPWSTR  line)

Referenced by RunScript().

◆ IsDecString()

BOOL IsDecString ( _In_ PWSTR  pszDecString)

Definition at line 14 of file misc.c.

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

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

◆ IsHexString()

BOOL IsHexString ( _In_ PWSTR  pszHexString)

Definition at line 36 of file misc.c.

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

Referenced by UniqueIdDisk().

◆ ListDisk()

EXIT_CODE ListDisk ( INT  argc,
PWSTR argv 
)

◆ ListPartition()

EXIT_CODE ListPartition ( INT  argc,
PWSTR argv 
)

◆ ListVirtualDisk()

EXIT_CODE ListVirtualDisk ( INT  argc,
PWSTR argv 
)

◆ ListVolume()

EXIT_CODE ListVolume ( INT  argc,
PWSTR argv 
)

◆ merge_main()

EXIT_CODE merge_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file merge.c.

15{
16 return EXIT_SUCCESS;
17}

◆ offline_main()

EXIT_CODE offline_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file offline.c.

15{
16 return EXIT_SUCCESS;
17}

◆ online_main()

EXIT_CODE online_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file online.c.

15{
16 return EXIT_SUCCESS;
17}

◆ PrintBusType()

VOID PrintBusType ( _Out_ PWSTR  pszBuffer,
_In_ INT  cchBufferMax,
_In_ STORAGE_BUS_TYPE  Bustype 
)

Definition at line 295 of file misc.c.

299{
300 if (BusType <= BusTypeMax)
303 pszBuffer,
304 cchBufferMax);
305 else
308 pszBuffer,
309 cchBufferMax);
310}
#define IDS_BUSTYPE_OTHER
Definition: resource.h:253
#define IDS_BUSTYPE_UNKNOWN
Definition: resource.h:232
INT WINAPI DECLSPEC_HOTPATCH LoadStringW(HINSTANCE instance, UINT resource_id, LPWSTR buffer, INT buflen)
Definition: string.c:1220
@ BusTypeMax
Definition: ntddstor.h:454
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
Definition: halfuncs.h:159

Referenced by DetailDisk().

◆ PrintDisk()

VOID PrintDisk ( _In_ PDISKENTRY  DiskEntry)

Definition at line 83 of file list.c.

85{
86 ULONGLONG DiskSize;
87 ULONGLONG FreeSize;
88 LPWSTR lpSizeUnit;
89 LPWSTR lpFreeUnit;
90
91 DiskSize = DiskEntry->SectorCount.QuadPart *
92 (ULONGLONG)DiskEntry->BytesPerSector;
93
94 if (DiskSize >= SIZE_10TB) /* 10 TB */
95 {
96 DiskSize = RoundingDivide(DiskSize, SIZE_1TB);
97 lpSizeUnit = L"TB";
98 }
99 else if (DiskSize >= SIZE_10GB) /* 10 GB */
100 {
101 DiskSize = RoundingDivide(DiskSize, SIZE_1GB);
102 lpSizeUnit = L"GB";
103 }
104 else
105 {
106 DiskSize = RoundingDivide(DiskSize, SIZE_1MB);
107 if (DiskSize == 0)
108 DiskSize = 1;
109 lpSizeUnit = L"MB";
110 }
111
112 FreeSize = GetFreeDiskSize(DiskEntry);
113 if (FreeSize >= SIZE_10TB) /* 10 TB */
114 {
115 FreeSize = RoundingDivide(FreeSize, SIZE_1TB);
116 lpFreeUnit = L"TB";
117 }
118 else if (FreeSize >= SIZE_10GB) /* 10 GB */
119 {
120 FreeSize = RoundingDivide(FreeSize, SIZE_1GB);
121 lpFreeUnit = L"GB";
122 }
123 else if (FreeSize >= SIZE_10MB) /* 10 MB */
124 {
125 FreeSize = RoundingDivide(FreeSize, SIZE_1MB);
126 lpFreeUnit = L"MB";
127 }
128 else if (FreeSize >= SIZE_10KB) /* 10 KB */
129 {
130 FreeSize = RoundingDivide(FreeSize, SIZE_1KB);
131 lpFreeUnit = L"KB";
132 }
133 else
134 {
135 lpFreeUnit = L"B";
136 }
137
139 (CurrentDisk == DiskEntry) ? L'*' : L' ',
140 DiskEntry->DiskNumber,
141 L"Online",
142 DiskSize,
143 lpSizeUnit,
144 FreeSize,
145 lpFreeUnit,
146 L" ",
147 (DiskEntry->PartitionStyle == PARTITION_STYLE_GPT) ? L"*" : L" ");
148}
static ULONGLONG GetFreeDiskSize(_In_ PDISKENTRY DiskEntry)
Definition: list.c:18
#define IDS_LIST_DISK_FORMAT
Definition: resource.h:103
#define SIZE_10TB
Definition: diskpart.h:264
#define SIZE_1TB
Definition: diskpart.h:263
#define SIZE_10GB
Definition: diskpart.h:262
#define SIZE_1KB
Definition: diskpart.h:257
#define SIZE_1MB
Definition: diskpart.h:259
#define SIZE_10MB
Definition: diskpart.h:260
#define SIZE_10KB
Definition: diskpart.h:258
#define SIZE_1GB
Definition: diskpart.h:261
if(dx< 0)
Definition: linetemp.h:194
ULONGLONG RoundingDivide(IN ULONGLONG Dividend, IN ULONGLONG Divisor)
Definition: partlist.c:95

Referenced by DetailVolume(), and ListDisk().

◆ PrintGUID()

VOID PrintGUID ( _Out_ PWSTR  pszBuffer,
_In_ GUID pGuid 
)

Definition at line 187 of file misc.c.

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

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

◆ PrintVolume()

VOID PrintVolume ( _In_ PVOLENTRY  VolumeEntry)

Definition at line 471 of file list.c.

473{
474 ULONGLONG VolumeSize;
475 PWSTR pszSizeUnit;
476 PWSTR pszVolumeType;
477
478 VolumeSize = VolumeEntry->Size.QuadPart;
479 if (VolumeSize >= SIZE_10TB) /* 10 TB */
480 {
481 VolumeSize = RoundingDivide(VolumeSize, SIZE_1TB);
482 pszSizeUnit = L"TB";
483 }
484 else if (VolumeSize >= SIZE_10GB) /* 10 GB */
485 {
486 VolumeSize = RoundingDivide(VolumeSize, SIZE_1GB);
487 pszSizeUnit = L"GB";
488 }
489 else if (VolumeSize >= SIZE_10MB) /* 10 MB */
490 {
491 VolumeSize = RoundingDivide(VolumeSize, SIZE_1MB);
492 pszSizeUnit = L"MB";
493 }
494 else
495 {
496 VolumeSize = RoundingDivide(VolumeSize, SIZE_1KB);
497 pszSizeUnit = L"KB";
498 }
499
500 switch (VolumeEntry->VolumeType)
501 {
503 pszVolumeType = L"DVD";
504 break;
506 pszVolumeType = L"Partition";
507 break;
509 pszVolumeType = L"Removable";
510 break;
512 default:
513 pszVolumeType = L"Unknown";
514 break;
515 }
516
518 (CurrentVolume == VolumeEntry) ? L'*' : L' ',
519 VolumeEntry->VolumeNumber,
520 VolumeEntry->DriveLetter,
521 (VolumeEntry->pszLabel) ? VolumeEntry->pszLabel : L"",
522 (VolumeEntry->pszFilesystem) ? VolumeEntry->pszFilesystem : L"",
523 pszVolumeType,
524 VolumeSize, pszSizeUnit,
525 L"", L"");
526}
#define IDS_LIST_VOLUME_FORMAT
Definition: resource.h:111

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

◆ ReadLayoutBuffer()

VOID ReadLayoutBuffer ( _In_ HANDLE  FileHandle,
_In_ PDISKENTRY  DiskEntry 
)

Definition at line 1065 of file partlist.c.

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

Referenced by AddDiskToList(), and CreateDisk().

◆ recover_main()

EXIT_CODE recover_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file recover.c.

15{
16 return EXIT_SUCCESS;
17}

◆ remove_main()

EXIT_CODE remove_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 15 of file remove.c.

18{
19 PWSTR pszSuffix = NULL;
20 WCHAR DriveLetter = UNICODE_NULL;
21 INT i, nExclusive = 0;
22 BOOL bResult;
23
24 DPRINT("remove_main()\n");
25
26 if (CurrentVolume == NULL)
27 {
29 return EXIT_SUCCESS;
30 }
31
33 {
35 return EXIT_SUCCESS;
36 }
37
38 for (i = 1; i < argc; i++)
39 {
40 if (_wcsicmp(argv[i], L"noerr") == 0)
41 {
42 /* noerr */
43 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
44#if 0
45 bNoErr = TRUE;
46#endif
47 }
48 }
49
50 for (i = 1; i < argc; i++)
51 {
52 if (HasPrefix(argv[i], L"letter=", &pszSuffix))
53 {
54 if (wcslen(pszSuffix) == 1)
55 {
56 DriveLetter = towupper(*pszSuffix);
57 nExclusive++;
58 }
59 else
60 {
62 return EXIT_SUCCESS;
63 }
64 }
65 else if (HasPrefix(argv[i], L"mount=", &pszSuffix))
66 {
67 DPRINT("Mount\n", pszSuffix);
68 ConPuts(StdOut, L"The MOUNT option is not supported yet!\n");
69 nExclusive++;
70 }
71 else if (_wcsicmp(argv[i], L"all") == 0)
72 {
73 ConPuts(StdOut, L"The ALL option is not supported yet!\n");
74 nExclusive++;
75 }
76 else if (_wcsicmp(argv[i], L"dismount") == 0)
77 {
78 ConPuts(StdOut, L"The DISMOUNT option is not supported yet!\n");
79 }
80 else if (_wcsicmp(argv[i], L"noerr") == 0)
81 {
82 /* noerr - Already handled above */
83 }
84 else
85 {
87 return EXIT_SUCCESS;
88 }
89 }
90
91 if (nExclusive > 1)
92 {
94 return EXIT_SUCCESS;
95 }
96
97 DPRINT("VolumeName: %S\n", CurrentVolume->VolumeName);
98 DPRINT("DeviceName: %S\n", CurrentVolume->DeviceName);
99 DPRINT("DriveLetter: %C\n", CurrentVolume->DriveLetter);
100
101 if (DriveLetter != UNICODE_NULL)
102 {
103 DPRINT1("DriveLetter: %C\n", DriveLetter);
104
105 if ((DriveLetter < L'C') || (DriveLetter > L'Z'))
106 {
108 return EXIT_SUCCESS;
109 }
110
111 if (DriveLetter != CurrentVolume->DriveLetter)
112 {
114 return EXIT_SUCCESS;
115 }
116 }
117 else
118 {
119 DriveLetter = CurrentVolume->DriveLetter;
120 }
121
122 bResult = DeleteDriveLetter(DriveLetter);
123 if (bResult == FALSE)
124 {
126 return EXIT_SUCCESS;
127 }
128
131
132 return EXIT_SUCCESS;
133}
#define IDS_REMOVE_NO_LETTER
Definition: resource.h:115
#define IDS_REMOVE_FAIL
Definition: resource.h:113
#define IDS_ASSIGN_INVALID_LETTER
Definition: resource.h:33
#define IDS_REMOVE_SUCCESS
Definition: resource.h:114
#define IDS_REMOVE_WRONG_LETTER
Definition: resource.h:116
BOOL DeleteDriveLetter(_In_ WCHAR DriveLetter)
Definition: mountmgr.c:338
#define towupper(c)
Definition: wctype.h:99

◆ RemoveVolume()

VOID RemoveVolume ( _In_ PVOLENTRY  VolumeEntry)

Definition at line 2832 of file partlist.c.

2834{
2835 if (VolumeEntry == NULL)
2836 return;
2837
2838 if (VolumeEntry == CurrentVolume)
2840
2841 RemoveEntryList(&VolumeEntry->ListEntry);
2842
2843 if (VolumeEntry->pszLabel)
2844 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszLabel);
2845
2846 if (VolumeEntry->pszFilesystem)
2847 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pszFilesystem);
2848
2849 if (VolumeEntry->pExtents)
2850 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry->pExtents);
2851
2852 /* Release disk entry */
2853 RtlFreeHeap(RtlGetProcessHeap(), 0, VolumeEntry);
2854}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986

Referenced by clean_main().

◆ repair_main()

EXIT_CODE repair_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file repair.c.

15{
16 ConPuts(StdOut, L"\nTODO: Add code later since Win 7 Home Premium doesn't have this feature.\n");
17 return EXIT_SUCCESS;
18}

◆ rescan_main()

EXIT_CODE rescan_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file rescan.c.

15{
22
23 return EXIT_SUCCESS;
24}
#define IDS_RESCAN_START
Definition: resource.h:118
#define IDS_RESCAN_END
Definition: resource.h:119
VOID DestroyVolumeList(VOID)
Definition: partlist.c:2005
NTSTATUS CreateVolumeList(VOID)
Definition: partlist.c:1967
VOID NTAPI DestroyPartitionList(IN PPARTLIST List)
Definition: partlist.c:2074
PPARTLIST NTAPI CreatePartitionList(VOID)
Definition: partlist.c:1988

◆ retain_main()

EXIT_CODE retain_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file retain.c.

15{
16 return EXIT_SUCCESS;
17}

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

EXIT_CODE san_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file san.c.

15{
16 return EXIT_SUCCESS;
17}

◆ ScanForUnpartitionedGptDiskSpace()

VOID ScanForUnpartitionedGptDiskSpace ( PDISKENTRY  DiskEntry)

Definition at line 921 of file partlist.c.

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

Referenced by AddDiskToList(), and ConvertGPT().

◆ ScanForUnpartitionedMbrDiskSpace()

VOID ScanForUnpartitionedMbrDiskSpace ( PDISKENTRY  DiskEntry)

Definition at line 660 of file partlist.c.

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

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

◆ ScrubAutomount()

BOOL ScrubAutomount ( VOID  )

Definition at line 141 of file mountmgr.c.

142{
143 HANDLE MountMgrHandle;
146
147 DPRINT("ScrubAutomount()\n");
148
150 if (!NT_SUCCESS(Status))
151 {
152 DPRINT1("OpenMountManager() Status 0x%08lx\n", Status);
153 return FALSE;
154 }
155
156 Status = NtDeviceIoControlFile(MountMgrHandle,
157 NULL,
158 NULL,
159 NULL,
160 &Iosb,
162 NULL,
163 0,
164 NULL,
165 0);
166
167 NtClose(MountMgrHandle);
168
169 if (!NT_SUCCESS(Status))
170 {
171 DPRINT1("NtDeviceIoControlFile() Status 0x%08lx\n", Status);
172 return FALSE;
173 }
174
175 return TRUE;
176}
#define IOCTL_MOUNTMGR_SCRUB_REGISTRY
Definition: mountmgr.h:170

Referenced by automount_main().

◆ SelectDisk()

EXIT_CODE SelectDisk ( INT  argc,
PWSTR argv 
)

◆ SelectPartition()

EXIT_CODE SelectPartition ( INT  argc,
PWSTR argv 
)

◆ SelectVolume()

EXIT_CODE SelectVolume ( INT  argc,
PWSTR argv 
)

◆ SetAutomountState()

BOOL SetAutomountState ( _In_ BOOL  bEnable)

Definition at line 90 of file mountmgr.c.

92{
93 HANDLE MountMgrHandle;
97
98 DPRINT("SetAutomountState()\n");
99
101 if (!NT_SUCCESS(Status))
102 {
103 DPRINT1("OpenMountManager() Status 0x%08lx\n", Status);
104 return TRUE;
105 }
106
107 if (bEnable)
108 AutoMount.NewState = Enabled;
109 else
110 AutoMount.NewState = Disabled;
111
112 Status = NtDeviceIoControlFile(MountMgrHandle,
113 NULL,
114 NULL,
115 NULL,
116 &Iosb,
118 &AutoMount,
119 sizeof(AutoMount),
120 NULL,
121 0);
122
123 NtClose(MountMgrHandle);
124
125 if (!NT_SUCCESS(Status))
126 {
127 DPRINT1("NtDeviceIoControlFile() Status 0x%08lx\n", Status);
128 return TRUE;
129 }
130
131 if (AutoMount.NewState == Enabled)
133 else
135 ConPuts(StdOut, L"\n");
136
137 return TRUE;
138}
@ Disabled
Definition: mountmgr.h:178
#define IOCTL_MOUNTMGR_SET_AUTO_MOUNT
Definition: mountmgr.h:174
MOUNTMGR_AUTO_MOUNT_STATE NewState
Definition: mountmgr.h:187

Referenced by automount_main().

◆ setid_main()

EXIT_CODE setid_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 16 of file setid.c.

19{
20 INT i, length;
21 PWSTR pszSuffix, pszId = NULL;
23
24 DPRINT("SetId()\n");
25
26 if (CurrentDisk == NULL)
27 {
29 return EXIT_SUCCESS;
30 }
31
33 {
35 return EXIT_SUCCESS;
36 }
37
38 for (i = 1; i < argc; i++)
39 {
40 if (_wcsicmp(argv[i], L"noerr") == 0)
41 {
42 /* noerr */
43 DPRINT("NOERR\n");
44 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
45 }
46 }
47
48 for (i = 1; i < argc; i++)
49 {
50 if (HasPrefix(argv[i], L"id=", &pszSuffix))
51 {
52 /* id=<Byte>|<GUID> */
53 DPRINT("ID : %s\n", pszSuffix);
54 pszId = pszSuffix;
55 }
56 else if (_wcsicmp(argv[i], L"noerr") == 0)
57 {
58 /* noerr - Already handled above */
59 }
60 else if (_wcsicmp(argv[i], L"override") == 0)
61 {
62 /* override */
63 DPRINT("OVERRIDE\n");
64 ConPuts(StdOut, L"The OVERRIDE option is not supported yet!\n");
65 }
66 else
67 {
69 return EXIT_SUCCESS;
70 }
71 }
72
74 {
76 {
78 return EXIT_SUCCESS;
79 }
80
84 if (!NT_SUCCESS(Status))
85 {
87 return EXIT_SUCCESS;
88 }
89 }
91 {
93
94 length = wcslen(pszId);
95 if (length == 0)
96 {
98 return EXIT_SUCCESS;
99 }
100
101 if (length > 2)
102 {
104 return EXIT_SUCCESS;
105 }
106
107 PartitionType = (UCHAR)wcstoul(pszSuffix, NULL, 16);
108 if ((PartitionType == 0) && (errno == ERANGE))
109 {
111 return EXIT_SUCCESS;
112 }
113
114 if (PartitionType == 0x42)
115 {
117 return EXIT_SUCCESS;
118 }
119
124 if (!NT_SUCCESS(Status))
125 {
127 return EXIT_SUCCESS;
128 }
129 }
130
132
133 return EXIT_SUCCESS;
134}
#define IDS_SETID_INVALID_TYPE
Definition: resource.h:137
#define IDS_SETID_FAIL
Definition: resource.h:134
#define IDS_SETID_SUCCESS
Definition: resource.h:135
#define IDS_SETID_INVALID_FORMAT
Definition: resource.h:136
BOOL StringToGUID(_Out_ GUID *pGuid, _In_ PWSTR pszString)
Definition: misc.c:227

◆ shrink_main()

EXIT_CODE shrink_main ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 12 of file shrink.c.

15{
16 return EXIT_SUCCESS;
17}

◆ StringToGUID()

BOOL StringToGUID ( _Out_ GUID pGuid,
_In_ PWSTR  pszString 
)

Definition at line 227 of file misc.c.

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

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

◆ UniqueIdDisk()

EXIT_CODE UniqueIdDisk ( _In_ INT  argc,
_In_ PWSTR argv 
)

Definition at line 17 of file uniqueid.c.

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

◆ UpdateGptDiskLayout()

VOID UpdateGptDiskLayout ( _In_ PDISKENTRY  DiskEntry,
_In_ BOOL  DeleteEntry 
)

Definition at line 2539 of file partlist.c.

2542{
2543 PLIST_ENTRY ListEntry;
2544 PPARTENTRY PartEntry;
2546 ULONG Count, Index;
2547
2548 DPRINT("UpdateGptDiskLayout()\n");
2549
2550 /* Count used partition entries */
2551 Count = 0;
2552 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
2553 ListEntry != &DiskEntry->PrimaryPartListHead;
2554 ListEntry = ListEntry->Flink)
2555 {
2556 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2557
2558 if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID))
2559 Count++;
2560 }
2561
2562 DPRINT("Used partition entries: %lu\n", Count);
2563
2564 if (DeleteEntry)
2565 Count++;
2566
2567 /* Reallocate the layout buffer */
2568 if (Count != DiskEntry->LayoutBuffer->PartitionCount)
2569 {
2570 PDRIVE_LAYOUT_INFORMATION_EX NewLayoutBuffer;
2571 ULONG NewLayoutBufferSize;
2572
2573 NewLayoutBufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
2575 NewLayoutBuffer = RtlReAllocateHeap(RtlGetProcessHeap(),
2577 DiskEntry->LayoutBuffer,
2578 NewLayoutBufferSize);
2579 if (NewLayoutBuffer == NULL)
2580 {
2581 DPRINT1("Failed to allocate the new layout buffer (size: %lu)\n", NewLayoutBufferSize);
2582 return;
2583 }
2584
2585 NewLayoutBuffer->PartitionCount = Count;
2586 DiskEntry->LayoutBuffer = NewLayoutBuffer;
2587 }
2588
2589 /* Fill the new layout buffer */
2590 Index = 0;
2591 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
2592 ListEntry != &DiskEntry->PrimaryPartListHead;
2593 ListEntry = ListEntry->Flink)
2594 {
2595 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2596
2597 if (!IsEqualGUID(&PartEntry->Gpt.PartitionType, &PARTITION_ENTRY_UNUSED_GUID))
2598 {
2599 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2600 PartEntry->PartitionIndex = Index;
2601
2602 DPRINT("Updating primary partition entry %lu\n", Index);
2603 PartitionInfo->PartitionStyle = PARTITION_STYLE_GPT;
2604 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
2605 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2606 PartitionInfo->PartitionNumber = Index + 1;
2607 PartitionInfo->RewritePartition = TRUE;
2608 CopyMemory(&PartitionInfo->Gpt.PartitionType, &PartEntry->Gpt.PartitionType, sizeof(GUID));
2609 CopyMemory(&PartitionInfo->Gpt.PartitionId, &PartEntry->Gpt.PartitionId, sizeof(GUID));
2610 PartitionInfo->Gpt.Attributes = PartEntry->Gpt.Attributes;
2611 ZeroMemory(&PartitionInfo->Gpt.Name, 36 * sizeof(WCHAR)); /* ??? */
2612
2613 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
2614
2615 Index++;
2616 }
2617 }
2618
2619 if (DeleteEntry)
2620 {
2621 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2623 PartitionInfo->RewritePartition = TRUE;
2624 }
2625}
#define ZeroMemory
Definition: minwinbase.h:31
ULONG PartitionIndex
Definition: partlist.h:76
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2105

Referenced by CreateEfiPartition(), CreateMsrPartition(), CreatePrimaryGptPartition(), DeleteGptPartition(), gpt_main(), setid_main(), and UniqueIdDisk().

◆ UpdateMbrDiskLayout()

VOID UpdateMbrDiskLayout ( _In_ PDISKENTRY  DiskEntry)

Definition at line 2362 of file partlist.c.

2364{
2367 PLIST_ENTRY ListEntry;
2368 PPARTENTRY PartEntry;
2369 LARGE_INTEGER HiddenSectors64;
2370 ULONG Index;
2372
2373 DPRINT("UpdateMbrDiskLayout()\n");
2374
2375 /* Resize the layout buffer if necessary */
2376 if (ReAllocateLayoutBuffer(DiskEntry) == FALSE)
2377 {
2378 DPRINT("ReAllocateLayoutBuffer() failed.\n");
2379 return;
2380 }
2381
2382 DiskEntry->LayoutBuffer->PartitionStyle = PARTITION_STYLE_MBR;
2383
2384 /* Update the primary partition table */
2385 Index = 0;
2386 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
2387 ListEntry != &DiskEntry->PrimaryPartListHead;
2388 ListEntry = ListEntry->Flink)
2389 {
2390 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2391
2392 if (PartEntry->IsPartitioned)
2393 {
2395
2396 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2397 PartEntry->PartitionIndex = Index;
2398
2399 /* Reset the current partition number only for newly-created (unmounted) partitions */
2400 if (PartEntry->New)
2401 PartEntry->PartitionNumber = 0;
2402
2404
2405 if (!IsSamePrimaryLayoutEntry(PartitionInfo, DiskEntry, PartEntry))
2406 {
2407 DPRINT1("Updating primary partition entry %lu\n", Index);
2408
2409 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2410 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
2411 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2412 PartitionInfo->Mbr.HiddenSectors = PartEntry->StartSector.LowPart;
2413 PartitionInfo->PartitionNumber = PartEntry->PartitionNumber;
2414 PartitionInfo->Mbr.PartitionType = PartEntry->Mbr.PartitionType;
2415 PartitionInfo->Mbr.BootIndicator = PartEntry->Mbr.BootIndicator;
2416 PartitionInfo->Mbr.RecognizedPartition = IsRecognizedPartition(PartEntry->Mbr.PartitionType);
2417 PartitionInfo->RewritePartition = TRUE;
2418 }
2419
2420 if (!IsContainerPartition(PartEntry->Mbr.PartitionType))
2422
2423 Index++;
2424 }
2425 }
2426
2427 ASSERT(Index <= 4);
2428
2429 /* Update the logical partition table */
2430 Index = 4;
2431 for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
2432 ListEntry != &DiskEntry->LogicalPartListHead;
2433 ListEntry = ListEntry->Flink)
2434 {
2435 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2436
2437 if (PartEntry->IsPartitioned)
2438 {
2440
2441 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2442 PartEntry->PartitionIndex = Index;
2443
2444 /* Reset the current partition number only for newly-created (unmounted) partitions */
2445 if (PartEntry->New)
2446 PartEntry->PartitionNumber = 0;
2447
2449
2450 DPRINT1("Updating logical partition entry %lu\n", Index);
2451
2452 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2453 PartitionInfo->StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector;
2454 PartitionInfo->PartitionLength.QuadPart = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
2455 PartitionInfo->Mbr.HiddenSectors = DiskEntry->SectorAlignment;
2456 PartitionInfo->PartitionNumber = PartEntry->PartitionNumber;
2457 PartitionInfo->Mbr.PartitionType = PartEntry->Mbr.PartitionType;
2458 PartitionInfo->Mbr.BootIndicator = FALSE;
2459 PartitionInfo->Mbr.RecognizedPartition = IsRecognizedPartition(PartEntry->Mbr.PartitionType);
2460 PartitionInfo->RewritePartition = TRUE;
2461
2462 /* Fill the link entry of the previous partition entry */
2463 if (LinkInfo != NULL)
2464 {
2466 LinkInfo->StartingOffset.QuadPart = (PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector;
2467 LinkInfo->PartitionLength.QuadPart = (PartEntry->StartSector.QuadPart + DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector;
2468 HiddenSectors64.QuadPart = PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment - DiskEntry->ExtendedPartition->StartSector.QuadPart;
2469 LinkInfo->Mbr.HiddenSectors = HiddenSectors64.LowPart;
2470 LinkInfo->PartitionNumber = 0;
2472 LinkInfo->Mbr.BootIndicator = FALSE;
2473 LinkInfo->Mbr.RecognizedPartition = FALSE;
2474 LinkInfo->RewritePartition = TRUE;
2475 }
2476
2477 /* Save a pointer to the link entry of the current partition entry */
2478 LinkInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index + 1];
2479
2481 Index += 4;
2482 }
2483 }
2484
2485 /* Wipe unused primary partition entries */
2486 for (Index = GetPrimaryPartitionCount(DiskEntry); Index < 4; Index++)
2487 {
2488 DPRINT1("Primary partition entry %lu\n", Index);
2489
2490 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2491
2493 {
2494 DPRINT1("Wiping primary partition entry %lu\n", Index);
2495
2496 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2497 PartitionInfo->StartingOffset.QuadPart = 0;
2498 PartitionInfo->PartitionLength.QuadPart = 0;
2499 PartitionInfo->Mbr.HiddenSectors = 0;
2500 PartitionInfo->PartitionNumber = 0;
2501 PartitionInfo->Mbr.PartitionType = PARTITION_ENTRY_UNUSED;
2502 PartitionInfo->Mbr.BootIndicator = FALSE;
2503 PartitionInfo->Mbr.RecognizedPartition = FALSE;
2504 PartitionInfo->RewritePartition = TRUE;
2505 }
2506 }
2507
2508 /* Wipe unused logical partition entries */
2509 for (Index = 4; Index < DiskEntry->LayoutBuffer->PartitionCount; Index++)
2510 {
2511 if (Index % 4 >= 2)
2512 {
2513 DPRINT1("Logical partition entry %lu\n", Index);
2514
2515 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index];
2516
2518 {
2519 DPRINT1("Wiping partition entry %lu\n", Index);
2520
2521 PartitionInfo->PartitionStyle = PARTITION_STYLE_MBR;
2522 PartitionInfo->StartingOffset.QuadPart = 0;
2523 PartitionInfo->PartitionLength.QuadPart = 0;
2524 PartitionInfo->Mbr.HiddenSectors = 0;
2525 PartitionInfo->PartitionNumber = 0;
2526 PartitionInfo->Mbr.PartitionType = PARTITION_ENTRY_UNUSED;
2527 PartitionInfo->Mbr.BootIndicator = FALSE;
2528 PartitionInfo->Mbr.RecognizedPartition = FALSE;
2529 PartitionInfo->RewritePartition = TRUE;
2530 }
2531 }
2532 }
2533
2534 DiskEntry->Dirty = TRUE;
2535}
ULONG OnDiskPartitionNumber
Definition: partlist.h:74
LARGE_INTEGER StartingOffset
Definition: imports.h:221
PARTITION_STYLE PartitionStyle
Definition: imports.h:220
PARTITION_INFORMATION_MBR Mbr
Definition: imports.h:226
LARGE_INTEGER PartitionLength
Definition: imports.h:222
$ULONG LowPart
Definition: ntbasedef.h:581
static BOOLEAN IsSamePrimaryLayoutEntry(IN PPARTITION_INFORMATION_EX PartitionInfo, IN PDISKENTRY DiskEntry, IN PPARTENTRY PartEntry)
Definition: partlist.c:2250
static BOOLEAN IsEmptyLayoutEntry(IN PPARTITION_INFORMATION_EX PartitionInfo)
Definition: partlist.c:2235
static BOOLEAN ReAllocateLayoutBuffer(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:2310
ULONG LowPart
Definition: typedefs.h:106
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061

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

◆ WriteGptPartitions()

NTSTATUS WriteGptPartitions ( _In_ PDISKENTRY  DiskEntry)

Definition at line 2158 of file partlist.c.

2160{
2168
2169 DPRINT("WriteGptPartitions() Disk: %lu\n", DiskEntry->DiskNumber);
2170
2171 /* If the disk is not dirty, there is nothing to do */
2172 if (!DiskEntry->Dirty)
2173 return STATUS_SUCCESS;
2174
2176 L"\\Device\\Harddisk%lu\\Partition0",
2177 DiskEntry->DiskNumber);
2179
2181 &Name,
2183 NULL,
2184 NULL);
2185
2189 &Iosb,
2190 0,
2192 if (!NT_SUCCESS(Status))
2193 {
2194 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
2195 return Status;
2196 }
2197
2198 //
2199 // FIXME: We first *MUST* use IOCTL_DISK_CREATE_DISK to initialize
2200 // the disk in MBR or GPT format in case the disk was not initialized!!
2201 // For this we must ask the user which format to use.
2202 //
2203
2204 /* Set the new disk layout and retrieve its updated version with possibly modified partition numbers */
2205 BufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
2206 ((DiskEntry->LayoutBuffer->PartitionCount - 1) * sizeof(PARTITION_INFORMATION_EX));
2208 NULL,
2209 NULL,
2210 NULL,
2211 &Iosb,
2213 DiskEntry->LayoutBuffer,
2214 BufferSize,
2215 DiskEntry->LayoutBuffer,
2216 BufferSize);
2218
2219 /* Check whether the IOCTL_DISK_SET_DRIVE_LAYOUT_EX call succeeded */
2220 if (!NT_SUCCESS(Status))
2221 {
2222 DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT_EX failed (Status 0x%08lx)\n", Status);
2223 return Status;
2224 }
2225
2226 /* The layout has been successfully updated, the disk is not dirty anymore */
2227 DiskEntry->Dirty = FALSE;
2228
2229 return Status;
2230}
#define BufferSize
Definition: mmc.h:75
#define IOCTL_DISK_SET_DRIVE_LAYOUT_EX
Definition: ntdddisk.h:208
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by CreateEfiPartition(), CreateMsrPartition(), CreatePrimaryGptPartition(), DeleteGptPartition(), gpt_main(), setid_main(), and UniqueIdDisk().

◆ WriteMbrPartitions()

NTSTATUS WriteMbrPartitions ( _In_ PDISKENTRY  DiskEntry)

Definition at line 2034 of file partlist.c.

2036{
2044 ULONG PartitionCount;
2045 PLIST_ENTRY ListEntry;
2046 PPARTENTRY PartEntry;
2048
2049 DPRINT("WriteMbrPartitions() Disk: %lu\n", DiskEntry->DiskNumber);
2050
2051 /* If the disk is not dirty, there is nothing to do */
2052 if (!DiskEntry->Dirty)
2053 return STATUS_SUCCESS;
2054
2056 L"\\Device\\Harddisk%lu\\Partition0",
2057 DiskEntry->DiskNumber);
2059
2061 &Name,
2063 NULL,
2064 NULL);
2065
2069 &Iosb,
2070 0,
2072 if (!NT_SUCCESS(Status))
2073 {
2074 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
2075 return Status;
2076 }
2077
2078 //
2079 // FIXME: We first *MUST* use IOCTL_DISK_CREATE_DISK to initialize
2080 // the disk in MBR or GPT format in case the disk was not initialized!!
2081 // For this we must ask the user which format to use.
2082 //
2083
2084 /* Save the original partition count to be restored later (see comment below) */
2085 PartitionCount = DiskEntry->LayoutBuffer->PartitionCount;
2086
2087 /* Set the new disk layout and retrieve its updated version with possibly modified partition numbers */
2088 BufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) +
2089 ((PartitionCount - 1) * sizeof(PARTITION_INFORMATION_EX));
2091 NULL,
2092 NULL,
2093 NULL,
2094 &Iosb,
2096 DiskEntry->LayoutBuffer,
2097 BufferSize,
2098 DiskEntry->LayoutBuffer,
2099 BufferSize);
2101
2102 /*
2103 * IOCTL_DISK_SET_DRIVE_LAYOUT calls IoWritePartitionTable(), which converts
2104 * DiskEntry->LayoutBuffer->PartitionCount into a partition *table* count,
2105 * where such a table is expected to enumerate up to 4 partitions:
2106 * partition *table* count == ROUND_UP(PartitionCount, 4) / 4 .
2107 * Due to this we need to restore the original PartitionCount number.
2108 */
2109 DiskEntry->LayoutBuffer->PartitionCount = PartitionCount;
2110
2111 /* Check whether the IOCTL_DISK_SET_DRIVE_LAYOUT call succeeded */
2112 if (!NT_SUCCESS(Status))
2113 {
2114 DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT failed (Status 0x%08lx)\n", Status);
2115 return Status;
2116 }
2117
2118 /* Update the partition numbers */
2119
2120 /* Update the primary partition table */
2121 for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
2122 ListEntry != &DiskEntry->PrimaryPartListHead;
2123 ListEntry = ListEntry->Flink)
2124 {
2125 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2126
2127 if (PartEntry->IsPartitioned)
2128 {
2130 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
2131 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
2132 }
2133 }
2134
2135 /* Update the logical partition table */
2136 for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
2137 ListEntry != &DiskEntry->LogicalPartListHead;
2138 ListEntry = ListEntry->Flink)
2139 {
2140 PartEntry = CONTAINING_RECORD(ListEntry, PARTENTRY, ListEntry);
2141
2142 if (PartEntry->IsPartitioned)
2143 {
2145 PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex];
2146 PartEntry->PartitionNumber = PartitionInfo->PartitionNumber;
2147 }
2148 }
2149
2150 /* The layout has been successfully updated, the disk is not dirty anymore */
2151 DiskEntry->Dirty = FALSE;
2152
2153 return Status;
2154}

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

Variable Documentation

◆ BiosDiskListHead

LIST_ENTRY BiosDiskListHead
extern

◆ cmds

◆ CurrentDisk

◆ CurrentPartition

PPARTENTRY CurrentPartition
extern

Definition at line 76 of file partlist.c.

Referenced by CreatePartitionList(), and DestroyPartitionList().

◆ CurrentVolume

◆ DiskListHead

LIST_ENTRY DiskListHead
extern

◆ VolumeListHead