ReactOS 0.4.15-dev-7788-g1ad9096
sdbwrite.c File Reference
#include "windef.h"
#include "ntndk.h"
#include <appcompat/sdbtypes.h>
#include <appcompat/sdbtagid.h>
#include "sdbpapi.h"
#include "sdbstringtable.h"
Include dependency graph for sdbwrite.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Functions

BOOL WINAPI SdbWriteStringRefTag (PDB pdb, TAG tag, TAGID tagid)
 
BOOL WINAPI SdbWriteStringTag (PDB pdb, TAG tag, LPCWSTR string)
 
TAGID WINAPI SdbBeginWriteListTag (PDB pdb, TAG tag)
 
BOOL WINAPI SdbEndWriteListTag (PDB pdb, TAGID tagid)
 
void WINAPI SdbCloseDatabase (PDB)
 
static void WINAPI SdbpWrite (PDB pdb, const void *data, DWORD size)
 
static BOOL WINAPI SdbpGetOrAddStringRef (PDB pdb, LPCWSTR string, TAGID *tagid)
 
static BOOL WINAPI SdbpWriteStringtable (PDB pdb)
 
PDB WINAPI SdbCreateDatabase (LPCWSTR path, PATH_TYPE type)
 
void WINAPI SdbCloseDatabaseWrite (PDB pdb)
 
BOOL WINAPI SdbWriteNULLTag (PDB pdb, TAG tag)
 
BOOL WINAPI SdbWriteWORDTag (PDB pdb, TAG tag, WORD data)
 
BOOL WINAPI SdbWriteDWORDTag (PDB pdb, TAG tag, DWORD data)
 
BOOL WINAPI SdbWriteQWORDTag (PDB pdb, TAG tag, QWORD data)
 
BOOL WINAPI SdbWriteBinaryTag (PDB pdb, TAG tag, const BYTE *data, DWORD size)
 
BOOL WINAPI SdbWriteBinaryTagFromFile (PDB pdb, TAG tag, LPCWSTR path)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file sdbwrite.c.

Function Documentation

◆ SdbBeginWriteListTag()

TAGID WINAPI SdbBeginWriteListTag ( PDB  pdb,
TAG  tag 
)

Writes a list tag to specified database All subsequent SdbWrite* functions shall write to newly created list untill TAGID of that list is passed to SdbEndWriteListTag.

Parameters
[in]pdbHandle to the shim database.
[in]tagTAG for the list
             RETURNS Success: TAGID of the newly created list, or TAGID_NULL on failure.
Returns
A TAGID.

Definition at line 321 of file sdbwrite.c.

322{
323 TAGID list_id;
324 DWORD dum = 0;
325
327 return TAGID_NULL;
328
329 list_id = pdb->write_iter;
330 SdbpWrite(pdb, &tag, sizeof(TAG));
331 SdbpWrite(pdb, &dum, sizeof(dum)); /* reserve some memory for storing list size */
332 return list_id;
333}
CDumExe dum
Definition: CComObject.cpp:71
DWORD TAGID
static PDB pdb
Definition: db.cpp:172
#define TAGID_NULL
Definition: db.cpp:38
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TAG_TYPE_LIST
Definition: apphelp.c:42
BOOL WINAPI SdbpCheckTagType(TAG tag, WORD type)
Definition: sdbapi.c:254
static void WINAPI SdbpWrite(PDB pdb, const void *data, DWORD size)
Definition: sdbwrite.c:38
Definition: fs_rec.h:143
Definition: ecma_167.h:138

Referenced by Database::BeginWriteListTag(), and SdbpWriteStringtable().

◆ SdbCloseDatabase()

void WINAPI SdbCloseDatabase ( PDB  pdb)

Closes specified database and frees its memory.

Parameters
[in]pdbHandle to the shim database.

Definition at line 373 of file sdbapi.c.

374{
375 if (!pdb)
376 return;
377
378 if (pdb->file)
379 NtClose(pdb->file);
380 if (pdb->string_buffer)
381 SdbCloseDatabase(pdb->string_buffer);
382 if (pdb->string_lookup)
383 SdbpTableDestroy(&pdb->string_lookup);
384 SdbFree(pdb->data);
385 SdbFree(pdb);
386}
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
void WINAPI SdbCloseDatabase(PDB pdb)
Definition: sdbapi.c:373
#define SdbFree(mem)
Definition: sdbpapi.h:37
void SdbpTableDestroy(struct SdbStringHashTable **pTable)

Referenced by SdbCloseDatabase(), SdbCloseDatabaseWrite(), SdbGetDatabaseVersion(), SdbOpenDatabase(), SdbpCreate(), and SdbpOpenDatabase().

