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.

527 lines
15 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. srapi.h
  5. Abstract:
  6. This module defines the public System Restore interface for nt.
  7. Author:
  8. Paul McDaniel (paulmcd) 24-Feb-2000
  9. Revision History:
  10. Paul McDaniel (paulmcd) 18-Apr-2000 completely new version
  11. --*/
  12. #ifndef _SRAPI_H_
  13. #define _SRAPI_H_
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /***************************************************************************++
  18. Routine Description:
  19. SrCreateControlHandle is used to retrieve a HANDLE that can be used
  20. to perform control operations on the driver.
  21. Arguments:
  22. pControlHandle - receives the newly created HANDLE. The controlling
  23. application must call CloseHandle when it is done.
  24. Options - one of the below options.
  25. Return Value:
  26. ULONG - Completion status.
  27. --***************************************************************************/
  28. #define SR_OPTION_OVERLAPPED 0x00000001 // for async
  29. #define SR_OPTION_VALID 0x00000001 //
  30. ULONG
  31. WINAPI
  32. SrCreateControlHandle (
  33. IN ULONG Options,
  34. OUT PHANDLE pControlHandle
  35. );
  36. /***************************************************************************++
  37. Routine Description:
  38. SrCreateRestorePoint is called by the controlling application to declare
  39. a new restore point. The driver will create a local restore directory
  40. and then return a unique sequence number to the controlling app.
  41. Arguments:
  42. ControlHandle - the control HANDLE.
  43. pNewRestoreNumber - holds the new restore number on return. example: if
  44. the new restore point directory is \_restore\rp5 this will return
  45. the number 5
  46. Return Value:
  47. ULONG - Completion status.
  48. --***************************************************************************/
  49. ULONG
  50. WINAPI
  51. SrCreateRestorePoint (
  52. IN HANDLE ControlHandle,
  53. OUT PULONG pNewRestoreNumber
  54. );
  55. /***************************************************************************++
  56. Routine Description:
  57. SrGetNextSequenceNum is called by the application to get the next
  58. available sequence number from the driver.
  59. Arguments:
  60. ControlHandle - the control HANDLE.
  61. pNewSequenceNumber - holds the new sequnce number on return.
  62. Return Value:
  63. ULONG - Completion status.
  64. --***************************************************************************/
  65. ULONG
  66. WINAPI
  67. SrGetNextSequenceNum(
  68. IN HANDLE ControlHandle,
  69. OUT PINT64 pNextSequenceNum
  70. );
  71. /***************************************************************************++
  72. Routine Description:
  73. SrReloadConfiguration causes the driver to reload it's configuration
  74. from it's configuration file that resides in a preassigned location.
  75. A controlling service can update this file, then alert the driver to
  76. reload it.
  77. this file is %systemdrive%\_restore\_exclude.cfg .
  78. Arguments:
  79. ControlHandle - the control HANDLE.
  80. Return Value:
  81. ULONG - Completion status.
  82. --***************************************************************************/
  83. ULONG
  84. WINAPI
  85. SrReloadConfiguration (
  86. IN HANDLE ControlHandle
  87. );
  88. /***************************************************************************++
  89. Routine Description:
  90. SrStopMonitoring will cause the driver to stop monitoring file changes.
  91. The default state of the driver on startup is to monitor file changes.
  92. Arguments:
  93. ControlHandle - the control HANDLE.
  94. Return Value:
  95. ULONG - Completion status.
  96. --***************************************************************************/
  97. ULONG
  98. WINAPI
  99. SrStopMonitoring (
  100. IN HANDLE ControlHandle
  101. );
  102. /***************************************************************************++
  103. Routine Description:
  104. SrStartMonitoring will cause the driver to start monitoring file changes.
  105. The default state of the driver on startup is to monitor file changes.
  106. This api is only needed in the case that the controlling application has
  107. called SrStopMonitoring and wishes to restart it.
  108. Arguments:
  109. ControlHandle - the control HANDLE.
  110. Return Value:
  111. ULONG - Completion status.
  112. --***************************************************************************/
  113. ULONG
  114. WINAPI
  115. SrStartMonitoring (
  116. IN HANDLE ControlHandle
  117. );
  118. //
  119. // these are the interesting types of events that can happen.
  120. //
  121. typedef enum _SR_EVENT_TYPE
  122. {
  123. SrEventInvalid = 0, // no action has been set
  124. SrEventStreamChange = 0x01, // data is being changed in a stream
  125. SrEventAclChange = 0x02, // an acl on a file or directory is changing
  126. SrEventAttribChange = 0x04, // an attribute on a file or directory is changing
  127. SrEventStreamOverwrite = 0x08, // a stream is being opened for overwrite
  128. SrEventFileDelete = 0x10, // a file is being opened for delete
  129. SrEventFileCreate = 0x20, // a file is newly created, not overwriting anything
  130. SrEventFileRename = 0x40, // a file is renamed (within monitored space)
  131. SrEventDirectoryCreate = 0x80, // a dir is created
  132. SrEventDirectoryRename = 0x100, // a dir is renamed (within monitored space)
  133. SrEventDirectoryDelete = 0x200, // an empty dir is deleted
  134. SrEventMountCreate = 0x400, // a mount point was created
  135. SrEventMountDelete = 0x800, // a mount point was deleted
  136. SrEventVolumeError = 0x1000, // a non-recoverable error occurred on the volume
  137. SrEventMaximum = 0x1000,
  138. SrEventStreamCreate = 0x2000, // a stream has been created. This will never
  139. // be logged, but is used to make sure that
  140. // we handle stream creations correctly.
  141. SrEventLogMask = 0xffff,
  142. //
  143. // flags
  144. //
  145. SrEventNoOptimization = 0x00010000, // this flag on means no optimizations are to be performed
  146. SrEventIsDirectory = 0x00020000, // this event happened on a directory
  147. SrEventIsNotDirectory = 0x00040000, // this event happened on a non-directory (file)
  148. SrEventSimulatedDelete = 0x00080000, // when set this is a simulated DELETE operation --
  149. // the file is not really being deleted, but to
  150. // SR it looks like a delete.
  151. SrEventInPreCreate = 0x00100000, // when set, the create has not yet been succeeded by the filesystem
  152. SrEventOpenById = 0x00200000 // when set, the create has not yet been succeeded by the filesystem
  153. // and this file is being opened by ID.
  154. } SR_EVENT_TYPE;
  155. //
  156. // this structure represents a notification from kernel mode
  157. // to user mode. This is because of interesting volume activity
  158. //
  159. typedef enum _SR_NOTIFICATION_TYPE
  160. {
  161. SrNotificationInvalid = 0, // no action has been set
  162. SrNotificationVolumeFirstWrite, // The first write on a volume occured
  163. SrNotificationVolume25MbWritten,// 25 meg has been written the the volume
  164. SrNotificationVolumeError, // A backup just failed, Context holds the win32 code.
  165. SrNotificationMaximum
  166. } SR_NOTIFICATION_TYPE, * PSR_NOTIFICATION_TYPE;
  167. #define SR_NOTIFY_BYTE_COUNT 25 * (1024 * 1024)
  168. //
  169. // this the largest nt path the sr chooses to monitor. paths larger than
  170. // this will be silently ignored and passed down to the file system
  171. // unmonitored.
  172. //
  173. // NOTE: This lenght INCLUDES the terminating NULL at the end of the
  174. // filename string.
  175. //
  176. #define SR_MAX_FILENAME_LENGTH 1000
  177. //
  178. // Restore needs to prepend the volume guid in addition to the filepath --
  179. // so the maximum filepath length relative to the volume that can be supported
  180. // is 1000 - strlen(guid) = 952 characters
  181. // restore also appends suffixes like (2) to these names in cases of locked or
  182. // conflicting files, so to be really safe, we choose an even smaller number
  183. //
  184. #define SR_MAX_FILENAME_PATH 940
  185. #define MAKE_TAG(tag) ( (ULONG)(tag) )
  186. #define SR_NOTIFICATION_RECORD_TAG MAKE_TAG( 'RNrS' )
  187. #define IS_VALID_NOTIFICATION_RECORD(pObject) \
  188. (((pObject) != NULL) && ((pObject)->Signature == SR_NOTIFICATION_RECORD_TAG))
  189. typedef struct _SR_NOTIFICATION_RECORD
  190. {
  191. //
  192. // SR_NOTIFICATION_RECORD_TAG
  193. //
  194. ULONG Signature;
  195. //
  196. // reserved
  197. //
  198. LIST_ENTRY ListEntry;
  199. //
  200. // the type of notification
  201. //
  202. SR_NOTIFICATION_TYPE NotificationType;
  203. //
  204. // the name of the volume being notified for
  205. //
  206. UNICODE_STRING VolumeName;
  207. //
  208. // a context/parameter
  209. //
  210. ULONG Context;
  211. } SR_NOTIFICATION_RECORD, * PSR_NOTIFICATION_RECORD;
  212. /***************************************************************************++
  213. Routine Description:
  214. SrWaitForNotificaiton is used to receive volume activity notifications
  215. from the driver. This includes new volume, delete volume, and out of disk
  216. space for a volume.
  217. Arguments:
  218. ControlHandle - the HANDLE from SrCreateControlHandle.
  219. pNotification - the buffer to hold the NOTIFICATION_RECORD.
  220. NotificationLength - the length in bytes of pNotification
  221. pOverlapped - an OVERLAPPED structure if async io is enabled on the
  222. HANDLE.
  223. Return Value:
  224. ULONG - Completion status.
  225. --***************************************************************************/
  226. ULONG
  227. WINAPI
  228. SrWaitForNotification (
  229. IN HANDLE ControlHandle,
  230. OUT PSR_NOTIFICATION_RECORD pNotification,
  231. IN ULONG NotificationLength,
  232. IN LPOVERLAPPED pOverlapped OPTIONAL
  233. );
  234. /***************************************************************************++
  235. Routine Description:
  236. SrSwitchAllLogs is used to cause the filter to close all of the open
  237. log files on all volumes, and use new log files. this is used so that
  238. another process can parse these files without worrying about the filter
  239. writing to them. use this to get a consistent view of the restore point.
  240. Arguments:
  241. ControlHandle - the HANDLE from SrCreateControlHandle.
  242. Return Value:
  243. ULONG - Completion status.
  244. --***************************************************************************/
  245. ULONG
  246. WINAPI
  247. SrSwitchAllLogs (
  248. IN HANDLE ControlHandle
  249. );
  250. /***************************************************************************++
  251. Routine Description:
  252. SrDisableVolume is used to temporarily disable monitoring on the
  253. specified volume. this is reset by a call to SrReloadConfiguration.
  254. There is no EnableVolume.
  255. Arguments:
  256. ControlHandle - the HANDLE from SrCreateControlHandle.
  257. pVolumeName - the name of the volume to disable, in the nt format of
  258. \Device\HarddiskDmVolumes\PhysicalDmVolumes\BlockVolume3.
  259. Return Value:
  260. ULONG - Completion status.
  261. --***************************************************************************/
  262. ULONG
  263. WINAPI
  264. SrDisableVolume (
  265. IN HANDLE ControlHandle,
  266. IN PWSTR pVolumeName
  267. );
  268. #define _SR_REQUEST(ioctl) \
  269. ((((ULONG)(ioctl)) >> 2) & 0x03FF)
  270. #define SR_CREATE_RESTORE_POINT 0
  271. #define SR_RELOAD_CONFIG 1
  272. #define SR_START_MONITORING 2
  273. #define SR_STOP_MONITORING 3
  274. #define SR_WAIT_FOR_NOTIFICATION 4
  275. #define SR_SWITCH_LOG 5
  276. #define SR_DISABLE_VOLUME 6
  277. #define SR_GET_NEXT_SEQUENCE_NUM 7
  278. #define SR_NUM_IOCTLS 8
  279. #define IOCTL_SR_CREATE_RESTORE_POINT CTL_CODE( FILE_DEVICE_UNKNOWN, SR_CREATE_RESTORE_POINT, METHOD_BUFFERED, FILE_WRITE_ACCESS )
  280. #define IOCTL_SR_RELOAD_CONFIG CTL_CODE( FILE_DEVICE_UNKNOWN, SR_RELOAD_CONFIG, METHOD_NEITHER, FILE_WRITE_ACCESS )
  281. #define IOCTL_SR_START_MONITORING CTL_CODE( FILE_DEVICE_UNKNOWN, SR_START_MONITORING, METHOD_NEITHER, FILE_WRITE_ACCESS )
  282. #define IOCTL_SR_STOP_MONITORING CTL_CODE( FILE_DEVICE_UNKNOWN, SR_STOP_MONITORING, METHOD_NEITHER, FILE_WRITE_ACCESS )
  283. #define IOCTL_SR_WAIT_FOR_NOTIFICATION CTL_CODE( FILE_DEVICE_UNKNOWN, SR_WAIT_FOR_NOTIFICATION, METHOD_OUT_DIRECT, FILE_READ_ACCESS )
  284. #define IOCTL_SR_SWITCH_LOG CTL_CODE( FILE_DEVICE_UNKNOWN, SR_SWITCH_LOG, METHOD_NEITHER, FILE_WRITE_ACCESS )
  285. #define IOCTL_SR_DISABLE_VOLUME CTL_CODE( FILE_DEVICE_UNKNOWN, SR_DISABLE_VOLUME, METHOD_BUFFERED, FILE_WRITE_ACCESS )
  286. #define IOCTL_SR_GET_NEXT_SEQUENCE_NUM CTL_CODE( FILE_DEVICE_UNKNOWN, SR_GET_NEXT_SEQUENCE_NUM,METHOD_BUFFERED, FILE_WRITE_ACCESS )
  287. //
  288. // Names of the object directory, devices, driver, and service.
  289. //
  290. #define SR_CONTROL_DEVICE_NAME L"\\FileSystem\\Filters\\SystemRestore"
  291. #define SR_DRIVER_NAME L"SR.SYS"
  292. #define SR_SERVICE_NAME L"SR"
  293. //
  294. // The current interface version number. This version number must be
  295. // updated after any significant changes to the interface (especially
  296. // structure changes).
  297. //
  298. #define SR_INTERFACE_VERSION_MAJOR 0x0000
  299. #define SR_INTERFACE_VERSION_MINOR 0x0005
  300. //
  301. // The name of the EA (Extended Attribute) passed to NtCreateFile(). This
  302. // allows us to pass version information at the time the driver is opened,
  303. // allowing SR.SYS to immediately fail open requests with invalid version
  304. // numbers.
  305. //
  306. // N.B. The EA name (including the terminator) must be a multiple of eight
  307. // to ensure natural alignment of the SR_OPEN_PACKET structure used as
  308. // the EA value.
  309. //
  310. // 7654321076543210
  311. #define SR_OPEN_PACKET_NAME "SrOpenPacket000"
  312. #define SR_OPEN_PACKET_NAME_LENGTH (sizeof(SR_OPEN_PACKET_NAME) - 1)
  313. C_ASSERT( ((SR_OPEN_PACKET_NAME_LENGTH + 1) & 7) == 0 );
  314. //
  315. // The following structure is used as the value for the EA named above.
  316. //
  317. typedef struct SR_OPEN_PACKET
  318. {
  319. USHORT MajorVersion;
  320. USHORT MinorVersion;
  321. } SR_OPEN_PACKET, *PSR_OPEN_PACKET;
  322. //
  323. // Registry paths.
  324. //
  325. #define REGISTRY_PARAMETERS L"\\Parameters"
  326. #define REGISTRY_DEBUG_CONTROL L"DebugControl"
  327. #define REGISTRY_PROCNAME_OFFSET L"ProcessNameOffset"
  328. #define REGISTRY_STARTDISABLED L"FirstRun"
  329. #define REGISTRY_DONTBACKUP L"DontBackup"
  330. #define REGISTRY_MACHINE_GUID L"MachineGuid"
  331. #define REGISTRY_SRSERVICE L"\\SRService"
  332. #define REGISTRY_SRSERVICE_START L"Start"
  333. //
  334. // directory and file paths
  335. //
  336. #define SYSTEM_VOLUME_INFORMATION L"\\System Volume Information"
  337. #define RESTORE_LOCATION SYSTEM_VOLUME_INFORMATION L"\\_restore%ws"
  338. #define GENERAL_RESTORE_LOCATION SYSTEM_VOLUME_INFORMATION L"\\_restore"
  339. #define RESTORE_FILELIST_LOCATION RESTORE_LOCATION L"\\_filelst.cfg"
  340. //
  341. // used as a prefix for restore point subdirs (e.g. \_restore\rp5)
  342. //
  343. #define RESTORE_POINT_PREFIX L"RP"
  344. //
  345. // used as a prefix for the backup files in a restore point subdir
  346. // (e.g. \_restore\rp5\A0000025.dll)
  347. //
  348. #define RESTORE_FILE_PREFIX L"A"
  349. #ifdef __cplusplus
  350. }
  351. #endif
  352. #endif // _SRAPI_H_