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.

957 lines
14 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. oslayer.h
  5. Abstract:
  6. OS layer API definition. These are the functions which the record manager uses
  7. to manage the CSC record database. This allows us to port the record manager
  8. to NT and win9x platforms without affecting the record manager code in any
  9. significant manner.
  10. Contents:
  11. Author:
  12. Shishir Pardikar
  13. Environment:
  14. kernel mode.
  15. Revision History:
  16. 1-1-94 original
  17. --*/
  18. //let's take this opportunity to null out the rdbss/minirdr style dbgtrace/log
  19. //if we're not on NT
  20. typedef void *CSCHFILE;
  21. #define CSCHFILE_NULL NULL
  22. #ifndef CSC_RECORDMANAGER_WINNT
  23. #ifndef NOTHING
  24. #define NOTHING
  25. #endif
  26. #define RxLog(Args) {NOTHING;}
  27. #define RxDbgTrace(INDENT,CONTROLPOINTNUM,Z) {NOTHING;}
  28. #define DbgBreakPoint() {NOTHING;}
  29. #define FILE_ATTRIBUTE_NORMAL 0
  30. #endif
  31. #undef CSC_BUILD_W_PROGRESS_CATCHERS
  32. #ifdef RX_PRIVATE_BUILD
  33. #ifdef CSC_RECORDMANAGER_WINNT
  34. #if defined(_X86_)
  35. #define CSC_BUILD_W_PROGRESS_CATCHERS
  36. #else
  37. #endif
  38. #endif
  39. #endif
  40. #if !DBG
  41. #undef CSC_BUILD_W_PROGRESS_CATCHERS
  42. #endif
  43. #ifdef CSC_BUILD_W_PROGRESS_CATCHERS
  44. typedef struct _CSC_PROGRESS_BLOCK {
  45. ULONG Counter;
  46. PVOID NearTop;
  47. PVOID NearArgs;
  48. ULONG Progress;
  49. ULONG LastBit;
  50. ULONG Loops;
  51. ULONG StackRemaining;
  52. PULONG RetAddrP;
  53. ULONG RetAddr;
  54. ULONG SignatureOfEnd;
  55. } CSC_PROGRESS_BLOCK, *PCSC_PROGRESS_BLOCK;
  56. VOID
  57. CscProgressInit (
  58. PCSC_PROGRESS_BLOCK ProgressBlock,
  59. ULONG Counter,
  60. PVOID NearArgs
  61. );
  62. VOID
  63. CscProgress (
  64. PCSC_PROGRESS_BLOCK ProgressBlock,
  65. ULONG Bit
  66. );
  67. extern ULONG DelShadowInternalEntries;
  68. #define JOE_DECL_PROGRESS() CSC_PROGRESS_BLOCK JOE_DECL_CURRENT_PROGRESS
  69. #define JOE_INIT_PROGRESS(counter,nearargs) \
  70. {CscProgressInit(&JOE_DECL_CURRENT_PROGRESS,counter,nearargs);}
  71. #define JOE_PROGRESS(bit) \
  72. {CscProgress(&JOE_DECL_CURRENT_PROGRESS,bit);}
  73. #else
  74. #define JOE_DECL_PROGRESS()
  75. #define JOE_INIT_PROGRESS(counter,nearargs)
  76. #define JOE_PROGRESS(bit)
  77. #endif
  78. #define PUBLIC
  79. #define PRIVATE
  80. #define COPY_BUFF_SIZE 4096
  81. #ifndef UNICODE
  82. #define UNICODE 2
  83. #endif
  84. #define ATTRIB_DEL_ANY 0x0007 // Attrib passed to ring0 delete
  85. //typedef USHORT USHORT;
  86. //typedef ULONG ULONG;
  87. #ifndef CSC_RECORDMANAGER_WINNT
  88. typedef void (PUBLIC *FARPROC)(void);
  89. #endif
  90. typedef pioreq PIOREQ;
  91. typedef struct ParsedPath *PPP, far *LPPP;
  92. typedef struct PathElement *PPE, far *LPPE;
  93. typedef LPVOID HFREMOTE;
  94. typedef HFREMOTE far * LPHFREMOTE;
  95. typedef PIOREQ LPPATH;
  96. typedef LPSTR LPTSTR;
  97. typedef char tchar;
  98. typedef _FILETIME FILETIME, *LPFILETIME;
  99. typedef struct _WIN32_FIND_DATAA _WIN32_FIND_DATAA, far *LPFIND32A;
  100. struct _WIN32_FIND_DATAA {
  101. ULONG dwFileAttributes;
  102. struct _FILETIME ftCreationTime;
  103. struct _FILETIME ftLastAccessTime;
  104. struct _FILETIME ftLastWriteTime;
  105. ULONG nFileSizeHigh;
  106. ULONG nFileSizeLow;
  107. ULONG dwReserved0;
  108. ULONG dwReserved1;
  109. UCHAR cFileName[MAX_PATH]; /* includes NUL */
  110. UCHAR cAlternateFileName[14]; /* includes NUL */
  111. }; /* _WIN32_FIND_DATAA */
  112. #define FILE_ATTRIBUTE_ALL (FILE_ATTRIBUTE_READONLY| FILE_ATTRIBUTE_HIDDEN \
  113. | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY \
  114. | FILE_ATTRIBUTE_ARCHIVE)
  115. #define IsFile(dwAttr) (!((dwAttr) & (FILE_ATTRIBUTE_DIRECTORY)))
  116. typedef int (*PATHPROC)(USHORT *, USHORT *, LPVOID);
  117. #define FLAG_RW_OSLAYER_INSTRUMENT 0x00000001
  118. #define FLAG_RW_OSLAYER_PAGED_BUFFER 0x00000002
  119. #define FLAG_CREATE_OSLAYER_INSTRUMENT 0x00000001
  120. #define FLAG_CREATE_OSLAYER_ALL_ACCESS 0x00000002
  121. #if defined(BITCOPY)
  122. #define FLAG_CREATE_OSLAYER_OPEN_STRM 0x00000004
  123. #endif // defined(BITCOPY)
  124. #include "hook.h"
  125. #ifdef CSC_RECORDMANAGER_WINNT
  126. //this comes from shadow.asm on win95......
  127. #define GetCurThreadHandle() (PtrToUlong(KeGetCurrentThread()))
  128. #define CheckHeap(a) {NOTHING;}
  129. extern ULONG EventLogForOpenFailure;
  130. #endif //ifdef CSC_RECORDMANAGER_WINNT
  131. #define SizeofFindRemote (sizeof(FINDINFO)+sizeof(ioreq)+sizeof(WIN32_FIND_DATA))
  132. #define LpIoreqFromFindInfo(pFindInfo) ((PIOREQ)((LPBYTE)(pFindInfo)+sizeof(FINDINFO)))
  133. #define LpFind32FromFindInfo(pFindInfo) ((LPFIND32)((LPBYTE)(pFindInfo)+sizeof(FINDINFO)+sizeof(ioreq)))
  134. #define LpFind32FromHfRemote(HfRemote) ((LPFIND32)((LPBYTE)(HfRemote)+sizeof(FINDINFO)+sizeof(ioreq)))
  135. #define SizeofFileRemote (sizeof(FILEINFO)+sizeof(ioreq))
  136. #define LpIoreqFromFileInfo(pFileInfo) ((PIOREQ)((LPBYTE)(pFileInfo)+sizeof(FILEINFO)))
  137. CSCHFILE CreateFileLocal(LPSTR lpName);
  138. /*++
  139. Routine Description:
  140. This routine creates a file on the local drive, if it doesn't exist. If it exists, it truncates
  141. the file.
  142. Arguments:
  143. lpName Fully qualified path name. On NT it is prefixed by \DosDevice\
  144. Returns:
  145. if successful, returns a file handle that can be used in read and write calls.
  146. If it fails, it retruns NULL.
  147. Notes:
  148. Need a scheme to return the actual error code
  149. --*/
  150. CSCHFILE OpenFileLocal(LPSTR lpName);
  151. /*++
  152. Routine Description:
  153. This routine opens a file on the local drive if it exists. If it doesn't exist the call fails
  154. Arguments:
  155. lpName Fully qualified path name. On NT it is prefixed by \DosDevice\
  156. Returns:
  157. if successful, returns a file handle that can be used in read and write calls.
  158. If it fails, it retruns NULL.
  159. Notes:
  160. Need a scheme to return the actual error code
  161. --*/
  162. int DeleteFileLocal(LPSTR lpName, USHORT usAttrib);
  163. /*++
  164. Routine Description:
  165. Arguments:
  166. Returns:
  167. Notes:
  168. --*/
  169. int FileExists (LPSTR lpName);
  170. /*++
  171. Routine Description:
  172. Arguments:
  173. Returns:
  174. Notes:
  175. --*/
  176. long ReadFileLocal (CSCHFILE handle, ULONG pos, LPVOID lpBuff, long lCount);
  177. /*++
  178. Routine Description:
  179. Arguments:
  180. Returns:
  181. Notes:
  182. --*/
  183. long WriteFileLocal (CSCHFILE handle, ULONG pos, LPVOID lpBuff, long lCount);
  184. /*++
  185. Routine Description:
  186. Arguments:
  187. Returns:
  188. Notes:
  189. --*/
  190. long ReadFileInContextLocal (CSCHFILE, ULONG, LPVOID, long);
  191. /*++
  192. Routine Description:
  193. Arguments:
  194. Returns:
  195. Notes:
  196. --*/
  197. long WriteFileInContextLocal (CSCHFILE, ULONG, LPVOID, long);
  198. /*++
  199. Routine Description:
  200. Arguments:
  201. Returns:
  202. Notes:
  203. --*/
  204. ULONG CloseFileLocal (CSCHFILE handle);
  205. /*++
  206. Routine Description:
  207. Arguments:
  208. Returns:
  209. Notes:
  210. --*/
  211. int GetFileSizeLocal (CSCHFILE, PULONG);
  212. /*++
  213. Routine Description:
  214. Arguments:
  215. Returns:
  216. Notes:
  217. --*/
  218. int GetDiskFreeSpaceLocal(int indx
  219. , ULONG *lpuSectorsPerCluster
  220. , ULONG *lpuBytesPerSector
  221. , ULONG *lpuFreeClusters
  222. , ULONG *lpuTotalClusters
  223. );
  224. /*++
  225. Routine Description:
  226. Arguments:
  227. Returns:
  228. Notes:
  229. --*/
  230. int CreateFileRemote(LPPATH lpPath, LPHFREMOTE);
  231. /*++
  232. Routine Description:
  233. Arguments:
  234. Returns:
  235. Notes:
  236. --*/
  237. int OpenFileRemote(LPPATH lpPath, LPHFREMOTE);
  238. /*++
  239. Routine Description:
  240. Arguments:
  241. Returns:
  242. Notes:
  243. --*/
  244. int OpenFileRemoteEx(LPPATH lpPath, UCHAR uchAccess, USHORT usAction,ULONG ulAttr, LPHFREMOTE);
  245. /*++
  246. Routine Description:
  247. Arguments:
  248. Returns:
  249. Notes:
  250. --*/
  251. int ReadFileRemote (HFREMOTE handle, PIOREQ pir, ULONG pos, LPVOID lpBuff, ULONG count);
  252. /*++
  253. Routine Description:
  254. Arguments:
  255. Returns:
  256. Notes:
  257. --*/
  258. int WriteFileRemote (HFREMOTE handle, PIOREQ pir, ULONG pos, LPVOID lpBuff, ULONG count);
  259. /*++
  260. Routine Description:
  261. Arguments:
  262. Returns:
  263. Notes:
  264. --*/
  265. int CloseFileRemote (HFREMOTE handle, PIOREQ pir);
  266. /*++
  267. Routine Description:
  268. Arguments:
  269. Returns:
  270. Notes:
  271. --*/
  272. int GetAttributesLocal (LPSTR lpPath, ULONG *lpuAttr);
  273. /*++
  274. Routine Description:
  275. Return the attributes of the file
  276. Arguments:
  277. lpPath A fully qualified path
  278. lpuAttr contains the attributes on return
  279. Returns:
  280. 0 if successfull, < 0 otherwise
  281. Notes:
  282. --*/
  283. int GetAttributesLocalEx (LPSTR lpPath, BOOL fFile, ULONG *lpuAttr);
  284. /*++
  285. Routine Description:
  286. Return the attributes of the file/directory
  287. Arguments:
  288. lpPath A fully qualified path
  289. fFile if TURE, the object is a file, else it is a directory
  290. lpuAttr contains the attributes on return
  291. Returns:
  292. 0 if successfull, < 0 otherwise
  293. Notes:
  294. --*/
  295. int SetAttributesLocal (LPSTR, ULONG);
  296. /*++
  297. Routine Description:
  298. Arguments:
  299. Returns:
  300. Notes:
  301. --*/
  302. int RenameFileLocal (LPSTR, LPSTR);
  303. /*++
  304. Routine Description:
  305. Arguments:
  306. Returns:
  307. Notes:
  308. --*/
  309. int FileLockLocal(CSCHFILE, ULONG, ULONG, ULONG, BOOL);
  310. /*++
  311. Routine Description:
  312. Arguments:
  313. Returns:
  314. Notes:
  315. --*/
  316. int FindOpenRemote (LPPATH lpPath, LPHFREMOTE);
  317. /*++
  318. Routine Description:
  319. Arguments:
  320. Returns:
  321. Notes:
  322. --*/
  323. int FindNextRemote (HFREMOTE handle, PIOREQ pir);
  324. /*++
  325. Routine Description:
  326. Arguments:
  327. Returns:
  328. Notes:
  329. --*/
  330. int FindCloseRemote (HFREMOTE handle, PIOREQ pir);
  331. /*++
  332. Routine Description:
  333. Arguments:
  334. Returns:
  335. Notes:
  336. --*/
  337. int CloseAllRemoteFiles(PRESOURCE);
  338. /*++
  339. Routine Description:
  340. Arguments:
  341. Returns:
  342. Notes:
  343. --*/
  344. int CloseAllRemoteFinds(PRESOURCE);
  345. /*++
  346. Routine Description:
  347. Arguments:
  348. Returns:
  349. Notes:
  350. --*/
  351. LPVOID AllocMem (ULONG uSize);
  352. //BUGBUG.REVIEW AllocMem should distinguish between paged and nonpaged pool
  353. /*++
  354. Routine Description:
  355. Arguments:
  356. Returns:
  357. Notes:
  358. --*/
  359. #ifndef CSC_RECORDMANAGER_WINNT
  360. VOID FreeMem (LPVOID lpBuff);
  361. VOID CheckHeap(LPVOID lpBuff);
  362. #else
  363. INLINE
  364. VOID
  365. FreeMem (
  366. PVOID p___
  367. )
  368. {RxFreePool(p___);}
  369. #endif //ifndef CSC_RECORDMANAGER_WINNT
  370. /*++
  371. Routine Description:
  372. Arguments:
  373. Returns:
  374. Notes:
  375. --*/
  376. //BUGBUG.REVIEW this was added here because it is called from record.c
  377. CSCHFILE R0OpenFile (USHORT usOpenFlags, UCHAR bAction, LPSTR lpPath);
  378. /*++
  379. Routine Description:
  380. Arguments:
  381. Returns:
  382. Notes:
  383. --*/
  384. //for the NT build these are added here AND the code is also moved from
  385. //hook.c to oslayer.c since these routines are called from oslayer.c
  386. PELEM PAllocElem (int cbSize);
  387. void FreeElem (PELEM pElem);
  388. void LinkElem (PELEM pElem, PPELEM ppheadElem);
  389. PELEM PUnlinkElem (PELEM pElem, PPELEM ppheadElem);
  390. int ReinitializeDatabase();
  391. BOOL IsSpecialApp(VOID);
  392. int DisconnectAllByName(LPPE lppeRes);
  393. int PRIVATE DeleteShadowHelper(BOOL fMarkDeleted, HSHADOW, HSHADOW);
  394. int InitShadowDB(VOID);
  395. CSCHFILE OpenFileLocalEx(LPSTR lpPath, BOOL fInstrument);
  396. /*++
  397. Routine Description:
  398. Arguments:
  399. Returns:
  400. Notes:
  401. --*/
  402. long ReadFileLocalEx(CSCHFILE handle, ULONG pos, LPVOID pBuff, long lCount, BOOL fInstrument);
  403. /*++
  404. Routine Description:
  405. Arguments:
  406. Returns:
  407. Notes:
  408. --*/
  409. long WriteFileLocalEx(CSCHFILE handle, ULONG pos, LPVOID lpBuff, long lCount, BOOL fInstrument);
  410. /*++
  411. Routine Description:
  412. Arguments:
  413. Returns:
  414. Notes:
  415. --*/
  416. long ReadFileLocalEx2(CSCHFILE handle, ULONG pos, LPVOID pBuff, long lCount, ULONG flags);
  417. /*++
  418. Routine Description:
  419. Arguments:
  420. Returns:
  421. Notes:
  422. --*/
  423. long WriteFileLocalEx2(CSCHFILE handle, ULONG pos, LPVOID lpBuff, long lCount, ULONG flags);
  424. /*++
  425. Routine Description:
  426. Arguments:
  427. Returns:
  428. Notes:
  429. --*/
  430. CSCHFILE R0OpenFileEx(USHORT usOpenFlags, UCHAR bAction, ULONG uAttr, LPSTR lpPath, BOOL fInstrument);
  431. /*++
  432. Routine Description:
  433. Arguments:
  434. Returns:
  435. Notes:
  436. --*/
  437. VOID GetSystemTime(_FILETIME *lpft);
  438. /*++
  439. Routine Description:
  440. Arguments:
  441. Returns:
  442. Notes:
  443. --*/
  444. int
  445. CreateDirectoryLocal(
  446. LPSTR lpPath
  447. );
  448. /*++
  449. Routine Description:
  450. This routine creates a directory if it doesn't exist.
  451. Arguments:
  452. lpPath Fully qualified directory path. On NT, this is of the form \DosDevice\c:\winnt\csc\d0
  453. On win95 the \DosDevice\ part is missing
  454. Returns:
  455. Notes:
  456. --*/
  457. LPVOID
  458. AllocMemPaged(
  459. unsigned long ulSize
  460. );
  461. /*++
  462. Routine Description:
  463. This routine allows allocating paged memory
  464. Arguments:
  465. Returns:
  466. Notes:
  467. --*/
  468. VOID
  469. FreeMemPaged(
  470. LPVOID lpMemPaqged
  471. );
  472. /*++
  473. Routine Description:
  474. This routine allows freeing paged memory
  475. Arguments:
  476. Returns:
  477. Notes:
  478. On win95 paged and fixed memory come from totally different allocators, so the appropriate
  479. deallocator has to be called for freeing it.
  480. --*/
  481. ULONG
  482. GetTimeInSecondsSince1970(
  483. VOID
  484. );
  485. BOOL
  486. IterateOnUNCPathElements(
  487. USHORT *lpuPath,
  488. PATHPROC lpfn,
  489. LPVOID lpCookie
  490. );
  491. BOOL
  492. IsPathUNC(
  493. USHORT *lpuPath,
  494. int cntMaxChars
  495. );
  496. VOID
  497. SetLastErrorLocal(
  498. DWORD dwError
  499. );
  500. DWORD
  501. GetLastErrorLocal(
  502. VOID
  503. );
  504. int
  505. FindNextFileLocal(
  506. CSCHFILE handle,
  507. _WIN32_FIND_DATAA *lpFind32A
  508. );
  509. CSCHFILE
  510. FindFirstFileLocal(
  511. LPSTR lpPath,
  512. _WIN32_FIND_DATAA *lpFind32A
  513. );
  514. int
  515. FindCloseLocal(
  516. CSCHFILE handle
  517. );
  518. BOOL
  519. HasStreamSupport(
  520. CSCHFILE handle,
  521. BOOL *lpfResult
  522. );