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.

422 lines
11 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 SetStart(const SECT);
  114. #ifdef LARGE_STREAMS
  115. inline void SetSize(const ULONGLONG);
  116. #else
  117. inline void SetSize(const ULONG);
  118. #endif
  119. inline void SetLeftSib(const SID);
  120. inline void SetRightSib(const SID);
  121. inline void SetChild(const SID);
  122. inline void SetFlags(const MSENTRYFLAGS mse);
  123. inline void SetColor(DECOLOR);
  124. inline void SetTime(WHICHTIME tt, TIME_T nt);
  125. inline void SetClassId(GUID cls);
  126. inline void SetUserFlags(DWORD dwUserFlags, DWORD dwMask);
  127. inline BOOL IsFree(VOID) const;
  128. inline BOOL IsEntry(CDfName const *pdfn) const;
  129. private:
  130. inline BYTE GetBitFlags(VOID) const;
  131. inline void SetBitFlags(BYTE bValue, BYTE bMask);
  132. // BYTE _bpad[CBDIRPAD]; // no more padding left
  133. };
  134. //+-------------------------------------------------------------------------
  135. //
  136. // Class: CDirSect (ds)
  137. //
  138. // Purpose: Provide sector sized block of DirEntries
  139. //
  140. // Interface:
  141. //
  142. // History: 18-Jul-91 PhilipLa Created.
  143. // 27-Dec-91 PhilipLa Converted from const size to
  144. // variable sized sectors.
  145. //
  146. // Notes:
  147. //
  148. //--------------------------------------------------------------------------
  149. #if _MSC_VER == 700
  150. #pragma warning(disable:4001)
  151. #elif _MSC_VER >= 800
  152. #pragma warning(disable:4200)
  153. #endif
  154. class CDirSect
  155. {
  156. public:
  157. SCODE Init(USHORT cbSector);
  158. SCODE InitCopy(USHORT cbSector,
  159. const CDirSect *pdsOld);
  160. inline CDirEntry * GetEntry(DIROFFSET iEntry);
  161. private:
  162. CDirEntry _adeEntry[];
  163. };
  164. #if _MSC_VER == 700
  165. #pragma warning(default:4001)
  166. #elif _MSC_VER >= 800
  167. #pragma warning(default:4200)
  168. #endif
  169. //+-------------------------------------------------------------------------
  170. //
  171. // Class: CDirVector (dv)
  172. //
  173. // Purpose: Provide resizable array of DirSectors.
  174. //
  175. // Interface:
  176. //
  177. // History: 27-Dec-91 PhilipLa Created.
  178. //
  179. // Notes:
  180. //
  181. //--------------------------------------------------------------------------
  182. class CDirVector: public CPagedVector
  183. {
  184. public:
  185. inline CDirVector(VOID);
  186. inline void InitCommon(USHORT cbSector);
  187. inline SCODE GetTable(
  188. const DIRINDEX iTable,
  189. const DWORD dwFlags,
  190. CDirSect **ppds);
  191. private:
  192. USHORT _cbSector;
  193. };
  194. inline void CDirVector::InitCommon(USHORT cbSector)
  195. {
  196. _cbSector = cbSector;
  197. }
  198. //+----------------------------------------------------------------------
  199. //
  200. // Class: CDirectory (dir)
  201. //
  202. // Purpose: Main interface for directory functionality
  203. //
  204. // Interface: GetFree - returns an SID for a free DirEntry
  205. // Find - finds its argument in the directory list
  206. // SetEntry - sets up a DirEntry and writes out its sector
  207. // GetName - returns the name of a DirEntry
  208. // GetStart - returns the start sector of a DirEntry
  209. // GetSize - returns the size of a DirEntry
  210. // GetFlags - returns the flag byte of a DirEntry
  211. //
  212. //
  213. // History: 18-Jul-91 PhilipLa Created.
  214. // 26-Aug-91 PhilipLa Added support for iterators
  215. // 26-Aug-92 t-chrisy Added init function for
  216. // corrupted directory object
  217. // Notes:
  218. //
  219. //-----------------------------------------------------------------------
  220. typedef enum DIRENTRYOP
  221. {
  222. DEOP_FIND = 0,
  223. DEOP_REMOVE = 1
  224. } DIRENTRYOP;
  225. class CDirectory
  226. {
  227. public:
  228. CDirectory();
  229. VOID Empty(VOID);
  230. SCODE Init(CMStream *pmsParent, DIRINDEX cSect);
  231. SCODE InitNew(CMStream *pmsParent);
  232. void InitCopy(CDirectory *pdirOld);
  233. SCODE FindGreaterEntry(
  234. SID sidChildRoot,
  235. CDfName const *pdfn,
  236. SID *psidResult);
  237. SCODE SetStart(const SID sid, const SECT sect);
  238. SCODE SetTime(const SID sid, WHICHTIME tt, TIME_T nt);
  239. SCODE SetAllTimes(SID const sid, TIME_T atm,TIME_T mtm, TIME_T ctm);
  240. SCODE SetChild(const SID sid, const SID sidChild);
  241. #ifdef LARGE_STREAMS
  242. SCODE SetSize(const SID sid, const ULONGLONG cbSize);
  243. #else
  244. SCODE SetSize(const SID sid, const ULONG cbSize);
  245. #endif
  246. SCODE SetClassId(const SID sid, const GUID cls);
  247. SCODE SetFlags(const SID sid, const MSENTRYFLAGS mse);
  248. SCODE SetUserFlags(const SID sid,
  249. DWORD dwUserFlags,
  250. DWORD dwMask);
  251. inline SCODE GetName(const SID sid, CDfName *pdfn);
  252. inline SCODE GetStart(const SID sid, SECT * psect);
  253. #ifdef LARGE_STREAMS
  254. inline SCODE GetSize(const SID sid, ULONGLONG *pulSize);
  255. #else
  256. inline SCODE GetSize(const SID sid, ULONG *pulSize);
  257. #endif
  258. inline SCODE GetChild(const SID sid, SID *psid);
  259. inline SCODE GetFlags(const SID sid, MSENTRYFLAGS *pmse);
  260. inline SCODE GetClassId(const SID sid, GUID *pcls);
  261. inline SCODE GetTime(const SID sid, WHICHTIME tt, TIME_T *ptime);
  262. inline SCODE GetAllTimes(SID const sid, TIME_T *patm,TIME_T *pmtm, TIME_T *pctm);
  263. inline SCODE GetUserFlags(const SID sid, DWORD *pdwUserFlags);
  264. SCODE GetDirEntry(
  265. const SID sid,
  266. const DWORD dwFlags,
  267. CDirEntry **ppde);
  268. void ReleaseEntry(SID sid);
  269. SCODE CreateEntry(
  270. SID sidParent,
  271. CDfName const *pdfn,
  272. MSENTRYFLAGS mef,
  273. SID *psidNew);
  274. SCODE RenameEntry(
  275. SID const sidParent,
  276. CDfName const *pdfn,
  277. CDfName const *pdfnNew);
  278. inline SCODE IsEntry(
  279. SID const sidParent,
  280. CDfName const *pdfn,
  281. SEntryBuffer *peb);
  282. SCODE DestroyAllChildren(
  283. SID const sidParent,
  284. ULONG ulDepth);
  285. SCODE DestroyChild(
  286. SID const sidParent,
  287. CDfName const *pdfn,
  288. ULONG ulDepth);
  289. SCODE StatEntry(
  290. SID const sid,
  291. SIterBuffer *pib,
  292. STATSTGW *pstatstg);
  293. inline SCODE Flush(VOID);
  294. inline void SetParent(CMStream * pmsParent);
  295. static int NameCompare(
  296. CDfName const *pdfn1,
  297. CDfName const *pdfn2);
  298. // Get the length of the Directory Stream in Sectors.
  299. inline ULONG GetNumDirSects(void) const;
  300. // Get the length of the Directory Stream in Entries.
  301. inline ULONG GetNumDirEntries(void) const;
  302. inline BOOL IsLargeSector () const;
  303. private:
  304. CDirVector _dv;
  305. DIRINDEX _cdsTable;
  306. CBasedMStreamPtr _pmsParent;
  307. DIROFFSET _cdeEntries;
  308. SID _sidFirstFree;
  309. SCODE Resize(DIRINDEX);
  310. inline DIRINDEX SidToTable(SID sid) const;
  311. inline SID PairToSid(
  312. DIRINDEX iTable,
  313. DIROFFSET iEntry) const;
  314. inline SCODE SidToPair(
  315. SID sid,
  316. DIRINDEX* pipds,
  317. DIROFFSET* pide) const;
  318. SCODE GetFree(SID * psid);
  319. SCODE InsertEntry(
  320. SID sidParent,
  321. SID sidInsert,
  322. CDfName const *pdfnInsert);
  323. SCODE FindEntry(
  324. SID sidParent,
  325. CDfName const *pdfnFind,
  326. DIRENTRYOP deop,
  327. SEntryBuffer *peb);
  328. SCODE SplitEntry(
  329. CDfName const *pdfn,
  330. SID sidTree,
  331. SID sidGreat,
  332. SID sidGrand,
  333. SID sidParent,
  334. SID sidChild,
  335. SID *psid);
  336. SCODE RotateEntry(
  337. CDfName const *pdfn,
  338. SID sidTree,
  339. SID sidParent,
  340. SID *psid);
  341. SCODE SetColorBlack(const SID sid);
  342. };
  343. #endif //__DIR_HXX__