Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

453 lines
12 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <ntioapi.h>
  5. #include "dfuser.h"
  6. #include <stdio.h>
  7. #include "dferr.h"
  8. #include "dfhlprs.h"
  9. #include "drvfull.h"
  10. #define ARRAYSIZE(a) (sizeof((a))/sizeof((a)[0]))
  11. _sFLAG_DESCR drivetypeFD[] =
  12. {
  13. FLAG_DESCR(DRIVE_UNKNOWN),
  14. FLAG_DESCR(DRIVE_NO_ROOT_DIR),
  15. FLAG_DESCR(DRIVE_REMOVABLE),
  16. FLAG_DESCR(DRIVE_FIXED),
  17. FLAG_DESCR(DRIVE_REMOTE),
  18. FLAG_DESCR(DRIVE_CDROM),
  19. FLAG_DESCR(DRIVE_RAMDISK),
  20. };
  21. HRESULT _GetDriveType(DWORD dwFlags[], LPTSTR pszArg, DWORD cchIndent)
  22. {
  23. HRESULT hres = S_OK;
  24. int i = 0;
  25. _StartClock();
  26. DWORD dw = GetDriveType(pszArg);
  27. _StopClock();
  28. _PrintIndent(cchIndent);
  29. i += wprintf(TEXT("Oper: GetDriveType\n"));
  30. _PrintElapsedTime(cchIndent, TRUE);
  31. _PrintIndent(cchIndent);
  32. i += wprintf(TEXT("Return Value: "));
  33. i += _PrintFlag(dw, drivetypeFD, ARRAYSIZE(drivetypeFD), 0, TRUE, TRUE,
  34. FALSE, FALSE);
  35. i += _PrintCR();
  36. return hres;
  37. }
  38. _sFLAG_DESCR _fdFileSys[] =
  39. {
  40. FLAG_DESCR(FS_CASE_IS_PRESERVED),
  41. FLAG_DESCR(FS_CASE_SENSITIVE),
  42. FLAG_DESCR(FS_UNICODE_STORED_ON_DISK),
  43. FLAG_DESCR(FS_PERSISTENT_ACLS),
  44. FLAG_DESCR(FS_FILE_COMPRESSION),
  45. FLAG_DESCR(FS_VOL_IS_COMPRESSED),
  46. FLAG_DESCR(FILE_NAMED_STREAMS),
  47. FLAG_DESCR(FILE_SUPPORTS_ENCRYPTION),
  48. FLAG_DESCR(FILE_SUPPORTS_OBJECT_IDS),
  49. FLAG_DESCR(FILE_SUPPORTS_REPARSE_POINTS),
  50. FLAG_DESCR(FILE_SUPPORTS_SPARSE_FILES),
  51. FLAG_DESCR(FILE_VOLUME_QUOTAS ),
  52. };
  53. HRESULT _GetVolumeInformation(DWORD dwFlags[], LPTSTR pszArg, DWORD cchIndent)
  54. {
  55. HRESULT hres = S_OK;
  56. int i = 0;
  57. WCHAR szLabel[250];
  58. WCHAR szFileSys[250];
  59. DWORD dwSerNum;
  60. DWORD dwMaxCompName;
  61. DWORD dwFileSysFlags;
  62. _StartClock();
  63. BOOL f = GetVolumeInformation(pszArg, szLabel, ARRAYSIZE(szLabel),
  64. &dwSerNum, &dwMaxCompName, &dwFileSysFlags, szFileSys,
  65. ARRAYSIZE(szFileSys));
  66. DWORD dw = GetDriveType(pszArg);
  67. _StopClock();
  68. _PrintIndent(cchIndent);
  69. i += wprintf(TEXT("Oper: GetVolumeInformation\n"));
  70. _PrintElapsedTime(cchIndent, TRUE);
  71. _PrintIndent(cchIndent);
  72. i += wprintf(TEXT("Return Value: %s\n"), f ? TEXT("TRUE") : TEXT("FALSE"));
  73. if (f)
  74. {
  75. _PrintIndent(cchIndent + 2);
  76. i += wprintf(TEXT("%s (LPTSTR lpVolumeNameBuffer)\n"), szLabel);
  77. _PrintIndent(cchIndent + 2);
  78. i += wprintf(TEXT("0x%08X (LPDWORD lpVolumeSerialNumber)\n"), dwSerNum);
  79. _PrintIndent(cchIndent + 2);
  80. i += wprintf(TEXT("%d (LPDWORD lpMaximumComponentLength)\n"), dwMaxCompName);
  81. _PrintIndent(cchIndent + 2);
  82. i += wprintf(TEXT("0x%08X (LPDWORD lpFileSystemFlags)\n"), dwFileSysFlags);
  83. i += _PrintFlag(dwFileSysFlags, _fdFileSys, ARRAYSIZE(_fdFileSys), cchIndent + 4,
  84. TRUE, TRUE, FALSE, TRUE);
  85. _PrintCR();
  86. _PrintIndent(cchIndent + 2);
  87. i += wprintf(TEXT("%s (LPTSTR lpFileSystemNameBuffer)\n"), szFileSys);
  88. }
  89. i += _PrintCR();
  90. return hres;
  91. }
  92. _sFLAG_DESCR _fdFileAttrib[] =
  93. {
  94. FLAG_DESCR(FILE_ATTRIBUTE_READONLY ),
  95. FLAG_DESCR(FILE_ATTRIBUTE_HIDDEN ),
  96. FLAG_DESCR(FILE_ATTRIBUTE_SYSTEM ),
  97. FLAG_DESCR(FILE_ATTRIBUTE_DIRECTORY ),
  98. FLAG_DESCR(FILE_ATTRIBUTE_ARCHIVE ),
  99. FLAG_DESCR(FILE_ATTRIBUTE_DEVICE ),
  100. FLAG_DESCR(FILE_ATTRIBUTE_NORMAL ),
  101. FLAG_DESCR(FILE_ATTRIBUTE_TEMPORARY ),
  102. FLAG_DESCR(FILE_ATTRIBUTE_SPARSE_FILE ),
  103. FLAG_DESCR(FILE_ATTRIBUTE_REPARSE_POINT ),
  104. FLAG_DESCR(FILE_ATTRIBUTE_COMPRESSED ),
  105. FLAG_DESCR(FILE_ATTRIBUTE_OFFLINE ),
  106. FLAG_DESCR(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED ),
  107. FLAG_DESCR(FILE_ATTRIBUTE_ENCRYPTED ),
  108. };
  109. _sFLAG_DESCR _fdDEVINFODEVTYPE[] =
  110. {
  111. FLAG_DESCR(FILE_DEVICE_BEEP ),
  112. FLAG_DESCR(FILE_DEVICE_CD_ROM ),
  113. FLAG_DESCR(FILE_DEVICE_CD_ROM_FILE_SYSTEM ),
  114. FLAG_DESCR(FILE_DEVICE_CONTROLLER ),
  115. FLAG_DESCR(FILE_DEVICE_DATALINK ),
  116. FLAG_DESCR(FILE_DEVICE_DFS ),
  117. FLAG_DESCR(FILE_DEVICE_DISK ),
  118. FLAG_DESCR(FILE_DEVICE_DISK_FILE_SYSTEM ),
  119. FLAG_DESCR(FILE_DEVICE_FILE_SYSTEM ),
  120. FLAG_DESCR(FILE_DEVICE_INPORT_PORT ),
  121. FLAG_DESCR(FILE_DEVICE_KEYBOARD ),
  122. FLAG_DESCR(FILE_DEVICE_MAILSLOT ),
  123. FLAG_DESCR(FILE_DEVICE_MIDI_IN ),
  124. FLAG_DESCR(FILE_DEVICE_MIDI_OUT ),
  125. FLAG_DESCR(FILE_DEVICE_MOUSE ),
  126. FLAG_DESCR(FILE_DEVICE_MULTI_UNC_PROVIDER ),
  127. FLAG_DESCR(FILE_DEVICE_NAMED_PIPE ),
  128. FLAG_DESCR(FILE_DEVICE_NETWORK ),
  129. FLAG_DESCR(FILE_DEVICE_NETWORK_BROWSER ),
  130. FLAG_DESCR(FILE_DEVICE_NETWORK_FILE_SYSTEM),
  131. FLAG_DESCR(FILE_DEVICE_NULL ),
  132. FLAG_DESCR(FILE_DEVICE_PARALLEL_PORT ),
  133. FLAG_DESCR(FILE_DEVICE_PHYSICAL_NETCARD ),
  134. FLAG_DESCR(FILE_DEVICE_PRINTER ),
  135. FLAG_DESCR(FILE_DEVICE_SCANNER ),
  136. FLAG_DESCR(FILE_DEVICE_SERIAL_MOUSE_PORT ),
  137. FLAG_DESCR(FILE_DEVICE_SERIAL_PORT ),
  138. FLAG_DESCR(FILE_DEVICE_SCREEN ),
  139. FLAG_DESCR(FILE_DEVICE_SOUND ),
  140. FLAG_DESCR(FILE_DEVICE_STREAMS ),
  141. FLAG_DESCR(FILE_DEVICE_TAPE ),
  142. FLAG_DESCR(FILE_DEVICE_TAPE_FILE_SYSTEM ),
  143. FLAG_DESCR(FILE_DEVICE_TRANSPORT ),
  144. FLAG_DESCR(FILE_DEVICE_UNKNOWN ),
  145. FLAG_DESCR(FILE_DEVICE_VIDEO ),
  146. FLAG_DESCR(FILE_DEVICE_VIRTUAL_DISK ),
  147. FLAG_DESCR(FILE_DEVICE_WAVE_IN ),
  148. FLAG_DESCR(FILE_DEVICE_WAVE_OUT ),
  149. FLAG_DESCR(FILE_DEVICE_8042_PORT ),
  150. FLAG_DESCR(FILE_DEVICE_NETWORK_REDIRECTOR ),
  151. FLAG_DESCR(FILE_DEVICE_BATTERY ),
  152. FLAG_DESCR(FILE_DEVICE_BUS_EXTENDER ),
  153. FLAG_DESCR(FILE_DEVICE_MODEM ),
  154. FLAG_DESCR(FILE_DEVICE_VDM ),
  155. FLAG_DESCR(FILE_DEVICE_MASS_STORAGE ),
  156. FLAG_DESCR(FILE_DEVICE_SMB ),
  157. FLAG_DESCR(FILE_DEVICE_KS ),
  158. FLAG_DESCR(FILE_DEVICE_CHANGER ),
  159. FLAG_DESCR(FILE_DEVICE_SMARTCARD ),
  160. FLAG_DESCR(FILE_DEVICE_ACPI ),
  161. FLAG_DESCR(FILE_DEVICE_DVD ),
  162. FLAG_DESCR(FILE_DEVICE_FULLSCREEN_VIDEO ),
  163. FLAG_DESCR(FILE_DEVICE_DFS_FILE_SYSTEM ),
  164. FLAG_DESCR(FILE_DEVICE_DFS_VOLUME ),
  165. FLAG_DESCR(FILE_DEVICE_SERENUM ),
  166. FLAG_DESCR(FILE_DEVICE_TERMSRV ),
  167. FLAG_DESCR(FILE_DEVICE_KSEC ),
  168. FLAG_DESCR(FILE_DEVICE_FIPS ),
  169. };
  170. _sFLAG_DESCR _fdDEVINFODEVCHARACT[] =
  171. {
  172. FLAG_DESCR(FILE_REMOVABLE_MEDIA ),
  173. FLAG_DESCR(FILE_READ_ONLY_DEVICE ),
  174. FLAG_DESCR(FILE_FLOPPY_DISKETTE ),
  175. FLAG_DESCR(FILE_WRITE_ONCE_MEDIA ),
  176. FLAG_DESCR(FILE_REMOTE_DEVICE ),
  177. FLAG_DESCR(FILE_DEVICE_IS_MOUNTED ),
  178. FLAG_DESCR(FILE_VIRTUAL_VOLUME ),
  179. FLAG_DESCR(FILE_AUTOGENERATED_DEVICE_NAME),
  180. FLAG_DESCR(FILE_DEVICE_SECURE_OPEN ),
  181. };
  182. HRESULT _NtMediaPresent(DWORD dwFlags[], LPTSTR pszArg, DWORD cchIndent)
  183. {
  184. HRESULT hr = S_OK;
  185. int i = 0;
  186. _StartClock();
  187. HANDLE h = _GetDeviceHandle(pszArg, FILE_READ_ATTRIBUTES, 0);
  188. _StopClock();
  189. _PrintElapsedTime(cchIndent, TRUE);
  190. if (INVALID_HANDLE_VALUE != h)
  191. {
  192. _PrintIndent(cchIndent);
  193. i += wprintf(TEXT("Was able to CreateFile\n"));
  194. NTSTATUS status;
  195. WCHAR buffer[sizeof(FILE_FS_VOLUME_INFORMATION) + MAX_PATH];
  196. FILE_FS_DEVICE_INFORMATION DeviceInfo;
  197. IO_STATUS_BLOCK ioStatus;
  198. status = NtQueryVolumeInformationFile(h, &ioStatus,
  199. buffer, sizeof(buffer), FileFsVolumeInformation);
  200. status = NtQueryVolumeInformationFile(h, &ioStatus,
  201. &DeviceInfo,
  202. sizeof(DeviceInfo),
  203. FileFsDeviceInformation);
  204. if (0 == status)
  205. {
  206. _PrintIndent(cchIndent);
  207. i += wprintf(TEXT("DeviceType\n"));
  208. i += _PrintFlag(DeviceInfo.DeviceType, _fdDEVINFODEVTYPE,
  209. ARRAYSIZE(_fdDEVINFODEVTYPE), cchIndent + 4,
  210. TRUE, TRUE, FALSE, FALSE);
  211. i += _PrintCR();
  212. _PrintIndent(cchIndent);
  213. i += wprintf(TEXT("Characteristics\n"));
  214. i += _PrintFlag(DeviceInfo.Characteristics, _fdDEVINFODEVCHARACT,
  215. ARRAYSIZE(_fdDEVINFODEVCHARACT), cchIndent + 4,
  216. TRUE, TRUE, FALSE, TRUE);
  217. }
  218. CloseHandle(h);
  219. }
  220. else
  221. {
  222. _PrintIndent(cchIndent);
  223. i += wprintf(TEXT("Was *NOT* able to CreateFile\n"));
  224. _PrintGetLastError(cchIndent);
  225. }
  226. return hr;
  227. }
  228. HRESULT _GetFileAttributes(DWORD dwFlags[], LPTSTR pszArg, DWORD cchIndent)
  229. {
  230. HRESULT hres = S_OK;
  231. int i = 0;
  232. _StartClock();
  233. DWORD dw = GetFileAttributes(pszArg);
  234. _StopClock();
  235. _PrintIndent(cchIndent);
  236. i += wprintf(TEXT("Oper: GetFileAttributes\n"));
  237. _PrintElapsedTime(cchIndent, TRUE);
  238. _PrintIndent(cchIndent);
  239. i += wprintf(TEXT("Return Value: 0x%08X\n"), dw);
  240. if (-1 != dw)
  241. {
  242. i += _PrintFlag(dw, _fdFileAttrib, ARRAYSIZE(_fdFileAttrib), cchIndent + 4,
  243. TRUE, TRUE, FALSE, TRUE);
  244. }
  245. i += _PrintCR();
  246. return hres;
  247. }
  248. HRESULT _QueryDosDeviceNULL(DWORD dwFlags[], LPTSTR pszArg, DWORD cchIndent)
  249. {
  250. HRESULT hres = S_OK;
  251. TCHAR sz[8192];
  252. int i = 0;
  253. _PrintIndent(cchIndent);
  254. i += wprintf(TEXT("Oper: QueryDosDevice with NULL\n"));
  255. _StartClock();
  256. DWORD dw = QueryDosDevice(NULL, sz, ARRAYSIZE(sz));
  257. _StopClock();
  258. _PrintIndent(cchIndent);
  259. i += wprintf(TEXT("Return Value: 0x%08X\n"), dw);
  260. i += _PrintCR();
  261. if (dw)
  262. {
  263. LPTSTR psz = sz;
  264. while (*psz)
  265. {
  266. i += wprintf(TEXT("%s\n"), psz);
  267. psz += lstrlen(psz) + 1;
  268. }
  269. }
  270. _PrintElapsedTime(cchIndent, TRUE);
  271. i += _PrintCR();
  272. return hres;
  273. }
  274. HRESULT _QueryDosDevice(DWORD dwFlags[], LPTSTR pszArg, DWORD cchIndent)
  275. {
  276. HRESULT hres = S_OK;
  277. TCHAR sz[4096];
  278. int i = 0;
  279. _PrintIndent(cchIndent);
  280. i += wprintf(TEXT("Oper: QueryDosDevice\n"));
  281. _StartClock();
  282. DWORD dw = QueryDosDevice(pszArg, sz, ARRAYSIZE(sz));
  283. _StopClock();
  284. _PrintIndent(cchIndent);
  285. i += wprintf(TEXT("Return Value: 0x%08X\n"), dw);
  286. i += _PrintCR();
  287. if (dw)
  288. {
  289. i += wprintf(TEXT("Target path: %s\n"), sz);
  290. }
  291. _PrintElapsedTime(cchIndent, TRUE);
  292. i += _PrintCR();
  293. return hres;
  294. }
  295. HRESULT _GetLogicalDrives(DWORD dwFlags[], LPTSTR pszArg, DWORD cchIndent)
  296. {
  297. HRESULT hres = S_OK;
  298. TCHAR sz[4096];
  299. int i = 0;
  300. _PrintIndent(cchIndent);
  301. i += wprintf(TEXT("Oper: GetLogicalDrives\n"));
  302. _StartClock();
  303. DWORD dwLGD = GetLogicalDrives();
  304. _StopClock();
  305. _PrintIndent(cchIndent);
  306. i += wprintf(TEXT("Return Value: 0x%08X\n"), dwLGD);
  307. i += _PrintCR();
  308. if (dwLGD)
  309. {
  310. for (DWORD j = 0; j < 32; ++j)
  311. {
  312. DWORD dw = 1 << j;
  313. if (dw & dwLGD)
  314. {
  315. i += wprintf(TEXT(" %c:\n"), TEXT('A') + (TCHAR)j);
  316. }
  317. }
  318. }
  319. _PrintElapsedTime(cchIndent, TRUE);
  320. i += _PrintCR();
  321. return hres;
  322. }
  323. typedef HRESULT (*_USERHANDLER)(DWORD dwFlags[], LPTSTR pszArg, DWORD cchIndent);
  324. struct _UserHandler
  325. {
  326. DWORD dwFlag;
  327. _USERHANDLER userhandler;
  328. };
  329. // from dfwnet.cpp
  330. HRESULT _EnumConnections(DWORD dwFlags[], LPTSTR pszArg, DWORD cchIndent);
  331. _UserHandler _userhandlers[] =
  332. {
  333. { USER_GETDRIVETYPE, _GetDriveType },
  334. { USER_GETVOLUMEINFORMATION, _GetVolumeInformation },
  335. { USER_GETFILEATTRIBUTES, _GetFileAttributes },
  336. { USER_QUERYDOSDEVICE, _QueryDosDevice },
  337. { USER_QUERYDOSDEVICENULL, _QueryDosDeviceNULL },
  338. { USER_GETLOGICALDRIVES, _GetLogicalDrives },
  339. { USER_WNETENUMRESOURCECONNECTED, _EnumConnections },
  340. { USER_WNETENUMRESOURCEREMEMBERED, _EnumConnections },
  341. { NT_MEDIAPRESENT, _NtMediaPresent },
  342. };
  343. HRESULT _ProcessUser(DWORD dwFlags[], LPTSTR pszArg, DWORD cchIndent)
  344. {
  345. HRESULT hres = E_INVALIDARG;
  346. for (DWORD dw = 0; dw < ARRAYSIZE(_userhandlers); ++dw)
  347. {
  348. if (_IsFlagSet(_userhandlers[dw].dwFlag, dwFlags))
  349. {
  350. hres = (*(_userhandlers[dw].userhandler))(dwFlags, pszArg,
  351. cchIndent);
  352. }
  353. }
  354. return hres;
  355. }