diff --git a/.clang-tidy b/.clang-tidy index 2261a0486..5881a7c4c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -21,6 +21,7 @@ Checks: - modernize-* - -modernize-use-trailing-return-type - -modernize-macro-to-enum + # already covered by cppcoreguidelines-avoid-c-arrays - -modernize-avoid-c-arrays - performance-* - -performance-enum-size diff --git a/.docker/Dockerfile.alpine b/.docker/Dockerfile.alpine new file mode 100644 index 000000000..6fd1b9f37 --- /dev/null +++ b/.docker/Dockerfile.alpine @@ -0,0 +1,95 @@ +# syntax=docker/dockerfile:1 +ARG ARCH=amd64 +FROM $ARCH/alpine:latest +RUN apk update +RUN apk upgrade +RUN apk add --no-cache \ + bash-completion \ + build-base \ + wget \ + curl \ + vim \ + tar \ + ripgrep \ + py3-pip \ + less +RUN apk add --no-cache \ + gcc \ + g++ \ + clang17 \ + clang18 \ + clang19 \ + git \ + zstd \ + ccache \ + samurai \ + cmake \ + make \ + bison \ + flex \ + ronn \ + fuse \ + fuse-dev \ + fuse-static \ + fuse3 \ + fuse3-dev \ + fuse3-static \ + pkgconf \ + binutils-dev \ + acl-dev \ + acl-static \ + libarchive-dev \ + libarchive-static \ + boost1.84-dev \ + boost1.84-dev \ + boost1.84-static \ + brotli-dev \ + libevent-dev \ + libevent-static \ + date-dev \ + jemalloc-dev \ + jemalloc-static \ + double-conversion-dev \ + bzip2-dev \ + bzip2-static \ + xz-dev \ + xz-static \ + zstd-dev \ + zstd-static \ + xxhash-dev \ + lz4-dev \ + range-v3-dev \ + libxml2-dev \ + libxml2-static \ + zlib-static \ + libmagic-static \ + openssl-dev \ + openssl-libs-static \ + libunwind-dev \ + libunwind-static \ + libdwarf-dev \ + elfutils-dev \ + fmt-dev \ + glog-dev \ + utfcpp \ + flac-dev \ + libogg-static \ + icu-static \ + expat-static \ + nlohmann-json \ + meson \ + gdb + +ARG ARCH +RUN wget -O - https://github.com/upx/upx/releases/download/v5.0.0/upx-5.0.0-$(bash -c "echo \${0//v8/}" $ARCH)_linux.tar.xz | tar -xJf - -C /usr/local/bin --strip-components=1 --wildcards "*/upx" +RUN pip3 install --break-system-packages --root-user-action ignore mistletoe +RUN git config --global --add safe.directory /workspace +COPY install-mold.sh /usr/local/bin/install-mold.sh +RUN bash /usr/local/bin/install-mold.sh +COPY install-bloaty.sh /usr/local/bin/install-bloaty.sh +RUN bash /usr/local/bin/install-bloaty.sh +COPY install-static-libs.sh /usr/local/bin/install-static-libs.sh +RUN bash /usr/local/bin/install-static-libs.sh gcc clang-19 :alpine +RUN adduser -G users -s bash -u 1000 -D mhx +USER mhx +ENTRYPOINT /workspace/.docker/build-linux.sh diff --git a/.docker/Dockerfile.fedora b/.docker/Dockerfile.fedora index 951a63e3a..acc401fc1 100644 --- a/.docker/Dockerfile.fedora +++ b/.docker/Dockerfile.fedora @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 ARG ARCH=amd64 -FROM $ARCH/fedora:latest +FROM $ARCH/fedora:rawhide RUN dnf update -y RUN dnf install -y \ bash-completion \ diff --git a/.docker/Dockerfile.ubuntu b/.docker/Dockerfile.ubuntu index 4665fea58..6ec4fd818 100644 --- a/.docker/Dockerfile.ubuntu +++ b/.docker/Dockerfile.ubuntu @@ -72,9 +72,10 @@ RUN apt install -y \ libflac++-dev \ nlohmann-json3-dev \ python3-mistletoe -COPY install-static-libs.sh /usr/local/bin/install-static-libs.sh -# TODO: gcc-14 cannot build the current version of libunwind -RUN bash /usr/local/bin/install-static-libs.sh gcc-13 clang-18 +### XXX: no more static libs for Ubuntu +# COPY install-static-libs.sh /usr/local/bin/install-static-libs.sh +# # TODO: gcc-14 cannot build the current version of libunwind +# RUN bash /usr/local/bin/install-static-libs.sh gcc-13 clang-18 :ubuntu ARG ARCH # upx-4.2.2 is broken for arm64 (https://github.com/upx/upx/issues/758) RUN wget -O - https://github.com/upx/upx/releases/download/v5.0.0/upx-5.0.0-$(bash -c "echo \${0//v8/}" $ARCH)_linux.tar.xz | tar -xJf - -C /usr/local/bin --strip-components=1 --wildcards "*/upx" diff --git a/.docker/Makefile b/.docker/Makefile index 423edb37d..7b727af66 100644 --- a/.docker/Makefile +++ b/.docker/Makefile @@ -1,4 +1,5 @@ IMAGE_UBUNTU="dwarfs-buildenv" +IMAGE_ALPINE="dwarfs-buildenv-alpine" IMAGE_UBUNTU2204="dwarfs-buildenv-ubuntu2204" IMAGE_FEDORA="dwarfs-buildenv-fedora" IMAGE_ARCH="dwarfs-buildenv-arch" @@ -24,6 +25,12 @@ run: build_arm: docker build -f Dockerfile.ubuntu -t $(IMAGE_UBUNTU) --build-arg ARCH=arm64v8 . +build_alpine: + docker build -f Dockerfile.alpine -t $(IMAGE_ALPINE) . + +run_alpine: + @docker run $(COMMON_RUN_OPTS) $(IMAGE_ALPINE) + build_ubuntu2204: docker build -f Dockerfile.ubuntu-2204 -t $(IMAGE_UBUNTU2204) . diff --git a/.docker/build-linux.sh b/.docker/build-linux.sh index f3a322c32..c9eaca068 100755 --- a/.docker/build-linux.sh +++ b/.docker/build-linux.sh @@ -55,12 +55,16 @@ rm -rf build mkdir build cd build -if [[ "$BUILD_DIST" == "ubuntu-2204" ]]; then - GCC_VERSION=12 - CLANG_VERSION=15 +# Stick to clang-18, clang-19 has a regression for nilsimsa performance +if [[ "$BUILD_DIST" == "alpine" ]]; then + GCC_VERSION= + CLANG_VERSION=-19 +elif [[ "$BUILD_DIST" == "ubuntu-2204" ]]; then + GCC_VERSION=-12 + CLANG_VERSION=-15 else - GCC_VERSION=14 - CLANG_VERSION=18 + GCC_VERSION=-14 + CLANG_VERSION=-18 fi case "-$BUILD_TYPE-" in @@ -83,7 +87,7 @@ case "-$BUILD_TYPE-" in *-gcc-*) case "-$BUILD_DIST-" in *-ubuntu-*) - export CC=gcc-$GCC_VERSION CXX=g++-$GCC_VERSION + export CC=gcc$GCC_VERSION CXX=g++$GCC_VERSION ;; esac export COMPILER=gcc @@ -93,8 +97,8 @@ case "-$BUILD_TYPE-" in ;; *-clang-*) case "-$BUILD_DIST-" in - *-ubuntu-*) - export CC=clang-$CLANG_VERSION CXX=clang++-$CLANG_VERSION + *-ubuntu-*|*-alpine-*) + export CC=clang$CLANG_VERSION CXX=clang++$CLANG_VERSION ;; *) export CC=clang CXX=clang++ @@ -116,7 +120,26 @@ case "-$BUILD_TYPE-" in ;; *-release-*) CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_BUILD_TYPE=Release" - CMAKE_ARGS="${CMAKE_ARGS} -DWITH_BENCHMARKS=1" + if [[ "-$BUILD_TYPE-" != *-minimal-* ]]; then + CMAKE_ARGS="${CMAKE_ARGS} -DWITH_BENCHMARKS=1" + fi + if [[ "-$BUILD_TYPE-" == *-static-* ]]; then + export CFLAGS="-ffunction-sections -fdata-sections -fvisibility=hidden -fmerge-all-constants" + export CXXFLAGS="${CFLAGS}" + export LDFLAGS="-Wl,--gc-sections" + fi + ;; + *-relsize-*) + CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_BUILD_TYPE=MinSizeRel" + if [[ "-$BUILD_TYPE-" != *-minimal-* ]]; then + CMAKE_ARGS="${CMAKE_ARGS} -DWITH_BENCHMARKS=1" + fi + if [[ "-$BUILD_TYPE-" == *-static-* ]]; then + export CFLAGS="-ffunction-sections -fdata-sections -fvisibility=hidden -fmerge-all-constants" + export CXXFLAGS="${CFLAGS}" + export LDFLAGS="-Wl,--gc-sections" + fi + export COMPILER="${COMPILER}-minsize" ;; *-reldbg-*) CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo" @@ -126,6 +149,23 @@ case "-$BUILD_TYPE-" in exit 1 esac +case "-$BUILD_TYPE-" in + *-lto-*) + CMAKE_ARGS="${CMAKE_ARGS} -DDISABLE_MOLD=1" + export CFLAGS="${CFLAGS} -flto=auto" + export CXXFLAGS="${CXXFLAGS} -flto=auto" + export LDFLAGS="${LDFLAGS} -flto=auto" + export COMPILER="${COMPILER}-lto" + ;; +esac + +case "-$BUILD_TYPE-" in + *-minimal-*) + CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_PERFMON=0 -DWITH_MAN_OPTION=0 -DENABLE_RICEPP=0" + CMAKE_ARGS="${CMAKE_ARGS} -DTRY_ENABLE_BROTLI=0 -DTRY_ENABLE_LZ4=0 -DTRY_ENABLE_FLAC=0" + ;; +esac + case "-$BUILD_TYPE-" in *-asan-*) CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_ASAN=1" @@ -174,14 +214,35 @@ fi CMAKE_ARGS="${CMAKE_ARGS} -DDWARFS_ARTIFACTS_DIR=/artifacts" +SUFFIX="" + +if [[ "$BUILD_DIST" == "alpine" ]]; then + SUFFIX="-musl" + + if [[ "-$BUILD_TYPE-" == *-minimal-* ]]; then + SUFFIX="${SUFFIX}-minimal" + fi + + if [[ "-$BUILD_TYPE-" == *-lto-* ]]; then + SUFFIX="${SUFFIX}-lto" + fi +fi + +if [[ -n "$SUFFIX" ]]; then + CMAKE_ARGS="${CMAKE_ARGS} -DDWARFS_ARTIFACT_SUFFIX=$SUFFIX" +fi + if [[ "-$BUILD_TYPE-" == *-shared-* ]]; then CMAKE_ARGS="${CMAKE_ARGS} -DBUILD_SHARED_LIBS=1 -DCMAKE_POSITION_INDEPENDENT_CODE=1" fi if [[ "-$BUILD_TYPE-" == *-static-* ]]; then CMAKE_ARGS_NONSTATIC="${CMAKE_ARGS}" - export LDFLAGS="-L/opt/static-libs/$COMPILER/lib" - CMAKE_ARGS="${CMAKE_ARGS} -DSTATIC_BUILD_DO_NOT_USE=1 -DWITH_UNIVERSAL_BINARY=1 -DWITH_PXATTR=1" + export LDFLAGS="${LDFLAGS} -L/opt/static-libs/$COMPILER/lib" + CMAKE_ARGS="${CMAKE_ARGS} -DSTATIC_BUILD_DO_NOT_USE=1 -DWITH_UNIVERSAL_BINARY=1 -DWITH_FUSE_EXTRACT_BINARY=1" + if [[ "$BUILD_TYPE" != *-minimal-* ]]; then + CMAKE_ARGS="${CMAKE_ARGS} -DWITH_PXATTR=1" + fi CMAKE_ARGS="${CMAKE_ARGS} -DSTATIC_BUILD_EXTRA_PREFIX=/opt/static-libs/$COMPILER" fi @@ -251,8 +312,8 @@ else if [[ "-$BUILD_TYPE-" == *-coverage-* ]]; then rm -f /tmp-runner/dwarfs-coverage.txt - llvm-profdata-$CLANG_VERSION merge -sparse profile/* -o dwarfs.profdata - llvm-cov-$CLANG_VERSION show -instr-profile=dwarfs.profdata \ + llvm-profdata$CLANG_VERSION merge -sparse profile/* -o dwarfs.profdata + llvm-cov$CLANG_VERSION show -instr-profile=dwarfs.profdata \ $(for i in mkdwarfs dwarfs dwarfsck dwarfsextract *_test ricepp/ricepp_test; do echo $i; done | sed -e's/^/-object=/') \ >/tmp-runner/dwarfs-coverage.txt fi @@ -289,7 +350,10 @@ else $RUN_TESTS fi + fi + # for release and resize builds, strip the binaries + if [[ "-$BUILD_TYPE-" =~ -(release|relsize)- ]]; then $BUILD_TOOL strip fi diff --git a/.docker/check_lib_versions.py b/.docker/check_lib_versions.py new file mode 100755 index 000000000..12f6b8243 --- /dev/null +++ b/.docker/check_lib_versions.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +import requests + +# List of GitHub repositories in 'author/project' format +repositories = [ + "libarchive/libarchive", + "xiph/flac", + "libunwind/libunwind", + "google/benchmark", + "openssl/openssl", + "jeremy-rifkin/cpptrace", + "google/double-conversion", + "fmtlib/fmt", + "google/glog", + "Cyan4973/xxHash", + "lz4/lz4", + "google/brotli", + "facebook/zstd", + "libfuse/libfuse", +] + +# Function to fetch the latest release information for a repository +def get_latest_release(repo): + url = f"https://api.github.com/repos/{repo}/releases/latest" + response = requests.get(url) + + if response.status_code == 200: + release = response.json() + tag_name = release['tag_name'] + release_date = release['published_at'] + return tag_name, release_date + else: + print(f"Failed to fetch data for {repo}") + return None, None + +# Fetch the latest release information for each repository +for repo in repositories: + version, release_date = get_latest_release(repo) + if version and release_date: + [author, project] = repo.split('/') + date = release_date.split('T')[0] + version = version.replace(f"{project}-", "").lstrip('v') + project = project.replace('-', '_').upper() + version_var = f"{project}_VERSION={version}" + print(f"{version_var:<40} # {date}") diff --git a/.docker/install-bloaty.sh b/.docker/install-bloaty.sh new file mode 100644 index 000000000..aad8007e8 --- /dev/null +++ b/.docker/install-bloaty.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -ex + +cd "$HOME" +mkdir pkgs +cd pkgs + +git clone --recurse-submodules https://github.com/google/bloaty +cd bloaty +mkdir build +cd build + +cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local +ninja +ninja install + +cd "$HOME" +rm -rf pkgs diff --git a/.docker/install-mold.sh b/.docker/install-mold.sh new file mode 100644 index 000000000..533f21786 --- /dev/null +++ b/.docker/install-mold.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -ex + +cd "$HOME" +mkdir pkgs +cd pkgs + +MOLD_VERSION=2.37.1 + +wget -O mold-${MOLD_VERSION}.tar.gz https://github.com/rui314/mold/archive/refs/tags/v${MOLD_VERSION}.tar.gz +tar xf mold-${MOLD_VERSION}.tar.gz +cd mold-${MOLD_VERSION} +mkdir build +cd build + +cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local +ninja +ninja install + +cd "$HOME" +rm -rf pkgs diff --git a/.docker/install-static-libs.sh b/.docker/install-static-libs.sh index 31157e960..99fa01b62 100644 --- a/.docker/install-static-libs.sh +++ b/.docker/install-static-libs.sh @@ -8,53 +8,169 @@ cd pkgs GCC="${1:-gcc}" CLANG="${2:-clang}" - -echo "Using $GCC and $CLANG" +PKGS="${3:-:none}" FILE_VERSION=5.46 FILE_SHA512=a6cb7325c49fd4af159b7555bdd38149e48a5097207acbe5e36deb5b7493ad6ea94d703da6e0edece5bb32959581741f4213707e5cb0528cd46d75a97a5242dc BZIP2_VERSION=1.0.8 -LIBARCHIVE_VERSION=3.7.7 -FLAC_VERSION=1.5.0 + +LIBARCHIVE_VERSION=3.7.9 # 2025-03-30 +FLAC_VERSION=1.5.0 # 2025-02-11 # TODO: https://github.com/libunwind/libunwind/issues/702 -LIBUNWIND_VERSION=1.7.2 -BENCHMARK_VERSION=1.9.1 -OPENSSL_VERSION=3.0.16 -CPPTRACE_VERSION=0.8.2 - -RETRY=0 -while true; do - file_=file-${FILE_VERSION}.tar.gz - rm -f "$file_" - curl -o "$file_" "ftp://ftp.astron.com/pub/file/$file_" - if echo "${FILE_SHA512} $file_" | sha512sum -c; then - break - fi - RETRY=$((RETRY+1)) - if [ $RETRY -gt 10 ]; then - echo "Failed to download $file_" - exit 1 +LIBUNWIND_VERSION=1.7.2 # 2023-07-30 +BENCHMARK_VERSION=1.9.2 # 2025-03-25 +OPENSSL_VERSION=3.4.1 # 2025-02-11 +CPPTRACE_VERSION=0.8.2 # 2025-02-23 +DOUBLE_CONVERSION_VERSION=3.3.1 # 2025-02-14 +FMT_VERSION=11.1.4 # 2025-02-26 +GLOG_VERSION=0.7.1 # 2024-06-08 +XXHASH_VERSION=0.8.3 # 2024-12-30 +LZ4_VERSION=1.10.0 # 2024-07-22 +BROTLI_VERSION=1.1.0 # 2023-08-31 +ZSTD_VERSION=1.5.7 # 2025-02-19 +LIBFUSE_VERSION=3.17.1 # 2025-03-24 + +echo "Using $GCC and $CLANG" + +if [[ "$PKGS" == ":ubuntu" ]]; then + PKGS="file,bzip2,libarchive,flac,libunwind,benchmark,openssl,cpptrace" + COMPILERS="clang gcc" +elif [[ "$PKGS" == ":alpine" ]]; then + PKGS="benchmark,brotli,cpptrace,double-conversion,flac,fmt,fuse,glog,libarchive,lz4,openssl,xxhash,zstd" + export COMMON_CFLAGS="-ffunction-sections -fdata-sections -fmerge-all-constants" + export COMMON_CXXFLAGS="$COMMON_CFLAGS" + COMPILERS="clang clang-lto clang-minsize-lto gcc" +elif [[ "$PKGS" == ":none" ]]; then + echo "No libraries to build" + exit 0 +fi + +FILE_TARBALL="file-${FILE_VERSION}.tar.gz" +BZIP2_TARBALL="bzip2-${BZIP2_VERSION}.tar.gz" +LIBARCHIVE_TARBALL="libarchive-${LIBARCHIVE_VERSION}.tar.xz" +FLAC_TARBALL="flac-${FLAC_VERSION}.tar.xz" +LIBUNWIND_TARBALL="libunwind-${LIBUNWIND_VERSION}.tar.gz" +BENCHMARK_TARBALL="benchmark-${BENCHMARK_VERSION}.tar.gz" +OPENSSL_TARBALL="openssl-${OPENSSL_VERSION}.tar.gz" +CPPTRACE_TARBALL="cpptrace-${CPPTRACE_VERSION}.tar.gz" +DOUBLE_CONVERSION_TARBALL="double-conversion-${DOUBLE_CONVERSION_VERSION}.tar.gz" +FMT_TARBALL="fmt-${FMT_VERSION}.tar.gz" +GLOG_TARBALL="glog-${GLOG_VERSION}.tar.gz" +XXHASH_TARBALL="xxHash-${XXHASH_VERSION}.tar.gz" +LZ4_TARBALL="lz4-${LZ4_VERSION}.tar.gz" +BROTLI_TARBALL="brotli-${BROTLI_VERSION}.tar.gz" +ZSTD_TARBALL="zstd-${ZSTD_VERSION}.tar.gz" +LIBFUSE_TARBALL="fuse-${LIBFUSE_VERSION}.tar.gz" + +use_lib() { + local lib="$1" + if [[ ",$PKGS," == *",$lib,"* ]]; then + return 0 + else + return 1 fi -done +} + +if use_lib file; then + RETRY=0 + while true; do + rm -f "$FILE_TARBALL" + curl -o "$FILE_TARBALL" "ftp://ftp.astron.com/pub/file/$FILE_TARBALL" + if echo "${FILE_SHA512} $FILE_TARBALL" | sha512sum -c; then + break + fi + RETRY=$((RETRY+1)) + if [ $RETRY -gt 10 ]; then + echo "Failed to download $FILE_TARBALL" + exit 1 + fi + done +fi + +fetch_lib() { + local lib="$1" + local url="$2" + local tarball="${3:-${url##*/}}" + if use_lib "$lib"; then + wget -O "$tarball" "$url" + fi +} + +fetch_lib bzip2 https://sourceware.org/pub/bzip2/${BZIP2_TARBALL} +fetch_lib libarchive https://github.com/libarchive/libarchive/releases/download/v${LIBARCHIVE_VERSION}/${LIBARCHIVE_TARBALL} +fetch_lib flac https://github.com/xiph/flac/releases/download/${FLAC_VERSION}/${FLAC_TARBALL} +fetch_lib libunwind https://github.com/libunwind/libunwind/releases/download/v${LIBUNWIND_VERSION}/${LIBUNWIND_TARBALL} +fetch_lib benchmark https://github.com/google/benchmark/archive/refs/tags/v${BENCHMARK_VERSION}.tar.gz ${BENCHMARK_TARBALL} +fetch_lib openssl https://github.com/openssl/openssl/releases/download/openssl-${OPENSSL_VERSION}/${OPENSSL_TARBALL} +fetch_lib cpptrace https://github.com/jeremy-rifkin/cpptrace/archive/refs/tags/v${CPPTRACE_VERSION}.tar.gz ${CPPTRACE_TARBALL} +fetch_lib double-conversion https://github.com/google/double-conversion/archive/refs/tags/v${DOUBLE_CONVERSION_VERSION}.tar.gz ${DOUBLE_CONVERSION_TARBALL} +fetch_lib fmt https://github.com/fmtlib/fmt/archive/refs/tags/${FMT_VERSION}.tar.gz ${FMT_TARBALL} +fetch_lib glog https://github.com/google/glog/archive/refs/tags/v${GLOG_VERSION}.tar.gz ${GLOG_TARBALL} +fetch_lib xxhash https://github.com/Cyan4973/xxHash/archive/refs/tags/v${XXHASH_VERSION}.tar.gz ${XXHASH_TARBALL} +fetch_lib lz4 https://github.com/lz4/lz4/releases/download/v${LZ4_VERSION}/${LZ4_TARBALL} +fetch_lib brotli https://github.com/google/brotli/archive/refs/tags/v${BROTLI_VERSION}.tar.gz ${BROTLI_TARBALL} +fetch_lib zstd https://github.com/facebook/zstd/releases/download/v${ZSTD_VERSION}/${ZSTD_TARBALL} +fetch_lib fuse https://github.com/libfuse/libfuse/releases/download/fuse-${LIBFUSE_VERSION}/${LIBFUSE_TARBALL} -wget https://sourceware.org/pub/bzip2/bzip2-${BZIP2_VERSION}.tar.gz -wget https://github.com/libarchive/libarchive/releases/download/v${LIBARCHIVE_VERSION}/libarchive-${LIBARCHIVE_VERSION}.tar.xz -wget https://github.com/xiph/flac/releases/download/${FLAC_VERSION}/flac-${FLAC_VERSION}.tar.xz -wget https://github.com/libunwind/libunwind/releases/download/v${LIBUNWIND_VERSION}/libunwind-${LIBUNWIND_VERSION}.tar.gz -wget https://github.com/google/benchmark/archive/refs/tags/v${BENCHMARK_VERSION}.tar.gz -wget https://github.com/openssl/openssl/releases/download/openssl-${OPENSSL_VERSION}/openssl-${OPENSSL_VERSION}.tar.gz -wget https://github.com/jeremy-rifkin/cpptrace/archive/refs/tags/v${CPPTRACE_VERSION}.tar.gz - -for COMPILER in clang gcc; do - if [[ "$COMPILER" == "clang" ]]; then - export CC="$CLANG" - export CXX="${CLANG/clang/clang++}" - elif [[ "$COMPILER" == "gcc" ]]; then - export CC="$GCC" - export CXX="${GCC/gcc/g++}" +for COMPILER in $COMPILERS; do + export CFLAGS="$COMMON_CFLAGS" + export CXXFLAGS="$COMMON_CXXFLAGS" + export LDFLAGS="$COMMON_LDFLAGS" + + case "$COMPILER" in + clang*) + export CC="$CLANG" + export CXX="${CLANG/clang/clang++}" + ;; + gcc*) + export CC="$GCC" + export CXX="${GCC/gcc/g++}" + ;; + *) + echo "Unknown compiler: $COMPILER" + exit 1 + ;; + esac + + case "-$COMPILER-" in + *-minsize-*) + export CFLAGS="$CFLAGS -Os" + export CXXFLAGS="$CXXFLAGS -Os" + ;; + esac + + case "$COMPILER" in + *-lto) + export CFLAGS="$CFLAGS -flto" + export CXXFLAGS="$CXXFLAGS -flto" + export LDFLAGS="$LDFLAGS -flto" + ;; + *-lto-thin) + export CFLAGS="$CFLAGS -flto=thin" + export CXXFLAGS="$CXXFLAGS -flto=thin" + export LDFLAGS="$LDFLAGS -flto=thin" + ;; + esac + + if [[ $CFLAGS =~ ^[[:space:]]*$ ]]; then + echo "unsetting CFLAGS" + unset CFLAGS + else + echo "setting CFLAGS: $CFLAGS" + fi + + if [[ $CXXFLAGS =~ ^[[:space:]]*$ ]]; then + echo "unsetting CXXFLAGS" + unset CXXFLAGS else - echo "Unknown compiler: $COMPILER" - exit 1 + echo "setting CXXFLAGS: $CXXFLAGS" + fi + + if [[ $LDFLAGS =~ ^[[:space:]]*$ ]]; then + echo "unsetting LDFLAGS" + unset LDFLAGS + else + echo "setting LDFLAGS: $LDFLAGS" fi cd "$HOME/pkgs" @@ -62,64 +178,172 @@ for COMPILER in clang gcc; do INSTALL_DIR=/opt/static-libs/$COMPILER - cd "$HOME/pkgs/$COMPILER" - tar xf ../libunwind-${LIBUNWIND_VERSION}.tar.gz - cd libunwind-${LIBUNWIND_VERSION} - ./configure --prefix="$INSTALL_DIR" - make -j$(nproc) - make install - - cd "$HOME/pkgs/$COMPILER" - tar xf ../bzip2-${BZIP2_VERSION}.tar.gz - cd bzip2-${BZIP2_VERSION} - make -j$(nproc) - make PREFIX="$INSTALL_DIR" install - - cd "$HOME/pkgs/$COMPILER" - tar xf ../openssl-${OPENSSL_VERSION}.tar.gz - cd openssl-${OPENSSL_VERSION} - ./Configure --prefix="$INSTALL_DIR" --libdir=lib threads no-fips no-shared no-pic no-dso - make -j$(nproc) - make install_sw - - cd "$HOME/pkgs/$COMPILER" - tar xf ../libarchive-${LIBARCHIVE_VERSION}.tar.xz - cd libarchive-${LIBARCHIVE_VERSION} - ./configure --prefix="$INSTALL_DIR" --without-iconv --without-xml2 --without-expat - make -j$(nproc) - make install - - cd "$HOME/pkgs/$COMPILER" - tar xf ../file-${FILE_VERSION}.tar.gz - cd file-${FILE_VERSION} - ./configure --prefix="$INSTALL_DIR" --enable-static=yes --enable-shared=no - make -j$(nproc) - make install - - cd "$HOME/pkgs/$COMPILER" - tar xf ../flac-${FLAC_VERSION}.tar.xz - cd flac-${FLAC_VERSION} - ./configure --prefix="$INSTALL_DIR" --enable-static=yes --enable-shared=no --disable-doxygen-docs --disable-ogg --disable-programs --disable-examples - make -j$(nproc) - make install - - cd "$HOME/pkgs/$COMPILER" - tar xf ../v${BENCHMARK_VERSION}.tar.gz - cd benchmark-${BENCHMARK_VERSION} - mkdir build - cd build - cmake .. -DBENCHMARK_ENABLE_TESTING=OFF -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" - make -j$(nproc) - make install - - cd "$HOME/pkgs/$COMPILER" - tar xf ../v${CPPTRACE_VERSION}.tar.gz - cd cpptrace-${CPPTRACE_VERSION} - mkdir build - cd build - cmake .. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" - make -j$(nproc) - make install + if use_lib fuse; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${LIBFUSE_TARBALL} + cd fuse-${LIBFUSE_VERSION} + mkdir build + cd build + meson setup .. --default-library=static --prefix="$INSTALL_DIR" + meson configure -D utils=false -D tests=false -D examples=false + meson setup --reconfigure .. + ninja + ninja install + fi + + if use_lib zstd; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${ZSTD_TARBALL} + cd zstd-${ZSTD_VERSION} + make -j$(nproc) + make install PREFIX="$INSTALL_DIR" + fi + + if use_lib libunwind; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${LIBUNWIND_TARBALL} + cd libunwind-${LIBUNWIND_VERSION} + ./configure --prefix="$INSTALL_DIR" + make -j$(nproc) + make install + fi + + if use_lib bzip2; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${BZIP2_TARBALL} + cd bzip2-${BZIP2_VERSION} + make -j$(nproc) + make PREFIX="$INSTALL_DIR" install + fi + + if use_lib openssl; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${OPENSSL_TARBALL} + cd openssl-${OPENSSL_VERSION} + ./Configure --prefix="$INSTALL_DIR" --libdir=lib threads no-fips no-shared no-pic no-dso no-aria no-async no-atexit \ + no-autoload-config no-blake2 no-bf no-camellia no-cast no-chacha no-cmac no-cms no-cmp no-comp no-ct no-des \ + no-dgram no-dh no-dsa no-ec no-engine no-filenames no-idea no-ktls no-md4 no-multiblock \ + no-nextprotoneg no-ocsp no-ocb no-poly1305 no-psk no-rc2 no-rc4 no-seed no-siphash no-siv no-sm3 no-sm4 \ + no-srp no-srtp no-ssl3-method no-ssl-trace no-tfo no-ts no-ui-console no-whirlpool no-fips-securitychecks \ + no-tests no-docs + + make -j$(nproc) + make install_sw + fi + + if use_lib libarchive; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${LIBARCHIVE_TARBALL} + cd libarchive-${LIBARCHIVE_VERSION} + # TODO: once DwarFS supports ACLs / xattrs, we need to update this + ./configure --prefix="$INSTALL_DIR" --without-iconv --without-xml2 --without-expat --without-openssl \ + --without-bz2lib --without-zlib --disable-acl --disable-xattr + make -j$(nproc) + make install + fi + + if use_lib file; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${FILE_TARBALL} + cd file-${FILE_VERSION} + ./configure --prefix="$INSTALL_DIR" --enable-static=yes --enable-shared=no + make -j$(nproc) + make install + fi + + if use_lib flac; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${FLAC_TARBALL} + cd flac-${FLAC_VERSION} + ./configure --prefix="$INSTALL_DIR" --enable-static=yes --enable-shared=no --disable-doxygen-docs --disable-ogg --disable-programs --disable-examples + make -j$(nproc) + make install + fi + + if use_lib benchmark; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${BENCHMARK_TARBALL} + cd benchmark-${BENCHMARK_VERSION} + mkdir build + cd build + cmake .. -DBENCHMARK_ENABLE_TESTING=OFF -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" + make -j$(nproc) + make install + fi + + if use_lib cpptrace; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${CPPTRACE_TARBALL} + cd cpptrace-${CPPTRACE_VERSION} + mkdir build + cd build + cmake .. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" + make -j$(nproc) + make install + fi + + if use_lib double-conversion; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${DOUBLE_CONVERSION_TARBALL} + cd double-conversion-${DOUBLE_CONVERSION_VERSION} + mkdir build + cd build + cmake .. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DBUILD_SHARED_LIBS=OFF + make -j$(nproc) + make install + fi + + if use_lib fmt; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${FMT_TARBALL} + cd fmt-${FMT_VERSION} + mkdir build + cd build + cmake .. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DBUILD_SHARED_LIBS=OFF -DFMT_DOC=OFF -DFMT_TEST=OFF + make -j$(nproc) + make install + fi + + if use_lib glog; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${GLOG_TARBALL} + cd glog-${GLOG_VERSION} + mkdir build + cd build + cmake .. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DBUILD_SHARED_LIBS=OFF + make -j$(nproc) + make install + fi + + if use_lib xxhash; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${XXHASH_TARBALL} + cd xxHash-${XXHASH_VERSION} + make -j$(nproc) + make install PREFIX="$INSTALL_DIR" + fi + + if use_lib brotli; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${BROTLI_TARBALL} + cd brotli-${BROTLI_VERSION} + mkdir build + cd build + cmake .. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DBUILD_SHARED_LIBS=OFF + make -j$(nproc) + make install + fi + + if use_lib lz4; then + cd "$HOME/pkgs/$COMPILER" + tar xf ../${LZ4_TARBALL} + cd lz4-${LZ4_VERSION}/build/cmake + mkdir build + cd build + cmake .. -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON + make -j$(nproc) + make install + fi done cd "$HOME" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 72a9d0077..2ce28de13 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -183,19 +183,19 @@ jobs: - arch: amd64 dist: ubuntu build_type: oldgcc-debug-shared-make-split - - arch: arm64v8 + - arch: amd64 dist: ubuntu build_type: gcc-debug-shared-noperfmon-ninja-split - - arch: arm64v8 + - arch: amd64 dist: ubuntu build_type: oldclang-debug-shared-make-split - - arch: arm64v8 + - arch: amd64 dist: ubuntu-2204 build_type: gcc-release-shared-ninja-split - - arch: arm64v8 + - arch: amd64 dist: ubuntu-2204 build_type: gcc-debug-shared-ninja-full - - arch: arm64v8 + - arch: amd64 dist: ubuntu-2204 build_type: clang-release-ninja-split @@ -256,7 +256,7 @@ jobs: build_type: - gcc-release-shared-ninja exclude: - - arch: amd64 + - arch: arm64v8 dist: ubuntu build_type: gcc-release-shared-ninja - arch: amd64 @@ -278,48 +278,96 @@ jobs: - arch: amd64 dist: ubuntu build_type: clang-debug-coverage-ninja + # - arch: amd64 + # dist: ubuntu + # build_type: gcc-release-ninja-static + # - arch: arm64v8 + # dist: ubuntu + # build_type: gcc-release-ninja-static + # - arch: amd64 + # dist: ubuntu + # build_type: gcc-release-ninja-O2-static + # - arch: arm64v8 + # dist: ubuntu + # build_type: gcc-release-ninja-O2-static + # - arch: amd64 + # dist: ubuntu + # build_type: clang-release-stacktrace-ninja-static + # - arch: arm64v8 + # dist: ubuntu + # build_type: clang-release-stacktrace-ninja-static + # - arch: amd64 + # dist: ubuntu + # build_type: clang-release-ninja-static + # - arch: arm64v8 + # dist: ubuntu + # build_type: clang-release-ninja-static + # - arch: amd64 + # dist: ubuntu + # build_type: clang-release-ninja-O2-static + # - arch: arm64v8 + # dist: ubuntu + # build_type: clang-release-ninja-O2-static + # - arch: amd64 + # dist: ubuntu + # build_type: clang-reldbg-stacktrace-ninja-static + # - arch: arm64v8 + # dist: ubuntu + # build_type: clang-reldbg-stacktrace-ninja-static + # - arch: amd64 + # dist: ubuntu + # build_type: clang-debug-stacktrace-ninja-static + # - arch: arm64v8 + # dist: ubuntu + # build_type: clang-debug-stacktrace-ninja-static - arch: amd64 - dist: ubuntu + dist: alpine build_type: gcc-release-ninja-static - arch: arm64v8 - dist: ubuntu + dist: alpine build_type: gcc-release-ninja-static - arch: amd64 - dist: ubuntu - build_type: gcc-release-ninja-O2-static + dist: alpine + build_type: clang-release-ninja-static - arch: arm64v8 - dist: ubuntu - build_type: gcc-release-ninja-O2-static + dist: alpine + build_type: clang-release-ninja-static + # - arch: amd64 + # dist: alpine + # build_type: clang-relsize-ninja-static + # - arch: arm64v8 + # dist: alpine + # build_type: clang-relsize-ninja-static + # - arch: amd64 + # dist: alpine + # build_type: gcc-release-lto-ninja-static + # - arch: arm64v8 + # dist: alpine + # build_type: gcc-release-lto-ninja-static - arch: amd64 - dist: ubuntu - build_type: clang-release-stacktrace-ninja-static + dist: alpine + build_type: clang-release-lto-ninja-static - arch: arm64v8 - dist: ubuntu - build_type: clang-release-stacktrace-ninja-static + dist: alpine + build_type: clang-release-lto-ninja-static - arch: amd64 - dist: ubuntu - build_type: clang-release-ninja-static + dist: alpine + build_type: clang-relsize-lto-ninja-static - arch: arm64v8 - dist: ubuntu - build_type: clang-release-ninja-static + dist: alpine + build_type: clang-relsize-lto-ninja-static - arch: amd64 - dist: ubuntu - build_type: clang-release-ninja-O2-static + dist: alpine + build_type: clang-relsize-minimal-lto-ninja-static - arch: arm64v8 - dist: ubuntu - build_type: clang-release-ninja-O2-static + dist: alpine + build_type: clang-relsize-minimal-lto-ninja-static - arch: amd64 - dist: ubuntu + dist: alpine build_type: clang-reldbg-stacktrace-ninja-static - arch: arm64v8 - dist: ubuntu + dist: alpine build_type: clang-reldbg-stacktrace-ninja-static - - arch: amd64 - dist: ubuntu - build_type: clang-debug-stacktrace-ninja-static - - arch: arm64v8 - dist: ubuntu - build_type: clang-debug-stacktrace-ninja-static runs-on: - self-hosted diff --git a/.gitmodules b/.gitmodules index 00dc232c1..4f8d2a175 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "folly"] path = folly - url = https://github.com/facebook/folly + url = https://github.com/mhx/folly [submodule "fbthrift"] path = fbthrift url = https://github.com/facebook/fbthrift diff --git a/CHANGES.md b/CHANGES.md index 8a0520ca8..3279477af 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,52 @@ # Change Log +## Version 0.12.0 - 2025-04-08 + +- (fix) Build release binaries against an up-to-date `libfuse`. + Fixes github #252. + +- (fix) Changes for compatibility with Boost.Process v2. + +- (feature) Re-licensed all libraries required for *reading* DwarFS + images under the MIT license. The source of all tools that just + *read* DwarFS images (i.e. everything except for `mkdwarfs`) are + also under the MIT license now. Everything else is still GPL-3.0. + Addresses github #255. + +- (feature) Significantly reduced binary size in the static release + builds. This is the result of refactoring code that unconditionally + pulled in code-heavy dependencies such as `libcrypto`, as well as + optimizing the build pipeline (e.g. building dependencies with only + the necessary set of features) and turning on link time optimization. + +- (feature) A new kind of "universal" binary `dwarfs-fuse-extract` is + part of the release now. This combines the FUSE driver (`dwarfs`) + and `dwarfsextract` into a single binary, but does not include the + `mkdwarfs` and `dwarfsck` tools that are also part of the regular + universal binary. `dwarfs-fuse-extract` is much smaller than the + regular universal binary and especially suitable to AppImage-like + applications. + +- (feature) New `hotness` categorizer in `mkdwarfs` that allows a list + of "hot" files to be stored in distinct file system blocks. + +- (feature) New `explicit` ordering mode in `mkdwarfs` that allows + files to be ordered accoring to the order in a given list file. + +- (feature) `dwarfs` now shows the version of the FUSE library used. + +- (feature) New `dwarfs` options `preload_all` and `preload_category` + to populate the block cache immediately after mounting. + +- (feature) New `dwarfs` option `analysis_file` that can be used for + profiling and as input to `mkdwarfs` new `hotness` categorizer and + `explicit` ordering mode. + +- (feature) New `dwarfs` option `block_allocator` that allows the user + to switch from a `malloc`-based block allocator to an `mmap`-based + one. This can help with returning memory back to the system if the + blocks are evicted from the cache. + ## Version 0.11.3 - 2025-03-31 - (fix) Handle absolute paths in `--input-list`. Fixes github #259. diff --git a/CMakeLists.txt b/CMakeLists.txt index 35a5989a9..6fa0ea1a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,11 @@ option(WITH_MAN_OPTION "build with --man option" ON) option(ENABLE_PERFMON "enable performance monitor in all tools" ON) option(TRY_ENABLE_FLAC "build with FLAC support" ON) option(ENABLE_RICEPP "build with RICEPP compression support" ON) +option(TRY_ENABLE_BROTLI "build with BROTLI compression support" ON) +option(TRY_ENABLE_LZ4 "build with LZ4 compression support" ON) +option(TRY_ENABLE_LZMA "build with LZMA compression support" ON) option(WITH_UNIVERSAL_BINARY "build with universal binary" OFF) +option(WITH_FUSE_EXTRACT_BINARY "build with fuse-extract binary" OFF) option(WITH_PXATTR "build with pxattr binary" OFF) option(WITH_EXAMPLE "build with example binary" OFF) option(ENABLE_STACKTRACE "build with stack trace support" OFF) @@ -205,10 +209,16 @@ if(WITH_LIBDWARFS) pkg_check_modules(LIBARCHIVE REQUIRED IMPORTED_TARGET libarchive>=${LIBARCHIVE_REQUIRED_VERSION}) pkg_check_modules(XXHASH REQUIRED IMPORTED_TARGET libxxhash>=${XXHASH_REQUIRED_VERSION}) pkg_check_modules(ZSTD REQUIRED IMPORTED_TARGET libzstd>=${ZSTD_REQUIRED_VERSION}) - pkg_check_modules(LIBLZ4 IMPORTED_TARGET liblz4>=${LIBLZ4_REQUIRED_VERSION}) - pkg_check_modules(LIBLZMA IMPORTED_TARGET liblzma>=${LIBLZMA_REQUIRED_VERSION}) - pkg_check_modules(LIBBROTLIDEC IMPORTED_TARGET libbrotlidec>=${LIBBROTLI_REQUIRED_VERSION}) - pkg_check_modules(LIBBROTLIENC IMPORTED_TARGET libbrotlienc>=${LIBBROTLI_REQUIRED_VERSION}) + if(TRY_ENABLE_LZ4) + pkg_check_modules(LIBLZ4 IMPORTED_TARGET liblz4>=${LIBLZ4_REQUIRED_VERSION}) + endif() + if(TRY_ENABLE_LZMA) + pkg_check_modules(LIBLZMA IMPORTED_TARGET liblzma>=${LIBLZMA_REQUIRED_VERSION}) + endif() + if(TRY_ENABLE_BROTLI) + pkg_check_modules(LIBBROTLIDEC IMPORTED_TARGET libbrotlidec>=${LIBBROTLI_REQUIRED_VERSION}) + pkg_check_modules(LIBBROTLIENC IMPORTED_TARGET libbrotlienc>=${LIBBROTLI_REQUIRED_VERSION}) + endif() # pkg_check_modules(LIBMAGIC IMPORTED_TARGET libmagic>=${LIBMAGIC_REQUIRED_VERSION}) if(TRY_ENABLE_FLAC) pkg_check_modules(FLAC IMPORTED_TARGET flac++>=${FLAC_REQUIRED_VERSION}) @@ -282,11 +292,36 @@ if(WITH_TOOLS) add_executable(dwarfsuniversal tools/src/universal.cpp) list(APPEND BINARY_TARGETS dwarfsuniversal) + target_compile_definitions(dwarfsuniversal PRIVATE + DWARFS_UNIVERSAL_NAME=\"dwarfs-universal\" + DWARFS_UNIVERSAL_MKDWARFS + DWARFS_UNIVERSAL_DWARFSCK + DWARFS_UNIVERSAL_DWARFSEXTRACT + ) target_link_libraries(dwarfsuniversal PRIVATE - mkdwarfs_main dwarfsck_main dwarfsextract_main) + mkdwarfs_main dwarfsck_main dwarfsextract_main + ) set_target_properties(dwarfsuniversal PROPERTIES RUNTIME_OUTPUT_DIRECTORY universal - OUTPUT_NAME dwarfs-universal) + OUTPUT_NAME dwarfs-universal + ) + endif() + + if(WITH_FUSE_EXTRACT_BINARY) + add_executable(dwarfsfuseextract tools/src/universal.cpp) + list(APPEND BINARY_TARGETS dwarfsfuseextract) + + target_compile_definitions(dwarfsfuseextract PRIVATE + DWARFS_UNIVERSAL_NAME=\"dwarfs-fuse-extract\" + DWARFS_UNIVERSAL_DWARFSEXTRACT + ) + target_link_libraries(dwarfsfuseextract PRIVATE + dwarfsextract_main + ) + set_target_properties(dwarfsfuseextract PROPERTIES + RUNTIME_OUTPUT_DIRECTORY universal + OUTPUT_NAME dwarfs-fuse-extract + ) endif() endif() @@ -321,9 +356,15 @@ if(WITH_FUSE_DRIVER) target_link_libraries(dwarfs_main PRIVATE ${WINFSP}) target_link_libraries(dwarfs-bin PRIVATE delayimp.lib) target_link_options(dwarfs-bin PRIVATE /DELAYLOAD:winfsp-x64.dll) - if(WITH_UNIVERSAL_BINARY) + if(TARGET dwarfsuniversal) target_link_libraries(dwarfsuniversal PRIVATE delayimp.lib) target_link_options(dwarfsuniversal PRIVATE /DELAYLOAD:winfsp-x64.dll) + target_compile_definitions(dwarfsuniversal PRIVATE DWARFS_UNIVERSAL_FUSE_DRIVER) + endif() + if(TARGET dwarfsfuseextract) + target_link_libraries(dwarfsfuseextract PRIVATE delayimp.lib) + target_link_options(dwarfsfuseextract PRIVATE /DELAYLOAD:winfsp-x64.dll) + target_compile_definitions(dwarfsfuseextract PRIVATE DWARFS_UNIVERSAL_FUSE_DRIVER) endif() elseif(APPLE) target_compile_definitions(dwarfs_main PRIVATE FUSE_USE_VERSION=29) @@ -332,8 +373,13 @@ if(WITH_FUSE_DRIVER) target_compile_definitions(dwarfs_main PRIVATE FUSE_USE_VERSION=35) target_link_libraries(dwarfs_main PRIVATE PkgConfig::FUSE3) endif() - if(WITH_UNIVERSAL_BINARY) + if(TARGET dwarfsuniversal) target_link_libraries(dwarfsuniversal PRIVATE dwarfs_main) + target_compile_definitions(dwarfsuniversal PRIVATE DWARFS_UNIVERSAL_FUSE_DRIVER) + endif() + if(TARGET dwarfsfuseextract) + target_link_libraries(dwarfsfuseextract PRIVATE dwarfs_main) + target_compile_definitions(dwarfsfuseextract PRIVATE DWARFS_UNIVERSAL_FUSE_DRIVER) endif() if(WINFSP) install(TARGETS dwarfs-bin RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -358,8 +404,13 @@ if(WITH_FUSE_DRIVER) target_link_libraries(dwarfs2_main PRIVATE PkgConfig::FUSE) add_executable(dwarfs2-bin tools/src/dwarfs.cpp) target_link_libraries(dwarfs2-bin PRIVATE dwarfs2_main) - if(WITH_UNIVERSAL_BINARY AND (NOT FUSE3_FOUND)) + if(TARGET dwarfsuniversal AND (NOT FUSE3_FOUND)) target_link_libraries(dwarfsuniversal PRIVATE dwarfs2_main) + target_compile_definitions(dwarfsuniversal PRIVATE DWARFS_UNIVERSAL_FUSE_DRIVER) + endif() + if(TARGET dwarfsfuseextract AND (NOT FUSE3_FOUND)) + target_link_libraries(dwarfsfuseextract PRIVATE dwarfs2_main) + target_compile_definitions(dwarfsfuseextract PRIVATE DWARFS_UNIVERSAL_FUSE_DRIVER) endif() set_target_properties(dwarfs2-bin PROPERTIES OUTPUT_NAME dwarfs2) add_custom_command(OUTPUT mount.dwarfs2 @@ -440,6 +491,7 @@ if(WITH_TESTS) integral_value_parser_test lazy_value_test metadata_requirements_test + nilsimsa_test options_test packed_int_vector_test packed_ptr_test @@ -579,15 +631,19 @@ if(WITH_LIBDWARFS AND WITH_BENCHMARKS) add_executable(sorted_array_map_benchmark test/sorted_array_map_benchmark.cpp) target_link_libraries(sorted_array_map_benchmark PRIVATE benchmark::benchmark) list(APPEND BENCHMARK_TARGETS sorted_array_map_benchmark) - endif() - # TODO: migrate to benchmark? - add_executable(segmenter_benchmark test/segmenter_benchmark.cpp) - target_link_libraries(segmenter_benchmark PRIVATE dwarfs_follybenchmark_lite dwarfs_test_helpers) - target_link_libraries(segmenter_benchmark PRIVATE dwarfs_writer) - list(APPEND BENCHMARK_TARGETS segmenter_benchmark) + add_executable(nilsimsa_benchmark test/nilsimsa_benchmark.cpp) + target_link_libraries(nilsimsa_benchmark PRIVATE benchmark::benchmark) + target_link_libraries(nilsimsa_benchmark PRIVATE dwarfs_writer) + list(APPEND BENCHMARK_TARGETS nilsimsa_benchmark) - list(APPEND BINARY_TARGETS ${BENCHMARK_TARGETS}) + add_executable(segmenter_benchmark test/segmenter_benchmark.cpp) + target_link_libraries(segmenter_benchmark PRIVATE dwarfs_test_helpers benchmark::benchmark) + target_link_libraries(segmenter_benchmark PRIVATE dwarfs_writer) + list(APPEND BENCHMARK_TARGETS segmenter_benchmark) + + list(APPEND BINARY_TARGETS ${BENCHMARK_TARGETS}) + endif() endif() if(WITH_LIBDWARFS AND WITH_FUZZ) @@ -808,29 +864,25 @@ if(STATIC_BUILD_DO_NOT_USE) import_static_lib(static_libglog "libglog.a") import_static_lib(static_libdoubleconv "libdouble-conversion.a") import_static_lib(static_libgflags "libgflags.a") - import_static_lib(static_libevent "libevent.a") - import_static_lib(static_libacl "libacl.a") - import_static_lib(static_libxml2 "libxml2.a") import_static_lib(static_libcrypto "libcrypto.a") import_static_lib(static_libz "libz.a") import_static_lib(static_libpthread "libpthread.a") import_static_lib(static_libdl "libdl.a") import_static_lib(static_libm "libm.a") import_static_lib(static_librt "librt.a") - import_static_lib(static_libssl "libssl.a") import_static_lib(static_libunwind "libunwind.a") import_static_lib(static_libarchive "libarchive.a") - import_static_lib(static_libmagic "libmagic.a") import_static_lib(static_libflac "libFLAC++.a") set_target_properties(static_libunwind PROPERTIES INTERFACE_LINK_LIBRARIES "${LIBLZMA_LIBRARIES};static_libz") set_target_properties(static_libglog PROPERTIES INTERFACE_LINK_LIBRARIES static_libgflags) - set_target_properties(static_librt PROPERTIES INTERFACE_LINK_LIBRARIES - static_libgflags) - set_target_properties(static_libmagic PROPERTIES INTERFACE_LINK_LIBRARIES - static_libz) + if(LIBMAGIC_FOUND) + import_static_lib(static_libmagic "libmagic.a") + set_target_properties(static_libmagic PROPERTIES INTERFACE_LINK_LIBRARIES + static_libz) + endif() foreach(tgt ${BINARY_TARGETS} ${TEST_TARGETS}) # ................................................................... @@ -844,9 +896,6 @@ if(STATIC_BUILD_DO_NOT_USE) static_libglog static_libgflags static_libarchive - static_libevent - static_libacl - static_libssl static_libcrypto static_libpthread static_libdl @@ -926,8 +975,15 @@ add_custom_target( -header-filter='.*/include/dwarfs/.*' USES_TERMINAL) +add_custom_target( + tidy-fix + COMMAND run-clang-tidy -p ${CMAKE_BINARY_DIR} -quiet -use-color -fix + -source-filter='.*/src/.*' + -header-filter='.*/include/dwarfs/.*' + USES_TERMINAL) + if(STATIC_BUILD_DO_NOT_USE OR APPLE) - if(CMAKE_BUILD_TYPE STREQUAL "Release") + if(CMAKE_BUILD_TYPE MATCHES "Release|MinSizeRel") foreach(tgt ${BINARY_TARGETS}) list(APPEND FILES_TO_STRIP $) endforeach() @@ -950,23 +1006,39 @@ if(DWARFS_OPTIMIZE) endif() if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") set(DWARFS_ARTIFACT_ID "${DWARFS_ARTIFACT_ID}-reldbg") +elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") + set(DWARFS_ARTIFACT_ID "${DWARFS_ARTIFACT_ID}-minsize") elseif(CMAKE_BUILD_TYPE STREQUAL "Debug") set(DWARFS_ARTIFACT_ID "${DWARFS_ARTIFACT_ID}-debug") endif() if(ENABLE_STACKTRACE) set(DWARFS_ARTIFACT_ID "${DWARFS_ARTIFACT_ID}-stacktrace") endif() +if(DWARFS_ARTIFACT_SUFFIX) + set(DWARFS_ARTIFACT_ID "${DWARFS_ARTIFACT_ID}${DWARFS_ARTIFACT_SUFFIX}") +endif() if(STATIC_BUILD_DO_NOT_USE OR WIN32) - if(WITH_UNIVERSAL_BINARY) - set(UNIVERSAL_OUT "dwarfs-universal-${DWARFS_ARTIFACT_ID}${CMAKE_EXECUTABLE_SUFFIX}") + if(TARGET dwarfsuniversal) + list(APPEND UNIVERSAL_TARGETS dwarfsuniversal) + endif() + + if(TARGET dwarfsfuseextract) + list(APPEND UNIVERSAL_TARGETS dwarfsfuseextract) + endif() + + foreach(tgt ${UNIVERSAL_TARGETS}) + get_target_property(TARGET_FILENAME ${tgt} OUTPUT_NAME) + get_filename_component(TARGET_FILENAME ${TARGET_FILENAME} NAME_WLE) + set(UNIVERSAL_OUT ${TARGET_FILENAME}-${DWARFS_ARTIFACT_ID}${CMAKE_EXECUTABLE_SUFFIX}) + message(STATUS "Creating universal binary for ${tgt} -> ${UNIVERSAL_OUT}") if(ENABLE_STACKTRACE) message(WARNING "UPX compression is disabled with ENABLE_STACKTRACE") add_custom_command( OUTPUT ${UNIVERSAL_OUT} - COMMAND ${CMAKE_COMMAND} -E copy $ ${UNIVERSAL_OUT} + COMMAND ${CMAKE_COMMAND} -E copy $ ${UNIVERSAL_OUT} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) else() @@ -977,13 +1049,16 @@ if(STATIC_BUILD_DO_NOT_USE OR WIN32) # executable significantly add_custom_command( OUTPUT ${UNIVERSAL_OUT} - COMMAND ${UPX_EXE} -9 -o ${UNIVERSAL_OUT} $ + COMMAND ${UPX_EXE} -9 --best -o ${UNIVERSAL_OUT} $ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) endif() - add_custom_target(universal_upx DEPENDS ${UNIVERSAL_OUT}) - endif() + list(APPEND UNIVERSAL_UPX_TARGETS ${CMAKE_CURRENT_BINARY_DIR}/${UNIVERSAL_OUT}) + set(UNIVERSAL_ENV_LIST "${UNIVERSAL_ENV_LIST}${tgt}_binary=${UNIVERSAL_OUT}\n") + endforeach() + + add_custom_target(universal_upx DEPENDS ${UNIVERSAL_UPX_TARGETS}) endif() if(DEFINED ENV{GITHUB_REF_TYPE}) @@ -1020,13 +1095,13 @@ if(DEFINED ENV{GITHUB_REF_TYPE}) if(STATIC_BUILD_DO_NOT_USE OR WIN32) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/artifacts.env" "binary_tarball=${CMAKE_PROJECT_NAME}-${DWARFS_ARTIFACT_ID}${PACKAGE_EXT}\n" - "universal_binary=${UNIVERSAL_OUT}\n") + "${UNIVERSAL_ENV_LIST}") add_custom_command( OUTPUT _copy_artifacts COMMAND ${CMAKE_COMMAND} -E make_directory ${ARTIFACTS_FULL_PATH} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-${DWARFS_ARTIFACT_ID}${PACKAGE_EXT} ${ARTIFACTS_FULL_PATH} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${UNIVERSAL_OUT} ${ARTIFACTS_FULL_PATH} + COMMAND ${CMAKE_COMMAND} -E copy -t ${ARTIFACTS_FULL_PATH} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-${DWARFS_ARTIFACT_ID}${PACKAGE_EXT} + COMMAND ${CMAKE_COMMAND} -E copy -t ${ARTIFACTS_FULL_PATH} ${UNIVERSAL_UPX_TARGETS} ) if(WITH_BENCHMARKS) @@ -1065,6 +1140,7 @@ else() set(CPACK_GENERATOR "TZST") endif() set(CPACK_SOURCE_GENERATOR "${CPACK_GENERATOR}") +set(CPACK_THREADS 0) set(CPACK_PACKAGE_VERSION_MAJOR "${PRJ_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${PRJ_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_PATCH "${PRJ_VERSION_PATCH}") diff --git a/LICENSE b/LICENSE index f288702d2..640d8eed0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,674 +1,30 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 +MIT WITH GPL-3.0-only - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. +Parts of the DwarFS project are licensed under the MIT license, while others are +licensed under the GPL-3.0 license. In general, the code used to *read* DwarFS +images is licensed under the MIT license, while the code used to *write* DwarFS +images is licensed under the GPL-3.0 license. Also, all testing/benchmarking +code is currently licensed under the GPL-3.0 license. - Preamble +That means you can use `mkdwarfs` to create images and then use these images +with only the MIT-licensed code. - The GNU General Public License is a free, copyleft license for -software and other kinds of works. +The following libraries and associated header files are licensed under the +MIT license: - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. +- `dwarfs_common` +- `dwarfs_compressor` +- `dwarfs_decompressor` +- `dwarfs_extractor` +- `dwarfs_reader` - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. +The following libraries and associated header files are licensed under the +GPL-3.0 license: - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. +- `dwarfs_rewrite` +- `dwarfs_writer` - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. +Each header and source file should contain an SPDX identifier near the top +of the file. - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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, either version 3 of the License, or - (at your option) any later version. - - 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 . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +Please also check the licenses of the projects that DwarFS depends on. diff --git a/LICENSE.GPL-3.0 b/LICENSE.GPL-3.0 new file mode 100644 index 000000000..f288702d2 --- /dev/null +++ b/LICENSE.GPL-3.0 @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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, either version 3 of the License, or + (at your option) any later version. + + 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 . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/TODO b/TODO index 7222bc426..d1e03f3ca 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,6 @@ -- Case-insensitive mounting? (github #232) +- More "real" benchmarks + +- Entry v2 - Mounting lots of images with shared cache? - Communication could be implemented using xattrs diff --git a/cmake/compile.cmake b/cmake/compile.cmake index 859a30aa8..6f99cc745 100644 --- a/cmake/compile.cmake +++ b/cmake/compile.cmake @@ -62,7 +62,7 @@ if(NOT WIN32) if(LDD_EXE) execute_process(COMMAND ${LDD_EXE} --version ERROR_VARIABLE LDD_VERSION) if(LDD_VERSION MATCHES "musl libc") - add_compile_definitions(DWARFS_MUSL=1 _LARGEFILE64_SOURCE) + add_compile_definitions(_LARGEFILE64_SOURCE) endif() endif() diff --git a/cmake/folly.cmake b/cmake/folly.cmake index f17566681..5e4283feb 100644 --- a/cmake/folly.cmake +++ b/cmake/folly.cmake @@ -55,6 +55,7 @@ set(CMAKE_DISABLE_FIND_PACKAGE_Snappy ON) set(CMAKE_DISABLE_FIND_PACKAGE_LibAIO ON) set(CMAKE_DISABLE_FIND_PACKAGE_LibUring ON) set(CMAKE_DISABLE_FIND_PACKAGE_Libsodium ON) +set(CMAKE_DISABLE_FIND_PACKAGE_LibDwarf ON) if(NOT PREFER_SYSTEM_FAST_FLOAT) set(FASTFLOAT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fast_float) @@ -74,20 +75,34 @@ if(NOT DWARFS_FMT_LIB) set_target_properties(folly_deps PROPERTIES INTERFACE_LINK_LIBRARIES "${FOLLY_DEPS_INTERFACE_LINK_LIBRARIES}") endif() +# remove dependencies that are not needed +get_target_property(_tmp_folly_deps folly_deps INTERFACE_LINK_LIBRARIES) +list(REMOVE_ITEM _tmp_folly_deps ${LIBEVENT_LIB} ${OPENSSL_LIBRARIES}) +list(REMOVE_ITEM _tmp_folly_deps Boost::context Boost::atomic Boost::regex Boost::system) +if(NOT WIN32) + list(REMOVE_ITEM _tmp_folly_deps Boost::thread) +endif() +set_target_properties(folly_deps PROPERTIES INTERFACE_LINK_LIBRARIES "${_tmp_folly_deps}") + add_library(dwarfs_folly_lite OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/Conv.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/Demangle.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/ExceptionString.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/File.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/FileUtil.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/Format.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/ScopeGuard.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/String.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/Unicode.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/container/detail/F14Table.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/detail/FileUtilDetail.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/detail/SplitStringSimd.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/hash/SpookyHashV2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/io/IOBuf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/io/IOBufQueue.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/json/dynamic.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/json/json.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/json/json_pointer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/lang/CString.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/lang/Exception.cpp ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/lang/SafeAssert.cpp @@ -145,61 +160,7 @@ endif() apply_folly_compile_options_to_target(dwarfs_folly_lite) target_link_libraries(dwarfs_folly_lite PUBLIC folly_deps) -if(WITH_BENCHMARKS) - add_library(dwarfs_follybenchmark_lite OBJECT - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/Benchmark.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/Format.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/SharedMutex.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/Unicode.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/concurrency/CacheLocality.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/detail/Futex.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/detail/PerfScoped.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/detail/StaticSingletonManager.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/ext/test_ext.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/io/FsUtil.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/json/dynamic.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/json/json.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/json/json_pointer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/AsyncFileWriter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/AsyncLogWriter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/CustomLogFormatter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/FileWriterFactory.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/GlogStyleFormatter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/ImmediateFileWriter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/LogCategory.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/LogCategoryConfig.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/LogHandlerConfig.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/LogLevel.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/LogMessage.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/LogName.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/LogStream.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/LogStreamProcessor.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/LoggerDB.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/ObjectToString.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/RateLimiter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/StandardLogHandler.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/StandardLogHandlerFactory.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/StreamHandlerFactory.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/logging/xlog.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/memory/ReentrantAllocator.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/synchronization/ParkingLot.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/synchronization/SanitizeThread.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/system/AtFork.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/system/Pid.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/system/ThreadId.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/testing/TestUtil.cpp - ) - if(NOT WIN32) - target_sources(dwarfs_follybenchmark_lite PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/folly/folly/Subprocess.cpp - ) - endif() - set_property(TARGET dwarfs_follybenchmark_lite PROPERTY CXX_STANDARD 20) - apply_folly_compile_options_to_target(dwarfs_follybenchmark_lite) - target_link_libraries(dwarfs_follybenchmark_lite PUBLIC dwarfs_folly_lite) -endif() - -foreach(tgt dwarfs_folly_lite dwarfs_follybenchmark_lite) +foreach(tgt dwarfs_folly_lite) if(TARGET ${tgt}) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # See: https://github.com/cpp-best-practices/cppbestpractices/blob/master/02-Use_the_Tools_Available.md diff --git a/cmake/libdwarfs.cmake b/cmake/libdwarfs.cmake index 95b180a6d..2616cabca 100644 --- a/cmake/libdwarfs.cmake +++ b/cmake/libdwarfs.cmake @@ -21,9 +21,9 @@ cmake_minimum_required(VERSION 3.28.0) add_library( dwarfs_common - src/block_compressor.cpp - src/block_compressor_parser.cpp + src/byte_buffer.cpp src/checksum.cpp + src/compression_registry.cpp src/conv.cpp src/error.cpp src/file_access_generic.cpp @@ -34,6 +34,7 @@ add_library( src/history.cpp src/library_dependencies.cpp src/logger.cpp + src/mapped_byte_buffer.cpp src/mmap.cpp src/option_map.cpp src/os_access_generic.cpp @@ -42,12 +43,17 @@ add_library( src/terminal_ansi.cpp src/thread_pool.cpp src/util.cpp + src/varint.cpp + src/vector_byte_buffer.cpp + src/vector_byte_buffer_factory.cpp src/xattr.cpp src/internal/features.cpp src/internal/file_status_conv.cpp src/internal/fs_section.cpp + src/internal/fs_section_checker.cpp src/internal/glob_to_regex.cpp + src/internal/metadata_utils.cpp src/internal/string_table.cpp src/internal/unicode_case_folding.cpp src/internal/wcwidth.c @@ -57,6 +63,7 @@ add_library( $/src/version.cpp + src/compression/base.cpp src/compression/null.cpp src/compression/zstd.cpp $<$:src/compression/lzma.cpp> @@ -66,9 +73,25 @@ add_library( $<$:src/compression/ricepp.cpp> ) +add_library( + dwarfs_compressor + + src/block_compressor.cpp + src/block_compressor_parser.cpp + src/compressor_registry.cpp +) + +add_library( + dwarfs_decompressor + + src/block_decompressor.cpp + src/decompressor_registry.cpp +) + add_library( dwarfs_reader + src/reader/block_cache_byte_buffer_factory.cpp src/reader/block_cache_options.cpp src/reader/block_range.cpp src/reader/filesystem_options.cpp @@ -125,6 +148,7 @@ add_library( # src/writer/categorizer/binary_categorizer.cpp src/writer/categorizer/fits_categorizer.cpp + src/writer/categorizer/hotness_categorizer.cpp src/writer/categorizer/incompressible_categorizer.cpp src/writer/categorizer/pcmaudio_categorizer.cpp @@ -163,8 +187,10 @@ add_cpp2_thrift_library(thrift/features.thrift TARGET dwarfs_features_thrift OUTPUT_PATH dwarfs) target_link_libraries(dwarfs_common PRIVATE dwarfs_folly_lite PkgConfig::LIBCRYPTO PkgConfig::XXHASH PkgConfig::ZSTD) -target_link_libraries(dwarfs_reader PUBLIC dwarfs_common) -target_link_libraries(dwarfs_writer PUBLIC dwarfs_common PkgConfig::ZSTD) +target_link_libraries(dwarfs_compressor PRIVATE dwarfs_common) +target_link_libraries(dwarfs_decompressor PRIVATE dwarfs_common) +target_link_libraries(dwarfs_reader PUBLIC dwarfs_common dwarfs_decompressor) +target_link_libraries(dwarfs_writer PUBLIC dwarfs_common dwarfs_compressor dwarfs_decompressor) target_link_libraries(dwarfs_extractor PUBLIC dwarfs_reader) target_link_libraries(dwarfs_rewrite PUBLIC dwarfs_reader dwarfs_writer) @@ -234,6 +260,8 @@ endif() list(APPEND LIBDWARFS_TARGETS dwarfs_common + dwarfs_compressor + dwarfs_decompressor dwarfs_reader dwarfs_writer dwarfs_extractor diff --git a/doc/dwarfs.md b/doc/dwarfs.md index 34c7a2923..7e34e97ff 100644 --- a/doc/dwarfs.md +++ b/doc/dwarfs.md @@ -115,6 +115,19 @@ options: system contains directories with entries that only differ in case. +- `-o preload_category=`*category*: + Preload all blocks from this category when mounting the file + system. This is typically used together with the `mkdwarfs` + "hotness" categorizer. If the cache size is too small, only as + many blocks as will fit in the cache will be preloaded. + +- `-o preload_all` + Preload *all* blocks from the file system. This is only useful + for file systems where all uncompressed blocks fit fully into + the configured cache size. To see the uncompressed block size, + you can use `dwarfsck`. If the cache size is too small, only as + many blocks as will fit in the cache will be preloaded. + - `-o (no_)cache_image`: By default, `dwarfs` tries to ensure that the compressed file system image will not be cached by the kernel (i.e. the default @@ -146,6 +159,13 @@ options: in particular will slow down the driver. This defaults to `info` in foreground mode (`-f`, `-d`) and to `warn` in background mode. +- `-o analysis_file=`*file*: + Write the paths of all files that were opened while the file system + image was mounted to this file. This can be used as a set of "hot" + files for the `hotness` categorizer in `mkdwarfs`. See the `mkdwarfs` + documentation for details on producing images optimized for fast + access times after mounting. + - `-o tidy_strategy=none`|`time`|`swap`: Use one of the following strategies to tidy the block cache. `none` is the default strategy that never tidies the cache. Blocks @@ -171,6 +191,18 @@ options: be an integer value. Suffixes `ms`, `s`, `m`, `h` are supported. If no suffix is given, the value will be assumed to be in seconds. +- `-o block_allocator=malloc`|`mmap`: + Select the allocator for decompressed file system blocks. By default, + blocks will be allocated using `malloc`. However, depending on the way + that `malloc` is implemented on your system, you may find that memory + used by `dwarfs` isn't released despite using cache tidying. In this + case, using the `mmap` block allocator is much more likely to release + the memory. Note, however, that the `mmap` allocator can be slower than + the `malloc` allocator. If your use case causes large numbers of blocks + to be constantly created/evicted (e.g. you have a hugh image and are + randomly accessing a large fraction of the files), this may impact the + performance. + - `-o seq_detector=`*num*: Threshold, in blocks, for the sequential access detector. If the most recently accessed *num* blocks are sequential, then the block following @@ -291,6 +323,132 @@ sudo mount -t overlay overlay -o lowerdir=install-ro:install-modules install If you want *this* merged overlay to be writable, just add in the `upperdir` and `workdir` options from before again. +### Optimizing Performance and Memory Usage + +Depending on your use case, you may want to ensure that `dwarfs` isn't +constantly consuming large amounts of memory. Or you may want to make +sure the file system can always be accessed as quickly as possible. +There are several options to tune performance based on your use case. + +If you don't care much about memory, use the `cachesize` option to make +sure as many decompressed file system blocks as possible can be kept in +memory. + +If your file system image is relatively small, you can also use the +`preload_all` option to immediately populate the cache after mounting. + +The more interesting use case is if you want to be conservative about +memory, but still don't want to sacrifice performance too much. Maybe +you only need to access a lot of files directly after mounting and then +only infrequently need to access other files. If this is the case, you +can use the `tidy_strategy`, `tidy_interval` and `tidy_max_age` options. +With these options, you can usually keep the `cachesize` relatively large +in order to maintain good throughput when accessing files, but the cache +will be tidied up quickly, releasing the memory again if it is no longer +accessed. A useful configuration could look like this: + +``` +dwarfs image mountpoint -otidy_strategy=time,tidy_interval=5s,tidy_max_age=10s +``` + +This will check the cache every 5 seconds and evict any blocks from the +cache that haven't been accessed for more than 10 seconds. What sounds +good in theory can be tricky in practice: just because `dwarfs` has freed +the memory doesn't necessarily mean that the memory allocator will *really* +return the memory to the system. + +If `dwarfs` is built with `jemalloc`, the memory allocator can be tuned +to return memory to the system quickly by setting the `MALLOC_CONF` +environment variable, for example: + +``` +MALLOC_CONF="background_thread:true,dirty_decay_ms:5000,muzzy_decay_ms:5000" +``` + +If `dwarfs` is *not* build with `jemalloc`, it is still possible to run it +with `jemalloc` by using `LD_PRELOAD`: + +``` +LD_PRELOAD=/usr/lib/libjemalloc.so dwarfs image mountpoint ... +``` + +The exact location of the `jemalloc` shared object depends on your system. +If that is *also* not an option, you can use the `block_allocator` option +to `dwarfs`: + +``` +dwarfs image mountpoint -oblock_allocator=mmap,tidy_strategy=time,... +``` + +This will instruct `dwarfs` to *not* use `malloc` for allocating blocks, +but rather use `mmap`. This should work nicely, albeit with some potential +impact on performance, especially with smaller block sizes. + +### Optimizing Application Startup Time + +If you're using DwarFS as storage for an application container, you may +want to optimize startup time. There are different ways to do that. + +If the application is going to read most of the file system image data +during startup, and the image is relatively small, it's worth trying to +just use the `preload_all` option. This will fill the cache with blocks +from the file system image as soon as it is mounted and can already have +a significant impact on startup time. + +If the application is only using a small subset of the data in the image +during startup, you can use "hotness" analysis and build an image that +is optimized to improve startup speed. It's basically profile guide +optimization for file systems. + +First you have to build an initial image you can use to perform the +analysis. Then, you use the `analysis_file` option to mount the image: + +``` +dwarfs image mountpoint -oanalysis_file=/tmp/image.prof +``` + +While the image is mounted, you start the application (or perform +whichever task you want to optimize the file system for). Then, when +you unmount the image, the file you have specified will contain a list +of all paths in the image that have been accessed, in the order in +which the access happened. + +You can then use the `hotness` categorizer in `mkdwarfs`, potentially +along with `explicit` ordering, to build the optimized image: + +``` +mkdwarfs -i input -o image --categorize=hotness --hotness-list=/tmp/image.prof +``` + +Or, with additional explicit ordering: + +``` +mkdwarfs -i input -o image --categorize=hotness --hotness-list=/tmp/image.prof \ + --order hotness::explicit:file=/tmp/image.prof +``` + +This will order the files in the `hotness` category using the same order +as in the profile. Otherwise, they will be ordered by similarity. + +Once you have built this optimized image, you can mount it using the +`preload_category` option: + +``` +dwarfs image mountpoint -opreload_category=hotness +``` + +This will preload all `hotness` blocks into the cache immediately after +mounting and hopefully speed up application startup significantly. + +There are plenty of other ways you can tune how the image is generated. +For example, if the input data already contains compressed files, you +may want to add the `incompressible` categorizer. This will not only +speed up the creation of the file system image as `mkdwarfs` won't waste +time trying to compress incompressible data, but also speed up access as +the data won't need to be decompressed. Also, you could think about using +different compression algorithms for the "hot" and "cold" files, e.g. +something fast like `zstd` for the hot files and `lzma` for the cold files. + ## AUTHOR Written by Marcus Holland-Moritz. diff --git a/doc/mkdwarfs.md b/doc/mkdwarfs.md index 2e5665fff..29ff97521 100644 --- a/doc/mkdwarfs.md +++ b/doc/mkdwarfs.md @@ -289,7 +289,7 @@ Most other options are concerned with compression tuning: "normalize" the permissions across the file system; this is equivalent to using `--chmod=ug-st,=Xr`. -- `--order=`[*category*`::`]`none`|`path`|`revpath`|`similarity`|`nilsimsa`[`:`*opt*[`=`*value*][`:`...]]: +- `--order=`[*category*`::`]`none`|`path`|`revpath`|`similarity`|`nilsimsa`[`:`*opt*[`=`*value*][`:`...]]|`explicit:file=`*file*: The order in which inodes will be written to the file system. Choosing `none`, the inodes will be stored in the order in which they are discovered. With `path`, they will be sorted asciibetically by path name of the first file @@ -310,6 +310,9 @@ Most other options are concerned with compression tuning: Unlike the old implementation, `nilsimsa` ordering is now completely deterministic. See [Nilsimsa Ordering](#nilsimsa-ordering) for a detailed description of the algorithm. + `explicit` ordering allows you to specify a file that contains the paths in + the desired order. The paths must be relative to the `--input` path, but + may start with a leading `/`. - `--max-similarity-size=`*value*: Don't perform similarity ordering for fragments (or files if they are not split @@ -401,6 +404,11 @@ Most other options are concerned with compression tuning: you can switch to `ascii`, which is like `unicode`, but looks less fancy. +- `--hotness-list=`*file*: + A file containing the paths of all "hot" files for the "hotness" + categorizer. The paths must be relative to the `--input` path, but + may start with a leading `/`. + - `--incompressible-min-input-size=`*value*: The minimum size of a file to be checked for incompressibility when the `incompressible` categorizer is active. diff --git a/example/example.cpp b/example/example.cpp index 16726b663..e89b19b37 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #include diff --git a/fbthrift b/fbthrift index 0b1692802..eeb175ae4 160000 --- a/fbthrift +++ b/fbthrift @@ -1 +1 @@ -Subproject commit 0b1692802fd3a95daad427b3aced684837fdb3bd +Subproject commit eeb175ae401943d897d20d66fbc2f17d3aff23ae diff --git a/folly b/folly index 782862824..cb9803db0 160000 --- a/folly +++ b/folly @@ -1 +1 @@ -Subproject commit 78286282478e1ae05b2e8cbcf0e2139eab283bea +Subproject commit cb9803db041c662c8ac84710cf0caa1edb69cdf9 diff --git a/include/dwarfs/block_compressor.h b/include/dwarfs/block_compressor.h index 148383acf..26492ba17 100644 --- a/include/dwarfs/block_compressor.h +++ b/include/dwarfs/block_compressor.h @@ -5,43 +5,39 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once -#include -#include -#include #include -#include -#include -#include #include #include -#include -#include -#include -#include +#include #include #include namespace dwarfs { -class option_map; - class bad_compression_ratio_error : public std::runtime_error { public: bad_compression_ratio_error() @@ -60,24 +56,15 @@ class block_compressor { block_compressor(block_compressor&& bc) = default; block_compressor& operator=(block_compressor&& rhs) = default; - std::vector compress(std::vector const& data) const { + shared_byte_buffer compress(shared_byte_buffer const& data) const { return impl_->compress(data, nullptr); } - std::vector compress(std::vector&& data) const { - return impl_->compress(std::move(data), nullptr); - } - - std::vector compress(std::vector const& data, - std::string const& metadata) const { + shared_byte_buffer + compress(shared_byte_buffer const& data, std::string const& metadata) const { return impl_->compress(data, &metadata); } - std::vector - compress(std::vector&& data, std::string const& metadata) const { - return impl_->compress(std::move(data), &metadata); - } - compression_type type() const { return impl_->type(); } std::string describe() const { return impl_->describe(); } @@ -99,12 +86,8 @@ class block_compressor { virtual std::unique_ptr clone() const = 0; - virtual std::vector - compress(std::vector const& data, - std::string const* metadata) const = 0; - virtual std::vector - compress(std::vector&& data, - std::string const* metadata) const = 0; + virtual shared_byte_buffer compress(shared_byte_buffer const& data, + std::string const* metadata) const = 0; virtual compression_type type() const = 0; virtual std::string describe() const = 0; @@ -119,116 +102,4 @@ class block_compressor { std::unique_ptr impl_; }; -class block_decompressor { - public: - block_decompressor(compression_type type, uint8_t const* data, size_t size, - std::vector& target); - - bool decompress_frame(size_t frame_size = BUFSIZ) { - return impl_->decompress_frame(frame_size); - } - - size_t uncompressed_size() const { return impl_->uncompressed_size(); } - - compression_type type() const { return impl_->type(); } - - std::optional metadata() const { return impl_->metadata(); } - - static std::vector - decompress(compression_type type, uint8_t const* data, size_t size) { - std::vector target; - block_decompressor bd(type, data, size, target); - bd.decompress_frame(bd.uncompressed_size()); - return target; - } - - class impl { - public: - virtual ~impl() = default; - - virtual bool decompress_frame(size_t frame_size) = 0; - virtual size_t uncompressed_size() const = 0; - virtual std::optional metadata() const = 0; - - virtual compression_type type() const = 0; - }; - - private: - std::unique_ptr impl_; -}; - -class compression_info { - public: - virtual ~compression_info() = default; - - virtual std::string_view name() const = 0; - virtual std::string_view description() const = 0; - virtual std::vector const& options() const = 0; - virtual std::set library_dependencies() const = 0; -}; - -class compression_factory : public compression_info { - public: - virtual std::unique_ptr - make_compressor(option_map& om) const = 0; - virtual std::unique_ptr - make_decompressor(std::span data, - std::vector& target) const = 0; -}; - -namespace detail { - -template -struct compression_factory_registrar; - -} // namespace detail - -class compression_registry { - public: - static compression_registry& instance(); - - std::unique_ptr - make_compressor(std::string_view spec) const; - std::unique_ptr - make_decompressor(compression_type type, std::span data, - std::vector& target) const; - - void for_each_algorithm( - std::function const& fn) - const; - - void register_factory(compression_type type, - std::unique_ptr&& factory); - - private: - compression_registry(); - ~compression_registry(); - - std::unordered_map> - factories_; - std::unordered_map names_; -}; - -namespace detail { - -#define DWARFS_COMPRESSION_TYPE_ENUMERATION_(name, value) \ - template <> \ - struct compression_factory_registrar { \ - static void reg(compression_registry&); \ - }; -#define DWARFS_NO_SEPARATOR_ -DWARFS_COMPRESSION_TYPE_LIST(DWARFS_COMPRESSION_TYPE_ENUMERATION_, - DWARFS_NO_SEPARATOR_) -#undef DWARFS_COMPRESSION_TYPE_ENUMERATION_ -#undef DWARFS_NO_SEPARATOR_ - -} // namespace detail - -#define REGISTER_COMPRESSION_FACTORY(factory) \ - void ::dwarfs::detail::compression_factory_registrar::reg( \ - ::dwarfs::compression_registry& cr) { \ - cr.register_factory(factory::type, std::make_unique()); \ - } - } // namespace dwarfs diff --git a/include/dwarfs/block_compressor_parser.h b/include/dwarfs/block_compressor_parser.h index a77caf670..c687c648d 100644 --- a/include/dwarfs/block_compressor_parser.h +++ b/include/dwarfs/block_compressor_parser.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/block_decompressor.h b/include/dwarfs/block_decompressor.h new file mode 100644 index 000000000..9c303c4a8 --- /dev/null +++ b/include/dwarfs/block_decompressor.h @@ -0,0 +1,82 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace dwarfs { + +class block_decompressor { + public: + block_decompressor(compression_type type, std::span data); + + shared_byte_buffer start_decompression(mutable_byte_buffer target); + shared_byte_buffer start_decompression(byte_buffer_factory const& bbf); + + bool decompress_frame(size_t frame_size = BUFSIZ) { + return impl_->decompress_frame(frame_size); + } + + size_t uncompressed_size() const { return impl_->uncompressed_size(); } + + compression_type type() const { return impl_->type(); } + + std::optional metadata() const { return impl_->metadata(); } + + static shared_byte_buffer + decompress(compression_type type, std::span data); + + class impl { + public: + virtual ~impl() = default; + + virtual void start_decompression(mutable_byte_buffer target) = 0; + virtual bool decompress_frame(size_t frame_size) = 0; + virtual size_t uncompressed_size() const = 0; + virtual std::optional metadata() const = 0; + + virtual compression_type type() const = 0; + }; + + private: + std::unique_ptr impl_; +}; + +} // namespace dwarfs diff --git a/include/dwarfs/byte_buffer.h b/include/dwarfs/byte_buffer.h new file mode 100644 index 000000000..50029432a --- /dev/null +++ b/include/dwarfs/byte_buffer.h @@ -0,0 +1,203 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace dwarfs { + +namespace detail { + +template +concept byte_range = requires(T const& t) { + { t.data() } -> std::same_as; + { t.size() } -> std::same_as; +}; + +std::strong_ordering +compare_spans(std::span lhs, std::span rhs); + +} // namespace detail + +class byte_buffer_interface { + public: + virtual ~byte_buffer_interface() = default; + + virtual uint8_t const* data() const = 0; + virtual size_t size() const = 0; + virtual size_t capacity() const = 0; + virtual std::span span() const = 0; +}; + +class mutable_byte_buffer_interface : public byte_buffer_interface { + public: + virtual uint8_t* mutable_data() = 0; + virtual std::span mutable_span() = 0; + virtual void clear() = 0; + virtual void reserve(size_t size) = 0; + virtual void resize(size_t size) = 0; + virtual void shrink_to_fit() = 0; + + // Freezes the location of the buffer in memory, i.e. all further calls + // that would reallocate the buffer will throw. + virtual void freeze_location() = 0; + + // TODO: See if we can do without this. This will *only* be implemented + // in the vector_byte_buffer, other implementations will throw. + virtual std::vector& raw_vector() = 0; +}; + +class shared_byte_buffer { + public: + using value_type = uint8_t; + + shared_byte_buffer() = default; + + explicit shared_byte_buffer(std::shared_ptr bb) + : bb_{std::move(bb)} {} + + uint8_t const* data() const { return bb_->data(); } + + size_t size() const { return bb_->size(); } + + size_t capacity() const { return bb_->capacity(); } + + bool empty() const { return bb_->size() == 0; } + + std::span span() const { return bb_->span(); } + + void swap(shared_byte_buffer& other) noexcept { std::swap(bb_, other.bb_); } + + template + friend bool operator==(shared_byte_buffer const& lhs, T const& rhs) { + return detail::compare_spans(lhs.span(), {rhs.data(), rhs.size()}) == + std::strong_ordering::equal; + } + + template + requires(!std::same_as) + friend bool operator==(T const& lhs, shared_byte_buffer const& rhs) { + return detail::compare_spans({lhs.data(), lhs.size()}, rhs.span()) == + std::strong_ordering::equal; + } + + template + friend std::strong_ordering + operator<=>(shared_byte_buffer const& lhs, T const& rhs) { + return detail::compare_spans(lhs.span(), {rhs.data(), rhs.size()}); + } + + template + requires(!std::same_as) + friend std::strong_ordering + operator<=>(T const& lhs, shared_byte_buffer const& rhs) { + return detail::compare_spans({lhs.data(), lhs.size()}, rhs.span()); + } + + private: + std::shared_ptr bb_; +}; + +class mutable_byte_buffer { + public: + using value_type = uint8_t; + + mutable_byte_buffer() = default; + + explicit mutable_byte_buffer( + std::shared_ptr bb) + : bb_{std::move(bb)} {} + + explicit operator bool() const noexcept { return static_cast(bb_); } + + uint8_t const* data() const { return bb_->data(); } + + uint8_t* data() { return bb_->mutable_data(); } + + size_t size() const { return bb_->size(); } + + size_t capacity() const { return bb_->capacity(); } + + bool empty() const { return bb_->size() == 0; } + + std::span span() const { return bb_->span(); } + + std::span span() { return bb_->mutable_span(); } + + void clear() { bb_->clear(); } + + void reserve(size_t size) { bb_->reserve(size); } + + void resize(size_t size) { bb_->resize(size); } + + void shrink_to_fit() { bb_->shrink_to_fit(); } + + void freeze_location() { bb_->freeze_location(); } + + std::vector& raw_vector() { return bb_->raw_vector(); } + + void swap(mutable_byte_buffer& other) noexcept { std::swap(bb_, other.bb_); } + + template + friend bool operator==(mutable_byte_buffer const& lhs, T const& rhs) { + return detail::compare_spans(lhs.span(), {rhs.data(), rhs.size()}) == + std::strong_ordering::equal; + } + + template + requires(!std::same_as) + friend bool operator==(T const& lhs, mutable_byte_buffer const& rhs) { + return detail::compare_spans({lhs.data(), lhs.size()}, rhs.span()) == + std::strong_ordering::equal; + } + + template + friend std::strong_ordering + operator<=>(mutable_byte_buffer const& lhs, T const& rhs) { + return detail::compare_spans(lhs.span(), {rhs.data(), rhs.size()}); + } + + template + requires(!std::same_as) + friend std::strong_ordering + operator<=>(T const& lhs, mutable_byte_buffer const& rhs) { + return detail::compare_spans({lhs.data(), lhs.size()}, rhs.span()); + } + + auto share() const { return shared_byte_buffer{bb_}; } + + private: + std::shared_ptr bb_; +}; + +} // namespace dwarfs diff --git a/include/dwarfs/byte_buffer_factory.h b/include/dwarfs/byte_buffer_factory.h new file mode 100644 index 000000000..647764fff --- /dev/null +++ b/include/dwarfs/byte_buffer_factory.h @@ -0,0 +1,61 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +#include + +namespace dwarfs { + +class byte_buffer_factory_interface { + public: + virtual ~byte_buffer_factory_interface() = default; + + virtual mutable_byte_buffer + create_mutable_fixed_reserve(size_t size) const = 0; +}; + +class byte_buffer_factory { + public: + byte_buffer_factory() = default; + + explicit byte_buffer_factory( + std::shared_ptr impl) + : impl_{std::move(impl)} {} + + mutable_byte_buffer create_mutable_fixed_reserve(size_t size) const { + return impl_->create_mutable_fixed_reserve(size); + } + + private: + std::shared_ptr impl_; +}; + +} // namespace dwarfs diff --git a/include/dwarfs/checksum.h b/include/dwarfs/checksum.h index f47c4acb5..453af865f 100644 --- a/include/dwarfs/checksum.h +++ b/include/dwarfs/checksum.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -34,21 +41,24 @@ namespace dwarfs { class checksum { public: - enum class algorithm { - SHA2_512_256, - XXH3_64, - XXH3_128, - }; - static bool is_available(std::string const& algo); static std::vector available_algorithms(); - static bool verify(algorithm alg, void const* data, size_t size, + struct xxh3_64_tag {}; + struct sha2_512_256_tag {}; + + static constexpr xxh3_64_tag xxh3_64{}; + static constexpr sha2_512_256_tag sha2_512_256{}; + + static bool verify(xxh3_64_tag, void const* data, size_t size, + void const* digest, size_t digest_size); + static bool verify(sha2_512_256_tag, void const* data, size_t size, void const* digest, size_t digest_size); static bool verify(std::string const& alg, void const* data, size_t size, void const* digest, size_t digest_size); - checksum(algorithm alg); + checksum(xxh3_64_tag); + checksum(sha2_512_256_tag); checksum(std::string const& alg); checksum& update(void const* data, size_t size) { @@ -76,6 +86,4 @@ class checksum { std::unique_ptr impl_; }; -std::ostream& operator<<(std::ostream& os, checksum::algorithm alg); - } // namespace dwarfs diff --git a/include/dwarfs/compiler.h b/include/dwarfs/compiler.h index b07f3c7c6..dafecd3c0 100644 --- a/include/dwarfs/compiler.h +++ b/include/dwarfs/compiler.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -33,9 +40,10 @@ #endif #endif -#if !defined(DWARFS_SANITIZE_THREAD) && !defined(DWARFS_MUSL) && \ - defined(__x86_64__) && __has_attribute(target_clones) -#define DWARFS_MULTIVERSIONING 1 +#if defined(__has_builtin) +#if __has_builtin(__builtin_cpu_supports) && __has_attribute(target) +#define DWARFS_USE_CPU_FEATURES 1 +#endif #endif #if defined(__GNUC__) || defined(__clang__) diff --git a/include/dwarfs/compression.h b/include/dwarfs/compression.h index 811b24537..ea01a91d8 100644 --- a/include/dwarfs/compression.h +++ b/include/dwarfs/compression.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/compression_constraints.h b/include/dwarfs/compression_constraints.h index 921085242..9638e0294 100644 --- a/include/dwarfs/compression_constraints.h +++ b/include/dwarfs/compression_constraints.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/compressor_factory.h b/include/dwarfs/compressor_factory.h new file mode 100644 index 000000000..18b8d68d6 --- /dev/null +++ b/include/dwarfs/compressor_factory.h @@ -0,0 +1,59 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include + +namespace dwarfs { + +class option_map; + +class compressor_info { + public: + virtual ~compressor_info() = default; + + virtual std::string_view name() const = 0; + virtual std::string_view description() const = 0; + virtual std::span options() const = 0; + virtual std::set library_dependencies() const = 0; +}; + +class compressor_factory : public compressor_info { + public: + virtual std::unique_ptr + create(option_map& om) const = 0; +}; + +} // namespace dwarfs diff --git a/include/dwarfs/compressor_registry.h b/include/dwarfs/compressor_registry.h new file mode 100644 index 000000000..c8c40711b --- /dev/null +++ b/include/dwarfs/compressor_registry.h @@ -0,0 +1,46 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +namespace dwarfs { + +class compressor_registry final : public detail::compressor_registry_base { + public: + static compressor_registry& instance(); + + std::unique_ptr create(std::string_view spec) const; + + private: + compressor_registry(); + ~compressor_registry(); +}; + +} // namespace dwarfs diff --git a/include/dwarfs/conv.h b/include/dwarfs/conv.h index 7bff10587..dafe95729 100644 --- a/include/dwarfs/conv.h +++ b/include/dwarfs/conv.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/decompressor_factory.h b/include/dwarfs/decompressor_factory.h new file mode 100644 index 000000000..69aa38156 --- /dev/null +++ b/include/dwarfs/decompressor_factory.h @@ -0,0 +1,56 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include + +namespace dwarfs { + +class decompressor_info { + public: + virtual ~decompressor_info() = default; + + virtual std::string_view name() const = 0; + virtual std::string_view description() const = 0; + virtual std::set library_dependencies() const = 0; +}; + +class decompressor_factory : public decompressor_info { + public: + virtual std::unique_ptr + create(std::span data) const = 0; +}; + +} // namespace dwarfs diff --git a/include/dwarfs/decompressor_registry.h b/include/dwarfs/decompressor_registry.h new file mode 100644 index 000000000..163c126c0 --- /dev/null +++ b/include/dwarfs/decompressor_registry.h @@ -0,0 +1,47 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +namespace dwarfs { + +class decompressor_registry final : public detail::decompressor_registry_base { + public: + static decompressor_registry& instance(); + + std::unique_ptr + create(compression_type type, std::span data) const; + + private: + decompressor_registry(); + ~decompressor_registry(); +}; + +} // namespace dwarfs diff --git a/include/dwarfs/detail/compression_registry.h b/include/dwarfs/detail/compression_registry.h new file mode 100644 index 000000000..2a5d9c176 --- /dev/null +++ b/include/dwarfs/detail/compression_registry.h @@ -0,0 +1,116 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include + +#include +#include + +namespace dwarfs { + +class library_dependencies; + +namespace detail { + +template +struct compression_registrar; + +class compression_registry_base { + protected: + void register_name(compression_type type, std::string_view name); + compression_type get_type(std::string const& name) const; + + private: + std::unordered_map names_; +}; + +template +class compression_registry : public compression_registry_base { + public: + compression_registry(); + + void register_factory(compression_type type, + std::unique_ptr&& factory); + + void for_each_algorithm( + std::function const& fn) const; + + void add_library_dependencies(library_dependencies& deps) const; + + protected: + template + void do_register(); + + FactoryT const& get_factory(compression_type type) const; + + private: + std::unordered_map> + factories_; +}; + +using compressor_registry_base = + compression_registry; +using decompressor_registry_base = + compression_registry; + +#define DWARFS_DETAIL_COMP_REGISTRAR_(type, name, value) \ + template <> \ + struct compression_registrar { \ + static std::unique_ptr reg(); \ + } + +#define DWARFS_COMPRESSION_TYPE_ENUMERATION_(name, value) \ + DWARFS_DETAIL_COMP_REGISTRAR_(compressor, name, value); \ + DWARFS_DETAIL_COMP_REGISTRAR_(decompressor, name, value); + +#define DWARFS_NO_SEPARATOR_ +DWARFS_COMPRESSION_TYPE_LIST(DWARFS_COMPRESSION_TYPE_ENUMERATION_, + DWARFS_NO_SEPARATOR_) +#undef DWARFS_COMPRESSION_TYPE_ENUMERATION_ +#undef DWARFS_NO_SEPARATOR_ + +} // namespace detail +} // namespace dwarfs + +#define REGISTER_COMPRESSOR_FACTORY(factory) \ + std::unique_ptr \ + dwarfs::detail::compression_registrar::reg() { \ + return std::make_unique(); \ + } + +#define REGISTER_DECOMPRESSOR_FACTORY(factory) \ + std::unique_ptr \ + dwarfs::detail::compression_registrar::reg() { \ + return std::make_unique(); \ + } diff --git a/include/dwarfs/detail/logging_class_factory.h b/include/dwarfs/detail/logging_class_factory.h index 7da316a5e..968286997 100644 --- a/include/dwarfs/detail/logging_class_factory.h +++ b/include/dwarfs/detail/logging_class_factory.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/error.h b/include/dwarfs/error.h index 28e25c660..d9d73b929 100644 --- a/include/dwarfs/error.h +++ b/include/dwarfs/error.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/file_access.h b/include/dwarfs/file_access.h index 3b8f75158..4222a167a 100644 --- a/include/dwarfs/file_access.h +++ b/include/dwarfs/file_access.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/file_access_generic.h b/include/dwarfs/file_access_generic.h index d8cd6f6fd..9910cc15b 100644 --- a/include/dwarfs/file_access_generic.h +++ b/include/dwarfs/file_access_generic.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/file_stat.h b/include/dwarfs/file_stat.h index 93b849708..a438f384d 100644 --- a/include/dwarfs/file_stat.h +++ b/include/dwarfs/file_stat.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/file_type.h b/include/dwarfs/file_type.h index 05046ab83..2c2c58893 100644 --- a/include/dwarfs/file_type.h +++ b/include/dwarfs/file_type.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/file_util.h b/include/dwarfs/file_util.h index 172565e4e..fa7e1856d 100644 --- a/include/dwarfs/file_util.h +++ b/include/dwarfs/file_util.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/format.h b/include/dwarfs/format.h index bf8d43ee0..6599567bb 100644 --- a/include/dwarfs/format.h +++ b/include/dwarfs/format.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/fstypes.h b/include/dwarfs/fstypes.h index e3353edba..54a92c258 100644 --- a/include/dwarfs/fstypes.h +++ b/include/dwarfs/fstypes.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/glob_matcher.h b/include/dwarfs/glob_matcher.h index cbb5e04bc..a7f36e0f5 100644 --- a/include/dwarfs/glob_matcher.h +++ b/include/dwarfs/glob_matcher.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/history.h b/include/dwarfs/history.h index 9ee4e018b..aec9f95dc 100644 --- a/include/dwarfs/history.h +++ b/include/dwarfs/history.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -30,6 +37,7 @@ #include +#include #include namespace dwarfs { @@ -50,7 +58,7 @@ class history { thrift::history::history const& get() const { return *history_; } void append(std::optional> args); size_t size() const; - std::vector serialize() const; + shared_byte_buffer serialize() const; void dump(std::ostream& os) const; nlohmann::json as_json() const; diff --git a/include/dwarfs/history_config.h b/include/dwarfs/history_config.h index b7b7ad60b..77e09d47e 100644 --- a/include/dwarfs/history_config.h +++ b/include/dwarfs/history_config.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/integral_value_parser.h b/include/dwarfs/integral_value_parser.h index de32ebb06..8201220b4 100644 --- a/include/dwarfs/integral_value_parser.h +++ b/include/dwarfs/integral_value_parser.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/internal/features.h b/include/dwarfs/internal/features.h index 2f2d11fc2..17fc1f9b3 100644 --- a/include/dwarfs/internal/features.h +++ b/include/dwarfs/internal/features.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/internal/file_status_conv.h b/include/dwarfs/internal/file_status_conv.h index 7e9da18f7..62157d8b1 100644 --- a/include/dwarfs/internal/file_status_conv.h +++ b/include/dwarfs/internal/file_status_conv.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/internal/fs_section.h b/include/dwarfs/internal/fs_section.h index 41f22001c..c64a0553d 100644 --- a/include/dwarfs/internal/fs_section.h +++ b/include/dwarfs/internal/fs_section.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -25,7 +32,6 @@ #include #include #include -#include #include @@ -50,12 +56,19 @@ class fs_section { std::string name() const { return impl_->name(); } std::string description() const { return impl_->description(); } bool check_fast(mmif const& mm) const { return impl_->check_fast(mm); } - bool check(mmif const& mm) const { return impl_->check(mm); } - bool verify(mmif const& mm) const { return impl_->verify(mm); } + std::span data(mmif const& mm) const { return impl_->data(mm); } + std::optional> checksum_span(mmif const& mm) const { + return impl_->checksum_span(mm); + } + + std::optional> integrity_span(mmif const& mm) const { + return impl_->integrity_span(mm); + } + size_t end() const { return start() + length(); } std::optional section_number() const { @@ -66,7 +79,7 @@ class fs_section { return impl_->xxh3_64_value(); } - std::optional> sha2_512_256_value() const { + std::optional> sha2_512_256_value() const { return impl_->sha2_512_256_value(); } @@ -83,12 +96,15 @@ class fs_section { virtual std::string name() const = 0; virtual std::string description() const = 0; virtual bool check_fast(mmif const& mm) const = 0; - virtual bool check(mmif const& mm) const = 0; - virtual bool verify(mmif const& mm) const = 0; virtual std::span data(mmif const& mm) const = 0; + virtual std::optional> + checksum_span(mmif const& mm) const = 0; + virtual std::optional> + integrity_span(mmif const& mm) const = 0; virtual std::optional section_number() const = 0; virtual std::optional xxh3_64_value() const = 0; - virtual std::optional> sha2_512_256_value() const = 0; + virtual std::optional> + sha2_512_256_value() const = 0; }; private: diff --git a/include/dwarfs/internal/fs_section_checker.h b/include/dwarfs/internal/fs_section_checker.h new file mode 100644 index 000000000..be5d89d0e --- /dev/null +++ b/include/dwarfs/internal/fs_section_checker.h @@ -0,0 +1,48 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +namespace dwarfs::internal { + +class fs_section_checker { + public: + fs_section_checker(mmif const& mm) + : mm_{mm} {} + + bool check(fs_section const& section) const; + bool check(fs_section::impl const& section) const; + bool verify(fs_section const& section) const; + + private: + mmif const& mm_; +}; + +} // namespace dwarfs::internal diff --git a/include/dwarfs/internal/glob_to_regex.h b/include/dwarfs/internal/glob_to_regex.h index 68fd21008..ad04e8fd9 100644 --- a/include/dwarfs/internal/glob_to_regex.h +++ b/include/dwarfs/internal/glob_to_regex.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/internal/lazy_value.h b/include/dwarfs/internal/lazy_value.h index 4526211e0..508f26a36 100644 --- a/include/dwarfs/internal/lazy_value.h +++ b/include/dwarfs/internal/lazy_value.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/writer/internal/block_data.h b/include/dwarfs/internal/metadata_utils.h similarity index 54% rename from include/dwarfs/writer/internal/block_data.h rename to include/dwarfs/internal/metadata_utils.h index e9ea346bd..82679421d 100644 --- a/include/dwarfs/writer/internal/block_data.h +++ b/include/dwarfs/internal/metadata_utils.h @@ -22,33 +22,31 @@ #pragma once #include -#include -#include -namespace dwarfs::writer::internal { +#include -class block_data { - public: - block_data() = default; - explicit block_data(std::vector&& vec) - : vec_{std::move(vec)} {} - explicit block_data(std::string_view str) - : vec_{str.begin(), str.end()} {} +#include +#include - std::vector const& vec() const { return vec_; } - std::vector& vec() { return vec_; } +namespace dwarfs::internal { - void reserve(size_t size) { vec_.reserve(size); } - - uint8_t const* data() const { return vec_.data(); } - uint8_t* data() { return vec_.data(); } +// This represents the order in which inodes are stored in inodes +// (or entry_table_v2_2 for older file systems) +enum class inode_rank { + INO_DIR, + INO_LNK, + INO_REG, + INO_DEV, + INO_OTH, +}; - size_t size() const { return vec_.size(); } +inode_rank get_inode_rank(uint32_t mode); - bool empty() const { return vec_.empty(); } +size_t find_inode_rank_offset( + ::apache::thrift::frozen::Layout::View meta, + inode_rank rank); - private: - std::vector vec_; -}; +size_t +find_inode_rank_offset(thrift::metadata::metadata const& meta, inode_rank rank); -} // namespace dwarfs::writer::internal +} // namespace dwarfs::internal diff --git a/include/dwarfs/internal/packed_int_vector.h b/include/dwarfs/internal/packed_int_vector.h index 2ac169095..c305d1851 100644 --- a/include/dwarfs/internal/packed_int_vector.h +++ b/include/dwarfs/internal/packed_int_vector.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/internal/packed_ptr.h b/include/dwarfs/internal/packed_ptr.h index cbe02718a..ce04fc76f 100644 --- a/include/dwarfs/internal/packed_ptr.h +++ b/include/dwarfs/internal/packed_ptr.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/internal/string_table.h b/include/dwarfs/internal/string_table.h index 1beba9d82..539de31e1 100644 --- a/include/dwarfs/internal/string_table.h +++ b/include/dwarfs/internal/string_table.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/internal/unicode_case_folding.h b/include/dwarfs/internal/unicode_case_folding.h index c91b1373b..fd235a675 100644 --- a/include/dwarfs/internal/unicode_case_folding.h +++ b/include/dwarfs/internal/unicode_case_folding.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/internal/worker_group.h b/include/dwarfs/internal/worker_group.h index 25d581c68..a4a44d6e6 100644 --- a/include/dwarfs/internal/worker_group.h +++ b/include/dwarfs/internal/worker_group.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/library_dependencies.h b/include/dwarfs/library_dependencies.h index 87a65b8d0..3bc674c2e 100644 --- a/include/dwarfs/library_dependencies.h +++ b/include/dwarfs/library_dependencies.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/logger.h b/include/dwarfs/logger.h index 7d39e724a..14539ad95 100644 --- a/include/dwarfs/logger.h +++ b/include/dwarfs/logger.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -340,6 +347,10 @@ class log_proxy { #define LOG_PROXY(policy, lgr) ::dwarfs::log_proxy log_(lgr) #define LOG_PROXY_DECL(policy) ::dwarfs::log_proxy log_ +#define LOG_PROXY_REF(policy) ::dwarfs::log_proxy const& log_ +#define LOG_PROXY_REF_(policy) LOG_PROXY_REF(policy), +#define LOG_PROXY_ARG log_ +#define LOG_PROXY_ARG_ log_, #define LOG_PROXY_INIT(lgr) log_(lgr) #define LOG_GET_LOGGER log_.get_logger() #define LOG_FATAL log_.fatal(DWARFS_CURRENT_SOURCE_LOCATION) diff --git a/include/dwarfs/map_util.h b/include/dwarfs/map_util.h index 033e54d15..b93612432 100644 --- a/include/dwarfs/map_util.h +++ b/include/dwarfs/map_util.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/mapped_byte_buffer.h b/include/dwarfs/mapped_byte_buffer.h new file mode 100644 index 000000000..52f22097b --- /dev/null +++ b/include/dwarfs/mapped_byte_buffer.h @@ -0,0 +1,43 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +namespace dwarfs { + +class mmif; + +class mapped_byte_buffer { + public: + static shared_byte_buffer create(std::span data, + std::shared_ptr mmif = nullptr); +}; + +} // namespace dwarfs diff --git a/include/dwarfs/match.h b/include/dwarfs/match.h index 947940d68..0758c333a 100644 --- a/include/dwarfs/match.h +++ b/include/dwarfs/match.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/mmap.h b/include/dwarfs/mmap.h index e4ed52b4a..38cb567c0 100644 --- a/include/dwarfs/mmap.h +++ b/include/dwarfs/mmap.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -32,10 +39,7 @@ namespace dwarfs { class mmap : public mmif { public: explicit mmap(std::filesystem::path const& path); - explicit mmap(std::string const& path); - explicit mmap(char const* path); mmap(std::filesystem::path const& path, size_t size); - mmap(std::string const& path, size_t size); void const* addr() const override; size_t size() const override; diff --git a/include/dwarfs/mmif.h b/include/dwarfs/mmif.h index 7a93daf16..cc26b0f45 100644 --- a/include/dwarfs/mmif.h +++ b/include/dwarfs/mmif.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/option_map.h b/include/dwarfs/option_map.h index 037cfb680..b24963dfc 100644 --- a/include/dwarfs/option_map.h +++ b/include/dwarfs/option_map.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/os_access.h b/include/dwarfs/os_access.h index f5adaa7c7..3448f3e3a 100644 --- a/include/dwarfs/os_access.h +++ b/include/dwarfs/os_access.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/os_access_generic.h b/include/dwarfs/os_access_generic.h index 21af2c5ca..b6efc2659 100644 --- a/include/dwarfs/os_access_generic.h +++ b/include/dwarfs/os_access_generic.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/pcm_sample_transformer.h b/include/dwarfs/pcm_sample_transformer.h index cdf87ff2f..fbb23a23b 100644 --- a/include/dwarfs/pcm_sample_transformer.h +++ b/include/dwarfs/pcm_sample_transformer.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/performance_monitor.h b/include/dwarfs/performance_monitor.h index 75e443456..5302a4f07 100644 --- a/include/dwarfs/performance_monitor.h +++ b/include/dwarfs/performance_monitor.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/block_cache_byte_buffer_factory.h b/include/dwarfs/reader/block_cache_byte_buffer_factory.h new file mode 100644 index 000000000..295a0dc68 --- /dev/null +++ b/include/dwarfs/reader/block_cache_byte_buffer_factory.h @@ -0,0 +1,43 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +#include + +namespace dwarfs::reader { + +class block_cache_byte_buffer_factory { + public: + static byte_buffer_factory create(); + static byte_buffer_factory create(block_cache_allocation_mode mode); +}; + +} // namespace dwarfs::reader diff --git a/include/dwarfs/reader/block_cache_options.h b/include/dwarfs/reader/block_cache_options.h index d17e8de9f..6d4a71294 100644 --- a/include/dwarfs/reader/block_cache_options.h +++ b/include/dwarfs/reader/block_cache_options.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -26,6 +33,11 @@ namespace dwarfs::reader { +enum class block_cache_allocation_mode { + MALLOC, + MMAP, +}; + struct block_cache_options { size_t max_bytes{static_cast(512) << 20}; size_t num_workers{0}; @@ -34,6 +46,8 @@ struct block_cache_options { bool init_workers{true}; bool disable_block_integrity_check{false}; size_t sequential_access_detector_threshold{0}; + block_cache_allocation_mode allocation_mode{ + block_cache_allocation_mode::MALLOC}; }; std::ostream& operator<<(std::ostream& os, block_cache_options const& opts); diff --git a/include/dwarfs/reader/block_range.h b/include/dwarfs/reader/block_range.h index aacfee50b..f5a671a9c 100644 --- a/include/dwarfs/reader/block_range.h +++ b/include/dwarfs/reader/block_range.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/cache_tidy_config.h b/include/dwarfs/reader/cache_tidy_config.h index ded248438..9d3a00f2a 100644 --- a/include/dwarfs/reader/cache_tidy_config.h +++ b/include/dwarfs/reader/cache_tidy_config.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/filesystem_options.h b/include/dwarfs/reader/filesystem_options.h index a0fccc8b9..9a9ba0cf3 100644 --- a/include/dwarfs/reader/filesystem_options.h +++ b/include/dwarfs/reader/filesystem_options.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/filesystem_v2.h b/include/dwarfs/reader/filesystem_v2.h index 4ae422de2..eb503b8b5 100644 --- a/include/dwarfs/reader/filesystem_v2.h +++ b/include/dwarfs/reader/filesystem_v2.h @@ -5,22 +5,30 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once +#include #include #include #include @@ -68,299 +76,260 @@ class filesystem_parser; } // namespace internal -class filesystem_v2 { +class filesystem_v2_lite { public: - filesystem_v2() = default; + filesystem_v2_lite() = default; - filesystem_v2(logger& lgr, os_access const& os, - std::filesystem::path const& path); + filesystem_v2_lite(logger& lgr, os_access const& os, + std::filesystem::path const& path); - filesystem_v2( + filesystem_v2_lite( logger& lgr, os_access const& os, std::filesystem::path const& path, filesystem_options const& options, std::shared_ptr const& perfmon = nullptr); - filesystem_v2(logger& lgr, os_access const& os, std::shared_ptr mm); + filesystem_v2_lite(logger& lgr, os_access const& os, + std::shared_ptr mm); - filesystem_v2( + filesystem_v2_lite( logger& lgr, os_access const& os, std::shared_ptr mm, filesystem_options const& options, std::shared_ptr const& perfmon = nullptr); - static int - identify(logger& lgr, os_access const& os, std::shared_ptr mm, - std::ostream& output, int detail_level = 0, size_t num_readers = 1, - bool check_integrity = false, file_off_t image_offset = 0); - - static std::optional> - header(std::shared_ptr mm); - - static std::optional> - header(std::shared_ptr mm, file_off_t image_offset); - - int check(filesystem_check_level level, size_t num_threads = 0) const { - return impl_->check(level, num_threads); - } - - void dump(std::ostream& os, fsinfo_options const& opts) const { - impl_->dump(os, opts); - } - - std::string dump(fsinfo_options const& opts) const { - return impl_->dump(opts); - } - - nlohmann::json info_as_json(fsinfo_options const& opts) const { - return impl_->info_as_json(opts); - } - - nlohmann::json metadata_as_json() const { return impl_->metadata_as_json(); } - - std::string serialize_metadata_as_json(bool simple) const { - return impl_->serialize_metadata_as_json(simple); - } - void walk(std::function const& func) const { - impl_->walk(func); + lite_->walk(func); } void walk_data_order(std::function const& func) const { - impl_->walk_data_order(func); + lite_->walk_data_order(func); } - dir_entry_view root() const { return impl_->root(); } + dir_entry_view root() const { return lite_->root(); } std::optional find(std::string_view path) const { - return impl_->find(path); + return lite_->find(path); } - std::optional find(int inode) const { return impl_->find(inode); } + std::optional find(int inode) const { return lite_->find(inode); } std::optional find(int inode, std::string_view name) const { - return impl_->find(inode, name); + return lite_->find(inode, name); } file_stat getattr(inode_view entry, std::error_code& ec) const { - return impl_->getattr(std::move(entry), ec); + return lite_->getattr(std::move(entry), ec); } file_stat getattr(inode_view entry) const { - return impl_->getattr(std::move(entry)); + return lite_->getattr(std::move(entry)); } file_stat getattr(inode_view entry, getattr_options const& opts, std::error_code& ec) const { - return impl_->getattr(std::move(entry), opts, ec); + return lite_->getattr(std::move(entry), opts, ec); } file_stat getattr(inode_view entry, getattr_options const& opts) const { - return impl_->getattr(std::move(entry), opts); + return lite_->getattr(std::move(entry), opts); } bool access(inode_view entry, int mode, file_stat::uid_type uid, file_stat::gid_type gid) const { - return impl_->access(std::move(entry), mode, uid, gid); + return lite_->access(std::move(entry), mode, uid, gid); } void access(inode_view entry, int mode, file_stat::uid_type uid, file_stat::gid_type gid, std::error_code& ec) const { - impl_->access(std::move(entry), mode, uid, gid, ec); + lite_->access(std::move(entry), mode, uid, gid, ec); } std::optional opendir(inode_view entry) const { - return impl_->opendir(std::move(entry)); + return lite_->opendir(std::move(entry)); } std::optional readdir(directory_view dir, size_t offset) const { - return impl_->readdir(dir, offset); + return lite_->readdir(dir, offset); } - size_t dirsize(directory_view dir) const { return impl_->dirsize(dir); } + size_t dirsize(directory_view dir) const { return lite_->dirsize(dir); } std::string readlink(inode_view entry, readlink_mode mode, std::error_code& ec) const { - return impl_->readlink(std::move(entry), mode, ec); + return lite_->readlink(std::move(entry), mode, ec); } std::string readlink(inode_view entry, std::error_code& ec) const { - return impl_->readlink(std::move(entry), readlink_mode::preferred, ec); + return lite_->readlink(std::move(entry), readlink_mode::preferred, ec); } std::string readlink(inode_view entry, readlink_mode mode = readlink_mode::preferred) const { - return impl_->readlink(std::move(entry), mode); + return lite_->readlink(std::move(entry), mode); } - void statvfs(vfs_stat* stbuf) const { impl_->statvfs(stbuf); } + void statvfs(vfs_stat* stbuf) const { lite_->statvfs(stbuf); } - int open(inode_view entry) const { return impl_->open(std::move(entry)); } + int open(inode_view entry) const { return lite_->open(std::move(entry)); } int open(inode_view entry, std::error_code& ec) const { - return impl_->open(std::move(entry), ec); + return lite_->open(std::move(entry), ec); } std::string read_string(uint32_t inode) const { - return impl_->read_string(inode); + return lite_->read_string(inode); } std::string read_string(uint32_t inode, std::error_code& ec) const { - return impl_->read_string(inode, ec); + return lite_->read_string(inode, ec); } std::string read_string(uint32_t inode, size_t size, file_off_t offset = 0) const { - return impl_->read_string(inode, size, offset); + return lite_->read_string(inode, size, offset); } std::string read_string(uint32_t inode, size_t size, std::error_code& ec) const { - return impl_->read_string(inode, size, 0, ec); + return lite_->read_string(inode, size, 0, ec); } std::string read_string(uint32_t inode, size_t size, file_off_t offset, std::error_code& ec) const { - return impl_->read_string(inode, size, offset, ec); + return lite_->read_string(inode, size, offset, ec); } size_t read(uint32_t inode, char* buf, size_t size, file_off_t offset = 0) const { - return impl_->read(inode, buf, size, offset); + return lite_->read(inode, buf, size, offset); } size_t read(uint32_t inode, char* buf, size_t size, file_off_t offset, std::error_code& ec) const { - return impl_->read(inode, buf, size, offset, ec); + return lite_->read(inode, buf, size, offset, ec); } size_t read(uint32_t inode, char* buf, size_t size, std::error_code& ec) const { - return impl_->read(inode, buf, size, 0, ec); + return lite_->read(inode, buf, size, 0, ec); } size_t readv(uint32_t inode, iovec_read_buf& buf) const { - return impl_->readv(inode, buf); + return lite_->readv(inode, buf); } size_t readv(uint32_t inode, iovec_read_buf& buf, std::error_code& ec) const { - return impl_->readv(inode, buf, ec); + return lite_->readv(inode, buf, ec); } size_t readv(uint32_t inode, iovec_read_buf& buf, size_t size, file_off_t offset, std::error_code& ec) const { - return impl_->readv(inode, buf, size, offset, ec); + return lite_->readv(inode, buf, size, offset, ec); } size_t readv(uint32_t inode, iovec_read_buf& buf, size_t size, file_off_t offset, size_t maxiov, std::error_code& ec) const { - return impl_->readv(inode, buf, size, offset, maxiov, ec); + return lite_->readv(inode, buf, size, offset, maxiov, ec); } size_t readv(uint32_t inode, iovec_read_buf& buf, size_t size, std::error_code& ec) const { - return impl_->readv(inode, buf, size, 0, ec); + return lite_->readv(inode, buf, size, 0, ec); } size_t readv(uint32_t inode, iovec_read_buf& buf, size_t size, file_off_t offset = 0) const { - return impl_->readv(inode, buf, size, offset); + return lite_->readv(inode, buf, size, offset); } size_t readv(uint32_t inode, iovec_read_buf& buf, size_t size, file_off_t offset, size_t maxiov) const { - return impl_->readv(inode, buf, size, offset, maxiov); + return lite_->readv(inode, buf, size, offset, maxiov); } std::vector> readv(uint32_t inode) const { - return impl_->readv(inode); + return lite_->readv(inode); } std::vector> readv(uint32_t inode, std::error_code& ec) const { - return impl_->readv(inode, ec); + return lite_->readv(inode, ec); } std::vector> readv(uint32_t inode, size_t size, file_off_t offset = 0) const { - return impl_->readv(inode, size, offset); + return lite_->readv(inode, size, offset); } std::vector> readv(uint32_t inode, size_t size, file_off_t offset, size_t maxiov) const { - return impl_->readv(inode, size, offset, maxiov); + return lite_->readv(inode, size, offset, maxiov); } std::vector> readv(uint32_t inode, size_t size, std::error_code& ec) const { - return impl_->readv(inode, size, 0, ec); + return lite_->readv(inode, size, 0, ec); } std::vector> readv(uint32_t inode, size_t size, file_off_t offset, std::error_code& ec) const { - return impl_->readv(inode, size, offset, ec); + return lite_->readv(inode, size, offset, ec); } std::vector> readv(uint32_t inode, size_t size, file_off_t offset, size_t maxiov, std::error_code& ec) const { - return impl_->readv(inode, size, offset, maxiov, ec); + return lite_->readv(inode, size, offset, maxiov, ec); } - std::optional> header() const { - return impl_->header(); - } - - void set_num_workers(size_t num) { impl_->set_num_workers(num); } + void set_num_workers(size_t num) { lite_->set_num_workers(num); } void set_cache_tidy_config(cache_tidy_config const& cfg) { - impl_->set_cache_tidy_config(cfg); + lite_->set_cache_tidy_config(cfg); } - size_t num_blocks() const { return impl_->num_blocks(); } - - bool has_symlinks() const { return impl_->has_symlinks(); } + size_t num_blocks() const { return lite_->num_blocks(); } - history const& get_history() const { return impl_->get_history(); } + bool has_symlinks() const { return lite_->has_symlinks(); } nlohmann::json get_inode_info(inode_view entry) const { - return impl_->get_inode_info(std::move(entry)); + return lite_->get_inode_info(std::move(entry)); } nlohmann::json get_inode_info(inode_view entry, size_t max_chunks) const { - return impl_->get_inode_info(std::move(entry), max_chunks); + return lite_->get_inode_info(std::move(entry), max_chunks); } std::vector get_all_block_categories() const { - return impl_->get_all_block_categories(); + return lite_->get_all_block_categories(); } std::vector get_all_uids() const { - return impl_->get_all_uids(); + return lite_->get_all_uids(); } std::vector get_all_gids() const { - return impl_->get_all_gids(); + return lite_->get_all_gids(); } - std::shared_ptr get_parser() const { - return impl_->get_parser(); + std::optional get_block_category(size_t block_number) const { + return lite_->get_block_category(block_number); } - std::optional get_block_category(size_t block_number) const { - return impl_->get_block_category(block_number); + void cache_blocks_by_category(std::string_view category) const { + lite_->cache_blocks_by_category(category); + } + + void cache_all_blocks() const { lite_->cache_all_blocks(); } + + std::shared_ptr get_parser() const { + return lite_->get_parser(); } - class impl { + class impl_lite { public: - virtual ~impl() = default; + virtual ~impl_lite() = default; - virtual int - check(filesystem_check_level level, size_t num_threads) const = 0; - virtual void dump(std::ostream& os, fsinfo_options const& opts) const = 0; - virtual std::string dump(fsinfo_options const& opts) const = 0; - virtual nlohmann::json info_as_json(fsinfo_options const& opts) const = 0; - virtual nlohmann::json metadata_as_json() const = 0; - virtual std::string serialize_metadata_as_json(bool simple) const = 0; virtual void walk(std::function const& func) const = 0; virtual void @@ -430,25 +399,95 @@ class filesystem_v2 { virtual std::vector> readv(uint32_t inode, size_t size, file_off_t offset, size_t maxiov, std::error_code& ec) const = 0; - virtual std::optional> header() const = 0; virtual void set_num_workers(size_t num) = 0; virtual void set_cache_tidy_config(cache_tidy_config const& cfg) = 0; virtual size_t num_blocks() const = 0; virtual bool has_symlinks() const = 0; - virtual history const& get_history() const = 0; virtual nlohmann::json get_inode_info(inode_view entry) const = 0; virtual nlohmann::json get_inode_info(inode_view entry, size_t max_chunks) const = 0; virtual std::vector get_all_block_categories() const = 0; virtual std::vector get_all_uids() const = 0; virtual std::vector get_all_gids() const = 0; - virtual std::shared_ptr get_parser() const = 0; virtual std::optional get_block_category(size_t block_number) const = 0; + virtual void cache_blocks_by_category(std::string_view category) const = 0; + virtual void cache_all_blocks() const = 0; + virtual std::shared_ptr get_parser() const = 0; + }; + + protected: + explicit filesystem_v2_lite(std::unique_ptr impl) + : lite_{std::move(impl)} {} + + template + requires std::derived_from + T const& as_() const { + return dynamic_cast(*lite_); + } + + private: + std::unique_ptr lite_; +}; + +class filesystem_v2 final : public filesystem_v2_lite { + public: + filesystem_v2() = default; + + filesystem_v2(logger& lgr, os_access const& os, + std::filesystem::path const& path); + + filesystem_v2( + logger& lgr, os_access const& os, std::filesystem::path const& path, + filesystem_options const& options, + std::shared_ptr const& perfmon = nullptr); + + filesystem_v2(logger& lgr, os_access const& os, std::shared_ptr mm); + + filesystem_v2( + logger& lgr, os_access const& os, std::shared_ptr mm, + filesystem_options const& options, + std::shared_ptr const& perfmon = nullptr); + + static int + identify(logger& lgr, os_access const& os, std::shared_ptr mm, + std::ostream& output, int detail_level = 0, size_t num_readers = 1, + bool check_integrity = false, file_off_t image_offset = 0); + + static std::optional> + header(std::shared_ptr mm); + + static std::optional> + header(std::shared_ptr mm, file_off_t image_offset); + + int check(filesystem_check_level level, size_t num_threads = 0) const; + + void dump(std::ostream& os, fsinfo_options const& opts) const; + std::string dump(fsinfo_options const& opts) const; + + nlohmann::json info_as_json(fsinfo_options const& opts) const; + nlohmann::json metadata_as_json() const; + std::string serialize_metadata_as_json(bool simple) const; + + std::optional> header() const; + + history const& get_history() const; + + class impl : public impl_lite { + public: + virtual int + check(filesystem_check_level level, size_t num_threads) const = 0; + virtual void dump(std::ostream& os, fsinfo_options const& opts) const = 0; + virtual std::string dump(fsinfo_options const& opts) const = 0; + virtual nlohmann::json info_as_json(fsinfo_options const& opts) const = 0; + virtual nlohmann::json metadata_as_json() const = 0; + virtual std::string serialize_metadata_as_json(bool simple) const = 0; + virtual std::optional> header() const = 0; + virtual history const& get_history() const = 0; }; private: - std::unique_ptr impl_; + impl const& full_() const; }; } // namespace reader diff --git a/include/dwarfs/reader/fsinfo_features.h b/include/dwarfs/reader/fsinfo_features.h index a60de1128..0361eb96e 100644 --- a/include/dwarfs/reader/fsinfo_features.h +++ b/include/dwarfs/reader/fsinfo_features.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/fsinfo_options.h b/include/dwarfs/reader/fsinfo_options.h index 101db12e2..09737e534 100644 --- a/include/dwarfs/reader/fsinfo_options.h +++ b/include/dwarfs/reader/fsinfo_options.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/getattr_options.h b/include/dwarfs/reader/getattr_options.h index 0add422e3..8b1a58855 100644 --- a/include/dwarfs/reader/getattr_options.h +++ b/include/dwarfs/reader/getattr_options.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/inode_reader_options.h b/include/dwarfs/reader/inode_reader_options.h index 57214c8c5..0ebbfd127 100644 --- a/include/dwarfs/reader/inode_reader_options.h +++ b/include/dwarfs/reader/inode_reader_options.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/internal/block_cache.h b/include/dwarfs/reader/internal/block_cache.h index b7183e658..d87065ede 100644 --- a/include/dwarfs/reader/internal/block_cache.h +++ b/include/dwarfs/reader/internal/block_cache.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/internal/cached_block.h b/include/dwarfs/reader/internal/cached_block.h index 10365c734..1cccf107c 100644 --- a/include/dwarfs/reader/internal/cached_block.h +++ b/include/dwarfs/reader/internal/cached_block.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -28,6 +35,7 @@ namespace dwarfs { +class byte_buffer_factory; class logger; class mmif; @@ -43,7 +51,8 @@ class cached_block { public: static std::unique_ptr create(logger& lgr, dwarfs::internal::fs_section const& b, - std::shared_ptr mm, bool release, bool disable_integrity_check); + std::shared_ptr mm, byte_buffer_factory const& bbf, bool release, + bool disable_integrity_check); virtual ~cached_block() = default; diff --git a/include/dwarfs/reader/internal/filesystem_parser.h b/include/dwarfs/reader/internal/filesystem_parser.h index c37e1cb6a..2f1b631c4 100644 --- a/include/dwarfs/reader/internal/filesystem_parser.h +++ b/include/dwarfs/reader/internal/filesystem_parser.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/internal/inode_reader_v2.h b/include/dwarfs/reader/internal/inode_reader_v2.h index 2138260b9..75e47bfa8 100644 --- a/include/dwarfs/reader/internal/inode_reader_v2.h +++ b/include/dwarfs/reader/internal/inode_reader_v2.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -24,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -93,6 +101,10 @@ class inode_reader_v2 { size_t num_blocks() const { return impl_->num_blocks(); } + void cache_blocks(std::span blocks) const { + impl_->cache_blocks(blocks); + } + class impl { public: virtual ~impl() = default; @@ -114,6 +126,7 @@ class inode_reader_v2 { virtual void set_num_workers(size_t num) = 0; virtual void set_cache_tidy_config(cache_tidy_config const& cfg) = 0; virtual size_t num_blocks() const = 0; + virtual void cache_blocks(std::span blocks) const = 0; }; private: diff --git a/include/dwarfs/reader/internal/metadata_types.h b/include/dwarfs/reader/internal/metadata_types.h index b6782d0f8..230b3dd48 100644 --- a/include/dwarfs/reader/internal/metadata_types.h +++ b/include/dwarfs/reader/internal/metadata_types.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -45,8 +52,7 @@ class logger; namespace reader::internal { -template -class metadata_; +class metadata_v2_data; class global_metadata { public: @@ -201,8 +207,7 @@ class chunk_range { using Meta = ::apache::thrift::frozen::MappedFrozen; - template - friend class internal::metadata_; + friend class internal::metadata_v2_data; public: class iterator diff --git a/include/dwarfs/reader/internal/metadata_v2.h b/include/dwarfs/reader/internal/metadata_v2.h index d30374e0b..ff2dd361a 100644 --- a/include/dwarfs/reader/internal/metadata_v2.h +++ b/include/dwarfs/reader/internal/metadata_v2.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -59,6 +66,8 @@ struct metadata_options; namespace internal { +class metadata_v2_data; + class metadata_v2 { public: metadata_v2() = default; @@ -73,24 +82,6 @@ class metadata_v2 { void check_consistency() const { impl_->check_consistency(); } - void - dump(std::ostream& os, fsinfo_options const& opts, - filesystem_info const* fsinfo, - std::function const& icb) const { - impl_->dump(os, opts, fsinfo, icb); - } - - nlohmann::json info_as_json(fsinfo_options const& opts, - filesystem_info const* fsinfo) const { - return impl_->info_as_json(opts, fsinfo); - } - - nlohmann::json as_json() const { return impl_->as_json(); } - - std::string serialize_as_json(bool simple) const { - return impl_->serialize_as_json(simple); - } - size_t size() const { return impl_->size(); } void walk(std::function const& func) const { @@ -177,24 +168,21 @@ class metadata_v2 { return impl_->get_all_gids(); } + std::vector + get_block_numbers_by_category(std::string_view category) const { + return impl_->get_block_numbers_by_category(category); + } + + metadata_v2_data const& internal_data() const { + return impl_->internal_data(); + } + class impl { public: virtual ~impl() = default; virtual void check_consistency() const = 0; - virtual void dump( - std::ostream& os, fsinfo_options const& opts, - filesystem_info const* fsinfo, - std::function const& icb) const = 0; - - virtual nlohmann::json - info_as_json(fsinfo_options const& opts, - filesystem_info const* fsinfo) const = 0; - - virtual nlohmann::json as_json() const = 0; - virtual std::string serialize_as_json(bool simple) const = 0; - virtual size_t size() const = 0; virtual void @@ -248,12 +236,36 @@ class metadata_v2 { virtual std::vector get_all_uids() const = 0; virtual std::vector get_all_gids() const = 0; + + virtual std::vector + get_block_numbers_by_category(std::string_view category) const = 0; + + virtual metadata_v2_data const& internal_data() const = 0; }; private: std::unique_ptr impl_; }; +class metadata_v2_utils { + public: + metadata_v2_utils(metadata_v2 const& meta); + + void dump(std::ostream& os, fsinfo_options const& opts, + filesystem_info const* fsinfo, + std::function const& icb) const; + + nlohmann::json + info_as_json(fsinfo_options const& opts, filesystem_info const* fsinfo) const; + + nlohmann::json as_json() const; + + std::string serialize_as_json(bool simple) const; + + private: + metadata_v2_data const& data_; +}; + } // namespace internal } // namespace reader } // namespace dwarfs diff --git a/include/dwarfs/reader/internal/offset_cache.h b/include/dwarfs/reader/internal/offset_cache.h index 4a9987ca7..2248b9bfb 100644 --- a/include/dwarfs/reader/internal/offset_cache.h +++ b/include/dwarfs/reader/internal/offset_cache.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/iovec_read_buf.h b/include/dwarfs/reader/iovec_read_buf.h index 178177731..3f856d764 100644 --- a/include/dwarfs/reader/iovec_read_buf.h +++ b/include/dwarfs/reader/iovec_read_buf.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/metadata_options.h b/include/dwarfs/reader/metadata_options.h index e8e629b45..7b77d7811 100644 --- a/include/dwarfs/reader/metadata_options.h +++ b/include/dwarfs/reader/metadata_options.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/reader/metadata_types.h b/include/dwarfs/reader/metadata_types.h index 74912e21e..28fa51338 100644 --- a/include/dwarfs/reader/metadata_types.h +++ b/include/dwarfs/reader/metadata_types.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -36,8 +43,7 @@ namespace dwarfs::reader { namespace internal { -template -class metadata_; +class metadata_v2_data; class inode_view_impl; class dir_entry_view_impl; @@ -139,9 +145,7 @@ class directory_iterator { static_assert(std::input_iterator); class directory_view { - template - friend class internal::metadata_; - + friend class internal::metadata_v2_data; friend class dir_entry_view; public: diff --git a/include/dwarfs/reader/mlock_mode.h b/include/dwarfs/reader/mlock_mode.h index ffe5c1295..44b8f064a 100644 --- a/include/dwarfs/reader/mlock_mode.h +++ b/include/dwarfs/reader/mlock_mode.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/scope_exit.h b/include/dwarfs/scope_exit.h index 4291dd9dd..655fc226c 100644 --- a/include/dwarfs/scope_exit.h +++ b/include/dwarfs/scope_exit.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/small_vector.h b/include/dwarfs/small_vector.h index 75b9da11e..399df8aff 100644 --- a/include/dwarfs/small_vector.h +++ b/include/dwarfs/small_vector.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/sorted_array_map.h b/include/dwarfs/sorted_array_map.h index 5bb1b8f1c..c9e679894 100644 --- a/include/dwarfs/sorted_array_map.h +++ b/include/dwarfs/sorted_array_map.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/source_location.h b/include/dwarfs/source_location.h index 137af972e..31e6dc870 100644 --- a/include/dwarfs/source_location.h +++ b/include/dwarfs/source_location.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/string.h b/include/dwarfs/string.h index 9f4546346..abf5ebfc0 100644 --- a/include/dwarfs/string.h +++ b/include/dwarfs/string.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/terminal.h b/include/dwarfs/terminal.h index 9d48055cc..2a804c8bc 100644 --- a/include/dwarfs/terminal.h +++ b/include/dwarfs/terminal.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/terminal_ansi.h b/include/dwarfs/terminal_ansi.h index ccc9cee8c..1011e0231 100644 --- a/include/dwarfs/terminal_ansi.h +++ b/include/dwarfs/terminal_ansi.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/thread_pool.h b/include/dwarfs/thread_pool.h index dd711ae01..ff98ef287 100644 --- a/include/dwarfs/thread_pool.h +++ b/include/dwarfs/thread_pool.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/types.h b/include/dwarfs/types.h index abc8953eb..24fd00789 100644 --- a/include/dwarfs/types.h +++ b/include/dwarfs/types.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/util.h b/include/dwarfs/util.h index 299de8768..2290381e5 100644 --- a/include/dwarfs/util.h +++ b/include/dwarfs/util.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/utility/filesystem_extractor.h b/include/dwarfs/utility/filesystem_extractor.h index 889aa4e03..7d5c91d13 100644 --- a/include/dwarfs/utility/filesystem_extractor.h +++ b/include/dwarfs/utility/filesystem_extractor.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once @@ -37,7 +44,7 @@ class os_access; namespace reader { -class filesystem_v2; +class filesystem_v2_lite; } @@ -70,15 +77,16 @@ class filesystem_extractor { void close() { impl_->close(); } - bool extract(reader::filesystem_v2 const& fs, + bool extract(reader::filesystem_v2_lite const& fs, filesystem_extractor_options const& opts = filesystem_extractor_options()) { return impl_->extract(fs, nullptr, opts); } - bool extract(reader::filesystem_v2 const& fs, glob_matcher const* matcher, - filesystem_extractor_options const& opts = - filesystem_extractor_options()) { + bool + extract(reader::filesystem_v2_lite const& fs, glob_matcher const* matcher, + filesystem_extractor_options const& opts = + filesystem_extractor_options()) { return impl_->extract(fs, matcher, opts); } @@ -92,7 +100,7 @@ class filesystem_extractor { virtual void open_disk(std::filesystem::path const& output) = 0; virtual void close() = 0; virtual bool - extract(reader::filesystem_v2 const& fs, glob_matcher const* matcher, + extract(reader::filesystem_v2_lite const& fs, glob_matcher const* matcher, filesystem_extractor_options const& opts) = 0; }; diff --git a/include/dwarfs/utility/rewrite_filesystem.h b/include/dwarfs/utility/rewrite_filesystem.h index 082046f43..2eedb9a21 100644 --- a/include/dwarfs/utility/rewrite_filesystem.h +++ b/include/dwarfs/utility/rewrite_filesystem.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/utility/rewrite_options.h b/include/dwarfs/utility/rewrite_options.h index 979f08acd..4f0ebb449 100644 --- a/include/dwarfs/utility/rewrite_options.h +++ b/include/dwarfs/utility/rewrite_options.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/varint.h b/include/dwarfs/varint.h new file mode 100644 index 000000000..e78b3b353 --- /dev/null +++ b/include/dwarfs/varint.h @@ -0,0 +1,46 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include + +namespace dwarfs { + +class varint { + public: + using value_type = uint64_t; + static constexpr size_t max_size{10}; + + static size_t encode(value_type value, uint8_t* buffer); + static value_type decode(std::span& buffer); +}; + +} // namespace dwarfs diff --git a/include/dwarfs/vector_byte_buffer.h b/include/dwarfs/vector_byte_buffer.h new file mode 100644 index 000000000..cb1e0dd54 --- /dev/null +++ b/include/dwarfs/vector_byte_buffer.h @@ -0,0 +1,47 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +#include + +namespace dwarfs { + +class vector_byte_buffer { + public: + static mutable_byte_buffer create(); + static mutable_byte_buffer create(size_t size); + static mutable_byte_buffer create_reserve(size_t size); + static mutable_byte_buffer create(std::string_view data); + static mutable_byte_buffer create(std::span data); + static mutable_byte_buffer create(std::vector&& data); +}; + +} // namespace dwarfs diff --git a/include/dwarfs/vector_byte_buffer_factory.h b/include/dwarfs/vector_byte_buffer_factory.h new file mode 100644 index 000000000..b6c901791 --- /dev/null +++ b/include/dwarfs/vector_byte_buffer_factory.h @@ -0,0 +1,40 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +namespace dwarfs { + +class vector_byte_buffer_factory { + public: + static byte_buffer_factory create(); +}; + +} // namespace dwarfs diff --git a/include/dwarfs/vfs_stat.h b/include/dwarfs/vfs_stat.h index e4aa86c71..d6c01c93a 100644 --- a/include/dwarfs/vfs_stat.h +++ b/include/dwarfs/vfs_stat.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/writer/categorized_option.h b/include/dwarfs/writer/categorized_option.h index 3f7d55340..c80df18fd 100644 --- a/include/dwarfs/writer/categorized_option.h +++ b/include/dwarfs/writer/categorized_option.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/categorizer.h b/include/dwarfs/writer/categorizer.h index ce0f40564..cc430c661 100644 --- a/include/dwarfs/writer/categorizer.h +++ b/include/dwarfs/writer/categorizer.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once @@ -41,6 +43,7 @@ class variables_map; namespace dwarfs { +class file_access; class logger; namespace writer { @@ -63,10 +66,26 @@ class categorizer { subcategory_less(fragment_category a, fragment_category b) const = 0; }; +class file_path_info { + public: + file_path_info(std::filesystem::path const& root_path, + std::filesystem::path const& full_path) + : root_path_{root_path} + , full_path_{full_path} {} + + std::filesystem::path const& root_path() const { return root_path_; } + std::filesystem::path const& full_path() const { return full_path_; } + std::filesystem::path relative_path() const; + + private: + std::filesystem::path const& root_path_; + std::filesystem::path const& full_path_; +}; + class random_access_categorizer : public categorizer { public: virtual inode_fragments - categorize(std::filesystem::path const& path, std::span data, + categorize(file_path_info const& path, std::span data, category_mapper const& mapper) const = 0; }; @@ -83,7 +102,7 @@ class sequential_categorizer_job { class sequential_categorizer : public categorizer { public: virtual std::unique_ptr - job(std::filesystem::path const& path, size_t total_size, + job(file_path_info const& path, size_t total_size, category_mapper const& mapper) const = 0; }; @@ -127,7 +146,7 @@ class categorizer_job { class categorizer_manager : public category_resolver { public: - categorizer_manager(logger& lgr); + categorizer_manager(logger& lgr, std::filesystem::path root); static fragment_category default_category(); @@ -206,8 +225,8 @@ class categorizer_info { class categorizer_factory : public categorizer_info { public: virtual std::unique_ptr - create(logger& lgr, - boost::program_options::variables_map const& vm) const = 0; + create(logger& lgr, boost::program_options::variables_map const& vm, + std::shared_ptr const& fa) const = 0; }; class categorizer_registry { @@ -216,7 +235,8 @@ class categorizer_registry { std::unique_ptr create(logger& lgr, std::string const& name, - boost::program_options::variables_map const& vm) const; + boost::program_options::variables_map const& vm, + std::shared_ptr const& fa) const; void add_options(boost::program_options::options_description& opts) const; @@ -235,6 +255,7 @@ namespace detail { void binary_categorizer_factory_registrar(categorizer_registry&); void fits_categorizer_factory_registrar(categorizer_registry&); +void hotness_categorizer_factory_registrar(categorizer_registry&); void incompressible_categorizer_factory_registrar(categorizer_registry&); void libmagic_categorizer_factory_registrar(categorizer_registry&); void pcmaudio_categorizer_factory_registrar(categorizer_registry&); diff --git a/include/dwarfs/writer/category_parser.h b/include/dwarfs/writer/category_parser.h index 841a8af83..d1e77a9d7 100644 --- a/include/dwarfs/writer/category_parser.h +++ b/include/dwarfs/writer/category_parser.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/category_resolver.h b/include/dwarfs/writer/category_resolver.h index 75cdf6e75..0b5d49083 100644 --- a/include/dwarfs/writer/category_resolver.h +++ b/include/dwarfs/writer/category_resolver.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/chmod_entry_transformer.h b/include/dwarfs/writer/chmod_entry_transformer.h index eea85783d..437fec648 100644 --- a/include/dwarfs/writer/chmod_entry_transformer.h +++ b/include/dwarfs/writer/chmod_entry_transformer.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/compression_metadata_requirements.h b/include/dwarfs/writer/compression_metadata_requirements.h index a1551d476..f770dd979 100644 --- a/include/dwarfs/writer/compression_metadata_requirements.h +++ b/include/dwarfs/writer/compression_metadata_requirements.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/console_writer.h b/include/dwarfs/writer/console_writer.h index 2146a911b..3e2d6468d 100644 --- a/include/dwarfs/writer/console_writer.h +++ b/include/dwarfs/writer/console_writer.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/contextual_option.h b/include/dwarfs/writer/contextual_option.h index db4f9164e..4563de2ef 100644 --- a/include/dwarfs/writer/contextual_option.h +++ b/include/dwarfs/writer/contextual_option.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/entry_factory.h b/include/dwarfs/writer/entry_factory.h index 1fbb193ee..602a0e238 100644 --- a/include/dwarfs/writer/entry_factory.h +++ b/include/dwarfs/writer/entry_factory.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once @@ -38,11 +40,12 @@ class entry; class entry_factory { public: + using node = std::shared_ptr; + entry_factory(); - std::shared_ptr - create(os_access const& os, std::filesystem::path const& path, - std::shared_ptr parent = nullptr) { + node create(os_access const& os, std::filesystem::path const& path, + node parent = {}) { return impl_->create(os, path, std::move(parent)); } @@ -50,9 +53,8 @@ class entry_factory { public: virtual ~impl() = default; - virtual std::shared_ptr - create(os_access const& os, std::filesystem::path const& path, - std::shared_ptr parent) = 0; + virtual node create(os_access const& os, std::filesystem::path const& path, + node parent) = 0; }; private: diff --git a/include/dwarfs/writer/entry_filter.h b/include/dwarfs/writer/entry_filter.h index 1913bb732..7709f61d8 100644 --- a/include/dwarfs/writer/entry_filter.h +++ b/include/dwarfs/writer/entry_filter.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/entry_interface.h b/include/dwarfs/writer/entry_interface.h index 36ee8e143..d8bddbf3c 100644 --- a/include/dwarfs/writer/entry_interface.h +++ b/include/dwarfs/writer/entry_interface.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/entry_transformer.h b/include/dwarfs/writer/entry_transformer.h index dcdc5e4e9..4eaac3955 100644 --- a/include/dwarfs/writer/entry_transformer.h +++ b/include/dwarfs/writer/entry_transformer.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/filesystem_block_category_resolver.h b/include/dwarfs/writer/filesystem_block_category_resolver.h index 6c80f0f6c..811cd8b50 100644 --- a/include/dwarfs/writer/filesystem_block_category_resolver.h +++ b/include/dwarfs/writer/filesystem_block_category_resolver.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/filesystem_writer.h b/include/dwarfs/writer/filesystem_writer.h index b62489efc..8654020d8 100644 --- a/include/dwarfs/writer/filesystem_writer.h +++ b/include/dwarfs/writer/filesystem_writer.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/filesystem_writer_options.h b/include/dwarfs/writer/filesystem_writer_options.h index c52f99c0b..eaee53411 100644 --- a/include/dwarfs/writer/filesystem_writer_options.h +++ b/include/dwarfs/writer/filesystem_writer_options.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/filter_debug.h b/include/dwarfs/writer/filter_debug.h index 8db1f4a5d..6d02a531f 100644 --- a/include/dwarfs/writer/filter_debug.h +++ b/include/dwarfs/writer/filter_debug.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/fragment_category.h b/include/dwarfs/writer/fragment_category.h index 80cce367e..0e9c7be81 100644 --- a/include/dwarfs/writer/fragment_category.h +++ b/include/dwarfs/writer/fragment_category.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/fragment_order_options.h b/include/dwarfs/writer/fragment_order_options.h index 9ca315093..79d5aba71 100644 --- a/include/dwarfs/writer/fragment_order_options.h +++ b/include/dwarfs/writer/fragment_order_options.h @@ -17,18 +17,28 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once +#include #include +#include +#include namespace dwarfs::writer { -// TODO: rename? -> inode_order_mode / fragment_order_mode -enum class fragment_order_mode { NONE, PATH, REVPATH, SIMILARITY, NILSIMSA }; +enum class fragment_order_mode { + NONE, + PATH, + REVPATH, + SIMILARITY, + NILSIMSA, + EXPLICIT +}; -// TODO: rename? -> inode_order_options / fragment_order_options struct fragment_order_options { static constexpr int const kDefaultNilsimsaMaxChildren{16384}; static constexpr int const kDefaultNilsimsaMaxClusterSize{16384}; @@ -36,6 +46,8 @@ struct fragment_order_options { fragment_order_mode mode{fragment_order_mode::NONE}; int nilsimsa_max_children{kDefaultNilsimsaMaxChildren}; int nilsimsa_max_cluster_size{kDefaultNilsimsaMaxClusterSize}; + std::string explicit_order_file{}; + std::unordered_map explicit_order{}; }; std::ostream& operator<<(std::ostream& os, fragment_order_mode mode); diff --git a/include/dwarfs/writer/fragment_order_parser.h b/include/dwarfs/writer/fragment_order_parser.h index 53c418fc6..815941709 100644 --- a/include/dwarfs/writer/fragment_order_parser.h +++ b/include/dwarfs/writer/fragment_order_parser.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once @@ -26,14 +28,25 @@ #include -namespace dwarfs::writer { +namespace dwarfs { + +class file_access; + +namespace writer { struct fragment_order_parser { public: static std::string choices(); + fragment_order_parser(std::shared_ptr const& fa) + : fa_{fa} {} + fragment_order_options parse(std::string_view arg) const; std::string to_string(fragment_order_options const& opts) const; + + private: + std::shared_ptr fa_; }; -} // namespace dwarfs::writer +} // namespace writer +} // namespace dwarfs diff --git a/include/dwarfs/writer/inode_fragments.h b/include/dwarfs/writer/inode_fragments.h index cf9f99b3c..95bdb74cb 100644 --- a/include/dwarfs/writer/inode_fragments.h +++ b/include/dwarfs/writer/inode_fragments.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/inode_options.h b/include/dwarfs/writer/inode_options.h index 453b7fb5a..41871b3d5 100644 --- a/include/dwarfs/writer/inode_options.h +++ b/include/dwarfs/writer/inode_options.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/block_manager.h b/include/dwarfs/writer/internal/block_manager.h index d6a62d6ab..126bff38c 100644 --- a/include/dwarfs/writer/internal/block_manager.h +++ b/include/dwarfs/writer/internal/block_manager.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once @@ -37,7 +39,7 @@ class block_manager { size_t get_logical_block() const; void set_written_block(size_t logical_block, size_t written_block, fragment_category::value_type category); - void map_logical_blocks(std::vector& vec); + void map_logical_blocks(std::vector& vec) const; std::vector get_written_block_categories() const; diff --git a/include/dwarfs/writer/internal/block_merger.h b/include/dwarfs/writer/internal/block_merger.h index 70ab95fb3..f02e6080d 100644 --- a/include/dwarfs/writer/internal/block_merger.h +++ b/include/dwarfs/writer/internal/block_merger.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/chmod_transformer.h b/include/dwarfs/writer/internal/chmod_transformer.h index b5361a25c..36556a007 100644 --- a/include/dwarfs/writer/internal/chmod_transformer.h +++ b/include/dwarfs/writer/internal/chmod_transformer.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/chunkable.h b/include/dwarfs/writer/internal/chunkable.h index fbcdb3270..59357a166 100644 --- a/include/dwarfs/writer/internal/chunkable.h +++ b/include/dwarfs/writer/internal/chunkable.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/cyclic_hash.h b/include/dwarfs/writer/internal/cyclic_hash.h index 9ab16e92f..912ea4b2a 100644 --- a/include/dwarfs/writer/internal/cyclic_hash.h +++ b/include/dwarfs/writer/internal/cyclic_hash.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/detail/multi_queue_block_merger_impl.h b/include/dwarfs/writer/internal/detail/multi_queue_block_merger_impl.h index 39e0a3ab6..b7d36ffaf 100644 --- a/include/dwarfs/writer/internal/detail/multi_queue_block_merger_impl.h +++ b/include/dwarfs/writer/internal/detail/multi_queue_block_merger_impl.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/entry.h b/include/dwarfs/writer/internal/entry.h index cd64a6bd8..622455d24 100644 --- a/include/dwarfs/writer/internal/entry.h +++ b/include/dwarfs/writer/internal/entry.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once @@ -77,7 +79,7 @@ class entry : public entry_interface { bool has_parent() const; std::shared_ptr parent() const; - void set_name(std::string const& name); + void clear_name(); std::filesystem::path fs_path() const; std::string path_as_string() const override; std::string dpath() const override; diff --git a/include/dwarfs/writer/internal/file_scanner.h b/include/dwarfs/writer/internal/file_scanner.h index 86f9afbf3..d89da114c 100644 --- a/include/dwarfs/writer/internal/file_scanner.h +++ b/include/dwarfs/writer/internal/file_scanner.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/filesystem_writer_detail.h b/include/dwarfs/writer/internal/filesystem_writer_detail.h index f8eff04db..6030fa6ae 100644 --- a/include/dwarfs/writer/internal/filesystem_writer_detail.h +++ b/include/dwarfs/writer/internal/filesystem_writer_detail.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once @@ -31,6 +33,7 @@ #include #include +#include #include #include #include @@ -45,8 +48,6 @@ class fs_section; namespace writer::internal { -class block_data; - class filesystem_writer_detail { public: virtual ~filesystem_writer_detail() = default; @@ -71,14 +72,13 @@ class filesystem_writer_detail { virtual void configure_rewrite(size_t filesystem_size, size_t block_count) = 0; virtual void copy_header(std::span header) = 0; - virtual void - write_block(fragment_category cat, std::shared_ptr&& data, - physical_block_cb_type physical_block_cb, - std::optional meta = std::nullopt) = 0; + virtual void write_block(fragment_category cat, shared_byte_buffer data, + physical_block_cb_type physical_block_cb, + std::optional meta = std::nullopt) = 0; virtual void finish_category(fragment_category cat) = 0; - virtual void write_metadata_v2_schema(std::shared_ptr&& data) = 0; - virtual void write_metadata_v2(std::shared_ptr&& data) = 0; - virtual void write_history(std::shared_ptr&& data) = 0; + virtual void write_metadata_v2_schema(shared_byte_buffer data) = 0; + virtual void write_metadata_v2(shared_byte_buffer data) = 0; + virtual void write_history(shared_byte_buffer data) = 0; virtual void check_block_compression( compression_type compression, std::span data, std::optional cat = std::nullopt) = 0; diff --git a/include/dwarfs/writer/internal/fragment_chunkable.h b/include/dwarfs/writer/internal/fragment_chunkable.h index b25a9c947..ec0e1ee7c 100644 --- a/include/dwarfs/writer/internal/fragment_chunkable.h +++ b/include/dwarfs/writer/internal/fragment_chunkable.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/global_entry_data.h b/include/dwarfs/writer/internal/global_entry_data.h index a4d182d94..2414ad384 100644 --- a/include/dwarfs/writer/internal/global_entry_data.h +++ b/include/dwarfs/writer/internal/global_entry_data.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/inode.h b/include/dwarfs/writer/internal/inode.h index 723153611..63e7d9c32 100644 --- a/include/dwarfs/writer/internal/inode.h +++ b/include/dwarfs/writer/internal/inode.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/inode_element_view.h b/include/dwarfs/writer/internal/inode_element_view.h index ee408c3ea..fd4f48c93 100644 --- a/include/dwarfs/writer/internal/inode_element_view.h +++ b/include/dwarfs/writer/internal/inode_element_view.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/inode_manager.h b/include/dwarfs/writer/internal/inode_manager.h index da1e70db5..ef4ebdeba 100644 --- a/include/dwarfs/writer/internal/inode_manager.h +++ b/include/dwarfs/writer/internal/inode_manager.h @@ -17,11 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once #include +#include #include #include #include @@ -75,7 +78,9 @@ class inode_manager { size_t total_size{0}; }; - inode_manager(logger& lgr, progress& prog, inode_options const& opts); + inode_manager(logger& lgr, progress& prog, + std::filesystem::path const& root_path, + inode_options const& opts); std::shared_ptr create_inode() { return impl_->create_inode(); } diff --git a/include/dwarfs/writer/internal/inode_ordering.h b/include/dwarfs/writer/internal/inode_ordering.h index 97ca2ac51..270d34467 100644 --- a/include/dwarfs/writer/internal/inode_ordering.h +++ b/include/dwarfs/writer/internal/inode_ordering.h @@ -17,11 +17,15 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once +#include #include +#include #include @@ -38,6 +42,7 @@ class worker_group; namespace writer { struct inode_options; +struct fragment_order_options; namespace internal { @@ -69,6 +74,12 @@ class inode_ordering { impl_->by_nilsimsa(wg, opts, sp, cat); } + void by_explicit_order(sortable_inode_span& sp, + std::filesystem::path const& root_path, + fragment_order_options const& opts) const { + impl_->by_explicit_order(sp, root_path, opts); + } + class impl { public: virtual ~impl() = default; @@ -82,6 +93,10 @@ class inode_ordering { by_nilsimsa(dwarfs::internal::worker_group& wg, similarity_ordering_options const& opts, sortable_inode_span& sp, fragment_category cat) const = 0; + virtual void + by_explicit_order(sortable_inode_span& sp, + std::filesystem::path const& root_path, + fragment_order_options const& opts) const = 0; }; private: diff --git a/include/dwarfs/writer/internal/metadata_freezer.h b/include/dwarfs/writer/internal/metadata_freezer.h index 59fdea10c..e6eef674f 100644 --- a/include/dwarfs/writer/internal/metadata_freezer.h +++ b/include/dwarfs/writer/internal/metadata_freezer.h @@ -17,13 +17,16 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once #include #include -#include + +#include namespace dwarfs { @@ -35,7 +38,7 @@ namespace writer::internal { class metadata_freezer { public: - static std::pair, std::vector> + static std::pair freeze(thrift::metadata::metadata const& data); }; diff --git a/include/dwarfs/writer/internal/multi_queue_block_merger.h b/include/dwarfs/writer/internal/multi_queue_block_merger.h index a62ef5daf..1ba229fe3 100644 --- a/include/dwarfs/writer/internal/multi_queue_block_merger.h +++ b/include/dwarfs/writer/internal/multi_queue_block_merger.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/nilsimsa.h b/include/dwarfs/writer/internal/nilsimsa.h index 0f1234151..8216e1e28 100644 --- a/include/dwarfs/writer/internal/nilsimsa.h +++ b/include/dwarfs/writer/internal/nilsimsa.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/progress.h b/include/dwarfs/writer/internal/progress.h index 828f059ef..81de13f06 100644 --- a/include/dwarfs/writer/internal/progress.h +++ b/include/dwarfs/writer/internal/progress.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/promise_receiver.h b/include/dwarfs/writer/internal/promise_receiver.h index 77515ad71..dd6aed257 100644 --- a/include/dwarfs/writer/internal/promise_receiver.h +++ b/include/dwarfs/writer/internal/promise_receiver.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/receiver.h b/include/dwarfs/writer/internal/receiver.h index ac7f06138..8e8192b02 100644 --- a/include/dwarfs/writer/internal/receiver.h +++ b/include/dwarfs/writer/internal/receiver.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/scanner_progress.h b/include/dwarfs/writer/internal/scanner_progress.h index 8c9380e6a..8badd1f7b 100644 --- a/include/dwarfs/writer/internal/scanner_progress.h +++ b/include/dwarfs/writer/internal/scanner_progress.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/similarity.h b/include/dwarfs/writer/internal/similarity.h index 8f613de3f..7b4146a53 100644 --- a/include/dwarfs/writer/internal/similarity.h +++ b/include/dwarfs/writer/internal/similarity.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/similarity_ordering.h b/include/dwarfs/writer/internal/similarity_ordering.h index c86182bc6..e2368d783 100644 --- a/include/dwarfs/writer/internal/similarity_ordering.h +++ b/include/dwarfs/writer/internal/similarity_ordering.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/sortable_span.h b/include/dwarfs/writer/internal/sortable_span.h index 544cc1351..4564afad8 100644 --- a/include/dwarfs/writer/internal/sortable_span.h +++ b/include/dwarfs/writer/internal/sortable_span.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/internal/speedometer.h b/include/dwarfs/writer/internal/speedometer.h index 81081745d..3b1b68796 100644 --- a/include/dwarfs/writer/internal/speedometer.h +++ b/include/dwarfs/writer/internal/speedometer.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/object.h b/include/dwarfs/writer/object.h index 5a8a17632..5dd39c3d5 100644 --- a/include/dwarfs/writer/object.h +++ b/include/dwarfs/writer/object.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/rule_based_entry_filter.h b/include/dwarfs/writer/rule_based_entry_filter.h index d3aa223f6..c90d2dfd1 100644 --- a/include/dwarfs/writer/rule_based_entry_filter.h +++ b/include/dwarfs/writer/rule_based_entry_filter.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/scanner.h b/include/dwarfs/writer/scanner.h index ab5560799..b9dda761c 100644 --- a/include/dwarfs/writer/scanner.h +++ b/include/dwarfs/writer/scanner.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/scanner_options.h b/include/dwarfs/writer/scanner_options.h index f0f0e581b..6f6e60b63 100644 --- a/include/dwarfs/writer/scanner_options.h +++ b/include/dwarfs/writer/scanner_options.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/segmenter.h b/include/dwarfs/writer/segmenter.h index 9d49e2ead..92848b9bf 100644 --- a/include/dwarfs/writer/segmenter.h +++ b/include/dwarfs/writer/segmenter.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once @@ -26,6 +28,8 @@ #include #include +#include + namespace dwarfs { struct compression_constraints; @@ -38,7 +42,6 @@ class writer_progress; namespace internal { -class block_data; class block_manager; class chunkable; @@ -55,8 +58,8 @@ class segmenter { unsigned block_size_bits{22}; }; - using block_ready_cb = std::function, size_t logical_block_num)>; + using block_ready_cb = + std::function; segmenter(logger& lgr, writer_progress& prog, std::shared_ptr blkmgr, config const& cfg, diff --git a/include/dwarfs/writer/segmenter_factory.h b/include/dwarfs/writer/segmenter_factory.h index a2b60a9a3..e040036f6 100644 --- a/include/dwarfs/writer/segmenter_factory.h +++ b/include/dwarfs/writer/segmenter_factory.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/writer/writer_progress.h b/include/dwarfs/writer/writer_progress.h index 227e77f94..7312c43c7 100644 --- a/include/dwarfs/writer/writer_progress.h +++ b/include/dwarfs/writer/writer_progress.h @@ -17,6 +17,8 @@ * * You should have received a copy of the GNU General Public License * along with dwarfs. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-only */ #pragma once diff --git a/include/dwarfs/xattr.h b/include/dwarfs/xattr.h index 00305f738..76c25527e 100644 --- a/include/dwarfs/xattr.h +++ b/include/dwarfs/xattr.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/include/dwarfs/zstd_context_manager.h b/include/dwarfs/zstd_context_manager.h index 943d2b6fc..171ae6e7d 100644 --- a/include/dwarfs/zstd_context_manager.h +++ b/include/dwarfs/zstd_context_manager.h @@ -5,18 +5,25 @@ * * This file is part of dwarfs. * - * dwarfs 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * dwarfs 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with dwarfs. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/ricepp/CMakeLists.txt b/ricepp/CMakeLists.txt index 8b80dfe62..559480fca 100644 --- a/ricepp/CMakeLists.txt +++ b/ricepp/CMakeLists.txt @@ -78,7 +78,7 @@ foreach(target ${RICEPP_LIBS_CPUSPECIFIC}) list(APPEND RICEPP_OBJECT_TARGETS ${target}) endforeach() -add_library(ricepp-core OBJECT ricepp.cpp) +add_library(ricepp-core OBJECT ricepp.cpp cpu_variant.cpp) # target_link_libraries(ricepp-core PUBLIC range-v3::range-v3) target_include_directories(ricepp-core SYSTEM PUBLIC $> @@ -162,10 +162,15 @@ if(WITH_BENCHMARKS) endif() add_executable(ricepp_benchmark ricepp_benchmark.cpp) - target_link_libraries(ricepp_benchmark ricepp benchmark::benchmark) + target_link_libraries(ricepp_benchmark PRIVATE ricepp benchmark::benchmark) add_executable(ricepp_benchmark_fits ricepp_benchmark_fits.cpp) - target_link_libraries(ricepp_benchmark_fits ricepp benchmark::benchmark) + target_link_libraries(ricepp_benchmark_fits PRIVATE ricepp benchmark::benchmark) + + if (JEMALLOC_FOUND) + target_link_libraries(ricepp_benchmark PRIVATE PkgConfig::JEMALLOC) + target_link_libraries(ricepp_benchmark_fits PRIVATE PkgConfig::JEMALLOC) + endif() endif() endif() @@ -192,6 +197,10 @@ if(WITH_TESTS) target_link_libraries(ricepp_test PRIVATE ricepp gtest gmock gtest_main) + if (JEMALLOC_FOUND) + target_link_libraries(ricepp_test PRIVATE PkgConfig::JEMALLOC) + endif() + if(ENABLE_COVERAGE) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") foreach(target ricepp ${RICEPP_OBJECT_TARGETS} ricepp_test) diff --git a/ricepp/LICENSE b/ricepp/LICENSE index f288702d2..a22a2da24 100644 --- a/ricepp/LICENSE +++ b/ricepp/LICENSE @@ -1,674 +1 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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, either version 3 of the License, or - (at your option) any later version. - - 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 . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +MIT diff --git a/ricepp/cpu_variant.cpp b/ricepp/cpu_variant.cpp new file mode 100644 index 000000000..8c68f0017 --- /dev/null +++ b/ricepp/cpu_variant.cpp @@ -0,0 +1,83 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of ricepp. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +#include "cpu_variant.h" + +namespace ricepp::detail { + +namespace { + +detail::cpu_variant get_cpu_variant_init() { +#ifndef _WIN32 +#if defined(__has_builtin) +#if __has_builtin(__builtin_cpu_supports) && \ + (defined(RICEPP_CPU_BMI2) || defined(RICEPP_CPU_BMI2_AVX512)) + __builtin_cpu_init(); + + bool const has_avx512vl = __builtin_cpu_supports("avx512vl"); + bool const has_avx512vbmi = __builtin_cpu_supports("avx512vbmi"); + bool const has_bmi2 = __builtin_cpu_supports("bmi2"); + + if (has_avx512vl && has_avx512vbmi && has_bmi2) { + return detail::cpu_variant::has_bmi2_avx512; + } + + if (has_bmi2) { + return detail::cpu_variant::has_bmi2; + } +#endif +#endif +#endif + + return detail::cpu_variant::fallback; +} + +} // namespace + +detail::cpu_variant get_cpu_variant() { + static detail::cpu_variant const variant = get_cpu_variant_init(); + return variant; +} + +void show_cpu_variant(std::string_view variant) { + if (std::getenv("RICEPP_SHOW_CPU_VARIANT")) { + std::cerr << "ricepp: using " << variant << " CPU variant\n"; + } +} + +void show_cpu_variant_once(std::string_view variant) { + static auto const _ = [&variant]() { + show_cpu_variant(variant); + return true; + }(); +} + +} // namespace ricepp::detail diff --git a/ricepp/cpu_variant.h b/ricepp/cpu_variant.h new file mode 100644 index 000000000..bf1174962 --- /dev/null +++ b/ricepp/cpu_variant.h @@ -0,0 +1,45 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of ricepp. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +namespace ricepp::detail { + +enum class cpu_variant { + fallback, + has_bmi2, + has_bmi2_avx512, +}; + +cpu_variant get_cpu_variant(); +void show_cpu_variant(std::string_view variant); +void show_cpu_variant_once(std::string_view variant); + +} // namespace ricepp::detail diff --git a/ricepp/include/ricepp/bitstream_reader.h b/ricepp/include/ricepp/bitstream_reader.h index 69eb7e25b..e35e8f259 100644 --- a/ricepp/include/ricepp/bitstream_reader.h +++ b/ricepp/include/ricepp/bitstream_reader.h @@ -5,18 +5,25 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/ricepp/include/ricepp/bitstream_writer.h b/ricepp/include/ricepp/bitstream_writer.h index 60f832417..cdfebf755 100644 --- a/ricepp/include/ricepp/bitstream_writer.h +++ b/ricepp/include/ricepp/bitstream_writer.h @@ -5,18 +5,25 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/ricepp/include/ricepp/byteswap.h b/ricepp/include/ricepp/byteswap.h index 3e79f15fa..ef2899e56 100644 --- a/ricepp/include/ricepp/byteswap.h +++ b/ricepp/include/ricepp/byteswap.h @@ -5,18 +5,25 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/ricepp/include/ricepp/codec.h b/ricepp/include/ricepp/codec.h index b0c0d1fc2..2acb90b86 100644 --- a/ricepp/include/ricepp/codec.h +++ b/ricepp/include/ricepp/codec.h @@ -5,18 +5,25 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/ricepp/include/ricepp/codec_config.h b/ricepp/include/ricepp/codec_config.h new file mode 100644 index 000000000..37a98b722 --- /dev/null +++ b/ricepp/include/ricepp/codec_config.h @@ -0,0 +1,43 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of ricepp. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include + +namespace ricepp { + +struct codec_config { + size_t block_size; + size_t component_stream_count; + std::endian byteorder; + unsigned unused_lsb_count; +}; + +} // namespace ricepp diff --git a/ricepp/include/ricepp/codec_interface.h b/ricepp/include/ricepp/codec_interface.h deleted file mode 100644 index 107138f67..000000000 --- a/ricepp/include/ricepp/codec_interface.h +++ /dev/null @@ -1,53 +0,0 @@ -/* vim:set ts=2 sw=2 sts=2 et: */ -/** - * \author Marcus Holland-Moritz (github@mhxnet.de) - * \copyright Copyright (c) Marcus Holland-Moritz - * - * This file is part of ricepp. - * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. - * - * ricepp 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 ricepp. If not, see . - */ - -#pragma once - -#include -#include -#include - -namespace ricepp { - -template -class codec_interface { - public: - using pixel_type = PixelT; - - virtual ~codec_interface() = default; - - [[nodiscard]] virtual std::vector - encode(std::span input) const = 0; - - virtual size_t worst_case_encoded_bytes(size_t pixel_count) const = 0; - - virtual size_t - worst_case_encoded_bytes(std::span input) const = 0; - - virtual std::span - encode(std::span output, - std::span input) const = 0; - - virtual void decode(std::span output, - std::span input) const = 0; -}; - -} // namespace ricepp diff --git a/ricepp/include/ricepp/create_decoder.h b/ricepp/include/ricepp/create_decoder.h new file mode 100644 index 000000000..183d491f0 --- /dev/null +++ b/ricepp/include/ricepp/create_decoder.h @@ -0,0 +1,43 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of ricepp. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include + +#include +#include + +namespace ricepp { + +template +std::unique_ptr> +create_decoder(codec_config const& config); + +} // namespace ricepp diff --git a/ricepp/include/ricepp/create_encoder.h b/ricepp/include/ricepp/create_encoder.h new file mode 100644 index 000000000..70cc73548 --- /dev/null +++ b/ricepp/include/ricepp/create_encoder.h @@ -0,0 +1,43 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of ricepp. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include + +#include +#include + +namespace ricepp { + +template +std::unique_ptr> +create_encoder(codec_config const& config); + +} // namespace ricepp diff --git a/ricepp/include/ricepp/decoder_interface.h b/ricepp/include/ricepp/decoder_interface.h new file mode 100644 index 000000000..008e9b1af --- /dev/null +++ b/ricepp/include/ricepp/decoder_interface.h @@ -0,0 +1,48 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of ricepp. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include + +namespace ricepp { + +template +class decoder_interface { + public: + using pixel_type = PixelT; + + virtual ~decoder_interface() = default; + + virtual void decode(std::span output, + std::span input) const = 0; +}; + +} // namespace ricepp diff --git a/ricepp/include/ricepp/detail/compiler.h b/ricepp/include/ricepp/detail/compiler.h index f64179b1e..2984c71d2 100644 --- a/ricepp/include/ricepp/detail/compiler.h +++ b/ricepp/include/ricepp/detail/compiler.h @@ -5,18 +5,25 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/ricepp/include/ricepp/detail/decode.h b/ricepp/include/ricepp/detail/decode.h index 36f06d2c1..64be216b4 100644 --- a/ricepp/include/ricepp/detail/decode.h +++ b/ricepp/include/ricepp/detail/decode.h @@ -5,18 +5,25 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/ricepp/include/ricepp/detail/encode.h b/ricepp/include/ricepp/detail/encode.h index 630fa34bd..b3373aeb6 100644 --- a/ricepp/include/ricepp/detail/encode.h +++ b/ricepp/include/ricepp/detail/encode.h @@ -5,18 +5,25 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once diff --git a/ricepp/include/ricepp/encoder_interface.h b/ricepp/include/ricepp/encoder_interface.h new file mode 100644 index 000000000..8205a5c97 --- /dev/null +++ b/ricepp/include/ricepp/encoder_interface.h @@ -0,0 +1,58 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of ricepp. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include +#include + +namespace ricepp { + +template +class encoder_interface { + public: + using pixel_type = PixelT; + + virtual ~encoder_interface() = default; + + [[nodiscard]] virtual std::vector + encode(std::span input) const = 0; + + virtual size_t worst_case_encoded_bytes(size_t pixel_count) const = 0; + + virtual size_t + worst_case_encoded_bytes(std::span input) const = 0; + + virtual std::span + encode(std::span output, + std::span input) const = 0; +}; + +} // namespace ricepp diff --git a/ricepp/include/ricepp/ricepp.h b/ricepp/include/ricepp/ricepp.h deleted file mode 100644 index 5474148c6..000000000 --- a/ricepp/include/ricepp/ricepp.h +++ /dev/null @@ -1,45 +0,0 @@ -/* vim:set ts=2 sw=2 sts=2 et: */ -/** - * \author Marcus Holland-Moritz (github@mhxnet.de) - * \copyright Copyright (c) Marcus Holland-Moritz - * - * This file is part of ricepp. - * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. - * - * ricepp 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 ricepp. If not, see . - */ - -#pragma once - -#include -#include -#include -#include -#include - -#include - -namespace ricepp { - -struct codec_config { - size_t block_size; - size_t component_stream_count; - std::endian byteorder; - unsigned unused_lsb_count; -}; - -template -std::unique_ptr> -create_codec(codec_config const& config); - -} // namespace ricepp diff --git a/ricepp/ricepp.cpp b/ricepp/ricepp.cpp index 6e5d62dc2..97292d3d8 100644 --- a/ricepp/ricepp.cpp +++ b/ricepp/ricepp.cpp @@ -5,106 +5,46 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ -#include -#include -#include -#include -#include - -#include +#include +#include #include "ricepp_cpuspecific.h" namespace ricepp { -namespace { - -detail::cpu_variant get_cpu_variant_init() { -#ifndef _WIN32 -#if defined(__has_builtin) -#if __has_builtin(__builtin_cpu_supports) && \ - (defined(RICEPP_CPU_BMI2) || defined(RICEPP_CPU_BMI2_AVX512)) - __builtin_cpu_init(); - - bool const has_avx512vl = __builtin_cpu_supports("avx512vl"); - bool const has_avx512vbmi = __builtin_cpu_supports("avx512vbmi"); - bool const has_bmi2 = __builtin_cpu_supports("bmi2"); - - if (has_avx512vl && has_avx512vbmi && has_bmi2) { - return detail::cpu_variant::has_bmi2_avx512; - } - - if (has_bmi2) { - return detail::cpu_variant::has_bmi2; - } -#endif -#endif -#endif - - return detail::cpu_variant::fallback; -} - -detail::cpu_variant get_cpu_variant() { - static detail::cpu_variant const variant = get_cpu_variant_init(); - return variant; -} - -void show_cpu_variant(std::string_view variant) { - if (std::getenv("RICEPP_SHOW_CPU_VARIANT")) { - std::cerr << "ricepp: using " << variant << " CPU variant\n"; - } -} - -void show_cpu_variant_once(std::string_view variant) { - static auto const _ = [&variant]() { - show_cpu_variant(variant); - return true; - }(); +template <> +std::unique_ptr> +create_encoder(codec_config const& config) { + return detail::create_codec_cpuspecific< + encoder_interface, detail::encoder_cpuspecific_, uint16_t>(config); } -} // namespace - template <> -std::unique_ptr> -create_codec(codec_config const& config) { - switch (get_cpu_variant()) { -#ifdef RICEPP_CPU_BMI2_AVX512 - case detail::cpu_variant::has_bmi2_avx512: - show_cpu_variant_once("BMI2+AVX512"); - return detail::create_codec_cpuspecific_< - uint16_t, detail::cpu_variant::has_bmi2_avx512>(config); -#endif - -#ifdef RICEPP_CPU_BMI2 - case detail::cpu_variant::has_bmi2: - show_cpu_variant_once("BMI2"); - return detail::create_codec_cpuspecific_( - config); -#endif - - default: - show_cpu_variant_once("fallback"); - return detail::create_codec_cpuspecific_( - config); - } - - throw std::runtime_error("internal error: unknown CPU variant"); +std::unique_ptr> +create_decoder(codec_config const& config) { + return detail::create_codec_cpuspecific< + decoder_interface, detail::decoder_cpuspecific_, uint16_t>(config); } } // namespace ricepp diff --git a/ricepp/ricepp_benchmark.cpp b/ricepp/ricepp_benchmark.cpp index 778a21f0b..56c8cdd95 100644 --- a/ricepp/ricepp_benchmark.cpp +++ b/ricepp/ricepp_benchmark.cpp @@ -5,18 +5,25 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #include @@ -25,7 +32,8 @@ #include #include -#include +#include +#include namespace { @@ -76,19 +84,23 @@ class ricepp_bm : public ::benchmark::Fixture { .full_freq = 1.0 / state.range(5), }); - codec_ = ricepp::create_codec({ + auto config = ricepp::codec_config{ .block_size = static_cast(state.range(6)), .component_stream_count = static_cast(state.range(7)), .byteorder = state.range(1) ? std::endian::big : std::endian::little, .unused_lsb_count = static_cast(state.range(2)), - }); + }; + + encoder_ = ricepp::create_encoder(config); + decoder_ = ricepp::create_decoder(config); - encoded_ = codec_->encode(data_); + encoded_ = encoder_->encode(data_); } void TearDown(::benchmark::State const&) {} - std::unique_ptr> codec_; + std::unique_ptr> encoder_; + std::unique_ptr> decoder_; std::vector data_; std::vector encoded_; }; @@ -119,9 +131,9 @@ void ricepp_params(benchmark::internal::Benchmark* b) { BENCHMARK_DEFINE_F(ricepp_bm, encode)(::benchmark::State& state) { std::vector encoded; - encoded.resize(codec_->worst_case_encoded_bytes(data_)); + encoded.resize(encoder_->worst_case_encoded_bytes(data_)); for (auto _ : state) { - auto r = codec_->encode(encoded, data_); + auto r = encoder_->encode(encoded, data_); ::benchmark::DoNotOptimize(r); } state.SetBytesProcessed(static_cast(state.iterations()) * @@ -132,7 +144,7 @@ BENCHMARK_DEFINE_F(ricepp_bm, decode)(::benchmark::State& state) { std::vector decoded; decoded.resize(data_.size()); for (auto _ : state) { - codec_->decode(decoded, encoded_); + decoder_->decode(decoded, encoded_); } state.SetBytesProcessed(static_cast(state.iterations()) * data_.size() * sizeof(data_[0])); diff --git a/ricepp/ricepp_benchmark_fits.cpp b/ricepp/ricepp_benchmark_fits.cpp index d3c02b3a1..8dab67c71 100644 --- a/ricepp/ricepp_benchmark_fits.cpp +++ b/ricepp/ricepp_benchmark_fits.cpp @@ -5,18 +5,25 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #include @@ -30,7 +37,8 @@ #include #include -#include +#include +#include namespace { @@ -72,12 +80,15 @@ class ricepp_bm : public ::benchmark::Fixture { auto const& camera_info = g_camera_info.at(camera); - codec_ = ricepp::create_codec({ + auto config = ricepp::codec_config{ .block_size = 128, .component_stream_count = camera_info.component_stream_count, .byteorder = std::endian::big, .unused_lsb_count = camera_info.unused_lsb_count, - }); + }; + + encoder_ = ricepp::create_encoder(config); + decoder_ = ricepp::create_decoder(config); if (data_.empty()) { std::filesystem::path testdata_dir; @@ -89,7 +100,7 @@ class ricepp_bm : public ::benchmark::Fixture { data_ = load_fits_data(testdata_dir / camera / (test + ".fit")); - encoded_ = codec_->encode(data_); + encoded_ = encoder_->encode(data_); } latch_->count_down(); @@ -124,7 +135,8 @@ class ricepp_bm : public ::benchmark::Fixture { return data; } - std::unique_ptr> codec_; + std::unique_ptr> encoder_; + std::unique_ptr> decoder_; std::vector data_; std::vector encoded_; std::optional latch_{1}; @@ -136,9 +148,9 @@ class ricepp_bm : public ::benchmark::Fixture { BENCHMARK_DEFINE_F(ricepp_bm, encode_##camera##_##test) \ (::benchmark::State & state) { \ thread_local std::vector encoded; \ - encoded.resize(codec_->worst_case_encoded_bytes(data_)); \ + encoded.resize(encoder_->worst_case_encoded_bytes(data_)); \ for (auto _ : state) { \ - auto r = codec_->encode(encoded, data_); \ + auto r = encoder_->encode(encoded, data_); \ ::benchmark::DoNotOptimize(r); \ } \ state.SetBytesProcessed(static_cast(state.iterations()) * \ @@ -151,7 +163,7 @@ class ricepp_bm : public ::benchmark::Fixture { thread_local std::vector decoded; \ decoded.resize(data_.size()); \ for (auto _ : state) { \ - codec_->decode(decoded, encoded_); \ + decoder_->decode(decoded, encoded_); \ } \ state.SetBytesProcessed(static_cast(state.iterations()) * \ data_.size() * sizeof(data_[0])); \ diff --git a/ricepp/ricepp_cpuspecific.cpp b/ricepp/ricepp_cpuspecific.cpp index db0c7e870..fb58e450c 100644 --- a/ricepp/ricepp_cpuspecific.cpp +++ b/ricepp/ricepp_cpuspecific.cpp @@ -5,124 +5,48 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ -#include -#include - -#include - #include #include -#include #include -#include -#include -#include "ricepp_cpuspecific.h" +#include "ricepp_cpuspecific_traits.h" -namespace ricepp { +namespace ricepp::detail { namespace { -template -class dynamic_pixel_traits { - public: - using value_type = ValueType; - static constexpr size_t const kBitCount = - std::numeric_limits::digits; - static constexpr value_type const kAllOnes = - std::numeric_limits::max(); - - dynamic_pixel_traits(std::endian byteorder, - unsigned unused_lsb_count) noexcept - : unused_lsb_count_{unused_lsb_count} - , byteorder_{byteorder} -#ifndef NDEBUG - , lsb_mask_{static_cast(~(kAllOnes << unused_lsb_count))} - , msb_mask_{static_cast(~(kAllOnes >> unused_lsb_count))} -#endif - { - assert(unused_lsb_count < kBitCount); - } - - [[nodiscard]] RICEPP_FORCE_INLINE value_type - read(value_type value) const noexcept { - value_type tmp = byteswap(value, byteorder_); - assert((tmp & lsb_mask_) == 0); - return tmp >> unused_lsb_count_; - } - - [[nodiscard]] RICEPP_FORCE_INLINE value_type - write(value_type value) const noexcept { - assert((value & msb_mask_) == 0); - return byteswap(static_cast(value << unused_lsb_count_), - byteorder_); - } - - private: - unsigned const unused_lsb_count_; - std::endian const byteorder_; -#ifndef NDEBUG - value_type const lsb_mask_; - value_type const msb_mask_; -#endif -}; - -template -class static_pixel_traits { - public: - using value_type = ValueType; - static constexpr size_t const kBitCount = - std::numeric_limits::digits; - static constexpr value_type const kAllOnes = - std::numeric_limits::max(); - static constexpr std::endian const kByteOrder = ByteOrder; - static constexpr unsigned const kUnusedLsbCount = UnusedLsbCount; - static constexpr value_type const kLsbMask = - static_cast(~(kAllOnes << kUnusedLsbCount)); - static constexpr value_type const kMsbMask = - static_cast(~(kAllOnes >> kUnusedLsbCount)); - static_assert(kUnusedLsbCount < kBitCount); - - [[nodiscard]] static RICEPP_FORCE_INLINE value_type - read(value_type value) noexcept { - value_type tmp = byteswap(value); - assert((tmp & kLsbMask) == 0); - return tmp >> kUnusedLsbCount; - } - - [[nodiscard]] static RICEPP_FORCE_INLINE value_type - write(value_type value) noexcept { - assert((value & kMsbMask) == 0); - return byteswap( - static_cast(value << kUnusedLsbCount)); - } -}; - template -class codec_impl final - : public codec_interface, +class encoder_impl final + : public encoder_interface, public PixelTraits { public: using pixel_type = typename PixelTraits::value_type; - using codec_type = codec; + using codec_type = + ricepp::codec; - codec_impl(PixelTraits const& traits, size_t block_size) + encoder_impl(PixelTraits const& traits, size_t block_size) : PixelTraits{traits} , block_size_{block_size} {} @@ -147,11 +71,6 @@ class codec_impl final input.size()); } - void decode(std::span output, - std::span input) const override { - decode_impl(output.data(), output.size(), input.data(), input.size()); - } - private: size_t worst_case_encoded_bytes_impl(codec_type& codec, size_t size) const { return (codec.worst_case_bit_count(size) + 8 - 1) / 8; @@ -169,12 +88,6 @@ class codec_impl final std::span{input, input_size}); } - void decode_impl(pixel_type* __restrict output, size_t output_size, - uint8_t const* __restrict input, size_t input_size) const { - return decode_impl(std::span{output, output_size}, - std::span{input, input_size}); - } - std::vector encode_impl(std::span input) const { std::vector output; codec_type codec{block_size_, *this}; @@ -194,101 +107,70 @@ class codec_impl final return std::span{output.begin(), writer.iterator()}; } - void decode_impl(std::span output, - std::span input) const { - bitstream_reader reader{input.begin(), input.end()}; - codec_type codec{block_size_, *this}; - codec.decode(output, reader); - } - private: size_t const block_size_; }; -template -std::unique_ptr> -create_codec_(size_t block_size, PixelTraits const& traits) { - if (block_size <= 512) { - return std::make_unique>( - traits, block_size); - } - - return nullptr; -} - -template -std::unique_ptr> -create_codec_(size_t block_size, size_t component_stream_count, - PixelTraits const& traits) { - switch (component_stream_count) { - case 1: - return create_codec_<1, PixelTraits>(block_size, traits); +template +class decoder_impl final + : public decoder_interface, + public PixelTraits { + public: + using pixel_type = typename PixelTraits::value_type; + using codec_type = codec; - case 2: - return create_codec_<2, PixelTraits>(block_size, traits); + decoder_impl(PixelTraits const& traits, size_t block_size) + : PixelTraits{traits} + , block_size_{block_size} {} - default: - break; + void decode(std::span output, + std::span input) const override { + decode_impl(output.data(), output.size(), input.data(), input.size()); } - return nullptr; -} - -template -std::unique_ptr> -create_codec_(size_t block_size, size_t component_stream_count) { - using pixel_traits = - static_pixel_traits; - - if (auto codec = create_codec_( - block_size, component_stream_count, pixel_traits{})) { - return codec; + private: + void decode_impl(pixel_type* __restrict output, size_t output_size, + uint8_t const* __restrict input, size_t input_size) const { + return decode_impl(std::span{output, output_size}, + std::span{input, input_size}); } - return nullptr; -} + void decode_impl(std::span output, + std::span input) const { + bitstream_reader reader{input.begin(), input.end()}; + codec_type codec{block_size_, *this}; + codec.decode(output, reader); + } -template -std::unique_ptr> -create_codec_(codec_config const& config) { - if (config.byteorder == std::endian::big) { - switch (config.unused_lsb_count) { - case 0: - return create_codec_( - config.block_size, config.component_stream_count); + private: + size_t const block_size_; +}; - case 2: - return create_codec_( - config.block_size, config.component_stream_count); +} // namespace - case 4: - return create_codec_( - config.block_size, config.component_stream_count); - } +template <> +std::unique_ptr> +encoder_cpuspecific_::create( + codec_config const& config) { + if (auto encoder = + create_codec_(config)) { + return encoder; } - using pixel_traits = dynamic_pixel_traits; - - return create_codec_( - config.block_size, config.component_stream_count, - pixel_traits{config.byteorder, config.unused_lsb_count}); + throw std::runtime_error("Unsupported configuration"); } -} // namespace - -namespace detail { - template <> -std::unique_ptr> -create_codec_cpuspecific_( +std::unique_ptr> +decoder_cpuspecific_::create( codec_config const& config) { - if (auto codec = create_codec_(config)) { - return codec; + if (auto decoder = + create_codec_(config)) { + return decoder; } throw std::runtime_error("Unsupported configuration"); } -} // namespace detail -} // namespace ricepp +} // namespace ricepp::detail diff --git a/ricepp/ricepp_cpuspecific.h b/ricepp/ricepp_cpuspecific.h index 6827c233a..9ed41b34f 100644 --- a/ricepp/ricepp_cpuspecific.h +++ b/ricepp/ricepp_cpuspecific.h @@ -5,26 +5,38 @@ * * This file is part of ricepp. * - * ricepp 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, either version 3 of the License, or - * (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * ricepp 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License - * along with ricepp. If not, see . + * 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #pragma once #include #include +#include +#include + +#include +#include -#include +#include "cpu_variant.h" namespace ricepp { @@ -32,15 +44,46 @@ struct codec_config; namespace detail { -enum class cpu_variant { - fallback, - has_bmi2, - has_bmi2_avx512, +template