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.

177 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. namedb.c
  5. Abstract:
  6. This module maintains a database of path names detected by the INSTALER program
  7. Author:
  8. Steve Wood (stevewo) 20-Aug-1994
  9. Revision History:
  10. --*/
  11. #include "instaler.h"
  12. typedef struct _NAME_TABLE_ENTRY {
  13. struct _NAME_TABLE_ENTRY *HashLink;
  14. UNICODE_STRING Name;
  15. ULONG OpenCount;
  16. ULONG FailedOpenCount;
  17. } NAME_TABLE_ENTRY, *PNAME_TABLE_ENTRY;
  18. #define NUMBER_OF_HASH_BUCKETS 37
  19. PNAME_TABLE_ENTRY NameTableBuckets[ NUMBER_OF_HASH_BUCKETS ];
  20. BOOLEAN
  21. IncrementOpenCount(
  22. PWSTR Name,
  23. BOOLEAN CallSuccessful
  24. )
  25. {
  26. PNAME_TABLE_ENTRY p;
  27. p = (PNAME_TABLE_ENTRY)Name - 1;
  28. if (p->Name.Buffer == Name) {
  29. if (CallSuccessful) {
  30. p->OpenCount += 1;
  31. }
  32. else {
  33. p->FailedOpenCount += 1;
  34. }
  35. return TRUE;
  36. }
  37. else {
  38. return FALSE;
  39. }
  40. }
  41. ULONG
  42. QueryOpenCount(
  43. PWSTR Name,
  44. BOOLEAN CallSuccessful
  45. )
  46. {
  47. PNAME_TABLE_ENTRY p;
  48. p = (PNAME_TABLE_ENTRY)Name - 1;
  49. if (p->Name.Buffer == Name) {
  50. if (CallSuccessful) {
  51. return p->OpenCount;
  52. }
  53. else {
  54. return p->FailedOpenCount;
  55. }
  56. }
  57. else {
  58. return 0;
  59. }
  60. }
  61. PWSTR
  62. AddName(
  63. PUNICODE_STRING Name
  64. )
  65. {
  66. ULONG n, Hash;
  67. WCHAR c;
  68. PWCH s;
  69. PNAME_TABLE_ENTRY *pp, p;
  70. n = Name->Length / sizeof( c );
  71. s = Name->Buffer;
  72. Hash = 0;
  73. while (n--) {
  74. c = RtlUpcaseUnicodeChar( *s++ );
  75. Hash = Hash + (c << 1) + (c >> 1) + c;
  76. }
  77. pp = &NameTableBuckets[ Hash % NUMBER_OF_HASH_BUCKETS ];
  78. while (p = *pp) {
  79. if (RtlEqualUnicodeString( &p->Name, Name, TRUE )) {
  80. return p->Name.Buffer;
  81. }
  82. else {
  83. pp = &p->HashLink;
  84. }
  85. }
  86. p = AllocMem( sizeof( *p ) + Name->Length + sizeof( UNICODE_NULL ) );
  87. if (p == NULL) {
  88. printf ("Memory allocation failure\n");
  89. ExitProcess (0);
  90. }
  91. *pp = p;
  92. p->HashLink = NULL;
  93. p->Name.Buffer = (PWSTR)(p + 1);
  94. p->Name.Length = Name->Length;
  95. p->Name.MaximumLength = (USHORT)(Name->Length + sizeof( UNICODE_NULL ));
  96. RtlMoveMemory( p->Name.Buffer, Name->Buffer, Name->Length );
  97. p->Name.Buffer[ Name->Length / sizeof( WCHAR ) ] = UNICODE_NULL;
  98. return p->Name.Buffer;
  99. }
  100. VOID
  101. DumpNameDataBase(
  102. FILE *LogFile
  103. )
  104. {
  105. ULONG i;
  106. PNAME_TABLE_ENTRY p;
  107. #if 0
  108. fprintf( LogFile, "Name Data Base entries:\n" );
  109. for (i=0; i<NUMBER_OF_HASH_BUCKETS; i++) {
  110. p = NameTableBuckets[ i ];
  111. if (p != NULL) {
  112. fprintf( LogFile, "Bucket[ %02u ]:\n", i );
  113. while (p) {
  114. fprintf( LogFile, " %ws\n", p->Name.Buffer );
  115. p = p->HashLink;
  116. }
  117. }
  118. }
  119. fprintf( LogFile, "\n" );
  120. #endif
  121. fprintf( LogFile, "List of paths with non-zero successful open counts\n" );
  122. for (i=0; i<NUMBER_OF_HASH_BUCKETS; i++) {
  123. p = NameTableBuckets[ i ];
  124. if (p != NULL) {
  125. while (p) {
  126. if (p->OpenCount != 0) {
  127. fprintf( LogFile, " %4u %ws\n", p->OpenCount, p->Name.Buffer );
  128. }
  129. p = p->HashLink;
  130. }
  131. }
  132. }
  133. fprintf( LogFile, "\n" );
  134. fprintf( LogFile, "List of paths with non-zero failed open counts\n" );
  135. for (i=0; i<NUMBER_OF_HASH_BUCKETS; i++) {
  136. p = NameTableBuckets[ i ];
  137. if (p != NULL) {
  138. while (p) {
  139. if (p->FailedOpenCount != 0) {
  140. fprintf( LogFile, " %4u %ws\n", p->FailedOpenCount, p->Name.Buffer );
  141. }
  142. p = p->HashLink;
  143. }
  144. }
  145. }
  146. fprintf( LogFile, "\n" );
  147. return;
  148. }