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.

423 lines
12 KiB

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