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.

464 lines
9.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: dirfunc.hxx
  7. //
  8. // Contents: Inline functions for Directory code
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. //----------------------------------------------------------------------------
  15. #ifndef __DIRFUNC_HXX__
  16. #define __DIRFUNC_HXX__
  17. #include "page.hxx"
  18. class CMStream;
  19. inline BOOL CDirEntry::IsFree(VOID) const
  20. {
  21. return _mse == 0;
  22. }
  23. inline BOOL CDirEntry::IsEntry(CDfName const * pdfn) const
  24. {
  25. return !IsFree() && pdfn->IsEqual(&_dfn);
  26. }
  27. inline void CDirEntry::SetLeftSib(const SID sid)
  28. {
  29. _sidLeftSib = sid;
  30. }
  31. inline void CDirEntry::SetRightSib(const SID sid)
  32. {
  33. _sidRightSib = sid;
  34. }
  35. inline void CDirEntry::SetChild(const SID sid)
  36. {
  37. _sidChild = sid;
  38. }
  39. inline void CDirEntry::SetName(const CDfName *pdfn)
  40. {
  41. _dfn.Set(pdfn->GetLength(), pdfn->GetBuffer());
  42. }
  43. inline void CDirEntry::SetStart(const SECT sect)
  44. {
  45. msfAssert(STREAMLIKE(_mse));
  46. _sectStart=sect;
  47. }
  48. inline void CDirEntry::SetSize(const ULONGLONG ulSize)
  49. {
  50. msfAssert(STREAMLIKE(_mse));
  51. _ulSize=ulSize;
  52. }
  53. inline void CDirEntry::SetFlags(const MSENTRYFLAGS mse)
  54. {
  55. msfAssert(mse <= 0xff);
  56. _mse = (const BYTE) mse;
  57. }
  58. inline void CDirEntry::SetBitFlags(BYTE bValue, BYTE bMask)
  59. {
  60. _bflags = (BYTE) ( (_bflags & ~bMask) | (bValue & bMask));
  61. }
  62. inline void CDirEntry::SetColor(DECOLOR color)
  63. {
  64. SetBitFlags((BYTE) color, DECOLORBIT);
  65. }
  66. inline void CDirEntry::SetTime(WHICHTIME tt, TIME_T nt)
  67. {
  68. msfAssert((tt == WT_CREATION) || (tt == WT_MODIFICATION));
  69. _time[tt] = nt;
  70. }
  71. inline void CDirEntry::SetClassId(GUID cls)
  72. {
  73. msfAssert(STORAGELIKE(_mse));
  74. _clsId = cls;
  75. }
  76. inline void CDirEntry::SetUserFlags(DWORD dwUserFlags, DWORD dwMask)
  77. {
  78. msfAssert(STORAGELIKE(_mse));
  79. _dwUserFlags = (_dwUserFlags & ~dwMask) | (dwUserFlags & dwMask);
  80. }
  81. inline SID CDirEntry::GetLeftSib(VOID) const
  82. {
  83. return _sidLeftSib;
  84. }
  85. inline SID CDirEntry::GetRightSib(VOID) const
  86. {
  87. return _sidRightSib;
  88. }
  89. inline SID CDirEntry::GetChild(VOID) const
  90. {
  91. return _sidChild;
  92. }
  93. inline GUID CDirEntry::GetClassId(VOID) const
  94. {
  95. msfAssert(STORAGELIKE(_mse));
  96. return _clsId;
  97. }
  98. inline CDfName const * CDirEntry::GetName(VOID) const
  99. {
  100. return &_dfn;
  101. }
  102. inline SECT CDirEntry::GetStart(VOID) const
  103. {
  104. msfAssert(STREAMLIKE(_mse));
  105. return _sectStart;
  106. }
  107. inline ULONGLONG CDirEntry::GetSize(BOOL fLarge) const
  108. {
  109. msfAssert(STREAMLIKE(_mse));
  110. return (fLarge) ? _ulSize : _ulSize & MAX_ULONG;
  111. }
  112. inline MSENTRYFLAGS CDirEntry::GetFlags(VOID) const
  113. {
  114. return (MSENTRYFLAGS) _mse;
  115. }
  116. inline BYTE CDirEntry::GetBitFlags(VOID) const
  117. {
  118. return _bflags;
  119. }
  120. inline DECOLOR CDirEntry::GetColor(VOID) const
  121. {
  122. return((DECOLOR) (GetBitFlags() & DECOLORBIT));
  123. }
  124. inline TIME_T CDirEntry::GetTime(WHICHTIME tt) const
  125. {
  126. msfAssert((tt == WT_CREATION) || (tt == WT_MODIFICATION));
  127. return _time[tt];
  128. }
  129. inline DWORD CDirEntry::GetUserFlags(VOID) const
  130. {
  131. msfAssert(STORAGELIKE(_mse));
  132. return _dwUserFlags;
  133. }
  134. inline CDirEntry* CDirSect::GetEntry(DIROFFSET iEntry)
  135. {
  136. return &(_adeEntry[iEntry]);
  137. }
  138. //+------------------------------------------------------------------
  139. //
  140. // Method: CDirEntry::ByteSwap, public
  141. //
  142. // Synopsis: Byte swap the directory entry
  143. //
  144. // Arguments: [cbSector] -- Sector Size
  145. //
  146. //-------------------------------------------------------------------
  147. inline void CDirEntry::ByteSwap(void)
  148. {
  149. _dfn.ByteSwap();
  150. ::ByteSwap(& _sidLeftSib);
  151. ::ByteSwap(& _sidRightSib);
  152. ::ByteSwap(& _sidChild);
  153. ::ByteSwap(& _clsId);
  154. ::ByteSwap(& _dwUserFlags);
  155. ::ByteSwap(& _time[0]);
  156. ::ByteSwap(& _time[1]);
  157. ::ByteSwap(& _sectStart);
  158. ::ByteSwap((LONGLONG*) & _ulSize);
  159. }
  160. //+------------------------------------------------------------------
  161. //
  162. // Method: CDirSect::ByteSwap, public
  163. //
  164. // Synopsis: Byte swap all entries in the sector
  165. //
  166. // Arguments: [cbSector] -- Sector Size
  167. //
  168. //-------------------------------------------------------------------
  169. inline void CDirSect::ByteSwap(USHORT cbSector)
  170. {
  171. for (unsigned int i=0; i< (cbSector/sizeof(CDirEntry)); i++)
  172. _adeEntry[i].ByteSwap();
  173. }
  174. //+------------------------------------------------------------------
  175. //
  176. // Method: CDirVector::CDirVector, public
  177. //
  178. // Synopsis: Default constructor
  179. //
  180. // Notes:
  181. //
  182. //------------------------------------------------------------------
  183. inline CDirVector::CDirVector(USHORT cbSector)
  184. : CPagedVector(SIDDIR),
  185. _cbSector(cbSector)
  186. {
  187. }
  188. //+-------------------------------------------------------------------------
  189. //
  190. // Method: CDirVector::GetTable, public
  191. //
  192. // Synopsis: Return a pointer to a DirSect for the given index
  193. // into the vector.
  194. //
  195. // Arguments: [iTable] -- index into vector
  196. //
  197. // Returns: Pointer to CDirSect indicated by index
  198. //
  199. // Notes:
  200. //
  201. //--------------------------------------------------------------------------
  202. inline SCODE CDirVector::GetTable(
  203. const DIRINDEX iTable,
  204. const DWORD dwFlags,
  205. CDirSect **ppds)
  206. {
  207. SCODE sc;
  208. sc = CPagedVector::GetTable(iTable, dwFlags, (void **)ppds);
  209. if (sc == STG_S_NEWPAGE)
  210. {
  211. (*ppds)->Init(_cbSector);
  212. }
  213. return sc;
  214. }
  215. inline DIRINDEX CDirectory::SidToTable(SID sid) const
  216. {
  217. return (DIRINDEX)(sid / _cdeEntries);
  218. }
  219. inline SCODE CDirectory::GetName(const SID sid, CDfName *pdfn)
  220. {
  221. SCODE sc;
  222. CDirEntry *pde;
  223. msfChk(GetDirEntry(sid, FB_NONE, &pde));
  224. *pdfn = *(pde->GetName());
  225. ReleaseEntry(sid);
  226. Err:
  227. return sc;
  228. }
  229. //+-------------------------------------------------------------------------
  230. //
  231. // Member: CDirectory::GetStart, public
  232. //
  233. // Synposis: Retrieves the starting sector of a directory entry
  234. //
  235. // Arguments: [sid] -- Stream ID of stream in question
  236. //
  237. // Returns: Starting sector of stream
  238. //
  239. // Algorithm: Return the starting sector of the stream. If the
  240. // identifier is SIDFAT, return 0. If the identifier
  241. // is SIDDIR, return 1. Otherwise, return the starting
  242. // sector of the entry in question.
  243. //
  244. // Notes:
  245. //
  246. //---------------------------------------------------------------------------
  247. inline SCODE CDirectory::GetStart(const SID sid, SECT *psect)
  248. {
  249. msfAssert(sid <= MAXREGSID);
  250. SCODE sc;
  251. CDirEntry *pde;
  252. msfChk(GetDirEntry(sid, FB_NONE, &pde));
  253. *psect = pde->GetStart();
  254. ReleaseEntry(sid);
  255. Err:
  256. return sc;
  257. }
  258. inline SCODE CDirectory::GetSize(
  259. const SID sid,
  260. ULONGLONG * pulSize)
  261. {
  262. SCODE sc;
  263. CDirEntry *pde;
  264. msfChk(GetDirEntry(sid, FB_NONE, &pde));
  265. *pulSize = pde->GetSize(IsLargeSector());
  266. ReleaseEntry(sid);
  267. Err:
  268. return sc;
  269. }
  270. inline SCODE CDirectory::GetChild(const SID sid, SID * psid)
  271. {
  272. SCODE sc;
  273. CDirEntry *pde;
  274. msfChk(GetDirEntry(sid, FB_NONE, &pde));
  275. *psid = pde->GetChild();
  276. ReleaseEntry(sid);
  277. Err:
  278. return sc;
  279. }
  280. inline SCODE CDirectory::GetFlags(
  281. const SID sid,
  282. MSENTRYFLAGS *pmse)
  283. {
  284. SCODE sc;
  285. CDirEntry *pde;
  286. msfChk(GetDirEntry(sid, FB_NONE, &pde));
  287. *pmse = pde->GetFlags();
  288. ReleaseEntry(sid);
  289. Err:
  290. return sc;
  291. }
  292. inline SCODE CDirectory::GetClassId(const SID sid, GUID *pcls)
  293. {
  294. SCODE sc;
  295. CDirEntry *pde;
  296. msfChk(GetDirEntry(sid, FB_NONE, &pde));
  297. *pcls = pde->GetClassId();
  298. ReleaseEntry(sid);
  299. Err:
  300. return sc;
  301. }
  302. inline SCODE CDirectory::GetUserFlags(const SID sid,
  303. DWORD *pdwUserFlags)
  304. {
  305. SCODE sc;
  306. CDirEntry *pde;
  307. msfChk(GetDirEntry(sid, FB_NONE, &pde));
  308. *pdwUserFlags = pde->GetUserFlags();
  309. ReleaseEntry(sid);
  310. Err:
  311. return sc;
  312. }
  313. inline SCODE CDirectory::GetTime(
  314. const SID sid,
  315. WHICHTIME tt,
  316. TIME_T *ptime)
  317. {
  318. SCODE sc;
  319. CDirEntry *pde;
  320. msfChk(GetDirEntry(sid, FB_NONE, &pde));
  321. *ptime = pde->GetTime(tt == WT_ACCESS ? WT_MODIFICATION : tt);
  322. ReleaseEntry(sid);
  323. Err:
  324. return sc;
  325. }
  326. inline SID CDirectory::PairToSid(
  327. DIRINDEX iTable,
  328. DIROFFSET iEntry) const
  329. {
  330. return (SID)((iTable * _cdeEntries) + iEntry);
  331. }
  332. inline SCODE CDirectory::SidToPair(
  333. SID sid,
  334. DIRINDEX* pipds,
  335. DIROFFSET* pide) const
  336. {
  337. *pipds = (DIRINDEX)(sid / _cdeEntries);
  338. *pide = (DIROFFSET)(sid % _cdeEntries);
  339. return S_OK;
  340. }
  341. inline void CDirectory::SetParent(CMStream *pms)
  342. {
  343. _pmsParent = pms;
  344. _dv.SetParent(pms);
  345. }
  346. inline SCODE CDirectory::IsEntry(SID const sidParent,
  347. CDfName const *pdfn,
  348. SEntryBuffer *peb)
  349. {
  350. return FindEntry(sidParent, pdfn, DEOP_FIND, peb);
  351. }
  352. //+-------------------------------------------------------------------------
  353. //
  354. // Method: CDirectory::Flush, private
  355. //
  356. // Synopsis: Write a dirsector out to the parent
  357. //
  358. // Arguments: [sid] -- SID of modified dirEntry
  359. //
  360. // Returns: S_OK if call completed OK.
  361. //
  362. // Algorithm: Convert SID into table number, then write that
  363. // table out to the parent Multistream
  364. //
  365. // Notes:
  366. //
  367. //--------------------------------------------------------------------------
  368. inline SCODE CDirectory::Flush(VOID)
  369. {
  370. return _dv.Flush();
  371. }
  372. //+---------------------------------------------------------------------------
  373. //
  374. // Member: CDirectory::IsLargeSector, public
  375. //
  376. // Synopsis: Return true if this is a large sector docfile
  377. //
  378. // Arguments: None.
  379. //
  380. // Returns: true if _cdeEntries > 4
  381. //
  382. //----------------------------------------------------------------------------
  383. inline BOOL CDirectory::IsLargeSector () const
  384. {
  385. return (_cdeEntries > (HEADERSIZE / DIRENTRYSIZE));
  386. }
  387. #endif // #ifndef __DIRFUNC_HXX__