ReactOS 0.4.16-dev-1113-g99ecbf5
drive.cpp File Reference
#include "precomp.h"
#include <process.h>
#include <ndk/obfuncs.h>
Include dependency graph for drive.cpp:

Go to the source code of this file.

Classes

struct  FORMAT_DRIVE_CONTEXT
 
struct  FORMAT_DRIVE_CONTEXT::tagTip
 

Typedefs

typedef struct FORMAT_DRIVE_CONTEXTPFORMAT_DRIVE_CONTEXT
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (shell)
 
BOOL IsDriveFloppyW (LPCWSTR pszDriveRoot)
 
static BOOL DevIoCtl (HANDLE hDevice, UINT Code, LPVOID pIn, UINT cbIn, LPVOID pOut, UINT cbOut)
 
static BOOL IsFloppy (PCWSTR pszDrive)
 
static BOOL IsSystemDrive (PFORMAT_DRIVE_CONTEXT pContext)
 
static HANDLE OpenLogicalDriveHandle (WORD DriveNumber)
 
static BOOL GetLogicalDriveSize (WORD DriveNumber, ULARGE_INTEGER &Result)
 
static PWSTR CreateTipText (FORMAT_DRIVE_CONTEXT &Ctx)
 
static BOOL GetDefaultClusterSize (LPWSTR szFs, PDWORD pClusterSize, PULARGE_INTEGER TotalNumberOfBytes)
 
