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.

553 lines
13 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. tablefcn.h
  5. Abstract:
  6. Defines the function prototypes for the functions used to access the
  7. Jet database tables.
  8. Include after frsalloc.h
  9. Author:
  10. David Orbits (davidor) - 10-Apr-1997
  11. Revision History:
  12. */
  13. JET_ERR
  14. DbsCreateJetSession(
  15. IN OUT PTHREAD_CTX ThreadCtx
  16. );
  17. JET_ERR
  18. DbsCloseJetSession(
  19. IN PTHREAD_CTX ThreadCtx
  20. );
  21. JET_ERR
  22. DbsInsertTable2(
  23. IN PTABLE_CTX TableCtx
  24. );
  25. JET_ERR
  26. DbsTableMoveFirst(
  27. IN PTHREAD_CTX ThreadCtx,
  28. IN PTABLE_CTX TableCtx,
  29. IN ULONG ReplicaNumber,
  30. IN ULONG RecordIndex
  31. );
  32. JET_ERR
  33. DbsOpenTable0(
  34. IN PTHREAD_CTX ThreadCtx,
  35. IN PTABLE_CTX TableCtx,
  36. IN ULONG ReplicaNumber,
  37. OUT PCHAR TableName,
  38. OUT JET_TABLEID *Tid
  39. );
  40. JET_ERR
  41. DbsOpenReplicaTables (
  42. IN PTHREAD_CTX ThreadCtx,
  43. IN PREPLICA Replica,
  44. IN PREPLICA_THREAD_CTX RtCtx
  45. );
  46. FRS_ERROR_CODE
  47. DbsCloseSessionReplicaTables (
  48. IN PTHREAD_CTX ThreadCtx,
  49. IN OUT PREPLICA Replica
  50. );
  51. JET_ERR
  52. DbsCloseReplicaTables (
  53. IN PTHREAD_CTX ThreadCtx,
  54. IN PREPLICA Replica,
  55. IN PREPLICA_THREAD_CTX RtCtx,
  56. IN BOOL SessionErrorCheck
  57. );
  58. VOID
  59. DbsSetJetColAddr (
  60. IN PTABLE_CTX TableCtx
  61. );
  62. VOID
  63. DbsSetJetColSize(
  64. IN PTABLE_CTX TableCtx
  65. );
  66. NTSTATUS
  67. DbsAllocRecordStorage(
  68. IN OUT PTABLE_CTX TableCtx
  69. );
  70. JET_ERR
  71. DbsCheckSetRetrieveErrors(
  72. IN OUT PTABLE_CTX TableCtx
  73. );
  74. #if DBG
  75. VOID
  76. DbsDisplayRecord(
  77. IN ULONG Severity,
  78. IN PTABLE_CTX TableCtx,
  79. IN BOOL Read,
  80. IN PCHAR Debsub,
  81. IN ULONG uLineNo,
  82. IN PULONG RecordFieldx,
  83. IN ULONG FieldCount
  84. );
  85. #endif DBG
  86. JET_ERR
  87. DbsRecordOperation(
  88. IN PTHREAD_CTX ThreadCtx,
  89. IN ULONG Operation,
  90. IN PVOID KeyValue,
  91. IN ULONG RecordIndex,
  92. IN PTABLE_CTX TableCtx
  93. );
  94. ULONG
  95. DbsRecordOperationMKey(
  96. IN PTHREAD_CTX ThreadCtx,
  97. IN ULONG Operation,
  98. IN PVOID *KeyValueArray,
  99. IN ULONG RecordIndex,
  100. IN PTABLE_CTX TableCtx
  101. );
  102. JET_ERR
  103. DbsWriteReplicaTableRecord(
  104. IN PTHREAD_CTX ThreadCtx,
  105. IN ULONG ReplicaNumber,
  106. IN PTABLE_CTX TableCtx
  107. );
  108. ULONG
  109. DbsWriteTableField(
  110. IN PTHREAD_CTX ThreadCtx,
  111. IN ULONG ReplicaNumber,
  112. IN PTABLE_CTX TableCtx,
  113. IN ULONG RecordFieldx
  114. );
  115. ULONG
  116. DbsWriteTableFieldMult(
  117. IN PTHREAD_CTX ThreadCtx,
  118. IN ULONG ReplicaNumber,
  119. IN PTABLE_CTX TableCtx,
  120. IN PULONG RecordFieldx,
  121. IN ULONG FieldCount
  122. );
  123. PVOID
  124. DbsDataExtensionFind(
  125. IN PVOID ExtBuf,
  126. IN DATA_EXTENSION_TYPE_CODES TypeCode
  127. );
  128. VOID
  129. DbsDataInitCocExtension(
  130. IN PCHANGE_ORDER_RECORD_EXTENSION CocExt
  131. );
  132. VOID
  133. DbsDataInitIDTableExtension(
  134. IN PIDTABLE_RECORD_EXTENSION IdtExt
  135. );
  136. DWORD
  137. FrsGetOrSetFileObjectId(
  138. IN HANDLE Handle,
  139. IN LPCWSTR FileName,
  140. IN BOOL CallerSupplied,
  141. OUT PFILE_OBJECTID_BUFFER ObjectIdBuffer
  142. );
  143. ULONG
  144. ChgOrdInboundRetired(
  145. IN PCHANGE_ORDER_ENTRY ChangeOrder
  146. );
  147. ULONG
  148. ChgOrdInboundRetry(
  149. IN PCHANGE_ORDER_ENTRY ChangeOrder,
  150. IN ULONG NewState
  151. );
  152. //
  153. // DB Service access functions.
  154. //
  155. VOID
  156. DbsInitialize(
  157. VOID
  158. );
  159. VOID
  160. DbsShutDown(
  161. VOID
  162. );
  163. PTABLE_CTX
  164. DbsCreateTableContext(
  165. IN ULONG TableType
  166. );
  167. ULONG
  168. DbsOpenTable(
  169. IN PTHREAD_CTX ThreadCtx,
  170. IN PTABLE_CTX TableCtx,
  171. IN ULONG ReplicaNumber,
  172. IN ULONG TableType,
  173. IN PVOID DataRecord
  174. );
  175. BOOL
  176. DbsFreeTableContext(
  177. IN PTABLE_CTX TableCtx,
  178. IN JET_SESID Sesid
  179. );
  180. PCOMMAND_PACKET
  181. DbsPrepareCmdPkt (
  182. PCOMMAND_PACKET CmdPkt,
  183. PREPLICA Replica,
  184. ULONG CmdRequest,
  185. PTABLE_CTX TableCtx,
  186. PVOID CallContext,
  187. ULONG TableType,
  188. ULONG AccessRequest,
  189. ULONG IndexType,
  190. PVOID KeyValue,
  191. ULONG KeyValueLength,
  192. BOOL Submit
  193. );
  194. PCOMMAND_PACKET
  195. DbsPrepFieldUpdateCmdPkt (
  196. PCOMMAND_PACKET CmdPkt,
  197. PREPLICA Replica,
  198. PTABLE_CTX TableCtx,
  199. PVOID CallContext,
  200. ULONG TableType,
  201. ULONG IndexType,
  202. PVOID KeyValue,
  203. ULONG KeyValueLength,
  204. ULONG FieldCount,
  205. PULONG FieldIDList
  206. );
  207. ULONG
  208. DbsInitializeIDTableRecord(
  209. IN OUT PTABLE_CTX TableCtx,
  210. IN HANDLE FileHandle,
  211. IN PREPLICA Replica,
  212. IN PCHANGE_ORDER_ENTRY ChangeOrder,
  213. IN PWCHAR FileName,
  214. IN OUT BOOL *ExistingOid
  215. );
  216. VOID
  217. DbsDBInitConfigRecord(
  218. IN PTABLE_CTX TableCtx,
  219. IN GUID *ReplicaSetGuid,
  220. IN PWCHAR ReplicaSetName,
  221. IN ULONG ReplicaNumber,
  222. IN PWCHAR ReplicaRootPath,
  223. IN PWCHAR ReplicaStagingPath,
  224. IN PWCHAR ReplicaVolume
  225. );
  226. ULONG
  227. DbsFidToGuid(
  228. IN PTHREAD_CTX ThreadCtx,
  229. IN PREPLICA Replica,
  230. IN PTABLE_CTX TableCtx,
  231. IN PULONGLONG Fid,
  232. OUT GUID *Guid
  233. );
  234. ULONG
  235. DbsGuidToFid(
  236. IN PTHREAD_CTX ThreadCtx,
  237. IN PREPLICA Replica,
  238. IN PTABLE_CTX TableCtx,
  239. IN GUID *Guid,
  240. OUT PULONGLONG Fid
  241. );
  242. ULONG
  243. DbsInitOneReplicaSet(
  244. PREPLICA Replica
  245. );
  246. ULONG
  247. DbsFreeRtCtx(
  248. IN PTHREAD_CTX ThreadCtx,
  249. IN PREPLICA Replica,
  250. IN PREPLICA_THREAD_CTX RtCtx,
  251. IN BOOL SessionErrorCheck
  252. );
  253. JET_ERR
  254. DbsDeleteTableRecord(
  255. IN PTABLE_CTX TableCtx
  256. );
  257. ULONG
  258. DbsDeleteTableRecordByIndex(
  259. IN PTHREAD_CTX ThreadCtx,
  260. IN PREPLICA Replica,
  261. IN PTABLE_CTX TableCtx,
  262. IN PVOID pIndex,
  263. IN ULONG IndexType,
  264. IN ULONG TableType
  265. );
  266. #define DbsDeleteIDTableRecord(_ThreadCtx_, _Replica_, _TableCtx_, _pIndex_) \
  267. DbsDeleteTableRecordByIndex(_ThreadCtx_, \
  268. _Replica_, \
  269. _TableCtx_, \
  270. _pIndex_, \
  271. GuidIndexx, \
  272. IDTablex)
  273. #define DbsDeleteDIRTableRecord(_ThreadCtx_, _Replica_, _TableCtx_, _pIndex_) \
  274. DbsDeleteTableRecordByIndex(_ThreadCtx_, \
  275. _Replica_, \
  276. _TableCtx_, \
  277. _pIndex_, \
  278. DFileGuidIndexx, \
  279. DIRTablex)
  280. ULONG
  281. DbsReadTableRecordByIndex(
  282. IN PTHREAD_CTX ThreadCtx,
  283. IN PREPLICA Replica,
  284. IN PTABLE_CTX TableCtx,
  285. IN PVOID pIndex,
  286. IN ULONG IndexType,
  287. IN ULONG TableType
  288. );
  289. ULONG
  290. DbsUpdateTableRecordByIndex(
  291. IN PTHREAD_CTX ThreadCtx,
  292. IN PREPLICA Replica,
  293. IN PTABLE_CTX TableCtx,
  294. IN PVOID pIndex,
  295. IN ULONG IndexType,
  296. IN ULONG TableType
  297. );
  298. ULONG
  299. DbsInsertTable(
  300. IN PTHREAD_CTX ThreadCtx,
  301. IN PREPLICA Replica,
  302. IN PTABLE_CTX TableCtx,
  303. IN ULONG TableType,
  304. IN PVOID DataRecord
  305. );
  306. ULONG
  307. DbsTableMoveToRecord(
  308. IN PTHREAD_CTX ThreadCtx,
  309. IN PTABLE_CTX TableCtx,
  310. IN ULONG RecordIndex,
  311. IN ULONG MoveArg
  312. );
  313. #define FrsMoveFirst JET_MoveFirst
  314. #define FrsMovePrevious JET_MovePrevious
  315. #define FrsMoveNext JET_MoveNext
  316. #define FrsMoveLast JET_MoveLast
  317. ULONG
  318. DbsTableRead(
  319. IN PTHREAD_CTX ThreadCtx,
  320. IN PTABLE_CTX TableCtx
  321. );
  322. ULONG
  323. DbsUpdateRecordField(
  324. IN PTHREAD_CTX ThreadCtx,
  325. IN PREPLICA Replica,
  326. IN PTABLE_CTX TableCtx,
  327. IN ULONG IndexField,
  328. IN PVOID IndexValue,
  329. IN ULONG UpdateField
  330. );
  331. ULONG
  332. DbsRequestSaveMark(
  333. PVOLUME_MONITOR_ENTRY pVme,
  334. BOOL Wait
  335. );
  336. ULONG
  337. DbsRequestReplicaServiceStateSave(
  338. IN PREPLICA Replica,
  339. IN BOOL Wait
  340. );
  341. ULONG
  342. DbsUpdateVV(
  343. IN PTHREAD_CTX ThreadCtx,
  344. IN PREPLICA Replica,
  345. IN PREPLICA_THREAD_CTX RtCtx,
  346. IN ULONGLONG OriginatorVsn,
  347. IN GUID *OriginatorGuid
  348. );
  349. //
  350. // An enumerate table function is passed as a parameter to FrsEnumerateTable().
  351. // It gets a PTHREAD_CTX, PTABLE_CTX and a pointer to a data record from the
  352. // table. It does its processing of the record data and returns a JET_ERR
  353. // status. If the status is JET_errSuccess it will be called with the next
  354. // record in the table. IF the status is NOT JET_errSuccess, that status is
  355. // returned as the status result of the FrsEnumerateTable() function. If
  356. // the status is JET_errInvalidObject then re-read the record and call the table
  357. // function again.
  358. //
  359. //
  360. typedef
  361. JET_ERR
  362. (NTAPI *PENUMERATE_TABLE_ROUTINE) (
  363. IN PTHREAD_CTX ThreadCtx,
  364. IN PTABLE_CTX TableCtx,
  365. IN PVOID Record,
  366. IN PVOID Context
  367. );
  368. typedef
  369. JET_ERR
  370. (NTAPI *PENUMERATE_TABLE_PREREAD) (
  371. IN PTHREAD_CTX ThreadCtx,
  372. IN PTABLE_CTX TableCtx,
  373. IN PVOID Context
  374. );
  375. typedef
  376. JET_ERR
  377. (NTAPI *PENUMERATE_OUTLOGTABLE_ROUTINE) (
  378. IN PTHREAD_CTX ThreadCtx,
  379. IN PTABLE_CTX TableCtx,
  380. IN PCHANGE_ORDER_COMMAND CoCmd,
  381. IN PVOID Context,
  382. IN ULONG OutLogSeqNumber
  383. );
  384. JET_ERR
  385. DbsEnumerateTable2(
  386. IN PTHREAD_CTX ThreadCtx,
  387. IN PTABLE_CTX TableCtx,
  388. IN ULONG RecordIndex,
  389. IN PENUMERATE_TABLE_ROUTINE RecordFunction,
  390. IN PVOID Context,
  391. IN PENUMERATE_TABLE_PREREAD PreReadFunction
  392. );
  393. JET_ERR
  394. DbsEnumerateTableFrom(
  395. IN PTHREAD_CTX ThreadCtx,
  396. IN PTABLE_CTX TableCtx,
  397. IN ULONG RecordIndex,
  398. IN PVOID KeyValue,
  399. IN INT ScanDirection,
  400. IN PENUMERATE_TABLE_ROUTINE RecordFunction,
  401. IN PVOID Context,
  402. IN PENUMERATE_TABLE_PREREAD PreReadFunction
  403. );
  404. #define FrsEnumerateTable(_TH, _TC, _RI, _RF, _CTX) \
  405. DbsEnumerateTable2(_TH, _TC, _RI, _RF, _CTX, NULL)
  406. #define FrsEnumerateTableFrom(_TH, _TC, _RI, _KV, _SD, _RF, _CTX) \
  407. DbsEnumerateTableFrom(_TH, _TC, _RI, _KV, _SD, _RF, _CTX, NULL)
  408. //
  409. // An enumerate directory function is passed as a parameter to
  410. // FrsEnumerateDirectory().
  411. //
  412. // The function gets a the directory handle and a pointer to a directory
  413. // record from the directory. It does its processing of the directory
  414. // data and returns a WIN32 STATUS. If the status is ERROR_SUCCESS it
  415. // will be called with the next record in the directory. IF the status
  416. // is NOT ERROR_SUCCESS, that status is returned as the status result of
  417. // the FrsEnumerateDirectory() function and enumeration stops.
  418. //
  419. // The function is responsible for recursing into the next level of
  420. // directory by calling FrsEnumerateDirectoryRecurse() as needed.
  421. //
  422. // FrsEnumerateDirectory() will continue an enumeration even if
  423. // errors occur if ENUMERATE_DIRECTORY_FLAGS_ERROR_CONTINUE is set.
  424. //
  425. // FrsEnumerateDirectory() will skip non-directory entries if
  426. // if ENUMERATE_DIRECTORY_FLAGS_DIRECTORIES_ONLY is set.
  427. //
  428. #define ENUMERATE_DIRECTORY_FLAGS_NONE (0x00000000)
  429. #define ENUMERATE_DIRECTORY_FLAGS_ERROR_CONTINUE (0x00000001)
  430. #define ENUMERATE_DIRECTORY_FLAGS_DIRECTORIES_ONLY (0x00000002)
  431. typedef
  432. DWORD
  433. (NTAPI *PENUMERATE_DIRECTORY_ROUTINE) (
  434. IN HANDLE DirectoryHandle,
  435. IN PWCHAR DirectoryName,
  436. IN DWORD DirectoryLevel,
  437. IN PFILE_DIRECTORY_INFORMATION DirectoryRecord,
  438. IN DWORD DirectoryFlags,
  439. IN PWCHAR FileName,
  440. IN PVOID Context
  441. );
  442. DWORD
  443. FrsEnumerateDirectoryDeleteWorker(
  444. IN HANDLE DirectoryHandle,
  445. IN PWCHAR DirectoryName,
  446. IN DWORD DirectoryLevel,
  447. IN PFILE_DIRECTORY_INFORMATION DirectoryRecord,
  448. IN DWORD DirectoryFlags,
  449. IN PWCHAR FileName,
  450. IN PVOID Ignored
  451. );
  452. DWORD
  453. FrsEnumerateDirectoryRecurse(
  454. IN HANDLE DirectoryHandle,
  455. IN PWCHAR DirectoryName,
  456. IN DWORD DirectoryLevel,
  457. IN PFILE_DIRECTORY_INFORMATION DirectoryRecord,
  458. IN DWORD DirectoryFlags,
  459. IN PWCHAR FileName,
  460. IN HANDLE FileHandle,
  461. IN PVOID Context,
  462. IN PENUMERATE_DIRECTORY_ROUTINE Function
  463. );
  464. DWORD
  465. FrsEnumerateDirectory(
  466. IN HANDLE DirectoryHandle,
  467. IN PWCHAR DirectoryName,
  468. IN DWORD DirectoryLevel,
  469. IN DWORD DirectoryFlags,
  470. IN PVOID Context,
  471. IN PENUMERATE_DIRECTORY_ROUTINE Function
  472. );