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.

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