Windows NT 4.0 source code leak
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.

598 lines
13 KiB

4 years ago
  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: DFSPROCS.H
  4. //
  5. // Contents:
  6. // This module defines all of the globally used procedures in the Dsfs
  7. // file system.
  8. //
  9. // Functions:
  10. //
  11. // History: 12 Nov 1991 AlanW Created from CDFS souce.
  12. // 8 May 1992 PeterCo Removed References to EPs
  13. // Added stuff to support PKT (M000)
  14. //-----------------------------------------------------------------------------
  15. #ifndef _DFSPROCS_
  16. #define _DFSPROCS_
  17. #include <ntifs.h>
  18. #include "ntext.h" // BUGBUG - These are
  19. // functions we use that are
  20. // missing from ntifs.h
  21. // Talk to DarrylH about this
  22. #include <tdi.h>
  23. #include <ntddnfs.h> // For communicating with
  24. // the SMB Rdr
  25. #include <ntddmup.h> // For UNC registration
  26. #include <fsrtl.h>
  27. #include <string.h>
  28. #include <winnetwk.h> // For NETRESOURCE def'n
  29. #include <dfsfsctl.h> // Dfs FsControl Codes.
  30. #include "dfserr.h"
  31. #include "dfsstr.h"
  32. #include "nodetype.h"
  33. #include "dfsmrshl.h"
  34. #include "dfsrtl.h"
  35. #include "pkt.h"
  36. #include "dfsstruc.h"
  37. #include "dfsdata.h"
  38. #include "log.h"
  39. #ifndef i386
  40. #define DFS_UNALIGNED UNALIGNED
  41. #else
  42. #define DFS_UNALIGNED
  43. #endif // MIPS
  44. //
  45. // The driver entry routine
  46. //
  47. NTSTATUS
  48. DfsDriverEntry(
  49. IN PDRIVER_OBJECT DriverObject,
  50. IN PUNICODE_STRING RegistryPath
  51. );
  52. //
  53. // The following routine is used to create and initialIze logical root
  54. // device objects, implemented in dsinit.c
  55. //
  56. NTSTATUS
  57. DfsInitializeLogicalRoot (
  58. IN LPCWSTR Name,
  59. IN PUNICODE_STRING Prefix OPTIONAL,
  60. IN PDFS_CREDENTIALS Credentials OPTIONAL,
  61. IN USHORT VcbFlags OPTIONAL
  62. );
  63. NTSTATUS
  64. DfsDeleteLogicalRoot (
  65. IN PWSTR Name,
  66. IN BOOLEAN fForce
  67. );
  68. NTSTATUS
  69. DfspLogRootNameToPath(
  70. LPCWSTR Name,
  71. PUNICODE_STRING RootName
  72. );
  73. BOOLEAN
  74. DfsLogicalRootExists(
  75. PWSTR pwszName
  76. );
  77. NTSTATUS
  78. DfsGetResourceFromVcb(
  79. PDFS_VCB Vcb,
  80. PUNICODE_STRING ProviderName,
  81. PUCHAR BufBegin,
  82. PUCHAR Buf,
  83. PULONG BufSize
  84. );
  85. NTSTATUS
  86. DfsGetResourceFromCredentials(
  87. PDFS_CREDENTIALS Vcb,
  88. PUNICODE_STRING ProviderName,
  89. PUCHAR BufBegin,
  90. PUCHAR Buf,
  91. PULONG BufSize
  92. );
  93. //
  94. // The following routines are used to manipulate the fcb associated with
  95. // each opened file object, implemented in FilObSup.c
  96. //
  97. typedef enum _TYPE_OF_OPEN {
  98. UnopenedFileObject = 1,
  99. FilesystemDeviceOpen,
  100. LogicalRootDeviceOpen,
  101. RedirectedFileOpen,
  102. UserVolumeOpen,
  103. UnknownOpen,
  104. } TYPE_OF_OPEN;
  105. VOID
  106. DfsSetFileObject (
  107. IN PFILE_OBJECT FileObject OPTIONAL,
  108. IN TYPE_OF_OPEN TypeOfOpen,
  109. IN PVOID VcbOrFcb
  110. );
  111. TYPE_OF_OPEN
  112. DfsDecodeFileObject (
  113. IN PFILE_OBJECT FileObject,
  114. OUT PDFS_VCB *Vcb,
  115. OUT PDFS_FCB *Fcb
  116. );
  117. //
  118. // In-memory structure support routines, implemented in StrucSup.c
  119. //
  120. PIRP_CONTEXT
  121. DfsCreateIrpContext (
  122. IN PIRP Irp,
  123. IN BOOLEAN Wait
  124. );
  125. VOID
  126. DfsDeleteIrpContext_Real (
  127. IN PIRP_CONTEXT IrpContext
  128. );
  129. #if DBG
  130. #define DfsDeleteIrpContext(IRPCONTEXT) { \
  131. DfsDeleteIrpContext_Real((IRPCONTEXT)); \
  132. (IRPCONTEXT) = NULL; \
  133. }
  134. #else
  135. #define DfsDeleteIrpContext(IRPCONTEXT) { \
  136. DfsDeleteIrpContext_Real((IRPCONTEXT)); \
  137. }
  138. #endif
  139. VOID
  140. DfsInitializeVcb (
  141. IN PIRP_CONTEXT IrpContext,
  142. IN OUT PDFS_VCB Vcb,
  143. IN PUNICODE_STRING LogRootPrefix,
  144. IN PDFS_CREDENTIALS Credentials OPTIONAL,
  145. IN PDEVICE_OBJECT TargetDeviceObject
  146. );
  147. VOID
  148. DfsDeleteVcb_Real (
  149. IN PIRP_CONTEXT IrpContext,
  150. IN PDFS_VCB Vcb
  151. );
  152. #if DBG
  153. #define DfsDeleteVcb(IRPCONTEXT,VCB) { \
  154. DfsDeleteVcb_Real((IRPCONTEXT),(VCB)); \
  155. (VCB) = NULL; \
  156. }
  157. #else
  158. #define DfsDeleteVcb(IRPCONTEXT,VCB) { \
  159. DfsDeleteVcb_Real((IRPCONTEXT),(VCB)); \
  160. }
  161. #endif
  162. PDFS_FCB
  163. DfsCreateFcb (
  164. IN PIRP_CONTEXT IrpContext,
  165. IN PDFS_VCB Vcb,
  166. IN PUNICODE_STRING FullName OPTIONAL
  167. );
  168. VOID
  169. DfsDeleteFcb_Real (
  170. IN PIRP_CONTEXT IrpContext,
  171. IN PDFS_FCB Fcb
  172. );
  173. #if DBG
  174. #define DfsDeleteFcb(IRPCONTEXT,FCB) { \
  175. DfsDeleteFcb_Real((IRPCONTEXT),(FCB)); \
  176. (FCB) = NULL; \
  177. }
  178. #else
  179. #define DfsDeleteFcb(IRPCONTEXT,FCB) { \
  180. DfsDeleteFcb_Real((IRPCONTEXT),(FCB)); \
  181. }
  182. #endif
  183. //
  184. // Miscellaneous routines
  185. //
  186. VOID GuidToString(
  187. IN GUID *pGuid,
  188. OUT PWSTR pwszGuid);
  189. VOID StringToGuid(
  190. IN PWSTR pwszGuid,
  191. OUT GUID *pGuid);
  192. NTSTATUS
  193. DfsFindLogicalRoot( // implemented in FsCtrl.c
  194. IN PUNICODE_STRING PrefixPath,
  195. OUT PDFS_VCB *Vcb,
  196. OUT PUNICODE_STRING RemainingPath
  197. );
  198. NTSTATUS
  199. DfsInsertProvider( // implemented in FsCtrl.c
  200. IN PUNICODE_STRING pustrProviderName,
  201. IN ULONG fProvCapability,
  202. IN ULONG eProviderId);
  203. NTSTATUS // implemented in provider.c
  204. DfsGetProviderForDevice(
  205. IN PUNICODE_STRING DeviceName,
  206. PPROVIDER_DEF *Provider);
  207. VOID
  208. DfsAgePktEntries(
  209. IN PVOID DfsTimerContext
  210. );
  211. NTSTATUS
  212. DfsFsctrlSetDomainGluon(
  213. IN PIRP_CONTEXT IrpContext,
  214. IN PIRP Irp,
  215. IN PVOID InputBuffer,
  216. IN ULONG InputBufferLength);
  217. NTSTATUS
  218. DfsFsctrlIsThisADfsPath(
  219. IN PUNICODE_STRING filePath,
  220. OUT PUNICODE_STRING pathName);
  221. NTSTATUS
  222. PktFsctrlFlushCache(
  223. IN PIRP_CONTEXT IrpContext,
  224. IN PIRP Irp,
  225. IN PVOID InputBuffer,
  226. IN ULONG InputBufferLength
  227. );
  228. //
  229. // Pass-through functions
  230. //
  231. NTSTATUS
  232. DfsVolumePassThrough(
  233. IN PDEVICE_OBJECT DeviceObject,
  234. IN PIRP Irp
  235. );
  236. NTSTATUS
  237. DfsCompleteVolumePassThrough(
  238. IN PDEVICE_OBJECT pDevice,
  239. IN PIRP Irp,
  240. IN PVOID Context
  241. );
  242. NTSTATUS
  243. DfsFilePassThrough(
  244. IN PDFS_FCB pFcb,
  245. IN PIRP Irp
  246. );
  247. //
  248. // The FSD Level dispatch routines. These routines are called by the
  249. // I/O system via the dispatch table in the Driver Object.
  250. //
  251. // They each accept as input a pointer to a device object (actually most
  252. // expect a logical root device object; some will also work with a file
  253. // system device object), and a pointer to the IRP. They either perform
  254. // the function at the FSD level or post the request to the FSP work
  255. // queue for FSP level processing.
  256. //
  257. NTSTATUS
  258. DfsFsdCleanup ( // implemented in Close.c
  259. IN PDEVICE_OBJECT DeviceObject,
  260. IN PIRP Irp
  261. );
  262. NTSTATUS
  263. DfsFsdClose ( // implemented in Close.c
  264. IN PDEVICE_OBJECT DeviceObject,
  265. IN PIRP Irp
  266. );
  267. NTSTATUS
  268. DfsFsdCreate ( // implemented in Create.c
  269. IN PDEVICE_OBJECT DeviceObject,
  270. IN PIRP Irp
  271. );
  272. NTSTATUS
  273. DfsFsdDeviceIoControl ( // implemented in FsCtrl.c
  274. IN PDEVICE_OBJECT DeviceObject,
  275. IN PIRP Irp
  276. );
  277. NTSTATUS
  278. DfsFsdDirectoryControl ( // implemented in DirCtrl.c
  279. IN PDEVICE_OBJECT DeviceObject,
  280. IN PIRP Irp
  281. );
  282. NTSTATUS
  283. DfsFsdQueryInformation ( // implemented in FileInfo.c
  284. IN PDEVICE_OBJECT DeviceObject,
  285. IN PIRP Irp
  286. );
  287. NTSTATUS
  288. DfsFsdQueryInformation ( // implemented in FileInfo.c
  289. IN PDEVICE_OBJECT DeviceObject,
  290. IN PIRP Irp
  291. );
  292. NTSTATUS
  293. DfsFsdSetInformation ( // implemented in FileInfo.c
  294. IN PDEVICE_OBJECT DeviceObject,
  295. IN PIRP Irp
  296. );
  297. NTSTATUS
  298. DfsFsdFileSystemControl ( // implemented in FsCtrl.c
  299. IN PDEVICE_OBJECT DeviceObject,
  300. IN PIRP Irp
  301. );
  302. NTSTATUS
  303. DfsFsdQueryVolumeInformation ( // implemented in VolInfo.c
  304. IN PDEVICE_OBJECT DeviceObject,
  305. IN PIRP Irp
  306. );
  307. NTSTATUS
  308. DfsFsdSetVolumeInformation ( // implemented in VolInfo.c
  309. IN PDEVICE_OBJECT DeviceObject,
  310. IN PIRP Irp
  311. );
  312. //
  313. // The following macro is used to determine if an FSD thread can block
  314. // for I/O or wait for a resource. It returns TRUE if the thread can
  315. // block and FALSE otherwise. This attribute can then be used to call
  316. // the FSD & FSP common work routine with the proper wait value.
  317. //
  318. #define CanFsdWait(IRP) ((BOOLEAN)( \
  319. IoIsOperationSynchronous(IRP) || \
  320. DfsData.OurProcess == PsGetCurrentProcess()) \
  321. )
  322. //
  323. // Routine for posting an Irp to the FSP, implemented in fspdisp.c
  324. //
  325. NTSTATUS
  326. DfsFsdPostRequest(
  327. IN PIRP_CONTEXT IrpContext,
  328. IN PIRP Irp
  329. );
  330. //
  331. // The FSP level dispatch/main routine. This is the routine that takes
  332. // IRPs from the work queue and calls the appropriate FSP level work routine.
  333. //
  334. VOID
  335. DfsFspDispatch ( // implemented in FspDisp.c
  336. IN PVOID Context
  337. );
  338. //
  339. // The following routines are the FSP work routines that are called
  340. // by the preceding DfsFsdDispath routine. Each takes as input a pointer
  341. // to the IRP, performs the function, and returns.
  342. //
  343. // Each of the following routines is also responsible for completing the IRP.
  344. // We moved this responsibility from the main loop to the individual routines
  345. // to allow them the ability to complete the IRP and continue post processing
  346. // actions.
  347. //
  348. VOID
  349. DfsFspClose ( // implemented in Close.c
  350. IN PIRP_CONTEXT IrpContext,
  351. IN PIRP Irp
  352. );
  353. VOID
  354. DfsFspQueryInformation ( // implemented in FileInfo.c
  355. IN PIRP_CONTEXT IrpContext,
  356. IN PIRP Irp
  357. );
  358. VOID
  359. DfsFspSetInformation ( // implemented in FileInfo.c
  360. IN PIRP_CONTEXT IrpContext,
  361. IN PIRP Irp
  362. );
  363. VOID
  364. DfsFspFileSystemControl ( // implemented in FsCtrl.c
  365. IN PIRP_CONTEXT IrpContext,
  366. IN PIRP Irp
  367. );
  368. VOID
  369. DfsFspQueryVolumeInformation ( // implemented in VolInfo.c
  370. IN PIRP_CONTEXT IrpContext,
  371. IN PIRP Irp
  372. );
  373. VOID
  374. DfsFspSetVolumeInformation ( // implemented in VolInfo.c
  375. IN PIRP_CONTEXT IrpContext,
  376. IN PIRP Irp
  377. );
  378. //
  379. // The following macro is used by the FSP and FSD routines to complete
  380. // an IRP.
  381. //
  382. // Note that this macro allows either the Irp or the IrpContext to be
  383. // null, however the only legal order to do this in is:
  384. //
  385. // DfsCompleteRequest( NULL, Irp, Status ); // completes Irp & preserves context
  386. // ...
  387. // DfsCompleteRequest( IrpContext, NULL, DontCare ); // deallocates context
  388. //
  389. // This would typically be done in order to pass a "naked" IrpContext off to the
  390. // Fsp for post processing, such as read ahead.
  391. //
  392. VOID
  393. DfsCompleteRequest_Real (
  394. IN PIRP_CONTEXT IrpContext,
  395. IN PIRP Irp,
  396. IN NTSTATUS Status
  397. );
  398. #define DfsCompleteRequest(IRPCONTEXT,IRP,STATUS) { \
  399. DfsCompleteRequest_Real(IRPCONTEXT,IRP,STATUS); \
  400. }
  401. //
  402. // The following two macros are used by the Fsd/Fsp exception handlers to
  403. // process an exception. The first macro is the exception filter used in
  404. // the Fsd/Fsp to decide if an exception should be handled at this level.
  405. // The second macro decides if the exception is to be finished off by
  406. // completing the IRP, and cleaning up the Irp Context, or if we should
  407. // bugcheck. Exception values such as STATUS_FILE_INVALID (raised by
  408. // VerfySup.c) cause us to complete the Irp and cleanup, while exceptions
  409. // such as accvio cause us to bugcheck.
  410. //
  411. // The basic structure for fsd/fsp exception handling is as follows:
  412. //
  413. // DfsFsdXxx(...)
  414. // {
  415. // try {
  416. //
  417. // ...
  418. //
  419. // } except(DfsExceptionFilter("Xxx\n")) {
  420. //
  421. // DfsProcessException( IrpContext, Irp, &Status );
  422. // }
  423. //
  424. // Return Status;
  425. // }
  426. //
  427. // LONG
  428. // DfsExceptionFilter (
  429. // IN PSZ String
  430. // );
  431. //
  432. // VOID
  433. // DfsProcessException (
  434. // IN PIRP_CONTEXT IrpContext,
  435. // IN PIRP Irp,
  436. // IN PNTSTATUS ExceptionCode
  437. // );
  438. //
  439. LONG
  440. DfsExceptionFilter (
  441. IN PIRP_CONTEXT IrpContext,
  442. IN NTSTATUS ExceptionCode,
  443. IN PEXCEPTION_POINTERS ExceptionPointer
  444. );
  445. NTSTATUS
  446. DfsProcessException (
  447. IN PIRP_CONTEXT IrpContext,
  448. IN PIRP Irp,
  449. IN NTSTATUS ExceptionCode
  450. );
  451. //
  452. // VOID
  453. // DfsRaiseStatus (
  454. // IN PRIP_CONTEXT IrpContext,
  455. // IN NT_STATUS Status
  456. // );
  457. //
  458. //
  459. #define DfsRaiseStatus(IRPCONTEXT,STATUS) { \
  460. (IRPCONTEXT)->ExceptionStatus = (STATUS); \
  461. ExRaiseStatus( (STATUS) ); \
  462. BugCheck( "DfsRaiseStatus " #STATUS ); \
  463. }
  464. //
  465. // The following macros are used to establish the semantics needed
  466. // to do a return from within a try-finally clause. As a rule every
  467. // try clause must end with a label call try_exit. For example,
  468. //
  469. // try {
  470. // :
  471. // :
  472. //
  473. // try_exit: NOTHING;
  474. // } finally {
  475. //
  476. // :
  477. // :
  478. // }
  479. //
  480. // Every return statement executed inside of a try clause should use the
  481. // try_return macro. If the compiler fully supports the try-finally construct
  482. // then the macro should be
  483. //
  484. // #define try_return(S) { return(S); }
  485. //
  486. // If the compiler does not support the try-finally construct then the macro
  487. // should be
  488. //
  489. // #define try_return(S) { S; goto try_exit; }
  490. //
  491. #define try_return(S) { S; goto try_exit; }
  492. #endif // _DFSPROCS_