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.

392 lines
10 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: dfmsp.hxx
  7. //
  8. // Contents: DocFile and MultiStream shared private definitions
  9. //
  10. //---------------------------------------------------------------
  11. #ifndef __DFMSP_HXX__
  12. #define __DFMSP_HXX__
  13. #include "ref.hxx"
  14. #include "ole.hxx"
  15. #include "msf.hxx"
  16. #include "wchar.h"
  17. #include <memory.h>
  18. #include <string.h>
  19. #include "../time.hxx"
  20. // Target-dependent things
  21. //
  22. // x86 16-bit build optimizations
  23. //
  24. // Some function parameters are always stack based pointers,
  25. // so we can let the compiler use near addressing via ss by
  26. // declaring the parameter stack based.
  27. //
  28. #define STACKBASED
  29. //
  30. // x86 16-bit retail build optimizations
  31. //
  32. // For the retail build, we group the code segments,
  33. // allowing us to make many calls near.
  34. //
  35. // Segmented memory model definitions
  36. #define HUGEP
  37. #ifndef LISet32
  38. #define LISet32(li, v) \
  39. ((li).HighPart = ((LONG)(v)) < 0 ? -1 : 0, (li).LowPart = (v))
  40. #endif
  41. #ifndef ULISet32
  42. #define ULISet32(li, v) ((li).HighPart = 0, (li).LowPart = (v))
  43. #endif
  44. #define LISetLow(li, v) ((li).LowPart = (v))
  45. #define LISetHigh(li, v) ((li).HighPart = (v))
  46. #define ULISetLow(li, v) ((li).LowPart = (v))
  47. #define ULISetHigh(li, v) ((li).HighPart = (v))
  48. #define LIGetLow(li) ((li).LowPart)
  49. #define LIGetHigh(li) ((li).HighPart)
  50. #define ULIGetLow(li) ((li).LowPart)
  51. #define ULIGetHigh(li) ((li).HighPart)
  52. // Fast safe increment/decrement
  53. #define AtomicInc(lp) (++*(lp))
  54. #define AtomicDec(lp) (--*(lp))
  55. // Switchable ANSI/Unicode support
  56. // Conversion routines assume null termination before max characters
  57. //----------------------------------------------------------------------------
  58. // The name of this function might change, so encapsulate it
  59. #define DfGetScode(hr) GetScode(hr)
  60. //
  61. // These function now just check for NULL values or are disabled
  62. // -- system dependent
  63. //
  64. // We leave these functions in so that it is a good place to verify memory,
  65. // if they can be implemented.
  66. //
  67. #define ValidateNotNull(x) \
  68. ((x) ? S_OK : STG_E_INVALIDPOINTER)
  69. #define ValidateBuffer(pv, n) \
  70. ValidateNotNull(pv)
  71. #define ValidatePtrBuffer(pv) \
  72. ValidateNotNull(pv)
  73. #define ValidateHugeBuffer(pv, n) \
  74. ValidateNotNull(pv)
  75. #define ValidateOutBuffer(pv, n) \
  76. ValidateNotNull(pv)
  77. #define ValidateOutPtrBuffer(pv) \
  78. ValidateNotNull(pv)
  79. #define ValidateHugeOutBuffer(pv, n) \
  80. ValidateNotNull(pv)
  81. #define ValidateIid(riid) S_OK // disabled
  82. #define ValidateInterface(punk,riid) \
  83. ValidateNotNull(punk)
  84. #define ValidateWcs(pwcs, cwcMax) \
  85. ValdateNotNull(pwcs)
  86. #define ValidateSz(psz, cchMax) S_OK \
  87. ValidateNotNull(psz)
  88. #define ValidateNameW(pwcs, cchMax) \
  89. ((pwcs)?(S_OK):(STG_E_INVALIDNAME))
  90. #define ValidateNameA(psz, cchMax) \
  91. ((psz)?(S_OK):(STG_E_INVALIDNAME))
  92. // Enumeration for Get/SetTime
  93. enum WHICHTIME
  94. {
  95. WT_CREATION=0,
  96. WT_MODIFICATION,
  97. WT_ACCESS
  98. };
  99. // Signature for transactioning
  100. typedef DWORD DFSIGNATURE;
  101. #define DF_INVALIDSIGNATURE ((DFSIGNATURE)-1)
  102. // Convenience macros for signature creation
  103. #define LONGSIG(c1, c2, c3, c4) \
  104. (((ULONG) (BYTE) (c1)) | \
  105. (((ULONG) (BYTE) (c2)) << 8) | \
  106. (((ULONG) (BYTE) (c3)) << 16) | \
  107. (((ULONG) (BYTE) (c4)) << 24))
  108. #ifndef min
  109. #define min(a, b) ((a)<(b) ? (a) : (b))
  110. #endif
  111. #ifndef max
  112. #define max(a, b) ((a)>(b) ? (a) : (b))
  113. #endif
  114. #define DfAllocWC(cwc, ppwcs) (*ppwcs = new WCHAR[cwc], \
  115. (*ppwcs != NULL) ? S_OK: STG_E_INSUFFICIENTMEMORY)
  116. #define DfAllocWCS(pwcs, ppwcs) DfAllocWC(wcslen(pwcs)+1, ppwcs)
  117. // Docfile locally unique identity
  118. // Every entry in a multistream has a LUID generated and stored for it
  119. typedef DWORD DFLUID;
  120. #define DF_NOLUID 0
  121. typedef WCHAR **SNBW;
  122. #ifndef _UNICODE
  123. typedef struct
  124. {
  125. WCHAR *pwcsName;
  126. DWORD type;
  127. ULARGE_INTEGER cbSize;
  128. FILETIME mtime;
  129. FILETIME ctime;
  130. FILETIME atime;
  131. DWORD grfMode;
  132. DWORD grfLocksSupported;
  133. CLSID clsid;
  134. DWORD grfStateBits;
  135. DWORD reserved;
  136. } STATSTGW;
  137. #else // if _UNICODE
  138. typedef STATSTG STATSTGW;
  139. #endif // ! _UNICODE
  140. #define TSTDMETHODIMP SCODE
  141. #define TSTDAPI(name) SCODE name##W
  142. #define CBSTORAGENAME (CWCSTORAGENAME*sizeof(WCHAR))
  143. // A Unicode case-insensitive compare
  144. // No such thing really exists so we use our own
  145. #define dfwcsnicmp(wcsa, wcsb, len) wcsnicmp(wcsa, wcsb, len)
  146. // A name for a docfile element
  147. class CDfName
  148. {
  149. private:
  150. BYTE _ab[CBSTORAGENAME];
  151. WORD _cb;
  152. public:
  153. CDfName(void) { _cb = 0; }
  154. void Set(WORD const cb, BYTE const *pb)
  155. {
  156. _cb = cb;
  157. if (pb)
  158. memcpy(_ab, pb, cb);
  159. }
  160. void Set(WCHAR const *pwcs)
  161. {
  162. Set( (WORD) ((wcslen(pwcs)+1)*sizeof(WCHAR)), (BYTE const *)pwcs);
  163. }
  164. // Special method for names with prepended character
  165. void Set(WCHAR const wcLead, WCHAR const *pwcs)
  166. {
  167. olAssert((wcslen(pwcs)+2)*sizeof(WCHAR) < CBSTORAGENAME);
  168. _cb = (USHORT) ((wcslen(pwcs)+2)*sizeof(WCHAR));
  169. *(WCHAR *)_ab = wcLead;
  170. wcscpy((WCHAR *)_ab+1, pwcs);
  171. }
  172. inline void Set(CDfName const *pdfn);
  173. CDfName(WORD const cb, BYTE const *pb) { Set(cb, pb); }
  174. CDfName(WCHAR const *pwcs) { Set(pwcs); }
  175. // CDfName(char const *psz) { Set(psz); }
  176. WORD GetLength(void) const { return _cb; }
  177. BYTE *GetBuffer(void) const { return (BYTE *) _ab; }
  178. BOOL IsEqual(CDfName const *dfn) const
  179. {
  180. // This assumes that all DfNames are actually Unicode strings
  181. return _cb == dfn->_cb &&
  182. dfwcsnicmp((WCHAR *)_ab, (WCHAR *)dfn->GetBuffer(), _cb) == 0;
  183. }
  184. inline void ByteSwap(void);
  185. };
  186. inline void CDfName::Set(CDfName const *pdfn)
  187. {
  188. Set(pdfn->GetLength(), pdfn->GetBuffer());
  189. }
  190. inline void CDfName::ByteSwap(void)
  191. {
  192. // assume all names are wide characters, we swap each word
  193. WCHAR *awName = (WCHAR*) _ab;
  194. ::ByteSwap(&_cb);
  195. for (unsigned int i=0; i<CBSTORAGENAME/sizeof(WCHAR); i++)
  196. {
  197. ::ByteSwap(awName);
  198. awName++;
  199. }
  200. }
  201. // Fast, fixed space iterator structure
  202. struct SIterBuffer
  203. {
  204. CDfName dfnName;
  205. DWORD type;
  206. };
  207. //SID is a Stream Identifier
  208. typedef ULONG SID;
  209. // IsEntry entry information
  210. struct SEntryBuffer
  211. {
  212. DFLUID luid;
  213. DWORD dwType;
  214. SID sid;
  215. };
  216. // Destroy flags
  217. #define DESTROY_FROM_HANDLE 0
  218. #define DESTROY_FROM_ENTRY 1
  219. #define DESTROY_FROM 0x01
  220. #define DESTROY_SELF 0x40
  221. #define DESTROY_RECURSIVE 0x80
  222. #define DESTROY_HANDLE (DESTROY_FROM_HANDLE | DESTROY_SELF)
  223. #define DESTROY_ENTRY (DESTROY_FROM_ENTRY | DESTROY_SELF)
  224. // Root startup flags
  225. #define RSF_OPEN 0x00
  226. #define RSF_CONVERT 0x01
  227. #define RSF_TRUNCATE 0x02
  228. #define RSF_CREATE 0x04
  229. #define RSF_DELAY 0x08
  230. #define RSF_DELETEONRELEASE 0x10
  231. #define RSF_OPENCREATE 0x20
  232. #define RSF_RESERVE_HANDLE 0x40
  233. #define RSF_CREATEFLAGS (RSF_CREATE | RSF_TRUNCATE | RSF_OPENCREATE)
  234. // Stream copy buffer size
  235. ULONG const STREAMBUFFERSIZE = 8192;
  236. // ILockBytes copy buffer size
  237. ULONG const LOCKBYTESBUFFERSIZE = 16384;
  238. // Docfile flags for permissions and other information kept
  239. // on streams and docfiles
  240. typedef WORD DFLAGS;
  241. #define DF_TRANSACTEDSELF 0x0001
  242. #define DF_TRANSACTED 0x0002
  243. #define DF_DIRECT 0x0000
  244. #define DF_INDEPENDENT 0x0004
  245. #define DF_DEPENDENT 0x0000
  246. #define DF_COMMIT 0x0008
  247. #define DF_ABORT 0x0000
  248. #define DF_INVALID 0x0010
  249. #define DF_REVERTED 0x0020
  250. #define DF_NOTREVERTED 0x0000
  251. #define DF_READ 0x0040
  252. #define DF_WRITE 0x0080
  253. #define DF_READWRITE (DF_READ | DF_WRITE)
  254. #define DF_DENYREAD 0x0100
  255. #define DF_DENYWRITE 0x0200
  256. #define DF_DENYALL (DF_DENYREAD | DF_DENYWRITE)
  257. #define DF_PRIORITY 0x0400
  258. #define DF_CREATE 0x0800
  259. #define DF_CACHE 0x1000
  260. #define DF_NOUPDATE 0x2000
  261. // Shift required to translate from DF_READWRITE to DF_DENYALL
  262. #define DF_DENIALSHIFT 2
  263. // Permission abstraction macros
  264. // These only work with DF_* flags
  265. #define P_READ(f) ((f) & DF_READ)
  266. #define P_WRITE(f) ((f) & DF_WRITE)
  267. #define P_READWRITE(f) (((f) & (DF_READ | DF_WRITE)) == (DF_READ | DF_WRITE))
  268. #define P_DENYREAD(f) ((f) & DF_DENYREAD)
  269. #define P_DENYWRITE(f) ((f) & DF_DENYWRITE)
  270. #define P_DENYALL(f) (((f) & (DF_DENYREAD | DF_DENYWRITE)) == \
  271. (DF_DENYREAD | DF_DENYWRITE))
  272. #define P_PRIORITY(f) ((f) & DF_PRIORITY)
  273. #define P_TRANSACTED(f) ((f) & DF_TRANSACTED)
  274. #define P_DIRECT(f) (!P_TRANSACTED(f))
  275. #define P_INDEPENDENT(f) ((f) & DF_INDEPENDENT)
  276. #define P_DEPENDENT(f) (!P_INDEPENDENT(f))
  277. #define P_TSELF(f) ((f) & DF_TRANSACTEDSELF)
  278. #define P_INVALID(f) ((f) & DF_INVALID)
  279. #define P_REVERTED(f) ((f) & DF_REVERTED)
  280. #define P_COMMIT(f) ((f) & DF_COMMIT)
  281. #define P_ABORT(f) (!P_COMMIT(f))
  282. #define P_CREATE(f) ((f) & DF_CREATE)
  283. #define P_CACHE(f) ((f) & DF_CACHE)
  284. #define P_NOUPDATE(f) ((f) & DF_NOUPDATE)
  285. // Translation functions
  286. DFLAGS ModeToDFlags(DWORD const dwModeFlags);
  287. DWORD DFlagsToMode(DFLAGS const df);
  288. // Flags for what state has been dirtied
  289. #define DIRTY_CREATETIME 0x0001
  290. #define DIRTY_MODIFYTIME 0x0002
  291. #define DIRTY_ACCESSTIME 0x0004
  292. #define DIRTY_CLASS 0x0008
  293. #define DIRTY_STATEBITS 0x0010
  294. // Allow text in asserts
  295. #define aMsg(s) (s)
  296. #define STGTY_REAL (STGTY_STORAGE | STGTY_STREAM | STGTY_LOCKBYTES)
  297. #define REAL_STGTY(f) (f)
  298. extern void *DfMemAlloc(DWORD dwFlags, size_t size);
  299. extern void DfMemFree(void *mem);
  300. extern void *TaskMemAlloc(size_t size);
  301. extern void TaskMemFree(void *mem);
  302. // Buffer management
  303. #define CB_LARGEBUFFER 32768
  304. #define CB_PAGEBUFFER 4096
  305. #define CB_SMALLBUFFER 512
  306. extern SCODE GetBuffer(USHORT cbMin, USHORT cbMax, BYTE **ppb,
  307. USHORT *pcbActual);
  308. extern void GetSafeBuffer(USHORT cbMin, USHORT cbMax, BYTE **ppb,
  309. USHORT *pcbActual);
  310. extern void FreeBuffer(BYTE *pb);
  311. #endif // #ifndef __DFMSP_HXX__