Fix compile on Linux

This commit is contained in:
Martin Raiber 2021-07-05 19:49:25 +02:00
parent b7f9d0d4a7
commit 45b2dff7ab
39 changed files with 492 additions and 1131 deletions

View File

@ -5,7 +5,7 @@ bin_PROGRAMS = urbackupclientctl urbackupclientgui blockalign
else
bin_PROGRAMS = urbackupclientctl blockalign
endif
urbackupclientbackend_SOURCES = AcceptThread.cpp Client.cpp Database.cpp Query.cpp SelectThread.cpp Server.cpp ServerLinux.cpp ServiceAcceptor.cpp ServiceWorker.cpp SessionMgr.cpp StreamPipe.cpp Template.cpp WorkerThread.cpp main.cpp md5.cpp stringtools.cpp libfastcgi/fastcgi.cpp Mutex_lin.cpp LoadbalancerClient.cpp DBSettingsReader.cpp file_common.cpp file_fstream.cpp file_linux.cpp FileSettingsReader.cpp LookupService.cpp SettingsReader.cpp Table.cpp OutputStream.cpp ThreadPool.cpp MemoryPipe.cpp Condition_lin.cpp MemorySettingsReader.cpp sqlite/shell.c SQLiteFactory.cpp PipeThrottler.cpp mt19937ar.cpp DatabaseCursor.cpp SharedMutex_lin.cpp StaticPluginRegistration.cpp common/data.cpp common/adler32.cpp OpenSSLPipe.cpp
urbackupclientbackend_SOURCES = AcceptThread.cpp Client.cpp Database.cpp Query.cpp SelectThread.cpp Server.cpp ServerLinux.cpp ServiceAcceptor.cpp ServiceWorker.cpp SessionMgr.cpp StreamPipe.cpp Template.cpp WorkerThread.cpp main.cpp md5.cpp stringtools.cpp libfastcgi/fastcgi.cpp Mutex_lin.cpp LoadbalancerClient.cpp DBSettingsReader.cpp file_common.cpp file_fstream.cpp file_linux.cpp file_memory.cpp FileSettingsReader.cpp LookupService.cpp SettingsReader.cpp Table.cpp OutputStream.cpp ThreadPool.cpp MemoryPipe.cpp Condition_lin.cpp MemorySettingsReader.cpp sqlite/shell.c SQLiteFactory.cpp PipeThrottler.cpp mt19937ar.cpp DatabaseCursor.cpp SharedMutex_lin.cpp StaticPluginRegistration.cpp common/data.cpp common/adler32.cpp OpenSSLPipe.cpp
if WITH_EMBEDDED_SQLITE3
urbackupclientbackend_SOURCES += sqlite/sqlite3.c
@ -19,9 +19,9 @@ endif
urbackupclientbackend_SOURCES += cryptoplugin/dllmain.cpp cryptoplugin/AESDecryption.cpp cryptoplugin/CryptoFactory.cpp cryptoplugin/pluginmgr.cpp cryptoplugin/AESEncryption.cpp cryptoplugin/ZlibCompression.cpp cryptoplugin/ZlibDecompression.cpp cryptoplugin/AESGCMDecryption.cpp cryptoplugin/AESGCMEncryption.cpp cryptoplugin/ECDHKeyExchange.cpp
urbackupclientbackend_SOURCES += fsimageplugin/dllmain.cpp fsimageplugin/filesystem.cpp fsimageplugin/FSImageFactory.cpp fsimageplugin/pluginmgr.cpp fsimageplugin/vhdfile.cpp fsimageplugin/fs/ntfs.cpp fsimageplugin/fs/unknown.cpp fsimageplugin/CompressedFile.cpp fsimageplugin/LRUMemCache.cpp fsimageplugin/cowfile.cpp fsimageplugin/FileWrapper.cpp fsimageplugin/ClientBitmap.cpp fsimageplugin/partclone.cpp
urbackupclientbackend_SOURCES += fsimageplugin/dllmain.cpp fsimageplugin/filesystem.cpp fsimageplugin/FSImageFactory.cpp fsimageplugin/pluginmgr.cpp fsimageplugin/vhdfile.cpp fsimageplugin/vhdxfile.cpp fsimageplugin/fs/ntfs.cpp fsimageplugin/fs/unknown.cpp fsimageplugin/CompressedFile.cpp fsimageplugin/LRUMemCache.cpp fsimageplugin/cowfile.cpp fsimageplugin/FileWrapper.cpp fsimageplugin/ClientBitmap.cpp fsimageplugin/partclone.cpp
urbackupclientbackend_SOURCES += urbackupclient/dllmain.cpp urbackupclient/clientdao.cpp urbackupclient/client.cpp urbackupclient/ClientService.cpp urbackupclient/ClientSend.cpp urbackupclient/client_restore.cpp urbackupclient/ServerIdentityMgr.cpp urbackupclient/ClientServiceCMD.cpp urbackupclient/ImageThread.cpp urbackupclient/InternetClient.cpp urbackupclient/file_permissions.cpp urbackupclient/lin_ver.cpp urbackupclient/lin_tokens.cpp urbackupclient/common_tokens.cpp urbackupclient/FileMetadataDownloadThread.cpp urbackupclient/RestoreFiles.cpp urbackupclient/RestoreDownloadThread.cpp urbackupclient/TokenCallback.cpp common/miniz.c urbackupclient/cmdline_preprocessor.cpp urbackupclient/ParallelHash.cpp urbackupclient/ClientHash.cpp
urbackupclientbackend_SOURCES += urbackupclient/dllmain.cpp urbackupclient/clientdao.cpp urbackupclient/client.cpp urbackupclient/ClientService.cpp urbackupclient/ClientSend.cpp urbackupclient/client_restore.cpp urbackupclient/ServerIdentityMgr.cpp urbackupclient/ClientServiceCMD.cpp urbackupclient/ImageThread.cpp urbackupclient/InternetClient.cpp urbackupclient/file_permissions.cpp urbackupclient/lin_ver.cpp urbackupclient/lin_tokens.cpp urbackupclient/common_tokens.cpp urbackupclient/FileMetadataDownloadThread.cpp urbackupclient/RestoreFiles.cpp urbackupclient/RestoreDownloadThread.cpp urbackupclient/TokenCallback.cpp common/miniz.c urbackupclient/cmdline_preprocessor.cpp urbackupclient/ParallelHash.cpp urbackupclient/ClientHash.cpp urbackupclient/RansomwareCanary.cpp urbackupclient/LocalBackup.cpp urbackupclient/LocalFileBackup.cpp urbackupclient/LocalFullFileBackup.cpp urbackupclient/LocalIncrFileBackup.cpp urbackupclient/FilesystemManager.cpp urbackupserver/treediff/TreeDiff.cpp urbackupserver/treediff/TreeNode.cpp urbackupserver/treediff/TreeReader.cpp urbackupcommon/backup_url_parser.cpp
urbackupclientbackend_SOURCES += fileservplugin/dllmain.cpp fileservplugin/bufmgr.cpp fileservplugin/CClientThread.cpp fileservplugin/CriticalSection.cpp fileservplugin/CTCPFileServ.cpp fileservplugin/CUDPThread.cpp fileservplugin/FileServ.cpp fileservplugin/FileServFactory.cpp fileservplugin/log.cpp fileservplugin/main.cpp fileservplugin/map_buffer.cpp fileservplugin/pluginmgr.cpp fileservplugin/ChunkSendThread.cpp fileservplugin/PipeFile.cpp fileservplugin/PipeSessions.cpp fileservplugin/PipeFileUnix.cpp fileservplugin/PipeFileBase.cpp fileservplugin/FileMetadataPipe.cpp fileservplugin/PipeFileTar.cpp fileservplugin/PipeFileExt.cpp
@ -34,72 +34,75 @@ urbackupclientbackend_SOURCES += btrfs/fuse/fuse.cpp \
btrfs/fuse/nt/device.cpp \
btrfs/fuse/nt/windef.cpp \
btrfs/fuse/nt/resource.cpp \
btrfs/fuse/nt/workqueue.cpp
btrfs/fuse/nt/workqueue.cpp \
btrfs/fuse/get_chunks.c \
btrfs/fuse/oslib/os_lin.cpp \
btrfs/fuse/oslib/utf8.cpp
urbackupclientbackend_SOURCES += external/btrfs/balance.c \
external/btrfs/blake2b-ref.c \
external/btrfs/boot.c \
external/btrfs/btrfs.c \
external/btrfs/cache.c \
external/btrfs/calcthread.c \
external/btrfs/compress.c \
external/btrfs/crc32c.c \
external/btrfs/create.c \
external/btrfs/devctrl.c \
external/btrfs/dirctrl.c \
external/btrfs/extent-tree.c \
external/btrfs/fastio.c \
external/btrfs/fileinfo.c \
external/btrfs/flushthread.c \
external/btrfs/free-space.c \
external/btrfs/fsctl.c \
external/btrfs/fsrtl.c \
external/btrfs/galois.c \
external/btrfs/mkbtrfs/mkbtrfs.c \
external/btrfs/pnp.c \
external/btrfs/read.c \
external/btrfs/registry.c \
external/btrfs/reparse.c \
external/btrfs/scrub.c \
external/btrfs/search.c \
external/btrfs/security.c \
external/btrfs/send.c \
external/btrfs/sha256.c \
external/btrfs/treefuncs.c \
external/btrfs/ubtrfs/ubtrfs.c \
external/btrfs/volume.c \
external/btrfs/worker-thread.c \
external/btrfs/write.c \
external/btrfs/xxhash.c
urbackupclientbackend_SOURCES += external/btrfs/src/balance.c \
external/btrfs/src/blake2b-ref.c \
external/btrfs/src/boot.c \
external/btrfs/src/btrfs.c \
external/btrfs/src/cache.c \
external/btrfs/src/calcthread.c \
external/btrfs/src/compress.c \
external/btrfs/src/crc32c.c \
external/btrfs/src/create.c \
external/btrfs/src/devctrl.c \
external/btrfs/src/dirctrl.c \
external/btrfs/src/extent-tree.c \
external/btrfs/src/fastio.c \
external/btrfs/src/fileinfo.c \
external/btrfs/src/flushthread.c \
external/btrfs/src/free-space.c \
external/btrfs/src/fsctl.c \
external/btrfs/src/fsrtl.c \
external/btrfs/src/galois.c \
external/btrfs/src/mkbtrfs/mkbtrfs.c \
external/btrfs/src/pnp.c \
external/btrfs/src/read.c \
external/btrfs/src/registry.c \
external/btrfs/src/reparse.c \
external/btrfs/src/scrub.c \
external/btrfs/src/search.c \
external/btrfs/src/security.c \
external/btrfs/src/send.c \
external/btrfs/src/sha256.c \
external/btrfs/src/treefuncs.c \
external/btrfs/src/ubtrfs/ubtrfs.c \
external/btrfs/src/volume.c \
external/btrfs/src/worker-thread.c \
external/btrfs/src/write.c \
external/btrfs/src/xxhash.c
if WITH_BTRFS_ZLIB
urbackupclientbackend_SOURCES += \
external/btrfs/zlib/adler32.c \
external/btrfs/zlib/deflate.c \
external/btrfs/zlib/inffast.c \
external/btrfs/zlib/inflate.c \
external/btrfs/zlib/inftrees.c \
external/btrfs/zlib/trees.c \
external/btrfs/zlib/zutil.c
external/btrfs/src/zlib/adler32.c \
external/btrfs/src/zlib/deflate.c \
external/btrfs/src/zlib/inffast.c \
external/btrfs/src/zlib/inflate.c \
external/btrfs/src/zlib/inftrees.c \
external/btrfs/src/zlib/trees.c \
external/btrfs/src/zlib/zutil.c
endif
if !WITH_ZSTD
urbackupclientbackend_SOURCES += \
external/btrfs/zstd/entropy_common.c \
external/btrfs/zstd/error_private.c \
external/btrfs/zstd/fse_compress.c \
external/btrfs/zstd/fse_decompress.c \
external/btrfs/zstd/hist.c \
external/btrfs/zstd/huf_compress.c \
external/btrfs/zstd/huf_decompress.c \
external/btrfs/zstd/zstd_common.c \
external/btrfs/zstd/zstd_compress.c \
external/btrfs/zstd/zstd_decompress.c \
external/btrfs/zstd/zstd_double_fast.c \
external/btrfs/zstd/zstd_fast.c \
external/btrfs/zstd/zstd_lazy.c \
external/btrfs/zstd/zstd_ldm.c \
external/btrfs/zstd/zstd_opt.c
external/btrfs/src/zstd/entropy_common.c \
external/btrfs/src/zstd/error_private.c \
external/btrfs/src/zstd/fse_compress.c \
external/btrfs/src/zstd/fse_decompress.c \
external/btrfs/src/zstd/hist.c \
external/btrfs/src/zstd/huf_compress.c \
external/btrfs/src/zstd/huf_decompress.c \
external/btrfs/src/zstd/zstd_common.c \
external/btrfs/src/zstd/zstd_compress.c \
external/btrfs/src/zstd/zstd_decompress.c \
external/btrfs/src/zstd/zstd_double_fast.c \
external/btrfs/src/zstd/zstd_fast.c \
external/btrfs/src/zstd/zstd_lazy.c \
external/btrfs/src/zstd/zstd_ldm.c \
external/btrfs/src/zstd/zstd_opt.c
endif
@ -108,9 +111,12 @@ FORTIFY_FLAGS = -fstack-protector-strong --param=ssp-buffer-size=4 -Wformat -Wer
FORTIFY_ldflags = -Wl,-z,relro
endif
urbackupclientbackend_LDADD = $(PTHREAD_LIBS) $(DLOPEN_LIBS)
urbackupclientbackend_CPPFLAGS = $(CRYPTOPP_CPPFLAGS) $(FORTIFY_FLAGS) $(SUID_CFLAGS)
urbackupclientbackend_LDADD = $(PTHREAD_LIBS) $(DLOPEN_LIBS) $(AWS_SDK_LIBS)
urbackupclientbackend_CPPFLAGS = $(CRYPTOPP_CPPFLAGS) $(FORTIFY_FLAGS) $(SUID_CFLAGS) $(AWS_SDK_INCLUDES) -Ibtrfs/fuse/nt
urbackupclientbackend_CXXFLAGS = $(PTHREAD_CFLAGS) -DLINUX -DSTATIC_PLUGIN -DVARDIR='"$(localstatedir)"' -DSYSCONFDIR='"$(sysconfdir)"' -DDATADIR='"$(datadir)"'
if DISABLE_CERTAIN_WARNINGS
urbackupclientbackend_CXXFLAGS += -Wno-subobject-linkage
endif
if WITH_EMBEDDED_SQLITE3
urbackupclientbackend_CFLAGS = -DSQLITE_ENABLE_UNLOCK_NOTIFY $(SUID_CFLAGS)
else
@ -128,6 +134,8 @@ if !WITH_ASSERTIONS
urbackupclientbackend_CPPFLAGS+=-DNDEBUG
endif
urbackupclientbackend_CFLAGS += -std=c11 -D__stdcall='' -D_stdcall=''
if WITH_ZSTD
if !EMBEDDED_ZSTD
urbackupclientbackend_LDADD += -lzstd
@ -349,7 +357,7 @@ cryptoplugin_headers = cryptoplugin/AESEncryption.h cryptoplugin/AESDecryption.h
fileservplugin_headers = fileservplugin/bufmgr.h fileservplugin/CUDPThread.h fileservplugin/FileServFactory.h fileservplugin/IFileServ.h fileservplugin/packet_ids.h fileservplugin/socket_header.h fileservplugin/CriticalSection.h fileservplugin/FileServ.h fileservplugin/log.h fileservplugin/pluginmgr.h fileservplugin/CClientThread.h fileservplugin/CTCPFileServ.h fileservplugin/IFileServFactory.h fileservplugin/map_buffer.h fileservplugin/settings.h fileservplugin/types.h fileservplugin/chunk_settings.h fileservplugin/ChunkSendThread.h fileservplugin/PipeFile.h fileservplugin/PipeSessions.h fileservplugin/PipeFileBase.h fileservplugin/IPermissionCallback.h fileservplugin/FileMetadataPipe.h fileservplugin/PipeFileTar.h fileservplugin/PipeFileExt.h fileservplugin/IPipeFileExt.h
fsimageplugin_headers = fsimageplugin/filesystem.h fsimageplugin/FSImageFactory.h fsimageplugin/IFilesystem.h fsimageplugin/IFSImageFactory.h fsimageplugin/IVHDFile.h fsimageplugin/pluginmgr.h fsimageplugin/vhdfile.h fsimageplugin/fs/ntfs.h fsimageplugin/fs/unknown.h fsimageplugin/CompressedFile.h fsimageplugin/LRUMemCache.h fsimageplugin/cowfile.h fsimageplugin/FileWrapper.h fsimageplugin/ClientBitmap.h common/miniz.h fsimageplugin/partclone.h
fsimageplugin_headers = fsimageplugin/filesystem.h fsimageplugin/FSImageFactory.h fsimageplugin/IFilesystem.h fsimageplugin/IFSImageFactory.h fsimageplugin/IVHDFile.h fsimageplugin/pluginmgr.h fsimageplugin/vhdfile.h fsimageplugin/vhdxfile.h fsimageplugin/fs/ntfs.h fsimageplugin/fs/unknown.h fsimageplugin/CompressedFile.h fsimageplugin/LRUMemCache.h fsimageplugin/cowfile.h fsimageplugin/FileWrapper.h fsimageplugin/ClientBitmap.h common/miniz.h fsimageplugin/partclone.h
urbackupclientctl_headers = clientctl/Connector.h clientctl/tcpstack.h clientctl/json/json.h clientctl/json/json-forwards.h
@ -359,7 +367,7 @@ else
client_headers =
endif
urbackupclient_headers = urbackupclient/DirectoryWatcherThread.h urbackupcommon/os_functions.h urbackupclient/ChangeJournalWatcher.h urbackupcommon/sha2/sha2.h urbackupclient/database.h urbackupcommon/escape.h urbackupclient/ClientSend.h urbackupclient/clientdao.h urbackupclient/client.h urbackupclient/ClientService.h fileservplugin/IFileServFactory.h fileservplugin/IFileServ.h common/data.h urbackupcommon/fileclient/tcpstack.h urbackupcommon/capa_bits.h urbackupclient/ServerIdentityMgr.h urbackupcommon/bufmgr.h urbackupcommon/CompressedPipe.h urbackupclient/ImageThread.h urbackupclient/InternetClient.h urbackupcommon/InternetServicePipe2.h urbackupcommon/settingslist.h cryptoplugin/IZlibCompression.h cryptoplugin/IZlibDecompression.h cryptoplugin/ICryptoFactory.h cryptoplugin/IAESDecryption.h cryptoplugin/IAESEncryption.h urbackupcommon/internet_pipe_capabilities.h urbackupcommon/settings.h urbackupcommon/fileclient/socket_header.h urbackupcommon/mbrdata.h urbackupcommon/InternetServiceIDs.h urbackupcommon/json.h urbackupclient/file_permissions.h urbackupclient/lin_ver.h urbackupcommon/glob.h urbackupclient/tokens.h urbackupclient/FileMetadataDownloadThread.h urbackupclient/RestoreFiles.h urbackupcommon/chunk_hasher.h common/adler32.h urbackupcommon/fileclient/FileClient.h urbackupcommon/fileclient/FileClientChunked.h urbackupcommon/file_metadata.h urbackupcommon/filelist_utils.h urbackupclient/RestoreDownloadThread.h urbackupclient/TokenCallback.h urbackupcommon/CompressedPipe2.h urbackupcommon/server_compat.h urbackupcommon/fileclient/packet_ids.h urbackupcommon/InternetServicePipe.h urbackupclient/backup_client_db.h urbackupcommon/SparseFile.h urbackupcommon/ExtentIterator.h urbackupcommon/TreeHash.h urbackupcommon/WalCheckpointThread.h common/miniz.h urbackupclient/ParallelHash.h urbackupclient/ClientHash.h urbackupcommon/CompressedPipeZstd.h urbackupclient/lin_sysvol.h urbackupcommon/WebSocketPipe.h
urbackupclient_headers = urbackupclient/DirectoryWatcherThread.h urbackupcommon/os_functions.h urbackupclient/ChangeJournalWatcher.h urbackupcommon/sha2/sha2.h urbackupclient/database.h urbackupcommon/escape.h urbackupclient/ClientSend.h urbackupclient/clientdao.h urbackupclient/client.h urbackupclient/ClientService.h fileservplugin/IFileServFactory.h fileservplugin/IFileServ.h common/data.h urbackupcommon/fileclient/tcpstack.h urbackupcommon/capa_bits.h urbackupclient/ServerIdentityMgr.h urbackupcommon/bufmgr.h urbackupcommon/CompressedPipe.h urbackupclient/ImageThread.h urbackupclient/InternetClient.h urbackupcommon/InternetServicePipe2.h urbackupcommon/settingslist.h cryptoplugin/IZlibCompression.h cryptoplugin/IZlibDecompression.h cryptoplugin/ICryptoFactory.h cryptoplugin/IAESDecryption.h cryptoplugin/IAESEncryption.h urbackupcommon/internet_pipe_capabilities.h urbackupcommon/settings.h urbackupcommon/fileclient/socket_header.h urbackupcommon/mbrdata.h urbackupcommon/InternetServiceIDs.h urbackupcommon/json.h urbackupclient/file_permissions.h urbackupclient/lin_ver.h urbackupcommon/glob.h urbackupclient/tokens.h urbackupclient/FileMetadataDownloadThread.h urbackupclient/RestoreFiles.h urbackupcommon/chunk_hasher.h common/adler32.h urbackupcommon/fileclient/FileClient.h urbackupcommon/fileclient/FileClientChunked.h urbackupcommon/file_metadata.h urbackupcommon/filelist_utils.h urbackupclient/RestoreDownloadThread.h urbackupclient/TokenCallback.h urbackupcommon/CompressedPipe2.h urbackupcommon/server_compat.h urbackupcommon/fileclient/packet_ids.h urbackupcommon/InternetServicePipe.h urbackupclient/backup_client_db.h urbackupcommon/SparseFile.h urbackupcommon/ExtentIterator.h urbackupcommon/TreeHash.h urbackupcommon/WalCheckpointThread.h common/miniz.h urbackupclient/ParallelHash.h urbackupclient/ClientHash.h urbackupcommon/CompressedPipeZstd.h urbackupclient/lin_sysvol.h urbackupcommon/WebSocketPipe.h urbackupclient/RansomwareCanary.h urbackupclient/LocalBackup.h urbackupclient/LocalFileBackup.h urbackupclient/LocalFullFileBackup.h urbackupclient/LocalIncrFileBackup.h urbackupclient/FilesystemManager.h urbackupserver/treediff/TreeDiff.h urbackupserver/treediff/TreeNode.h urbackupserver/treediff/TreeReader.h urbackupcommon/backup_url_parser.h
tclap_headers = \
@ -426,14 +434,13 @@ btrfsplugin_headers = \
btrfs/btrfsplugin/BackupFileSystem.h \
btrfs/btrfsplugin/BtrfsFactory.h \
btrfs/btrfsplugin/pluginmgr.h \
btrfs/btrfsplugin/IBtrfsFactory.h \
btrfs/btrfsplugin/IBtrfsFactory.h
btrfsfuse_headers = \
btrfs/fuse/fuse.h \
btrfs/fuse/nt/device.h \
btrfs/fuse/nt/ata.h \
btrfs/fuse/nt/guiddef.h \
btrfs/fuse/nt/ndddisk.h \
btrfs/fuse/nt/ntddstor.h \
btrfs/fuse/nt/ntifs.h \
btrfs/fuse/nt/winnt.h \
@ -450,58 +457,63 @@ btrfsfuse_headers = \
btrfs/fuse/nt/ntstrsafe.h \
btrfs/fuse/nt/wdm.h \
btrfs/fuse/nt/Windows.h \
btrfs/fuse/nt/workqueue.h
btrfs/fuse/nt/workqueue.h \
btrfs/fuse/nt/intrin.h \
btrfs/fuse/nt/initguid.h \
btrfs/fuse/nt/sal.h \
btrfs/fuse/nt/diskguid.h \
btrfs/fuse/nt/wdmguid.h
btrfs_headers = \
external/btrfs/blake2-impl.h \
external/btrfs/btrfs.h \
external/btrfs/btrfsioctl.h \
external/btrfs/btrfs_drv.h \
external/btrfs/crc32c.h \
external/btrfs/mkbtrfs/resource.h \
external/btrfs/resource.h \
external/btrfs/shellext/balance.h \
external/btrfs/shellext/contextmenu.h \
external/btrfs/shellext/devices.h \
external/btrfs/shellext/factory.h \
external/btrfs/shellext/iconoverlay.h \
external/btrfs/shellext/mountmgr.h \
external/btrfs/shellext/propsheet.h \
external/btrfs/shellext/recv.h \
external/btrfs/shellext/resource.h \
external/btrfs/shellext/scrub.h \
external/btrfs/shellext/send.h \
external/btrfs/shellext/shellext.h \
external/btrfs/shellext/volpropsheet.h \
external/btrfs/ubtrfs/resource.h \
external/btrfs/xxhash.h \
external/btrfs/zlib/deflate.h \
external/btrfs/zlib/inffast.h \
external/btrfs/zlib/inffixed.h \
external/btrfs/zlib/inflate.h \
external/btrfs/zlib/inftrees.h \
external/btrfs/zlib/trees.h \
external/btrfs/zlib/zconf.h \
external/btrfs/zlib/zlib.h \
external/btrfs/zlib/zutil.h \
external/btrfs/zstd/bitstream.h \
external/btrfs/zstd/compiler.h \
external/btrfs/zstd/cpu.h \
external/btrfs/zstd/debug.h \
external/btrfs/zstd/error_private.h \
external/btrfs/zstd/fse.h \
external/btrfs/zstd/hist.h \
external/btrfs/zstd/huf.h \
external/btrfs/zstd/mem.h \
external/btrfs/zstd/zstd.h \
external/btrfs/zstd/zstd_compress_internal.h \
external/btrfs/zstd/zstd_double_fast.h \
external/btrfs/zstd/zstd_errors.h \
external/btrfs/zstd/zstd_fast.h \
external/btrfs/zstd/zstd_internal.h \
external/btrfs/zstd/zstd_lazy.h \
external/btrfs/zstd/zstd_ldm.h \
external/btrfs/zstd/zstd_opt.h
external/btrfs/src/blake2-impl.h \
external/btrfs/src/btrfs.h \
external/btrfs/src/btrfsioctl.h \
external/btrfs/src/btrfs_drv.h \
external/btrfs/src/crc32c.h \
external/btrfs/src/mkbtrfs/resource.h \
external/btrfs/src/resource.h \
external/btrfs/src/shellext/balance.h \
external/btrfs/src/shellext/contextmenu.h \
external/btrfs/src/shellext/devices.h \
external/btrfs/src/shellext/factory.h \
external/btrfs/src/shellext/iconoverlay.h \
external/btrfs/src/shellext/mountmgr.h \
external/btrfs/src/shellext/propsheet.h \
external/btrfs/src/shellext/recv.h \
external/btrfs/src/shellext/resource.h \
external/btrfs/src/shellext/scrub.h \
external/btrfs/src/shellext/send.h \
external/btrfs/src/shellext/shellext.h \
external/btrfs/src/shellext/volpropsheet.h \
external/btrfs/src/ubtrfs/resource.h \
external/btrfs/src/xxhash.h \
external/btrfs/src/zlib/deflate.h \
external/btrfs/src/zlib/inffast.h \
external/btrfs/src/zlib/inffixed.h \
external/btrfs/src/zlib/inflate.h \
external/btrfs/src/zlib/inftrees.h \
external/btrfs/src/zlib/trees.h \
external/btrfs/src/zlib/zconf.h \
external/btrfs/src/zlib/zlib.h \
external/btrfs/src/zlib/zutil.h \
external/btrfs/src/zstd/bitstream.h \
external/btrfs/src/zstd/compiler.h \
external/btrfs/src/zstd/cpu.h \
external/btrfs/src/zstd/debug.h \
external/btrfs/src/zstd/error_private.h \
external/btrfs/src/zstd/fse.h \
external/btrfs/src/zstd/hist.h \
external/btrfs/src/zstd/huf.h \
external/btrfs/src/zstd/mem.h \
external/btrfs/src/zstd/zstd.h \
external/btrfs/src/zstd/zstd_compress_internal.h \
external/btrfs/src/zstd/zstd_double_fast.h \
external/btrfs/src/zstd/zstd_errors.h \
external/btrfs/src/zstd/zstd_fast.h \
external/btrfs/src/zstd/zstd_internal.h \
external/btrfs/src/zstd/zstd_lazy.h \
external/btrfs/src/zstd/zstd_ldm.h \
external/btrfs/src/zstd/zstd_opt.h
noinst_HEADERS=SessionMgr.h WorkerThread.h Helper_win32.h Database.h defaults.h ServiceAcceptor.h Query.h SettingsReader.h \
file.h file_memory.h MemorySettingsReader.h Condition_lin.h LookupService.h Template.h types.h DBSettingsReader.h \