◆ SdbCloseDatabaseWrite()

void WINAPI SdbCloseDatabaseWrite ( PDB  pdb)

Closes specified database and writes data to file.

Parameters
[in]pdbHandle to the shim database.

Definition at line 129 of file sdbwrite.c.

130{
131 ASSERT(pdb->for_write);
133 SdbpFlush(pdb);
135}
#define ASSERT(a)
Definition: mode.c:44
void WINAPI SdbpFlush(PDB pdb)
Definition: sdbapi.c:140
static BOOL WINAPI SdbpWriteStringtable(PDB pdb)
Definition: sdbwrite.c:80
void WINAPI SdbCloseDatabase(PDB)
Definition: sdbapi.c:373

Referenced by Database::toSdb().

◆ SdbCreateDatabase()

PDB WINAPI SdbCreateDatabase ( LPCWSTR  path,
PATH_TYPE  type 
)

Creates new shim database file

If a file already exists on specified path, that file shall be overwritten.

Note
Use SdbCloseDatabaseWrite to close the database opened with this function.
Parameters
[in]pathPath to the new shim database.
[in]typeType of path. Either DOS_PATH or NT_PATH.
Returns
Success: Handle to the newly created shim database, NULL otherwise.

Definition at line 104 of file sdbwrite.c.

105{
106 static const DWORD version_major = 2, version_minor = 1;
107 static const char* magic = "sdbf";
108 PDB pdb;
109
111 if (!pdb)
112 return NULL;
113
114 pdb->size = sizeof(DWORD) + sizeof(DWORD) + (DWORD)strlen(magic);
115 pdb->data = SdbAlloc(pdb->size);
116
117 SdbpWrite(pdb, &version_major, sizeof(DWORD));
118 SdbpWrite(pdb, &version_minor, sizeof(DWORD));
120
121 return pdb;
122}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
u32_t magic(void)
#define DWORD
Definition: nt_native.h:44
PDB WINAPI SdbpCreate(LPCWSTR path, PATH_TYPE type, BOOL write)
Definition: sdbapi.c:93
#define SdbAlloc(size)
Definition: sdbpapi.h:35

Referenced by Database::toSdb().

◆ SdbEndWriteListTag()

BOOL WINAPI SdbEndWriteListTag ( PDB  pdb,
TAGID  tagid 
)

Marks end of the specified list.

Parameters
[in]pdbHandle to the shim database.
[in]tagidTAGID of the list.
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 343 of file sdbwrite.c.

344{
345 ASSERT(pdb->for_write);
346
348 return FALSE;
349
350 /* Write size of list to list tag header */
351 *(DWORD*)&pdb->data[tagid + sizeof(TAG)] = pdb->write_iter - tagid - sizeof(TAG) - sizeof(TAGID);
352 return TRUE;
353}
#define TAG(x)
Definition: ObTypes.c:145
#define FALSE
Definition: types.h:117
BOOL WINAPI SdbpCheckTagIDType(PDB pdb, TAGID tagid, WORD type)
Definition: sdbapi.c:261

Referenced by Database::EndWriteListTag(), and SdbpWriteStringtable().

◆ SdbpGetOrAddStringRef()

static BOOL WINAPI SdbpGetOrAddStringRef ( PDB  pdb,
LPCWSTR  string,
TAGID tagid 
)
static

Definition at line 55 of file sdbwrite.c.

56{
57 PDB buf = pdb->string_buffer;
58 ASSERT(pdb->for_write);
59
60 if (pdb->string_buffer == NULL)
61 {
62 pdb->string_buffer = buf = SdbAlloc(sizeof(DB));
63 if (buf == NULL)
64 return FALSE;
65 buf->size = 128;
66 buf->data = SdbAlloc(buf->size);
67 buf->for_write = TRUE;
68 if (buf->data == NULL)
69 return FALSE;
70 }
71
72 *tagid = buf->write_iter + sizeof(TAG) + sizeof(DWORD);
73 if (SdbpAddStringToTable(&pdb->string_lookup, string, tagid))
75
76 return pdb->string_lookup != NULL;
77}
#define TAG_STRINGTABLE_ITEM
Definition: db.cpp:96
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
BOOL SdbpAddStringToTable(struct SdbStringHashTable **table, const WCHAR *str, TAGID *tagid)
BOOL WINAPI SdbWriteStringTag(PDB pdb, TAG tag, LPCWSTR string)
Definition: sdbwrite.c:220
Definition: sdbtypes.h:24

