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.

570 lines
15 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1996.
  5. //
  6. // File: msf.hxx
  7. //
  8. // Contents: Header for MSF for external use
  9. //
  10. // Classes: CMStream - Main multi-stream object
  11. //
  12. //--------------------------------------------------------------------------
  13. #ifndef __MSF_HXX__
  14. #define __MSF_HXX__
  15. #include "ref.hxx"
  16. #include "error.hxx"
  17. #define SECURE
  18. #define msfErr(l, e) ErrJmp(msf, l, e, sc)
  19. #define msfChkTo(l, e) if (FAILED(sc = (e))) msfErr(l, sc) else 1
  20. #define msfHChkTo(l, e) if (FAILED(sc = GetScode(e))) msfErr(l, sc) else 1
  21. #define msfChk(e) msfChkTo(Err, e)
  22. #define msfHChk(e) msfHChkTo(Err, e)
  23. #define msfMemTo(l, e) if (!(e)) msfErr(l, STG_E_INSUFFICIENTMEMORY) else 1
  24. #define msfMem(e) msfMemTo(Err, e)
  25. #if DEVL == 1
  26. DECLARE_DEBUG(msf);
  27. #endif
  28. #if DBG == 1
  29. #define msfDebugOut(x) msfInlineDebugOut x
  30. #include <assert.h>
  31. #define msfAssert(e) assert(e)
  32. #define msfVerify(e) assert(e)
  33. #else
  34. #define msfDebugOut(x)
  35. #define msfAssert(e)
  36. #define msfVerify(e) (e)
  37. #endif
  38. // MSF entry flags type
  39. typedef DWORD MSENTRYFLAGS;
  40. // MEF_ANY refers to all entries regardless of type
  41. const MSENTRYFLAGS MEF_ANY = 255;
  42. //CWCSTREAMNAME is the maximum length (in wide characters) of
  43. // a stream name.
  44. const USHORT CWCSTREAMNAME = 32;
  45. //OFFSET and SECT are used to determine positions within
  46. //a file.
  47. typedef SHORT OFFSET;
  48. typedef ULONG SECT;
  49. #define MAXINDEXTYPE ULONG
  50. //FSINDEX and FSOFFSET are used to determine the position of a sector
  51. //within the Fat.
  52. typedef ULONG FSINDEX;
  53. typedef USHORT FSOFFSET;
  54. // DIRINDEX and DIROFFSET and used to index directory tables
  55. typedef ULONG DIRINDEX;
  56. typedef USHORT DIROFFSET;
  57. //Size of a mini sector in bytes.
  58. const USHORT MINISECTORSHIFT = 6;
  59. const USHORT MINISECTORSIZE = 1 << MINISECTORSHIFT; //64
  60. //Maximum size of a ministream.
  61. const USHORT MINISTREAMSIZE=4096;
  62. //Size of a single sector in bytes.
  63. const USHORT SECTORSHIFT512 = 9;
  64. const USHORT SECTORSHIFT4K = 12;
  65. //Size of header.
  66. const USHORT HEADERSIZE = 1 << SECTORSHIFT512; //512
  67. //Size of single DirEntry
  68. const USHORT DIRENTRYSIZE = HEADERSIZE / 4;
  69. //
  70. // Predefined Sector Indices
  71. //
  72. const SECT MAXREGSECT = 0xFFFFFFFB;
  73. const SECT DIFSECT=0xFFFFFFFC;
  74. const SECT FATSECT=0xFFFFFFFD;
  75. const SECT ENDOFCHAIN=0xFFFFFFFE;
  76. const SECT FREESECT=0xFFFFFFFF;
  77. //Start of Fat chain
  78. const SECT SECTFAT = 0;
  79. //Start of directory chain
  80. const SECT SECTDIR = 1;
  81. class CDirectStream;
  82. class CMSFIterator;
  83. class CMSFPageTable;
  84. class CStreamCache;
  85. #define FLUSH_ILB TRUE
  86. // ----------------------
  87. // Byte swapping routines
  88. // ----------------------
  89. #include "../byteordr.hxx"
  90. #include "dfmsp.hxx"
  91. class CMStream;
  92. #include "header.hxx"
  93. #include "fat.hxx"
  94. #include "dir.hxx"
  95. #include "difat.hxx"
  96. //
  97. // Predefined Stream ID's
  98. //
  99. //Return code for Directory
  100. //Used to signal a 'Stream Not Found' condition
  101. const SID NOSTREAM=0xFFFFFFFF;
  102. //Stream ID of FAT chain
  103. const SID SIDFAT=0xFFFFFFFE;
  104. //Stream ID of Directory chain
  105. const SID SIDDIR=0xFFFFFFFD;
  106. //SID for root level object
  107. const SID SIDROOT = 0;
  108. //SID of MiniFat
  109. const SID SIDMINIFAT = 0xFFFFFFFC;
  110. //SID of Double-indirect Fat
  111. const SID SIDDIF = 0xFFFFFFFB;
  112. //Stream ID for MiniStream chain
  113. const SID SIDMINISTREAM = SIDROOT;
  114. //SID of the largest regular (non-control) SID
  115. const SID MAXREGSID = 0xFFFFFFFA;
  116. extern "C" WCHAR const wcsContents[];
  117. //+----------------------------------------------------------------------
  118. //
  119. // Class: CMStream (ms)
  120. //
  121. // Purpose: Main interface to multi-streams
  122. //
  123. // Interface: See below
  124. //
  125. // Notes:
  126. //
  127. //-----------------------------------------------------------------------
  128. class CMStream
  129. {
  130. public:
  131. CMStream( ILockBytes **pplstParent,
  132. USHORT uSectorShift);
  133. ~CMStream();
  134. SCODE Init(VOID);
  135. SCODE InitNew(VOID);
  136. SCODE InitConvert(VOID);
  137. void Empty(void);
  138. inline SCODE CreateEntry( SID const sidParent,
  139. CDfName const *pdfn,
  140. MSENTRYFLAGS const mefFlags,
  141. SID *psid);
  142. // No implementation, currently unused, placeholder
  143. void ReleaseEntry(SID const sid);
  144. inline SCODE DestroyEntry( SID const sidParent,
  145. CDfName const *pdfn);
  146. inline SCODE KillStream( SECT sectStart, ULONGLONG ulSize);
  147. inline SCODE RenameEntry( SID const sidParent,
  148. CDfName const *pdfn,
  149. CDfName const *pdfnNew);
  150. inline SCODE IsEntry( SID const sidParent,
  151. CDfName const *pdfn,
  152. SEntryBuffer *peb);
  153. inline SCODE StatEntry( SID const sid,
  154. CDfName *pName,
  155. STATSTGW *pstatstg);
  156. inline SCODE GetChild( SID const sid,
  157. SID *psid);
  158. inline SCODE FindGreaterEntry( SID sidParent,
  159. CDfName const *pdfnKey,
  160. SID *psid);
  161. inline SCODE GetTime( SID const sid,
  162. WHICHTIME const tt,
  163. TIME_T *pnt);
  164. inline SCODE SetTime( SID const sid,
  165. WHICHTIME const tt,
  166. TIME_T nt);
  167. inline SCODE GetClass( SID const sid, CLSID *pclsid);
  168. inline SCODE SetClass(SID const sid, REFCLSID clsid);
  169. inline SCODE GetStateBits(SID const sd, DWORD *pgrfStateBits);
  170. inline SCODE SetStateBits(SID const sid, DWORD grfStateBits,
  171. DWORD grfMask);
  172. inline SCODE GetEntrySize( SID const sid, ULONGLONG *pcbSize);
  173. SCODE GetIterator( SID const sidParent, CMSFIterator **pit);
  174. inline SCODE SetSize(VOID);
  175. inline SCODE SetMiniSize(VOID);
  176. SCODE MWrite( SID sid,
  177. BOOL fIsMiniStream,
  178. ULONGLONG ulOffset,
  179. VOID const HUGEP *pBuffer,
  180. ULONG ulCount,
  181. CStreamCache *pstmc,
  182. ULONG *pulRetVal);
  183. SCODE GetName(SID const sid, CDfName *pdfn);
  184. inline CMSFHeader * GetHeader(VOID) const;
  185. inline CFat * GetFat(VOID) const;
  186. inline CFat * GetMiniFat(VOID) const;
  187. inline CDIFat * GetDIFat(VOID) const;
  188. inline CDirectory * GetDir(VOID) const;
  189. inline CMSFPageTable * GetPageTable(VOID) const;
  190. inline USHORT GetSectorSize(VOID) const;
  191. inline USHORT GetSectorShift(VOID) const;
  192. inline USHORT GetSectorMask(VOID) const;
  193. SCODE Flush(BOOL fFlushILB);
  194. SCODE FlushHeader(USHORT uForce);
  195. inline CDirectStream * GetMiniStream(VOID) const;
  196. inline ILockBytes * GetILB(VOID) const;
  197. inline SCODE GetSect(SID sid, SECT sect, SECT *psect);
  198. SCODE GetESect(SID sid, SECT sect, SECT *psect);
  199. SCODE SecureSect(
  200. const SECT sect,
  201. const ULONGLONG ulSize,
  202. const BOOL fIsMini);
  203. private:
  204. ILockBytes **_pplstParent;
  205. CMSFHeader _hdr;
  206. CMSFPageTable *_pmpt;
  207. CDirectory _dir;
  208. CFat _fat;
  209. CDIFat _fatDif;
  210. CFat _fatMini;
  211. CDirectStream* _pdsministream;
  212. USHORT _uSectorSize;
  213. USHORT _uSectorShift;
  214. USHORT _uSectorMask;
  215. SCODE InitCommon(VOID);
  216. SECT GetStart(SID sid) const;
  217. SCODE ConvertILB(SECT sectMax);
  218. friend SCODE DllGetScratchMultiStream( CMStream **ppms,
  219. ILockBytes **pplstStream,
  220. CMStream *pmsMaster);
  221. #ifdef _MSC_VER
  222. #pragma warning(disable:4512)
  223. // default assignment operator could not be generated, which is fine
  224. // since we are not using it.
  225. #endif // _MSC_VER
  226. };
  227. #ifdef _MSC_VER
  228. #pragma warning(default:4512)
  229. #endif // _MSC_VER
  230. //+-------------------------------------------------------------------------
  231. //
  232. // Method: CMStream::GetSectorSize, public
  233. //
  234. // Synopsis: Returns the current sector size
  235. //
  236. //--------------------------------------------------------------------------
  237. inline USHORT CMStream::GetSectorSize(VOID) const
  238. {
  239. return _uSectorSize;
  240. }
  241. //+-------------------------------------------------------------------------
  242. //
  243. // Method: CMStream::GetSectorShift, public
  244. //
  245. // Synopsis: Returns the current shift for sector math
  246. //
  247. //--------------------------------------------------------------------------
  248. inline USHORT CMStream::GetSectorShift(VOID) const
  249. {
  250. return _uSectorShift;
  251. }
  252. //+-------------------------------------------------------------------------
  253. //
  254. // Method: CMStream::GetSectorMask, public
  255. //
  256. // Synopsis: Returns the current mask for sector math
  257. //
  258. //--------------------------------------------------------------------------
  259. inline USHORT CMStream::GetSectorMask(VOID) const
  260. {
  261. return _uSectorMask;
  262. }
  263. //+-------------------------------------------------------------------------
  264. //
  265. // Method: CMStream::GetHeader, public
  266. //
  267. // Synopsis: Returns a pointer to the current header.
  268. //
  269. //--------------------------------------------------------------------------
  270. inline CMSFHeader * CMStream::GetHeader(VOID) const
  271. {
  272. return (CMSFHeader *)(&_hdr);
  273. }
  274. //+-------------------------------------------------------------------------
  275. //
  276. // Method: CMStream::GetFat, public
  277. //
  278. // Synopsis: Returns a pointer to the current Fat
  279. //
  280. //--------------------------------------------------------------------------
  281. inline CFat * CMStream::GetFat(VOID) const
  282. {
  283. return (CFat *)&_fat;
  284. }
  285. //+-------------------------------------------------------------------------
  286. //
  287. // Member: CMStream::GetMiniFat
  288. //
  289. // Synopsis: Returns a pointer to the current minifat
  290. //
  291. //--------------------------------------------------------------------------
  292. inline CFat * CMStream::GetMiniFat(VOID) const
  293. {
  294. return (CFat *)&_fatMini;
  295. }
  296. //+-------------------------------------------------------------------------
  297. //
  298. // Method: CMStream::GetDIFat, public
  299. //
  300. // Synopsis: Returns pointer to the current Double Indirect Fat
  301. //
  302. //--------------------------------------------------------------------------
  303. inline CDIFat * CMStream::GetDIFat(VOID) const
  304. {
  305. return (CDIFat *)&_fatDif;
  306. }
  307. //+-------------------------------------------------------------------------
  308. //
  309. // Member: CMStream::GetDir
  310. //
  311. // Synopsis: Returns a pointer to the current directory
  312. //
  313. //--------------------------------------------------------------------------
  314. inline CDirectory * CMStream::GetDir(VOID) const
  315. {
  316. return (CDirectory *)&_dir;
  317. }
  318. //+-------------------------------------------------------------------------
  319. //
  320. // Member: CMStream::GetMiniStream
  321. //
  322. // Synopsis: Returns pointer to the current ministream
  323. //
  324. //--------------------------------------------------------------------------
  325. inline CDirectStream * CMStream::GetMiniStream(VOID) const
  326. {
  327. return(_pdsministream);
  328. }
  329. //+-------------------------------------------------------------------------
  330. //
  331. // Member: CMStream::GetILB
  332. //
  333. // Synopsis: Returns a pointer to the current parent ILockBytes
  334. //
  335. //--------------------------------------------------------------------------
  336. inline ILockBytes * CMStream::GetILB(VOID) const
  337. {
  338. return(*_pplstParent);
  339. }
  340. //+-------------------------------------------------------------------------
  341. //
  342. // Member: CMStream::GetPageTable
  343. //
  344. // Synopsis: Returns a pointer to the current page table
  345. //
  346. //--------------------------------------------------------------------------
  347. inline CMSFPageTable * CMStream::GetPageTable(VOID) const
  348. {
  349. return _pmpt;
  350. }
  351. //+-------------------------------------------------------------------------
  352. //
  353. // Method: CMStream::StatEntry
  354. //
  355. // Synopsis: For a given handle, fill in the Multistream specific
  356. // information of a STATSTG.
  357. //
  358. // Arguments: [sid] -- SID that information is requested on.
  359. // [pName] -- Name of entry to fill in (if not null)
  360. // [pstatstg] -- STATSTG to fill in (if not null)
  361. //
  362. // Returns: S_OK
  363. //
  364. //--------------------------------------------------------------------------
  365. inline SCODE CMStream::StatEntry(SID const sid,
  366. CDfName *pName,
  367. STATSTGW *pstatstg)
  368. {
  369. return _dir.StatEntry(sid, pName, pstatstg);
  370. }
  371. //+-------------------------------------------------------------------------
  372. //
  373. // Member: CMStream::GetChild, public
  374. //
  375. // Synposis: Return the child SID for a directory entry
  376. //
  377. // Arguments: [sid] - Parent
  378. // [psid] - Child SID return
  379. //
  380. // Returns: Appropriate status code
  381. //
  382. //---------------------------------------------------------------------------
  383. inline SCODE CMStream::GetChild(
  384. SID const sid,
  385. SID *psid)
  386. {
  387. return _dir.GetChild(sid, psid);
  388. }
  389. //+---------------------------------------------------------------------------
  390. //
  391. // Member: CMStream::FindGreaterEntry, public
  392. //
  393. // Synopsis: Returns the next greater entry for the given parent SID
  394. //
  395. // Arguments: [sidParent] - SID of parent storage
  396. // [CDfName *pdfnKey] - Previous key
  397. // [psid] - Result
  398. //
  399. // Returns: Appropriate status code
  400. //
  401. // Modifies: [psid]
  402. //
  403. //----------------------------------------------------------------------------
  404. inline SCODE CMStream::FindGreaterEntry(SID sidParent,
  405. CDfName const *pdfnKey,
  406. SID *psid)
  407. {
  408. return _dir.FindGreaterEntry(sidParent, pdfnKey, psid);
  409. }
  410. extern SCODE DllMultiStreamFromStream(
  411. CMStream **ppms,
  412. ILockBytes **pplstStream,
  413. DWORD dwFlags);
  414. extern SCODE DllMultiStreamFromCorruptedStream(
  415. CMStream **ppms,
  416. ILockBytes **pplstStream,
  417. DWORD dwFlags);
  418. extern void DllReleaseMultiStream(CMStream *pms);
  419. extern SCODE DllIsMultiStream(ILockBytes *plstStream);
  420. extern SCODE DllGetCommitSig(ILockBytes *plst, DFSIGNATURE *psig);
  421. extern SCODE DllSetCommitSig(ILockBytes *plst, DFSIGNATURE sig);
  422. #if DEVL == 1
  423. extern VOID SetInfoLevel(ULONG x);
  424. #endif
  425. #endif //__MSF_HXX__