View File

@ -61,7 +61,7 @@ public:
private:
std::auto_ptr<CStreamPipe> bpipe;
std::unique_ptr<CStreamPipe> bpipe;
BIO* bbio;
SSL_CTX* ctx;

View File

@ -30,7 +30,7 @@ private:
pthread_rwlock_t lock;
#ifdef SHARED_MUTEX_CHECK
std::auto_ptr<IMutex> check_mutex;
std::unique_ptr<IMutex> check_mutex;
std::set<pthread_t> check_threads;
#endif
};

View File

@ -37,7 +37,7 @@
#ifndef STATIC_PLUGIN
IServer* Server;
#else
#include "../StaticPluginRegistration.h"
#include "../../StaticPluginRegistration.h"
extern IServer* Server;

View File

@ -19,7 +19,8 @@
#include <iostream>
#include <vector>
#include <assert.h>
#include "os.h"
#include <atomic>
#include "oslib/os.h"
#include "../../utf8/utf8.h"
#include "../../stringtools.h"
@ -29,7 +30,7 @@ extern "C"
{
#include <ntifs.h>
#include <device.h>
#include "src/btrfsioctl.h"
#include "../../external/btrfs/src/btrfsioctl.h"
#include "get_chunks.h"
NTSTATUS __stdcall DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath);

