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.

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