static VOID InsertDefaultClusterSizeForFs (HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
 
static VOID EnableFormatDriveDlgControls (HWND hwndDlg, int EnableState)
 
static VOID InitializeFormatDriveDlg (HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
 
static PFORMAT_DRIVE_CONTEXT GetFormatContext ()
 
static BOOLEAN NTAPI FormatExCB (IN CALLBACKCOMMAND Command, IN ULONG SubAction, IN PVOID ActionInfo)
 
static VOID FormatDrive (HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
 
static DWORD CALLBACK FormatDriveThread (PVOID pThreadParameter)
 
static INT_PTR CALLBACK FormatDriveDlg (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
DWORD WINAPI SHFormatDrive (HWND hwnd, UINT drive, UINT fmtID, UINT options)
 

Typedef Documentation

◆ PFORMAT_DRIVE_CONTEXT

Function Documentation

◆ CreateTipText()

static PWSTR CreateTipText ( FORMAT_DRIVE_CONTEXT Ctx)
static

Definition at line 109 of file drive.cpp.

110{
111 HANDLE hDevice = OpenLogicalDriveHandle(Ctx.Drive);
112 if (hDevice == INVALID_HANDLE_VALUE)
113 return NULL;
114
115 ULONG cb;
116 ZeroMemory(&Ctx.Tip, sizeof(Ctx.Tip));
117 NtQueryObject(hDevice, ObjectNameInformation, &Ctx.Tip, sizeof(Ctx.Tip), &cb);
118 if (Ctx.Tip.Name.Buffer && Ctx.Tip.Name.Buffer[0] == '\\')
119 StringCbCatW(Ctx.Tip.Name.Buffer, sizeof(Ctx.Tip) - sizeof(UNICODE_STRING), L"\n");
120 else
121 (Ctx.Tip.Name.Buffer = Ctx.Tip.Buffer)[0] = UNICODE_NULL;
122
124 if (!DevIoCtl(hDevice, IOCTL_DISK_GET_PARTITION_INFO_EX, NULL, 0, &pie, sizeof(pie)))
125 {
126 pie.PartitionStyle = PARTITION_STYLE_RAW;
128 if (DevIoCtl(hDevice, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0, &pi, sizeof(pi)))
129 {
131 pie.PartitionNumber = pi.PartitionNumber;
132 }
133 }
134 CloseHandle(hDevice);
135
136 WCHAR szBuf[150], szGuid[39], *pszTip = Ctx.Tip.Name.Buffer;
137 szBuf[0] = UNICODE_NULL;
139 {
141 StringCchPrintfW(szBuf, _countof(szBuf), L"GPT %s %s", szGuid, pie.Gpt.Name);
142 }
144 {
145 StringCchPrintfW(szBuf, _countof(szBuf), L"MBR (%d)", pie.PartitionNumber);
146 }
147 StringCbCatW(pszTip, sizeof(Ctx.Tip) - sizeof(Ctx.Tip.Name), szBuf);
148 return pszTip;
149}
@ ObjectNameInformation
Definition: DriverTester.h:55
NTSTATUS NtQueryObject(IN HANDLE Handle, IN OBJECT_INFO_CLASS ObjectInformationClass, OUT PVOID ObjectInformation, IN ULONG ObjectInformationLength, OUT PULONG ReturnLength)
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2434
static BOOL DevIoCtl(HANDLE hDevice, UINT Code, LPVOID pIn, UINT cbIn, LPVOID pOut, UINT cbOut)
Definition: drive.cpp:42
static HANDLE OpenLogicalDriveHandle(WORD DriveNumber)
Definition: drive.cpp:75
#define IOCTL_DISK_GET_PARTITION_INFO_EX
Definition: ntddk_ex.h:206
@ PARTITION_STYLE_GPT
Definition: imports.h:202
@ PARTITION_STYLE_MBR
Definition: imports.h:201
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
static const WCHAR szGuid[]
Definition: rtlstr.c:1892
static refpint_t pi[]
Definition: server.c:96
#define UNICODE_NULL
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
#define L(x)
Definition: ntvdm.h:50
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
struct FORMAT_DRIVE_CONTEXT::tagTip Tip
PARTITION_STYLE PartitionStyle
Definition: imports.h:220
PARTITION_INFORMATION_GPT Gpt
Definition: imports.h:227
uint32_t ULONG
Definition: typedefs.h:59
#define ZeroMemory
Definition: winbase.h:1743
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by FormatDriveDlg().

◆ DevIoCtl()

static BOOL DevIoCtl ( HANDLE  hDevice,
UINT  Code,
LPVOID  pIn,
UINT  cbIn,
LPVOID  pOut,
UINT  cbOut 
)
inlinestatic

Definition at line 42 of file drive.cpp.

43{
44 DWORD cb = 0;
45 return DeviceIoControl(hDevice, Code, pIn, cbIn, pOut, cbOut, &cb, NULL);
46}
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1701

Referenced by CreateTipText(), and GetLogicalDriveSize().

◆ EnableFormatDriveDlgControls()

static VOID EnableFormatDriveDlgControls ( HWND  hwndDlg,
int  EnableState 
)
static

Definition at line 361 of file drive.cpp.

362{
363 BOOL CanClose = EnableState != 0, Enable = EnableState > 0;
364 HMENU hSysMenu = GetSystemMenu(hwndDlg, FALSE);
365 EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | (CanClose ? MF_ENABLED : MF_GRAYED));
366 EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), CanClose);
367 static const WORD id[] = { IDOK, 28673, 28677, 28680, 28679, 28674 };
368 for (UINT i = 0; i < _countof(id); ++i)
369 EnableWindow(GetDlgItem(hwndDlg, id[i]), Enable);
370}
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned short WORD
Definition: ntddk_ex.h:93
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
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
unsigned int UINT
Definition: ndis.h:50
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
#define MF_BYCOMMAND
Definition: winuser.h:202
#define IDCANCEL
Definition: winuser.h:842
HMENU WINAPI GetSystemMenu(_In_ HWND, _In_ BOOL)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:841
#define MF_ENABLED
Definition: winuser.h:128
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define SC_CLOSE
Definition: winuser.h:2603
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MF_GRAYED
Definition: winuser.h:129

Referenced by FormatDriveThread(), and InitializeFormatDriveDlg().

◆ FormatDrive()

static VOID FormatDrive ( HWND  hwndDlg,
PFORMAT_DRIVE_CONTEXT  pContext 
)
static

Definition at line 524 of file drive.cpp.

525{
526 WCHAR szDrive[] = { WCHAR(pContext->Drive + 'A'), ':', '\\', '\0' };
527 WCHAR szFileSys[40];
528 WCHAR szLabel[40];
529 INT iSelIndex;
530 UINT Length;
531 HWND hDlgCtrl;
536
537 /* get filesystem */
538 hDlgCtrl = GetDlgItem(hwndDlg, 28677);
539 iSelIndex = SendMessageW(hDlgCtrl, CB_GETCURSEL, 0, 0);
540 if (iSelIndex == CB_ERR)
541 {
542 ERR("Unable to get file system selection\n");
543 return;
544 }
545 Length = SendMessageW(hDlgCtrl, CB_GETLBTEXTLEN, iSelIndex, 0);
546 if ((int)Length == CB_ERR || Length + 1 > _countof(szFileSys))
547 {
548 ERR("Unable to get file system selection\n");
549 return;
550 }
551
552 /* retrieve the file system */
553 SendMessageW(hDlgCtrl, CB_GETLBTEXT, iSelIndex, (LPARAM)szFileSys);
554 szFileSys[_countof(szFileSys)-1] = L'\0';
555
556 /* retrieve the volume label */
557 hDlgCtrl = GetWindow(hwndDlg, 28679);
558 Length = SendMessageW(hDlgCtrl, WM_GETTEXTLENGTH, 0, 0);
559 if (Length + 1 > _countof(szLabel))
560 {
561 ERR("Unable to get volume label\n");
562 return;
563 }
564 SendMessageW(hDlgCtrl, WM_GETTEXT, _countof(szLabel), (LPARAM)szLabel);
565 szLabel[(sizeof(szLabel)/sizeof(WCHAR))-1] = L'\0';
566
567 /* check for quickformat */
568 if (SendDlgItemMessageW(hwndDlg, 28674, BM_GETCHECK, 0, 0) == BST_CHECKED)
570 else
572
573 /* get the cluster size */
574 hDlgCtrl = GetDlgItem(hwndDlg, 28680);
575 iSelIndex = SendMessageW(hDlgCtrl, CB_GETCURSEL, 0, 0);
576 if (iSelIndex == CB_ERR)
577 {
578 FIXME("\n");
579 return;
580 }
581 ClusterSize = SendMessageW(hDlgCtrl, CB_GETITEMDATA, iSelIndex, 0);
582 if ((int)ClusterSize == CB_ERR)
583 {
584 FIXME("\n");
585 return;
586 }
587
588 hDlgCtrl = GetDlgItem(hwndDlg, 28680);
589 SendMessageW(hDlgCtrl, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
590
591 /* See if the drive is removable or not */
592 DriveType = GetDriveTypeW(szDrive);
593 switch (DriveType)
594 {
595 case DRIVE_UNKNOWN:
596 case DRIVE_REMOTE:
597 case DRIVE_CDROM:
599 {
600 FIXME("\n");
601 return;
602 }
603
604 case DRIVE_REMOVABLE:
605 MediaFlag = FMIFS_FLOPPY;
606 break;
607
608 case DRIVE_FIXED:
609 case DRIVE_RAMDISK:
610 MediaFlag = FMIFS_HARDDISK;
611 break;
612 }
613
614 /* Format the drive */
615 pContext->Result = FALSE;
616 NT_TIB &tib = NtCurrentTeb()->NtTib;
617 PVOID BakArbitraryUserPointer = tib.ArbitraryUserPointer;
618 tib.ArbitraryUserPointer = pContext;
619
620 FormatEx(szDrive,
621 MediaFlag,
622 szFileSys,
623 szLabel,
626 FormatExCB);
627
628 tib.ArbitraryUserPointer = BakArbitraryUserPointer;
629 if (!pContext->Result)
630 {
631 pContext->Result = SHFMT_ERROR;
632 }
633 else if (QuickFormat)
634 {
635 pContext->Result = SHFMT_OPT_FULL;
636 }
637 else
638 {
639 pContext->Result = FALSE;
640 }
641}
UINT DriveType
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
BOOL QuickFormat
Definition: format.c:66
DWORD ClusterSize
Definition: format.c:67
#define TRUE
Definition: types.h:120
VOID NTAPI FormatEx(IN PWCHAR DriveRoot, IN FMIFS_MEDIA_FLAG MediaFlag, IN PWCHAR Format, IN PWCHAR Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN PFMIFSCALLBACK Callback)
Definition: format.c:39
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
static BOOLEAN NTAPI FormatExCB(IN CALLBACKCOMMAND Command, IN ULONG SubAction, IN PVOID ActionInfo)
Definition: drive.cpp:482
FMIFS_MEDIA_FLAG
Definition: fmifs.h:52
@ FMIFS_FLOPPY
Definition: fmifs.h:61
@ FMIFS_HARDDISK
Definition: fmifs.h:65
#define NtCurrentTeb
#define DRIVE_CDROM
Definition: machpc98.h:119
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define PBM_SETRANGE
Definition: commctrl.h:2188
#define SHFMT_ERROR
Definition: shlobj.h:327
#define SHFMT_OPT_FULL
Definition: shlobj.h:333
PVOID ArbitraryUserPointer
Definition: compat.h:719
int32_t INT
Definition: typedefs.h:58
#define DRIVE_UNKNOWN
Definition: winbase.h:282
#define DRIVE_NO_ROOT_DIR
Definition: winbase.h:283
#define DRIVE_REMOTE
Definition: winbase.h:279
#define DRIVE_RAMDISK
Definition: winbase.h:281
#define DRIVE_FIXED
Definition: winbase.h:278
#define DRIVE_REMOVABLE
Definition: winbase.h:277
LONG_PTR LPARAM
Definition: windef.h:208
#define WM_GETTEXTLENGTH
Definition: winuser.h:1630
#define CB_GETLBTEXTLEN
Definition: winuser.h:1964
#define CB_GETLBTEXT
Definition: winuser.h:1963
#define MAKELPARAM(l, h)
Definition: winuser.h:4019
#define CB_ERR
Definition: winuser.h:2446
#define WM_GETTEXT
Definition: winuser.h:1629
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define CB_GETITEMDATA
Definition: winuser.h:1961
HWND WINAPI GetWindow(_In_ HWND, _In_ UINT)
#define CB_GETCURSEL
Definition: winuser.h:1954
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define BST_CHECKED
Definition: winuser.h:197
#define BM_GETCHECK
Definition: winuser.h:1929

Referenced by FormatDriveThread().

◆ FormatDriveDlg()

static INT_PTR CALLBACK FormatDriveDlg ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 671 of file drive.cpp.

672{
674
675 switch(uMsg)
676 {
677 case WM_INITDIALOG:
680 return TRUE;
681 case WM_COMMAND:
682 switch(LOWORD(wParam))
683 {
684 case IDOK:
685 if (pContext->bFormattingNow)
686 break;
687
692 {
693 pContext->bFormattingNow = TRUE;
695 }
696 break;
697 case IDCANCEL:
698 if (pContext->bFormattingNow)
699 break;
700
701 EndDialog(hwndDlg, pContext->Result);
702 break;
703 case 28677: // filesystem combo
704 if (HIWORD(wParam) == CBN_SELENDOK)
705 {
706 if (pContext->bFormattingNow)
707 break;
708
709 InsertDefaultClusterSizeForFs(hwndDlg, pContext);
710 }
711 break;
712 }
713 break;
714 case WM_NOTIFY:
715 {
717 if (ttdi.hdr.code == TTN_NEEDTEXTW)
718 {
719 ttdi.uFlags |= TTF_DI_SETITEM;
720 if (PWSTR pszTip = CreateTipText(*pContext))
721 ttdi.lpszText = pszTip;
722 }
723 break;
724 }
725 case WM_NEXTDLGCTL:
726 PostMessage(hwndDlg, WM_APP, TRUE, 0); // Delay our action until after focus has changed
727 break;
728 case WM_APP: // Show/Hide tip if tabbed to the info icon
729 {
730 TTTOOLINFOW tool;
731 tool.cbSize = sizeof(tool);
732 tool.hwnd = hwndDlg;
733 tool.uId = (UINT_PTR)pContext->hWndTipTrigger;
734 if (wParam && GetFocus() == pContext->hWndTipTrigger)
735 {
736 RECT r;
737 GetWindowRect(pContext->hWndTipTrigger, &r);
738 r.left += (r.right - r.left) / 2;
739 r.top += (r.bottom - r.top) / 2;
740 SendMessageW(pContext->hWndTip, TTM_TRACKPOSITION, 0, MAKELONG(r.left, r.top));
741 SendMessageW(pContext->hWndTip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&tool);
742 }
743 else
744 {
746 }
747 break;
748 }
749 case WM_MOVING:
750 SendMessage(hwndDlg, WM_APP, FALSE, 0);
751 break;
752 }
753 return FALSE;
754}
#define shell32_hInstance
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
struct FORMAT_DRIVE_CONTEXT * PFORMAT_DRIVE_CONTEXT
static PWSTR CreateTipText(FORMAT_DRIVE_CONTEXT &Ctx)
Definition: drive.cpp:109
static DWORD CALLBACK FormatDriveThread(PVOID pThreadParameter)
Definition: drive.cpp:646
static VOID InitializeFormatDriveDlg(HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
Definition: drive.cpp:373
static VOID InsertDefaultClusterSizeForFs(HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
Definition: drive.cpp:247
#define ShellMessageBoxW
Definition: precomp.h:63
BOOL WINAPI SHCreateThread(LPTHREAD_START_ROUTINE pfnThreadProc, VOID *pData, DWORD dwFlags, LPTHREAD_START_ROUTINE pfnCallback)
Definition: thread.c:356
#define WM_APP
Definition: eventvwr.h:73
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
if(dx< 0)
Definition: linetemp.h:194
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
#define LOWORD(l)
Definition: pedump.c:82
#define NMTTDISPINFO
Definition: commctrl.h:1919
#define TTF_DI_SETITEM
Definition: commctrl.h:1772
#define TTM_TRACKPOSITION
Definition: commctrl.h:1818
#define TTN_NEEDTEXTW
Definition: commctrl.h:1887
#define TTM_TRACKACTIVATE
Definition: commctrl.h:1817
#define WM_NOTIFY
Definition: richedit.h:61
#define CTF_PROCESS_REF
Definition: shlwapi.h:1980
#define CTF_COINIT
Definition: shlwapi.h:1981
#define CTF_FREELIBANDEXIT
Definition: shlwapi.h:1982
#define IDS_FORMAT_TITLE
Definition: shresdef.h:201
#define IDS_FORMAT_WARNING
Definition: shresdef.h:202
UINT_PTR uId
Definition: commctrl.h:1743
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
uint16_t * PWSTR
Definition: typedefs.h:56
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define HIWORD(l)
Definition: typedefs.h:247
HWND WINAPI GetFocus(void)
Definition: window.c:1875
#define DWLP_USER
Definition: winuser.h:883
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
#define WM_COMMAND
Definition: winuser.h:1751
#define WM_INITDIALOG
Definition: winuser.h:1750
#define WM_NEXTDLGCTL
Definition: winuser.h:1654
#define MB_OKCANCEL
Definition: winuser.h:815
#define SendMessage
Definition: winuser.h:5863
#define MB_ICONWARNING
Definition: winuser.h:797
#define PostMessage
Definition: winuser.h:5852
#define CBN_SELENDOK
Definition: winuser.h:1992
#define WM_MOVING
Definition: winuser.h:1820
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)

Referenced by SHFormatDrive().

◆ FormatDriveThread()

static DWORD CALLBACK FormatDriveThread ( PVOID  pThreadParameter)
static

Definition at line 646 of file drive.cpp.

647{
648 PFORMAT_DRIVE_CONTEXT pContext = (PFORMAT_DRIVE_CONTEXT)pThreadParameter;
649 HWND hwndDlg = pContext->hWndMain;
650 WCHAR szDrive[] = { WCHAR(pContext->Drive + 'A'), ':', '\\', '\0' };
651
652 /* Disable controls during format */
654
656
657 FormatDrive(hwndDlg, pContext);
658
659 if (pContext->Result != SHFMT_ERROR)
662
663 /* Re-enable controls after format */
665 pContext->bFormattingNow = FALSE;
666
667 return 0;
668}
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
static VOID EnableFormatDriveDlgControls(HWND hwndDlg, int EnableState)
Definition: drive.cpp:361
static VOID FormatDrive(HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
Definition: drive.cpp:524
#define SHCNE_UPDATEITEM
Definition: shlobj.h:1911
#define SHCNE_MEDIAINSERTED
Definition: shlobj.h:1903
#define SHCNE_MEDIAREMOVED
Definition: shlobj.h:1904
#define SHCNF_FLUSH
Definition: shlobj.h:1936
#define SHCNF_PATHW
Definition: shlobj.h:1933

Referenced by FormatDriveDlg().

◆ FormatExCB()

static BOOLEAN NTAPI FormatExCB ( IN CALLBACKCOMMAND  Command,
IN ULONG  SubAction,
IN PVOID  ActionInfo 
)
static

Definition at line 482 of file drive.cpp.

486{
488 const WCHAR szDrive[] = { WCHAR(pCtx->Drive + 'A'), ':', '\\', '\0' };
489 WCHAR szLabel[40];
490 PDWORD Progress;
491 PBOOLEAN pSuccess;
492 switch(Command)
493 {
494 case PROGRESS:
495 Progress = (PDWORD)ActionInfo;
496 SendDlgItemMessageW(pCtx->hWndMain, 28678, PBM_SETPOS, (WPARAM)*Progress, 0);
497 break;
498 case DONE:
499 pSuccess = (PBOOLEAN)ActionInfo;
500 pCtx->Result = (*pSuccess);
501 SendDlgItemMessageW(pCtx->hWndMain, 28679, WM_GETTEXT, _countof(szLabel), (LPARAM)szLabel);
502 SetVolumeLabelW(szDrive, *szLabel ? szLabel : NULL);
505 SendDlgItemMessageW(pCtx->hWndMain, 28678, PBM_SETPOS, 0, 0);
506 break;
507
508 case VOLUMEINUSE:
510 case FSNOTSUPPORTED:
512 pCtx->Result = FALSE;
513 FIXME("Unsupported command in FormatExCB\n");
514 break;
515
516 default:
517 break;
518 }
519
520 return TRUE;
521}
BOOL WINAPI SetVolumeLabelW(IN LPCWSTR lpRootPathName, IN LPCWSTR lpVolumeName OPTIONAL)
Definition: volume.c:503
static PFORMAT_DRIVE_CONTEXT GetFormatContext()
Definition: drive.cpp:475
@ FSNOTSUPPORTED
Definition: fmifs.h:89
@ VOLUMEINUSE
Definition: fmifs.h:90
@ CLUSTERSIZETOOSMALL
Definition: fmifs.h:98
@ INSUFFICIENTRIGHTS
Definition: fmifs.h:88
@ PROGRESS
Definition: fmifs.h:82
DWORD * PDWORD
Definition: pedump.c:68
#define PBM_SETPOS
Definition: commctrl.h:2189
#define DONE
Definition: rnr20lib.h:14
#define IDS_FORMAT_COMPLETE
Definition: shresdef.h:203
Definition: shell.h:41
unsigned char * PBOOLEAN
Definition: typedefs.h:53
UINT_PTR WPARAM
Definition: windef.h:207
#define MB_OK
Definition: winuser.h:801
#define MB_ICONINFORMATION
Definition: winuser.h:813

Referenced by FormatDrive().

◆ GetDefaultClusterSize()

static BOOL GetDefaultClusterSize ( LPWSTR  szFs,
PDWORD  pClusterSize,
PULARGE_INTEGER  TotalNumberOfBytes 
)
static

Definition at line 152 of file drive.cpp.

153{
155
156 if (!_wcsicmp(szFs, L"FAT16") ||
157 !_wcsicmp(szFs, L"FAT")) // REACTOS HACK
158 {
159 if (TotalNumberOfBytes->QuadPart <= (16 * 1024 * 1024))
160 ClusterSize = 2048;
161 else if (TotalNumberOfBytes->QuadPart <= (32 * 1024 * 1024))
162 ClusterSize = 512;
163 else if (TotalNumberOfBytes->QuadPart <= (64 * 1024 * 1024))
164 ClusterSize = 1024;
165 else if (TotalNumberOfBytes->QuadPart <= (128 * 1024 * 1024))
166 ClusterSize = 2048;
167 else if (TotalNumberOfBytes->QuadPart <= (256 * 1024 * 1024))
168 ClusterSize = 4096;
169 else if (TotalNumberOfBytes->QuadPart <= (512 * 1024 * 1024))
170 ClusterSize = 8192;
171 else if (TotalNumberOfBytes->QuadPart <= (1024 * 1024 * 1024))
172 ClusterSize = 16384;
173 else if (TotalNumberOfBytes->QuadPart <= (2048LL * 1024LL * 1024LL))
174 ClusterSize = 32768;
175 else if (TotalNumberOfBytes->QuadPart <= (4096LL * 1024LL * 1024LL))
176 ClusterSize = 8192;
177 else
178 return FALSE;
179 }
180 else if (!_wcsicmp(szFs, L"FAT32"))
181 {
182 if (TotalNumberOfBytes->QuadPart <= (64 * 1024 * 1024))
183 ClusterSize = 512;
184 else if (TotalNumberOfBytes->QuadPart <= (128 * 1024 * 1024))
185 ClusterSize = 1024;
186 else if (TotalNumberOfBytes->QuadPart <= (256 * 1024 * 1024))
187 ClusterSize = 2048;
188 else if (TotalNumberOfBytes->QuadPart <= (8192LL * 1024LL * 1024LL))
189 ClusterSize = 2048;
190 else if (TotalNumberOfBytes->QuadPart <= (16384LL * 1024LL * 1024LL))
191 ClusterSize = 8192;
192 else if (TotalNumberOfBytes->QuadPart <= (32768LL * 1024LL * 1024LL))
193 ClusterSize = 16384;
194 else
195 return FALSE;
196 }
197 else if (!_wcsicmp(szFs, L"FATX"))
198 {
199 if (TotalNumberOfBytes->QuadPart <= (16 * 1024 * 1024))
200 ClusterSize = 2048;
201 else if (TotalNumberOfBytes->QuadPart <= (32 * 1024 * 1024))
202 ClusterSize = 512;
203 else if (TotalNumberOfBytes->QuadPart <= (64 * 1024 * 1024))
204 ClusterSize = 1024;
205 else if (TotalNumberOfBytes->QuadPart <= (128 * 1024 * 1024))
206 ClusterSize = 2048;
207 else if (TotalNumberOfBytes->QuadPart <= (256 * 1024 * 1024))
208 ClusterSize = 4096;
209 else if (TotalNumberOfBytes->QuadPart <= (8192LL * 1024LL * 1024LL))
210 ClusterSize = 2048;
211 else if (TotalNumberOfBytes->QuadPart <= (16384LL * 1024LL * 1024LL))
212 ClusterSize = 8192;
213 else if (TotalNumberOfBytes->QuadPart <= (32768LL * 1024LL * 1024LL))
214 ClusterSize = 16384;
215 else
216 return FALSE;
217 }
218 else if (!_wcsicmp(szFs, L"NTFS"))
219 {
220 if (TotalNumberOfBytes->QuadPart <= (512 * 1024 * 1024))
221 ClusterSize = 512;
222 else if (TotalNumberOfBytes->QuadPart <= (1024 * 1024 * 1024))
223 ClusterSize = 1024;
224 else if (TotalNumberOfBytes->QuadPart <= (2048LL * 1024LL * 1024LL))
225 ClusterSize = 2048;
226 else
227 ClusterSize = 2048;
228 }
229 else if (!_wcsicmp(szFs, L"EXT2"))
230 {
231 // auto block size calculation
232 ClusterSize = 0;
233 }
234 else if (!_wcsicmp(szFs, L"BtrFS"))
235 {
236 // auto block size calculation
237 ClusterSize = 0;
238 }
239 else
240 return FALSE;
241
242 *pClusterSize = ClusterSize;
243 return TRUE;
244}
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185

Referenced by InsertDefaultClusterSizeForFs().

◆ GetFormatContext()

static PFORMAT_DRIVE_CONTEXT GetFormatContext ( )
inlinestatic

Definition at line 475 of file drive.cpp.

476{
477 // FormatEx does not allow us to specify a context parameter so we have to store it in the thread
478 return (PFORMAT_DRIVE_CONTEXT)NtCurrentTeb()->NtTib.ArbitraryUserPointer;
479}

Referenced by FormatExCB().

◆ GetLogicalDriveSize()

static BOOL GetLogicalDriveSize ( WORD  DriveNumber,
ULARGE_INTEGER Result 
)
static

Definition at line 83 of file drive.cpp.

84{
85 BOOL bSuccess = FALSE;
86 const WCHAR szDrivePath[] = { WCHAR(DriveNumber + 'A'), ':', '\\', '\0' };
87
88 HANDLE hDevice = OpenLogicalDriveHandle(DriveNumber);
89 if (hDevice != INVALID_HANDLE_VALUE)
90 {
91 GET_LENGTH_INFORMATION LengthInfo;
92 bSuccess = DevIoCtl(hDevice, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &LengthInfo, sizeof(LengthInfo));
93 Result.QuadPart = LengthInfo.Length.QuadPart;
94 if (!bSuccess && GetDriveTypeW(szDrivePath) == DRIVE_REMOVABLE) // Blank floppy
95 {
97 bSuccess = DevIoCtl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &dg, sizeof(dg));
98 if (bSuccess)
100 }
101 CloseHandle(hDevice);
102 }
103 if (!bSuccess || !Result.QuadPart)
104 bSuccess = GetDiskFreeSpaceExW(szDrivePath, NULL, &Result, NULL); // Note: Not exact if NTFS quotas are in effect
105 return bSuccess;
106}
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
BOOL WINAPI GetDiskFreeSpaceExW(IN LPCWSTR lpDirectoryName OPTIONAL, OUT PULARGE_INTEGER lpFreeBytesAvailableToCaller, OUT PULARGE_INTEGER lpTotalNumberOfBytes, OUT PULARGE_INTEGER lpTotalNumberOfFreeBytes)
Definition: disk.c:342
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: imports.h:192
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:400
ULONG TracksPerCylinder
Definition: ntdddisk.h:402
ULONG SectorsPerTrack
Definition: ntdddisk.h:403
ULONG BytesPerSector
Definition: ntdddisk.h:404
LARGE_INTEGER Length
Definition: imports.h:232
LONGLONG QuadPart
Definition: typedefs.h:114
_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

Referenced by InitializeFormatDriveDlg(), and InsertDefaultClusterSizeForFs().

◆ InitializeFormatDriveDlg()

static VOID InitializeFormatDriveDlg ( HWND  hwndDlg,
PFORMAT_DRIVE_CONTEXT  pContext 
)
static

Definition at line 373 of file drive.cpp.

374{
375 WCHAR szDrive[] = { WCHAR(pContext->Drive + 'A'), ':', '\\', '\0' };
376 WCHAR szText[120], szFs[30];
378 ULARGE_INTEGER TotalNumberOfBytes;
379 DWORD dwIndex, dwDefault;
380 UCHAR uMinor, uMajor;
381 BOOLEAN Latest;
382 HWND hwndFileSystems;
383
384 pContext->hWndMain = hwndDlg;
385 pContext->hWndTipTrigger = GetDlgItem(hwndDlg, 30000);
386 TTTOOLINFOW tool;
387 tool.cbSize = sizeof(tool);
388 tool.hwnd = hwndDlg;
390 tool.uId = (UINT_PTR)pContext->hWndTipTrigger;
394 0, 0, 0, 0, hwndDlg, NULL, NULL, NULL);
395 SendMessageW(pContext->hWndTip, TTM_ADDTOOLW, 0, (LPARAM)&tool);
398 SendMessageW(pContext->hWndTipTrigger, STM_SETICON, (WPARAM)hIco, 0);
399
400 cchText = GetWindowTextW(hwndDlg, szText, _countof(szText) - 1);
401 szText[cchText++] = L' ';
402 szFs[0] = UNICODE_NULL;
403 if (GetVolumeInformationW(szDrive, &szText[cchText], _countof(szText) - cchText, NULL, NULL, NULL, szFs, _countof(szFs)))
404 {
405 if (szText[cchText] == UNICODE_NULL)
406 {
407 /* load default volume label */
409 }
410 else
411 {
412 /* set volume label */
413 SetDlgItemTextW(hwndDlg, 28679, &szText[cchText]);
414 cchText += wcslen(&szText[cchText]);
415 }
416 }
417
418 StringCchPrintfW(szText + cchText, _countof(szText) - cchText, L" (%c:)", szDrive[0]);
419
420 /* set window text */
421 SetWindowTextW(hwndDlg, szText);
422
423 if (GetLogicalDriveSize(pContext->Drive, TotalNumberOfBytes))
424 {
425 if (StrFormatByteSizeW(TotalNumberOfBytes.QuadPart, szText, _countof(szText)))
426 {
427 /* add drive capacity */
428 SendDlgItemMessageW(hwndDlg, 28673, CB_ADDSTRING, 0, (LPARAM)szText);
429 SendDlgItemMessageW(hwndDlg, 28673, CB_SETCURSEL, 0, (LPARAM)0);
430 }
431 }
432 else
433 {
434 /* No known size, don't allow format (no partition or no floppy) */
435 EnableFormatDriveDlgControls(hwndDlg, -1);
436 }
437
438 if (pContext->Options & SHFMT_OPT_FULL)
439 {
440 /* check quick format button */
441 SendDlgItemMessageW(hwndDlg, 28674, BM_SETCHECK, BST_CHECKED, 0);
442 }
443
444 /* enumerate all available filesystems */
445 dwIndex = 0;
446 dwDefault = 0;
447 hwndFileSystems = GetDlgItem(hwndDlg, 28677);
448
449 int iForceDefault = -1;
450 while (QueryAvailableFileSystemFormat(dwIndex, szText, &uMajor, &uMinor, &Latest))
451 {
452 if (!_wcsicmp(szText, szFs))
453 iForceDefault = dwDefault = dwIndex; /* default to the same filesystem */
454
455 if (iForceDefault < 0 && !_wcsicmp(szText, L"NTFS") && !IsFloppy(szDrive))
456 dwDefault = dwIndex;
457
458 SendMessageW(hwndFileSystems, CB_ADDSTRING, 0, (LPARAM)szText);
459 dwIndex++;
460 }
461
462 if (!dwIndex)
463 {
464 ERR("no filesystem providers\n");
465 return;
466 }
467
468 /* select default filesys */
469 SendMessageW(hwndFileSystems, CB_SETCURSEL, dwDefault, 0);
470 /* setup cluster combo */
471 InsertDefaultClusterSizeForFs(hwndDlg, pContext);
472}
unsigned char BOOLEAN
BOOLEAN NTAPI QueryAvailableFileSystemFormat(IN DWORD Index, IN OUT PWCHAR FileSystem, OUT UCHAR *Major, OUT UCHAR *Minor, OUT BOOLEAN *LatestVersion)
Definition: query.c:20
BOOL WINAPI GetVolumeInformationW(IN LPCWSTR lpRootPathName, IN LPWSTR lpVolumeNameBuffer, IN DWORD nVolumeNameSize, OUT LPDWORD lpVolumeSerialNumber OPTIONAL, OUT LPDWORD lpMaximumComponentLength OPTIONAL, OUT LPDWORD lpFileSystemFlags OPTIONAL, OUT LPWSTR lpFileSystemNameBuffer OPTIONAL, IN DWORD nFileSystemNameSize)
Definition: volume.c:226
static BOOL GetLogicalDriveSize(WORD DriveNumber, ULARGE_INTEGER &Result)
Definition: drive.cpp:83
static BOOL IsFloppy(PCWSTR pszDrive)
Definition: drive.cpp:48
LPWSTR WINAPI StrFormatByteSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
Definition: string.c:2394
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static HICON
Definition: imagelist.c:80
#define WS_POPUP
Definition: pedump.c:616
#define WS_EX_TOPMOST
Definition: pedump.c:647
#define LPSTR_TEXTCALLBACKW
Definition: commctrl.h:2385
#define TOOLTIPS_CLASSW
Definition: commctrl.h:1707
#define TTF_IDISHWND
Definition: commctrl.h:1764
#define TTF_SUBCLASS
Definition: commctrl.h:1767
#define TTM_ADDTOOLW
Definition: commctrl.h:1792
#define TTS_ALWAYSTIP
Definition: commctrl.h:1757
#define TTF_ABSOLUTE
Definition: commctrl.h:1769
#define TTS_NOPREFIX
Definition: commctrl.h:1758
#define TTF_TRACK
Definition: commctrl.h:1768
#define TTS_BALLOON
Definition: commctrl.h:1761
#define IDI_SHELL_IDEA
Definition: shresdef.h:804
#define IDS_DRIVE_FIXED
Definition: shresdef.h:111
LPWSTR lpszText
Definition: commctrl.h:1746
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1394
#define STM_SETICON
Definition: winuser.h:2103
#define IMAGE_ICON
Definition: winuser.h:212
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE hInst, _In_ LPCWSTR name, _In_ UINT type, _In_ int cx, _In_ int cy, _In_ UINT fuLoad)
Definition: cursoricon.c:2540
#define CB_SETCURSEL
Definition: winuser.h:1972
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define BM_SETCHECK
Definition: winuser.h:1932
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
#define SM_CXSMICON
Definition: winuser.h:1023
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define CB_ADDSTRING
Definition: winuser.h:1947
_In_ int cchText
Definition: winuser.h:4476
#define LR_SHARED
Definition: winuser.h:1111
int WINAPI GetSystemMetrics(_In_ int)
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by FormatDriveDlg().

◆ InsertDefaultClusterSizeForFs()

static VOID InsertDefaultClusterSizeForFs ( HWND  hwndDlg,
PFORMAT_DRIVE_CONTEXT  pContext 
)
static

Definition at line 247 of file drive.cpp.

248{
249 WCHAR wszBuf[100] = {0};
250 WCHAR wszDefaultSize[100] = {0};
251 PCWSTR pwszFsSizeLimit;
252 INT iSelIndex;
253 ULARGE_INTEGER TotalNumberOfBytes;
255 LRESULT lIndex;
256 HWND hDlgCtrl;
257
258 hDlgCtrl = GetDlgItem(hwndDlg, 28677);
259 iSelIndex = SendMessage(hDlgCtrl, CB_GETCURSEL, 0, 0);
260 if (iSelIndex == CB_ERR)
261 return;
262
263 if (SendMessageW(hDlgCtrl, CB_GETLBTEXT, iSelIndex, (LPARAM)wszBuf) == CB_ERR)
264 return;
265
266 if (!GetLogicalDriveSize(pContext->Drive, TotalNumberOfBytes))
267 return;
268
269 if (!_wcsicmp(wszBuf, L"FAT16") ||
270 !_wcsicmp(wszBuf, L"FAT")) // REACTOS HACK
271 {
272 pwszFsSizeLimit = L"4GB";
273 }
274 else if (!_wcsicmp(wszBuf, L"FAT32"))
275 {
276 pwszFsSizeLimit = L"32GB";
277 }
278 else if (!_wcsicmp(wszBuf, L"FATX"))
279 {
280 pwszFsSizeLimit = L"1GB/32GB";
281 }
282 else if (!_wcsicmp(wszBuf, L"NTFS"))
283 {
284 pwszFsSizeLimit = L"256TB";
285 }
286 else if (!_wcsicmp(wszBuf, L"EXT2"))
287 {
288 pwszFsSizeLimit = L"32TB";
289 }
290 else
291 {
292 pwszFsSizeLimit = L"16EB";
293 }
294
295 if (!_wcsicmp(wszBuf, L"FAT16") ||
296 !_wcsicmp(wszBuf, L"FAT") || // REACTOS HACK
297 !_wcsicmp(wszBuf, L"FAT32") ||
298 !_wcsicmp(wszBuf, L"FATX") ||
299 !_wcsicmp(wszBuf, L"NTFS") ||
300 !_wcsicmp(wszBuf, L"EXT2") ||
301 !_wcsicmp(wszBuf, L"BtrFS"))
302 {
303 if (!GetDefaultClusterSize(wszBuf, &ClusterSize, &TotalNumberOfBytes))
304 {
305 TRACE("%S is not supported on drive larger than %S, current size: %lu\n", wszBuf, pwszFsSizeLimit, TotalNumberOfBytes.QuadPart);
306 SendMessageW(hDlgCtrl, CB_DELETESTRING, iSelIndex, 0);
307 return;
308 }
309
310 if (LoadStringW(shell32_hInstance, IDS_DEFAULT_CLUSTER_SIZE, wszDefaultSize, _countof(wszDefaultSize)))
311 {
312 hDlgCtrl = GetDlgItem(hwndDlg, 28680); // Get the window handle of "allocation unit size" combobox
313 SendMessageW(hDlgCtrl, CB_RESETCONTENT, 0, 0);
314 lIndex = SendMessageW(hDlgCtrl, CB_ADDSTRING, 0, (LPARAM)wszDefaultSize);
315 if (lIndex != CB_ERR)
316 SendMessageW(hDlgCtrl, CB_SETITEMDATA, lIndex, (LPARAM)ClusterSize);
317 SendMessageW(hDlgCtrl, CB_SETCURSEL, 0, 0);
318 }
319
320 if (!_wcsicmp(wszBuf, L"NTFS"))
321 {
322 ClusterSize = 512;
323 for (lIndex = 0; lIndex < 4; lIndex++)
324 {
325 TotalNumberOfBytes.QuadPart = ClusterSize;
326 if (StrFormatByteSizeW(TotalNumberOfBytes.QuadPart, wszDefaultSize, _countof(wszDefaultSize)))
327 {
328 lIndex = SendMessageW(hDlgCtrl, CB_ADDSTRING, 0, (LPARAM)wszDefaultSize);
329 if (lIndex != CB_ERR)
330 SendMessageW(hDlgCtrl, CB_SETITEMDATA, lIndex, (LPARAM)ClusterSize);
331 }
332 ClusterSize *= 2;
333 }
334 }
335
336 SendMessageW(GetDlgItem(hwndDlg, 28675), BM_SETCHECK, BST_UNCHECKED, 0);
337#if 0 // TODO: Call EnableVolumeCompression if checked
338 if (!_wcsicmp(wszBuf, L"EXT2") ||
339 !_wcsicmp(wszBuf, L"BtrFS") ||
340 !_wcsicmp(wszBuf, L"NTFS"))
341 {
342 /* Enable the "Enable Compression" button */
343 EnableWindow(GetDlgItem(hwndDlg, 28675), TRUE);
344 }
345 else
346#endif
347 {
348 /* Disable the "Enable Compression" button */
349 EnableWindow(GetDlgItem(hwndDlg, 28675), FALSE);
350 }
351 }
352 else
353 {
354 FIXME("Unknown filesystem: %ls\n", wszBuf);
355 SendDlgItemMessageW(hwndDlg, 28680, CB_RESETCONTENT, iSelIndex, 0);
356 return;
357 }
358}
static BOOL GetDefaultClusterSize(LPWSTR szFs, PDWORD pClusterSize, PULARGE_INTEGER TotalNumberOfBytes)
Definition: drive.cpp:152
#define IDS_DEFAULT_CLUSTER_SIZE
Definition: shresdef.h:228
#define TRACE(s)
Definition: solgame.cpp:4
const uint16_t * PCWSTR
Definition: typedefs.h:57
LONG_PTR LRESULT
Definition: windef.h:209
#define CB_SETITEMDATA
Definition: winuser.h:1977
#define BST_UNCHECKED
Definition: winuser.h:199
#define CB_RESETCONTENT
Definition: winuser.h:1970
#define CB_DELETESTRING
Definition: winuser.h:1948

Referenced by FormatDriveDlg(), and InitializeFormatDriveDlg().

◆ IsDriveFloppyW()

BOOL IsDriveFloppyW ( LPCWSTR  pszDriveRoot)

Definition at line 320 of file drvdefext.cpp.

321{
322 LPCWSTR RootPath = pszDriveRoot;
323 WCHAR szRoot[16], szDeviceName[16];
324 UINT uType;
325 HANDLE hDevice;
327 ULONG ulCharacteristics;
328 BOOL ret;
329
330 lstrcpynW(szRoot, RootPath, _countof(szRoot));
331
332 if (L'a' <= szRoot[0] && szRoot[0] <= 'z')
333 {
334 szRoot[0] += ('A' - 'a');
335 }
336
337 if ('A' <= szRoot[0] && szRoot[0] <= L'Z' &&
338 szRoot[1] == L':' && szRoot[2] == 0)
339 {
340 // 'C:' --> 'C:\'
341 szRoot[2] = L'\\';
342 szRoot[3] = 0;
343 }
344
345 if (!PathIsRootW(szRoot))
346 {
347 return FALSE;
348 }
349
350 uType = GetDriveTypeW(szRoot);
351 if (uType == DRIVE_REMOVABLE)
352 {
353 if (szRoot[0] == L'A' || szRoot[0] == L'B')
354 return TRUE;
355 }
356 else
357 {
358 return FALSE;
359 }
360
362 szDeviceName[4] = szRoot[0];
363 szDeviceName[5] = L':';
365
368 NULL, OPEN_EXISTING, 0, NULL);
369 if (hDevice == INVALID_HANDLE_VALUE)
370 {
371 return FALSE;
372 }
373
374 ret = FALSE;
375 if (GetDriveTypeAndCharacteristics(hDevice, &DeviceType, &ulCharacteristics))
376 {
377 if ((ulCharacteristics & FILE_FLOPPY_DISKETTE) == FILE_FLOPPY_DISKETTE)
378 ret = TRUE;
379 }
380
381 CloseHandle(hDevice);
382
383 return ret;
384}
static const WCHAR szDeviceName[]
Definition: provider.c:56
#define DEVICE_TYPE
Definition: guid.c:10
#define OPEN_EXISTING
Definition: compat.h:775
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
#define lstrcpynW
Definition: compat.h:738
BOOL WINAPI PathIsRootW(LPCWSTR lpszPath)
Definition: path.c:1648
static BOOL GetDriveTypeAndCharacteristics(HANDLE hDevice, DEVICE_TYPE *pDeviceType, ULONG *pCharacteristics)
Definition: drvdefext.cpp:301
DeviceType
Definition: mmdrv.h:42
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
int ret
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by CDrvDefExt::InitGeneralPage(), and IsFloppy().