Referenced by SdbWriteStringTag().

◆ SdbpWrite()

static void WINAPI SdbpWrite ( PDB  pdb,
const void data,
DWORD  size 
)
static

Definition at line 38 of file sdbwrite.c.

39{
40 ASSERT(pdb->for_write);
41 if (pdb->write_iter + size > pdb->size)
42 {
43 DWORD oldSize = pdb->size;
44 /* Round to powers of two to prevent too many reallocations */
45 while (pdb->size < pdb->write_iter + size) pdb->size <<= 1;
46 pdb->data = SdbReAlloc(pdb->data, pdb->size, oldSize);
47 }
48
49 memcpy(pdb->data + pdb->write_iter, data, size);
50 pdb->write_iter += size;
51}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define SdbReAlloc(mem, size, oldSize)
Definition: sdbpapi.h:36

Referenced by SdbBeginWriteListTag(), SdbCreateDatabase(), SdbpWriteStringtable(), SdbWriteBinaryTag(), SdbWriteDWORDTag(), SdbWriteNULLTag(), SdbWriteQWORDTag(), SdbWriteStringRefTag(), SdbWriteStringTag(), and SdbWriteWORDTag().

◆ SdbpWriteStringtable()

static BOOL WINAPI SdbpWriteStringtable ( PDB  pdb)
static

Definition at line 80 of file sdbwrite.c.

81{
83 PDB buf = pdb->string_buffer;
84 if (buf == NULL || pdb->string_lookup == NULL)
85 return FALSE;
86
88 SdbpWrite(pdb, buf->data, buf->write_iter);
90}
#define TAG_STRINGTABLE
Definition: db.cpp:94
TAGID WINAPI SdbBeginWriteListTag(PDB pdb, TAG tag)
Definition: sdbwrite.c:321
BOOL WINAPI SdbEndWriteListTag(PDB pdb, TAGID tagid)
Definition: sdbwrite.c:343

Referenced by SdbCloseDatabaseWrite().

◆ SdbWriteBinaryTag()

BOOL WINAPI SdbWriteBinaryTag ( PDB  pdb,
TAG  tag,
const BYTE data,
DWORD  size 
)

Writes data the specified shim database.

Parameters
[in]pdbHandle to the shim database.
[in]tagA tag for the entry.
[in]dataPointer to data.
[in]sizeNumber of bytes to write.
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 273 of file sdbwrite.c.

274{
276 return FALSE;
277
278 SdbpWrite(pdb, &tag, sizeof(TAG));
279 SdbpWrite(pdb, &size, sizeof(size));
281 return TRUE;
282}
#define TAG_TYPE_BINARY
Definition: apphelp.c:44

Referenced by SdbWriteBinaryTagFromFile(), and Database::WriteBinary().

◆ SdbWriteBinaryTagFromFile()

BOOL WINAPI SdbWriteBinaryTagFromFile ( PDB  pdb,
TAG  tag,
LPCWSTR  path 
)

Writes data from a file to the specified shim database.

Parameters
[in]pdbHandle to the shim database.
[in]tagA tag for the entry.
[in]pathPath of the input file.
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 294 of file sdbwrite.c.

295{
296 MEMMAPPED mapped;
297
299 return FALSE;
300
301 if (!SdbpOpenMemMappedFile(path, &mapped))
302 return FALSE;
303
304 SdbWriteBinaryTag(pdb, tag, mapped.view, mapped.size);
305 SdbpCloseMemMappedFile(&mapped);
306 return TRUE;
307}
void WINAPI SdbpCloseMemMappedFile(PMEMMAPPED mapping)
Definition: sdbapi.c:244
BOOL WINAPI SdbpOpenMemMappedFile(LPCWSTR path, PMEMMAPPED mapping)
Definition: sdbapi.c:170
BOOL WINAPI SdbWriteBinaryTag(PDB pdb, TAG tag, const BYTE *data, DWORD size)
Definition: sdbwrite.c:273
SIZE_T size
Definition: sdbpapi.h:46
PBYTE view
Definition: sdbpapi.h:45

◆ SdbWriteDWORDTag()

BOOL WINAPI SdbWriteDWORDTag ( PDB  pdb,
TAG  tag,
DWORD  data 
)

Writes a DWORD entry to the specified shim database.

Parameters
[in]pdbHandle to the shim database.
[in]tagA tag for the entry.
[in]dataDWORD entry which will be written to the database.
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 182 of file sdbwrite.c.

