ReactOS 0.4.16-dev-2332-g4cba65d
storage32.c
Go to the documentation of this file.
1/*
2 * Compound Storage (32 bit version)
3 * Storage implementation
4 *
5 * This file contains the compound file implementation
6 * of the storage interface.
7 *
8 * Copyright 1999 Francis Beaudet
9 * Copyright 1999 Sylvain St-Germain
10 * Copyright 1999 Thuy Nguyen
11 * Copyright 2005 Mike McCormack
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 *
27 * NOTES
28 * The compound file implementation of IStorage used for create
29 * and manage substorages and streams within a storage object
30 * residing in a compound file object.
31 */
32
33#include <assert.h>
34#include <stdarg.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38
39#define COBJMACROS
40#include "windef.h"
41#include "winbase.h"
42#include "winnls.h"
43#include "winuser.h"
44#include "wine/debug.h"
45
46#include "ole2.h" /* For Write/ReadClassStm */
47
48#include "winreg.h"
49#include "wine/wingdi16.h"
50
52
53static const BYTE STORAGE_magic[8] ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1};
54
55/***********************************************************************
56 * WriteClassStg [coml2.@]
57 */
59{
60 if (!pStg)
61 return E_INVALIDARG;
62
63 if (!rclsid)
65
66 return IStorage_SetClass(pStg, rclsid);
67}
68
69/***********************************************************************
70 * ReadClassStg (coml2.@)
71 */
73{
74 STATSTG pstatstg;
75 HRESULT hRes;
76
77 TRACE("(%p, %p)\n", pstg, pclsid);
78
79 if (!pstg || !pclsid)
80 return E_INVALIDARG;
81
82 /*
83 * read a STATSTG structure (contains the clsid) from the storage
84 */
85 hRes = IStorage_Stat(pstg, &pstatstg, STATFLAG_NONAME);
86
87 if (SUCCEEDED(hRes))
88 *pclsid = pstatstg.clsid;
89
90 return hRes;
91}
92
93/***********************************************************************
94 * WriteClassStm (coml2.@)
95 */
97{
98 TRACE("(%p,%p)\n", pStm, rclsid);
99
100 if (!pStm || !rclsid)
101 return E_INVALIDARG;
102
103 return IStream_Write(pStm, rclsid, sizeof(CLSID), NULL);
104}
105
106/***********************************************************************
107 * ReadClassStm (coml2.@)
108 */
110{
111 ULONG nbByte;
112 HRESULT res;
113
114 TRACE("(%p,%p)\n", pStm, pclsid);
115
116 if (!pStm || !pclsid)
117 return E_INVALIDARG;
118
119 /* clear the output args */
120 *pclsid = CLSID_NULL;
121
122 res = IStream_Read(pStm, pclsid, sizeof(CLSID), &nbByte);
123
124 if (FAILED(res))
125 return res;
126
127 if (nbByte != sizeof(CLSID))
128 return STG_E_READFAULT;
129 else
130 return S_OK;
131}
132
135 OleStream_Convert = 0x00000004
137
138/***********************************************************************
139 * GetConvertStg (coml2.@)
140 */
142{
143 static const DWORD version_magic = 0x02000001;
144 DWORD header[2];
146 HRESULT hr;
147
148 TRACE("%p\n", stg);
149
150 if (!stg) return E_INVALIDARG;
151
152 hr = IStorage_OpenStream(stg, L"\1Ole", NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stream);
153 if (FAILED(hr)) return hr;
154
155 hr = IStream_Read(stream, header, sizeof(header), NULL);
156 IStream_Release(stream);
157 if (FAILED(hr)) return hr;
158
159 if (header[0] != version_magic)
160 {
161 ERR("got wrong version magic for 1Ole stream, %#lx.\n", header[0]);
162 return E_FAIL;
163 }
164
165 return header[1] & OleStream_Convert ? S_OK : S_FALSE;
166}
167
168/******************************************************************************
169 * StgIsStorageILockBytes [coml2.@]
170 */
172{
173 BYTE sig[sizeof(STORAGE_magic)];
175 ULONG read = 0;
176
177 offset.HighPart = 0;
178 offset.LowPart = 0;
179
180 ILockBytes_ReadAt(plkbyt, offset, sig, sizeof(sig), &read);
181
182 if (read == sizeof(sig) && memcmp(sig, STORAGE_magic, sizeof(sig)) == 0)
183 return S_OK;
184
185 return S_FALSE;
186}
187
188/******************************************************************************
189 * StgIsStorageFile [coml2.@]
190 */
192{
193 HANDLE hf;
194 BYTE magic[8];
195 DWORD bytes_read;
196
197 TRACE("%s\n", debugstr_w(fn));
201
202 if (hf == INVALID_HANDLE_VALUE)
203 return STG_E_FILENOTFOUND;
204
205 if (!ReadFile(hf, magic, 8, &bytes_read, NULL))
206 {
207 WARN(" unable to read file\n");
208 CloseHandle(hf);
209 return S_FALSE;
210 }
211
212 CloseHandle(hf);
213
214 if (bytes_read != 8)
215 {
216 TRACE(" too short\n");
217 return S_FALSE;
218 }
219
220 if (!memcmp(magic, STORAGE_magic, 8))
221 {
222 TRACE(" -> YES\n");
223 return S_OK;
224 }
225
226 TRACE(" -> Invalid header.\n");
227 return S_FALSE;
228}
229
230/******************************************************************************
231 * StgCreatePropSetStg [coml2.@]
232 */
234{
235 TRACE("%p, %#lx, %p.\n", pstg, reserved, propset);
236 if (reserved)
238
239 return IStorage_QueryInterface(pstg, &IID_IPropertySetStorage, (void**)propset);
240}
#define read
Definition: acwin.h:96
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
HRESULT WINAPI ReadClassStg(IStorage *pstg, CLSID *pclsid)
Definition: storage32.c:72
HRESULT WINAPI WriteClassStm(IStream *pStm, REFCLSID rclsid)
Definition: storage32.c:96
HRESULT WINAPI StgIsStorageFile(LPCOLESTR fn)
Definition: storage32.c:191
static const BYTE STORAGE_magic[8]
Definition: storage32.c:53
HRESULT WINAPI ReadClassStm(IStream *pStm, CLSID *pclsid)
Definition: storage32.c:109
HRESULT WINAPI GetConvertStg(IStorage *stg)
Definition: storage32.c:141
HRESULT WINAPI StgCreatePropSetStg(IStorage *pstg, DWORD reserved, IPropertySetStorage **propset)
Definition: storage32.c:233
HRESULT WINAPI StgIsStorageILockBytes(ILockBytes *plkbyt)
Definition: storage32.c:171
HRESULT WINAPI WriteClassStg(IStorage *pStg, REFCLSID rclsid)
Definition: storage32.c:58
stream_1ole_flags
Definition: storage32.c:133
@ OleStream_Convert
Definition: storage32.c:135
@ OleStream_LinkedObject
Definition: storage32.c:134
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
#define L(x)
Definition: resources.c:13
r reserved
Definition: btrfs.c:3006
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint res
Definition: glext.h:9613
GLintptr offset
Definition: glext.h:5920
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_w
Definition: kernel32.h:32
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:940
#define STGM_READ
Definition: objbase.h:934
#define CLSID_NULL
Definition: guiddef.h:99
#define REFCLSID
Definition: guiddef.h:117
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
Definition: parse.h:23
uint32_t ULONG
Definition: typedefs.h:59
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159
#define WINAPI
Definition: msvc.h:6
#define STG_E_INVALIDPOINTER
Definition: winerror.h:3666
#define S_FALSE
Definition: winerror.h:3451
#define STG_E_READFAULT
Definition: winerror.h:3671
#define STG_E_FILENOTFOUND
Definition: winerror.h:3660
#define STG_E_INVALIDPARAMETER
Definition: winerror.h:3675
unsigned char BYTE
Definition: xxhash.c:193