◆ IsFloppy()

static BOOL IsFloppy ( PCWSTR  pszDrive)
static

Definition at line 48 of file drive.cpp.

49{
50 return GetDriveTypeW(pszDrive) == DRIVE_REMOVABLE && IsDriveFloppyW(pszDrive);
51}
BOOL IsDriveFloppyW(LPCWSTR pszDriveRoot)
Definition: drvdefext.cpp:320

Referenced by InitializeFormatDriveDlg(), InstallBootcodeToRemovable(), USBSTOR_GetDeviceType(), and USBSTOR_GetGenericType().

◆ IsSystemDrive()

static BOOL IsSystemDrive ( PFORMAT_DRIVE_CONTEXT  pContext)
static

Definition at line 66 of file drive.cpp.

67{
68 WCHAR wszSystemDrv[MAX_PATH];
69 wszSystemDrv[0] = UNICODE_NULL;
70 GetSystemDirectory(wszSystemDrv, _countof(wszSystemDrv));
71 return (wszSystemDrv[0] | 32) == pContext->Drive + L'a';
72}
#define MAX_PATH
Definition: compat.h:34
#define GetSystemDirectory
Definition: winbase.h:3873

Referenced by SHFormatDrive().

◆ OpenLogicalDriveHandle()

static HANDLE OpenLogicalDriveHandle ( WORD  DriveNumber)
static

