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.

2189 lines
49 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. frs.h
  5. Abstract:
  6. This header handles information global to the ntrepl\frs modules
  7. Author:
  8. Billy Fuller (billyf) - 20-Mar-1997
  9. --*/
  10. #ifndef _FRSH_
  11. #define _FRSH_
  12. #include <schedule.h>
  13. #include <debug.h>
  14. #include <frsrpc.h>
  15. #include <frsapi.h>
  16. #include <frsalloc.h>
  17. #include <winldap.h>
  18. #include <dsgetdc.h>
  19. #include <mmsystem.h>
  20. #include <global.h>
  21. #include <winsvc.h>
  22. #include <ntfrsres.h>
  23. #include <eventlog.h>
  24. #include <resource.h>
  25. //
  26. // Types for the common comm subsystem
  27. //
  28. typedef enum _COMMAND_SERVER_ID {
  29. CS_NONE = 0,
  30. CS_RS,
  31. CS_MAX
  32. } COMMAND_SERVER_ID, *PCOMMAND_SERVER_ID;
  33. //
  34. // GLOBALS
  35. //
  36. #define NTFRS_MAJOR (0)
  37. #define NTFRS_MINOR (0)
  38. extern ULONG NtFrsMajor;
  39. extern ULONG NtFrsMinor;
  40. extern PCHAR NtFrsModule;
  41. extern PCHAR NtFrsDate;
  42. extern PCHAR NtFrsTime;
  43. //
  44. // Staging File Version Levels
  45. //
  46. #define NTFRS_STAGE_MAJOR (0)
  47. #define NTFRS_STAGE_MINOR_0 (0)
  48. #define NTFRS_STAGE_MINOR_1 (1) // ChangeOrder Record extension added to stage file.
  49. #define NTFRS_STAGE_MINOR_2 (2) // Compression Guid added to stage file.
  50. extern ULONG NtFrsStageMajor;
  51. extern ULONG NtFrsStageMinor;
  52. //
  53. // Communication packet version levels.
  54. //
  55. #define NTFRS_COMM_MINOR_0 (0)
  56. #define NTFRS_COMM_MINOR_1 (1) // MD5
  57. #define NTFRS_COMM_MINOR_2 (2) // Trigger schedule
  58. #define NTFRS_COMM_MINOR_3 (3) // ChangeOrder Record Extension.
  59. //
  60. // The following minor rev forces the Replica Number fields in the change order
  61. // to be a ULONG (v.s. ULONG_PTR) for 32 - 64 bit interop. Add hack to always
  62. // ship the 4 ptrs in the CO as 32 bits of zeros for 32 bit compat (see schema.h).
  63. //
  64. // Also the change order extension supports a var len comm element v.s. fixed
  65. // size as in rev_3. When sending the CO Externsion to rev 3 servers you can
  66. // only send the COMM_CO_EXT_WIN2K element with the MD5 checksum. For Rev 4
  67. // servers and above you can send COMM_CO_EXTENSION_2 data elements.
  68. //
  69. // Added COMM_COMPRESSION_GUID as part of Join request.
  70. //
  71. #define NTFRS_COMM_MINOR_4 (4) // ChangeOrder Record Extension. COMM_CO_EXTENSION_2
  72. extern ULONG NtFrsCommMinor;
  73. //
  74. // SCHEDULE
  75. // Defines for both an byte-per-hour and a nibble-per-hour
  76. //
  77. #ifdef SCHEDULE_NIBBLE_PER_HOUR
  78. //
  79. // Each hour in a schedule is 4 bits (rounded up).
  80. //
  81. #define SCHEDULE_DATA_BYTES ((SCHEDULE_DATA_ENTRIES + 1) / 2)
  82. //
  83. // Each hour in a schedule is 8 bits (byte).
  84. //
  85. #else SCHEDULE_NIBBLE_PER_HOUR
  86. #define SCHEDULE_DATA_BYTES SCHEDULE_DATA_ENTRIES
  87. #endif SCHEDULE_NIBBLE_PER_HOUR
  88. //
  89. // Defines for checking Service state transitions.
  90. // Used in FrsSetServiceStatus()
  91. //
  92. #define FRS_SVC_TRANSITION_TABLE_SIZE 5
  93. #define FRS_SVC_TRANSITION_LEGAL 0
  94. #define FRS_SVC_TRANSITION_NOOP 1
  95. #define FRS_SVC_TRANSITION_ILLEGAL 2
  96. //
  97. // FRS MEMORY MANAGEMENT
  98. //
  99. VOID
  100. FrsInitializeMemAlloc(
  101. VOID
  102. );
  103. VOID
  104. FrsUnInitializeMemAlloc(
  105. VOID
  106. );
  107. //
  108. // DS
  109. //
  110. //
  111. // Some useful DS search constants
  112. //
  113. #define CONFIG_NAMING_CONTEXT L"cn=configuration"
  114. #define CLASS_ANY L"(objectClass=*)"
  115. #define CLASS_CXTION L"(objectClass=nTDSConnection)"
  116. #define CLASS_MEMBER L"(objectClass=nTFRSMember)"
  117. #define CLASS_REPLICA_SET L"(objectClass=nTFRSReplicaSet)"
  118. #define CLASS_NTFRS_SETTINGS L"(objectClass=nTFRSSettings)"
  119. #define CLASS_NTDS_SETTINGS L"(objectClass=nTDSSettings)"
  120. #define CLASS_SUBSCRIBER L"(objectClass=nTFRSSubscriber)"
  121. #define CLASS_SUBSCRIPTIONS L"(objectClass=nTFRSSubscriptions)"
  122. #define CLASS_NTDS_DSA L"(objectClass=nTDSDSA)"
  123. #define CLASS_COMPUTER L"(objectClass=computer)"
  124. #define CLASS_USER L"(objectClass=user)"
  125. #define CLASS_SERVER L"(objectClass=server)"
  126. #define CATEGORY_ANY L"(objectCategory=*)"
  127. #define CATEGORY_CXTION L"(objectCategory=nTDSConnection)"
  128. #define CATEGORY_MEMBER L"(objectCategory=nTFRSMember)"
  129. #define CATEGORY_REPLICA_SET L"(objectCategory=nTFRSReplicaSet)"
  130. #define CATEGORY_NTFRS_SETTINGS L"(objectCategory=nTFRSSettings)"
  131. #define CATEGORY_NTDS_SETTINGS L"(objectCategory=nTDSSettings)"
  132. #define CATEGORY_SUBSCRIBER L"(objectCategory=nTFRSSubscriber)"
  133. #define CATEGORY_SUBSCRIPTIONS L"(objectCategory=nTFRSSubscriptions)"
  134. #define CATEGORY_NTDS_DSA L"(objectCategory=nTDSDSA)"
  135. #define CATEGORY_COMPUTER L"(objectCategory=computer)"
  136. #define CATEGORY_USER L"(objectCategory=user)"
  137. #define CATEGORY_SERVER L"(objectCategory=server)"
  138. //
  139. // Codes for the various Config Node to Object Type mappings
  140. // Note: Update string array DsConfigTypeName[] when this changes.
  141. //
  142. #define CONFIG_TYPE_UNDEFINED (0)
  143. #define CONFIG_TYPE_IN_CXTION (1)
  144. #define CONFIG_TYPE_MEMBER (2)
  145. #define CONFIG_TYPE_REPLICA_SET (3)
  146. #define CONFIG_TYPE_NTFRS_SETTINGS (4)
  147. #define CONFIG_TYPE_NTDS_SETTINGS (5)
  148. #define CONFIG_TYPE_SUBSCRIBER (6)
  149. #define CONFIG_TYPE_SUBSCRIPTIONS (7)
  150. #define CONFIG_TYPE_NTDS_DSA (8)
  151. #define CONFIG_TYPE_COMPUTER (9)
  152. #define CONFIG_TYPE_USER (10)
  153. #define CONFIG_TYPE_SERVER (11)
  154. #define CONFIG_TYPE_SERVICES_ROOT (12)
  155. #define CONFIG_TYPE_OUT_CXTION (13)
  156. #define ATTR_DIRECTORY_FILTER L"frsDirectoryFilter"
  157. #define ATTR_FILE_FILTER L"frsFileFilter"
  158. #define ATTR_NEW_SET_GUID L"frsReplicaSetGUID"
  159. #define ATTR_OLD_SET_GUID L"replicaSetGUID"
  160. #define ATTR_CLASS L"objectClass"
  161. #define ATTR_DN L"distinguishedName"
  162. #define ATTR_OBJECT_GUID L"objectGUID"
  163. #define ATTR_SCHEDULE L"schedule"
  164. #define ATTR_NEW_VERSION_GUID L"frsVersionGuid"
  165. #define ATTR_OLD_VERSION_GUID L"replicaVersionGuid"
  166. #define ATTR_REPLICA_SET L"nTFRSReplicaSet"
  167. #define ATTR_NTFRS_SETTINGS L"nTFRSSettings"
  168. #define ATTR_SERVER L"server"
  169. #define ATTR_MEMBER L"nTFRSMember"
  170. #define ATTR_REPLICA_ROOT L"frsRootPath"
  171. #define ATTR_REPLICA_STAGE L"frsStagingPath"
  172. #define ATTR_FROM_SERVER L"fromServer"
  173. #define ATTR_PRIMARY_MEMBER L"frsPrimaryMember"
  174. #define ATTR_SCHEDULE L"schedule"
  175. #define ATTR_USN_CHANGED L"uSNChanged"
  176. #define ATTR_NAMING_CONTEXTS L"namingContexts"
  177. #define ATTR_DEFAULT_NAMING_CONTEXT L"defaultNamingContext"
  178. #define ATTR_COMPUTER_REF L"frsComputerReference"
  179. #define ATTR_COMPUTER_REF_BL L"frsComputerReferenceBL"
  180. #define ATTR_SERVER_REF L"ServerReference"
  181. #define ATTR_SERVER_REF_BL L"ServerReferenceBL"
  182. #define ATTR_MEMBER_REF L"frsMemberReference"
  183. #define ATTR_MEMBER_REF_BL L"frsMemberReferenceBL"
  184. #define ATTR_WORKING L"frsWorkingPath"
  185. #define ATTR_SET_TYPE L"frsReplicaSetType"
  186. #define ATTR_SUBSCRIPTIONS L"nTFRSSubscriptions"
  187. #define ATTR_SUBSCRIBER L"nTFRSSubscriber"
  188. #define ATTR_CN L"cn"
  189. #define ATTR_EXTENSIONS L"frsExtensions"
  190. #define ATTR_SAM L"sAMAccountName"
  191. #define ATTR_CXTION L"nTDSConnection"
  192. #define ATTR_ENABLED_CXTION L"enabledConnection"
  193. #define ATTR_OPTIONS L"options"
  194. #define ATTR_TRANSPORT_TYPE L"transportType"
  195. #define ATTR_USER_ACCOUNT_CONTROL L"userAccountControl"
  196. #define ATTR_DNS_HOST_NAME L"dNSHostName"
  197. #define ATTR_SERVICE_PRINCIPAL_NAME L"servicePrincipalName"
  198. #define ATTR_TRUE L"TRUE"
  199. #define ATTR_FALSE L"FALSE"
  200. #define CN_ROOT L""
  201. #define CN_SYSVOLS L"Microsoft System Volumes"
  202. #define CN_ENTERPRISE_SYSVOL NTFRSAPI_REPLICA_SET_TYPE_ENTERPRISE
  203. #define CN_SERVERS L"Servers"
  204. #define CN_NTDS_SETTINGS L"ntds settings"
  205. #define CN_SUBSCRIPTIONS L"NTFRS Subscriptions"
  206. #define CN_COMPUTERS L"Computers"
  207. #define CN_DOMAIN_CONTROLLERS L"Domain Controllers"
  208. #define CN_SERVICES L"Services"
  209. #define CN_SITES L"Sites"
  210. #define CN_SYSTEM L"System"
  211. #define CN_NTFRS_SETTINGS L"File Replication Service"
  212. #define CN_DOMAIN_SYSVOL L"Domain System Volume (SYSVOL share)"
  213. //
  214. // Some useful ldap macroes
  215. //
  216. #define LDAP_FREE_MSG(x) {if (x) {ldap_msgfree(x); (x) = NULL;}}
  217. #define LDAP_FREE_VALUES(x) {if (x) {ldap_value_free(x); (x) = NULL;}}
  218. #define LDAP_FREE_BER_VALUES(x) {if (x) {ldap_value_free_len(x); (x) = NULL;}}
  219. //
  220. // DS Poller
  221. //
  222. VOID
  223. FrsDsInitialize(
  224. VOID
  225. );
  226. DWORD
  227. FrsDsSetDsPollingInterval(
  228. IN ULONG UseShortInterval,
  229. IN DWORD LongInterval,
  230. IN DWORD ShortInterval
  231. );
  232. DWORD
  233. FrsDsGetDsPollingInterval(
  234. OUT ULONG *Interval,
  235. OUT ULONG *LongInterval,
  236. OUT ULONG *ShortInterval
  237. );
  238. DWORD
  239. FrsDsStartDemotion(
  240. IN PWCHAR ReplicaSetName
  241. );
  242. DWORD
  243. FrsDsCommitDemotion(
  244. VOID
  245. );
  246. //
  247. // Default File and Directory filter lists.
  248. //
  249. // The compiled in default is only used if no value is supplied in
  250. // EITHER the DS or the Registry.
  251. // The table below shows how the final filter is formed.
  252. //
  253. // value Value
  254. // supplied supplied Resulting filter string Used
  255. // in DS in Registry
  256. // No No DEFAULT_xxx_FILTER_LIST
  257. // No Yes Value from registry
  258. // Yes No Value from DS
  259. // Yes Yes Value from DS + Value from registry
  260. //
  261. //
  262. #define FRS_DS_COMPOSE_FILTER_LIST(_DsFilterList, _RegFilterList, _DefaultFilterList) \
  263. \
  264. (((_DsFilterList) != NULL) ? \
  265. ( ((_RegFilterList) != NULL) ? \
  266. FrsWcsCat3((_DsFilterList), L",", (_RegFilterList)) : \
  267. FrsWcsDup((_DsFilterList)) \
  268. ) : \
  269. ( ((_RegFilterList) != NULL) ? \
  270. FrsWcsDup((_RegFilterList)) : \
  271. FrsWcsDup((_DefaultFilterList)) \
  272. ) \
  273. )
  274. //
  275. // Add a new message to the ds polling summary.
  276. //
  277. #define FRS_DS_ADD_TO_POLL_SUMMARY(_DsPollSummaryBuf, _NewMessage, _NewMessageLen) \
  278. \
  279. if ((DsPollSummaryBufLen + _NewMessageLen) > DsPollSummaryMaxBufLen ) { \
  280. PWCHAR _TempDsPollSummaryBuf = NULL; \
  281. _TempDsPollSummaryBuf = FrsAlloc(DsPollSummaryMaxBufLen + 2 * 1000); \
  282. DsPollSummaryMaxBufLen += (2 * 1000); \
  283. CopyMemory(_TempDsPollSummaryBuf, DsPollSummaryBuf, DsPollSummaryBufLen); \
  284. FrsFree(DsPollSummaryBuf); \
  285. DsPollSummaryBuf = _TempDsPollSummaryBuf; \
  286. } \
  287. \
  288. CopyMemory(&DsPollSummaryBuf[DsPollSummaryBufLen/2], _NewMessage, _NewMessageLen);\
  289. DsPollSummaryBufLen += _NewMessageLen;
  290. //
  291. // FRS Dummy event logging routines
  292. //
  293. extern VOID LogFrsException(FRS_ERROR_CODE, ULONG_PTR, PWCHAR);
  294. extern VOID LogException(DWORD, PWCHAR);
  295. //
  296. // FRS Exception Handling
  297. //
  298. extern VOID FrsRaiseException(FRS_ERROR_CODE, ULONG_PTR);
  299. extern DWORD FrsException(EXCEPTION_POINTERS *);
  300. extern DWORD FrsExceptionLastCode(VOID);
  301. extern ULONG_PTR FrsExceptionLastInfo(VOID);
  302. extern VOID FrsExceptionQuiet(BOOL);
  303. extern PVOID MallocException(DWORD);
  304. //
  305. // FRS Events
  306. //
  307. extern HANDLE ShutDownEvent; // shutdown the service
  308. extern HANDLE DataBaseEvent; // database is up and running
  309. extern HANDLE JournalEvent; // journal is up and running
  310. extern HANDLE ChgOrdEvent; // Change order accept is up and running
  311. extern HANDLE ReplicaEvent; // replica is up and running
  312. extern HANDLE CommEvent; // communication is up and running
  313. extern HANDLE DsPollEvent; // used to poll the ds
  314. extern HANDLE DsShutDownComplete; // ds polling thread has shut down
  315. //
  316. // FRS Global flags
  317. //
  318. extern BOOL EventLogIsRunning; // is the event log service up and running?
  319. extern BOOL RpcssIsRunning; // is the rpc endpoint service up and running?
  320. //
  321. // Main Initialization
  322. //
  323. VOID
  324. MainInit(
  325. VOID
  326. );
  327. //
  328. // Outbound Log Processor
  329. //
  330. VOID
  331. OutLogInitialize(
  332. VOID
  333. );
  334. VOID
  335. ShutDownOutLog(
  336. VOID
  337. );
  338. //
  339. // Vv Join
  340. //
  341. VOID
  342. SubmitVvJoin(
  343. IN PREPLICA Replica,
  344. IN PCXTION Cxtion,
  345. IN USHORT Command
  346. );
  347. DWORD
  348. SubmitVvJoinSync(
  349. IN PREPLICA Replica,
  350. IN PCXTION Cxtion,
  351. IN USHORT Command
  352. );
  353. //
  354. // FRS RPC
  355. //
  356. //
  357. // The protocols sequences we think we know how to support
  358. // XXX these constants should be in a win header file!
  359. //
  360. #define PROTSEQ_TCP_IP L"ncacn_ip_tcp"
  361. #define PROTSEQ_NAMED_PIPE L"ncacn_np"
  362. //
  363. // All computer names passed to RpcStringBindingCompose() using PROTSEQ_TCP_IP
  364. // need to have the leading two back slashes removed or the call fails with
  365. // RPC_S_SERVER_UNAVAILABLE.
  366. //
  367. #define FRS_TRIM_LEADING_2SLASH(_Name_) \
  368. if (((_Name_) != NULL) && \
  369. (wcslen(_Name_) > 1) && \
  370. ((_Name_)[0] == L'\\' ) && \
  371. ((_Name_)[1] == L'\\')) { \
  372. (_Name_) += 2; \
  373. }
  374. DWORD
  375. FrsRpcBindToServer(
  376. IN PGNAME Name,
  377. IN PWCHAR PrincName,
  378. IN ULONG AuthLevel,
  379. OUT handle_t *Handle
  380. );
  381. BOOL
  382. FrsRpcInitialize(
  383. VOID
  384. );
  385. VOID
  386. FrsRpcUnInitialize(
  387. VOID
  388. );
  389. VOID
  390. FrsRpcUnBindFromServer(
  391. handle_t *Handle
  392. );
  393. //
  394. // FRS threads
  395. //
  396. #if DBG
  397. DWORD
  398. FrsTest(
  399. PVOID
  400. );
  401. #endif DBG
  402. //
  403. // FRS Thread Management Support
  404. //
  405. VOID
  406. ThSupSubmitThreadExitCleanup(
  407. PFRS_THREAD
  408. );
  409. VOID
  410. ThSupInitialize(
  411. VOID
  412. );
  413. DWORD
  414. ThSupExitThreadGroup(
  415. DWORD (*)(PVOID)
  416. );
  417. VOID
  418. ThSupExitSingleThread(
  419. PFRS_THREAD
  420. );
  421. DWORD
  422. ThSupWaitThread(
  423. PFRS_THREAD FrsThread,
  424. DWORD Millisec
  425. );
  426. PVOID
  427. ThSupGetThreadData(
  428. PFRS_THREAD
  429. );
  430. PFRS_THREAD
  431. ThSupGetThread(
  432. DWORD (*)(PVOID)
  433. );
  434. VOID
  435. ThSupReleaseRef(
  436. PFRS_THREAD
  437. );
  438. BOOL
  439. ThSupCreateThread(
  440. PWCHAR Name,
  441. PVOID Param,
  442. DWORD (*Main)(PVOID),
  443. DWORD (*Exit)(PVOID)
  444. );
  445. DWORD
  446. ThSupExitThreadNOP(
  447. PVOID
  448. );
  449. DWORD
  450. ThSupExitWithTombstone(
  451. PVOID
  452. );
  453. //
  454. // shutdown functions called by ShutDown()
  455. //
  456. extern VOID ShutDownRpc(VOID); // Cleanup after StartRpc thread
  457. //
  458. // Globals
  459. //
  460. extern WCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 2]; // A useful piece of info
  461. extern PWCHAR ComputerDnsName; // A useful piece of info
  462. //
  463. // Service functions
  464. //
  465. DWORD
  466. FrsGetServiceState(
  467. PWCHAR,
  468. PWCHAR
  469. );
  470. BOOL
  471. FrsWaitService(
  472. PWCHAR,
  473. PWCHAR,
  474. INT,
  475. INT
  476. );
  477. BOOL
  478. FrsIsServiceRunning(
  479. PWCHAR,
  480. PWCHAR
  481. );
  482. DWORD
  483. FrsSetServiceStatus(
  484. IN DWORD Status,
  485. IN DWORD CheckPoint,
  486. IN DWORD Hint,
  487. IN DWORD ExitCode
  488. );
  489. //
  490. // FRS Version Vector
  491. //
  492. #define LOCK_GEN_TABLE(_vv_) \
  493. GTabLockTable(_vv_); \
  494. DPRINT1(5, "LOCK_GEN_TABLE: "#_vv_":%08x\n", _vv_);
  495. #define UNLOCK_GEN_TABLE(_vv_) \
  496. DPRINT1(5, "UNLOCK_GEN_TABLE: "#_vv_":%08x\n", _vv_); \
  497. GTabUnLockTable(_vv_);
  498. PGEN_TABLE
  499. VVDupOutbound(
  500. IN PGEN_TABLE VV
  501. );
  502. ULONG
  503. VVReserveRetireSlot(
  504. IN PREPLICA Replica,
  505. IN PCHANGE_ORDER_ENTRY Coe
  506. );
  507. ULONG
  508. VVRetireChangeOrder(
  509. IN PTHREAD_CTX ThreadCtx,
  510. IN PREPLICA Replica,
  511. IN PCHANGE_ORDER_ENTRY ChangeOrder,
  512. IN ULONG CleanUpFlags
  513. );
  514. PCHANGE_ORDER_ENTRY
  515. VVReferenceRetireSlot(
  516. IN PREPLICA Replica,
  517. IN PCHANGE_ORDER_COMMAND CoCmd
  518. );
  519. VOID
  520. VVUpdate(
  521. IN PGEN_TABLE VV,
  522. IN ULONGLONG Vsn,
  523. IN GUID *Guid
  524. );
  525. VOID
  526. VVInsertOutbound(
  527. IN PGEN_TABLE VV,
  528. IN PGVSN GVsn
  529. );
  530. VOID
  531. VVUpdateOutbound(
  532. IN PGEN_TABLE VV,
  533. IN PGVSN GVsn
  534. );
  535. BOOL
  536. VVHasVsnNoLock(
  537. IN PGEN_TABLE VV,
  538. IN GUID *OriginatorGuid,
  539. IN ULONGLONG Vsn
  540. );
  541. BOOL
  542. VVHasOriginatorNoLock(
  543. IN PGEN_TABLE VV,
  544. IN GUID *OriginatorGuid
  545. );
  546. BOOL
  547. VVHasVsn(
  548. IN PGEN_TABLE VV,
  549. IN PCHANGE_ORDER_COMMAND Coc
  550. );
  551. PGVSN
  552. VVGetGVsn(
  553. IN PGEN_TABLE VV,
  554. IN GUID *Guid
  555. );
  556. PVOID
  557. VVFreeOutbound(
  558. IN PGEN_TABLE VV
  559. );
  560. VOID
  561. VVFree(
  562. IN PGEN_TABLE VV
  563. );
  564. #if DBG
  565. #define VV_PRINT(_Severity_, _Header_, _VV_) \
  566. DPRINT1(_Severity_, "++ VV_PRINT :%08x\n", _VV_); \
  567. VVPrint(_Severity_, _Header_, _VV_, FALSE)
  568. #define VV_PRINT_OUTBOUND(_Severity_, _Header_, _VV_) \
  569. DPRINT1(_Severity_, "++ VV_PRINT_OUTBOUND :%08x\n", _VV_); \
  570. VVPrint(_Severity_, _Header_, _VV_, TRUE)
  571. VOID
  572. VVPrint(
  573. IN ULONG Severity,
  574. IN PWCHAR Header,
  575. IN PGEN_TABLE VV,
  576. IN BOOL IsOutbound
  577. );
  578. #else DBG
  579. #define VV_PRINT(_Severity_, _Header_, _VV_)
  580. #define VV_PRINT_OUTBOUND(_Severity_, _Header_, _VV_)
  581. #endif DBG
  582. //
  583. // FRS Generic Table Routines
  584. //
  585. PGEN_TABLE
  586. GTabAllocTable(
  587. VOID
  588. );
  589. PGEN_TABLE
  590. GTabAllocNumberTable(
  591. VOID
  592. );
  593. PGEN_TABLE
  594. GTabAllocStringTable(
  595. VOID
  596. );
  597. PGEN_TABLE
  598. GTabAllocStringAndBoolTable(
  599. VOID
  600. );
  601. VOID
  602. GTabEmptyTableNoLock(
  603. IN PGEN_TABLE GTable,
  604. IN PVOID (*CallerFree)(PVOID)
  605. );
  606. VOID
  607. GTabEmptyTable(
  608. IN PGEN_TABLE GTable,
  609. IN PVOID (*CallerFree)(PVOID)
  610. );
  611. PVOID
  612. GTabFreeTable(
  613. PGEN_TABLE,
  614. PVOID (*)(PVOID)
  615. );
  616. PVOID
  617. GTabLookup(
  618. PGEN_TABLE,
  619. PVOID,
  620. PWCHAR
  621. );
  622. BOOL
  623. GTabIsEntryPresent(
  624. IN PGEN_TABLE GTable,
  625. IN GUID *Key1,
  626. IN PWCHAR Key2
  627. );
  628. PVOID
  629. GTabLookupTableString(
  630. IN PGEN_TABLE GTable,
  631. IN PWCHAR Key1,
  632. IN PWCHAR Key2
  633. );
  634. PVOID
  635. GTabLookupNoLock(
  636. PGEN_TABLE,
  637. PVOID,
  638. PWCHAR
  639. );
  640. PGEN_ENTRY
  641. GTabLookupEntryNoLock(
  642. PGEN_TABLE,
  643. PVOID,
  644. PWCHAR
  645. );
  646. PGEN_ENTRY
  647. GTabNextEntryNoLock(
  648. PGEN_TABLE,
  649. PVOID
  650. );
  651. PVOID
  652. GTabNextDatumNoLock(
  653. IN PGEN_TABLE GTable,
  654. IN PVOID *Key
  655. );
  656. PVOID
  657. GTabNextDatum(
  658. PGEN_TABLE,
  659. PVOID
  660. );
  661. DWORD
  662. GTabNumberInTable(
  663. PGEN_TABLE
  664. );
  665. VOID
  666. GTabLockTable(
  667. PGEN_TABLE
  668. );
  669. VOID
  670. GTabUnLockTable(
  671. PGEN_TABLE
  672. );
  673. PVOID
  674. GTabInsertUniqueEntry(
  675. IN PGEN_TABLE GTable,
  676. IN PVOID NewData,
  677. IN PVOID Key1,
  678. IN PVOID Key2
  679. );
  680. VOID
  681. GTabInsertEntry(
  682. PGEN_TABLE,
  683. PVOID,
  684. PVOID,
  685. PWCHAR
  686. );
  687. VOID
  688. GTabInsertEntryNoLock(
  689. IN PGEN_TABLE GTable,
  690. IN PVOID NewData,
  691. IN PVOID Key1,
  692. IN PWCHAR Key2
  693. );
  694. VOID
  695. GTabDelete(
  696. PGEN_TABLE,
  697. PVOID,
  698. PWCHAR,
  699. PVOID (*)(PVOID)
  700. );
  701. VOID
  702. GTabDeleteNoLock(
  703. PGEN_TABLE,
  704. PVOID,
  705. PWCHAR,
  706. PVOID (*)(PVOID)
  707. );
  708. VOID
  709. GTabPrintTable(
  710. PGEN_TABLE
  711. );
  712. //
  713. // GNAME
  714. //
  715. PVOID
  716. FrsFreeGName(
  717. PVOID
  718. );
  719. PGNAME
  720. FrsBuildGName(
  721. GUID *,
  722. PWCHAR
  723. );
  724. PGVSN
  725. FrsBuildGVsn(
  726. GUID *,
  727. ULONGLONG
  728. );
  729. PGNAME
  730. FrsCopyGName(
  731. GUID *,
  732. PWCHAR
  733. );
  734. PGNAME
  735. FrsDupGName(
  736. PGNAME
  737. );
  738. VOID
  739. FrsPrintGName(
  740. PGNAME
  741. );
  742. VOID
  743. FrsPrintGuid(
  744. GUID *
  745. );
  746. GUID *
  747. FrsDupGuid(
  748. GUID *
  749. );
  750. //
  751. // FRS REPLICA COMMAND SERVER
  752. //
  753. #define FRS_CO_COMM_PROGRESS(_sev, _cmd, _sn, _partner, _text) \
  754. DPRINT7(_sev, ":: CoG %08x, CxtG %08x, Sn %5d, vsn %08x %08x, FN: %-15ws, [%s], %ws\n", \
  755. (_cmd)->ChangeOrderGuid.Data1, \
  756. (_cmd)->CxtionGuid.Data1, \
  757. (_sn), \
  758. PRINTQUAD((_cmd)->FrsVsn), \
  759. (_cmd)->FileName, \
  760. (_text), \
  761. (_partner));
  762. #define FRS_CO_FILE_PROGRESS(_F_, _V_, _M_) \
  763. DPRINT3(0, ":V: %-11ws (%08x): %s\n", _F_, (ULONG)(_V_), _M_);
  764. #define FRS_CO_FILE_PROGRESS_WSTATUS(_F_, _V_, _M_, _W_) \
  765. DPRINT4(0, ":V: %-11ws (%08x): %s (%d)\n", _F_, (ULONG)(_V_), _M_, _W_);
  766. VOID
  767. RcsInitializeReplicaCmdServer(
  768. VOID
  769. );
  770. VOID
  771. RcsFrsUnInitializeReplicaCmdServer(
  772. VOID
  773. );
  774. VOID
  775. RcsShutDownReplicaCmdServer(
  776. VOID
  777. );
  778. PREPLICA
  779. RcsFindReplicaByNumber(
  780. IN ULONG ReplicaNumber
  781. );
  782. PREPLICA
  783. RcsFindReplicaByGuid(
  784. IN GUID *Guid
  785. );
  786. PREPLICA
  787. RcsFindReplicaById(
  788. IN ULONG Id
  789. );
  790. PREPLICA
  791. RcsFindSysVolByName(
  792. IN PWCHAR ReplicaSetName
  793. );
  794. PREPLICA
  795. RcsFindSysVolByType(
  796. IN DWORD ReplicaSetType
  797. );
  798. PREPLICA
  799. RcsFindNextReplica(
  800. IN PVOID *Key
  801. );
  802. VOID
  803. RcsSubmitReplicaCxtion(
  804. IN PREPLICA Replica,
  805. IN PCXTION Cxtion,
  806. IN USHORT Command
  807. );
  808. DWORD
  809. RcsSubmitReplicaSync(
  810. IN PREPLICA Replica,
  811. IN PREPLICA NewReplica, OPTIONAL
  812. IN PCXTION VolatileCxtion, OPTIONAL
  813. IN USHORT Command
  814. );
  815. VOID
  816. RcsSubmitReplica(
  817. IN PREPLICA Replica,
  818. IN PREPLICA NewReplica, OPTIONAL
  819. IN USHORT Command
  820. );
  821. DWORD
  822. RcsCreateReplicaSetMember(
  823. IN PREPLICA Replica
  824. );
  825. VOID
  826. RcsMergeReplicaFromDs(
  827. IN PREPLICA Replica
  828. );
  829. VOID
  830. RcsBeginMergeWithDs(
  831. VOID
  832. );
  833. VOID
  834. RcsEndMergeWithDs(
  835. VOID
  836. );
  837. ULONG
  838. RcsSubmitCommPktWithErrorToRcs(
  839. IN PCOMM_PACKET CommPkt
  840. );
  841. VOID
  842. RcsSubmitTransferToRcs(
  843. IN PCOMMAND_PACKET Cmd,
  844. IN USHORT Command
  845. );
  846. VOID
  847. RcsCmdPktCompletionRoutine(
  848. IN PCOMMAND_PACKET Cmd,
  849. IN PVOID Arg
  850. );
  851. VOID
  852. RcsSubmitRemoteCoInstallRetry(
  853. IN PCHANGE_ORDER_ENTRY Coe
  854. );
  855. VOID
  856. RcsSubmitRemoteCoAccepted(
  857. IN PCHANGE_ORDER_ENTRY Coe
  858. );
  859. VOID
  860. RcsSubmitLocalCoAccepted(
  861. IN PCHANGE_ORDER_ENTRY Coe
  862. );
  863. VOID
  864. RcsInboundCommitOk(
  865. IN PREPLICA Replica,
  866. IN PCHANGE_ORDER_ENTRY Coe
  867. );
  868. BOOL
  869. RcsSendCoToOneOutbound(
  870. IN PREPLICA Replica,
  871. IN PCXTION Cxtion,
  872. IN PCHANGE_ORDER_COMMAND Coc
  873. );
  874. //
  875. // FRS COMMAND SERVER
  876. //
  877. VOID
  878. FrsSubmitCommandServer(
  879. PCOMMAND_SERVER,
  880. PCOMMAND_PACKET
  881. );
  882. ULONG
  883. FrsSubmitCommandServerAndWait(
  884. IN PCOMMAND_SERVER Cs,
  885. IN PCOMMAND_PACKET Cmd,
  886. IN ULONG Timeout
  887. );
  888. VOID
  889. FrsKickCommandServer(
  890. PCOMMAND_SERVER
  891. );
  892. PCOMMAND_PACKET
  893. FrsGetCommandServer(
  894. PCOMMAND_SERVER
  895. );
  896. PCOMMAND_PACKET
  897. FrsGetCommandServerIdled(
  898. IN PCOMMAND_SERVER,
  899. OUT PFRS_QUEUE *
  900. );
  901. PCOMMAND_PACKET
  902. FrsGetCommandServerTimeout(
  903. IN PCOMMAND_SERVER,
  904. IN ULONG,
  905. OUT PBOOL
  906. );
  907. PCOMMAND_PACKET
  908. FrsGetCommandServerTimeoutIdled(
  909. IN PCOMMAND_SERVER,
  910. IN ULONG,
  911. OUT PFRS_QUEUE *,
  912. OUT PBOOL
  913. );
  914. DWORD
  915. FrsWaitForCommandServer(
  916. PCOMMAND_SERVER,
  917. DWORD
  918. );
  919. VOID
  920. FrsExitCommandServer(
  921. PCOMMAND_SERVER,
  922. PFRS_THREAD
  923. );
  924. VOID
  925. FrsRunDownCommandServer(
  926. PCOMMAND_SERVER,
  927. PFRS_QUEUE
  928. );
  929. VOID
  930. FrsCancelCommandServer(
  931. PCOMMAND_SERVER,
  932. PFRS_QUEUE
  933. );
  934. VOID
  935. FrsInitializeCommandServer(
  936. PCOMMAND_SERVER,
  937. DWORD,
  938. PWCHAR,
  939. DWORD (*)(PVOID)
  940. );
  941. VOID
  942. FrsDeleteCommandServer(
  943. PCOMMAND_SERVER
  944. );
  945. //
  946. // FRS STAGING FILE GENERATOR SERVER
  947. //
  948. VOID
  949. ShutDownStageCs(
  950. VOID
  951. );
  952. VOID
  953. FrsStageCsInitialize(
  954. VOID
  955. );
  956. VOID
  957. FrsStageCsUnInitialize(
  958. VOID
  959. );
  960. VOID
  961. FrsStageCsSubmitTransfer(
  962. IN PCOMMAND_PACKET,
  963. IN USHORT
  964. );
  965. BOOL
  966. StageDeleteFile(
  967. IN PCHANGE_ORDER_COMMAND Coc,
  968. IN BOOL Acquire
  969. );
  970. DWORD
  971. StageAcquire(
  972. IN GUID *ChangeOrderGuid,
  973. IN PWCHAR Name,
  974. IN ULONGLONG FileSize,
  975. IN OUT PULONG Flags,
  976. OUT GUID *CompressionFormatUsed
  977. );
  978. VOID
  979. StageRelease(
  980. IN GUID *ChangeOrderGuid,
  981. IN PWCHAR Name,
  982. IN ULONG Flags,
  983. IN PULONGLONG SizeOfFileGenerated,
  984. OUT GUID *CompressionFormatUsed
  985. );
  986. VOID
  987. StageReleaseNotRecovered(
  988. );
  989. VOID
  990. StageReleaseAll(
  991. );
  992. BOOL
  993. FrsDoesCoAlterNameSpace(
  994. IN PCHANGE_ORDER_COMMAND Coc
  995. );
  996. BOOL
  997. FrsDoesCoNeedStage(
  998. IN PCHANGE_ORDER_COMMAND Coc
  999. );
  1000. DWORD
  1001. FrsVerifyVolume(
  1002. IN PWCHAR Name,
  1003. IN PWCHAR SetName,
  1004. IN ULONG Flags
  1005. );
  1006. DWORD
  1007. FrsDoesDirectoryExist(
  1008. IN PWCHAR Name,
  1009. OUT PDWORD pAttributes
  1010. );
  1011. DWORD
  1012. FrsCheckForNoReparsePoint(
  1013. IN PWCHAR Name
  1014. );
  1015. DWORD
  1016. FrsDoesFileExist(
  1017. IN PWCHAR Name
  1018. );
  1019. DWORD
  1020. FrsCreateDirectory(
  1021. IN PWCHAR
  1022. );
  1023. DWORD
  1024. StuCreateFile(
  1025. IN PWCHAR,
  1026. OUT PHANDLE
  1027. );
  1028. DWORD
  1029. FrsDeleteFile(
  1030. IN PWCHAR
  1031. );
  1032. DWORD
  1033. StuWriteFile(
  1034. IN PWCHAR,
  1035. IN HANDLE,
  1036. IN PVOID,
  1037. IN DWORD
  1038. );
  1039. DWORD
  1040. StuReadFile(
  1041. IN PWCHAR,
  1042. IN HANDLE,
  1043. IN PVOID,
  1044. IN DWORD,
  1045. IN PULONG
  1046. );
  1047. BOOL
  1048. StuReadBlockFile(
  1049. IN PWCHAR,
  1050. IN HANDLE,
  1051. IN PVOID,
  1052. IN DWORD
  1053. );
  1054. DWORD
  1055. FrsSetCompression(
  1056. IN PWCHAR,
  1057. IN HANDLE,
  1058. IN USHORT
  1059. );
  1060. DWORD
  1061. FrsGetCompression(
  1062. IN PWCHAR,
  1063. IN HANDLE,
  1064. IN PUSHORT
  1065. );
  1066. DWORD
  1067. FrsSetFilePointer(
  1068. IN PWCHAR,
  1069. IN HANDLE,
  1070. IN ULONG,
  1071. IN ULONG
  1072. );
  1073. DWORD
  1074. FrsSetFileTime(
  1075. IN PWCHAR,
  1076. IN HANDLE,
  1077. IN FILETIME *,
  1078. IN FILETIME *,
  1079. IN FILETIME *
  1080. );
  1081. DWORD
  1082. FrsSetEndOfFile(
  1083. IN PWCHAR,
  1084. IN HANDLE
  1085. );
  1086. BOOL
  1087. FrsGetFileInfoByHandle(
  1088. IN PWCHAR,
  1089. IN HANDLE,
  1090. OUT PFILE_NETWORK_OPEN_INFORMATION
  1091. );
  1092. DWORD
  1093. FrsFlushFile(
  1094. IN PWCHAR,
  1095. IN HANDLE
  1096. );
  1097. DWORD
  1098. StuOpenFile(
  1099. IN PWCHAR,
  1100. IN DWORD,
  1101. OUT PHANDLE
  1102. );
  1103. DWORD
  1104. FrsSetFileAttributes(
  1105. IN PWCHAR,
  1106. IN HANDLE,
  1107. IN ULONG
  1108. );
  1109. BOOL
  1110. FrsCreateStageName(
  1111. IN GUID *,
  1112. OUT PWCHAR *
  1113. );
  1114. PWCHAR
  1115. StuCreStgPath(
  1116. IN PWCHAR,
  1117. IN GUID *,
  1118. IN PWCHAR
  1119. );
  1120. DWORD
  1121. StuInstallRename(
  1122. IN PCHANGE_ORDER_ENTRY,
  1123. IN BOOL,
  1124. IN BOOL
  1125. );
  1126. ULONG
  1127. StuInstallStage(
  1128. IN PCHANGE_ORDER_ENTRY
  1129. );
  1130. //
  1131. // FRS STAGING FILE FETCHER SERVER
  1132. //
  1133. VOID
  1134. ShutDownFetchCs(
  1135. VOID
  1136. );
  1137. VOID
  1138. FrsFetchCsInitialize(
  1139. VOID
  1140. );
  1141. VOID
  1142. FrsFetchCsSubmitTransfer(
  1143. PCOMMAND_PACKET,
  1144. USHORT
  1145. );
  1146. //
  1147. // FRS STAGING FILE INSTALLER SERVER
  1148. //
  1149. VOID
  1150. ShutDownInstallCs(
  1151. VOID
  1152. );
  1153. VOID
  1154. FrsInstallCsInitialize(
  1155. VOID
  1156. );
  1157. VOID
  1158. FrsInstallCsSubmitTransfer(
  1159. PCOMMAND_PACKET,
  1160. USHORT
  1161. );
  1162. //
  1163. // FRS INITIAL SYNC COOMMAND SERVER
  1164. //
  1165. VOID
  1166. ShutDownInitSyncCs(
  1167. VOID
  1168. );
  1169. VOID
  1170. InitSyncCsInitialize(
  1171. VOID
  1172. );
  1173. VOID
  1174. InitSyncCsSubmitTransfer(
  1175. PCOMMAND_PACKET,
  1176. USHORT
  1177. );
  1178. VOID
  1179. InitSyncSubmitToInitSyncCs(
  1180. IN PREPLICA Replica,
  1181. IN USHORT Command
  1182. );
  1183. //
  1184. // FRS DELAYED SERVER
  1185. //
  1186. VOID
  1187. FrsDelCsSubmitSubmit(
  1188. PCOMMAND_SERVER,
  1189. PCOMMAND_PACKET,
  1190. ULONG
  1191. );
  1192. VOID
  1193. FrsDelQueueSubmit(
  1194. IN PCOMMAND_PACKET DelCmd,
  1195. IN ULONG Timeout
  1196. );
  1197. VOID
  1198. FrsDelCsSubmitUnIdled(
  1199. PCOMMAND_SERVER,
  1200. PFRS_QUEUE,
  1201. ULONG
  1202. );
  1203. VOID
  1204. FrsDelCsSubmitKick(
  1205. PCOMMAND_SERVER,
  1206. PFRS_QUEUE,
  1207. ULONG
  1208. );
  1209. VOID
  1210. ShutDownDelCs(
  1211. VOID
  1212. );
  1213. VOID
  1214. FrsDelCsInitialize(
  1215. VOID
  1216. );
  1217. //
  1218. // FRS COMM SUBSYSTEM
  1219. //
  1220. BOOL
  1221. CommCheckPkt(
  1222. PCOMM_PACKET
  1223. );
  1224. VOID
  1225. CommDumpCommPkt(
  1226. PCOMM_PACKET,
  1227. DWORD
  1228. );
  1229. //
  1230. // FRS utilities
  1231. //
  1232. DWORD
  1233. FrsForceOpenId(
  1234. OUT PHANDLE Handle,
  1235. OUT OVERLAPPED *OpLock,
  1236. IN PVOLUME_MONITOR_ENTRY pVme,
  1237. IN PVOID Id,
  1238. IN DWORD IdLen,
  1239. IN ACCESS_MASK DesiredAccess,
  1240. IN ULONG CreateOptions,
  1241. IN ULONG ShareMode,
  1242. IN ULONG CreateDispostion
  1243. );
  1244. DWORD
  1245. FrsRenameByHandle(
  1246. IN PWCHAR Name,
  1247. IN ULONG NameLen,
  1248. IN HANDLE Handle,
  1249. IN HANDLE TargetHandle,
  1250. IN BOOL ReplicaIfExists
  1251. );
  1252. DWORD
  1253. FrsDeleteByHandle(
  1254. IN PWCHAR Name,
  1255. IN HANDLE Handle
  1256. );
  1257. DWORD
  1258. FrsCheckObjectId(
  1259. IN PWCHAR Name,
  1260. IN HANDLE Handle,
  1261. IN GUID *Guid
  1262. );
  1263. DWORD
  1264. FrsOpenBaseNameForInstall(
  1265. IN PCHANGE_ORDER_ENTRY Coe,
  1266. OUT HANDLE *Handle
  1267. );
  1268. DWORD
  1269. FrsGetObjectId(
  1270. IN HANDLE Handle,
  1271. OUT PFILE_OBJECTID_BUFFER ObjectIdBuffer
  1272. );
  1273. #define GENERIC_PREFIX L"NTFRS_"
  1274. #define STAGE_FINAL_PREFIX GENERIC_PREFIX
  1275. #define STAGE_FINAL_COMPRESSED_PREFIX L"NTFRS_CMP_"
  1276. #define PRE_INSTALL_PREFIX GENERIC_PREFIX
  1277. #define STAGE_GENERATE_PREFIX L"NTFRS_G_"
  1278. #define STAGE_GENERATE_COMPRESSED_PREFIX L"NTFRS_G_CMP_"
  1279. PWCHAR
  1280. FrsCreateGuidName(
  1281. IN GUID *Guid,
  1282. IN PWCHAR Prefix
  1283. );
  1284. //
  1285. // MISC
  1286. //
  1287. VOID
  1288. FrsDsSwapPtrs(
  1289. PVOID *,
  1290. PVOID *
  1291. );
  1292. #if DBG
  1293. #define INITIALIZE_HARD_WIRED() FrsDsInitializeHardWired()
  1294. VOID
  1295. FrsDsInitializeHardWired(
  1296. VOID
  1297. );
  1298. #else DBG
  1299. #define INITIALIZE_HARD_WIRED()
  1300. #endif DBG
  1301. //
  1302. // Outbound Log Processor
  1303. //
  1304. ULONG
  1305. OutLogSubmit(
  1306. IN PREPLICA Replica,
  1307. IN PCXTION Cxtion,
  1308. IN USHORT Command
  1309. );
  1310. //
  1311. // Database
  1312. //
  1313. JET_ERR
  1314. DbsUpdateTable(
  1315. IN PTABLE_CTX TableCtx
  1316. );
  1317. ULONG
  1318. DbsPackSchedule(
  1319. IN PSCHEDULE Schedule,
  1320. IN ULONG Fieldx,
  1321. IN PTABLE_CTX TableCtx
  1322. );
  1323. ULONG
  1324. DbsPackStrW(
  1325. IN PWCHAR StrW,
  1326. IN ULONG Fieldx,
  1327. IN PTABLE_CTX TableCtx
  1328. );
  1329. ULONG
  1330. DbsUnPackStrW(
  1331. OUT PWCHAR *StrW,
  1332. IN ULONG Fieldx,
  1333. IN PTABLE_CTX TableCtx
  1334. );
  1335. //
  1336. // The subsystem commands below apply to an entire subsystem, e.g. the
  1337. // journal. Some of the commands may not apply to a subsystem.
  1338. // The service level commands are the means to tell a subsystem that you
  1339. // want the subsystem to provide/perform a given service. For example
  1340. // a PREPARE_SERVICE command sent to the Journal subsystem tells the
  1341. // journal to initialize journalling for a specified replica set. Multiple
  1342. // prepare service commands are sent when the FRS first starts up. They are
  1343. // then followed by a START_SUBSYSTEM command. This way the journal knows
  1344. // to start processing the USN journal on a gvien volume at the lowest
  1345. // CommitUsn point for ANY replica set hosted by the volume.
  1346. //
  1347. // Some commands may not be implemented by all subsystems. For example
  1348. // the PAUSE_SERVICE command is not provided for a single replica set
  1349. // as long as the FRS is running because we have to continuously monitor
  1350. // the journal so as not to lose data. Some subsystems may not have any
  1351. // service level commands.
  1352. //
  1353. #define CMD_COMMAND_ERROR 0x00
  1354. #define CMD_INIT_SUBSYSTEM 0x01
  1355. #define CMD_START_SUBSYSTEM 0x02
  1356. #define CMD_STOP_SUBSYSTEM 0x03
  1357. #define CMD_PAUSE_SUBSYSTEM 0x04
  1358. #define CMD_QUERY_INFO_SUBSYSTEM 0x05
  1359. #define CMD_SET_CONFIG_SUBSYSTEM 0x06
  1360. #define CMD_QUERY_CONFIG_SUBSYSTEM 0x07
  1361. #define CMD_CANCEL_COMMAND_SUBSYSTEM 0x08
  1362. #define CMD_READ_SUBSYSTEM 0x09
  1363. #define CMD_WRITE_SUBSYSTEM 0x0A
  1364. #define CMD_PREPARE_SERVICE1 0x21
  1365. #define CMD_PREPARE_SERVICE2 0x22
  1366. #define CMD_START_SERVICE 0x23
  1367. #define CMD_STOP_SERVICE 0x24
  1368. #define CMD_PAUSE_SERVICE 0x25
  1369. #define CMD_QUERY_INFO_SERVICE 0x26
  1370. #define CMD_SET_CONFIG_SERVICE 0x27
  1371. #define CMD_QUERY_CONFIG_SERVICE 0x28
  1372. #define CMD_CANCEL_COMMAND_SERVICE 0x29
  1373. #define CMD_READ_SERVICE 0x2A
  1374. #define CMD_WRITE_SERVICE 0x2B
  1375. #define CMD_RESYNC_SERVICE 0x2C
  1376. #define CMD_VERIFY_SERVICE 0x2D
  1377. extern FRS_QUEUE JournalProcessQueue;
  1378. extern FRS_QUEUE DBServiceProcessQueue;
  1379. //
  1380. // Service UNIQUE Commands start at 0x100 for each service.
  1381. //
  1382. /***********************************************************
  1383. * *
  1384. * Commands specific to the Journal service. *
  1385. * *
  1386. ***********************************************************/
  1387. // sequence break
  1388. #define CMD_JOURNAL_PAUSED 0x101
  1389. #define CMD_JOURNAL_INIT_ONE_RS 0x102
  1390. #define CMD_JOURNAL_DELETE_DIR_FILTER_ENTRY 0x103
  1391. #define CMD_JOURNAL_CLEAN_WRITE_FILTER 0x104
  1392. /***********************************************************
  1393. * *
  1394. * Commands specific to the Database service. *
  1395. * *
  1396. ***********************************************************/
  1397. // sequence break
  1398. #define CMD_CLOSE_TABLE 0x101
  1399. #define CMD_UPDATE_RECORD_FIELDS 0x102
  1400. #define CMD_UPDATE_TABLE_RECORD 0x103
  1401. #define CMD_INSERT_TABLE_RECORD 0x104
  1402. #define CMD_READ_TABLE_RECORD 0x105
  1403. #define CMD_CREATE_REPLICA_SET_MEMBER 0x106
  1404. #define CMD_OPEN_REPLICA_SET_MEMBER 0x107
  1405. #define CMD_CLOSE_REPLICA_SET_MEMBER 0x108
  1406. #define CMD_LOAD_REPLICA_FILE_TREE 0x109
  1407. #define CMD_DELETE_REPLICA_SET_MEMBER 0x10A
  1408. #define CMD_DELETE_TABLE_RECORD 0x10B
  1409. #define CMD_CREATE_START_NEW_MEMBER 0x10C
  1410. #define CMD_LOAD_ONE_REPLICA_FILE_TREE 0x10D
  1411. #define CMD_STOP_REPLICATION_SINGLE_REPLICA 0x10E
  1412. #define CMD_DBS_RETIRE_INBOUND_CO 0x10F
  1413. #define CMD_DBS_RETRY_INBOUND_CO 0x110
  1414. #define CMD_DBS_RETIRE_REJECTED_CO 0x111
  1415. #define CMD_UPDATE_REPLICA_SET_MEMBER 0x112
  1416. #define CMD_DBS_REPLICA_SAVE_MARK 0x113
  1417. #define CMD_DBS_INJECT_OUTBOUND_CO 0x114
  1418. #define CMD_DBS_REPLICA_SERVICE_STATE_SAVE 0x115
  1419. //
  1420. // Given a ptr to a DB_SERVICE_REQUEST return the ptr to the data record.
  1421. //
  1422. #define DBS_GET_RECORD_ADDRESS(_DbsRequest) \
  1423. ((_DbsRequest)->TableCtx->pDataRecord)
  1424. #define DBS_GET_TABLECTX(_DbsRequest) \
  1425. ((_DbsRequest)->TableCtx)
  1426. #define DBS_FREE_TABLECTX(_DbsRequest) \
  1427. DbsFreeTableCtx((_DbsRequest)->TableCtx, COMMAND_PACKET_TYPE); \
  1428. (_DbsRequest)->TableCtx = FrsFree((_DbsRequest)->TableCtx);
  1429. //
  1430. // The following access macros assume that the field buffers used for the record
  1431. // read and write operations are the same. That is that both the Jet Set and
  1432. // Ret structs point to the same buffer. They each take a table ctx parameter
  1433. // and a record field ID code (defined as an ENUM in schema.h).
  1434. //
  1435. // Get the field's receive buffer length.
  1436. #define DBS_GET_FIELD_SIZE(_TableCtx, _Field) \
  1437. ((_TableCtx)->pJetRetCol[_Field].cbActual)
  1438. // Get the field's maximum buffer length.
  1439. #define DBS_GET_FIELD_SIZE_MAX( _TableCtx, _Field) \
  1440. ((_TableCtx)->pJetRetCol[_Field].cbData)
  1441. // Get the address of the field's buffer.
  1442. #define DBS_GET_FIELD_ADDRESS( _TableCtx, _Field) \
  1443. ((_TableCtx)->pJetRetCol[_Field].pvData)
  1444. //
  1445. // Set the size of the data in the field buffer.
  1446. // Warning - Don't do this on fixed size fields.
  1447. //
  1448. #define DBS_SET_FIELD_SIZE(_TableCtx, _Field, _NewSize) \
  1449. (_TableCtx)->pJetRetCol[_Field].cbActual = _NewSize; \
  1450. (_TableCtx)->pJetSetCol[_Field].cbData = _NewSize;
  1451. //
  1452. // Set the maximum size of the field buffer.
  1453. // Warning - Don't do this on fixed size fields.
  1454. // Warning - ONLY USE IF YOU KNOW WHAT YOU'RE DOING OTHERWISE USE DBS_REALLOC_FIELD
  1455. //
  1456. #define DBS_SET_FIELD_SIZE_MAX(_TableCtx, _Field, _NewSize) \
  1457. (_TableCtx)->pJetRetCol[_Field].cbData = _NewSize;
  1458. // Set the address of the field's buffer. It doesn't update the ptr in base record.
  1459. // Warning - Don't do this on fixed size fields.
  1460. // Warning - ONLY USE IF YOU KNOW WHAT YOU'RE DOING OTHERWISE USE DBS_REALLOC_FIELD
  1461. #define DBS_SET_FIELD_ADDRESS( _TableCtx, _Field, _NewAddr) \
  1462. (_TableCtx)->pJetRetCol[_Field].pvData = _NewAddr; \
  1463. (_TableCtx)->pJetSetCol[_Field].pvData = _NewAddr;
  1464. //
  1465. // Reallocate the buffer size for a variable length binary field.
  1466. // Set _NewSize to zero to delete the buffer.
  1467. // Set _KeepData to TRUE if you want to copy the data from the old buffer to the new.
  1468. // This function also updates the buffer pointer in the base record.
  1469. //
  1470. #define DBS_REALLOC_FIELD(_TableCtx, _FieldIndex, _NewSize, _KeepData) \
  1471. DbsTranslateJetError(DbsReallocateFieldBuffer(_TableCtx, \
  1472. _FieldIndex, \
  1473. _NewSize, \
  1474. _KeepData), TRUE)
  1475. #define DBS_ACCESS_BYKEY 0
  1476. #define DBS_ACCESS_FIRST 1
  1477. #define DBS_ACCESS_LAST 2
  1478. #define DBS_ACCESS_NEXT 3
  1479. #define DBS_ACCESS_MASK (0xF)
  1480. //
  1481. // If set the close the table after completing the operation.
  1482. //
  1483. #define DBS_ACCESS_CLOSE (0x80000000)
  1484. //
  1485. // If set then free the table context struct and the data record struct
  1486. // after completing the operation. Useful on record inserts and the table
  1487. // close command. (CMD_CLOSE_TABLE)
  1488. //
  1489. #define DBS_ACCESS_FREE_TABLECTX (0x40000000)
  1490. /***********************************************************
  1491. * *
  1492. * Commands specific to the Outbound Log subsystem. *
  1493. * *
  1494. ***********************************************************/
  1495. // sequence break
  1496. #define CMD_OUTLOG_WORK_CO 0x100
  1497. #define CMD_OUTLOG_ADD_REPLICA 0x101
  1498. #define CMD_OUTLOG_REMOVE_REPLICA 0x102
  1499. #define CMD_OUTLOG_INIT_PARTNER 0x103
  1500. #define CMD_OUTLOG_ADD_NEW_PARTNER 0x104
  1501. #define CMD_OUTLOG_DEACTIVATE_PARTNER 0x105
  1502. #define CMD_OUTLOG_ACTIVATE_PARTNER 0x106
  1503. #define CMD_OUTLOG_CLOSE_PARTNER 0x107
  1504. #define CMD_OUTLOG_REMOVE_PARTNER 0x108
  1505. #define CMD_OUTLOG_RETIRE_CO 0x109
  1506. #define CMD_OUTLOG_UPDATE_PARTNER 0x10A
  1507. /***********************************************************
  1508. * *
  1509. * Commands specific to the test subsystem. *
  1510. * *
  1511. ***********************************************************/
  1512. // sequence break
  1513. #define CMD_NOP 0x100
  1514. /***********************************************************
  1515. * *
  1516. * Commands specific to the replica command server *
  1517. * *
  1518. ***********************************************************/
  1519. // sequence break
  1520. //
  1521. //
  1522. #define CMD_UNKNOWN 0x100
  1523. #define CMD_START 0x108
  1524. #define CMD_DELETE 0x110
  1525. #define CMD_DELETE_RETRY 0x112
  1526. #define CMD_DELETE_NOW 0x114
  1527. #define CMD_START_REPLICAS 0x118
  1528. #define CMD_CHECK_SCHEDULES 0x119
  1529. #define CMD_JOIN_CXTION 0x120
  1530. #define CMD_NEED_JOIN 0x121
  1531. #define CMD_START_JOIN 0x122
  1532. #define CMD_JOINED 0x128
  1533. #define CMD_JOINING 0x130
  1534. #define CMD_JOINING_AFTER_FLUSH 0x131
  1535. #define CMD_VVJOIN_START 0x132
  1536. #define CMD_VVJOIN_SUCCESS 0x134
  1537. #define CMD_VVJOIN_DONE 0x136
  1538. #define CMD_VVJOIN_DONE_UNJOIN 0x138
  1539. #define CMD_UNJOIN 0x140
  1540. #define CMD_UNJOIN_REMOTE 0x148
  1541. #define CMD_CHECK_PROMOTION 0x150
  1542. #define CMD_HUNG_CXTION 0x160
  1543. #define CMD_LOCAL_CO_ACCEPTED 0x200
  1544. #define CMD_CREATE_STAGE 0x210
  1545. #define CMD_CREATE_EXISTING 0x212
  1546. #define CMD_CHECK_OID 0x214
  1547. #define CMD_REMOTE_CO 0x218
  1548. #define CMD_REMOTE_CO_ACCEPTED 0x220
  1549. #define CMD_SEND_STAGE 0x228
  1550. #define CMD_SENDING_STAGE 0x230
  1551. #define CMD_RECEIVING_STAGE 0x238
  1552. #define CMD_RECEIVED_STAGE 0x240
  1553. #define CMD_CREATED_EXISTING 0x242
  1554. #define CMD_RETRY_STAGE 0x243
  1555. #define CMD_RETRY_FETCH 0x244
  1556. #define CMD_SEND_RETRY_FETCH 0x245
  1557. #define CMD_ABORT_FETCH 0x246
  1558. #define CMD_SEND_ABORT_FETCH 0x247
  1559. #define CMD_INSTALL_STAGE 0x248
  1560. #define CMD_REMOTE_CO_DONE 0x250
  1561. /*****************************************************************
  1562. * *
  1563. * Commands specific to the init sync controller command server *
  1564. * *
  1565. *****************************************************************/
  1566. // sequence break
  1567. //
  1568. //
  1569. #define CMD_INITSYNC_START_SYNC 0x100
  1570. #define CMD_INITSYNC_JOIN_NEXT 0x101
  1571. #define CMD_INITSYNC_START_JOIN 0x102
  1572. #define CMD_INITSYNC_VVJOIN_DONE 0x103
  1573. #define CMD_INITSYNC_KEEP_ALIVE 0x104
  1574. #define CMD_INITSYNC_CHECK_PROGRESS 0x105
  1575. #define CMD_INITSYNC_UNJOIN 0x106
  1576. #define CMD_INITSYNC_JOINED 0x107
  1577. #define CMD_INITSYNC_COMM_TIMEOUT 0x108
  1578. /***********************************************************
  1579. * *
  1580. * Commands specific to the Delayed command server. *
  1581. * *
  1582. ***********************************************************/
  1583. // sequence break
  1584. //
  1585. #define CMD_DELAYED_SUBMIT 0x100
  1586. #define CMD_DELAYED_UNIDLED 0x101
  1587. #define CMD_DELAYED_KICK 0x102
  1588. #define CMD_DELAYED_QUEUE_SUBMIT 0x103
  1589. #define CMD_DELAYED_COMPLETE 0x104
  1590. /***********************************************************
  1591. * *
  1592. * Commands specific to the DS command server. *
  1593. * *
  1594. ***********************************************************/
  1595. // sequence break
  1596. //
  1597. #define CMD_POLL_DS 0x100
  1598. /***********************************************************
  1599. * *
  1600. * Commands specific to the thread command server. *
  1601. * *
  1602. ***********************************************************/
  1603. // sequence break
  1604. //
  1605. #define CMD_WAIT 0x100
  1606. /***********************************************************
  1607. * *
  1608. * Commands specific to the Send command server. *
  1609. * *
  1610. ***********************************************************/
  1611. // sequence break
  1612. //
  1613. #define CMD_SND_COMM_PACKET 0x100
  1614. #define CMD_SND_CMD 0x110
  1615. /***********************************************************
  1616. * *
  1617. * Commands specific to the Receive command server. *
  1618. * *
  1619. ***********************************************************/
  1620. // sequence break
  1621. //
  1622. #define CMD_RECEIVE 0x100
  1623. /***********************************************************
  1624. * *
  1625. * Commands specific to the staging area command server. *
  1626. * *
  1627. ***********************************************************/
  1628. // sequence break
  1629. //
  1630. #define CMD_ALLOC_STAGING 0x100
  1631. #define CMD_FREE_STAGING 0x101
  1632. /***********************************************************
  1633. * *
  1634. * Completion routine types for use in command packets. *
  1635. * *
  1636. ***********************************************************/
  1637. //
  1638. //
  1639. #define COMPLETION_INVOKE_ON_CANCEL 0x20
  1640. #define COMPLETION_INVOKE_ON_SUCCESS 0x40
  1641. #define COMPLETION_INVOKE_ON_ERROR 0x80
  1642. /*++
  1643. VOID
  1644. FrsSetCompletionRoutine(
  1645. IN PCOMMAND_PACKET CmdPkt,
  1646. IN PCOMMAND_PACKET_COMPLETION_ROUTINE CompletionRoutine,
  1647. IN PVOID Context,
  1648. IN BOOLEAN InvokeOnSuccess,
  1649. IN BOOLEAN InvokeOnError,
  1650. IN BOOLEAN InvokeOnCancel
  1651. )
  1652. Routine Description:
  1653. This routine is invoked to set the address of a completion routine which
  1654. is to be invoked when a command packet has been completed by a
  1655. subsystem.
  1656. If the completion routine and the completion queue are both null then
  1657. the packet is freed at completion.
  1658. If both are specified the completion routine is called first and on
  1659. return the packet is placed on the CompletionQueue. The Completion
  1660. routine can of course modify the CompletionQueue.
  1661. If a Completion Routine is provided then the packet is never freed
  1662. by the command packet completion dispatchet. This is the responsibility
  1663. of the completion routine.
  1664. Arguments:
  1665. CmdPkt - Pointer to the Command Packet itself.
  1666. CompletionRoutine - Address of the completion routine that is to be
  1667. invoked once the command packet is completed.
  1668. Context - Specifies a context parameter to be passed to the completion
  1669. routine.
  1670. InvokeOnSuccess - Specifies that the completion routine is invoked when the
  1671. operation is successfully completed.
  1672. InvokeOnError - Specifies that the completion routine is invoked when the
  1673. operation completes with an error status.
  1674. InvokeOnCancel - Specifies that the completion routine is invoked when the
  1675. operation is being canceled.
  1676. Return Value:
  1677. None.
  1678. --*/
  1679. #define FrsSetCompletionRoutine(_CmdPkt, _CompletionRoutine, _CompletionArg) { \
  1680. (_CmdPkt)->CompletionRoutine = (_CompletionRoutine); \
  1681. (_CmdPkt)->CompletionArg = (_CompletionArg); \
  1682. }
  1683. #define FrsSetCommandErrorStatus(_CmdPkt, _Status ) \
  1684. (_CmdPkt)->FrsErrorStatus = (_Status)
  1685. #define FrsSetCommand( _CmdPkt, _Queue, _Command, _Flags) { \
  1686. (_CmdPkt)->TargetQueue = (_Queue); \
  1687. (_CmdPkt)->Command = (USHORT) (_Command); \
  1688. (_CmdPkt)->Flags = (UCHAR) (_Flags); \
  1689. }
  1690. //
  1691. // Mark this command request as synchronous.
  1692. //
  1693. #define FrsSetCommandSynchronous( _CmdPkt) \
  1694. (_CmdPkt)->Flags |= CMD_PKT_FLAGS_SYNC;
  1695. //
  1696. // The following are special queues for handling commands.
  1697. //
  1698. VOID
  1699. FrsSubmitCommand(
  1700. IN PCOMMAND_PACKET CmdPkt,
  1701. IN BOOL Headwise
  1702. );
  1703. ULONG
  1704. FrsSubmitCommandAndWait(
  1705. IN PCOMMAND_PACKET Cmd,
  1706. IN BOOL Headwise,
  1707. IN ULONG Timeout
  1708. );
  1709. VOID
  1710. FrsUnSubmitCommand(
  1711. IN PCOMMAND_PACKET CmdPkt
  1712. );
  1713. VOID
  1714. FrsCompleteCommand(
  1715. IN PCOMMAND_PACKET CmdPkt,
  1716. IN DWORD ErrorStatus
  1717. );
  1718. VOID
  1719. FrsCommandScheduler(
  1720. PFRS_QUEUE Queue
  1721. );
  1722. PCOMMAND_PACKET
  1723. FrsAllocCommand(
  1724. IN PFRS_QUEUE TargetQueue,
  1725. IN USHORT Command
  1726. );
  1727. PCOMMAND_PACKET
  1728. FrsAllocCommandEx(
  1729. IN PFRS_QUEUE TargetQueue,
  1730. IN USHORT Command,
  1731. IN ULONG Size
  1732. );
  1733. VOID
  1734. FrsFreeCommand(
  1735. IN PCOMMAND_PACKET Cmd,
  1736. IN PVOID Arg
  1737. );
  1738. PCOMMAND_PACKET
  1739. FrsGetCommand(
  1740. IN PFRS_QUEUE Queue,
  1741. IN DWORD MilliSeconds
  1742. );
  1743. VOID
  1744. FrsRunDownCommand(
  1745. IN PFRS_QUEUE Queue
  1746. );
  1747. extern FRS_QUEUE FrsScheduleQueue;
  1748. //
  1749. // Some Journal related functions.
  1750. //
  1751. ULONG
  1752. JrnlMonitorInit(
  1753. PFRS_QUEUE ReplicaListHead,
  1754. ULONG Phase
  1755. );
  1756. ULONG
  1757. JrnlPauseVolume(
  1758. IN PVOLUME_MONITOR_ENTRY pVme,
  1759. IN DWORD MilliSeconds
  1760. );
  1761. ULONG
  1762. JrnlUnPauseVolume(
  1763. IN PVOLUME_MONITOR_ENTRY pVme,
  1764. IN PJBUFFER Jbuff,
  1765. IN BOOL HaveLock
  1766. );
  1767. BOOL
  1768. JrnlSetReplicaState(
  1769. IN PREPLICA Replica,
  1770. IN ULONG NewState
  1771. );
  1772. #if DBG
  1773. #define DUMP_USN_RECORD2(_Severity, _UsnRecord, _ReplicaNum, _LocCmd) \
  1774. DumpUsnRecord(_Severity, _UsnRecord, _ReplicaNum, _LocCmd, DEBSUB, __LINE__)
  1775. #define DUMP_USN_RECORD(_Severity, _UsnRecord) \
  1776. DumpUsnRecord(_Severity, _UsnRecord, 0, CO_LOCATION_NUM_CMD, DEBSUB, __LINE__)
  1777. VOID
  1778. DumpUsnRecord(
  1779. IN ULONG Severity,
  1780. IN PUSN_RECORD UsnRecord,
  1781. IN ULONG ReplicaNumber,
  1782. IN ULONG LocationCmd,
  1783. IN PCHAR Debsub,
  1784. IN ULONG uLineNo
  1785. );
  1786. #else DBG
  1787. #define DUMP_USN_RECORD(_Severity, _UsnRecord)
  1788. #endif DBG
  1789. ULONG
  1790. ChgOrdInsertRemoteCo(
  1791. IN PCOMMAND_PACKET Cmd,
  1792. IN PCXTION Cxtion
  1793. );
  1794. DWORD
  1795. ChgOrdHammerObjectId(
  1796. IN PWCHAR Name,
  1797. IN PVOID Id,
  1798. IN DWORD IdLen,
  1799. IN PVOLUME_MONITOR_ENTRY pVme,
  1800. IN BOOL CallerSupplied,
  1801. OUT USN *Usn,
  1802. IN OUT PFILE_OBJECTID_BUFFER FileObjID,
  1803. IN OUT BOOL *ExistingOid
  1804. );
  1805. DWORD
  1806. ChgOrdSkipBasicInfoChange(
  1807. IN PCHANGE_ORDER_ENTRY Coe,
  1808. IN PBOOL SkipCo
  1809. );
  1810. VOID
  1811. JrnlCleanupVme(
  1812. IN PVOLUME_MONITOR_ENTRY pVme
  1813. );
  1814. //
  1815. // Waitable timer list
  1816. //
  1817. DWORD
  1818. WaitSubmit(
  1819. IN PCOMMAND_PACKET Cmd,
  1820. IN DWORD Timeout,
  1821. IN USHORT TimeoutCommand
  1822. );
  1823. VOID
  1824. WaitUnsubmit(
  1825. IN PCOMMAND_PACKET Cmd
  1826. );
  1827. VOID
  1828. WaitInitialize(
  1829. VOID
  1830. );
  1831. VOID
  1832. ShutDownWait(
  1833. VOID
  1834. );
  1835. #endif // _FRSH_