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.

147 lines
4.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: cBFile.cpp
  8. //
  9. // Contents: Microsoft Internet Security Certificate Class
  10. //
  11. // History: 24-Oct-1997 pberkman created
  12. //
  13. //--------------------------------------------------------------------------
  14. #ifndef CBFILE_HXX
  15. #define CBFILE_HXX
  16. #pragma pack(8)
  17. #define BFILE_VERSION_1 0x0001
  18. typedef struct BFILE_HEADER_
  19. {
  20. DWORD fDirty : 1;
  21. DWORD sVersion : 16;
  22. DWORD dwFiller1 : 15;
  23. DWORD sIntVersion : 16;
  24. DWORD dwFiller2 : 16;
  25. DWORD cbSortedEOF;
  26. DWORD cbKey;
  27. DWORD cbData;
  28. DWORD dwLastRecNum;
  29. DWORD dwFiller3;
  30. } BFILE_HEADER;
  31. typedef struct BFILE_RECORD_
  32. {
  33. DWORD dwRecNum;
  34. DWORD cbKey;
  35. void *pvKey;
  36. DWORD cbDataOffset;
  37. DWORD cbData;
  38. void *pvData;
  39. DWORD fDeleted : 1;
  40. DWORD dwFiller1 : 31;
  41. } BFILE_RECORD;
  42. #ifdef _WIN64
  43. #define BFILE_SIZEOFSIG 8
  44. #else
  45. #define BFILE_SIZEOFSIG 6
  46. #endif
  47. #define BFILE_SIG "CBFILE"
  48. #define BFILE_KEYEXT L".cbk"
  49. #define BFILE_DATAEXT L".cbd"
  50. #define BFILE_HEADERSIZE (sizeof(BFILE_HEADER) + BFILE_SIZEOFSIG)
  51. #define BFILE_KEYSIZE (sHeader.cbKey + sizeof(DWORD))
  52. #define BFILE_RECSIZE (sizeof(DWORD) + sHeader.cbData)
  53. #pragma pack()
  54. class cBFile_
  55. {
  56. public:
  57. cBFile_(CRITICAL_SECTION *pCriticalSection,
  58. WCHAR *pwszBFilePath, WCHAR *pwszBFileBaseName,
  59. DWORD cbKey, DWORD cbData, SHORT sVersion, BOOL *pfCreatedOK);
  60. virtual ~cBFile_(void);
  61. BOOL Initialize(void);
  62. void setKey(void *pvInKey);
  63. void setData(void *pvInData);
  64. DWORD KeySize(void) { return(sHeader.cbKey); }
  65. void *getKey(void) { return(sRecord.pvKey); }
  66. void *getData(void) { return(sRecord.pvData); }
  67. DWORD getRecNum(void) { return(sRecord.dwRecNum); }
  68. DWORD getKeyNum(void) { return(dwFirstNextRecNum); }
  69. DWORD getVersion(void) { return(sHeader.sVersion); }
  70. void UseRecNumAsKey(BOOL fUse) { fUseRecNumAsKey = fUse; }
  71. BOOL Find(void);
  72. BOOL Update(void);
  73. BOOL Add(void);
  74. void Sort(void);
  75. BOOL GetFirst(void);
  76. BOOL GetNext(DWORD dwCurRec = 0xffffffff);
  77. BOOL GetPrev(DWORD dwCurRec = 0xffffffff);
  78. DWORD GetNumKeys(void);
  79. BOOL GetHeader(BFILE_HEADER *psHeader);
  80. void *GetDumpKey(DWORD dwIdx, void *pvRetKey, DWORD *pdwRecOffset);
  81. protected:
  82. BOOL BinaryFind(DWORD *pcbDataOffset);
  83. BOOL GetDataRecord(DWORD cbDataOffset);
  84. void UpdateDataRecord(DWORD cbDataOffset);
  85. BOOL AddDirtyKey(void);
  86. DWORD AddDataRecord(void);
  87. BOOL UpdateHeader(void);
  88. BOOL ReadHeader(void);
  89. private:
  90. CRITICAL_SECTION *pCritical;
  91. BOOL fInitialized;
  92. BOOL fReadOnly;
  93. BOOL fDirty;
  94. BOOL fUseRecNumAsKey;
  95. BFILE_HEADER sHeader;
  96. BFILE_RECORD sRecord;
  97. HANDLE hKFile;
  98. HANDLE hDFile;
  99. BYTE *pbKMap;
  100. DWORD cbKMap;
  101. BYTE *pbDMap;
  102. DWORD cbDMap;
  103. HANDLE hDMutex;
  104. WCHAR *pwszPath;
  105. WCHAR *pwszBaseName;
  106. DWORD dwFirstNextRecNum;
  107. BOOL OpenFiles(void);
  108. BOOL Lock(void);
  109. BOOL Unlock(void);
  110. BOOL RemapKey(void);
  111. BOOL RemapData(void);
  112. void UnmapAll(void);
  113. void SpeedSort(void);
  114. DWORD GetInsertionPoint(void *pvIn);
  115. };
  116. #endif // CBFILE_HXX