Definition at line 75 of file drive.cpp.

76{
77 const WCHAR szPath[] = { '\\', '\\', '?', '\\', WCHAR(DriveNumber + 'A'), ':', '\0' };
80}
LPCWSTR szPath
Definition: env.c:37
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_SHARE_DELETE
Definition: nt_native.h:682

Referenced by CreateTipText(), and GetLogicalDriveSize().

◆ SHFormatDrive()

DWORD WINAPI SHFormatDrive ( HWND  hwnd,
UINT  drive,
UINT  fmtID,
UINT  options 
)

Definition at line 762 of file drive.cpp.

763{
765 int result;
766
767 TRACE("%p, 0x%08x, 0x%08x, 0x%08x - stub\n", hwnd, drive, fmtID, options);
768
769 Context.Drive = drive;
770 Context.Options = options;
771 Context.Result = FALSE;
772 Context.bFormattingNow = FALSE;
773
774 if (!IsSystemDrive(&Context))
775 {
777 }
778 else
779 {
782 TRACE("SHFormatDrive(): The provided drive for format is a system volume! Aborting...\n");
783 }
784
785 return result;
786}
static INT_PTR CALLBACK FormatDriveDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: drive.cpp:671
static BOOL IsSystemDrive(PFORMAT_DRIVE_CONTEXT pContext)
Definition: drive.cpp:66
GLuint64EXT * result
Definition: glext.h:11304
#define IDS_NO_FORMAT_TITLE
Definition: shresdef.h:206
#define IDS_NO_FORMAT
Definition: shresdef.h:207
#define IDD_FORMAT_DRIVE
Definition: shresdef.h:545
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)

Referenced by DoFormatDriveThread().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( shell  )