View File

@ -1,6 +1,6 @@
#include <stdlib.h>
#include "get_chunks.h"
#include "src/btrfs_drv.h"
#include "../../external/btrfs/src/btrfs_drv.h"
#include <memory.h>
SBtrfsChunk* get_btrfs_chunks(device_extension* Vcb, size_t* n_chunks)

View File

@ -2,7 +2,7 @@ extern "C"
{
#include "device.h"
}
#include "../../Interface/File.h"
#include "../../../Interface/File.h"
#include <string>
namespace

0
btrfs/fuse/nt/diskguid.h Normal file
View File

View File

@ -15,4 +15,8 @@ typedef GUID* PGUID;
DEFINE_GUID(GUID_DEVINTERFACE_VOLUME, 0x3eee337e, 0xd03b, 0x4980, 0xa8, 0xed, 0x8c, 0x40, 0x6d, 0x68, 0xf3, 0xf0);
DEFINE_GUID(GUID_DEVINTERFACE_HIDDEN_VOLUME, 0x3eee337e, 0xd03b, 0x4980, 0xa8, 0xed, 0x8c, 0x40, 0x6d, 0x68, 0xf3, 0xf1);
DEFINE_GUID(GUID_DEVINTERFACE_DISK, 0x3eee337e, 0xd03b, 0x4980, 0xa8, 0xed, 0x8c, 0x40, 0x6d, 0x68, 0xf3, 0xf2);
DEFINE_GUID(GUID_DEVICE_INTERFACE_ARRIVAL, 0x3eee337e, 0xd03b, 0x4981, 0xa8, 0xed, 0x8c, 0x40, 0x6d, 0x68, 0xf3, 0xf2);
DEFINE_GUID(GUID_DEVICE_INTERFACE_REMOVAL, 0x3eee337e, 0xd03b, 0x4982, 0xa8, 0xed, 0x8c, 0x40, 0x6d, 0x68, 0xf3, 0xf2);
DEFINE_GUID(GUID_TARGET_DEVICE_QUERY_REMOVE, 0x3eee337e, 0xd03b, 0x4983, 0xa8, 0xed, 0x8c, 0x40, 0x6d, 0x68, 0xf3, 0xf2);

0
btrfs/fuse/nt/initguid.h Normal file
View File

1
btrfs/fuse/nt/intrin.h Normal file
View File

@ -0,0 +1 @@
#include <cpuid.h>

View File

