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.

561 lines
12 KiB

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