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.

101 lines
2.6 KiB

  1. /************************************************************************
  2. Copyright (c) 2000 - 2000 Microsoft Corporation
  3. Module Name :
  4. metadata.h
  5. Abstract :
  6. Main header for code for reading and writting to the metadata.
  7. Author :
  8. Revision History :
  9. ***********************************************************************/
  10. // These functions may throw a ComError.
  11. //
  12. void SafeWriteFile( HANDLE hFile, void *pBuffer, DWORD dwSize );
  13. void SafeReadFile( HANDLE hFile, void *pBuffer, DWORD dwSize );
  14. void SafeWriteStringHandle( HANDLE hFile, StringHandle & str );
  15. StringHandle SafeReadStringHandle( HANDLE hFile );
  16. void SafeWriteFile( HANDLE hFile, WCHAR * str );
  17. void SafeReadFile( HANDLE hFile, WCHAR ** pStr );
  18. void SafeWriteSid( HANDLE hFile, SidHandle & Sid );
  19. void SafeReadSid( HANDLE hFile, SidHandle & sid );
  20. template <class T>
  21. void SafeWriteFile( HANDLE hFile, T Data )
  22. {
  23. SafeWriteFile( hFile, &Data, sizeof( Data ) );
  24. }
  25. template <class T>
  26. void SafeReadFile( HANDLE hFile, T *pBuffer)
  27. {
  28. SafeReadFile( hFile, pBuffer, sizeof(*pBuffer) );
  29. }
  30. void SafeWriteBlockBegin( HANDLE hFile, GUID BlockGuid );
  31. void SafeWriteBlockEnd( HANDLE hFile, GUID BlockGuid );
  32. void SafeReadBlockBegin( HANDLE hFile, GUID BlockGuid );
  33. void SafeReadBlockEnd( HANDLE hFile, GUID BlockGuid );
  34. //
  35. // allows any one of several GUIDs.
  36. //
  37. int SafeReadGuidChoice( HANDLE hFile, const GUID * guids[] );
  38. class CQmgrStateFiles
  39. {
  40. auto_FILE_HANDLE m_Files[2];
  41. auto_ptr<WCHAR> m_FileNames[2];
  42. UINT64 m_ExpandSize[2];
  43. INT64 m_OriginalFileSizes[2];
  44. DWORD m_CurrentIndex;
  45. static auto_ptr<WCHAR> GetNameFromIndex( DWORD dwIndex );
  46. static auto_FILE_HANDLE OpenMetadataFile( auto_ptr<WCHAR> FileName );
  47. static void WriteEmptyMetadataFile( HANDLE hFile );
  48. public:
  49. CQmgrStateFiles();
  50. HANDLE GetNextStateFile();
  51. void UpdateStateFile();
  52. HANDLE GetCurrentStateFile();
  53. void ExtendMetadata( INT64 ExtendAmount = ( METADATA_PREALLOC_SIZE + METADATA_PADDING ) );
  54. void ShrinkMetadata();
  55. };
  56. class CQmgrReadStateFile
  57. {
  58. private:
  59. CQmgrStateFiles & m_StateFiles;
  60. HANDLE m_FileHandle;
  61. public:
  62. CQmgrReadStateFile( CQmgrStateFiles & StateFiles );
  63. HANDLE GetHandle() { return m_FileHandle;}
  64. void ValidateEndOfFile();
  65. };
  66. class CQmgrWriteStateFile
  67. {
  68. private:
  69. CQmgrStateFiles & m_StateFiles;
  70. HANDLE m_FileHandle;
  71. public:
  72. CQmgrWriteStateFile( CQmgrStateFiles & StateFiles );
  73. HANDLE GetHandle() { return m_FileHandle;}
  74. void CommitFile();
  75. };