Leaked source code of windows server 2003
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.

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