Source code of Windows XP (NT5)
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.

313 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. groveler.h
  5. Abstract:
  6. SIS Groveler file groveling headers
  7. Authors:
  8. Cedric Krumbein, 1998
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #define CS_DIR_PATH _T("\\SIS Common Store")
  14. #define GROVELER_FILE_NAME _T("GrovelerFile")
  15. #define DATABASE_FILE_NAME _T("database.mdb")
  16. #define DATABASE_DELETE_RES_FILE_NAME _T("res*.log")
  17. #define DATABASE_DELETE_LOG_FILE_NAME _T("*.log")
  18. #define LAST_USN_NAME _T("LastUSN")
  19. #define USN_ID_NAME _T("UsnID")
  20. #define MIN_FILE_SIZE 1
  21. #define MIN_GROVEL_INTERVAL 600000000 // One minute
  22. #define SIG_PAGE_SIZE 4096
  23. #define CMP_PAGE_SIZE 65536
  24. #define MAX_ACTIONS_PER_TRANSACTION 64
  25. #define UNINITIALIZED_USN MAXLONGLONG
  26. // Groveler class definitions
  27. enum GrovelStatus {
  28. Grovel_ok,
  29. Grovel_pending,
  30. Grovel_error,
  31. Grovel_overrun,
  32. Grovel_new,
  33. Grovel_disable
  34. };
  35. struct FileData {
  36. SGNativeTableEntry entry;
  37. DWORDLONG parentID,
  38. retryTime;
  39. HANDLE handle;
  40. DWORD startTime,
  41. stopTime;
  42. OVERLAPPED readSynch,
  43. oplock;
  44. TCHAR fileName[MAX_PATH+1];
  45. BYTE *buffer [2];
  46. };
  47. enum DatabaseActionType {
  48. TABLE_PUT,
  49. TABLE_DELETE_BY_FILE_ID,
  50. QUEUE_PUT,
  51. QUEUE_DELETE
  52. };
  53. struct DatabaseActionList {
  54. DatabaseActionType type;
  55. union {
  56. SGNativeTableEntry *tableEntry;
  57. DWORDLONG fileID;
  58. SGNativeQueueEntry *queueEntry;
  59. DWORD queueIndex;
  60. } u;
  61. };
  62. class Groveler {
  63. private:
  64. TCHAR *driveName,
  65. *driveLetterName,
  66. *databaseName,
  67. **disallowedNames;
  68. DWORD sectorSize,
  69. sigReportThreshold,
  70. cmpReportThreshold,
  71. numDisallowedNames,
  72. numDisallowedIDs,
  73. disallowedAttributes,
  74. startAllottedTime,
  75. timeAllotted,
  76. hashCount,
  77. hashReadCount,
  78. hashReadTime,
  79. compareCount,
  80. compareReadCount,
  81. compareReadTime,
  82. matchCount,
  83. mergeCount,
  84. mergeTime,
  85. numFilesEnqueued,
  86. numFilesDequeued;
  87. DWORDLONG *disallowedIDs,
  88. *inUseFileID1,
  89. *inUseFileID2,
  90. usnID,
  91. minFileSize,
  92. minFileAge,
  93. grovelInterval,
  94. lastUSN,
  95. hashBytes,
  96. compareBytes,
  97. matchBytes,
  98. mergeBytes;
  99. HANDLE volumeHandle,
  100. grovHandle,
  101. grovelStartEvent,
  102. grovelStopEvent,
  103. grovelThread;
  104. SGDatabase *sgDatabase;
  105. GrovelStatus grovelStatus;
  106. BOOL abortGroveling,
  107. inScan,
  108. inCompare,
  109. terminate;
  110. BOOL IsAllowedID(DWORDLONG fileID) const;
  111. BOOL IsAllowedName(TCHAR *fileName) const;
  112. VOID WaitForEvent(HANDLE event);
  113. BOOL OpenFileByID(
  114. FileData *file,
  115. BOOL writeEnable);
  116. BOOL OpenFileByName(
  117. FileData *file,
  118. BOOL writeEnable,
  119. TCHAR *fileName = NULL);
  120. BOOL IsFileMapped(FileData *file);
  121. BOOL SetOplock(FileData *file);
  122. VOID CloseFile(FileData *file);
  123. BOOL CreateDatabase(void);
  124. VOID DoTransaction(
  125. DWORD numActions,
  126. DatabaseActionList *actionList);
  127. VOID EnqueueCSIndex(CSID *csIndex);
  128. VOID SigCheckPoint(
  129. FileData *target,
  130. BOOL targetRead);
  131. VOID CmpCheckPoint(
  132. FileData *target,
  133. FileData *match,
  134. BOOL targetRead,
  135. BOOL matchRead);
  136. BOOL MergeCheckPoint(
  137. FileData *target,
  138. FileData *match,
  139. OVERLAPPED *mergeSynch,
  140. HANDLE abortMergeEvent,
  141. BOOL merge);
  142. BOOL GetTarget(
  143. FileData *target,
  144. DWORD *queueIndex);
  145. VOID CalculateSignature(FileData *target);
  146. VOID GetMatchList(
  147. FileData *target,
  148. FIFO *matchList,
  149. Table *csIndexTable);
  150. BOOL GetCSFile(
  151. FileData *target,
  152. FileData *match,
  153. Table *csIndexTable);
  154. BOOL GetMatch(
  155. FileData *target,
  156. FileData *match,
  157. FIFO *matchList);
  158. BOOL Compare(
  159. FileData *target,
  160. FileData *match);
  161. BOOL Merge(
  162. FileData *target,
  163. FileData *match,
  164. OVERLAPPED *mergeSynch,
  165. HANDLE abortMergeEvent);
  166. VOID Worker();
  167. GrovelStatus extract_log2(
  168. OUT DWORD *num_entries_extracted,
  169. OUT DWORDLONG *num_bytes_extracted,
  170. OUT DWORDLONG *num_bytes_skipped,
  171. OUT DWORD *num_files_enqueued,
  172. OUT DWORD *num_files_dequeued);
  173. static DWORD WorkerThread(VOID *groveler);
  174. public:
  175. static BOOL is_sis_installed(const _TCHAR *drive_name);
  176. static BOOL set_log_drive(const _TCHAR *drive_name);
  177. Groveler();
  178. ~Groveler();
  179. GrovelStatus open(
  180. IN const TCHAR *drive_name,
  181. IN const TCHAR *drive_letterName,
  182. IN BOOL is_log_drive,
  183. IN DOUBLE read_report_discard_threshold,
  184. IN DWORD min_file_size,
  185. IN DWORD min_file_age,
  186. IN BOOL allow_compressed_files,
  187. IN BOOL allow_encrypted_files,
  188. IN BOOL allow_hidden_files,
  189. IN BOOL allow_offline_files,
  190. IN BOOL allow_temporary_files,
  191. IN DWORD num_excluded_paths,
  192. IN const TCHAR **excluded_paths,
  193. IN DWORD base_regrovel_interval,
  194. IN DWORD max_regrovel_interval);
  195. GrovelStatus close();
  196. GrovelStatus scan_volume(
  197. IN DWORD time_allotted,
  198. IN BOOL start_over,
  199. OUT DWORD *time_consumed,
  200. OUT DWORD *findfirst_count,
  201. OUT DWORD *findnext_count,
  202. OUT DWORD *count_of_files_enqueued);
  203. GrovelStatus set_usn_log_size(
  204. IN DWORDLONG usn_log_size);
  205. GrovelStatus get_usn_log_info(
  206. OUT USN_JOURNAL_DATA *usnJournalData);
  207. GrovelStatus extract_log(
  208. OUT DWORD *num_entries_extracted,
  209. OUT DWORDLONG *num_bytes_extracted,
  210. OUT DWORDLONG *num_bytes_skipped,
  211. OUT DWORD *num_files_enqueued,
  212. OUT DWORD *num_files_dequeued);
  213. GrovelStatus grovel(
  214. IN DWORD time_allotted,
  215. OUT DWORD *hash_read_ops,
  216. OUT DWORD *hash_read_time,
  217. OUT DWORD *count_of_files_hashed,
  218. OUT DWORDLONG *bytes_of_files_hashed,
  219. OUT DWORD *compare_read_ops,
  220. OUT DWORD *compare_read_time,
  221. OUT DWORD *count_of_files_compared,
  222. OUT DWORDLONG *bytes_of_files_compared,
  223. OUT DWORD *count_of_files_matching,
  224. OUT DWORDLONG *bytes_of_files_matching,
  225. OUT DWORD *merge_time,
  226. OUT DWORD *count_of_files_merged,
  227. OUT DWORDLONG *bytes_of_files_merged,
  228. OUT DWORD *count_of_files_enqueued,
  229. OUT DWORD *count_of_files_dequeued);
  230. DWORD count_of_files_in_queue() const;
  231. DWORD count_of_files_to_compare() const;
  232. DWORD time_to_first_file_ready() const;
  233. };
  234. // Special debugging flags
  235. // #define DEBUG_USN_REASON
  236. // #define DEBUG_GET_BY_ATTR
  237. // #define DEBUG_UNTHROTTLED