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.

522 lines
16 KiB

  1. /*
  2. +---------------------------------------------------------------
  3. *
  4. * Microsoft Windows
  5. * Copyright (C) Microsoft Corporation, 1992 - 1996.
  6. *
  7. * File: storage.h
  8. *
  9. * Contents: This is the main file to include to use the reference
  10. * implementation.
  11. *
  12. * Note: Some of the defintions have been changed to TCHAR
  13. * instead of WCHAR, to add support for ANSI APIs.
  14. * TCHAR becomes WCHAR with _UNICODE defined, and char
  15. * otherwise. (See tchar.h for details).
  16. *
  17. *---------------------------------------------------------------
  18. */
  19. #ifndef _STORAGE_H_
  20. #define _STORAGE_H_
  21. #include "ref.hxx"
  22. #include "tchar.h"
  23. /****** Storage Error Codes *************************************************/
  24. /* DOS-based error codes */
  25. #define STG_E_INVALIDFUNCTION \
  26. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x01)
  27. #define STG_E_FILENOTFOUND \
  28. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x02)
  29. #define STG_E_PATHNOTFOUND \
  30. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x03)
  31. #define STG_E_TOOMANYOPENFILES \
  32. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x04)
  33. #define STG_E_ACCESSDENIED \
  34. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x05)
  35. #define STG_E_INVALIDHANDLE \
  36. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x06)
  37. #define STG_E_INSUFFICIENTMEMORY \
  38. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x08)
  39. #define STG_E_INVALIDPOINTER \
  40. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x09)
  41. #define STG_E_NOMOREFILES \
  42. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x12)
  43. #define STG_E_DISKISWRITEPROTECTED \
  44. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x13)
  45. #define STG_E_SEEKERROR \
  46. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x19)
  47. #define STG_E_SHAREVIOLATION \
  48. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x20)
  49. #define STG_E_WRITEFAULT \
  50. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x1d)
  51. #define STG_E_READFAULT \
  52. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x1e)
  53. #define STG_E_LOCKVIOLATION \
  54. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x21)
  55. #define STG_E_FILEALREADYEXISTS \
  56. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x50)
  57. #define STG_E_INVALIDPARAMETER \
  58. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x57)
  59. #define STG_E_MEDIUMFULL \
  60. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x70)
  61. #define STG_E_ABNORMALAPIEXIT \
  62. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0xfa)
  63. #define STG_E_INVALIDHEADER \
  64. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0xfb)
  65. #define STG_E_INVALIDNAME \
  66. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0xfc)
  67. #define STG_E_UNKNOWN \
  68. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0xfd)
  69. #define STG_E_UNIMPLEMENTEDFUNCTION\
  70. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0xfe)
  71. #define STG_E_INVALIDFLAG \
  72. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0xff)
  73. /* Standard storage error codes */
  74. #define STG_E_INUSE \
  75. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x100)
  76. #define STG_E_NOTCURRENT \
  77. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x101)
  78. #define STG_E_REVERTED \
  79. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x102)
  80. #define STG_E_CANTSAVE \
  81. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x103)
  82. #define STG_E_OLDFORMAT \
  83. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x104)
  84. #define STG_E_OLDDLL \
  85. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x105)
  86. #define STG_E_SHAREREQUIRED \
  87. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x106)
  88. #define STG_E_NOTFILEBASEDSTORAGE \
  89. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x107)
  90. #define STG_E_DOCFILECORRUPT \
  91. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x109)
  92. #define STG_E_BADBASEADDRESS \
  93. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x110)
  94. #define STG_E_DOCFILETOOLARGE \
  95. MAKE_SCODE(SEVERITY_ERROR, FACILITY_STORAGE, 0x111)
  96. /* Information returns */
  97. #define STG_S_CONVERTED \
  98. MAKE_SCODE(SEVERITY_SUCCESS, FACILITY_STORAGE, 0x200)
  99. #define STG_S_BUFFEROVERFLOW \
  100. MAKE_SCODE(SEVERITY_SUCCESS, FACILITY_STORAGE, 0x201)
  101. #define STG_S_TRYOVERWRITE \
  102. MAKE_SCODE(SEVERITY_SUCCESS, FACILITY_STORAGE, 0x202)
  103. /****** Storage types *******************************************************/
  104. #ifndef HUGEP
  105. #define HUGEP
  106. #endif
  107. #define CWCSTORAGENAME 32
  108. /* Storage instantiation modes */
  109. #define STGM_DIRECT 0x00000000L
  110. /* not used in ref, but defined here for error checking etc. */
  111. #define STGM_TRANSACTED 0x00010000L
  112. #define STGM_SIMPLE 0x08000000L
  113. #define STGM_NOSCRATCH 0x00100000L
  114. #define STGM_READ 0x00000000L
  115. #define STGM_WRITE 0x00000001L
  116. #define STGM_READWRITE 0x00000002L
  117. #define STGM_SHARE_DENY_NONE 0x00000040L
  118. #define STGM_SHARE_DENY_READ 0x00000030L
  119. #define STGM_SHARE_DENY_WRITE 0x00000020L
  120. #define STGM_SHARE_EXCLUSIVE 0x00000010L
  121. #define STGM_PRIORITY 0x00040000L
  122. #define STGM_DELETEONRELEASE 0x04000000L
  123. #define STGM_CREATE 0x00001000L
  124. #define STGM_CONVERT 0x00020000L
  125. #define STGM_FAILIFTHERE 0x00000000L
  126. /* Storage commit types */
  127. typedef enum tagSTGC
  128. {
  129. STGC_DEFAULT = 0,
  130. STGC_OVERWRITE = 1,
  131. STGC_ONLYIFCURRENT = 2,
  132. STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE = 4
  133. } STGC;
  134. /* Stream name block definitions */
  135. typedef TCHAR FAR* FAR* SNB;
  136. #ifndef _FILETIME_
  137. #define _FILETIME_
  138. typedef struct FARSTRUCT tagFILETIME
  139. {
  140. DWORD dwLowDateTime;
  141. DWORD dwHighDateTime;
  142. } FILETIME;
  143. #endif
  144. /* Storage stat buffer */
  145. typedef struct FARSTRUCT tagSTATSTG
  146. {
  147. TCHAR FAR* pwcsName;
  148. DWORD type;
  149. ULARGE_INTEGER cbSize;
  150. FILETIME mtime;
  151. FILETIME ctime;
  152. FILETIME atime;
  153. DWORD grfMode;
  154. DWORD grfLocksSupported;
  155. CLSID clsid;
  156. DWORD grfStateBits;
  157. DWORD reserved;
  158. } STATSTG;
  159. /* Storage element types */
  160. typedef enum tagSTGTY
  161. {
  162. STGTY_STORAGE = 1,
  163. STGTY_STREAM = 2,
  164. STGTY_LOCKBYTES = 3,
  165. STGTY_PROPERTY = 4
  166. } STGTY;
  167. typedef enum tagSTREAM_SEEK
  168. {
  169. STREAM_SEEK_SET = 0,
  170. STREAM_SEEK_CUR = 1,
  171. STREAM_SEEK_END = 2
  172. } STREAM_SEEK;
  173. typedef enum tagLOCKTYPE
  174. {
  175. LOCK_WRITE = 1,
  176. LOCK_EXCLUSIVE = 2,
  177. LOCK_ONLYONCE = 4
  178. } LOCKTYPE;
  179. typedef enum tagSTGMOVE
  180. {
  181. STGMOVE_MOVE = 0,
  182. STGMOVE_COPY = 1
  183. } STGMOVE;
  184. typedef enum tagSTATFLAG
  185. {
  186. STATFLAG_DEFAULT = 0,
  187. STATFLAG_NONAME = 1
  188. } STATFLAG;
  189. #define STGFMT_STORAGE 0
  190. #define STGFMT_FILE 3
  191. #define STGFMT_ANY 4
  192. #define STGFMT_DOCFILE 5
  193. // STG initialization options for StgCreateStorageEx
  194. #define STGOPTIONS_VERSION 2
  195. typedef struct tagSTGOPTIONS
  196. {
  197. USHORT usVersion; // Versions 1 and 2 supported
  198. USHORT reserved; // must be 0 for padding
  199. ULONG ulSectorSize; // docfile header sector size (512)
  200. const TCHAR *pwcsTemplateFile; // version 2 or above
  201. } STGOPTIONS;
  202. /****** Storage Enumerators *************************************************/
  203. #define LPENUMSTATSTG IEnumSTATSTG FAR*
  204. #undef INTERFACE
  205. #define INTERFACE IEnumSTATSTG
  206. DECLARE_INTERFACE_(IEnumSTATSTG, IUnknown)
  207. {
  208. /* *** IUnknown methods *** */
  209. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  210. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  211. STDMETHOD_(ULONG,Release) (THIS) PURE;
  212. /* *** IENUMSTATSTG methods *** */
  213. STDMETHOD(Next) (THIS_ ULONG celt, STATSTG FAR * rgelt, ULONG FAR *pceltFetched) PURE;
  214. STDMETHOD(Skip) (THIS_ ULONG celt) PURE;
  215. STDMETHOD(Reset) (THIS) PURE;
  216. STDMETHOD(Clone) (THIS_ IEnumSTATSTG FAR *FAR *ppenm) PURE;
  217. };
  218. /****** ILockBytes Interface ************************************************/
  219. #define LPLOCKBYTES ILockBytes FAR*
  220. #undef INTERFACE
  221. #define INTERFACE ILockBytes
  222. DECLARE_INTERFACE_(ILockBytes, IUnknown)
  223. {
  224. /* *** IUnknown methods *** */
  225. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  226. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  227. STDMETHOD_(ULONG,Release) (THIS) PURE;
  228. /* *** ILockBytes methods *** */
  229. STDMETHOD(ReadAt) (THIS_ ULARGE_INTEGER ulOffset,
  230. VOID HUGEP *pv,
  231. ULONG cb,
  232. ULONG FAR *pcbRead) PURE;
  233. STDMETHOD(WriteAt) (THIS_ ULARGE_INTEGER ulOffset,
  234. VOID const HUGEP *pv,
  235. ULONG cb,
  236. ULONG FAR *pcbWritten) PURE;
  237. STDMETHOD(Flush) (THIS) PURE;
  238. STDMETHOD(SetSize) (THIS_ ULARGE_INTEGER cb) PURE;
  239. STDMETHOD(LockRegion) (THIS_ ULARGE_INTEGER libOffset,
  240. ULARGE_INTEGER cb,
  241. DWORD dwLockType) PURE;
  242. STDMETHOD(UnlockRegion) (THIS_ ULARGE_INTEGER libOffset,
  243. ULARGE_INTEGER cb,
  244. DWORD dwLockType) PURE;
  245. STDMETHOD(Stat) (THIS_ STATSTG FAR *pstatstg, DWORD grfStatFlag) PURE;
  246. };
  247. /****** IStream Interface ***************************************************/
  248. #define LPSTREAM IStream FAR*
  249. #undef INTERFACE
  250. #define INTERFACE IStream
  251. DECLARE_INTERFACE_(IStream, IUnknown)
  252. {
  253. /* *** IUnknown methods *** */
  254. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  255. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  256. STDMETHOD_(ULONG,Release) (THIS) PURE;
  257. /* *** IStream methods *** */
  258. STDMETHOD(Read) (THIS_ VOID HUGEP *pv,
  259. ULONG cb, ULONG FAR *pcbRead) PURE;
  260. STDMETHOD(Write) (THIS_ VOID const HUGEP *pv,
  261. ULONG cb,
  262. ULONG FAR *pcbWritten) PURE;
  263. STDMETHOD(Seek) (THIS_ LARGE_INTEGER dlibMove,
  264. DWORD dwOrigin,
  265. ULARGE_INTEGER FAR *plibNewPosition) PURE;
  266. STDMETHOD(SetSize) (THIS_ ULARGE_INTEGER libNewSize) PURE;
  267. STDMETHOD(CopyTo) (THIS_ IStream FAR *pstm,
  268. ULARGE_INTEGER cb,
  269. ULARGE_INTEGER FAR *pcbRead,
  270. ULARGE_INTEGER FAR *pcbWritten) PURE;
  271. STDMETHOD(Commit) (THIS_ DWORD grfCommitFlags) PURE;
  272. STDMETHOD(Revert) (THIS) PURE;
  273. STDMETHOD(LockRegion) (THIS_ ULARGE_INTEGER libOffset,
  274. ULARGE_INTEGER cb,
  275. DWORD dwLockType) PURE;
  276. STDMETHOD(UnlockRegion) (THIS_ ULARGE_INTEGER libOffset,
  277. ULARGE_INTEGER cb,
  278. DWORD dwLockType) PURE;
  279. STDMETHOD(Stat) (THIS_ STATSTG FAR *pstatstg, DWORD grfStatFlag) PURE;
  280. STDMETHOD(Clone)(THIS_ IStream FAR * FAR *ppstm) PURE;
  281. };
  282. /****** IStorage Interface **************************************************/
  283. #define LPSTORAGE IStorage FAR*
  284. #undef INTERFACE
  285. #define INTERFACE IStorage
  286. DECLARE_INTERFACE_(IStorage, IUnknown)
  287. {
  288. /* *** IUnknown methods *** */
  289. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  290. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  291. STDMETHOD_(ULONG,Release) (THIS) PURE;
  292. /* *** IStorage methods *** */
  293. STDMETHOD(CreateStream) (THIS_ const TCHAR FAR* pwcsName,
  294. DWORD grfMode,
  295. DWORD reserved1,
  296. DWORD reserved2,
  297. IStream FAR *FAR *ppstm) PURE;
  298. STDMETHOD(OpenStream) (THIS_ const TCHAR FAR* pwcsName,
  299. void FAR *reserved1,
  300. DWORD grfMode,
  301. DWORD reserved2,
  302. IStream FAR *FAR *ppstm) PURE;
  303. STDMETHOD(CreateStorage) (THIS_ const TCHAR FAR* pwcsName,
  304. DWORD grfMode,
  305. DWORD reserved1,
  306. DWORD reserved2,
  307. IStorage FAR *FAR *ppstg) PURE;
  308. STDMETHOD(OpenStorage) (THIS_ const TCHAR FAR* pwcsName,
  309. IStorage FAR *pstgPriority,
  310. DWORD grfMode,
  311. SNB snbExclude,
  312. DWORD reserved,
  313. IStorage FAR *FAR *ppstg) PURE;
  314. STDMETHOD(CopyTo) (THIS_ DWORD ciidExclude,
  315. IID const FAR *rgiidExclude,
  316. SNB snbExclude,
  317. IStorage FAR *pstgDest) PURE;
  318. STDMETHOD(MoveElementTo) (THIS_ TCHAR const FAR* lpszName,
  319. IStorage FAR *pstgDest,
  320. TCHAR const FAR* lpszNewName,
  321. DWORD grfFlags) PURE;
  322. STDMETHOD(Commit) (THIS_ DWORD grfCommitFlags) PURE;
  323. STDMETHOD(Revert) (THIS) PURE;
  324. STDMETHOD(EnumElements) (THIS_ DWORD reserved1,
  325. void FAR *reserved2,
  326. DWORD reserved3,
  327. IEnumSTATSTG FAR *FAR *ppenm) PURE;
  328. STDMETHOD(DestroyElement) (THIS_ const TCHAR FAR* pwcsName) PURE;
  329. STDMETHOD(RenameElement) (THIS_ const TCHAR FAR* pwcsOldName,
  330. const TCHAR FAR* pwcsNewName) PURE;
  331. STDMETHOD(SetElementTimes) (THIS_ const TCHAR FAR *lpszName,
  332. FILETIME const FAR *pctime,
  333. FILETIME const FAR *patime,
  334. FILETIME const FAR *pmtime) PURE;
  335. STDMETHOD(SetClass) (THIS_ REFCLSID clsid) PURE;
  336. STDMETHOD(SetStateBits) (THIS_ DWORD grfStateBits, DWORD grfMask) PURE;
  337. STDMETHOD(Stat) (THIS_ STATSTG FAR *pstatstg, DWORD grfStatFlag) PURE;
  338. };
  339. /****** IRootStorage Interface **********************************************/
  340. #define LPROOTSTORAGE IRootStorage FAR*
  341. #undef INTERFACE
  342. #define INTERFACE IRootStorage
  343. DECLARE_INTERFACE_(IRootStorage, IUnknown)
  344. {
  345. /* *** IUnknown methods *** */
  346. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  347. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  348. STDMETHOD_(ULONG,Release) (THIS) PURE;
  349. /* *** IRootStorage methods *** */
  350. STDMETHOD(SwitchToFile) (THIS_ LPTSTR lpstrFile) PURE;
  351. };
  352. /****** Storage API Prototypes ********************************************/
  353. #ifdef __cplusplus
  354. extern "C" {
  355. #endif
  356. STDAPI StgCreateDocfile(const TCHAR FAR* pwcsName,
  357. DWORD grfMode,
  358. DWORD reserved,
  359. IStorage FAR * FAR *ppstgOpen);
  360. STDAPI StgCreateDocfileOnILockBytes(ILockBytes FAR *plkbyt,
  361. DWORD grfMode,
  362. DWORD reserved,
  363. IStorage FAR * FAR *ppstgOpen);
  364. STDAPI StgOpenStorage(const TCHAR FAR* pwcsName,
  365. IStorage FAR *pstgPriority,
  366. DWORD grfMode,
  367. SNB snbExclude,
  368. DWORD reserved,
  369. IStorage FAR * FAR *ppstgOpen);
  370. STDAPI StgOpenStorageOnILockBytes(ILockBytes FAR *plkbyt,
  371. IStorage FAR *pstgPriority,
  372. DWORD grfMode,
  373. SNB snbExclude,
  374. DWORD reserved,
  375. IStorage FAR * FAR *ppstgOpen);
  376. STDAPI StgIsStorageFile(const TCHAR FAR* pwcsName);
  377. STDAPI StgIsStorageILockBytes(ILockBytes FAR* plkbyt);
  378. STDAPI StgCreateStorageEx (const TCHAR* pwcsName,
  379. DWORD grfMode,
  380. DWORD stgfmt, // enum
  381. DWORD grfAttrs, // reserved
  382. STGOPTIONS * pStgOptions,
  383. void * reserved,
  384. REFIID riid,
  385. void ** ppObjectOpen);
  386. /****** Malloc API's ********************************************/
  387. interface IMalloc;
  388. #define LPMALLOC IMalloc FAR*
  389. STDAPI CoGetMalloc( DWORD dwMemContext, LPMALLOC * ppMalloc );
  390. STDAPI_(LPVOID) CoTaskMemAlloc( ULONG cb );
  391. STDAPI_(void) CoTaskMemFree( void* pv );
  392. STDAPI_(LPVOID) CoTaskMemRealloc( LPVOID pv, ULONG cb );
  393. #ifdef __cplusplus
  394. };
  395. #endif
  396. /****** IMalloc Interface **********************************************/
  397. #undef INTERFACE
  398. #define INTERFACE IMalloc
  399. DECLARE_INTERFACE_(IMalloc, IUnknown)
  400. {
  401. /*** IUnknown methods ***/
  402. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  403. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  404. STDMETHOD_(ULONG,Release) (THIS) PURE;
  405. /*** IMallic methods ***/
  406. STDMETHOD_(void*,Alloc) ( ULONG cb) PURE;
  407. STDMETHOD_(void *,Realloc) ( void *pv, ULONG cb) PURE;
  408. STDMETHOD_(void,Free) ( void *pv) PURE;
  409. STDMETHOD_(ULONG,GetSize) ( void *pv) PURE;
  410. STDMETHOD_(int,DidAlloc) ( void *pv) PURE;
  411. STDMETHOD_(void,HeapMinimize)( void ) PURE;
  412. };
  413. #define MEMCTX_TASK 1 /* the only supported flag for CoGetMalloc */
  414. #endif /* ifndef _STORAGE_H_ */