@ -2,6 +2,7 @@
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <thread>
#include <set>
struct ERESOURCE_INT {

View File

@ -1,10 +1,11 @@
#pragma once
#include "windef.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "windef.h"
struct ERESOURCE_INT;
typedef struct _ERESOURCE {

1
btrfs/fuse/nt/sal.h Normal file
View File

@ -0,0 +1 @@
#include "windef.h"

0
btrfs/fuse/nt/wdmguid.h Normal file
View File

View File

@ -5,14 +5,13 @@ extern "C"
#include "device.h"
}
#include "../fuse.h"
#include "event.h"
#include <memory>
#include <iostream>
#include <thread>
#include <stdarg.h>
#include <assert.h>
#include <os.h>
#include "../oslib/os.h"
#include <map>
#include <vector>
#include <mutex>
@ -20,9 +19,16 @@ extern "C"
#include <set>
#include <array>
#include <thread>
#include <condition_variable>
#include "file.h"
#include "utf8.h"
#include "../../utf8/utf8.h"
#include "../oslib/utf8.h"
#include "../../../utf8/utf8.h"
#ifndef _WIN32
#define vsprintf_s vsnprintf
#define vprintf_s vprintf
#define vswprintf_s vswprintf
#endif
POBJECT_TYPE* IoFileObjectType;
@ -68,15 +74,6 @@ namespace
}
PFILE_OBJECT last_file_object = NULL;
struct SSpinlockSlot
{
std::mutex m;
std::atomic<bool> in_use;
};
std::array<SSpinlockSlot, 30> spinlock_slots;
std::atomic<unsigned int> curr_spinlock_slot(0);
}
struct KSPIN_LOCK_IMPL
@ -84,23 +81,6 @@ struct KSPIN_LOCK_IMPL
std::mutex m;
};
void init_events()
{
for (SEventSlot& slot : event_slots)
{
slot.waiters_a = 0;
slot.waiters_b = 0;
slot.waiters = &slot.waiters_a;
slot.evt_a = create_event(FALSE);
slot.evt_b = create_event(FALSE);
slot.evt = slot.evt_a;
}
for (SSpinlockSlot& slot : spinlock_slots)
{
slot.in_use = false;
}
}
LONG KeSetEvent(PKEVENT event, int a, BOOLEAN b)
{
LONG prev = std::atomic_load_explicit(reinterpret_cast<std::atomic<LONG>*>(&(event->eword)), std::memory_order_acquire);
@ -151,7 +131,6 @@ void init_object_type()
void init_windef()
{
init_events();
init_object_type();
}
@ -540,22 +519,6 @@ PLIST_ENTRY RemoveHeadList(PLIST_ENTRY ListHead)
return ret;
}
void InitializeListHead(PLIST_ENTRY ListHead)
{
ListHead->Flink = ListHead;
ListHead->Blink = ListHead;
}
void InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY ListEntry)
{
PLIST_ENTRY LastEntry = ListHead->Blink;
ListEntry->Flink = ListHead;
ListEntry->Blink = LastEntry;
ListHead->Blink = ListEntry;
LastEntry->Flink = ListEntry;
}
PLIST_ENTRY RemoveTailList(PLIST_ENTRY ListHead)
{
PLIST_ENTRY ret = ListHead->Blink;
@ -629,11 +592,6 @@ size_t RtlCompareMemory(const void* const src1, const void* const src2, size_t l
return len;
}
void RtlCopyMemory(PVOID dst, const PVOID src, size_t len)
{
memcpy(dst, src, len);
}
void RtlMoveMemory(PVOID dst, const void* src, size_t len)
{
memmove(dst, src, len);
@ -886,7 +844,7 @@ void InitializeObjectAttributes(POBJECT_ATTRIBUTES ObjectAttributes, PUNICODE_ST
{
if (arg1 != NULL)
{
ULONG len = min(sizeof(ObjectAttributes->path) - 1, arg1->Length / sizeof(WCHAR));
ULONG len = (std::min)(sizeof(ObjectAttributes->path) - 1, arg1->Length / sizeof(WCHAR));
memcpy(ObjectAttributes->path, arg1->Buffer, len * sizeof(WCHAR));
ObjectAttributes->path[len] = 0;
}
@ -1921,4 +1879,34 @@ BOOLEAN WdmlibRtlIsNtDdiVersionAvailable(ULONG Version)
HANDLE Handle32ToHandle(void* POINTER_32 ptr)
{
return HANDLE();
}
}
#ifndef _WIN32
int MultiByteToWideChar(UINT CodePage, DWORD Flags, char* ByteStr, int ByteStrSize, wchar_t* OutStr, int OutStrSize)
{
return 0;
}
PVOID GetModuleHandle(PVOID p1) { return nullptr; }
BOOL LoadStringW(PVOID module, int resid, WCHAR* str, size_t str_size)
{
return FALSE;
}
DWORD GetLastError(void)
{
return errno;
}
HMODULE LoadLibraryW(WCHAR* str)
{
return nullptr;
}
PVOID GetProcAddress(HMODULE, char* name)
{
return nullptr;
}
#endif

View File

@ -3,12 +3,66 @@
#include <guiddef.h>
#include <ntstatus.h>
#include <string.h>
#include <stdarg.h>
#ifndef _WIN32
#include <wchar.h>
#endif
#ifndef _WCHAR_T_DEFINED
#if !defined(_WCHAR_T_DEFINED) && defined(_WIN32)
typedef unsigned short wchar_t;
#define _WCHAR_T_DEFINED
#endif
#if !defined(_WIN32) && !defined(__stdcall)
#define __stdcall
#define _stdcall
#endif
#ifndef _WIN32
#define _MSC_VER 1
#define _Requires_lock_held_(a)
#define _Requires_exclusive_lock_held_(a)
#define _Releases_lock_(a)
#define _Out_writes_bytes_opt_(a)
#define _Pre_satisfies_(a)
#define _Post_satisfies_(a)
#define _Releases_exclusive_lock_(a)
#define _Create_lock_level_(a)
#define _Lock_level_order_(a,b)
#define _Has_lock_level_(a)
#define _Requires_lock_not_held_(a)
#define _Acquires_exclusive_lock_(a)
#define _Acquires_shared_lock_(a)
#define _In_opt_
#define _In_
#define _Out_
#define _Ret_maybenull_
#define _In_reads_bytes_opt_(x)
#define _When_(x, y)
#define _Success_(x)
#define _Inout_
#define _Out_writes_bytes_(x)
#define _In_reads_bytes_(x)
#define _In_z_
#define _Out_opt_
#ifndef __cplusplus
#define __try if (1)
#define __except(x) if (0 && (x))
#define __finally if (1)
#endif
#ifndef S_IFDIR
# define S_IFDIR 0040000
#endif
#ifndef S_IFREG
# define S_IFREG 0100000
#endif
#ifndef S_IFLNK
# define S_IFLNK 0120000
#endif
#define _stricmp strncasecmp
#define MAX_PATH 255
#endif
typedef unsigned char BOOL;
typedef BOOL BOOLEAN;
typedef void* HANDLE;
@ -22,8 +76,13 @@ typedef unsigned int UINT;
typedef LONG NTSTATUS;
typedef unsigned long DWORD;
typedef unsigned short WORD;
#ifdef _WIN32
typedef unsigned __int64 ULONGLONG;
typedef __int64 LONGLONG;
#else
typedef unsigned long long int ULONGLONG;
typedef long long int LONGLONG;
#endif
typedef short CSHORT;
typedef ULONG ACCESS_MASK;
typedef unsigned char UCHAR;
@ -39,6 +98,7 @@ typedef unsigned int KAFFINITY;
typedef char* PCHAR;
typedef size_t SIZE_T;
#ifdef _WIN32
#define POINTER_64 __ptr64
typedef unsigned __int64 POINTER_64_INT;
#if defined(_WIN64)
@ -46,6 +106,11 @@ typedef unsigned __int64 POINTER_64_INT;
#else
#define POINTER_32
#endif
#else
#define POINTER_64
#define POINTER_32
typedef unsigned long long int POINTER_64_INT;
#endif
typedef union
{
@ -2142,9 +2207,21 @@ BOOLEAN IsListEmpty(const LIST_ENTRY* ListHead);
PLIST_ENTRY RemoveHeadList(PLIST_ENTRY ListHead);
void InitializeListHead(PLIST_ENTRY ListHead);
FORCEINLINE void InitializeListHead(PLIST_ENTRY ListHead)
{
ListHead->Flink = ListHead;
ListHead->Blink = ListHead;
}
void InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY ListEntry);
FORCEINLINE void InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY ListEntry)
{
PLIST_ENTRY LastEntry = ListHead->Blink;
ListEntry->Flink = ListHead;
ListEntry->Blink = LastEntry;
ListHead->Blink = ListEntry;
LastEntry->Flink = ListEntry;
}
PLIST_ENTRY RemoveTailList(PLIST_ENTRY ListHead);
@ -2158,7 +2235,10 @@ void ZwClose(HANDLE hFile);
size_t RtlCompareMemory(const void* const src1, const void* const src2, size_t len);
void RtlCopyMemory(PVOID dst, const void* src, size_t len);
FORCEINLINE void RtlCopyMemory(PVOID dst, const void* src, size_t len)
{
memcpy(dst, src, len);
}
void RtlMoveMemory(PVOID dst, const void* src, size_t len);
@ -2619,6 +2699,19 @@ BOOL AdjustTokenPrivileges(HANDLE token, BOOL b, TOKEN_PRIVILEGES* TokenPrivs, U
NTSTATUS NtFsControlFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext,
PIO_STATUS_BLOCK IoStatusBlock, ULONG FsControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength);
#ifndef _WIN32
int MultiByteToWideChar(UINT CodePage, DWORD Flags, char* ByteStr, int ByteStrSize, wchar_t* OutStr, int OutStrSize);
#define CP_OEMCP 1
#define MB_PRECOMPOSED 1
PVOID GetModuleHandle(PVOID p1);
BOOL LoadStringW(PVOID module, int resid, WCHAR* str, size_t str_size);
DWORD GetLastError(void);
HMODULE LoadLibraryW(WCHAR* str);
PVOID GetProcAddress(HMODULE, char* name);
#endif
#define CONTAINING_RECORD(addr, type, field) ((type*)( (char*)(addr)-(ULONG_PTR)(&((type*)0)->field)))
#define FILE_ATTRIBUTE_SPARSE_FILE (1)

View File

@ -1,33 +0,0 @@
#include "event.h"
#include <Windows.h>
HANDLE create_event(bool state)
{
return CreateEventEx(NULL, NULL, state ? CREATE_EVENT_INITIAL_SET : 0, EVENT_ALL_ACCESS);
}
bool event_wait(HANDLE hEvent, DWORD ms)
{
DWORD rc = WaitForSingleObjectEx(hEvent, ms, TRUE);
return rc == WAIT_OBJECT_0 || rc==WAIT_IO_COMPLETION;
}
bool event_set(HANDLE hEvent)
{
return SetEvent(hEvent) == TRUE;
}
bool event_reset(HANDLE hEvent)
{
return ResetEvent(hEvent) == TRUE;
}
void event_destroy(HANDLE hEvent)
{
CloseHandle(hEvent);
}
bool event_pulse(HANDLE hEvent)
{
return PulseEvent(hEvent) == TRUE;
}

View File

@ -1,16 +0,0 @@
#pragma once
typedef void* HANDLE;
typedef unsigned long DWORD;
HANDLE create_event(bool state);
bool event_wait(HANDLE hEvent, DWORD ms);
bool event_set(HANDLE hEvent);
bool event_reset(HANDLE hEvent);
void event_destroy(HANDLE hEvent);
bool event_pulse(HANDLE hEvent);

View File

@ -1,4 +1,5 @@
#pragma once
#include <cstddef>
size_t os_get_num_cpus();

92
btrfs/fuse/oslib/os_lin.cpp Executable file
View File

@ -0,0 +1,92 @@
#include <wctype.h>
#include "os.h"
#include <unistd.h>
#include <assert.h>
#include <linux/futex.h>
#include <sys/syscall.h>
#include <random>
wchar_t os_toupper(wchar_t ch)
{
return towupper(ch);
}
long os_interlocked_increment(long volatile* val)
{
return __sync_add_and_fetch(val, 1);
}
long long os_interlocked_increment64(long long volatile* val)
{
return __sync_add_and_fetch(val, 1);
}
long os_interlocked_decrement(long volatile* val)
{
return __sync_sub_and_fetch(val, 1);
}
long os_interlocked_add(long volatile* val, long add)
{
return __sync_add_and_fetch(val, add);
}
void os_sleep(unsigned int ms)
{
if (ms > 1000)
{
sleep(ms / 1000);
if (ms % 1000 != 0)
{
usleep((ms % 1000) * 1000);
}
}
else
{
usleep(ms * 1000);
}
}
long os_interlocked_compare_exchange(long volatile* dest, long change, long comp)
{
return __sync_val_compare_and_swap(dest, comp, change);
}
#define INFINITE 0xFFFFFFFF
bool os_wait_on_address(volatile void* address, void* compare_address, size_t address_size, unsigned int waitms)
{
assert(address_size==sizeof(unsigned int));
struct timespec timeout;
timeout.tv_sec = waitms/1000;
waitms-=timeout.tv_sec*1000;
timeout.tv_nsec = waitms*1000*1000;
struct timespec* timeout_p = &timeout;
if(waitms==INFINITE)
timeout_p=nullptr;
unsigned int* cmp_ptr = reinterpret_cast<unsigned int*>(compare_address);
int rc = syscall(SYS_futex, address, FUTEX_WAIT_PRIVATE, *cmp_ptr, timeout_p);
return rc == 0;
}
void os_wake_by_address_single(void* address)
{
syscall(SYS_futex, address, FUTEX_WAKE_PRIVATE, 1);
}
long long os_perf_counter(long long* freq)
{
if (freq != nullptr)
{
*freq=0;
}
return 0;
}
unsigned long os_rand_next(unsigned long curr)
{
std::mt19937 mr(curr);
return mr();
}

View File

@ -26,7 +26,6 @@
<ClCompile Include="utf8.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="event.h" />
<ClInclude Include="file.h" />
<ClInclude Include="os.h" />
<ClInclude Include="utf8.h" />

View File

@ -32,9 +32,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="event.h">
<Filter>Quelldateien</Filter>
</ClInclude>
<ClInclude Include="file.h">
<Filter>Quelldateien</Filter>
</ClInclude>

View File

@ -1,34 +0,0 @@
// Copyright 2006 Nemanja Trifunovic
/*
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
#include "utf8/checked.h"
#include "utf8/unchecked.h"
#endif // header guard

View File

@ -1,318 +0,0 @@
// Copyright 2006 Nemanja Trifunovic
/*
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#ifndef UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
#define UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
#include "core.h"
#include <stdexcept>
namespace utf8
{
// Exceptions that may be thrown from the library functions.
class invalid_code_point : public std::exception {
uint32_t cp;
public:
invalid_code_point(uint32_t cp) : cp(cp) {}
virtual const char* what() const throw() { return "Invalid code point"; }
uint32_t code_point() const {return cp;}
};
class invalid_utf8 : public std::exception {
uint8_t u8;
public:
invalid_utf8 (uint8_t u) : u8(u) {}
virtual const char* what() const throw() { return "Invalid UTF-8"; }
uint8_t utf8_octet() const {return u8;}
};
class invalid_utf16 : public std::exception {
uint16_t u16;
public:
invalid_utf16 (uint16_t u) : u16(u) {}
virtual const char* what() const throw() { return "Invalid UTF-16"; }
uint16_t utf16_word() const {return u16;}
};
class not_enough_room : public std::exception {
public:
virtual const char* what() const throw() { return "Not enough space"; }
};
/// The library API - functions intended to be called by the users
template <typename octet_iterator, typename output_iterator>
output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement)
{
while (start != end) {
octet_iterator sequence_start = start;
internal::utf_error err_code = internal::validate_next(start, end);
switch (err_code) {
case internal::OK :
for (octet_iterator it = sequence_start; it != start; ++it)
*out++ = *it;
break;
case internal::NOT_ENOUGH_ROOM:
throw not_enough_room();
case internal::INVALID_LEAD:
append (replacement, out);
++start;
break;
case internal::INCOMPLETE_SEQUENCE:
case internal::OVERLONG_SEQUENCE:
case internal::INVALID_CODE_POINT:
append (replacement, out);
++start;
// just one replacement mark for the sequence
while (internal::is_trail(*start) && start != end)
++start;
break;
}
}
return out;
}
template <typename octet_iterator, typename output_iterator>
inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out)
{
static const uint32_t replacement_marker = internal::mask16(0xfffd);
return replace_invalid(start, end, out, replacement_marker);
}
template <typename octet_iterator>
octet_iterator append(uint32_t cp, octet_iterator result)
{
if (!internal::is_code_point_valid(cp))
throw invalid_code_point(cp);
if (cp < 0x80) // one octet
*(result++) = static_cast<uint8_t>(cp);
else if (cp < 0x800) { // two octets
*(result++) = static_cast<uint8_t>((cp >> 6) | 0xc0);
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
}
else if (cp < 0x10000) { // three octets
*(result++) = static_cast<uint8_t>((cp >> 12) | 0xe0);
*(result++) = static_cast<uint8_t>((cp >> 6) & 0x3f | 0x80);
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
}
else if (cp <= internal::CODE_POINT_MAX) { // four octets
*(result++) = static_cast<uint8_t>((cp >> 18) | 0xf0);
*(result++) = static_cast<uint8_t>((cp >> 12)& 0x3f | 0x80);
*(result++) = static_cast<uint8_t>((cp >> 6) & 0x3f | 0x80);
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
}
else
throw invalid_code_point(cp);
return result;
}
template <typename octet_iterator>
uint32_t next(octet_iterator& it, octet_iterator end)
{
uint32_t cp = 0;
internal::utf_error err_code = internal::validate_next(it, end, &cp);
switch (err_code) {
case internal::OK :
break;
case internal::NOT_ENOUGH_ROOM :
throw not_enough_room();
case internal::INVALID_LEAD :
case internal::INCOMPLETE_SEQUENCE :
case internal::OVERLONG_SEQUENCE :
throw invalid_utf8(*it);
case internal::INVALID_CODE_POINT :
throw invalid_code_point(cp);
}
return cp;
}
template <typename octet_iterator>
uint32_t peek_next(octet_iterator it, octet_iterator end)
{
return next(it, end);
}
template <typename octet_iterator>
uint32_t prior(octet_iterator& it, octet_iterator start)
{
octet_iterator end = it;
while (internal::is_trail(*(--it)))
if (it < start)
throw invalid_utf8(*it); // error - no lead byte in the sequence
octet_iterator temp = it;
return next(temp, end);
}
/// Deprecated in versions that include "prior"
template <typename octet_iterator>
uint32_t previous(octet_iterator& it, octet_iterator pass_start)
{
octet_iterator end = it;
while (internal::is_trail(*(--it)))
if (it == pass_start)
throw invalid_utf8(*it); // error - no lead byte in the sequence
octet_iterator temp = it;
return next(temp, end);
}
template <typename octet_iterator, typename distance_type>
void advance (octet_iterator& it, distance_type n, octet_iterator end)
{
for (distance_type i = 0; i < n; ++i)
next(it, end);
}
template <typename octet_iterator>
typename std::iterator_traits<octet_iterator>::difference_type
distance (octet_iterator first, octet_iterator last)
{
typename std::iterator_traits<octet_iterator>::difference_type dist;
for (dist = 0; first < last; ++dist)
next(first, last);
return dist;
}
template <typename u16bit_iterator, typename octet_iterator>
octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
{
while (start != end) {
uint32_t cp = internal::mask16(*start++);
// Take care of surrogate pairs first
if (internal::is_surrogate(cp)) {
if (start != end) {
uint32_t trail_surrogate = internal::mask16(*start++);
if (trail_surrogate >= internal::TRAIL_SURROGATE_MIN && trail_surrogate <= internal::TRAIL_SURROGATE_MAX)
cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
else
throw invalid_utf16(static_cast<uint16_t>(trail_surrogate));
}
else
throw invalid_utf16(static_cast<uint16_t>(*start));
}
result = append(cp, result);
}
return result;
}
template <typename u16bit_iterator, typename octet_iterator>
u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
{
while (start != end) {
uint32_t cp = next(start, end);
if (cp > 0xffff) { //make a surrogate pair
*result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
*result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
}
else
*result++ = static_cast<uint16_t>(cp);
}
return result;
}
template <typename octet_iterator, typename u32bit_iterator>
octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
{
while (start != end)
result = append(*(start++), result);
return result;
}
template <typename octet_iterator, typename u32bit_iterator>
u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
{
while (start < end)
(*result++) = next(start, end);
return result;
}
// The iterator class
template <typename octet_iterator>
class iterator : public std::iterator <std::bidirectional_iterator_tag, uint32_t> {
octet_iterator it;
octet_iterator range_start;
octet_iterator range_end;
public:
iterator () {};
explicit iterator (const octet_iterator& octet_it,
const octet_iterator& range_start,
const octet_iterator& range_end) :
it(octet_it), range_start(range_start), range_end(range_end)
{
if (it < range_start || it > range_end)
throw std::out_of_range("Invalid utf-8 iterator position");
}
// the default "big three" are OK
octet_iterator base () const { return it; }
uint32_t operator * () const
{
octet_iterator temp = it;
return next(temp, range_end);
}
bool operator == (const iterator& rhs) const
{
if (range_start != rhs.range_start || range_end != rhs.range_end)
throw std::logic_error("Comparing utf-8 iterators defined with different ranges");
return (it == rhs.it);
}
bool operator != (const iterator& rhs) const
{
return !(operator == (rhs));
}
iterator& operator ++ ()
{
next(it, range_end);
return *this;
}
iterator operator ++ (int)
{
iterator temp = *this;
next(it, range_end);
return temp;
}
iterator& operator -- ()
{
prior(it, range_start);
return *this;
}
iterator operator -- (int)
{
iterator temp = *this;
prior(it, range_start);
return temp;
}
}; // class iterator
} // namespace utf8
#endif //header guard

View File

@ -1,259 +0,0 @@
// Copyright 2006 Nemanja Trifunovic
/*
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#ifndef UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
#define UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
#include <iterator>
namespace utf8
{
// The typedefs for 8-bit, 16-bit and 32-bit unsigned integers
// You may need to change them to match your system.
// These typedefs have the same names as ones from cstdint, or boost/cstdint
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
// Helper code - not intended to be directly called by the library users. May be changed at any time
namespace internal
{
// Unicode constants
// Leading (high) surrogates: 0xd800 - 0xdbff
// Trailing (low) surrogates: 0xdc00 - 0xdfff
const uint16_t LEAD_SURROGATE_MIN = 0xd800u;
const uint16_t LEAD_SURROGATE_MAX = 0xdbffu;
const uint16_t TRAIL_SURROGATE_MIN = 0xdc00u;
const uint16_t TRAIL_SURROGATE_MAX = 0xdfffu;
const uint16_t LEAD_OFFSET = LEAD_SURROGATE_MIN - (0x10000 >> 10);
const uint32_t SURROGATE_OFFSET = 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN;
// Maximum valid value for a Unicode code point
const uint32_t CODE_POINT_MAX = 0x0010ffffu;
template<typename octet_type>
inline uint8_t mask8(octet_type oc)
{
return static_cast<uint8_t>(0xff & oc);
}
template<typename u16_type>
inline uint16_t mask16(u16_type oc)
{
return static_cast<uint16_t>(0xffff & oc);
}
template<typename octet_type>
inline bool is_trail(octet_type oc)
{
return ((mask8(oc) >> 6) == 0x2);
}
template <typename u16>
inline bool is_surrogate(u16 cp)
{
return (cp >= LEAD_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX);
}
template <typename u32>
inline bool is_code_point_valid(u32 cp)
{
return (cp <= CODE_POINT_MAX && !is_surrogate(cp) && cp != 0xfffe && cp != 0xffff);
}
template <typename octet_iterator>
inline typename std::iterator_traits<octet_iterator>::difference_type
sequence_length(octet_iterator lead_it)
{
uint8_t lead = mask8(*lead_it);
if (lead < 0x80)
return 1;
else if ((lead >> 5) == 0x6)
return 2;
else if ((lead >> 4) == 0xe)
return 3;
else if ((lead >> 3) == 0x1e)
return 4;
else
return 0;
}
enum utf_error {OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT};
template <typename octet_iterator>
utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t* code_point)
{
uint32_t cp = mask8(*it);
// Check the lead octet
typedef typename std::iterator_traits<octet_iterator>::difference_type octet_difference_type;
octet_difference_type length = sequence_length(it);
// "Shortcut" for ASCII characters
if (length == 1) {
if (end - it > 0) {
if (code_point)
*code_point = cp;
++it;
return OK;
}
else
return NOT_ENOUGH_ROOM;
}
// Do we have enough memory?
if (std::distance(it, end) < length)
return NOT_ENOUGH_ROOM;
// Check trail octets and calculate the code point
switch (length) {
case 0:
return INVALID_LEAD;
break;
case 2:
if (is_trail(*(++it))) {
cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f);
}
else {
--it;
return INCOMPLETE_SEQUENCE;
}
break;
case 3:
if (is_trail(*(++it))) {
cp = ((cp << 12) & 0xffff) + ((mask8(*it) << 6) & 0xfff);
if (is_trail(*(++it))) {
cp += (*it) & 0x3f;
}
else {
std::advance(it, -2);
return INCOMPLETE_SEQUENCE;
}
}
else {
--it;
return INCOMPLETE_SEQUENCE;
}
break;
case 4:
if (is_trail(*(++it))) {
cp = ((cp << 18) & 0x1fffff) + ((mask8(*it) << 12) & 0x3ffff);
if (is_trail(*(++it))) {
cp += (mask8(*it) << 6) & 0xfff;
if (is_trail(*(++it))) {
cp += (*it) & 0x3f;
}
else {
std::advance(it, -3);
return INCOMPLETE_SEQUENCE;
}
}
else {
std::advance(it, -2);
return INCOMPLETE_SEQUENCE;
}
}
else {
--it;
return INCOMPLETE_SEQUENCE;
}
break;
}
// Is the code point valid?
if (!is_code_point_valid(cp)) {
for (octet_difference_type i = 0; i < length - 1; ++i)
--it;
return INVALID_CODE_POINT;
}
if (code_point)
*code_point = cp;
if (cp < 0x80) {
if (length != 1) {
std::advance(it, (int)(-(length-1)));
return OVERLONG_SEQUENCE;
}
}
else if (cp < 0x800) {
if (length != 2) {
std::advance(it, (int)(-(length-1)));
return OVERLONG_SEQUENCE;
}
}
else if (cp < 0x10000) {
if (length != 3) {
std::advance(it, (int)(-(length-1)));
return OVERLONG_SEQUENCE;
}
}
++it;
return OK;
}
template <typename octet_iterator>
inline utf_error validate_next(octet_iterator& it, octet_iterator end) {
return validate_next(it, end, 0);
}
} // namespace internal
/// The library API - functions intended to be called by the users
// Byte order mark
const uint8_t bom[] = {0xef, 0xbb, 0xbf};
template <typename octet_iterator>
octet_iterator find_invalid(octet_iterator start, octet_iterator end)
{
octet_iterator result = start;
while (result != end) {
internal::utf_error err_code = internal::validate_next(result, end);
if (err_code != internal::OK)
return result;
}
return result;
}
template <typename octet_iterator>
inline bool is_valid(octet_iterator start, octet_iterator end)
{
return (find_invalid(start, end) == end);
}
template <typename octet_iterator>
inline bool is_bom (octet_iterator it)
{
return (
(internal::mask8(*it++)) == bom[0] &&
(internal::mask8(*it++)) == bom[1] &&
(internal::mask8(*it)) == bom[2]
);
}
} // namespace utf8
#endif // header guard

View File

@ -1,228 +0,0 @@
// Copyright 2006 Nemanja Trifunovic
/*
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#ifndef UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
#define UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
#include "core.h"
namespace utf8
{
namespace unchecked
{
template <typename octet_iterator>
octet_iterator append(uint32_t cp, octet_iterator result)
{
if (cp < 0x80) // one octet
*(result++) = static_cast<uint8_t>(cp);
else if (cp < 0x800) { // two octets
*(result++) = static_cast<uint8_t>((cp >> 6) | 0xc0);
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
}
else if (cp < 0x10000) { // three octets
*(result++) = static_cast<uint8_t>((cp >> 12) | 0xe0);
*(result++) = static_cast<uint8_t>((cp >> 6) & 0x3f | 0x80);
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
}
else { // four octets
*(result++) = static_cast<uint8_t>((cp >> 18) | 0xf0);
*(result++) = static_cast<uint8_t>((cp >> 12)& 0x3f | 0x80);
*(result++) = static_cast<uint8_t>((cp >> 6) & 0x3f | 0x80);
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
}
return result;
}
template <typename octet_iterator>
uint32_t next(octet_iterator& it)
{
uint32_t cp = internal::mask8(*it);
typename std::iterator_traits<octet_iterator>::difference_type length = utf8::internal::sequence_length(it);
switch (length) {
case 1:
break;
case 2:
it++;
cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f);
break;
case 3:
++it;
cp = ((cp << 12) & 0xffff) + ((internal::mask8(*it) << 6) & 0xfff);
++it;
cp += (*it) & 0x3f;
break;
case 4:
++it;
cp = ((cp << 18) & 0x1fffff) + ((internal::mask8(*it) << 12) & 0x3ffff);
++it;
cp += (internal::mask8(*it) << 6) & 0xfff;
++it;
cp += (*it) & 0x3f;
break;
}
++it;
return cp;
}
template <typename octet_iterator>
uint32_t peek_next(octet_iterator it)
{
return next(it);
}
template <typename octet_iterator>
uint32_t prior(octet_iterator& it)
{
while (internal::is_trail(*(--it))) ;
octet_iterator temp = it;
return next(temp);
}
// Deprecated in versions that include prior, but only for the sake of consistency (see utf8::previous)
template <typename octet_iterator>
inline uint32_t previous(octet_iterator& it)
{
return prior(it);
}
template <typename octet_iterator, typename distance_type>
void advance (octet_iterator& it, distance_type n)
{
for (distance_type i = 0; i < n; ++i)
next(it);
}
template <typename octet_iterator>
typename std::iterator_traits<octet_iterator>::difference_type
distance (octet_iterator first, octet_iterator last)
{
typename std::iterator_traits<octet_iterator>::difference_type dist;
for (dist = 0; first < last; ++dist)
next(first);
return dist;
}
template <typename u16bit_iterator, typename octet_iterator>
octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
{
while (start != end) {
uint32_t cp = internal::mask16(*start++);
// Take care of surrogate pairs first
if (internal::is_surrogate(cp)) {
uint32_t trail_surrogate = internal::mask16(*start++);
cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
}
result = append(cp, result);
}
return result;
}
template <typename u16bit_iterator, typename octet_iterator>
u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
{
while (start != end) {
uint32_t cp = next(start);
if (cp > 0xffff) { //make a surrogate pair
*result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
*result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
}
else
*result++ = static_cast<uint16_t>(cp);
}
return result;
}
template <typename octet_iterator, typename u32bit_iterator>
octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
{
while (start != end)
result = append(*(start++), result);
return result;
}
template <typename octet_iterator, typename u32bit_iterator>
u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
{
while (start < end)
(*result++) = next(start);
return result;
}
// The iterator class
template <typename octet_iterator>
class iterator : public std::iterator <std::bidirectional_iterator_tag, uint32_t> {
octet_iterator it;
public:
iterator () {};
explicit iterator (const octet_iterator& octet_it): it(octet_it) {}
// the default "big three" are OK
octet_iterator base () const { return it; }
uint32_t operator * () const
{
octet_iterator temp = it;
return next(temp);
}
bool operator == (const iterator& rhs) const
{
return (it == rhs.it);
}
bool operator != (const iterator& rhs) const
{
return !(operator == (rhs));
}
iterator& operator ++ ()
{
std::advance(it, internal::sequence_length(it));
return *this;
}
iterator operator ++ (int)
{
iterator temp = *this;
std::advance(it, internal::sequence_length(it));
return temp;
}
iterator& operator -- ()
{
prior(it);
return *this;
}
iterator operator -- (int)
{
iterator temp = *this;
prior(it);
return temp;
}
}; // class iterator
} // namespace utf8::unchecked
} // namespace utf8
#endif // header guard

View File

@ -48,6 +48,8 @@ AC_ARG_ENABLE([embedded-zstd],
AS_HELP_STRING([--enable-embedded-zstd], [Compile and use ZSTD included with the source distribution.]))
AM_CONDITIONAL(EMBEDDED_ZSTD, test "x$enable_embedded_zstd" = xyes)
AM_CONDITIONAL(WITH_BTRFS_ZLIB, test 1 = 0)
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
@ -64,8 +66,52 @@ fi
AC_LANG([C++])
AX_CXX_COMPILE_STDCXX([17])
# Checks for libraries.
AX_CHECK_OPENSSL([with_openssl=true], [with_openssl=false])
AM_CONDITIONAL([WITH_OPENSSL], [test x$with_openssl = xtrue])
if test "x$with_openssl" != "xtrue"
then
AC_MSG_ERROR([OpenSSL library not present or not recent enough.])
fi
LIBCURL_CHECK_CONFIG(,[7.20.0],,[
AC_MSG_ERROR([Your system lacks of libcurl >= 7.20.0])
])
AC_CHECK_HEADER(aws/s3/S3Client.h, [HAS_AWS_SDK_H=1])
AC_CHECK_LIB(aws-c-common, aws_string_destroy, [HAS_AWS_C_COMMON=1])
AC_MSG_CHECKING([linking to aws-c++-sdk])
SAVED_LDFLAGS="$LDFLAGS"
SAVED_LIBS="$LIBS"
SAVED_CPPFLAGS="$CPPFLAGS"
AWS_SDK_INCLUDES=""
AWS_SDK_LIBS="-laws-cpp-sdk-s3 -laws-cpp-sdk-core -laws-c-event-stream -laws-checksums -laws-c-common"
LDFLAGS="$LDFLAGS"
CPPFLAGS="$CPPFLAGS $PTHREAD_CFLAGS $AWS_SDK_INCLUDES"
LIBS="$LIBS $AWS_SDK_LIBS $OPENSSL_LIBS $LIBS $LIBCURL $PTHREAD_LIBS"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <aws/s3/model/BucketLocationConstraint.h>],
[Aws::S3::Model::BucketLocationConstraintMapper::GetNameForBucketLocationConstraint(Aws::S3::Model::BucketLocationConstraint::af_south_1);])],
[
HAS_AWS_CPP_SDK=1
AC_MSG_RESULT([yes])
],
[AC_MSG_RESULT([no])])
LDFLAGS="$SAVED_LDFLAGS"
CPPFLAGS="$SAVED_CPPFLAGS"
LIBS="$SAVED_LIBS"
AC_SUBST([AWS_SDK_INCLUDES])
AC_SUBST([AWS_SDK_LIBS])
if test "x$HAS_AWS_SDK_H" != "x1" || test "x$HAS_AWS_C_COMMON" != "x1" || test "x$HAS_AWS_CPP_SDK" != "x1"
then
AC_MSG_ERROR(AWS C++ SDK not found or installed correctly)
fi
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([pthread.h arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h sys/socket.h sys/time.h unistd.h mntent.h spawn.h linux/fiemap.h sys/random.h linux/fs.h])
@ -88,6 +134,10 @@ AX_CHECK_COMPILE_FLAG(-fstack-protector-strong --param=ssp-buffer-size=4 -Wforma
AX_CHECK_COMPILE_FLAG(-msse4.1 -msse4.2,
[AM_CONDITIONAL(WITH_SSE4_2, test xyes = xyes)],
[AM_CONDITIONAL(WITH_SSE4_2, test xyes = xno)])
AX_CHECK_COMPILE_FLAG(-Wno-subobject-linkage,
[AM_CONDITIONAL(DISABLE_CERTAIN_WARNINGS, test xyes = xyes)],
[AM_CONDITIONAL(DISABLE_CERTAIN_WARNINGS, test xyes = xno)])
AX_CHECK_LINK_FLAG([-Wl,-z,relro],
[], [AM_CONDITIONAL(WITH_FORTIFY, test xyes = xno)])
@ -172,14 +222,6 @@ then
])
fi
AX_CHECK_OPENSSL([with_openssl=true], [with_openssl=false])
AM_CONDITIONAL([WITH_OPENSSL], [test x$with_openssl = xtrue])
if test "x$with_openssl" != "xtrue"
then
AC_MSG_WARN([OpenSSL library not present or not recent enough. Compiling without OpenSSL support (web socket/https proxy support)])
fi
AM_CONDITIONAL(WITH_GUI_CLIENT, test "x$enable_headless" != "xyes")
AS_IF([test "x$enable_headless" != "xyes"],

View File

@ -77,6 +77,10 @@ AC_STRUCT_TM
AX_CHECK_COMPILE_FLAG(-fstack-protector-strong --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIE,
[], [AM_CONDITIONAL(WITH_FORTIFY, test xyes = xno)])
AX_CHECK_COMPILE_FLAG(-Wno-subobject-linkage,
[AM_CONDITIONAL(DISABLE_CERTAIN_WARNINGS, test xyes = xyes)],
[AM_CONDITIONAL(DISABLE_CERTAIN_WARNINGS, test xyes = xno)])
AX_CHECK_LINK_FLAG([-Wl,-z,relro],
[], [AM_CONDITIONAL(WITH_FORTIFY, test xyes = xno)])

View File

@ -77,7 +77,7 @@ static void print_string(FILE* f, int resid, ...) {
va_end(ap);
}
int main(int argc, char** argv) {
int main_mkbtrfs(int argc, char** argv) {
HMODULE ubtrfs;
bool baddrive = false, success;
char *ds = NULL, *labels = NULL;

View File

@ -97,19 +97,6 @@ typedef struct {
DSTRING* label;
} options;
FORCEINLINE VOID InitializeListHead(PLIST_ENTRY ListHead) {
ListHead->Flink = ListHead->Blink = ListHead;
}
FORCEINLINE VOID InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry) {
PLIST_ENTRY Blink;
Blink = ListHead->Blink;
Entry->Flink = ListHead;
Entry->Blink = Blink;
Blink->Flink = Entry;
ListHead->Blink = Entry;
}
typedef struct {
KEY key;

View File

@ -227,7 +227,7 @@ static U64 XXH_read64(const void* memPtr)
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
/* Note : although _rotl exists for minGW (GCC under windows), performance seems poor */
#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(__GNUC__)
# define XXH_rotl32(x,r) _rotl(x,r)
# define XXH_rotl64(x,r) _rotl64(x,r)
#else
@ -235,7 +235,7 @@ static U64 XXH_read64(const void* memPtr)
# define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
#endif
#if defined(_MSC_VER) /* Visual Studio */
#if defined(_MSC_VER) && !defined(__GNUC__) /* Visual Studio */
# define XXH_swap32 _byteswap_ulong
# define XXH_swap64 _byteswap_uint64
#elif GCC_VERSION >= 403

View File

@ -19,6 +19,7 @@
#include "vhdxfile.h"
#include "../stringtools.h"
#include <assert.h>
#include <cstring>
#include "CompressedFile.h"
#include "../urbackupcommon/os_functions.h"
#include "FileWrapper.h"
@ -49,9 +50,9 @@ namespace
{
std::vector<char> ret;
ret.resize(500);
memcpy(ret.data(), "vhdxfile", 8);
std::memcpy(ret.data(), "vhdxfile", 8);
std::string creator = Server->ConvertToUTF16("UrBackup vhdx file");
memcpy(ret.data() + 8, creator.data(), creator.size());
std::memcpy(ret.data() + 8, creator.data(), creator.size());
return ret;
}
@ -87,7 +88,7 @@ namespace
void copyGUID(const VhdxGUID& src, VhdxGUID& dst)
{
memcpy(dst, src, 16);
std::memcpy(dst, src, 16);
}
void reorderGUID(VhdxGUID& g)
@ -166,7 +167,7 @@ namespace
std::vector<char> ret;
ret.resize(sizeof(VhdxHeader));
VhdxHeader* vhdxHeader = reinterpret_cast<VhdxHeader*>(ret.data());
memcpy(ret.data(), "head", 4);
std::memcpy(ret.data(), "head", 4);
vhdxHeader->SequenceNumber = SequenceNumber;
secureRandomGuid(vhdxHeader->FileWriteGuid);
secureRandomGuid(vhdxHeader->DataWriteGuid);
@ -311,14 +312,14 @@ namespace
void makeMetaTableGUID(VhdxGUID& g)
{
unsigned char meta_guid[16] = { 0x8B, 0x7C, 0xA2, 0x06, 0x47, 0x90, 0x4B, 0x9A, 0xB8, 0xFE, 0x57, 0x5F, 0x05, 0x0F, 0x88, 0x6E };
memcpy(g, meta_guid, sizeof(meta_guid));
std::memcpy(g, meta_guid, sizeof(meta_guid));
reorderGUID(g);
}
void makeBatGUID(VhdxGUID& g)
{
unsigned char bat_guid[16] = { 0x2D, 0xC2, 0x77, 0x66, 0xF6, 0x23, 0x42, 0x00, 0x9D, 0x64, 0x11, 0x5E, 0x9B, 0xFD, 0x4A, 0x08 };
memcpy(g, bat_guid, sizeof(bat_guid));
std::memcpy(g, bat_guid, sizeof(bat_guid));
reorderGUID(g);
}
@ -330,7 +331,7 @@ namespace
std::vector<char> ret;
ret.resize(64 * 1024);
memcpy(ret.data(), "regi", 4);
std::memcpy(ret.data(), "regi", 4);
VhdxRegionTableHeader* header = reinterpret_cast<VhdxRegionTableHeader*>(ret.data());
header->EntryCount = 2;
@ -413,42 +414,42 @@ namespace
void makeFileParametersGUID(VhdxGUID& g)
{
unsigned char file_parameters_guid[16] = { 0xCA, 0xA1, 0x67, 0x37, 0xFA, 0x36, 0x4D, 0x43, 0xB3, 0xB6, 0x33, 0xF0, 0xAA, 0x44, 0xE7, 0x6B };
memcpy(&g, file_parameters_guid, sizeof(file_parameters_guid));
std::memcpy(&g, file_parameters_guid, sizeof(file_parameters_guid));
reorderGUID(g);
}
void makeVirtualDiskSizeGUID(VhdxGUID& g)
{
unsigned char virtual_disk_size_guid[16] = { 0x2F, 0xA5, 0x42, 0x24, 0xCD, 0x1B, 0x48, 0x76, 0xB2, 0x11, 0x5D, 0xBE, 0xD8, 0x3B, 0xF4, 0xB8 };
memcpy(&g, virtual_disk_size_guid, sizeof(virtual_disk_size_guid));
std::memcpy(&g, virtual_disk_size_guid, sizeof(virtual_disk_size_guid));
reorderGUID(g);
}
void makeLogicalSectorSizeGUID(VhdxGUID& g)
{
unsigned char logical_sector_size_guid[16] = { 0x81, 0x41, 0xBF, 0x1D, 0xA9, 0x6F, 0x47, 0x09, 0xBA, 0x47, 0xF2, 0x33, 0xA8, 0xFA, 0xAB, 0x5F };
memcpy(&g, logical_sector_size_guid, sizeof(logical_sector_size_guid));
std::memcpy(&g, logical_sector_size_guid, sizeof(logical_sector_size_guid));
reorderGUID(g);
}
void makePhysicalSectorSizeGUID(VhdxGUID& g)
{
unsigned char physical_sector_size_guid[16] = { 0xCD, 0xA3, 0x48, 0xC7, 0x44, 0x5D, 0x44, 0x71, 0x9C, 0xC9, 0xE9, 0x88, 0x52, 0x51, 0xC5, 0x56 };
memcpy(&g, physical_sector_size_guid, sizeof(physical_sector_size_guid));
std::memcpy(&g, physical_sector_size_guid, sizeof(physical_sector_size_guid));
reorderGUID(g);
}
void makeVirtualDiskIdGUID(VhdxGUID& g)
{
unsigned char page83_data_guid[16] = { 0xBE, 0xCA, 0x12, 0xAB, 0xB2, 0xE6, 0x45, 0x23, 0x93, 0xEF, 0xC3, 0x09, 0xE0, 0x00, 0xC7, 0x46 };
memcpy(&g, page83_data_guid, sizeof(page83_data_guid));
std::memcpy(&g, page83_data_guid, sizeof(page83_data_guid));
reorderGUID(g);
}
void makeParentLocatorGUID(VhdxGUID& g)
{
unsigned char parent_locator_guid[16] = { 0xA8, 0xD3, 0x5F, 0x2D, 0xB3, 0x0B, 0x45, 0x4D, 0xAB, 0xF7, 0xD3, 0xD8, 0x48, 0x34, 0xAB, 0x0C };
memcpy(&g, parent_locator_guid, sizeof(parent_locator_guid));
std::memcpy(&g, parent_locator_guid, sizeof(parent_locator_guid));
reorderGUID(g);
}
@ -456,7 +457,7 @@ namespace
{
unsigned char vhdx_parent_locator_guid[16] = { 0xB0, 0x4A, 0xEF, 0xB7, 0xD1, 0x9E, 0x4A, 0x81, 0xB7, 0x89, 0x25,
0xB8, 0xE9, 0x44, 0x59, 0x13 };
memcpy(&g, vhdx_parent_locator_guid, sizeof(vhdx_parent_locator_guid));
std::memcpy(&g, vhdx_parent_locator_guid, sizeof(vhdx_parent_locator_guid));
reorderGUID(g);
}
@ -492,7 +493,7 @@ namespace
+ sizeof(VhdxVirtualDiskId)
+ parent_locator_size);
memcpy(ret.data(), "metadata", 8);
std::memcpy(ret.data(), "metadata", 8);
VhdxMetadataTableHeader* header = reinterpret_cast<VhdxMetadataTableHeader*>(ret.data());
header->EntryCount = 5;
@ -579,12 +580,12 @@ namespace
entry->KeyOffset = static_cast<_u32>(str_pos - parent_locator_entry->Offset);
entry->KeyLength = static_cast<_u16>(it.first.size());
memcpy(ret.data() + str_pos, it.first.data(), it.first.size());
std::memcpy(ret.data() + str_pos, it.first.data(), it.first.size());
str_pos += it.first.size();
entry->ValueOffset = static_cast<_u32>(str_pos - parent_locator_entry->Offset);
entry->ValueLength = static_cast<_u16>(it.second.size());
memcpy(ret.data() + str_pos, it.second.data(), it.second.size());
std::memcpy(ret.data() + str_pos, it.second.data(), it.second.size());
str_pos += it.second.size();
}
@ -778,9 +779,9 @@ namespace
LogData log_data;
log_data.offset = data_desc->FileOffset;
memcpy(log_data.data, data_desc->LeadingBytes, 8);
memcpy(log_data.data + 8, data_sec->data, sizeof(data_sec->data));
memcpy(log_data.data + 8 + sizeof(data_sec->data), data_desc->TrailingBytes, 4);
std::memcpy(log_data.data, data_desc->LeadingBytes, 8);
std::memcpy(log_data.data + 8, data_sec->data, sizeof(data_sec->data));
std::memcpy(log_data.data + 8 + sizeof(data_sec->data), data_desc->TrailingBytes, 4);
loge.to_write.push_back(log_data);
}
@ -1750,7 +1751,7 @@ void VHDXFile::getDataWriteGUID(VhdxGUID& g)
bool VHDXFile::createNew()
{
memset(&curr_header, 0, sizeof(curr_header));
memcpy(&curr_header, "head", 4);
std::memcpy(&curr_header, "head", 4);
curr_header.SequenceNumber = 1;
secureRandomGuid(curr_header.FileWriteGuid);
secureRandomGuid(curr_header.DataWriteGuid);
@ -2045,7 +2046,7 @@ bool VHDXFile::readHeader()
return false;
}
memcpy(&curr_header, sel_header, sizeof(curr_header));
std::memcpy(&curr_header, sel_header, sizeof(curr_header));
return true;
}
@ -2092,7 +2093,7 @@ bool VHDXFile::readRegionTable(int64 off)
if (equalsGUID(entry->Guid, meta_table_guid))
{
memcpy(&meta_table_region, entry, sizeof(meta_table_region));
std::memcpy(&meta_table_region, entry, sizeof(meta_table_region));
if (found & 1)
{
Server->Log("Found metadata table region entry twice", LL_WARNING);
@ -2102,7 +2103,7 @@ bool VHDXFile::readRegionTable(int64 off)
}
else if (equalsGUID(entry->Guid, bat_guid))
{
memcpy(&bat_region, entry, sizeof(bat_region));
std::memcpy(&bat_region, entry, sizeof(bat_region));
if (found & 2)
{
Server->Log("Found BAT table region entry twice", LL_WARNING);
@ -2231,7 +2232,7 @@ bool VHDXFile::readMeta()
return false;
}
memcpy(&vhdx_params, entry_buf.data(), sizeof(vhdx_params));
std::memcpy(&vhdx_params, entry_buf.data(), sizeof(vhdx_params));
}
else if (equalsGUID(table_entry->ItemId, virtual_disk_size_guid))
{
@ -2701,7 +2702,7 @@ bool VHDXFile::logWrite(int64 off, const char* buf, size_t bsize,
LogEntryHeader* header = reinterpret_cast<LogEntryHeader*>(log_entry.data());
memcpy(&header->signature, "loge", 4);
std::memcpy(&header->signature, "loge", 4);
header->Checksum = 0;
header->EntryLength = static_cast<_u32>(log_entry.size());
@ -2721,10 +2722,10 @@ bool VHDXFile::logWrite(int64 off, const char* buf, size_t bsize,
{
LogDataDescriptor* data_desc = reinterpret_cast<LogDataDescriptor*>(log_entry.data() + 64 + i * 32);
memcpy(&data_desc->signature, "desc", 4);
std::memcpy(&data_desc->signature, "desc", 4);
data_desc->FileOffset = off + i * log_sector_size;
memcpy(data_desc->LeadingBytes, buf + i * log_sector_size, 8);
memcpy(data_desc->TrailingBytes, buf + i * log_sector_size + (log_sector_size - 4), 4);
std::memcpy(data_desc->LeadingBytes, buf + i * log_sector_size, 8);
std::memcpy(data_desc->TrailingBytes, buf + i * log_sector_size + (log_sector_size - 4), 4);
data_desc->SequenceNumber = header->SequenceNumber;
}
@ -2732,12 +2733,12 @@ bool VHDXFile::logWrite(int64 off, const char* buf, size_t bsize,
{
LogDataSector* data_sec = reinterpret_cast<LogDataSector*>(log_entry.data() + log_sector_size + i * log_sector_size);
memcpy(&data_sec->signature, "data", 4);
std::memcpy(&data_sec->signature, "data", 4);
SSequence seq;
seq.QuadPart = header->SequenceNumber;
data_sec->SequenceLow = seq.LowPart;
data_sec->SequenceHigh = seq.HighPart;
memcpy(data_sec->data, buf + i + 8, log_sector_size - 8 - 4);
std::memcpy(data_sec->data, buf + i + 8, log_sector_size - 8 - 4);
}
header->Checksum = crc32c(reinterpret_cast<unsigned char*>(log_entry.data()), log_entry.size());

View File

@ -11,6 +11,9 @@
#include "ClientService.h"
#include <chrono>
#include <atomic>
#include <memory>
#include <thread>
#include <condition_variable>
using namespace std::chrono_literals;
extern IBtrfsFactory* btrfs_fak;
@ -40,6 +43,11 @@ namespace
});
}
TmpFileHandlingFileSystem(const TmpFileHandlingFileSystem&) = delete;
void operator=(const TmpFileHandlingFileSystem&) = delete;
TmpFileHandlingFileSystem(TmpFileHandlingFileSystem&&) = delete;
void operator=(TmpFileHandlingFileSystem&&) = delete;
~TmpFileHandlingFileSystem()
{
{
@ -377,10 +385,14 @@ bool FilesystemManager::mountFileSystem(const std::string& url, const std::strin
IBackupFileSystem* fs = filesystems[url];
std::thread dm([url, fs, mount_path]() {
#ifndef _WIN32
//TODO: Implement fuse
#else
if (!dokany_mount(fs, mount_path))
{
Server->Log("Mounting fs " + url + " at \"" + mount_path + "\" failed", LL_ERROR);
}
#endif
});
dm.detach();

View File

@ -28,6 +28,7 @@
#include <memory>
#include <set>
#include <chrono>
#include <condition_variable>
using namespace std::chrono_literals;

View File

@ -20,6 +20,7 @@
#include "../fileservplugin/IFileServ.h"
#include "../urbackupcommon/chunk_hasher.h"
#include "../urbackupcommon/file_metadata.h"
#include "../common/data.h"
#include "../fileservplugin/IFileMetadataPipe.h"
#include "client.h"
#include "../Interface/BackupFileSystem.h"

View File

@ -45,6 +45,7 @@ struct SOwner
static bool getOwner(const std::string& fn, SOwner& owner)
{
#ifdef _WIN32
PSID newOwner = nullptr;
PSECURITY_DESCRIPTOR new_sec_d = nullptr;
DWORD rc = GetNamedSecurityInfoW(Server->ConvertToWchar(os_file_prefix(fn)).c_str(),
@ -65,6 +66,10 @@ static bool getOwner(const std::string& fn, SOwner& owner)
LocalFree(new_sec_d);
}
return rc == ERROR_SUCCESS;
#else
//TODO: Implement
return false;
#endif
}
#ifdef _WIN32
@ -116,6 +121,10 @@ HRESULT ModifyPrivilege(
static bool setOwner(const std::string& fn, const SOwner& owner)
{
#ifndef _WIN32
//TODO: Implement
return false;
#else
if (!owner.has_owner || owner.Owner == nullptr)
return false;
@ -129,6 +138,7 @@ static bool setOwner(const std::string& fn, const SOwner& owner)
NULL);
return rc == ERROR_SUCCESS;
#endif
}
static size_t zipWrite(void* pOpaque, mz_uint64 file_ofs, const void* pBuf, size_t n)

View File

@ -84,6 +84,7 @@ extern IServer* Server;
#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
#include "../common/miniz.h"
#include <vector>
#include <thread>
namespace
{

View File

@ -34,7 +34,6 @@ struct TokenCacheInt
};
TokenCache::TokenCache()
: token_cache(NULL)
{
}