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.

419 lines
11 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. control.c
  5. Abstract:
  6. User-mode interface to SR.SYS.
  7. Author:
  8. Keith Moore (keithmo) 15-Dec-1998
  9. Paul McDaniel (paulmcd) 07-Mar-2000 (sr)
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. //
  14. // Private macros.
  15. //
  16. //
  17. // Private prototypes.
  18. //
  19. //
  20. // Public functions.
  21. //
  22. /***************************************************************************++
  23. Routine Description:
  24. Opens a control channel to SR.SYS.
  25. Arguments:
  26. Options - Supplies zero or more SR_OPTION_* flags.
  27. pControlHandle - Receives a handle to the control channel if successful.
  28. Return Value:
  29. ULONG - Completion status.
  30. --***************************************************************************/
  31. ULONG
  32. WINAPI
  33. SrCreateControlHandle(
  34. IN ULONG Options,
  35. OUT PHANDLE pControlHandle
  36. )
  37. {
  38. NTSTATUS status;
  39. //
  40. // First, just try to open the driver.
  41. //
  42. status = SrpOpenDriverHelper(
  43. pControlHandle, // pHandle
  44. GENERIC_READ | // DesiredAccess
  45. GENERIC_WRITE |
  46. SYNCHRONIZE,
  47. Options, // Options
  48. FILE_OPEN, // CreateDisposition
  49. NULL // pSecurityAttributes
  50. );
  51. //
  52. // If we couldn't open the driver because it's not running, then try
  53. // to start the driver & retry the open.
  54. //
  55. if (status == STATUS_OBJECT_NAME_NOT_FOUND ||
  56. status == STATUS_OBJECT_PATH_NOT_FOUND)
  57. {
  58. if (SrpTryToStartDriver())
  59. {
  60. status = SrpOpenDriverHelper(
  61. pControlHandle, // pHandle
  62. GENERIC_READ | // DesiredAccess
  63. GENERIC_WRITE |
  64. SYNCHRONIZE,
  65. Options, // Options
  66. FILE_OPEN, // CreateDisposition
  67. NULL // pSecurityAttributes
  68. );
  69. }
  70. }
  71. return SrpNtStatusToWin32Status( status );
  72. } // SrCreateControlHandle
  73. /***************************************************************************++
  74. Routine Description:
  75. SrCreateRestorePoint is called by the controlling application to declare
  76. a new restore point. The driver will create a local restore directory
  77. and then return a unique sequence number to the controlling app.
  78. Arguments:
  79. ControlHandle - the control HANDLE.
  80. pNewSequenceNumber - holds the new sequnce number on return.
  81. Return Value:
  82. ULONG - Completion status.
  83. --***************************************************************************/
  84. ULONG
  85. WINAPI
  86. SrCreateRestorePoint(
  87. IN HANDLE ControlHandle,
  88. OUT PULONG pNewRestoreNumber
  89. )
  90. {
  91. NTSTATUS Status;
  92. //
  93. // Make the request.
  94. //
  95. Status =
  96. SrpSynchronousDeviceControl( ControlHandle, // FileHandle
  97. IOCTL_SR_CREATE_RESTORE_POINT, // IoControlCode
  98. NULL, // pInputBuffer
  99. 0, // InputBufferLength
  100. pNewRestoreNumber, // pOutputBuffer
  101. sizeof(ULONG), // OutputBufferLength
  102. NULL ); // pBytesTransferred
  103. return SrpNtStatusToWin32Status( Status );
  104. } // SrCreateRestorePoint
  105. /***************************************************************************++
  106. Routine Description:
  107. SrGetNextSequenceNum is called by the application to get the next
  108. available sequence number from the driver.
  109. Arguments:
  110. ControlHandle - the control HANDLE.
  111. pNewSequenceNumber - holds the new sequnce number on return.
  112. Return Value:
  113. ULONG - Completion status.
  114. --***************************************************************************/
  115. ULONG
  116. WINAPI
  117. SrGetNextSequenceNum(
  118. IN HANDLE ControlHandle,
  119. OUT PINT64 pNextSequenceNum
  120. )
  121. {
  122. NTSTATUS Status;
  123. //
  124. // Make the request.
  125. //
  126. Status =
  127. SrpSynchronousDeviceControl( ControlHandle, // FileHandle
  128. IOCTL_SR_GET_NEXT_SEQUENCE_NUM,
  129. NULL, // pInputBuffer
  130. 0, // InputBufferLength
  131. pNextSequenceNum, // pOutputBuffer
  132. sizeof(INT64), // OutputBufferLength
  133. NULL ); // pBytesTransferred
  134. return SrpNtStatusToWin32Status( Status );
  135. } // SrCreateRestorePoint
  136. /***************************************************************************++
  137. Routine Description:
  138. SrReloadConfiguration causes the driver to reload it's configuration
  139. from it's configuration file that resides in a preassigned location.
  140. A controlling service can update this file, then alert the driver to
  141. reload it.
  142. Arguments:
  143. ControlHandle - the control HANDLE.
  144. Return Value:
  145. ULONG - Completion status.
  146. --***************************************************************************/
  147. ULONG
  148. WINAPI
  149. SrReloadConfiguration(
  150. IN HANDLE ControlHandle
  151. )
  152. {
  153. NTSTATUS Status;
  154. //
  155. // Make the request.
  156. //
  157. Status =
  158. SrpSynchronousDeviceControl( ControlHandle, // FileHandle
  159. IOCTL_SR_RELOAD_CONFIG, // IoControlCode
  160. NULL, // pInputBuffer
  161. 0, // InputBufferLength
  162. NULL, // pOutputBuffer
  163. 0, // OutputBufferLength
  164. NULL ); // pBytesTransferred
  165. return SrpNtStatusToWin32Status( Status );
  166. } // SrReloadConfiguration
  167. /***************************************************************************++
  168. Routine Description:
  169. SrStopMonitoring will cause the driver to stop monitoring file changes.
  170. The default state of the driver on startup is to monitor file changes.
  171. Arguments:
  172. ControlHandle - the control HANDLE.
  173. Return Value:
  174. ULONG - Completion status.
  175. --***************************************************************************/
  176. ULONG
  177. WINAPI
  178. SrStopMonitoring(
  179. IN HANDLE ControlHandle
  180. )
  181. {
  182. NTSTATUS Status;
  183. //
  184. // Make the request.
  185. //
  186. Status =
  187. SrpSynchronousDeviceControl( ControlHandle, // FileHandle
  188. IOCTL_SR_STOP_MONITORING, // IoControlCode
  189. NULL, // pInputBuffer
  190. 0, // InputBufferLength
  191. NULL, // pOutputBuffer
  192. 0, // OutputBufferLength
  193. NULL ); // pBytesTransferred
  194. return SrpNtStatusToWin32Status( Status );
  195. } // SrStopMonitoring
  196. /***************************************************************************++
  197. Routine Description:
  198. SrStartMonitoring will cause the driver to start monitoring file changes.
  199. The default state of the driver on startup is to monitor file changes.
  200. This api is only needed in the case that the controlling application has
  201. called SrStopMonitoring and wishes to restart it.
  202. Arguments:
  203. ControlHandle - the control HANDLE.
  204. Return Value:
  205. ULONG - Completion status.
  206. --***************************************************************************/
  207. ULONG
  208. WINAPI
  209. SrStartMonitoring(
  210. IN HANDLE ControlHandle
  211. )
  212. {
  213. NTSTATUS Status;
  214. //
  215. // Make the request.
  216. //
  217. Status =
  218. SrpSynchronousDeviceControl( ControlHandle, // FileHandle
  219. IOCTL_SR_START_MONITORING, // IoControlCode
  220. NULL, // pInputBuffer
  221. 0, // InputBufferLength
  222. NULL, // pOutputBuffer
  223. 0, // OutputBufferLength
  224. NULL ); // pBytesTransferred
  225. return SrpNtStatusToWin32Status( Status );
  226. } // SrStartMonitoring
  227. /***************************************************************************++
  228. Routine Description:
  229. SrDisableVolume is used to temporarily disable monitoring on the
  230. specified volume. this is reset by a call to SrReloadConfiguration.
  231. There is no EnableVolume.
  232. Arguments:
  233. ControlHandle - the HANDLE from SrCreateControlHandle.
  234. pVolumeName - the name of the volume to disable, in the nt format of
  235. \Device\HarddiskDmVolumes\PhysicalDmVolumes\BlockVolume3.
  236. Return Value:
  237. ULONG - Completion status.
  238. --***************************************************************************/
  239. ULONG
  240. WINAPI
  241. SrDisableVolume(
  242. IN HANDLE ControlHandle,
  243. IN PWSTR pVolumeName
  244. )
  245. {
  246. NTSTATUS Status;
  247. //
  248. // Make the request.
  249. //
  250. Status =
  251. SrpSynchronousDeviceControl( ControlHandle, // FileHandle
  252. IOCTL_SR_DISABLE_VOLUME, // IoControlCode
  253. pVolumeName,// pInputBuffer
  254. (lstrlenW(pVolumeName)+1)*sizeof(WCHAR),// InputBufferLength
  255. NULL, // pOutputBuffer
  256. 0, // OutputBufferLength
  257. NULL ); // pBytesTransferred
  258. return SrpNtStatusToWin32Status( Status );
  259. } // SrDisableVolume
  260. /***************************************************************************++
  261. Routine Description:
  262. SrSwitchAllLogs is used to cause the filter to close all of the open
  263. log files on all volumes, and use new log files. this is used so that
  264. another process can parse these files without worrying about the filter
  265. writing to them. use this to get a consistent view of the restore point.
  266. Arguments:
  267. ControlHandle - the HANDLE from SrCreateControlHandle.
  268. Return Value:
  269. ULONG - Completion status.
  270. --***************************************************************************/
  271. ULONG
  272. WINAPI
  273. SrSwitchAllLogs(
  274. IN HANDLE ControlHandle
  275. )
  276. {
  277. NTSTATUS Status;
  278. //
  279. // Make the request.
  280. //
  281. Status =
  282. SrpSynchronousDeviceControl( ControlHandle, // FileHandle
  283. IOCTL_SR_SWITCH_LOG, // IoControlCode
  284. NULL, // pInputBuffer
  285. 0, // InputBufferLength
  286. NULL, // pOutputBuffer
  287. 0, // OutputBufferLength
  288. NULL ); // pBytesTransferred
  289. return SrpNtStatusToWin32Status( Status );
  290. } // SrSwitchAllLogs
  291. //
  292. // Private functions.
  293. //