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.

385 lines
9.8 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: dir.hxx
  7. //
  8. // Contents: Directory header for Mstream project
  9. //
  10. // Classes: CDirEntry - Information on a single stream
  11. // CDirSect - Sector sized array of DirEntry
  12. // CDirVector - Resizable array of CDirSect
  13. // CDirectory - Grouping of DirSectors
  14. //
  15. // Notes: Properties and storage elements are kept in the same
  16. // child list so the *ChildProp functions are unused. 1/18/93
  17. //
  18. //--------------------------------------------------------------------
  19. #include "msf.hxx"
  20. #include "wchar.h"
  21. #include "vect.hxx"
  22. #ifndef __DIR_HXX__
  23. #define __DIR_HXX__
  24. #define DIR_HIT 0x01
  25. struct SPreDirEntry
  26. {
  27. protected:
  28. CDfName _dfn; // Name (word-aligned)
  29. BYTE _mse; // STGTY_...
  30. BYTE _bflags;
  31. SID _sidLeftSib; // Siblings
  32. SID _sidRightSib; // Siblings
  33. SID _sidChild; // Storage - Child list
  34. GUID _clsId; // Storage - Class id
  35. DWORD _dwUserFlags; // Storage - User flags
  36. TIME_T _time[2]; // Storage - time stamps
  37. SECT _sectStart; // Stream - start
  38. ULONG _ulSize; // Stream - size
  39. //DFPROPTYPE _dptPropType; // Property - type
  40. };
  41. #define STGTY_INVALID 0
  42. #define STGTY_ROOT 5
  43. // Macros which tell whether a direntry has stream fields,
  44. // storage fields or property fields
  45. #define STREAMLIKE(mse) \
  46. (((mse) & STGTY_REAL) == STGTY_STREAM || (mse) == STGTY_ROOT)
  47. #define STORAGELIKE(mse) \
  48. (((mse) & STGTY_REAL) == STGTY_STORAGE || (mse) == STGTY_ROOT)
  49. //+----------------------------------------------------------------------
  50. //
  51. // Class: CDirEntry (de)
  52. //
  53. // Purpose: Holds information on one stream
  54. //
  55. // Interface: GetName - returns name of stream
  56. // GetStart - return first sector for stream
  57. // GetSize - returns size of stream
  58. // GetFlags - returns flag byte
  59. //
  60. // SetName - sets name
  61. // SetStart - sets first sector
  62. // SetSize - sets size
  63. // SetFlags - sets flag byte
  64. //
  65. // IsFree - returns 1 if element is not in use
  66. // IsEntry - returns 1 is element name matches argument
  67. //
  68. // Notes: B-flat,C-sharp
  69. //
  70. //-----------------------------------------------------------------------
  71. const CBDIRPAD = DIRENTRYSIZE - sizeof(SPreDirEntry);
  72. // DirEntry bit flags are used for the following private state
  73. // Usage Bit
  74. #define DECOLORBIT 0x01
  75. #define DERESERVED 0xfe
  76. typedef enum
  77. {
  78. DE_RED = 0,
  79. DE_BLACK = 1
  80. } DECOLOR;
  81. class CDirEntry: private SPreDirEntry
  82. {
  83. public:
  84. CDirEntry();
  85. inline void Init(MSENTRYFLAGS mse);
  86. inline CDfName const * GetName(VOID) const;
  87. inline SECT GetStart(VOID) const;
  88. inline ULONG GetSize(VOID) const;
  89. inline SID GetLeftSib(VOID) const;
  90. inline SID GetRightSib(VOID) const;
  91. inline SID GetChild(VOID) const;
  92. inline MSENTRYFLAGS GetFlags(VOID) const;
  93. inline DECOLOR GetColor(VOID) const;
  94. inline TIME_T GetTime(WHICHTIME tt) const;
  95. inline GUID GetClassId(VOID) const;
  96. inline DWORD GetUserFlags(VOID) const;
  97. inline void SetName(const CDfName *pdfn);
  98. inline void SetStart(const SECT);
  99. inline void SetSize(const ULONG);
  100. inline void SetLeftSib(const SID);
  101. inline void SetRightSib(const SID);
  102. inline void SetChild(const SID);
  103. inline void SetFlags(const MSENTRYFLAGS mse);
  104. inline void SetColor(DECOLOR);
  105. inline void SetTime(WHICHTIME tt, TIME_T nt);
  106. inline void SetClassId(GUID cls);
  107. inline void SetUserFlags(DWORD dwUserFlags, DWORD dwMask);
  108. inline BOOL IsFree(VOID) const;
  109. inline BOOL IsEntry(CDfName const *pdfn) const;
  110. inline void ByteSwap(void);
  111. private:
  112. inline BYTE GetBitFlags(VOID) const;
  113. inline void SetBitFlags(BYTE bValue, BYTE bMask);
  114. BYTE _bpad[CBDIRPAD];
  115. };
  116. //+-------------------------------------------------------------------------
  117. //
  118. // Class: CDirSect (ds)
  119. //
  120. // Purpose: Provide sector sized block of DirEntries
  121. //
  122. // Interface:
  123. //
  124. // Notes:
  125. //
  126. //--------------------------------------------------------------------------
  127. class CDirSect
  128. {
  129. public:
  130. SCODE Init(USHORT cbSector);
  131. inline CDirEntry* GetEntry(DIROFFSET iEntry);
  132. inline void ByteSwap(USHORT cbSector);
  133. private:
  134. #ifdef _MSC_VER
  135. #pragma warning(disable: 4200)
  136. CDirEntry _adeEntry[];
  137. #pragma warning(default: 4200)
  138. #endif
  139. #ifdef __GNUC__
  140. CDirEntry _adeEntry[0];
  141. #endif
  142. };
  143. //+-------------------------------------------------------------------------
  144. //
  145. // Class: CDirVector (dv)
  146. //
  147. // Purpose: Provide resizable array of DirSectors.
  148. //
  149. // Interface:
  150. //
  151. // Notes:
  152. //
  153. //--------------------------------------------------------------------------
  154. class CDirVector: public CPagedVector
  155. {
  156. public:
  157. inline CDirVector(USHORT cbSector);
  158. inline ~CDirVector() {}
  159. inline SCODE GetTable(
  160. const DIRINDEX iTable,
  161. const DWORD dwFlags,
  162. CDirSect **ppds);
  163. inline USHORT GetSectorSize(void) const
  164. { return _cbSector; }
  165. private:
  166. const USHORT _cbSector;
  167. #ifdef _MSC_VER
  168. #pragma warning(disable:4512)
  169. // since there is a const member, there should be no assignment operator
  170. #endif // _MSC_VER
  171. };
  172. #ifdef _MSC_VER
  173. #pragma warning(default:4512)
  174. // since there is a const member, there should be no assignment operator
  175. #endif // _MSC_VER
  176. //+----------------------------------------------------------------------
  177. //
  178. // Class: CDirectory (dir)
  179. //
  180. // Purpose: Main interface for directory functionality
  181. //
  182. // Interface: GetFree - returns an SID for a free DirEntry
  183. // Find - finds its argument in the directory list
  184. // SetEntry - sets up a DirEntry and writes out its sector
  185. // GetName - returns the name of a DirEntry
  186. // GetStart - returns the start sector of a DirEntry
  187. // GetSize - returns the size of a DirEntry
  188. // GetFlags - returns the flag byte of a DirEntry
  189. //
  190. //
  191. // Notes:
  192. //
  193. //-----------------------------------------------------------------------
  194. typedef enum DIRENTRYOP
  195. {
  196. DEOP_FIND = 0,
  197. DEOP_REMOVE = 1
  198. } DIRENTRYOP;
  199. class CDirectory
  200. {
  201. public:
  202. CDirectory(USHORT cbSector);
  203. ~CDirectory() {}
  204. VOID Empty(VOID);
  205. SCODE Init(CMStream *pmsParent, DIRINDEX cSect);
  206. SCODE InitNew(CMStream *pmsParent);
  207. SCODE FindGreaterEntry(
  208. SID sidChildRoot,
  209. CDfName const *pdfn,
  210. SID *psidResult);
  211. SCODE SetStart(const SID sid, const SECT sect);
  212. SCODE SetTime(const SID sid, WHICHTIME tt, TIME_T nt);
  213. SCODE SetChild(const SID sid, const SID sidChild);
  214. SCODE SetSize(const SID sid, const ULONG cbSize);
  215. SCODE SetClassId(const SID sid, const GUID cls);
  216. SCODE SetFlags(const SID sid, const MSENTRYFLAGS mse);
  217. SCODE SetUserFlags(const SID sid,
  218. DWORD dwUserFlags,
  219. DWORD dwMask);
  220. inline SCODE GetName(const SID sid, CDfName *pdfn);
  221. inline SCODE GetStart(const SID sid, SECT * psect);
  222. inline SCODE GetSize(const SID sid, ULONG *pulSize);
  223. inline SCODE GetChild(const SID sid, SID *psid);
  224. inline SCODE GetFlags(const SID sid, MSENTRYFLAGS *pmse);
  225. inline SCODE GetClassId(const SID sid, GUID *pcls);
  226. inline SCODE GetTime(const SID sid, WHICHTIME tt, TIME_T *ptime);
  227. inline SCODE GetUserFlags(const SID sid, DWORD *pdwUserFlags);
  228. SCODE GetDirEntry(
  229. const SID sid,
  230. const DWORD dwFlags,
  231. CDirEntry **ppde);
  232. void ReleaseEntry(SID sid);
  233. SCODE CreateEntry(
  234. SID sidParent,
  235. CDfName const *pdfn,
  236. MSENTRYFLAGS mef,
  237. SID *psidNew);
  238. SCODE RenameEntry(
  239. SID const sidParent,
  240. CDfName const *pdfn,
  241. CDfName const *pdfnNew);
  242. inline SCODE IsEntry(
  243. SID const sidParent,
  244. CDfName const *pdfn,
  245. SEntryBuffer *peb);
  246. SCODE DestroyAllChildren(
  247. SID const sidParent);
  248. SCODE DestroyChild(
  249. SID const sidParent,
  250. CDfName const *pdfn);
  251. SCODE StatEntry(SID const sid,
  252. CDfName *pNextKey,
  253. STATSTGW *pstatstg);
  254. inline SCODE Flush(VOID);
  255. inline void SetParent(CMStream * pmsParent);
  256. private:
  257. CDirVector _dv;
  258. DIRINDEX _cdsTable;
  259. CMStream * _pmsParent;
  260. DIROFFSET _cdeEntries;
  261. SID _sidFirstFree;
  262. SCODE Resize(DIRINDEX);
  263. inline DIRINDEX SidToTable(SID sid) const;
  264. inline SID PairToSid(
  265. DIRINDEX iTable,
  266. DIROFFSET iEntry) const;
  267. inline SCODE SidToPair(
  268. SID sid,
  269. DIRINDEX* pipds,
  270. DIROFFSET* pide) const;
  271. SCODE GetFree(SID * psid);
  272. SCODE InsertEntry(
  273. SID sidParent,
  274. SID sidInsert,
  275. CDfName const *pdfnInsert);
  276. SCODE FindEntry(
  277. SID sidParent,
  278. CDfName const *pdfnFind,
  279. DIRENTRYOP deop,
  280. SEntryBuffer *peb);
  281. static int NameCompare(
  282. CDfName const *pdfn1,
  283. CDfName const *pdfn2);
  284. SCODE SplitEntry(
  285. CDfName const *pdfn,
  286. SID sidTree,
  287. SID sidGreat,
  288. SID sidGrand,
  289. SID sidParent,
  290. SID sidChild,
  291. SID *psid);
  292. SCODE RotateEntry(
  293. CDfName const *pdfn,
  294. SID sidTree,
  295. SID sidParent,
  296. SID *psid);
  297. SCODE SetColorBlack(const SID sid);
  298. #ifdef _MSC_VER
  299. #pragma warning(disable:4512)
  300. // since there is a const member, there should be no assignment operator
  301. #endif // _MSC_VER
  302. };
  303. #ifdef _MSC_VER
  304. #pragma warning(default:4512)
  305. #endif // _MSC_VER
  306. #endif //__DIR_HXX__