183{
185 return FALSE;
186
187 SdbpWrite(pdb, &tag, sizeof(TAG));
188 SdbpWrite(pdb, &data, sizeof(data));
189 return TRUE;
190}
#define TAG_TYPE_DWORD
Definition: shimdbg.c:107

Referenced by Database::toSdb(), ShimRef::toSdb(), FlagRef::toSdb(), and Database::WriteDWord().

◆ SdbWriteNULLTag()

BOOL WINAPI SdbWriteNULLTag ( PDB  pdb,
TAG  tag 
)

Writes a tag-only (NULL) entry to the specified shim database.

Parameters
[in]pdbHandle to the shim database.
[in]tagA tag for the entry.
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 145 of file sdbwrite.c.

146{
148 return FALSE;
149
150 SdbpWrite(pdb, &tag, sizeof(TAG));
151 return TRUE;
152}
#define TAG_TYPE_NULL
Definition: apphelp.c:36

Referenced by InExclude::toSdb().

◆ SdbWriteQWORDTag()

BOOL WINAPI SdbWriteQWORDTag ( PDB  pdb,
TAG  tag,
QWORD  data 
)

Writes a DWORD entry to the specified shim database.

Parameters
[in]pdbHandle to the shim database.
[in]tagA tag for the entry.
[in]dataQWORD entry which will be written to the database.
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 201 of file sdbwrite.c.

202{
204 return FALSE;
205
206 SdbpWrite(pdb, &tag, sizeof(TAG));
207 SdbpWrite(pdb, &data, sizeof(data));
208 return TRUE;
209}
#define TAG_TYPE_QWORD
Definition: shimdbg.c:108

Referenced by Database::toSdb(), and Database::WriteQWord().

◆ SdbWriteStringRefTag()

BOOL WINAPI SdbWriteStringRefTag ( PDB  pdb,
TAG  tag,
TAGID  tagid 
)

Writes a stringref tag to specified database

Note
Reference (tagid) is not checked for validity.
Parameters
[in]pdbHandle to the shim database.
[in]tagTAG which will be written.
[in]tagidTAGID of the string tag refers to.
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 253 of file sdbwrite.c.

254{
256 return FALSE;
257
258 SdbpWrite(pdb, &tag, sizeof(TAG));
259 SdbpWrite(pdb, &tagid, sizeof(tagid));
260 return TRUE;
261}
#define TAG_TYPE_STRINGREF
Definition: shimdbg.c:109

Referenced by SdbWriteStringTag().

◆ SdbWriteStringTag()

BOOL WINAPI SdbWriteStringTag ( PDB  pdb,
TAG  tag,
LPCWSTR  string 
)

Writes a wide string entry to the specified shim database.

Parameters
[in]pdbHandle to the shim database.
[in]tagA tag for the entry.
[in]stringWide string entry which will be written to the database.
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 220 of file sdbwrite.c.

221{
222 DWORD size;
223
225 {
226 TAGID tagid = 0;
227 if (!SdbpGetOrAddStringRef(pdb, string, &tagid))
228 return FALSE;
229
230 return SdbWriteStringRefTag(pdb, tag, tagid);
231 }
232
234 return FALSE;
235
236 size = SdbpStrsize(string);
237 SdbpWrite(pdb, &tag, sizeof(TAG));
238 SdbpWrite(pdb, &size, sizeof(size));
239 SdbpWrite(pdb, string, size);
240 return TRUE;
241}
DWORD SdbpStrsize(PCWSTR string)
Definition: sdbapi.c:157
#define TAG_TYPE_STRING
Definition: apphelp.c:43
BOOL WINAPI SdbWriteStringRefTag(PDB pdb, TAG tag, TAGID tagid)
Definition: sdbwrite.c:253
static BOOL WINAPI SdbpGetOrAddStringRef(PDB pdb, LPCWSTR string, TAGID *tagid)
Definition: sdbwrite.c:55

Referenced by SdbpGetOrAddStringRef(), and Database::WriteString().

◆ SdbWriteWORDTag()

BOOL WINAPI SdbWriteWORDTag ( PDB  pdb,
TAG  tag,
WORD  data 
)

Writes a WORD entry to the specified shim database.

Parameters
[in]pdbHandle to the shim database.
[in]tagA tag for the entry.
[in]dataWORD entry which will be written to the database.
Returns
TRUE if it succeeds, FALSE if it fails.

Definition at line 163 of file sdbwrite.c.

164{
166 return FALSE;
167
168 SdbpWrite(pdb, &tag, sizeof(TAG));
169 SdbpWrite(pdb, &data, sizeof(data));
170 return TRUE;
171}
#define TAG_TYPE_WORD
Definition: apphelp.c:38