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.

294 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. This file implements the main entry point
  7. for this project and also processes all
  8. command dispatching.
  9. Author:
  10. Wesley Witt [wesw] 1-March-2000
  11. Revision History:
  12. --*/
  13. #include <precomp.h>
  14. BOOL RunningOnWin2K;
  15. typedef INT (*PFSCOMMANDFUNC)(INT,PWSTR*);
  16. typedef struct _COMMAND_VECTOR {
  17. PWSTR CommandName;
  18. union {
  19. PVOID _make_it_compile;
  20. PFSCOMMANDFUNC CommandFunc;
  21. struct _COMMAND_VECTOR *CommandVector;
  22. DWORD_PTR HelpMessage;
  23. };
  24. } COMMAND_VECTOR, *PCOMMAND_VECTOR;
  25. COMMAND_VECTOR CmdVectorUsn[] =
  26. {
  27. { L"?", UsnHelp },
  28. { L"help", UsnHelp },
  29. { L"createjournal", CreateUsnJournal },
  30. { L"deletejournal", DeleteUsnJournal },
  31. { L"enumdata", EnumUsnData },
  32. { L"queryjournal", QueryUsnJournal },
  33. { L"readdata", ReadFileUsnData },
  34. { NULL, NULL }
  35. };
  36. COMMAND_VECTOR CmdVectorQuota[] =
  37. {
  38. { L"?", QuotaHelp },
  39. { L"help", QuotaHelp },
  40. { L"disable", DisableQuota },
  41. { L"track", TrackQuota },
  42. { L"enforce", EnforceQuota },
  43. { L"violations", GetDiskQuotaViolation },
  44. { L"modify", ChangeDiskQuota },
  45. { L"query", QueryDiskQuota },
  46. { NULL, NULL }
  47. };
  48. COMMAND_VECTOR CmdVectorDirty[] =
  49. {
  50. { L"?", DirtyHelp },
  51. { L"help", DirtyHelp },
  52. { L"query", IsVolumeDirty },
  53. { L"set", MarkVolumeDirty },
  54. { NULL, NULL }
  55. };
  56. COMMAND_VECTOR CmdVectorFsInfo[] =
  57. {
  58. { L"?", FsInfoHelp },
  59. { L"help", FsInfoHelp },
  60. { L"drives", ListDrives },
  61. { L"drivetype", DriveType },
  62. { L"volumeinfo", VolumeInfo },
  63. { L"ntfsinfo", GetNtfsVolumeData },
  64. { L"statistics", GetFileSystemStatistics },
  65. { NULL, NULL }
  66. };
  67. COMMAND_VECTOR CmdVectorReparse[] =
  68. {
  69. { L"?", ReparseHelp },
  70. { L"help", ReparseHelp },
  71. { L"query", GetReparsePoint },
  72. { L"delete", DeleteReparsePoint },
  73. { NULL, NULL }
  74. };
  75. COMMAND_VECTOR CmdVectorBehavior[] =
  76. {
  77. { L"?", BehaviorHelp },
  78. { L"help", BehaviorHelp },
  79. { L"query", RegistryQueryValueKey },
  80. { L"set", RegistrySetValueKey },
  81. { NULL, NULL }
  82. };
  83. COMMAND_VECTOR CmdVectorFile[] =
  84. {
  85. { L"?", FileHelp },
  86. { L"help", FileHelp },
  87. { L"findbysid", FindFilesBySid },
  88. { L"queryallocranges", QueryAllocatedRanges },
  89. { L"setshortname", SetShortName },
  90. { L"setvaliddata", SetValidDataLength },
  91. { L"setzerodata", SetZeroData },
  92. { L"createnew", CreateNewFile },
  93. { NULL, NULL }
  94. };
  95. COMMAND_VECTOR CmdVectorVolume[] =
  96. {
  97. { L"?", VolumeHelp },
  98. { L"help", VolumeHelp },
  99. { L"dismount", DismountVolume },
  100. { L"diskfree", DiskFreeSpace },
  101. { NULL, NULL }
  102. };
  103. COMMAND_VECTOR CmdVectorObjectId[] =
  104. {
  105. { L"?", ObjectIdHelp },
  106. { L"help", ObjectIdHelp },
  107. { L"query", GetObjectId },
  108. { L"set", SetObjectId },
  109. { L"delete", DeleteObjectId },
  110. { L"create", CreateOrGetObjectId },
  111. { NULL, NULL }
  112. };
  113. COMMAND_VECTOR CmdVectorSparse[] =
  114. {
  115. { L"?", SparseHelp },
  116. { L"help", SparseHelp },
  117. { L"setflag", SetSparse },
  118. { L"queryflag", QuerySparse },
  119. { L"queryrange", QuerySparseRange },
  120. { L"setrange", SetSparseRange },
  121. { NULL, NULL }
  122. };
  123. COMMAND_VECTOR CmdVectorHardLink[] =
  124. {
  125. { L"?", HardLinkHelp },
  126. { L"help", HardLinkHelp },
  127. { L"create", CreateHardLinkFile },
  128. { NULL, NULL }
  129. };
  130. COMMAND_VECTOR CmdVectorGroups[] =
  131. {
  132. { L"behavior", CmdVectorBehavior },
  133. { L"dirty", CmdVectorDirty },
  134. { L"file", CmdVectorFile },
  135. { L"fsinfo", CmdVectorFsInfo },
  136. { L"hardlink", CmdVectorHardLink },
  137. { L"objectid", CmdVectorObjectId },
  138. { L"quota", CmdVectorQuota },
  139. { L"reparsepoint", CmdVectorReparse },
  140. { L"sparse", CmdVectorSparse },
  141. { L"usn", CmdVectorUsn },
  142. { L"volume", CmdVectorVolume },
  143. { NULL, NULL }
  144. };
  145. PCOMMAND_VECTOR
  146. FindCommand(
  147. PCOMMAND_VECTOR Cmds,
  148. LPWSTR CmdName
  149. )
  150. {
  151. while (Cmds->CommandName) {
  152. if (!_wcsicmp( Cmds->CommandName, CmdName )) {
  153. return Cmds;
  154. }
  155. Cmds += 1;
  156. }
  157. return NULL;
  158. }
  159. INT
  160. __cdecl wmain(
  161. INT argc,
  162. PWSTR argv[]
  163. )
  164. /*++
  165. Routine Description:
  166. This routine is the 'main' routine for the tool 'fscutl'.
  167. Arguments:
  168. argc - The argument count.
  169. argv - Array of Strings of the form :
  170. ' fscutl <command> <options/flags> <parameters> ...'
  171. Return Value:
  172. INT - Return Status
  173. --*/
  174. {
  175. PCOMMAND_VECTOR Cmds = NULL;
  176. PCOMMAND_VECTOR Cmds2 = NULL;
  177. OSVERSIONINFOEX OsVer;
  178. #if FALSE
  179. LANGID (WINAPI *pSetThreadUILanguage)( ) = NULL;
  180. if (pSetThreadUILanguage == NULL) {
  181. pSetThreadUILanguage = (PVOID) GetProcAddress( GetModuleHandle( TEXT( "kernel32" )), "SetThreadUILanguage" );
  182. }
  183. if (pSetThreadUILanguage == NULL) {
  184. SetThreadLocale( MAKELCID( MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ), SORT_DEFAULT ));
  185. } else {
  186. (*pSetThreadUILanguage)( 0 );
  187. }
  188. #endif
  189. setlocale( LC_ALL, ".OCP" ) ;
  190. SHIFT( argc, argv );
  191. OsVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  192. if (GetVersionEx( (LPOSVERSIONINFO)&OsVer ) && OsVer.dwMajorVersion == 5 && OsVer.dwMinorVersion == 0) {
  193. RunningOnWin2K = TRUE;
  194. }
  195. if (!IsUserAdmin()) {
  196. DisplayMsg( MSG_ADMIN_REQUIRED );
  197. return EXIT_CODE_FAILURE;
  198. }
  199. //
  200. // Check for blind usage
  201. //
  202. if (argc == 0) {
  203. Help( 0, NULL );
  204. return EXIT_CODE_SUCCESS;
  205. }
  206. //
  207. // We have a two-level dispatch scheme. First level selects a table and second
  208. // selects a function
  209. //
  210. Cmds = FindCommand( CmdVectorGroups, argv[0] );
  211. if (Cmds == NULL) {
  212. DisplayMsg( MSG_INVALID_PARAMETER, argv[0] );
  213. Help( 0, NULL );
  214. return EXIT_CODE_FAILURE;
  215. }
  216. SHIFT( argc, argv );
  217. //
  218. // If there's no argument, then it's a cry for help
  219. //
  220. if (argc == 0) {
  221. Cmds2 = FindCommand( Cmds->CommandVector, L"?" );
  222. Cmds2->CommandFunc( argc, argv );
  223. return EXIT_CODE_SUCCESS;
  224. }
  225. //
  226. // Go to second level dispatch.
  227. //
  228. Cmds2 = FindCommand( Cmds->CommandVector, argv[0] );
  229. if (Cmds2 == NULL) {
  230. DisplayMsg( MSG_INVALID_PARAMETER, argv[0] );
  231. Cmds2 = FindCommand( Cmds->CommandVector, L"?" );
  232. SHIFT( argc, argv );
  233. Cmds2->CommandFunc( argc, argv );
  234. return EXIT_CODE_FAILURE;
  235. }
  236. SHIFT( argc, argv );
  237. return Cmds2->CommandFunc( argc, argv );
  238. }