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.

195 lines
6.6 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <direct.h>
  6. #include <io.h>
  7. #include <conio.h>
  8. #define GetFileAttributeError 0xFFFFFFFF
  9. #define printval( var, type) printf( #var " = %" #type "\n", var) // macro for debugging
  10. #define READ_BUFFER_SIZE ( 8*1024*sizeof(DWORD)) // 32k blocks
  11. #define ATTRIBUTE_TYPE DWORD
  12. #define GET_ATTRIBUTES( FileName, Attributes) Attributes = GetFileAttributes( FileName)
  13. #define SET_ATTRIBUTES( FileName, Attributes) !SetFileAttributes( FileName, Attributes)
  14. HINSTANCE NtDll; // used to load Dll's rather than link with them
  15. #define WORK_INITIALIZE_ITEM 0
  16. #define WORK_ITEM 1
  17. #define WORK_TERMINATE_ITEM 2
  18. typedef VOID (*PWORKER_ROUTINE)();
  19. typedef struct _WORK_QUEUE {
  20. CRITICAL_SECTION CriticalSection;
  21. HANDLE Semaphore;
  22. LIST_ENTRY Queue;
  23. BOOL Terminating;
  24. PWORKER_ROUTINE WorkerRoutine;
  25. DWORD NumberOfWorkerThreads;
  26. HANDLE WorkerThreads[ 1 ]; // Variable length array
  27. } WORK_QUEUE, *PWORK_QUEUE;
  28. typedef struct _WORK_QUEUE_ITEM {
  29. LIST_ENTRY List;
  30. DWORD Reason;
  31. PWORK_QUEUE WorkQueue;
  32. } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
  33. typedef struct _VIRTUAL_BUFFER {
  34. LPVOID Base;
  35. SIZE_T PageSize;
  36. LPVOID CommitLimit;
  37. LPVOID ReserveLimit;
  38. } VIRTUAL_BUFFER, *PVIRTUAL_BUFFER;
  39. typedef struct _COPY_REQUEST_STATE {
  40. VIRTUAL_BUFFER Buffer;
  41. LPSTR CurrentOutput;
  42. } COPY_REQUEST_STATE, *PCOPY_REQUEST_STATE;
  43. CRITICAL_SECTION CreatePathCriticalSection;
  44. typedef struct _COPY_REQUEST {
  45. WORK_QUEUE_ITEM WorkItem;
  46. LPSTR Destination;
  47. LPSTR FullPathSrc;
  48. ATTRIBUTE_TYPE Attributes;
  49. DWORD SizeLow;
  50. } COPY_REQUEST, *PCOPY_REQUEST;
  51. INT NumberOfWorkerThreads;
  52. DWORD TlsIndex;
  53. PWORK_QUEUE CDWorkQueue;
  54. #define NONREADONLYSYSTEMHIDDEN ( ~( FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))
  55. #define NORMAL_ATTRIBUTES (FILE_ATTRIBUTE_DIRECTORY | \
  56. FILE_ATTRIBUTE_READONLY | \
  57. FILE_ATTRIBUTE_SYSTEM | \
  58. FILE_ATTRIBUTE_HIDDEN | \
  59. FILE_ATTRIBUTE_ARCHIVE)
  60. #define _strrev
  61. FILE *CheckFile;
  62. char CheckFileName[_MAX_PATH];
  63. typedef struct NodeStruct {
  64. char *Name;
  65. FILETIME Time;
  66. ATTRIBUTE_TYPE Attributes;
  67. int Height;
  68. struct NodeStruct *First;
  69. struct NodeStruct *Last;
  70. struct NodeStruct *Left;
  71. struct NodeStruct *Next;
  72. struct NodeStruct *Right;
  73. DWORD SizeHigh;
  74. DWORD SizeLow;
  75. char Flag[5];
  76. struct NodeStruct *DiffNode;
  77. BOOL Process;
  78. } *LinkedFileList; /* linked file list */
  79. typedef struct CFLStruct {
  80. LinkedFileList *List;
  81. char *Path;
  82. } *PCFLStruct;
  83. DWORD ReadBuffer[READ_BUFFER_SIZE/sizeof(DWORD)];
  84. BOOL ProcessModeDefault;
  85. //
  86. // Flags passed to COMPDIR
  87. //
  88. BOOL fBreakLinks;
  89. BOOL fCheckAttribs;
  90. BOOL fCheckBits;
  91. BOOL fChecking;
  92. BOOL fCheckSize;
  93. BOOL fCheckTime;
  94. BOOL fCreateNew;
  95. BOOL fCreateLink;
  96. BOOL fDoNotDelete;
  97. BOOL fDoNotRecurse;
  98. BOOL fDontCopyAttribs;
  99. BOOL fDontLowerCase;
  100. BOOL fExclude;
  101. BOOL fExecute;
  102. BOOL fIgnoreRs; // Ignore Resource, TimeStamps, CheckSums and Rebase Information
  103. BOOL fIgnoreSlmFiles;
  104. BOOL fMatching;
  105. BOOL fMultiThread;
  106. BOOL fOpposite;
  107. BOOL fScript;
  108. BOOL fSpecAttribs;
  109. BOOL fVerbose;
  110. BOOL ExitValue;
  111. BOOL SparseTree;
  112. BOOL NoMapBinaryCompare( char *file1, char *file2);
  113. BOOL BinaryCompare( char *file1, char *file2);
  114. LPSTR CombineThreeStrings( char *FirstString, char *SecondString, char *ThirdString);
  115. void CompDir( char *Path1, char *Path2);
  116. BOOL FilesDiffer( LinkedFileList File1, LinkedFileList File2, char *Path1, char *Path2);
  117. void CompLists( LinkedFileList *AddList, LinkedFileList *DelList, LinkedFileList *DifList, char *Path1, char *Path2);
  118. void CopyNode( char *Destination, LinkedFileList Source, char *FullPathSrc);
  119. DWORD CreateFileList( LPVOID ThreadParameter);
  120. BOOL DelNode( char *name);
  121. BOOL IsFlag( char *argv);
  122. BOOL MyCreatePath( char *Path, BOOL IsDirectory);
  123. BOOL MyCopyFile( LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExists);
  124. void ParseEnvArgs( void);
  125. void ParseArgs( int argc, char *argv[]);
  126. void PrintFile( LinkedFileList File, char *Path, char *DiffPath);
  127. void PrintList( LinkedFileList list);
  128. void ProcessAdd( LinkedFileList List, char *String1, char *String2);
  129. void ProcessDel( LinkedFileList List, char *String);
  130. void ProcessDiff( LinkedFileList List, char *String1, char *String2);
  131. void ProcessLists( LinkedFileList AddList, LinkedFileList DelList, LinkedFileList DifList,
  132. char *Path1, char *Path2 );
  133. void Usage( void);
  134. BOOL AddToList( LinkedFileList Node, LinkedFileList *list);
  135. void CreateNode( LinkedFileList *Node, WIN32_FIND_DATA *Buff);
  136. BOOL InitializeNtDllFunctions();
  137. BOOL MakeLink( char *src, char *dst, BOOL Output);
  138. int NumberOfLinks( char *FileName);
  139. BOOL SisCopyFile( LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExists, LPBOOL fTrySis);
  140. PWORK_QUEUE CreateWorkQueue( IN DWORD NumberOfWorkerThreads, IN PWORKER_ROUTINE WorkerRoutine);
  141. VOID ProcessRequest( IN PWORK_QUEUE_ITEM WorkItem);
  142. VOID DestroyWorkQueue( IN OUT PWORK_QUEUE WorkQueue);
  143. DWORD WorkerThread( LPVOID lpThreadParameter);
  144. VOID DestroyWorkQueue( IN OUT PWORK_QUEUE WorkQueue);
  145. BOOL QueueWorkItem( IN OUT PWORK_QUEUE WorkQueue, IN PWORK_QUEUE_ITEM WorkItem);
  146. VOID ProcessCopyFile( IN PCOPY_REQUEST WorkerRequest, IN PCOPY_REQUEST_STATE State);
  147. BOOL CreateVirtualBuffer( OUT PVIRTUAL_BUFFER Buffer, IN SIZE_T CommitSize, IN SIZE_T ReserveSize OPTIONAL);
  148. BOOL ExtendVirtualBuffer( IN PVIRTUAL_BUFFER Buffer, IN LPVOID Address);
  149. BOOL TrimVirtualBuffer( IN PVIRTUAL_BUFFER Buffer);
  150. BOOL FreeVirtualBuffer( IN PVIRTUAL_BUFFER Buffer);
  151. int VirtualBufferExceptionFilter( IN DWORD ExceptionCode, IN PEXCEPTION_POINTERS ExceptionInfo, IN OUT PVIRTUAL_BUFFER Buffer);
  152. void CreateNameNode( LinkedFileList *Node, char *Name);
  153. void DuplicateNode( LinkedFileList FirstNode, LinkedFileList *Node);
  154. BOOL Excluded( char *Buff, char *Path);
  155. BOOL Matched( char *Buff, char *Path);
  156. void FreeList( LinkedFileList *list);
  157. LPSTR MyStrCat( char* firststring, char *secondstring);
  158. BOOL Match( char *pat, char* text);
  159. void OutOfMem( void);
  160. void PrintTree( LinkedFileList List, int Level);
  161. BOOL FindInMatchListTop( char *Name, LinkedFileList *List);
  162. BOOL FindInMatchListFront( char *Name, LinkedFileList *List);
  163. LinkedFileList *FindInList( char *Name, LinkedFileList *List);
  164. LinkedFileList *Next( LinkedFileList List);