Windows NT 4.0 source code leak
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.

334 lines
8.0 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. tstat.c
  5. Abstract:
  6. This module reads and displays the redirector statistics.
  7. Author:
  8. Colin Watson (ColinW) 10-Apr-1992
  9. Environment:
  10. Application mode
  11. Revision History:
  12. --*/
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <ntddnfs.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #define CHAR_SP 0x20
  21. #define Verbose 1
  22. #define NamedField(Flag) {#Flag, Flag}
  23. #define dprintf(Arguments) { \
  24. if ( Verbose ) { \
  25. printf Arguments ; \
  26. } \
  27. }
  28. #define DumpNewLine() { \
  29. dprintf(("\n")); \
  30. DumpCurrentColumn = 1; \
  31. }
  32. #define DumpLabel(Label,Width) { \
  33. ULONG i; \
  34. CHAR _Str[30]; \
  35. _Str[0] = _Str[1] = CHAR_SP; \
  36. strncpy(&_Str[2],#Label,Width); \
  37. for(i=strlen(_Str);i<Width;i++) {_Str[i] = CHAR_SP;} \
  38. _Str[Width] = '\0'; \
  39. dprintf(("%s", _Str)); \
  40. }
  41. #define DumpField(Field) { \
  42. if ((DumpCurrentColumn + 18 + 9 + 9) > 80) {DumpNewLine();} \
  43. DumpCurrentColumn += 18 + 9 + 9; \
  44. DumpLabel(Field,18); \
  45. dprintf((":%8lx", Ptr->Field)); \
  46. dprintf((" ")); \
  47. }
  48. #define DumpLarge_Integer(Field) { \
  49. DumpField(Field.LowPart); \
  50. DumpField(Field.HighPart); \
  51. }
  52. #define DumpChar(Field) { \
  53. if ((DumpCurrentColumn + 18 + 9 + 9) > 80) {DumpNewLine();} \
  54. DumpCurrentColumn += 18 + 9 + 9; \
  55. DumpLabel(Field,18); \
  56. dprintf((":%8lx", (LONG)Ptr->Field)); \
  57. dprintf((" "); )\
  58. }
  59. #define DumpBoolean(Field) { \
  60. if (Ptr->Field) DumpLabel(Field,18); \
  61. }
  62. #define DumpTime(Field) { \
  63. TIME_FIELDS TimeFields; \
  64. if ((DumpCurrentColumn + 18 + 10 + 10 + 9) > 80) {DumpNewLine();} \
  65. DumpCurrentColumn += 18 + 10 + 10 + 9; \
  66. DumpLabel(Field,18); \
  67. RtlTimeToTimeFields(&Ptr->Field, &TimeFields); \
  68. dprintf((":%02d-%02d-%04d ", TimeFields.Month, TimeFields.Day, TimeFields.Year)); \
  69. dprintf(("%02d:%02d:%02d", TimeFields.Hour, TimeFields.Minute, TimeFields.Second)); \
  70. dprintf((" ")); \
  71. }
  72. #define DumpBitfield(Value, Field) { \
  73. if ((Value) & Field) { \
  74. if ((DumpCurrentColumn + 27) > 80) {DumpNewLine();} \
  75. DumpCurrentColumn += 27;\
  76. DumpLabel(#Field,27); \
  77. } \
  78. }
  79. #define DumpOption(Value, Field) { \
  80. if ((Value) == Field) { \
  81. if ((DumpCurrentColumn + 27) > 80) {DumpNewLine();} \
  82. DumpCurrentColumn += 27;\
  83. DumpLabel(#Field,27); \
  84. } \
  85. }
  86. #define DumpName(Field,Width) { \
  87. ULONG i; \
  88. CHAR _String[256]; \
  89. if ((DumpCurrentColumn + 18 + Width) > 80) {DumpNewLine();} \
  90. DumpCurrentColumn += 18 + Width; \
  91. DumpLabel(Field,18); \
  92. for(i=0;i<Width;i++) {_String[i] = Ptr->Field[i];} \
  93. _String[Width] = '\0'; \
  94. dprintf(("%s", _String)); \
  95. }
  96. #define DumpUName(Field,Width) { \
  97. ULONG i; \
  98. CHAR _String[256]; \
  99. if ((DumpCurrentColumn + 18 + Width) > 80) {DumpNewLine();} \
  100. DumpCurrentColumn += 18 + Width; \
  101. DumpLabel(Field,18); \
  102. for(i=0;i<Width;i++) {_String[i] = (UCHAR )(Ptr->Field[i]);} \
  103. _String[Width] = '\0'; \
  104. dprintf(("%s", _String)); \
  105. }
  106. void
  107. dump(
  108. PVOID far_p,
  109. ULONG len
  110. );
  111. VOID
  112. HexDumpLine (
  113. PCHAR pch,
  114. ULONG len,
  115. PCHAR s,
  116. PCHAR t,
  117. USHORT flag
  118. );
  119. int
  120. _cdecl
  121. main (argc, argv)
  122. int argc;
  123. char *argv[];
  124. {
  125. HANDLE FileHandle;
  126. NTSTATUS Status;
  127. REDIR_STATISTICS Stats;
  128. IO_STATUS_BLOCK IoStatusBlock;
  129. ULONG DumpCurrentColumn = 0;
  130. OBJECT_ATTRIBUTES Obja;
  131. UNICODE_STRING FileName;
  132. RTL_RELATIVE_NAME RelativeName;
  133. RtlInitUnicodeString(&FileName,DD_NFS_DEVICE_NAME_U);
  134. RelativeName.ContainingDirectory = NULL;
  135. InitializeObjectAttributes(
  136. &Obja,
  137. &FileName,
  138. OBJ_CASE_INSENSITIVE,
  139. RelativeName.ContainingDirectory,
  140. NULL
  141. );
  142. Status = NtCreateFile(
  143. &FileHandle,
  144. SYNCHRONIZE,
  145. &Obja,
  146. &IoStatusBlock,
  147. NULL,
  148. FILE_ATTRIBUTE_NORMAL,
  149. FILE_SHARE_READ | FILE_SHARE_WRITE,
  150. FILE_OPEN_IF,
  151. FILE_SYNCHRONOUS_IO_NONALERT,
  152. NULL,
  153. 0
  154. );
  155. /* Status = NtCreateFile(
  156. &FileHandle,
  157. SYNCHRONIZE | GENERIC_WRITE | FILE_READ_ATTRIBUTES,
  158. &Obja,
  159. &IoStatusBlock,
  160. NULL,
  161. FILE_ATTRIBUTE_NORMAL,
  162. FILE_SHARE_WRITE,
  163. FILE_SUPERSEDE,
  164. FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY,
  165. NULL,
  166. 0
  167. );
  168. */
  169. printf( "NtCreateFile of \\Device\\LanmanRedirector returned %X\n", Status );
  170. if ( NT_SUCCESS(Status) ) {
  171. Status = NtFsControlFile(
  172. FileHandle,
  173. NULL,
  174. NULL,
  175. NULL,
  176. &IoStatusBlock,
  177. FSCTL_LMR_GET_STATISTICS,
  178. NULL,
  179. 0,
  180. &Stats,
  181. sizeof(Stats)
  182. );
  183. printf( "NtFsControlFile returned %X\n", Status );
  184. if ( NT_SUCCESS(Status) ) {
  185. PREDIR_STATISTICS Ptr = &Stats;
  186. DumpLarge_Integer(BytesReceived);
  187. DumpLarge_Integer(SmbsReceived);
  188. DumpLarge_Integer(PagingReadBytesRequested);
  189. DumpLarge_Integer(NonPagingReadBytesRequested);
  190. DumpLarge_Integer(CacheReadBytesRequested);
  191. DumpLarge_Integer(NetworkReadBytesRequested);
  192. DumpLarge_Integer(BytesTransmitted);
  193. DumpLarge_Integer(SmbsTransmitted);
  194. DumpLarge_Integer(PagingWriteBytesRequested);
  195. DumpLarge_Integer(NonPagingWriteBytesRequested);
  196. DumpLarge_Integer(CacheWriteBytesRequested);
  197. DumpLarge_Integer(NetworkWriteBytesRequested);
  198. DumpField(ReadOperations);
  199. DumpField(RandomReadOperations);
  200. DumpField(ReadSmbs);
  201. DumpField(LargeReadSmbs);
  202. DumpField(SmallReadSmbs);
  203. DumpField(WriteOperations);
  204. DumpField(RandomWriteOperations);
  205. DumpField(WriteSmbs);
  206. DumpField(LargeWriteSmbs);
  207. DumpField(SmallWriteSmbs);
  208. DumpField(RawReadsDenied);
  209. DumpField(RawWritesDenied);
  210. DumpField(NetworkErrors);
  211. DumpField(Sessions);
  212. DumpField(Reconnects);
  213. DumpField(CoreConnects);
  214. DumpField(Lanman20Connects);
  215. DumpField(Lanman21Connects);
  216. DumpField(LanmanNtConnects);
  217. DumpField(ServerDisconnects);
  218. DumpField(HungSessions);
  219. DumpField(CurrentCommands);
  220. }
  221. }
  222. NtClose(FileHandle);
  223. printf( "Ending Tstat\n" );
  224. return 0;
  225. }
  226. /*
  227. * ndump_core: debug routine to print core
  228. */
  229. void
  230. dump(
  231. PVOID far_p,
  232. ULONG len
  233. )
  234. {
  235. ULONG l;
  236. char s[80], t[80];
  237. PCHAR far_pchar = (PCHAR)far_p;
  238. ULONG MaxDump = 256;
  239. if (len > MaxDump)
  240. len = MaxDump;
  241. while (len) {
  242. l = len < 16 ? len : 16;
  243. printf("\n%lx ", far_pchar);
  244. HexDumpLine (far_pchar, l, s, t, 0);
  245. printf("%s%.*s%s", s, 1 + ((16 - l) * 3), "", t);
  246. len -= l;
  247. far_pchar += l;
  248. }
  249. printf("\n");
  250. }
  251. VOID
  252. HexDumpLine (
  253. PCHAR pch,
  254. ULONG len,
  255. PCHAR s,
  256. PCHAR t,
  257. USHORT flag
  258. )
  259. {
  260. static UCHAR rghex[] = "0123456789ABCDEF";
  261. UCHAR c;
  262. UCHAR *hex, *asc;
  263. hex = s;
  264. asc = t;
  265. *(asc++) = '*';
  266. while (len--) {
  267. c = *(pch++);
  268. *(hex++) = rghex [c >> 4] ;
  269. *(hex++) = rghex [c & 0x0F];
  270. *(hex++) = ' ';
  271. *(asc++) = (c < ' ' || c > '~') ? (CHAR )'.' : c;
  272. }
  273. *(asc++) = '*';
  274. *asc = 0;
  275. *hex = 0;
  276. flag;
  277. }