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.

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