summaryrefslogtreecommitdiff
path: root/tools/mdbx_dump
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-05-22 20:25:34 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-05-22 20:25:34 +0300
commit4ba812b71eb6e3cbefcea50d71dd8b7b98779a73 (patch)
tree89f8527d0e01ccaa96b3f9498dad1073e512b8c6 /tools/mdbx_dump
parente705d77b5ce00ddcddb4584b6b3df3e538a86b46 (diff)
Database
- libmdbx inlined not to change the code of utilities - libmdbx.mir removed from build scripts
Diffstat (limited to 'tools/mdbx_dump')
-rw-r--r--tools/mdbx_dump/mdbx_dump.vcxproj49
-rw-r--r--tools/mdbx_dump/mdbx_dump.vcxproj.filters17
-rw-r--r--tools/mdbx_dump/src/mdbx_dump.cc393
-rw-r--r--tools/mdbx_dump/src/stdafx.cxx20
-rw-r--r--tools/mdbx_dump/src/stdafx.h30
5 files changed, 0 insertions, 509 deletions
diff --git a/tools/mdbx_dump/mdbx_dump.vcxproj b/tools/mdbx_dump/mdbx_dump.vcxproj
deleted file mode 100644
index 9b608a4fa1..0000000000
--- a/tools/mdbx_dump/mdbx_dump.vcxproj
+++ /dev/null
@@ -1,49 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup Label="ProjectConfigurations">
- <ProjectConfiguration Include="Debug|Win32">
- <Configuration>Debug</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Debug|x64">
- <Configuration>Debug</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
- <Configuration>Release</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|x64">
- <Configuration>Release</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- </ItemGroup>
- <PropertyGroup Label="Globals">
- <ProjectGuid>{EE383404-7976-4E87-BD13-A9B7B47C0C10}</ProjectGuid>
- <ProjectName>mdbx_dump</ProjectName>
- </PropertyGroup>
- <ImportGroup Label="PropertySheets">
- <Import Project="$(ProjectDir)..\..\build\vc.common\app.props" />
- </ImportGroup>
- <ItemGroup>
- <ClCompile Include="src\mdbx_dump.cc">
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
- </ClCompile>
- <ClCompile Include="src\stdafx.cxx">
- <PrecompiledHeader>Create</PrecompiledHeader>
- </ClCompile>
- <ClInclude Include="src\stdafx.h" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\..\libs\libmdbx\libmdbx.vcxproj">
- <Project>{6d19209b-ece7-4b9c-941c-0aa2b484f199}</Project>
- </ProjectReference>
- </ItemGroup>
- <ItemDefinitionGroup>
- <Link>
- <SubSystem>Console</SubSystem>
- <DelayLoadDLLs Condition="'$(Configuration)'=='Debug'">libmdbx.mir;ucrtbased.dll;vcruntime140d.dll</DelayLoadDLLs>
- <DelayLoadDLLs Condition="'$(Configuration)'=='Release'">libmdbx.mir;ucrtbase.dll;api-ms-win-crt-string-l1-1-0.dll;api-ms-win-crt-heap-l1-1-0.dll;api-ms-win-crt-locale-l1-1-0.dll;api-ms-win-crt-math-l1-1-0.dll;api-ms-win-crt-runtime-l1-1-0.dll;api-ms-win-crt-stdio-l1-1-0.dll;VCRUNTIME140.dll</DelayLoadDLLs>
- </Link>
- </ItemDefinitionGroup>
-</Project> \ No newline at end of file
diff --git a/tools/mdbx_dump/mdbx_dump.vcxproj.filters b/tools/mdbx_dump/mdbx_dump.vcxproj.filters
deleted file mode 100644
index 59fc2eb498..0000000000
--- a/tools/mdbx_dump/mdbx_dump.vcxproj.filters
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <Import Project="$(ProjectDir)..\..\build\vc.common\common.filters" />
- <ItemGroup>
- <ClCompile Include="src\stdafx.cxx">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="src\mdbx_dump.cc">
- <Filter>Source Files</Filter>
- </ClCompile>
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="src\stdafx.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- </ItemGroup>
-</Project> \ No newline at end of file
diff --git a/tools/mdbx_dump/src/mdbx_dump.cc b/tools/mdbx_dump/src/mdbx_dump.cc
deleted file mode 100644
index 138650d8e7..0000000000
--- a/tools/mdbx_dump/src/mdbx_dump.cc
+++ /dev/null
@@ -1,393 +0,0 @@
-/* mdbx_dump.c - memory-mapped database dump tool */
-
-/*
- * Copyright 2015-2020 Leonid Yuriev <leo@yuriev.ru>
- * and other libmdbx authors: please see AUTHORS file.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted only as authorized by the OpenLDAP
- * Public License.
- *
- * A copy of this license is available in the file LICENSE in the
- * top-level directory of the distribution or, alternatively, at
- * <http://www.OpenLDAP.org/license.html>. */
-
-#include "stdafx.h"
-
-#ifdef _MSC_VER
-#if _MSC_VER > 1800
-#pragma warning(disable : 4464) /* relative include path contains '..' */
-#endif
-#pragma warning(disable : 4996) /* The POSIX name is deprecated... */
-#endif /* _MSC_VER (warnings) */
-
-#define MDBX_TOOLS /* Avoid using internal mdbx_assert() */
-#include "../../libs/libmdbx/src/src/internals.h"
-
-#include <ctype.h>
-
-#define PRINT 1
-static int mode;
-
-typedef struct flagbit {
- int bit;
- char *name;
-} flagbit;
-
-flagbit dbflags[] = {{MDBX_REVERSEKEY, "reversekey"},
- {MDBX_DUPSORT, "dupsort"},
- {MDBX_INTEGERKEY, "integerkey"},
- {MDBX_DUPFIXED, "dupfixed"},
- {MDBX_INTEGERDUP, "integerdup"},
- {MDBX_REVERSEDUP, "reversedup"},
- {0, NULL}};
-
-#if defined(_WIN32) || defined(_WIN64)
-#include "../../libs/libmdbx/src/src/wingetopt.h"
-#include "../../libs/libmdbx/src/src/wingetopt.c"
-
-static volatile BOOL user_break;
-static BOOL WINAPI ConsoleBreakHandlerRoutine(DWORD dwCtrlType) {
- (void)dwCtrlType;
- user_break = true;
- return true;
-}
-
-#else /* WINDOWS */
-
-static volatile sig_atomic_t user_break;
-static void signal_handler(int sig) {
- (void)sig;
- user_break = 1;
-}
-
-#endif /* !WINDOWS */
-
-static const char hexc[] = "0123456789abcdef";
-
-static void dumpbyte(unsigned char c) {
- putchar(hexc[c >> 4]);
- putchar(hexc[c & 0xf]);
-}
-
-static void text(MDBX_val *v) {
- unsigned char *c, *end;
-
- putchar(' ');
- c = (BYTE*)v->iov_base;
- end = c + v->iov_len;
- while (c < end) {
- if (isprint(*c) && *c != '\\') {
- putchar(*c);
- } else {
- putchar('\\');
- dumpbyte(*c);
- }
- c++;
- }
- putchar('\n');
-}
-
-static void dumpval(MDBX_val *v) {
- unsigned char *c, *end;
-
- putchar(' ');
- c = (BYTE*)v->iov_base;
- end = c + v->iov_len;
- while (c < end) {
- dumpbyte(*c++);
- }
- putchar('\n');
-}
-
-/* Dump in BDB-compatible format */
-static int dumpit(MDBX_txn *txn, MDBX_dbi dbi, char *name) {
- MDBX_cursor *mc;
- MDBX_stat ms;
- MDBX_val key, data;
- MDBX_envinfo info;
- unsigned int flags;
- int rc, i;
-
- rc = mdbx_dbi_flags(txn, dbi, &flags);
- if (rc)
- return rc;
-
- rc = mdbx_dbi_stat(txn, dbi, &ms, sizeof(ms));
- if (rc)
- return rc;
-
- rc = mdbx_env_info_ex(mdbx_txn_env(txn), txn, &info, sizeof(info));
- if (rc)
- return rc;
-
- printf("VERSION=3\n");
- printf("format=%s\n", mode & PRINT ? "print" : "bytevalue");
- if (name)
- printf("database=%s\n", name);
- printf("type=btree\n");
- printf("mapsize=%" PRIu64 "\n", info.mi_geo.upper);
- printf("maxreaders=%u\n", info.mi_maxreaders);
-
- for (i = 0; dbflags[i].bit; i++)
- if (flags & dbflags[i].bit)
- printf("%s=1\n", dbflags[i].name);
-
- printf("db_pagesize=%d\n", ms.ms_psize);
- printf("HEADER=END\n");
-
- rc = mdbx_cursor_open(txn, dbi, &mc);
- if (rc)
- return rc;
-
- while ((rc = mdbx_cursor_get(mc, &key, &data, MDBX_NEXT)) == MDBX_SUCCESS) {
- if (user_break) {
- rc = MDBX_EINTR;
- break;
- }
- if (mode & PRINT) {
- text(&key);
- text(&data);
- } else {
- dumpval(&key);
- dumpval(&data);
- }
- }
- printf("DATA=END\n");
- if (rc == MDBX_NOTFOUND)
- rc = MDBX_SUCCESS;
-
- return rc;
-}
-
-static void usage(char *prog) {
- fprintf(stderr,
- "usage: %s [-V] [-q] [-f file] [-l] [-p] [-a|-s subdb] [-r] [-n] "
- "dbpath\n"
- " -V\t\tprint version and exit\n"
- " -q\t\tbe quiet\n"
- " -f\t\twrite to file instead of stdout\n"
- " -l\t\tlist subDBs and exit\n"
- " -p\t\tuse printable characters\n"
- " -a\t\tdump main DB and all subDBs,\n"
- " \t\tby default dump only the main DB\n"
- " -s\t\tdump only the named subDB\n"
- " -r\t\trescure mode (ignore errors to dump corrupted DB)\n"
- " -n\t\tNOSUBDIR mode for open\n",
- prog);
- exit(EXIT_FAILURE);
-}
-
-int main(int argc, char *argv[]) {
- int i, rc;
- MDBX_env *env;
- MDBX_txn *txn;
- MDBX_dbi dbi;
- char *prog = argv[0];
- char *envname;
- char *subname = NULL;
- int alldbs = 0, envflags = 0, list = 0, quiet = 0, rescue = 0;
- DECLARE_VERSION();
-
- if (argc < 2)
- usage(prog);
-
- while ((i = getopt(argc, argv, "af:lnps:Vrq")) != EOF) {
- switch (i) {
- case 'V':
- printf("mdbx_dump version %d.%d.%d.%d\n"
- " - source: %s %s, commit %s, tree %s\n"
- " - anchor: %s\n"
- " - build: %s for %s by %s\n"
- " - flags: %s\n"
- " - options: %s\n",
- MDBX_version.major, MDBX_version.minor, MDBX_version.release,
- MDBX_version.revision, MDBX_version.git.describe,
- MDBX_version.git.datetime, MDBX_version.git.commit,
- MDBX_version.git.tree, MDBX_sourcery_anchor, MDBX_build.datetime,
- MDBX_build.target, MDBX_build.compiler, MDBX_build.flags,
- MDBX_build.options);
- return EXIT_SUCCESS;
- case 'l':
- list = 1;
- /*FALLTHROUGH*/;
- __fallthrough;
- case 'a':
- if (subname)
- usage(prog);
- alldbs++;
- break;
- case 'f':
- if (freopen(optarg, "w", stdout) == NULL) {
- fprintf(stderr, "%s: %s: reopen: %s\n", prog, optarg,
- mdbx_strerror(errno));
- exit(EXIT_FAILURE);
- }
- break;
- case 'n':
- envflags |= MDBX_NOSUBDIR;
- break;
- case 'p':
- mode |= PRINT;
- break;
- case 's':
- if (alldbs)
- usage(prog);
- subname = optarg;
- break;
- case 'q':
- quiet = 1;
- break;
- case 'r':
- rescue = 1;
- break;
- default:
- usage(prog);
- }
- }
-
- if (optind != argc - 1)
- usage(prog);
-
-#if defined(_WIN32) || defined(_WIN64)
- SetConsoleCtrlHandler(ConsoleBreakHandlerRoutine, true);
-#else
-#ifdef SIGPIPE
- signal(SIGPIPE, signal_handler);
-#endif
-#ifdef SIGHUP
- signal(SIGHUP, signal_handler);
-#endif
- signal(SIGINT, signal_handler);
- signal(SIGTERM, signal_handler);
-#endif /* !WINDOWS */
-
- envname = argv[optind];
- if (!quiet) {
- fprintf(stderr, "mdbx_dump %s (%s, T-%s)\nRunning for %s...\n",
- MDBX_version.git.describe, MDBX_version.git.datetime,
- MDBX_version.git.tree, envname);
- fflush(NULL);
- }
-
- rc = mdbx_env_create(&env);
- if (rc) {
- fprintf(stderr, "mdbx_env_create failed, error %d %s\n", rc,
- mdbx_strerror(rc));
- return EXIT_FAILURE;
- }
-
- if (alldbs || subname) {
- mdbx_env_set_maxdbs(env, 2);
- }
-
- rc = mdbx_env_open(
- env, envname,
- envflags | (rescue ? MDBX_RDONLY | MDBX_EXCLUSIVE : MDBX_RDONLY), 0);
- if (rc) {
- fprintf(stderr, "mdbx_env_open failed, error %d %s\n", rc,
- mdbx_strerror(rc));
- goto env_close;
- }
-
- rc = mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn);
- if (rc) {
- fprintf(stderr, "mdbx_txn_begin failed, error %d %s\n", rc,
- mdbx_strerror(rc));
- goto env_close;
- }
-
- rc = mdbx_dbi_open(txn, subname, 0, &dbi);
- if (rc) {
- fprintf(stderr, "mdbx_open failed, error %d %s\n", rc, mdbx_strerror(rc));
- goto txn_abort;
- }
-
- if (alldbs) {
- MDBX_cursor *cursor;
- MDBX_val key;
- int count = 0;
-
- rc = mdbx_cursor_open(txn, dbi, &cursor);
- if (rc) {
- fprintf(stderr, "mdbx_cursor_open failed, error %d %s\n", rc,
- mdbx_strerror(rc));
- goto txn_abort;
- }
- while ((rc = mdbx_cursor_get(cursor, &key, NULL, MDBX_NEXT_NODUP)) == 0) {
- if (user_break) {
- rc = MDBX_EINTR;
- break;
- }
- char *str;
- MDBX_dbi db2;
- if (memchr(key.iov_base, '\0', key.iov_len))
- continue;
- count++;
- str = (char*)mdbx_malloc(key.iov_len + 1);
- memcpy(str, key.iov_base, key.iov_len);
- str[key.iov_len] = '\0';
- rc = mdbx_dbi_open(txn, str, 0, &db2);
- if (rc == MDBX_SUCCESS) {
- if (list) {
- printf("%s\n", str);
- list++;
- } else {
- rc = dumpit(txn, db2, str);
- if (rc) {
- if (!rescue)
- break;
- fprintf(stderr, "%s: %s: ignore %s for `%s` and continue\n", prog,
- envname, mdbx_strerror(rc), str);
- /* Here is a hack for rescue mode, don't do that:
- * - we should restart transaction in case error due
- * database corruption;
- * - but we won't close cursor, reopen and re-positioning it
- * for new a transaction;
- * - this is possible since DB is opened in read-only exclusive
- * mode and transaction is the same, i.e. has the same address
- * and so on. */
- rc = mdbx_txn_reset(txn);
- if (rc) {
- fprintf(stderr, "mdbx_txn_reset failed, error %d %s\n", rc,
- mdbx_strerror(rc));
- goto env_close;
- }
- rc = mdbx_txn_renew(txn);
- if (rc) {
- fprintf(stderr, "mdbx_txn_renew failed, error %d %s\n", rc,
- mdbx_strerror(rc));
- goto env_close;
- }
- }
- }
- mdbx_dbi_close(env, db2);
- }
- mdbx_free(str);
- if (rc)
- continue;
- }
- mdbx_cursor_close(cursor);
- if (!count) {
- fprintf(stderr, "%s: %s does not contain multiple databases\n", prog,
- envname);
- rc = MDBX_NOTFOUND;
- } else if (rc == MDBX_INCOMPATIBLE) {
- /* LY: the record it not a named sub-db. */
- rc = MDBX_SUCCESS;
- }
- } else {
- rc = dumpit(txn, dbi, subname);
- }
- if (rc && rc != MDBX_NOTFOUND)
- fprintf(stderr, "%s: %s: %s\n", prog, envname, mdbx_strerror(rc));
-
- mdbx_dbi_close(env, dbi);
-txn_abort:
- mdbx_txn_abort(txn);
-env_close:
- mdbx_env_close(env);
-
- return rc ? EXIT_FAILURE : EXIT_SUCCESS;
-}
diff --git a/tools/mdbx_dump/src/stdafx.cxx b/tools/mdbx_dump/src/stdafx.cxx
deleted file mode 100644
index 77a6bea7ef..0000000000
--- a/tools/mdbx_dump/src/stdafx.cxx
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
-Copyright (C) 2018-20 Miranda NG team (https://miranda-ng.org)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "stdafx.h"
-
-#include "..\..\build\appstub\appstub.cpp"
diff --git a/tools/mdbx_dump/src/stdafx.h b/tools/mdbx_dump/src/stdafx.h
deleted file mode 100644
index f22afc24b5..0000000000
--- a/tools/mdbx_dump/src/stdafx.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
-Copyright (C) 2018-20 Miranda NG team (https://miranda-ng.org)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation version 2
-of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#pragma once
-
-#include <stdio.h>
-#include <windows.h>
-
-#define DECLARE_VERSION() \
- mdbx_version_info MDBX_version; \
- mdbx_build_info MDBX_build; \
- char* MDBX_sourcery_anchor; \
- HINSTANCE hDll = LoadLibraryA("libmdbx.mir"); \
- MDBX_version = *(mdbx_version_info *)GetProcAddress(hDll, "mdbx_version"); \
- MDBX_build = *(mdbx_build_info*)GetProcAddress(hDll, "mdbx_build"); \
- MDBX_sourcery_anchor = (char*)GetProcAddress(hDll, "mdbx_sourcery_MDBX_BUILD_SOURCERY");