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.

231 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. config.c
  5. Abstract:
  6. Reads cluster configuration from file
  7. Author:
  8. Ahmed Mohamed (ahmedm) 12, 01, 2000
  9. Revision History:
  10. --*/
  11. #include <windows.h>
  12. #include <winioctl.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <assert.h>
  17. extern void debug_init();
  18. void
  19. msg_set_mode(int mode);
  20. void
  21. msg_set_uport(int uport);
  22. void
  23. msg_set_mport(int mport);
  24. void
  25. msg_set_subnet(char *addr);
  26. void
  27. msg_set_mipaddr(char *addr);
  28. void
  29. msg_set_bufcount(int count);
  30. void
  31. msg_set_bufsize(int count);
  32. #define stricmp(a,b) strcmp(a,b)
  33. static char qfile[256];
  34. static char vname[256];
  35. static char crsname[256];
  36. static int crssz = 128*1024;
  37. char *
  38. WINAPI
  39. config_get_volume()
  40. {
  41. return vname;
  42. }
  43. char *
  44. WINAPI
  45. config_get_crsfile()
  46. {
  47. return crsname;
  48. }
  49. int
  50. WINAPI
  51. config_get_crssz()
  52. {
  53. return crssz;
  54. }
  55. char *
  56. WINAPI
  57. config_get_qfile()
  58. {
  59. return qfile;
  60. }
  61. static void
  62. parse_node(char *buf)
  63. {
  64. char *s, *p, *q;
  65. int WINAPI msg_addnode(int id, char *n, char *a);
  66. int id;
  67. p = strchr(buf, ':');
  68. if (p == NULL)
  69. return;
  70. *p = '\0'; p++;
  71. id = atoi(buf);
  72. s = p;
  73. p = strchr(s, ':');
  74. if (p == NULL)
  75. return;
  76. p++;
  77. q = strchr(p, '\n');
  78. if (q) {
  79. *q = '\0'; q += 2;
  80. }
  81. msg_addnode(id, s, p);
  82. }
  83. static void
  84. parse_vol(char *buf)
  85. {
  86. char *s, *p, *q;
  87. s = (char *)buf;
  88. #if 0
  89. p = strchr(s, ':');
  90. if (p == NULL)
  91. return;
  92. *p = '\0'; p++;
  93. #else
  94. p = s;
  95. #endif
  96. q = strchr(p, '\n');
  97. if (q) {
  98. *q = '\0'; q += 2;
  99. }
  100. // add volume
  101. strcpy(vname, s);
  102. }
  103. static void
  104. parse(char *buf, ULONG len)
  105. {
  106. char *s, *p, *q;
  107. void WINAPI debug_log_file(char*);
  108. void WINAPI debug_level(ULONG);
  109. s = (char *)buf;
  110. s[len] = '\0';
  111. p = strchr(s, ':');
  112. if (p == NULL)
  113. return;
  114. *p = '\0'; p++;
  115. q = strchr(p, '\n');
  116. if (q) {
  117. *q = '\0'; q += 2;
  118. }
  119. if (!stricmp(s, "quorm")) {
  120. strcpy(qfile, p);
  121. } else if (!stricmp(s, "log_file")) {
  122. debug_log_file(p);
  123. } else if (!stricmp(s, "log_level")) {
  124. ULONG x = (ULONG) atoi(p);
  125. debug_level(x);
  126. } else if (!stricmp(s, "crs_file")) {
  127. strcpy(crsname, p);
  128. } else if (!stricmp(s, "crs_size")) {
  129. crssz = atoi(p);
  130. if (crssz == 0) {
  131. crssz = 128;
  132. }
  133. } else if (!stricmp(s, "mcast")) {
  134. msg_set_mode(atoi(p));
  135. } else if (!stricmp(s, "mcast_ipaddr")) {
  136. msg_set_mipaddr(p);
  137. } else if (!stricmp(s, "mcast_port")) {
  138. int x = atoi(p);
  139. msg_set_mport(x);
  140. } else if (!stricmp(s, "subnet")) {
  141. msg_set_subnet(p);
  142. } else if (!stricmp(s, "ucast_port")) {
  143. int x = atoi(p);
  144. msg_set_uport(x);
  145. } else if (!stricmp(s, "buffers")) {
  146. int x = atoi(p);
  147. msg_set_bufcount(x);
  148. } else if (!stricmp(s, "bufsize")) {
  149. int x = atoi(p);
  150. msg_set_bufsize(x);
  151. } else if (!stricmp(s, "node")) {
  152. parse_node(p);
  153. } else if (!stricmp(s, "volume")) {
  154. parse_vol(p);
  155. } else {
  156. fprintf(stderr,"Unknown tag '%s'\n", s);
  157. }
  158. }
  159. void
  160. ConfigInit()
  161. {
  162. char buf[256];
  163. FILE *fp;
  164. char *s = getenv("RfsFile");
  165. if (s == NULL)
  166. s = "rfs.conf";
  167. debug_init();
  168. // Open cluster
  169. fp = fopen(s, "r");
  170. if (fp == NULL) {
  171. fprintf(stderr,"Unable to open configuration file '%s'\n", s);
  172. exit(0);
  173. }
  174. // init stuff
  175. strcpy(crsname, "c:\\crs.log");
  176. while (fgets(buf, sizeof(buf), fp)) {
  177. if (strlen(buf) > 2) {
  178. parse(buf, strlen(buf));
  179. }
  180. }
  181. fclose(fp);
  182. }