ReactOS  0.4.15-dev-4857-g47842d7
drive.cpp
Go to the documentation of this file.
1 /*
2  * Shell Library Functions
3  *
4  * Copyright 2005 Johannes Anderwald
5  * Copyright 2017 Katayama Hirofumi MZ
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "precomp.h"
23 #include <process.h>
24 
26 
27 typedef struct
28 {
34 
35 EXTERN_C HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface, IDataObject *pDataObj);
37 
38 /*
39  * TODO: In Windows the Shell doesn't know by itself if a drive is
40  * a system one or not but rather a packet message is being sent by
41  * FMIFS library code and further translated into specific packet
42  * status codes in the Shell, the packet being _FMIFS_PACKET_TYPE.
43  *
44  * With that being said, most of this code as well as FMIFS library code
45  * have to be refactored in order to comply with the way Windows works.
46  *
47  * See the enum definition for more details:
48  * https://github.com/microsoft/winfile/blob/master/src/fmifs.h#L23
49  */
50 static BOOL
52 {
53  WCHAR wszDriveLetter[6], wszSystemDrv[6];
54 
55  wszDriveLetter[0] = pContext->Drive + L'A';
56  StringCchCatW(wszDriveLetter, _countof(wszDriveLetter), L":");
57 
58  if (!GetEnvironmentVariableW(L"SystemDrive", wszSystemDrv, _countof(wszSystemDrv)))
59  return FALSE;
60 
61  if (!wcsicmp(wszDriveLetter, wszSystemDrv))
62  return TRUE;
63 
64  return FALSE;
65 }
66 
67 static BOOL
68 GetDefaultClusterSize(LPWSTR szFs, PDWORD pClusterSize, PULARGE_INTEGER TotalNumberOfBytes)
69 {
71 
72  if (!wcsicmp(szFs, L"FAT16") ||
73  !wcsicmp(szFs, L"FAT")) // REACTOS HACK
74  {
75  if (TotalNumberOfBytes->QuadPart <= (16 * 1024 * 1024))
76  ClusterSize = 2048;
77  else if (TotalNumberOfBytes->QuadPart <= (32 * 1024 * 1024))
78  ClusterSize = 512;
79  else if (TotalNumberOfBytes->QuadPart <= (64 * 1024 * 1024))
80  ClusterSize = 1024;
81  else if (TotalNumberOfBytes->QuadPart <= (128 * 1024 * 1024))
82  ClusterSize = 2048;
83  else if (TotalNumberOfBytes->QuadPart <= (256 * 1024 * 1024))
84  ClusterSize = 4096;
85  else if (TotalNumberOfBytes->QuadPart <= (512 * 1024 * 1024))
86  ClusterSize = 8192;
87  else if (TotalNumberOfBytes->QuadPart <= (1024 * 1024 * 1024))
88  ClusterSize = 16384;
89  else if (TotalNumberOfBytes->QuadPart <= (2048LL * 1024LL * 1024LL))
90  ClusterSize = 32768;
91  else if (TotalNumberOfBytes->QuadPart <= (4096LL * 1024LL * 1024LL))
92  ClusterSize = 8192;
93  else
94  return FALSE;
95  }
96  else if (!wcsicmp(szFs, L"FAT32"))
97  {
98  if (TotalNumberOfBytes->QuadPart <= (64 * 1024 * 1024))
99  ClusterSize = 512;
100  else if (TotalNumberOfBytes->QuadPart <= (128 * 1024 * 1024))
101  ClusterSize = 1024;
102  else if (TotalNumberOfBytes->QuadPart <= (256 * 1024 * 1024))
103  ClusterSize = 2048;
104  else if (TotalNumberOfBytes->QuadPart <= (8192LL * 1024LL * 1024LL))
105  ClusterSize = 2048;
106  else if (TotalNumberOfBytes->QuadPart <= (16384LL * 1024LL * 1024LL))
107  ClusterSize = 8192;
108  else if (TotalNumberOfBytes->QuadPart <= (32768LL * 1024LL * 1024LL))
109  ClusterSize = 16384;
110  else
111  return FALSE;
112  }
113  else if (!wcsicmp(szFs, L"FATX"))
114  {
115  if (TotalNumberOfBytes->QuadPart <= (16 * 1024 * 1024))
116  ClusterSize = 2048;
117  else if (TotalNumberOfBytes->QuadPart <= (32 * 1024 * 1024))
118  ClusterSize = 512;
119  else if (TotalNumberOfBytes->QuadPart <= (64 * 1024 * 1024))
120  ClusterSize = 1024;
121  else if (TotalNumberOfBytes->QuadPart <= (128 * 1024 * 1024))
122  ClusterSize = 2048;
123  else if (TotalNumberOfBytes->QuadPart <= (256 * 1024 * 1024))
124  ClusterSize = 4096;
125  else if (TotalNumberOfBytes->QuadPart <= (8192LL * 1024LL * 1024LL))
126  ClusterSize = 2048;
127  else if (TotalNumberOfBytes->QuadPart <= (16384LL * 1024LL * 1024LL))
128  ClusterSize = 8192;
129  else if (TotalNumberOfBytes->QuadPart <= (32768LL * 1024LL * 1024LL))
130  ClusterSize = 16384;
131  else
132  return FALSE;
133  }
134  else if (!wcsicmp(szFs, L"NTFS"))
135  {
136  if (TotalNumberOfBytes->QuadPart <= (512 * 1024 * 1024))
137  ClusterSize = 512;
138  else if (TotalNumberOfBytes->QuadPart <= (1024 * 1024 * 1024))
139  ClusterSize = 1024;
140  else if (TotalNumberOfBytes->QuadPart <= (2048LL * 1024LL * 1024LL))
141  ClusterSize = 2048;
142  else
143  ClusterSize = 2048;
144  }
145  else if (!wcsicmp(szFs, L"EXT2"))
146  {
147  // auto block size calculation
148  ClusterSize = 0;
149  }
150  else if (!wcsicmp(szFs, L"BtrFS"))
151  {
152  // auto block size calculation
153  ClusterSize = 0;
154  }
155  else
156  return FALSE;
157 
158  *pClusterSize = ClusterSize;
159  return TRUE;
160 }
161 
162 typedef struct _DRIVE_PROP_PAGE
163 {
168 
169 HRESULT
171 {
172  HPSXA hpsx = NULL;
174  PROPSHEETHEADERW psh;
175  CComObject<CDrvDefExt> *pDrvDefExt = NULL;
176  WCHAR wszName[256];
177 
178  ZeroMemory(&psh, sizeof(PROPSHEETHEADERW));
179  psh.dwSize = sizeof(PROPSHEETHEADERW);
180  psh.dwFlags = 0; // FIXME: make it modeless
181  psh.hwndParent = NULL;
182  psh.nStartPage = 0;
183  psh.phpage = hpsp;
184 
185  LPITEMIDLIST completePidl = ILCombine(pidlFolder, apidl[0]);
186  if (!completePidl)
187  return E_OUTOFMEMORY;
188 
189  if (ILGetDisplayNameExW(NULL, completePidl, wszName, ILGDN_NORMAL))
190  {
191  psh.pszCaption = wszName;
192  psh.dwFlags |= PSH_PROPTITLE;
193  }
194 
195  ILFree(completePidl);
196 
197  CComPtr<IDataObject> pDataObj;
198  HRESULT hr = SHCreateDataObject(pidlFolder, 1, apidl, NULL, IID_PPV_ARG(IDataObject, &pDataObj));
199 
200  if (SUCCEEDED(hr))
201  {
202  hr = CComObject<CDrvDefExt>::CreateInstance(&pDrvDefExt);
203  if (SUCCEEDED(hr))
204  {
205  pDrvDefExt->AddRef(); // CreateInstance returns object with 0 ref count
206  hr = pDrvDefExt->Initialize(pidlFolder, pDataObj, NULL);
207  if (SUCCEEDED(hr))
208  {
209  hr = pDrvDefExt->AddPages(AddPropSheetPageCallback, (LPARAM)&psh);
210  if (FAILED(hr))
211  ERR("AddPages failed\n");
212  } else
213  ERR("Initialize failed\n");
214  }
215 
217  if (hpsx)
219  }
220 
221  // NOTE: Currently property sheet is modal. If we make it modeless, then it returns HWND.
222  INT_PTR ret = PropertySheetW(&psh);
223 
224  if (hpsx)
226  if (pDrvDefExt)
227  pDrvDefExt->Release();
228 
229  if (ret >= 0)
230  return S_OK;
231  return E_FAIL;
232 }
233 
234 static VOID
236 {
237  WCHAR wszBuf[100] = {0};
238  WCHAR wszDefaultSize[100] = {0};
239  PCWSTR pwszFsSizeLimit;
240  WCHAR szDrive[] = L"C:\\";
241  INT iSelIndex;
242  ULARGE_INTEGER FreeBytesAvailableUser, TotalNumberOfBytes;
244  LRESULT lIndex;
245  HWND hDlgCtrl;
246 
247  hDlgCtrl = GetDlgItem(hwndDlg, 28677);
248  iSelIndex = SendMessage(hDlgCtrl, CB_GETCURSEL, 0, 0);
249  if (iSelIndex == CB_ERR)
250  return;
251 
252  if (SendMessageW(hDlgCtrl, CB_GETLBTEXT, iSelIndex, (LPARAM)wszBuf) == CB_ERR)
253  return;
254 
255  szDrive[0] = pContext->Drive + L'A';
256 
257  if (!GetDiskFreeSpaceExW(szDrive, &FreeBytesAvailableUser, &TotalNumberOfBytes, NULL))
258  return;
259 
260  if (!wcsicmp(wszBuf, L"FAT16") ||
261  !wcsicmp(wszBuf, L"FAT")) // REACTOS HACK
262  {
263  pwszFsSizeLimit = L"4GB";
264  }
265  else if (!wcsicmp(wszBuf, L"FAT32"))
266  {
267  pwszFsSizeLimit = L"32GB";
268  }
269  else if (!wcsicmp(wszBuf, L"FATX"))
270  {
271  pwszFsSizeLimit = L"1GB/32GB";
272  }
273  else if (!wcsicmp(wszBuf, L"NTFS"))
274  {
275  pwszFsSizeLimit = L"256TB";
276  }
277  else if (!wcsicmp(wszBuf, L"EXT2"))
278  {
279  pwszFsSizeLimit = L"32TB";
280  }
281  else
282  {
283  pwszFsSizeLimit = L"16EB";
284  }
285 
286  if (!wcsicmp(wszBuf, L"FAT16") ||
287  !wcsicmp(wszBuf, L"FAT") || // REACTOS HACK
288  !wcsicmp(wszBuf, L"FAT32") ||
289  !wcsicmp(wszBuf, L"FATX") ||
290  !wcsicmp(wszBuf, L"NTFS") ||
291  !wcsicmp(wszBuf, L"EXT2") ||
292  !wcsicmp(wszBuf, L"BtrFS"))
293  {
294  if (!GetDefaultClusterSize(wszBuf, &ClusterSize, &TotalNumberOfBytes))
295  {
296  TRACE("%S is not supported on drive larger than %S, current size: %lu\n", wszBuf, pwszFsSizeLimit, TotalNumberOfBytes.QuadPart);
297  SendMessageW(hDlgCtrl, CB_DELETESTRING, iSelIndex, 0);
298  return;
299  }
300 
301  if (LoadStringW(shell32_hInstance, IDS_DEFAULT_CLUSTER_SIZE, wszDefaultSize, _countof(wszDefaultSize)))
302  {
303  hDlgCtrl = GetDlgItem(hwndDlg, 28680); // Get the window handle of "allocation unit size" combobox
304  SendMessageW(hDlgCtrl, CB_RESETCONTENT, 0, 0);
305  lIndex = SendMessageW(hDlgCtrl, CB_ADDSTRING, 0, (LPARAM)wszDefaultSize);
306  if (lIndex != CB_ERR)
307  SendMessageW(hDlgCtrl, CB_SETITEMDATA, lIndex, (LPARAM)ClusterSize);
308  SendMessageW(hDlgCtrl, CB_SETCURSEL, 0, 0);
309  }
310 
311  if (!wcsicmp(wszBuf, L"NTFS"))
312  {
313  ClusterSize = 512;
314  for (lIndex = 0; lIndex < 4; lIndex++)
315  {
316  TotalNumberOfBytes.QuadPart = ClusterSize;
317  if (StrFormatByteSizeW(TotalNumberOfBytes.QuadPart, wszDefaultSize, _countof(wszDefaultSize)))
318  {
319  lIndex = SendMessageW(hDlgCtrl, CB_ADDSTRING, 0, (LPARAM)wszDefaultSize);
320  if (lIndex != CB_ERR)
321  SendMessageW(hDlgCtrl, CB_SETITEMDATA, lIndex, (LPARAM)ClusterSize);
322  }
323  ClusterSize *= 2;
324  }
325  }
326 
327  SendMessageW(GetDlgItem(hwndDlg, 28675), BM_SETCHECK, BST_UNCHECKED, 0);
328  if (!wcsicmp(wszBuf, L"EXT2") ||
329  !wcsicmp(wszBuf, L"BtrFS") ||
330  !wcsicmp(wszBuf, L"NTFS"))
331  {
332  /* Enable the "Enable Compression" button */
333  EnableWindow(GetDlgItem(hwndDlg, 28675), TRUE);
334  }
335  else
336  {
337  /* Disable the "Enable Compression" button */
338  EnableWindow(GetDlgItem(hwndDlg, 28675), FALSE);
339  }
340  }
341  else
342  {
343  FIXME("Unknown filesystem: %ls\n", wszBuf);
344  SendDlgItemMessageW(hwndDlg, 28680, CB_RESETCONTENT, iSelIndex, 0);
345  return;
346  }
347 }
348 
349 static VOID
351 {
352  WCHAR szText[120];
353  WCHAR szDrive[] = L"C:\\";
354  WCHAR szFs[30] = L"";
355  INT cchText;
356  ULARGE_INTEGER FreeBytesAvailableUser, TotalNumberOfBytes;
357  DWORD dwIndex, dwDefault;
358  UCHAR uMinor, uMajor;
359  BOOLEAN Latest;
360  HWND hwndFileSystems;
361 
362  cchText = GetWindowTextW(hwndDlg, szText, _countof(szText) - 1);
363  if (cchText < 0)
364  cchText = 0;
365  szText[cchText++] = L' ';
366  szDrive[0] = pContext->Drive + L'A';
367  if (GetVolumeInformationW(szDrive, &szText[cchText], _countof(szText) - cchText, NULL, NULL, NULL, szFs, _countof(szFs)))
368  {
369  if (szText[cchText] == UNICODE_NULL)
370  {
371  /* load default volume label */
373  }
374  else
375  {
376  /* set volume label */
377  SetDlgItemTextW(hwndDlg, 28679, &szText[cchText]);
378  cchText += wcslen(&szText[cchText]);
379  }
380  }
381 
382  StringCchPrintfW(szText + cchText, _countof(szText) - cchText, L" (%c:)", szDrive[0]);
383 
384  /* set window text */
385  SetWindowTextW(hwndDlg, szText);
386 
387  if (GetDiskFreeSpaceExW(szDrive, &FreeBytesAvailableUser, &TotalNumberOfBytes, NULL))
388  {
389  if (StrFormatByteSizeW(TotalNumberOfBytes.QuadPart, szText, _countof(szText)))
390  {
391  /* add drive capacity */
392  SendDlgItemMessageW(hwndDlg, 28673, CB_ADDSTRING, 0, (LPARAM)szText);
393  SendDlgItemMessageW(hwndDlg, 28673, CB_SETCURSEL, 0, (LPARAM)0);
394  }
395  }
396 
397  if (pContext->Options & SHFMT_OPT_FULL)
398  {
399  /* check quick format button */
400  SendDlgItemMessageW(hwndDlg, 28674, BM_SETCHECK, BST_CHECKED, 0);
401  }
402 
403  /* enumerate all available filesystems */
404  dwIndex = 0;
405  dwDefault = 0;
406  hwndFileSystems = GetDlgItem(hwndDlg, 28677);
407 
408  while(QueryAvailableFileSystemFormat(dwIndex, szText, &uMajor, &uMinor, &Latest))
409  {
410  if (!wcsicmp(szText, szFs))
411  dwDefault = dwIndex;
412 
413  SendMessageW(hwndFileSystems, CB_ADDSTRING, 0, (LPARAM)szText);
414  dwIndex++;
415  }
416 
417  if (!dwIndex)
418  {
419  ERR("no filesystem providers\n");
420  return;
421  }
422 
423  /* select default filesys */
424  SendMessageW(hwndFileSystems, CB_SETCURSEL, dwDefault, 0);
425  /* setup cluster combo */
426  InsertDefaultClusterSizeForFs(hwndDlg, pContext);
427 }
428 
431 
432 static BOOLEAN NTAPI
435  IN ULONG SubAction,
436  IN PVOID ActionInfo)
437 {
438  PDWORD Progress;
439  PBOOLEAN pSuccess;
440  switch(Command)
441  {
442  case PROGRESS:
443  Progress = (PDWORD)ActionInfo;
444  SendDlgItemMessageW(FormatDrvDialog, 28678, PBM_SETPOS, (WPARAM)*Progress, 0);
445  break;
446  case DONE:
447  pSuccess = (PBOOLEAN)ActionInfo;
448  bSuccess = (*pSuccess);
451  break;
452 
453  case VOLUMEINUSE:
454  case INSUFFICIENTRIGHTS:
455  case FSNOTSUPPORTED:
456  case CLUSTERSIZETOOSMALL:
457  bSuccess = FALSE;
458  FIXME("Unsupported command in FormatExCB\n");
459  break;
460 
461  default:
462  break;
463  }
464 
465  return TRUE;
466 }
467 
468 VOID
470 {
471  WCHAR szDrive[4] = { L'C', ':', '\\', 0 };
472  WCHAR szFileSys[40] = {0};
473  WCHAR szLabel[40] = {0};
474  INT iSelIndex;
475  UINT Length;
476  HWND hDlgCtrl;
480  FMIFS_MEDIA_FLAG MediaFlag = FMIFS_HARDDISK;
481 
482  /* set volume path */
483  szDrive[0] = pContext->Drive + L'A';
484 
485  /* get filesystem */
486  hDlgCtrl = GetDlgItem(hwndDlg, 28677);
487  iSelIndex = SendMessageW(hDlgCtrl, CB_GETCURSEL, 0, 0);
488  if (iSelIndex == CB_ERR)
489  {
490  ERR("Unable to get file system selection\n");
491  return;
492  }
493  Length = SendMessageW(hDlgCtrl, CB_GETLBTEXTLEN, iSelIndex, 0);
494  if ((int)Length == CB_ERR || Length + 1 > _countof(szFileSys))
495  {
496  ERR("Unable to get file system selection\n");
497  return;
498  }
499 
500  /* retrieve the file system */
501  SendMessageW(hDlgCtrl, CB_GETLBTEXT, iSelIndex, (LPARAM)szFileSys);
502  szFileSys[_countof(szFileSys)-1] = L'\0';
503 
504  /* retrieve the volume label */
505  hDlgCtrl = GetWindow(hwndDlg, 28679);
506  Length = SendMessageW(hDlgCtrl, WM_GETTEXTLENGTH, 0, 0);
507  if (Length + 1 > _countof(szLabel))
508  {
509  ERR("Unable to get volume label\n");
510  return;
511  }
512  SendMessageW(hDlgCtrl, WM_GETTEXT, _countof(szLabel), (LPARAM)szLabel);
513  szLabel[(sizeof(szLabel)/sizeof(WCHAR))-1] = L'\0';
514 
515  /* check for quickformat */
516  if (SendDlgItemMessageW(hwndDlg, 28674, BM_GETCHECK, 0, 0) == BST_CHECKED)
517  QuickFormat = TRUE;
518  else
519  QuickFormat = FALSE;
520 
521  /* get the cluster size */
522  hDlgCtrl = GetDlgItem(hwndDlg, 28680);
523  iSelIndex = SendMessageW(hDlgCtrl, CB_GETCURSEL, 0, 0);
524  if (iSelIndex == CB_ERR)
525  {
526  FIXME("\n");
527  return;
528  }
529  ClusterSize = SendMessageW(hDlgCtrl, CB_GETITEMDATA, iSelIndex, 0);
530  if ((int)ClusterSize == CB_ERR)
531  {
532  FIXME("\n");
533  return;
534  }
535 
536  hDlgCtrl = GetDlgItem(hwndDlg, 28680);
537  SendMessageW(hDlgCtrl, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
538  bSuccess = FALSE;
539 
540  /* FIXME
541  * will cause display problems
542  * when performing more than one format
543  */
544  FormatDrvDialog = hwndDlg;
545 
546  /* See if the drive is removable or not */
547  DriveType = GetDriveTypeW(szDrive);
548  switch (DriveType)
549  {
550  case DRIVE_UNKNOWN:
551  case DRIVE_REMOTE:
552  case DRIVE_CDROM:
553  case DRIVE_NO_ROOT_DIR:
554  {
555  FIXME("\n");
556  return;
557  }
558 
559  case DRIVE_REMOVABLE:
560  MediaFlag = FMIFS_FLOPPY;
561  break;
562 
563  case DRIVE_FIXED:
564  case DRIVE_RAMDISK:
565  MediaFlag = FMIFS_HARDDISK;
566  break;
567  }
568 
569  /* Format the drive */
570  FormatEx(szDrive,
571  MediaFlag,
572  szFileSys,
573  szLabel,
574  QuickFormat,
575  ClusterSize,
576  FormatExCB);
577 
579  if (!bSuccess)
580  {
581  pContext->Result = SHFMT_ERROR;
582  }
583  else if (QuickFormat)
584  {
585  pContext->Result = SHFMT_OPT_FULL;
586  }
587  else
588  {
589  pContext->Result = FALSE;
590  }
591 }
592 
594 {
597 };
598 
599 static unsigned __stdcall DoFormatDrive(void *args)
600 {
601  FORMAT_DRIVE_PARAMS *pParams = reinterpret_cast<FORMAT_DRIVE_PARAMS *>(args);
602  HWND hwndDlg = pParams->hwndDlg;
603  PFORMAT_DRIVE_CONTEXT pContext = pParams->pContext;
604 
605  /* Disable controls during format */
606  HMENU hSysMenu = GetSystemMenu(hwndDlg, FALSE);
608  EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
610  EnableWindow(GetDlgItem(hwndDlg, 28673), FALSE);
611  EnableWindow(GetDlgItem(hwndDlg, 28677), FALSE);
612  EnableWindow(GetDlgItem(hwndDlg, 28680), FALSE);
613  EnableWindow(GetDlgItem(hwndDlg, 28679), FALSE);
614  EnableWindow(GetDlgItem(hwndDlg, 28674), FALSE);
615 
616  FormatDrive(hwndDlg, pContext);
617 
618  /* Re-enable controls after format */
619  EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE);
620  EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), TRUE);
621  EnableWindow(GetDlgItem(hwndDlg, 28673), TRUE);
622  EnableWindow(GetDlgItem(hwndDlg, 28677), TRUE);
623  EnableWindow(GetDlgItem(hwndDlg, 28680), TRUE);
624  EnableWindow(GetDlgItem(hwndDlg, 28679), TRUE);
625  EnableWindow(GetDlgItem(hwndDlg, 28674), TRUE);
627  pContext->bFormattingNow = FALSE;
628 
629  delete pParams;
630  return 0;
631 }
632 
633 static INT_PTR CALLBACK
635 {
636  PFORMAT_DRIVE_CONTEXT pContext;
637 
638  switch(uMsg)
639  {
640  case WM_INITDIALOG:
643  return TRUE;
644  case WM_COMMAND:
645  switch(LOWORD(wParam))
646  {
647  case IDOK:
648  pContext = (PFORMAT_DRIVE_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);
649  if (pContext->bFormattingNow)
650  break;
651 
652  if (ShellMessageBoxW(shell32_hInstance, hwndDlg,
656  {
657  pContext->bFormattingNow = TRUE;
658 
660  pParams->hwndDlg = hwndDlg;
661  pParams->pContext = pContext;
662 
663  unsigned tid;
664  HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, DoFormatDrive, pParams, 0, &tid);
666  }
667  break;
668  case IDCANCEL:
669  pContext = (PFORMAT_DRIVE_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);
670  if (pContext->bFormattingNow)
671  break;
672 
673  EndDialog(hwndDlg, pContext->Result);
674  break;
675  case 28677: // filesystem combo
676  if (HIWORD(wParam) == CBN_SELENDOK)
677  {
678  pContext = (PFORMAT_DRIVE_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);
679  if (pContext->bFormattingNow)
680  break;
681 
682  InsertDefaultClusterSizeForFs(hwndDlg, pContext);
683  }
684  break;
685  }
686  }
687  return FALSE;
688 }
689 
690 /*************************************************************************
691  * SHFormatDrive (SHELL32.@)
692  */
693 
694 DWORD
695 WINAPI
697 {
699  int result;
700 
701  TRACE("%p, 0x%08x, 0x%08x, 0x%08x - stub\n", hwnd, drive, fmtID, options);
702 
703  Context.Drive = drive;
704  Context.Options = options;
705  Context.Result = FALSE;
706  Context.bFormattingNow = FALSE;
707 
708  if (!IsSystemDrive(&Context))
709  {
711  }
712  else
713  {
716  TRACE("SHFormatDrive(): The provided drive for format is a system volume! Aborting...\n");
717  }
718 
719  return result;
720 }
void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
Definition: shellord.c:2150
#define WM_GETTEXTLENGTH
Definition: winuser.h:1606
HWND hwndParent
Definition: prsht.h:295
LPWSTR WINAPI StrFormatByteSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
Definition: string.c:2380
#define CB_SETITEMDATA
Definition: winuser.h:1953
struct _DRIVE_PROP_PAGE DRIVE_PROP_PAGE
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define IN
Definition: typedefs.h:39
#define CB_GETLBTEXTLEN
Definition: winuser.h:1940
#define IDOK
Definition: winuser.h:824
#define CloseHandle
Definition: compat.h:598
#define LL
Definition: tui.h:150
BOOL CALLBACK AddPropSheetPageCallback(HPROPSHEETPAGE hPage, LPARAM lParam)
Definition: precomp.h:133
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define MF_BYCOMMAND
Definition: winuser.h:202
#define IDS_NO_FORMAT_TITLE
Definition: shresdef.h:203
HRESULT hr
Definition: shlfolder.c:183
GLuint64EXT * result
Definition: glext.h:11304
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
HRESULT WINAPI SHCreateDataObject(PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IDataObject *pdtInner, REFIID riid, void **ppv)
#define TRUE
Definition: types.h:120
#define CB_GETLBTEXT
Definition: winuser.h:1939
UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
Definition: shellord.c:1973
#define SHFMT_ERROR
Definition: shlobj.h:292
#define CB_GETITEMDATA
Definition: winuser.h:1937
#define WM_GETTEXT
Definition: winuser.h:1605
#define MAKELPARAM(l, h)
Definition: winuser.h:3988
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:699
#define DRIVE_RAMDISK
Definition: winbase.h:252
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define CALLBACK
Definition: compat.h:35
Definition: fmifs.h:68
UINT DriveType
#define ZeroMemory
Definition: winbase.h:1667
#define PBM_SETPOS
Definition: commctrl.h:2184
BOOL(CALLBACK * LPFNADDPROPSHEETPAGE)(HPROPSHEETPAGE, LPARAM)
Definition: prsht.h:327
static BOOL IsSystemDrive(PFORMAT_DRIVE_CONTEXT pContext)
Definition: drive.cpp:51
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
UINT_PTR WPARAM
Definition: windef.h:207
struct _PROPSHEETHEADERW PROPSHEETHEADERW
Definition: shell.h:41
int32_t INT_PTR
Definition: typedefs.h:64
_CRTIMP uintptr_t __cdecl _beginthreadex(_In_opt_ void *_Security, _In_ unsigned _StackSize, _In_ unsigned(__stdcall *_StartAddress)(void *), _In_opt_ void *_ArgList, _In_ unsigned _InitFlag, _Out_opt_ unsigned *_ThrdAddr)
CALLBACKCOMMAND
Definition: fmifs.h:66
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
Definition: match.c:390
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:58
static BOOLEAN bSuccess
Definition: drive.cpp:430
#define SetWindowLongPtr
Definition: treelist.c:70
#define CB_GETCURSEL
Definition: winuser.h:1930
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
#define DRIVE_REMOVABLE
Definition: winbase.h:248
#define MB_ICONWARNING
Definition: winuser.h:780
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
static VOID InsertDefaultClusterSizeForFs(HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
Definition: drive.cpp:235
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
static HWND FormatDrvDialog
Definition: drive.cpp:429
#define PBM_SETRANGE
Definition: commctrl.h:2183
#define L(x)
Definition: ntvdm.h:50
#define DRIVE_REMOTE
Definition: winbase.h:250
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define DRIVE_CDROM
Definition: machpc98.h:115
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
const PCUITEMID_CHILD * PCUITEMID_CHILD_ARRAY
Definition: shtypes.idl:71
LPCWSTR pszCaption
Definition: prsht.h:301
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CBN_SELENDOK
Definition: winuser.h:1968
if SUCCEEDED(hr)
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
#define FIXME(fmt,...)
Definition: debug.h:111
#define CB_ADDSTRING
Definition: winuser.h:1923
unsigned char BOOLEAN
HMENU WINAPI GetSystemMenu(_In_ HWND, _In_ BOOL)
VOID FormatDrive(HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
Definition: drive.cpp:469
#define ILGDN_NORMAL
Definition: undocshell.h:69
LONG_PTR LPARAM
Definition: windef.h:208
#define MB_OKCANCEL
Definition: winuser.h:798
#define BM_GETCHECK
Definition: winuser.h:1905
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
Definition: propsheet.c:2905
const char * LPCSTR
Definition: xmlstorage.h:183
BOOL ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
Definition: pidl.c:91
BOOL QuickFormat
Definition: format.c:66
#define CB_RESETCONTENT
Definition: winuser.h:1946
int options
Definition: main.c:106
#define DRIVE_UNKNOWN
Definition: winbase.h:253
#define CB_ERR
Definition: winuser.h:2415
_In_ int cchText
Definition: winuser.h:4445
#define BM_SETCHECK
Definition: winuser.h:1908
#define TRACE(s)
Definition: solgame.cpp:4
#define IDS_DRIVE_FIXED
Definition: shresdef.h:113
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define PSH_PROPTITLE
Definition: prsht.h:40
LONG HRESULT
Definition: typedefs.h:79
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:38
#define IDS_FORMAT_WARNING
Definition: shresdef.h:199
#define _countof(array)
Definition: sndvol32.h:68
#define MF_ENABLED
Definition: winuser.h:128
static BOOLEAN NTAPI FormatExCB(IN CALLBACKCOMMAND Command, IN ULONG SubAction, IN PVOID ActionInfo)
Definition: drive.cpp:433
DWORD ClusterSize
Definition: format.c:67
#define WINAPI
Definition: msvc.h:6
PVOID HANDLE
Definition: typedefs.h:73
unsigned long DWORD
Definition: ntddk_ex.h:95
#define __stdcall
Definition: typedefs.h:25
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
DWORD dwSize
Definition: prsht.h:293
DWORD dwFlags
Definition: prsht.h:294
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
static VOID InitializeFormatDriveDlg(HWND hwndDlg, PFORMAT_DRIVE_CONTEXT pContext)
Definition: drive.cpp:350
#define IDS_FORMAT_TITLE
Definition: shresdef.h:198
#define wcsicmp
Definition: compat.h:15
#define MB_ICONINFORMATION
Definition: winuser.h:796
unsigned char UCHAR
Definition: xmlstorage.h:181
int ret
char * PBOOLEAN
Definition: retypes.h:11
HWND WINAPI GetWindow(_In_ HWND, _In_ UINT)
#define IDD_FORMAT_DRIVE
Definition: shresdef.h:490
#define DWLP_USER
Definition: winuser.h:866
#define IDS_FORMAT_COMPLETE
Definition: shresdef.h:200
#define CB_SETCURSEL
Definition: winuser.h:1948
#define WM_COMMAND
Definition: winuser.h:1727
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
#define BST_UNCHECKED
Definition: winuser.h:199
#define DRIVE_NO_ROOT_DIR
Definition: winbase.h:254
#define DRIVE_FIXED
Definition: winbase.h:249
INT_PTR(CALLBACK * DLGPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2876
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
HPROPSHEETPAGE * phpage
Definition: prsht.h:309
#define ERR(fmt,...)
Definition: debug.h:110
DWORD WINAPI SHFormatDrive(HWND hwnd, UINT drive, UINT fmtID, UINT options)
Definition: drive.cpp:696
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
#define S_OK
Definition: intsafe.h:52
static char drive[2]
Definition: batch.c:28
#define shell32_hInstance
HRESULT SH_ShowDriveProperties(WCHAR *pwszDrive, LPCITEMIDLIST pidlFolder, PCUITEMID_CHILD_ARRAY apidl)
Definition: drive.cpp:170
static INT_PTR CALLBACK FormatDriveDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: drive.cpp:634
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1412
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
FxAutoRegKey hKey
PFORMAT_DRIVE_CONTEXT pContext
Definition: drive.cpp:596
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define ShellMessageBoxW
Definition: precomp.h:63
DLGPROC dlgproc
Definition: drive.cpp:165
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define MB_OK
Definition: winuser.h:784
HANDLE hThread
Definition: wizard.c:28
DWORD * PDWORD
Definition: pedump.c:68
#define IDS_NO_FORMAT
Definition: shresdef.h:204
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define IDS_DEFAULT_CLUSTER_SIZE
Definition: shresdef.h:225
#define BST_CHECKED
Definition: winuser.h:197
#define SC_CLOSE
Definition: winuser.h:2572
#define SHFMT_OPT_FULL
Definition: shlobj.h:298
struct tagContext Context
Definition: acpixf.h:1034
#define SendMessage
Definition: winuser.h:5823
struct FORMAT_DRIVE_CONTEXT * PFORMAT_DRIVE_CONTEXT
#define HIWORD(l)
Definition: typedefs.h:247
unsigned int ULONG
Definition: retypes.h:1
static unsigned __stdcall DoFormatDrive(void *args)
Definition: drive.cpp:599
EXTERN_C HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface, IDataObject *pDataObj)
#define DONE
Definition: rnr20lib.h:14
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define GetWindowLongPtr
Definition: treelist.c:73
HPROPSHEETPAGE SH_CreatePropertySheetPage(LPCSTR resname, DLGPROC dlgproc, LPARAM lParam, LPWSTR szTitle)
#define MF_GRAYED
Definition: winuser.h:129
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IDCANCEL
Definition: winuser.h:825
#define CB_DELETESTRING
Definition: winuser.h:1924
LONG_PTR LRESULT
Definition: windef.h:209
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022
#define EXTERN_C
Definition: basetyps.h:12
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:614
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
LPCSTR resname
Definition: drive.cpp:164
#define MAX_PROPERTY_SHEET_PAGE
static TfClientId tid
#define WM_INITDIALOG
Definition: winuser.h:1726
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
static BOOL GetDefaultClusterSize(LPWSTR szFs, PDWORD pClusterSize, PULARGE_INTEGER TotalNumberOfBytes)
Definition: drive.cpp:68
BOOL WINAPI GetDiskFreeSpaceExW(IN LPCWSTR lpDirectoryName OPTIONAL, OUT PULARGE_INTEGER lpFreeBytesAvailableToCaller, OUT PULARGE_INTEGER lpTotalNumberOfBytes, OUT PULARGE_INTEGER lpTotalNumberOfFreeBytes)
Definition: disk.c:342
WINE_DEFAULT_DEBUG_CHANNEL(shell)
FMIFS_MEDIA_FLAG
Definition: fmifs.h:37
BOOLEAN NTAPI QueryAvailableFileSystemFormat(IN DWORD Index, IN OUT PWCHAR FileSystem, OUT UCHAR *Major, OUT UCHAR *Minor, OUT BOOLEAN *LatestVersion)
Definition: query.c:14
UINT nStartPage
Definition: prsht.h:304