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.

425 lines
13 KiB

  1. #include "drvfull.h"
  2. #include <tchar.h>
  3. #include <stdio.h>
  4. #include <windows.h>
  5. //#include <winnetp.h>
  6. #include "dfioctl.h"
  7. #include "dfuser.h"
  8. #include "dfpnp.h"
  9. #include "dfcm.h"
  10. #include "dfstpdi.h"
  11. #include "dfhlprs.h"
  12. #define CCHINDENT 2
  13. #define CCHINDENT2 (CCHINDENT * 2)
  14. #define CCHINDENT3 (CCHINDENT * 3)
  15. #define CCHINDENT4 (CCHINDENT * 4)
  16. #define FIRST_ARG 1
  17. #define SECOND_ARG 2
  18. #define THIRD_ARG 3
  19. #define FOURTH_ARG 4
  20. #define ARRAYSIZE(a) (sizeof((a))/sizeof((a)[0]))
  21. struct _sFlag
  22. {
  23. LPTSTR pszFlag;
  24. DWORD dwFlag;
  25. DWORD dwArg;
  26. };
  27. static _sFlag _flagTable[] =
  28. {
  29. { TEXT("-hg"), IOCTL_GEOMETRY, FIRST_ARG},
  30. { TEXT("-hl"), IOCTL_LAYOUT, FIRST_ARG},
  31. { TEXT("-hp"), IOCTL_PARTITION, FIRST_ARG},
  32. { TEXT("-hpsure"), IOCTL_PARTITIONSURE, FIRST_ARG},
  33. { TEXT("-hpgpt"), IOCTL_PARTITIONGPT, FIRST_ARG},
  34. { TEXT("-vn"), IOCTL_VOLUMENUMBER, FIRST_ARG},
  35. { TEXT("-ma"), IOCTL_MEDIAACCESSIBLE, FIRST_ARG},
  36. { TEXT("-mw"), IOCTL_DISKISWRITABLE, FIRST_ARG},
  37. { TEXT("-mt"), IOCTL_MEDIATYPES, FIRST_ARG},
  38. { TEXT("-mt2"), IOCTL_MEDIATYPES2, FIRST_ARG},
  39. { TEXT("-mx"), IOCTL_MEDIATYPESEX, FIRST_ARG},
  40. { TEXT("-mdvd"), IOCTL_DVD, FIRST_ARG},
  41. { TEXT("-ej"), IOCTL_EJECT, FIRST_ARG},
  42. { TEXT("-dar"), IOCTL_MCNCONTROL, FIRST_ARG},
  43. { TEXT("-grp"), IOCTL_GETREPARSEPOINT, FIRST_ARG},
  44. { TEXT("-gcmmc2"), IOCTL_CDROMGETCONFIGMMC2, FIRST_ARG},
  45. { TEXT("-gcdvdram"), IOCTL_CDROMGETCONFIGDVDRAM, FIRST_ARG},
  46. { TEXT("-gcrw"), IOCTL_CDROMGETCONFIGRW, FIRST_ARG},
  47. { TEXT("-gcwo"), IOCTL_CDROMGETCONFIGWO, FIRST_ARG},
  48. { TEXT("-gcisw"), IOCTL_CDROMGETCONFIGISW, FIRST_ARG},
  49. { TEXT("-gcall"), IOCTL_CDROMGETCONFIGALL, FIRST_ARG},
  50. { TEXT("-pnpe"), PNP_CMENUM, SECOND_ARG},
  51. { TEXT("-pnps"), PNP_WATCHSETUPDI, SECOND_ARG},
  52. { TEXT("-pnpc"), PNP_WATCHCM, SECOND_ARG},
  53. { TEXT("-pnpd"), PNP_CMDEVICE, SECOND_ARG},
  54. { TEXT("-pnpi"), PNP_CMINTERFACE, SECOND_ARG},
  55. { TEXT("-pnph"), PNP_HANDLE, SECOND_ARG},
  56. { TEXT("-pnpeb"), PNP_EJECTBUTTON, SECOND_ARG},
  57. { TEXT("-pnpl"), PNP_CMDEVICEIDLIST, SECOND_ARG},
  58. { TEXT("-pnpcs"), PNP_CUSTOMPROPERTY, SECOND_ARG},
  59. { TEXT("-ugdt"), USER_GETDRIVETYPE, THIRD_ARG},
  60. { TEXT("-ugvi"), USER_GETVOLUMEINFORMATION, THIRD_ARG},
  61. { TEXT("-ugfa"), USER_GETFILEATTRIBUTES, THIRD_ARG},
  62. { TEXT("-uqdd"), USER_QUERYDOSDEVICE, THIRD_ARG},
  63. { TEXT("-uqddn"), USER_QUERYDOSDEVICENULL, THIRD_ARG},
  64. { TEXT("-ugld"), USER_GETLOGICALDRIVES, THIRD_ARG},
  65. { TEXT("-uwneterc"), USER_WNETENUMRESOURCECONNECTED, THIRD_ARG},
  66. { TEXT("-uwneterr"), USER_WNETENUMRESOURCEREMEMBERED, THIRD_ARG},
  67. { TEXT("-ntma"), NT_MEDIAPRESENT, THIRD_ARG},
  68. { TEXT("-Z"), MOD_FULLREPORTFULL, FOURTH_ARG},
  69. { TEXT("-Z1"), MOD_FULLREPORT1, FOURTH_ARG},
  70. { TEXT("-Z2"), MOD_FULLREPORT2, FOURTH_ARG},
  71. { TEXT("-Z3"), MOD_FULLREPORT3, FOURTH_ARG},
  72. };
  73. void _SetFlag(_sFlag* psflag, DWORD dwFlags[])
  74. {
  75. dwFlags[psflag->dwArg - 1] |= psflag->dwFlag;
  76. }
  77. BOOL _IsFlagSet(DWORD dwFlag, DWORD dwFlags[])
  78. {
  79. BOOL fRet = FALSE;
  80. for (DWORD dw = 0; dw < ARRAYSIZE(_flagTable); ++dw)
  81. {
  82. if (dwFlag == _flagTable[dw].dwFlag)
  83. {
  84. if ((dwFlags[_flagTable[dw].dwArg - 1] & OPER_MASK) & dwFlag)
  85. {
  86. fRet = TRUE;
  87. }
  88. break;
  89. }
  90. }
  91. return fRet;
  92. }
  93. BOOL _IsCategorySet(DWORD dwFlag, DWORD dwFlags[])
  94. {
  95. BOOL fRet = FALSE;
  96. for (DWORD dw = 0; dw < ARRAYSIZE(_flagTable); ++dw)
  97. {
  98. if (dwFlag == (_flagTable[dw].dwFlag & CAT_MASK))
  99. {
  100. if ((dwFlags[_flagTable[dw].dwArg - 1] & CAT_MASK) & dwFlag)
  101. {
  102. fRet = TRUE;
  103. }
  104. break;
  105. }
  106. }
  107. return fRet;
  108. }
  109. HRESULT _ExtractFlags(int argc, wchar_t* argv[], DWORD dwFlags[])
  110. {
  111. HRESULT hres = E_FAIL;
  112. // for now
  113. for (int i = 0; i < argc; ++i)
  114. {
  115. for (DWORD dw = 0; dw < ARRAYSIZE(_flagTable); ++dw)
  116. {
  117. if (!lstrcmp(_flagTable[dw].pszFlag, argv[i]))
  118. {
  119. _SetFlag(&(_flagTable[dw]), dwFlags);
  120. hres = S_OK;
  121. break;
  122. }
  123. }
  124. }
  125. return hres;
  126. }
  127. HRESULT _Dispatch(DWORD dwFlags[], LPTSTR pszArg)
  128. {
  129. HRESULT hres = S_OK;
  130. if (_IsCategorySet(IOCTL_FLAGS, dwFlags))
  131. {
  132. hres = _ProcessIOCTL(dwFlags, pszArg, CCHINDENT);
  133. }
  134. else
  135. {
  136. if (_IsCategorySet(PNP_FLAGS, dwFlags))
  137. {
  138. // for now
  139. if (_IsFlagSet(PNP_WATCHCM, dwFlags))
  140. {
  141. hres = _FullTree(dwFlags, 4);
  142. }
  143. else
  144. {
  145. // for now
  146. /* if (_IsFlagSet(PNP_HAL, dwFlags))
  147. {
  148. hres = _HALGetPCIBusData(dwFlags, 4);
  149. }
  150. else
  151. {*/
  152. // for now
  153. if (_IsFlagSet(PNP_CMDEVICE, dwFlags))
  154. {
  155. hres = _DeviceInfo(dwFlags, pszArg, 4);
  156. }
  157. else
  158. {
  159. if (_IsFlagSet(PNP_CMINTERFACE, dwFlags))
  160. {
  161. hres = _DeviceInterface(dwFlags, pszArg, 4);
  162. }
  163. else
  164. {
  165. if (_IsFlagSet(PNP_CMENUM, dwFlags))
  166. {
  167. hres = _EnumDevice(dwFlags, pszArg, 4);
  168. }
  169. else
  170. {
  171. if (_IsFlagSet(PNP_CMDEVICEIDLIST, dwFlags))
  172. {
  173. hres = _DeviceIDList(dwFlags, pszArg, 4);
  174. }
  175. else
  176. {
  177. if (_IsFlagSet(PNP_CUSTOMPROPERTY, dwFlags))
  178. {
  179. hres = _CustomProperty(dwFlags, pszArg, 4);
  180. }
  181. else
  182. {
  183. hres = _ProcessPNP(dwFlags, pszArg, CCHINDENT);
  184. }
  185. }
  186. }
  187. }
  188. }
  189. // }
  190. }
  191. }
  192. else
  193. {
  194. if (_IsCategorySet(USER_FLAGS, dwFlags))
  195. {
  196. hres = _ProcessUser(dwFlags, pszArg, CCHINDENT);
  197. }
  198. else
  199. {
  200. hres = E_INVALIDARG;
  201. }
  202. }
  203. }
  204. return hres;
  205. }
  206. HRESULT _Help()
  207. {
  208. HRESULT hres = S_OK;
  209. wprintf(TEXT("Some title\n\n"));
  210. _PrintIndent(CCHINDENT);
  211. wprintf(TEXT("Flags:\n"));
  212. _PrintIndent(CCHINDENT2);
  213. wprintf(TEXT("-h* (Hard drive)\n"));
  214. _PrintIndent(CCHINDENT4);
  215. wprintf(TEXT("-hg drive Geometry (1)\n"));
  216. _PrintIndent(CCHINDENT4);
  217. wprintf(TEXT("-hl drive Layout (1)\n"));
  218. _PrintIndent(CCHINDENT4);
  219. wprintf(TEXT("-hp partition drive (one partition) (1)\n"));
  220. _PrintIndent(CCHINDENT4);
  221. wprintf(TEXT("-hpgpt is partition GPT? (guid partition table) (2)\n"));
  222. _PrintIndent(CCHINDENT2);
  223. wprintf(TEXT("-m* (Media)\n"));
  224. _PrintIndent(CCHINDENT4);
  225. wprintf(TEXT("-ma is Media Accessible? (2)\n"));
  226. _PrintIndent(CCHINDENT4);
  227. wprintf(TEXT("-mt Media Type (using IOCTL_STORAGE_GET_MEDIA_TYPES) (2)(3)\n"));
  228. _PrintIndent(CCHINDENT4);
  229. wprintf(TEXT("-mt2 Media Type (using IOCTL_DISK_GET_MEDIA_TYPES) (2)(3)\n"));
  230. _PrintIndent(CCHINDENT4);
  231. wprintf(TEXT("-mw is Media Write-Protected? (2)\n"));
  232. _PrintIndent(CCHINDENT4);
  233. wprintf(TEXT("-mx Media Type Ex (2)(4)\n"));
  234. _PrintIndent(CCHINDENT4);
  235. wprintf(TEXT("-mdvd DVD drive? (2)(4)\n"));
  236. _PrintIndent(CCHINDENT4);
  237. wprintf(TEXT("-grp Get Reparse Point Guid (6)\n"));
  238. _PrintIndent(CCHINDENT4);
  239. wprintf(TEXT("-gc* (CDROM Get Configuration)\n"));
  240. _PrintIndent(CCHINDENT4);
  241. wprintf(TEXT("-gcmmc2 is MMC2 compliant? (5)\n"));
  242. _PrintIndent(CCHINDENT4);
  243. wprintf(TEXT("-gcall all MMC2 features implemented. (5)\n"));
  244. /* _PrintIndent(CCHINDENT4);
  245. wprintf(TEXT("-gcdvdram is DVD-RAM drive? (5)\n"));
  246. _PrintIndent(CCHINDENT4);
  247. wprintf(TEXT("-gcrw is random writable? (5)\n"));
  248. _PrintIndent(CCHINDENT4);
  249. wprintf(TEXT("-gcwo is write once (5)\n"));
  250. _PrintIndent(CCHINDENT4);
  251. wprintf(TEXT("-gcisw is incremental streaming writable (5)\n"));*/
  252. _PrintIndent(CCHINDENT2);
  253. wprintf(TEXT("-v* (Volume)\n"));
  254. _PrintIndent(CCHINDENT4);
  255. wprintf(TEXT("-vn Volume Number? (2)\n"));
  256. /* _PrintIndent(CCHINDENT2);
  257. wprintf(TEXT("-e* (Eject)\n"));
  258. _PrintIndent(CCHINDENT4);
  259. wprintf(TEXT("-ej EJect media (2)\n"));
  260. _PrintIndent(CCHINDENT4);
  261. wprintf(TEXT("-el Load Media (2)\n"));
  262. _PrintIndent(CCHINDENT4);
  263. wprintf(TEXT("-ed Disable hardware button (2)\n"));
  264. _PrintIndent(CCHINDENT4);
  265. wprintf(TEXT("-ee Enable hardware button (2)\n"));*/
  266. _PrintIndent(CCHINDENT2);
  267. wprintf(TEXT("-pnp* Plug 'n' Play\n"));
  268. _PrintIndent(CCHINDENT4);
  269. wprintf(TEXT("-pnps Handle using SetupDI* API\n"));
  270. _PrintIndent(CCHINDENT4);
  271. wprintf(TEXT("-pnpc Handle using CM_* API\n"));
  272. _PrintIndent(CCHINDENT4);
  273. wprintf(TEXT("-pnpd Dump device info using CM_* API\n"));
  274. _PrintIndent(CCHINDENT4);
  275. wprintf(TEXT("-pnpi Dump device interface info using CM_* API\n"));
  276. _PrintIndent(CCHINDENT4);
  277. wprintf(TEXT("-pnph Watch HANDLE event on Volume (5)\n"));
  278. _PrintIndent(CCHINDENT4);
  279. wprintf(TEXT("-pnpeb Monitor Eject button (5)\n"));
  280. _PrintIndent(CCHINDENT4);
  281. wprintf(TEXT("-pnpe Enum device implementing the interface (7)\n"));
  282. _PrintIndent(CCHINDENT4);
  283. wprintf(TEXT("-pnpl Enum device ID list\n"));
  284. _PrintIndent(CCHINDENT4);
  285. wprintf(TEXT("-pnpcs PnP device CustomProperties\n"));
  286. _PrintIndent(CCHINDENT2);
  287. wprintf(TEXT("-u* User functions\n"));
  288. _PrintIndent(CCHINDENT4);
  289. wprintf(TEXT("-ugdt GetDriveType ()\n"));
  290. _PrintIndent(CCHINDENT4);
  291. wprintf(TEXT("-ugvi GetVolumeInformation (2)(5)\n"));
  292. _PrintIndent(CCHINDENT4);
  293. wprintf(TEXT("-ugfa GetFileAttributes\n"));
  294. _PrintIndent(CCHINDENT4);
  295. wprintf(TEXT("-uqdd QueryDosDevice ()\n"));
  296. _PrintIndent(CCHINDENT4);
  297. wprintf(TEXT("-uqddn QueryDosDevice with NULL for first param\n"));
  298. _PrintIndent(CCHINDENT4);
  299. wprintf(TEXT("-ugld GetLogicalDrives\n"));
  300. _PrintIndent(CCHINDENT4);
  301. wprintf(TEXT("-uwneterc WNetEnumResource Connected\n"));
  302. _PrintIndent(CCHINDENT4);
  303. wprintf(TEXT("-uwneterr WNetEnumResource Remembered\n"));
  304. _PrintIndent(CCHINDENT4);
  305. wprintf(TEXT("-ntma NtQueryVolumeInformationFile (TBD)\n"));
  306. /* _PrintCR();
  307. _PrintIndent(CCHINDENT2);
  308. wprintf(TEXT("-? This message.\n"));*/
  309. _PrintCR();
  310. _PrintIndent(CCHINDENT);
  311. wprintf(TEXT("Modifiers:\n"));
  312. /* _PrintIndent(CCHINDENT2);
  313. wprintf(TEXT("-F Force\n"));
  314. _PrintIndent(CCHINDENT2);
  315. wprintf(TEXT("-R Raw function call\n"));
  316. _PrintIndent(CCHINDENT2);
  317. wprintf(TEXT("-T Elapsed time\n"));*/
  318. _PrintIndent(CCHINDENT2);
  319. wprintf(TEXT("-Z Full report - as much as possible\n"));
  320. _PrintIndent(CCHINDENT2);
  321. wprintf(TEXT("-Z1 Full report - level 1\n"));
  322. _PrintIndent(CCHINDENT2);
  323. wprintf(TEXT("-Z2 Full report - level 2\n"));
  324. _PrintIndent(CCHINDENT2);
  325. wprintf(TEXT("-Z3 Full report - level 3\n"));
  326. _PrintCR();
  327. _PrintIndent(CCHINDENT);
  328. wprintf(TEXT("Notes:\n"));
  329. _PrintIndent(CCHINDENT2);
  330. wprintf(TEXT("(1) Requires '\\\\.\\PhysicalDriveX' arg, where X is 0-n\n"));
  331. _PrintIndent(CCHINDENT2);
  332. wprintf(TEXT("(2) Requires '\\\\.\\c:' arg or '\\\\?\\Volume{GUID}' (both without trailing '\\')\n"));
  333. _PrintIndent(CCHINDENT2);
  334. wprintf(TEXT("(3) Floppy only\n"));
  335. _PrintIndent(CCHINDENT2);
  336. wprintf(TEXT("(4) Non-Floppy only\n"));
  337. _PrintIndent(CCHINDENT2);
  338. wprintf(TEXT("(5) Requires '\\\\?\\Volume{GUID}' (without trailing '\\')\n"));
  339. _PrintIndent(CCHINDENT2);
  340. wprintf(TEXT("(6) Requires a junction point pathname\n"));
  341. _PrintIndent(CCHINDENT2);
  342. wprintf(TEXT("(7) An interface GUID, e.g. '{4D36E967-E325-11CE-BFC1-08002BE10318}'\n"));
  343. _PrintIndent(CCHINDENT2);
  344. wprintf(TEXT("(8) A DOS device name, e.g. 'c:'\n"));
  345. return hres;
  346. }
  347. int g_argc = 0;
  348. wchar_t** g_argv = NULL;
  349. #ifdef UNICODE
  350. extern "C"
  351. {
  352. int __cdecl wmain(int argc, wchar_t* argv[])
  353. #else
  354. int __cdecl main(int argc, char* argv[])
  355. #endif
  356. {
  357. HRESULT hres = S_OK;
  358. if (argc > 1)
  359. {
  360. DWORD dwFlags[MAX_FLAGS] = {0};
  361. g_argv = argv;
  362. g_argc = argc;
  363. hres = _ExtractFlags(argc, argv, dwFlags);
  364. if (SUCCEEDED(hres))
  365. {
  366. hres = _Dispatch(dwFlags, argv[argc - 1]);
  367. }
  368. }
  369. else
  370. {
  371. hres = _Help();
  372. }
  373. return hres;
  374. }
  375. #ifdef UNICODE
  376. }
  377. #endif