diff --git a/.github/workflows/build-centos8.yml b/.github/workflows/build-centos8.yml index 3bb9ebb3..2cd246f3 100644 --- a/.github/workflows/build-centos8.yml +++ b/.github/workflows/build-centos8.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Set up Git repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: recursive - name: Build LTFS diff --git a/.github/workflows/build-debian11.yml b/.github/workflows/build-debian11.yml index 3c0f35e7..bfc663b0 100644 --- a/.github/workflows/build-debian11.yml +++ b/.github/workflows/build-debian11.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Set up Git repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: recursive - name: Build LTFS diff --git a/.github/workflows/build-debian12.yml b/.github/workflows/build-debian12.yml index 395cdf81..db1a76d8 100644 --- a/.github/workflows/build-debian12.yml +++ b/.github/workflows/build-debian12.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Set up Git repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: recursive - name: Build LTFS diff --git a/.github/workflows/build-fedora28.yml b/.github/workflows/build-fedora28.yml index 8a3bf106..7b37bb96 100644 --- a/.github/workflows/build-fedora28.yml +++ b/.github/workflows/build-fedora28.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Set up Git repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: recursive - name: Build LTFS diff --git a/.github/workflows/build-ubuntu-bionic.yml b/.github/workflows/build-ubuntu-bionic.yml index 53d6a063..2909c508 100644 --- a/.github/workflows/build-ubuntu-bionic.yml +++ b/.github/workflows/build-ubuntu-bionic.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Set up Git repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: recursive - name: Build LTFS diff --git a/.github/workflows/build-ubuntu-focal.yml b/.github/workflows/build-ubuntu-focal.yml index 30a3ce8c..7c23a54d 100644 --- a/.github/workflows/build-ubuntu-focal.yml +++ b/.github/workflows/build-ubuntu-focal.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Set up Git repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: recursive - name: Build LTFS diff --git a/.github/workflows/build-ubuntu-xeneal.yml b/.github/workflows/build-ubuntu-xeneal.yml index d68432ee..c3d4f1d9 100644 --- a/.github/workflows/build-ubuntu-xeneal.yml +++ b/.github/workflows/build-ubuntu-xeneal.yml @@ -9,7 +9,7 @@ jobs: steps: - name: Set up Git repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: recursive - name: Build LTFS diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml new file mode 100644 index 00000000..e067d0c6 --- /dev/null +++ b/.github/workflows/cmake.yml @@ -0,0 +1,30 @@ +name: CMake Build + +on: [push, pull_request] + +jobs: + build: + name: Build and test with CMake + runs-on: ubuntu-latest + + steps: + - name: Set up Git repository + uses: actions/checkout@v6 + with: + submodules: recursive + + - name: Install dependencies + run: | + sudo apt-get -q update + sudo apt-get -q -y install --no-install-recommends \ + build-essential cmake pkg-config \ + icu-devtools libicu-dev libxml2-dev uuid-dev libsnmp-dev \ + libfuse-dev attr + + - name: Build + run: | + cmake -S . -B build + cmake --build build -j"$(nproc)" + + - name: Run tests + run: ctest --test-dir build --output-on-failure diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 6c1b7cf4..c9046ffb 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -39,13 +39,13 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: recursive # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v4 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -56,7 +56,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) #- name: Autobuild - # uses: github/codeql-action/autobuild@v2 + # uses: github/codeql-action/autobuild@v4 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -74,4 +74,4 @@ jobs: make - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v4 diff --git a/.github/workflows/update-uthash.yml b/.github/workflows/update-uthash.yml index f4adb134..a095fca7 100644 --- a/.github/workflows/update-uthash.yml +++ b/.github/workflows/update-uthash.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: recursive token: ${{ secrets.GITHUB_TOKEN }} @@ -36,7 +36,7 @@ jobs: - name: Create Pull Request if: steps.check_changes.outputs.changed == 'true' - uses: peter-evans/create-pull-request@v5 + uses: peter-evans/create-pull-request@v8 with: commit-message: 'chore: update uthash.h from upstream' title: 'chore: update uthash.h from upstream' diff --git a/.gitignore b/.gitignore index 0711b11e..295a99da 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ aclocal.m4 autom4te.cache/ build-aux/ m4/ -config.h.in +/config.h.in configure # Files generated by ./configure config.h @@ -15,6 +15,8 @@ stamp-h1 .deps/ Makefile ltfs.pc +# Directory generated by cmake -S . -B build +/build/ # Files generated by make *.o *.a diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..8ea38ae0 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,287 @@ +# +# CMake build for LTFS. Coexists with the autotools build; both are +# maintained. The package version is read from the top-level VERSION file +# (the single source of truth shared with configure.ac). +# +cmake_minimum_required(VERSION 3.18) + +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + message(FATAL_ERROR "In-source builds would overwrite autotools files; use a build directory, e.g. cmake -S . -B build") +endif() + +# --- Version (single source of truth: ./VERSION) ----------------------------- +file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" _ltfs_ver_lines) +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION") +list(GET _ltfs_ver_lines 0 LTFS_VERSION_NUM) +list(LENGTH _ltfs_ver_lines _ltfs_ver_n) +set(LTFS_VERSION_SUFFIX "") +if(_ltfs_ver_n GREATER 1) + list(GET _ltfs_ver_lines 1 LTFS_VERSION_SUFFIX) +endif() +if(LTFS_VERSION_SUFFIX STREQUAL "") + set(LTFS_VERSION_FULL "${LTFS_VERSION_NUM}") +else() + set(LTFS_VERSION_FULL "${LTFS_VERSION_NUM} ${LTFS_VERSION_SUFFIX}") +endif() + +project(ltfs VERSION ${LTFS_VERSION_NUM} LANGUAGES C) + +if(NOT CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin)$") + message(WARNING "The CMake build is not tested on ${CMAKE_SYSTEM_NAME}.") +endif() + +set(LTFS_PACKAGE_NAME "LTFS") +set(LTFS_PACKAGE_TARNAME "ltfs") +set(LTFS_BUGREPORT "IBM corporation.") + +set(CMAKE_C_STANDARD 11) +#set(CMAKE_C_STANDARD 17) # bump to C17 once the oldest supported toolchains are GCC 8+/Clang 7+ +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) # gnu11: LTFS uses GNU extensions (_GNU_SOURCE, asprintf, ...) +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE) +endif() + +include(GNUInstallDirs) + +# Keep the install libdir in the RUNPATH of the installed binaries and +# plugins, as the libtool build does, unless it is a system directory. +if("${CMAKE_INSTALL_RPATH}" STREQUAL "") + list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" _ltfs_system_libdir) + if(_ltfs_system_libdir EQUAL -1) + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}") + endif() +endif() + +include(CheckIncludeFile) +include(CheckSymbolExists) +include(CheckTypeSize) +include(CheckCCompilerFlag) + +# --- Options (mirror the autotools --enable/--with switches) ------------------ +# SNMP is not supported on macOS (README: configure --disable-snmp there). +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(_ltfs_snmp_default OFF) +else() + set(_ltfs_snmp_default ON) +endif() +option(LTFS_ENABLE_SNMP "Build with SNMP support" ${_ltfs_snmp_default}) +option(LTFS_ENABLE_LINTAPE "Build the IBM lin_tape backend (Linux only)" OFF) +option(LTFS_SUPPORT_BUGGY_IFS "Work around buggy tape interfaces" OFF) +option(LTFS_LIVELINK "Enable livelink symlink mode" ON) +option(LTFS_WERROR "Treat warnings as errors" OFF) +option(LTFS_DEBUG "Compile with extra debugging output" OFF) + +# New locking defaults ON for NetBSD (its old locking is broken), OFF elsewhere. +if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") + option(LTFS_NEW_LOCKING "Use the new locking implementation" ON) +else() + option(LTFS_NEW_LOCKING "Use the new locking implementation" OFF) +endif() + +# Default plugin selection, matching configure.ac. +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(_default_tape "sg") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(_default_tape "iokit") +elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + set(_default_tape "cam") +elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") + set(_default_tape "scsipi-ibmtape") +endif() +set(DEFAULT_TAPE "${_default_tape}" CACHE STRING "Default tape backend plugin") +if(DEFAULT_TAPE STREQUAL "lin_tape" AND NOT LTFS_ENABLE_LINTAPE) + message(NOTICE "DEFAULT_TAPE=lin_tape: enabling LTFS_ENABLE_LINTAPE") + set(LTFS_ENABLE_LINTAPE ON CACHE BOOL "Build the IBM lin_tape backend (Linux only)" FORCE) +endif() +set(DEFAULT_IOSCHED "unified" CACHE STRING "Default I/O scheduler plugin") +set(DEFAULT_KMI "none" CACHE STRING "Default key manager plugin") + +# --- Dependencies ------------------------------------------------------------ +# find_package is used wherever a CMake package exists (LibXml2, ICU, Threads). +# libfuse, libuuid, and net-snmp ship no CMake config; pkg-config is their +# canonical interface, wrapped as IMPORTED_TARGETs (PkgConfig::*). +find_package(PkgConfig REQUIRED) + +pkg_check_modules(FUSE REQUIRED IMPORTED_TARGET fuse>=2.6.0) + +find_package(LibXml2 2.6.16 REQUIRED) + +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + pkg_check_modules(UUID REQUIRED IMPORTED_TARGET uuid>=1.6) +else() + pkg_check_modules(UUID REQUIRED IMPORTED_TARGET uuid>=1.36) +endif() + +# ICU via the CMake module (replaces the removed icu-config). +find_package(ICU REQUIRED COMPONENTS uc i18n io data) +set(LTFS_ICU6X OFF) +if(ICU_VERSION VERSION_GREATER_EQUAL "60") + set(LTFS_ICU6X ON) +endif() + +find_package(Threads REQUIRED) +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") + find_library(RT_LIBRARY rt) +endif() + +# SNMP (optional). +if(LTFS_ENABLE_SNMP) + pkg_check_modules(NETSNMP IMPORTED_TARGET netsnmp-agent>=5.3) + if(NETSNMP_FOUND) + set(LTFS_SNMP_LIBS PkgConfig::NETSNMP) + else() + find_program(NET_SNMP_CONFIG net-snmp-config) + if(NET_SNMP_CONFIG) + execute_process(COMMAND ${NET_SNMP_CONFIG} --agent-libs + RESULT_VARIABLE _snmp_result + OUTPUT_VARIABLE _snmp_libs + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(_snmp_result EQUAL 0 AND NOT _snmp_libs STREQUAL "") + separate_arguments(LTFS_SNMP_LIBS UNIX_COMMAND "${_snmp_libs}") + # net-snmp-config repeats -lm and -lssl; CMake would then also repeat the + # message objects (plain object files) on the link line. + list(REMOVE_DUPLICATES LTFS_SNMP_LIBS) + endif() + endif() + endif() + if(NOT LTFS_SNMP_LIBS) + message(FATAL_ERROR "net-snmp development files not found; install them or configure with -DLTFS_ENABLE_SNMP=OFF") + endif() +endif() + +# Platform-specific libraries (declared for all platforms; used where built). +# backtrace() has a CMake module (libc on glibc, libexecinfo on the BSDs); +# cam/bsdxml/mt and the Apple frameworks ship neither CMake configs nor +# pkg-config files, so find_library is the canonical way to locate them. +if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + find_library(CAM_LIBRARY cam REQUIRED) + find_library(BSDXML_LIBRARY bsdxml REQUIRED) + find_library(MT_LIBRARY mt REQUIRED) + find_package(Backtrace REQUIRED) +elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") + find_package(Backtrace REQUIRED) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + find_library(IOKIT_FRAMEWORK IOKit REQUIRED) + find_library(COREFOUNDATION_FRAMEWORK CoreFoundation REQUIRED) +endif() + +# ICU host tools for the message bundles. +if(NOT ICU_GENRB_EXECUTABLE OR NOT ICU_PKGDATA_EXECUTABLE) + message(FATAL_ERROR "ICU genrb and pkgdata not found; install the ICU tools (e.g. icu-devtools)") +endif() + +# --- Feature checks for config.h --------------------------------------------- +check_include_file("sys/sysctl.h" HAVE_SYS_SYSCTL_H) +check_include_file("fcntl.h" HAVE_FCNTL_H) +check_include_file("limits.h" HAVE_LIMITS_H) +check_include_file("stddef.h" HAVE_STDDEF_H) +check_include_file("stdint.h" HAVE_STDINT_H) +check_include_file("stdlib.h" HAVE_STDLIB_H) +check_include_file("string.h" HAVE_STRING_H) +check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H) +check_include_file("sys/mount.h" HAVE_SYS_MOUNT_H) +check_include_file("sys/time.h" HAVE_SYS_TIME_H) +check_include_file("termios.h" HAVE_TERMIOS_H) +check_include_file("unistd.h" HAVE_UNISTD_H) +check_type_size("time_t" SIZEOF_TIME_T) + +# xmlTextReaderSetup and XML_PARSE_HUGE (need libxml2 flags in scope). +# XML_PARSE_HUGE is an enumerator, not a macro, so it needs a compile test. +include(CheckCSourceCompiles) +set(CMAKE_REQUIRED_INCLUDES ${LIBXML2_INCLUDE_DIRS}) +set(CMAKE_REQUIRED_LIBRARIES ${LIBXML2_LIBRARIES}) +check_symbol_exists(xmlTextReaderSetup "libxml/xmlreader.h" HAVE_XML_READER_SETUP) +check_c_source_compiles(" +#include +int main(void) { int foo = XML_PARSE_HUGE; (void)foo; return 0; }" + HAVE_XML_PARSE_HUGE) +unset(CMAKE_REQUIRED_INCLUDES) +unset(CMAKE_REQUIRED_LIBRARIES) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/config.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ltfs") + +# --- Common compile settings ------------------------------------------------- +# Definitions every translation unit gets, mirroring AM_CPPFLAGS/AM_CFLAGS. +add_compile_definitions( + _GNU_SOURCE + LTFS_CONFIG_FILE="${CMAKE_INSTALL_FULL_SYSCONFDIR}/ltfs.conf" + LTFS_BASE_DIR="${CMAKE_INSTALL_PREFIX}" +) +if(LTFS_ENABLE_SNMP) + add_compile_definitions(ENABLE_SNMP) +endif() +if(LTFS_NEW_LOCKING) + add_compile_definitions(USE_NEW_LOCKING) +endif() +if(NOT LTFS_LIVELINK) + add_compile_definitions(POSIXLINK_ONLY) +endif() +if(LTFS_DEBUG) + add_compile_definitions(DEBUG TRACE) +endif() +if(LTFS_ICU6X) + add_compile_definitions(ICU6x) +endif() +if(LTFS_SUPPORT_BUGGY_IFS AND (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")) + add_compile_definitions(SUPPORT_BUGGY_IFS) +endif() + +# -Wno-unused-parameter: callback signatures (FUSE operations, plugin ops) +# must keep parameters they do not use. +# -Wno-missing-field-initializers: designated initializers of operation and +# option tables intentionally leave the remaining members zeroed. +add_compile_options(-Wall -Wextra -Wno-unused-parameter + -Wno-missing-field-initializers -Wsign-compare -fsigned-char + -fno-strict-aliasing) +if(LTFS_WERROR) + add_compile_options(-Werror -Wno-deprecated-declarations) + if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8) + add_compile_options(-Wno-stringop-truncation) + endif() +endif() +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") + add_link_options(LINKER:--no-undefined LINKER:--as-needed) +endif() + +# config.h (binary dir) and the src tree on the include path for every target. +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src) + +# CRC files need SSE4.2 on capable x86; detected once, applied to the ltfs_crc +# object library (see src/tape_drivers). +set(LTFS_CRC_OPTIONS "") +if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i[3-6]86") + check_c_compiler_flag("-msse4.2" LTFS_HAVE_MSSE42) + if(LTFS_HAVE_MSSE42) + set(LTFS_CRC_OPTIONS -msse4.2 -D__SSE42__) + endif() +endif() + +# Helper modules. +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +include(LtfsMessages) +include(LtfsPlugin) + +enable_testing() + +# --- Subprojects ------------------------------------------------------------- +add_subdirectory(messages) +add_subdirectory(src) +add_subdirectory(conf) +add_subdirectory(man) +add_subdirectory(init.d) +add_subdirectory(tests) + +# pkg-config file (reuse the autotools template). +set(prefix "${CMAKE_INSTALL_PREFIX}") +set(exec_prefix "\${prefix}") +set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") +set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") +set(PACKAGE "ltfs") +set(VERSION "${LTFS_VERSION_FULL}") +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ltfs.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/ltfs.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ltfs.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/Makefile.am b/Makefile.am index 31ff904c..f7cec8cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,6 +36,7 @@ ACLOCAL_AMFLAGS = -I m4 nobase_pkginclude_HEADERS = config.h +EXTRA_DIST = VERSION SUBDIRS = messages src conf init.d man diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..db91859f --- /dev/null +++ b/VERSION @@ -0,0 +1,2 @@ +2.4.9.1 +(Prelim) diff --git a/cmake/LtfsMessages.cmake b/cmake/LtfsMessages.cmake new file mode 100644 index 00000000..bb257588 --- /dev/null +++ b/cmake/LtfsMessages.cmake @@ -0,0 +1,40 @@ +# ICU message-bundle compilation for the CMake build. Reuses the shared +# messages/make_message_src.sh so the genrb/pkgdata logic lives in one place. + +# ltfs_add_message_bundle() +# Compiles messages//*.txt into /messages/lib_dat.a and +# registers a build target msg_. Link it into a consumer with +# ltfs_link_message(). +function(ltfs_add_message_bundle name) + set(_src_dir "${CMAKE_SOURCE_DIR}/messages/${name}") + set(_out_dir "${CMAKE_BINARY_DIR}/messages") + set(_archive "${_out_dir}/lib${name}_dat.a") + file(GLOB _txt CONFIGURE_DEPENDS "${_src_dir}/*.txt") + + add_custom_command( + OUTPUT "${_archive}" + COMMAND ${CMAKE_COMMAND} -E make_directory "${_out_dir}" + COMMAND ${CMAKE_COMMAND} -E rm -f "${_archive}" + COMMAND ${CMAKE_COMMAND} -E env "GENRB=${ICU_GENRB_EXECUTABLE}" "PKGDATA=${ICU_PKGDATA_EXECUTABLE}" + sh "${CMAKE_SOURCE_DIR}/messages/make_message_src.sh" + "lib${name}_dat.a" "${_src_dir}" "${_out_dir}" + DEPENDS ${_txt} "${CMAKE_SOURCE_DIR}/messages/make_message_src.sh" + COMMENT "Compiling message bundle ${name}" + VERBATIM) + + add_custom_target(msg_${name} DEPENDS "${_archive}") + # Record the archive path for ltfs_link_message(). + set_property(GLOBAL PROPERTY ltfs_msg_archive_${name} "${_archive}") +endfunction() + +# ltfs_link_message( ) +# Links message bundle into (as a plain archive input, the +# way the autotools build put it on LDFLAGS) and orders the build after it. +function(ltfs_link_message target name) + get_property(_archive GLOBAL PROPERTY ltfs_msg_archive_${name}) + if(NOT _archive) + message(FATAL_ERROR "Unknown message bundle '${name}'") + endif() + target_link_libraries(${target} PRIVATE "${_archive}") + add_dependencies(${target} msg_${name}) +endfunction() diff --git a/cmake/LtfsPlugin.cmake b/cmake/LtfsPlugin.cmake new file mode 100644 index 00000000..d41f3063 --- /dev/null +++ b/cmake/LtfsPlugin.cmake @@ -0,0 +1,36 @@ +# Helper for LTFS runtime plugins (tape backends, I/O schedulers, key managers). +# Reproduces the autotools "-module -avoid-version" behavior: an unversioned +# shared module named lib.so, installed under /ltfs. + +# ltfs_add_plugin( +# SOURCES +# [MSG ] +# [CRC] # link the SSE-optimized CRC objects +# [INCLUDES ] +# [DEFINES ] +# [LIBS ]) +function(ltfs_add_plugin target) + cmake_parse_arguments(P "CRC" "MSG" "SOURCES;INCLUDES;DEFINES;LIBS" ${ARGN}) + + add_library(${target} MODULE ${P_SOURCES}) + set_target_properties(${target} PROPERTIES + PREFIX "" # name is exactly .so, no extra lib prefix + SUFFIX ".so" # plugins are .so even on macOS (loader expects it) + OUTPUT_NAME "${target}") + + target_link_libraries(${target} PRIVATE ltfs ${P_LIBS}) + if(P_CRC) + target_link_libraries(${target} PRIVATE ltfs_crc) + endif() + if(P_INCLUDES) + target_include_directories(${target} PRIVATE ${P_INCLUDES}) + endif() + if(P_DEFINES) + target_compile_definitions(${target} PRIVATE ${P_DEFINES}) + endif() + if(P_MSG) + ltfs_link_message(${target} ${P_MSG}) + endif() + + install(TARGETS ${target} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/ltfs) +endfunction() diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 00000000..5ecdcb35 --- /dev/null +++ b/cmake/config.h.in @@ -0,0 +1,34 @@ +/* config.h generated by CMake: the autotools config.h macros the sources use. + * Feature toggles are passed on the command line, as in the autotools build. */ +#ifndef LTFS_CMAKE_CONFIG_H +#define LTFS_CMAKE_CONFIG_H + +#define PACKAGE "@LTFS_PACKAGE_TARNAME@" +#define PACKAGE_NAME "@LTFS_PACKAGE_NAME@" +#define PACKAGE_TARNAME "@LTFS_PACKAGE_TARNAME@" +#define PACKAGE_VERSION "@LTFS_VERSION_FULL@" +#define PACKAGE_STRING "@LTFS_PACKAGE_NAME@ @LTFS_VERSION_FULL@" +#define PACKAGE_BUGREPORT "@LTFS_BUGREPORT@" +#define PACKAGE_URL "" +#define VERSION "@LTFS_VERSION_FULL@" + +/* Referenced by the sources */ +#cmakedefine HAVE_SYS_SYSCTL_H 1 +#cmakedefine HAVE_XML_PARSE_HUGE 1 +#cmakedefine HAVE_XML_READER_SETUP 1 +#define SIZEOF_TIME_T @SIZEOF_TIME_T@ + +/* Header availability (parity with autotools; mostly unreferenced) */ +#cmakedefine HAVE_FCNTL_H 1 +#cmakedefine HAVE_LIMITS_H 1 +#cmakedefine HAVE_STDDEF_H 1 +#cmakedefine HAVE_STDINT_H 1 +#cmakedefine HAVE_STDLIB_H 1 +#cmakedefine HAVE_STRING_H 1 +#cmakedefine HAVE_SYS_IOCTL_H 1 +#cmakedefine HAVE_SYS_MOUNT_H 1 +#cmakedefine HAVE_SYS_TIME_H 1 +#cmakedefine HAVE_TERMIOS_H 1 +#cmakedefine HAVE_UNISTD_H 1 + +#endif /* LTFS_CMAKE_CONFIG_H */ diff --git a/conf/CMakeLists.txt b/conf/CMakeLists.txt new file mode 100644 index 00000000..28d3ef7b --- /dev/null +++ b/conf/CMakeLists.txt @@ -0,0 +1,35 @@ +# Generate ltfs.conf from ltfs.conf.in, reproducing the autotools multi-pass +# sed substitution (__PLATFORM_DRIVERS__, __LIBDIR__, __DEFAULT_*__, +# __CONFDIR__). +set(_plat_drivers "") +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(_plat_drivers "plugin tape sg __LIBDIR__/ltfs/libtape-sg.so") + if(LTFS_ENABLE_LINTAPE) + string(APPEND _plat_drivers "\nplugin tape lin_tape __LIBDIR__/ltfs/libtape-lin_tape.so") + endif() +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(_plat_drivers "plugin tape iokit __LIBDIR__/ltfs/libtape-iokit.so") +elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + set(_plat_drivers "plugin tape cam __LIBDIR__/ltfs/libtape-cam.so") +elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") + set(_plat_drivers "plugin tape scsipi-ibmtape __LIBDIR__/ltfs/libtape-scsipi-ibmtape.so") +endif() + +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/ltfs.conf.in" _conf) +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/ltfs.conf.in") +string(REPLACE "__PLATFORM_DRIVERS__" "${_plat_drivers}" _conf "${_conf}") +string(REPLACE "__LIBDIR__" "${CMAKE_INSTALL_FULL_LIBDIR}" _conf "${_conf}") +string(REPLACE "__DEFAULT_TAPE__" "${DEFAULT_TAPE}" _conf "${_conf}") +string(REPLACE "__DEFAULT_IOSCHED__" "${DEFAULT_IOSCHED}" _conf "${_conf}") +string(REPLACE "__DEFAULT_KMI__" "${DEFAULT_KMI}" _conf "${_conf}") +string(REPLACE "__CONFDIR__" "${CMAKE_INSTALL_FULL_SYSCONFDIR}" _conf "${_conf}") +file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ltfs.conf" CONTENT "${_conf}") + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ltfs.conf" + DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}") +# ltfs.conf.local holds user edits: install it only when absent. +install(CODE " + if(NOT EXISTS \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_SYSCONFDIR}/ltfs.conf.local\") + file(INSTALL \"${CMAKE_CURRENT_SOURCE_DIR}/ltfs.conf.local\" + DESTINATION \"${CMAKE_INSTALL_FULL_SYSCONFDIR}\") + endif()") diff --git a/configure.ac b/configure.ac index 75c7a535..3e4ec856 100644 --- a/configure.ac +++ b/configure.ac @@ -36,7 +36,12 @@ dnl dnl LTFS configure.ac. dnl -AC_INIT([LTFS], [2.4.9.0 (Prelim)], IBM corporation.) +dnl Package version is kept in the top-level VERSION file (line 1: numeric +dnl X.Y.Z.W, line 2: optional suffix) so the autotools and CMake builds share +dnl a single source of truth. The awk joins them into "X.Y.Z.W suffix". +AC_INIT([LTFS], + m4_esyscmd_s([awk 'NR==1{n=$0} NR==2{s=$0} END{if(s=="")printf "%s",n; else printf "%s %s",n,s}' VERSION]), + IBM corporation.) AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIRS([m4]) diff --git a/init.d/CMakeLists.txt b/init.d/CMakeLists.txt new file mode 100644 index 00000000..1c694b21 --- /dev/null +++ b/init.d/CMakeLists.txt @@ -0,0 +1,9 @@ +# Service script, installed only when absent (it may carry local edits). +install(CODE " + if(NOT EXISTS \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/ltfs/ltfs\") + file(INSTALL \"${CMAKE_CURRENT_SOURCE_DIR}/ltfs\" + DESTINATION \"${CMAKE_INSTALL_FULL_DATADIR}/ltfs\" + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE) + endif()") diff --git a/man/CMakeLists.txt b/man/CMakeLists.txt new file mode 100644 index 00000000..e3c338c9 --- /dev/null +++ b/man/CMakeLists.txt @@ -0,0 +1,4 @@ +install(FILES mkltfs.8 ltfsck.8 ltfs-sde.8 + DESTINATION ${CMAKE_INSTALL_MANDIR}/man8) +install(FILES ltfs_ordered_copy.1 + DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) diff --git a/messages/CMakeLists.txt b/messages/CMakeLists.txt new file mode 100644 index 00000000..3dfd5924 --- /dev/null +++ b/messages/CMakeLists.txt @@ -0,0 +1,28 @@ +# Compile the ICU message bundles. Platform bundles (lin_tape, iokit) are +# added when those backends build. +set(LTFS_MESSAGE_BUNDLES + libltfs + internal_error + tape_common + bin_ltfs + bin_mkltfs + bin_ltfsck + iosched_fcfs + iosched_unified + kmi_simple + kmi_flatfile + tape_generic_file + tape_generic_itdtimg) + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + list(APPEND LTFS_MESSAGE_BUNDLES tape_linux_sg) + if(LTFS_ENABLE_LINTAPE) + list(APPEND LTFS_MESSAGE_BUNDLES tape_linux_lin_tape) + endif() +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + list(APPEND LTFS_MESSAGE_BUNDLES tape_iokit) +endif() + +foreach(_b ${LTFS_MESSAGE_BUNDLES}) + ltfs_add_message_bundle(${_b}) +endforeach() diff --git a/messages/Makefile.am b/messages/Makefile.am index 3d712e00..39e572d4 100644 --- a/messages/Makefile.am +++ b/messages/Makefile.am @@ -80,6 +80,6 @@ if CHK_MESSAGE endif clean-local: - rm -rf $(RESOURCES) */work + rm -rf $(RESOURCES) */work .work-* rm -f ../src/ltfsmsg.h rm -f *.la diff --git a/messages/internal_error/root.txt b/messages/internal_error/root.txt index 081a81e3..ed0f0996 100644 --- a/messages/internal_error/root.txt +++ b/messages/internal_error/root.txt @@ -309,6 +309,7 @@ root:table { I5048E:string{ "Unexpected partition map in a label." } I5049E:string{ "Unexpected blocksize in a label." } I5050E:string{ "Unexpected compression in a label." } + I5051E:string{ "Directory nesting in the index is too deep." } // Special error codes I9997E:string{ "Child process error (ltfsck/mkltfs): %s (%d)." } diff --git a/messages/libltfs/root.txt b/messages/libltfs/root.txt index e1b94ab6..96f0e386 100644 --- a/messages/libltfs/root.txt +++ b/messages/libltfs/root.txt @@ -836,6 +836,7 @@ v 17292I:string { "Current position is (%llu, %llu), Error position is (%llu, %llu)." } 17293E:string { "Position mismatch. Cached tape position = %llu. Current tape position = %llu." } 17294I:string { "Continue signal (%d) received" } + 17295E:string { "XML parser: directory nesting is too deep (limit %d)." } // For Debug 19999I:string { "%s %s %d." } diff --git a/messages/make_message_src.sh b/messages/make_message_src.sh index 82488e81..b2e7e7b5 100755 --- a/messages/make_message_src.sh +++ b/messages/make_message_src.sh @@ -1,38 +1,44 @@ #!/bin/sh +# Compile an ICU message bundle (a directory of *.txt resource files) into a +# static archive lib_dat.a using genrb + pkgdata. +# +# Usage: make_message_src.sh [src_bundle_dir] [out_dir] +# e.g. libbin_ltfs_dat.a; the bundle name is derived from it +# [src_bundle_dir] directory holding the *.txt files (default: ./) +# [out_dir] directory to write the archive into (default: .) +# +# genrb/pkgdata are taken from $GENRB/$PKGDATA when set (the build system +# passes the paths it discovered); otherwise they are guessed per-OS. This +# script is shared by the autotools and CMake builds: the one-argument form +# preserves the historical in-source layout used by messages/Makefile.am. + set -e KERNEL_NAME=`uname -s` + +# Resolve the ICU tools, honoring the environment first. if [ "$KERNEL_NAME" = "Darwin" ]; then ICU_FRAMEWORK=/Library/Frameworks/ICU.framework - - if [ -d ${ICU_FRAMEWORK} ]; then - export PATH=${PATH}:${ICU_FRAMEWORK}/Versions/Current/usr/bin - export DYLD_LIBRARY_PATH=${ICU_FRAMEWORK}/Versions/Current/usr/lib - GENRB=${ICU_FRAMEWORK}/Versions/Current/usr/bin/genrb - PKGDATA=${ICU_FRAMEWORK}/Versions/Current/usr/bin/pkgdata + if [ -d "${ICU_FRAMEWORK}" ]; then + export PATH="${PATH}:${ICU_FRAMEWORK}/Versions/Current/usr/bin" + export DYLD_LIBRARY_PATH="${ICU_FRAMEWORK}/Versions/Current/usr/lib" + : "${GENRB:=${ICU_FRAMEWORK}/Versions/Current/usr/bin/genrb}" + : "${PKGDATA:=${ICU_FRAMEWORK}/Versions/Current/usr/bin/pkgdata}" else - GENRB=genrb - PKGDATA=pkgdata + : "${GENRB:=genrb}" + : "${PKGDATA:=pkgdata}" fi elif [ "$KERNEL_NAME" = "FreeBSD" ]; then - GENRB=genrb - PKGDATA=/usr/local/bin/pkgdata + : "${GENRB:=genrb}" + : "${PKGDATA:=/usr/local/bin/pkgdata}" else - if [ -x /usr/bin/genrb ]; then - GENRB=/usr/bin/genrb - else - GENRB=genrb - fi - if [ -x /usr/bin/pkgdata ]; then - PKGDATA=/usr/bin/pkgdata - else - PKGDATA=pkgdata - fi + if [ -x /usr/bin/genrb ]; then : "${GENRB:=/usr/bin/genrb}"; else : "${GENRB:=genrb}"; fi + if [ -x /usr/bin/pkgdata ]; then : "${PKGDATA:=/usr/bin/pkgdata}"; else : "${PKGDATA:=pkgdata}"; fi fi -if [ "$#" -ne "1" ]; then - echo "Usage: $0 object_file" +if [ "$#" -lt "1" ]; then + echo "Usage: $0 archive_name [src_bundle_dir] [out_dir]" exit 1 fi @@ -46,65 +52,64 @@ case $KERNEL_NAME in ;; esac -cd ${BASENAME} +# Source bundle dir and output dir default to the historical in-source layout. +SRC_DIR=${2:-./${BASENAME}} +OUT_DIR=${3:-.} +mkdir -p "$OUT_DIR" +OUT_DIR=`cd "$OUT_DIR" && pwd` # absolute, survives the work-dir cd +SRC_DIR=`cd "$SRC_DIR" && pwd` make_obj() { echo "Processing ${BASENAME}" - # Create a fresh work directory - if [ -d work ]; then - rm -rf work - fi - mkdir work + WORK="${OUT_DIR}/.work-${BASENAME}" + rm -rf "$WORK" + mkdir -p "$WORK" - # Generate files - ${GENRB} -d work -q *.txt - cd work - ls *.res >packagelist.txt - ${PKGDATA} -p ${BASENAME} -m static -q packagelist.txt >/dev/null + # Generate the resource files, then package them statically. + ${GENRB} -d "$WORK" -q "${SRC_DIR}"/*.txt + ( cd "$WORK" && ls *.res > packagelist.txt && \ + ${PKGDATA} -p ${BASENAME} -m static -q packagelist.txt >/dev/null ) case $KERNEL_NAME in MINGW32_NT*) - mv ${BASENAME}.dat ../../ + mv "$WORK/${BASENAME}.dat" "$OUT_DIR/" ;; FreeBSD) - # pkgdata with -m static generates an ar(1) archive - # with several object files on FreeBSD. To avoid - # reworking the makefiles for all OSes, just rename - # the archive to match the regular convention. The - # linker handles it without a problem. - mv lib${BASENAME}.a ../../lib${BASENAME}_dat.a + # pkgdata -m static produces an ar(1) archive with several + # object files on FreeBSD; rename it to the regular convention. + mv "$WORK/lib${BASENAME}.a" "$OUT_DIR/lib${BASENAME}_dat.a" ;; NetBSD) - # generate libtool archive for later linking - mv lib${BASENAME}.a ../../lib${BASENAME}_dat.a + # Generate a libtool archive for later linking. + mv "$WORK/lib${BASENAME}.a" "$OUT_DIR/lib${BASENAME}_dat.a" OBJFILE=${BASENAME}_dat.o LTFILE=${BASENAME}_dat.lo - mkdir -p .libs ../../.libs - mv ${OBJFILE} .libs + mkdir -p "$WORK/.libs" "$OUT_DIR/.libs" + mv "$WORK/${OBJFILE}" "$WORK/.libs" LTVERS=`libtool --version | sed -e 's/^\([^ ]*\) (GNU \(.*\)) \(.*\)$$/\1 - GNU \2 \3/' -e q` - echo "# ${OBJFILE} - a libtool object file" > ${LTFILE} - echo "# Generated by ${LTVERS}" >> ${LTFILE} - echo "pic_object='.libs/${OBJFILE}'" >> ${LTFILE} - echo "non_pic_object=none" >> ${LTFILE} - libtool --mode=link --tag=CC cc -o ../../lib${BASENAME}_dat.la ${LTFILE} - cp ../../lib${BASENAME}_dat.a ../../.libs + echo "# ${OBJFILE} - a libtool object file" > "$OUT_DIR/${LTFILE}" + echo "# Generated by ${LTVERS}" >> "$OUT_DIR/${LTFILE}" + echo "pic_object='.libs/${OBJFILE}'" >> "$OUT_DIR/${LTFILE}" + echo "non_pic_object=none" >> "$OUT_DIR/${LTFILE}" + cp "$WORK/.libs/${OBJFILE}" "$OUT_DIR/.libs/" + ( cd "$OUT_DIR" && libtool --mode=link --tag=CC cc -o "lib${BASENAME}_dat.la" "${LTFILE}" ) + cp "$OUT_DIR/lib${BASENAME}_dat.a" "$OUT_DIR/.libs" ;; *) - mv ${BASENAME}_dat.o ../../lib${BASENAME}_dat.a + mv "$WORK/${BASENAME}_dat.o" "$OUT_DIR/lib${BASENAME}_dat.a" ;; esac - # Clean up - cd .. - rm -rf work + rm -rf "$WORK" } -# Check whether we need to do anything -if [ -f "../$1" ]; then - for file in *.txt; do - if [ "$file" -nt "../$1" ]; then +# Rebuild only when a source file is newer than the existing archive. +OUT_FILE="$OUT_DIR/$1" +if [ -f "$OUT_FILE" ]; then + for file in "$SRC_DIR"/*.txt; do + if [ "$file" -nt "$OUT_FILE" ]; then make_obj exit 0 fi diff --git a/messages/tape_linux_sg/root.txt b/messages/tape_linux_sg/root.txt index 981fdc1b..8d22abf8 100644 --- a/messages/tape_linux_sg/root.txt +++ b/messages/tape_linux_sg/root.txt @@ -138,6 +138,9 @@ root:table { 30295I:string { "Have unstable TUR response, start over (Cur = %d, Prev = %d)." } 30296I:string { "Capturing a stable TUR at line %d." } 30297W:string { "Cannot retrieve drive dump: failed to communicate with drive. Tried (%d) times." } + 30298W:string { "Retrying %s operation due Power On-Reset event reached. Tried (%d) times." } + 30299E:string { "Could not clear POR status, device might be faulty, ret: (%d)." } + 30300E:string { "Could resolve block position after failure, ret: (%d)." } 30392D:string { "Backend %s %s." } 30393D:string { "Backend %s: %d %s." } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..50089da6 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,47 @@ +add_subdirectory(libltfs) + +# CRC routines compiled with SSE4.2 where available (replaces the autotools +# per-backend symlink + CRC_OPTIMIZE compile rule). One object library, linked +# into every tape backend. +add_library(ltfs_crc OBJECT + tape_drivers/reed_solomon_crc.c + tape_drivers/crc32c_crc.c) +target_include_directories(ltfs_crc PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/tape_drivers) +if(LTFS_CRC_OPTIONS) + target_compile_options(ltfs_crc PRIVATE ${LTFS_CRC_OPTIONS}) +endif() +set_target_properties(ltfs_crc PROPERTIES POSITION_INDEPENDENT_CODE ON) + +# I/O scheduler and key-manager plugins (always built). +add_subdirectory(iosched) +add_subdirectory(kmi) + +# Tape backends: the file simulator and the image driver are portable; the +# real device backends are platform-specific. +add_subdirectory(tape_drivers/generic/file) +add_subdirectory(tape_drivers/generic/itdtimg) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + add_subdirectory(tape_drivers/linux/sg) + if(LTFS_ENABLE_LINTAPE) + add_subdirectory(tape_drivers/linux/lin_tape) + endif() +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + add_subdirectory(tape_drivers/osx/iokit) +elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + # Not ported to CMake yet; use the autotools build for this backend. + message(STATUS "LTFS: the cam tape backend has no CMake target yet, skipping") +elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") + message(STATUS "LTFS: the scsipi-ibmtape tape backend has no CMake target yet, skipping") +endif() + +add_subdirectory(utils) + +# The ltfs mount executable. +add_executable(ltfs_bin main.c ltfs_fuse.c) +set_target_properties(ltfs_bin PROPERTIES OUTPUT_NAME ltfs) +set_target_properties(ltfs_bin PROPERTIES POSITION_INDEPENDENT_CODE ON ENABLE_EXPORTS ON) +target_link_libraries(ltfs_bin PRIVATE ltfs) +ltfs_link_message(ltfs_bin bin_ltfs) +install(TARGETS ltfs_bin RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/iosched/CMakeLists.txt b/src/iosched/CMakeLists.txt new file mode 100644 index 00000000..15ee4e49 --- /dev/null +++ b/src/iosched/CMakeLists.txt @@ -0,0 +1,7 @@ +ltfs_add_plugin(libiosched-fcfs + SOURCES fcfs.c + MSG iosched_fcfs) + +ltfs_add_plugin(libiosched-unified + SOURCES unified.c cache_manager.c + MSG iosched_unified) diff --git a/src/kmi/CMakeLists.txt b/src/kmi/CMakeLists.txt new file mode 100644 index 00000000..d9927e33 --- /dev/null +++ b/src/kmi/CMakeLists.txt @@ -0,0 +1,8 @@ +ltfs_add_plugin(libkmi-simple + SOURCES simple.c key_format_ltfs.c + DEFINES KMI_SIMPLE + MSG kmi_simple) + +ltfs_add_plugin(libkmi-flatfile + SOURCES flatfile.c key_format_ltfs.c + MSG kmi_flatfile) diff --git a/src/libltfs/CMakeLists.txt b/src/libltfs/CMakeLists.txt new file mode 100644 index 00000000..43830b9e --- /dev/null +++ b/src/libltfs/CMakeLists.txt @@ -0,0 +1,102 @@ +# The core LTFS library: a versioned shared object that the executables and +# all runtime plugins link against. +add_library(ltfs SHARED + ltfs.c + ltfs_internal.c + ltfs_fsops.c + ltfs_fsops_raw.c + ltfssnmp.c + fs.c + xml_common.c + xml_writer.c + xml_reader.c + xml_writer_libltfs.c + xml_reader_libltfs.c + label.c + base64.c + tape.c + iosched.c + dcache.c + kmi.c + pathname.c + index_criteria.c + xattr.c + ltfslogging.c + ltfstrace.c + ltfs_thread.c + config_file.c + plugin.c + periodic_sync.c + arch/uuid_internal.c + arch/filename_handling.c + arch/time_internal.c + arch/arch_info.c + arch/errormap.c) + +# Versioning is taken from the autotools build, which passes no -version-info +# (libtool default 0.0.0). Both builds should probably move to real SOVERSIONs, +# bumped on incompatible ABI changes. +set_target_properties(ltfs PROPERTIES + VERSION 0.0.0 + SOVERSION 0 + MACHO_COMPATIBILITY_VERSION 1 + MACHO_CURRENT_VERSION 1.0) + +# Dependencies are PUBLIC so executables and plugins that link ltfs inherit +# the include paths and link flags, mirroring the autotools "flags are +# global" arrangement. All are imported targets. +target_link_libraries(ltfs PUBLIC + PkgConfig::FUSE + LibXml2::LibXml2 + PkgConfig::UUID + ICU::uc ICU::i18n ICU::io ICU::data + Threads::Threads + ${CMAKE_DL_LIBS}) +if(RT_LIBRARY) + target_link_libraries(ltfs PUBLIC ${RT_LIBRARY}) +endif() +if(Backtrace_LIBRARIES) + target_link_libraries(ltfs PUBLIC ${Backtrace_LIBRARIES}) +endif() +if(LTFS_ENABLE_SNMP) + target_link_libraries(ltfs PUBLIC ${LTFS_SNMP_LIBS}) +endif() + +ltfs_link_message(ltfs libltfs) +ltfs_link_message(ltfs internal_error) +ltfs_link_message(ltfs tape_common) + +install(TARGETS ltfs LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +# Public headers (the autotools nobase_pkginclude_HEADERS set), preserving the +# libltfs/ and tape_drivers/ subpaths under /ltfs. +set(_pub_hdrs + libltfs/config_file.h libltfs/dcache_ops.h libltfs/iosched_ops.h + libltfs/kmi_ops.h libltfs/ltfs_fsops.h libltfs/tape_ops.h + libltfs/ltfs_error.h libltfs/ltfs.h libltfs/ltfslogging.h + libltfs/ltfstrace.h libltfs/ltfs_types.h libltfs/ltfs_thread.h + libltfs/ltfs_locking.h libltfs/ltfs_locking_old.h libltfs/ltfs_locking_new.h + libltfs/queue.h libltfs/uthash.h libltfs/uthash_ext.h libltfs/plugin.h + libltfs/tape.h libltfs/xml.h + libltfs/arch/signal_internal.h libltfs/arch/arch_info.h + libltfs/arch/time_internal.h libltfs/arch/errormap.h + libltfs/arch/ltfs_arch_ops.h + tape_drivers/ibm_tape.h tape_drivers/spc_op_codes.h + tape_drivers/ssc_op_codes.h tape_drivers/tape_drivers.h) +foreach(_h ${_pub_hdrs}) + get_filename_component(_subdir "${_h}" DIRECTORY) + install(FILES "${CMAKE_SOURCE_DIR}/src/${_h}" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ltfs/${_subdir}") +endforeach() + +# SNMP MIB definitions. +if(LTFS_ENABLE_SNMP) + install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/LTFS-MIB.txt" + DESTINATION "${CMAKE_INSTALL_PREFIX}/share/snmp") + # LtfsSnmpTrapDef.txt holds user edits: install it only when absent. + install(CODE " + if(NOT EXISTS \"\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/share/snmp/LtfsSnmpTrapDef.txt\") + file(INSTALL \"${CMAKE_CURRENT_SOURCE_DIR}/LtfsSnmpTrapDef.txt\" + DESTINATION \"${CMAKE_INSTALL_PREFIX}/share/snmp\") + endif()") +endif() diff --git a/src/libltfs/arch/errormap.c b/src/libltfs/arch/errormap.c index bc64bc84..1c05aca1 100644 --- a/src/libltfs/arch/errormap.c +++ b/src/libltfs/arch/errormap.c @@ -342,6 +342,7 @@ static struct error_map fuse_error_list[] = { { LTFS_XML_WRONG_PART_MAP, "I5048E", EINVAL}, { LTFS_XML_WRONG_BLOCKSIZE, "I5049E", EINVAL}, { LTFS_XML_WRONG_COMP, "I5050E", EINVAL}, + { LTFS_XML_DEEP_NESTING, "I5051E", EINVAL}, { EDEV_NO_SENSE, "D0000E", EIO}, { EDEV_OVERRUN, "D0002E", EIO}, { EDEV_UNDERRUN, "D0003E", ENODATA}, diff --git a/src/libltfs/ltfs_endian.h b/src/libltfs/ltfs_endian.h index 9296c10c..fa3c619a 100644 --- a/src/libltfs/ltfs_endian.h +++ b/src/libltfs/ltfs_endian.h @@ -48,6 +48,9 @@ #ifndef __LTFS_ENDIAN_H__ #define __LTFS_ENDIAN_H__ +#include +#include + /* TODO: verify that this is correct for mingw */ #ifdef mingw_PLATFORM #include @@ -55,54 +58,79 @@ #include #endif /* mingw_PLATFORM */ +/* + * These were function-like macros that cast the buffer to uint16_t/uint32_t and + * dereferenced it directly. Buffers are byte arrays accessed at arbitrary offsets + * (e.g. cdb + 3), so those casts performed unaligned accesses, which are undefined + * behaviour and fault on architectures that require natural alignment. They are now + * static inline functions that copy through memcpy; the compiler lowers each fixed + * size memcpy to a single load/store (plus a byte swap), so there is no overhead. + */ + /** * Convert a uint64_t value (src) to big endian and store it in the 8-byte buffer * pointed to by dest. */ -#define ltfs_u64tobe(dest, src) \ - do { \ - uint32_t *tmp = (uint32_t *)(dest); \ - uint64_t stmp = (src); \ - tmp[0] = htonl((stmp >> 32) & 0xffffffff); \ - tmp[1] = htonl(stmp & 0xffffffff); \ - } while (0) +static inline void ltfs_u64tobe(void *dest, uint64_t src) +{ + uint32_t tmp[2]; + tmp[0] = htonl((uint32_t)((src >> 32) & 0xffffffff)); + tmp[1] = htonl((uint32_t)(src & 0xffffffff)); + memcpy(dest, tmp, sizeof(tmp)); +} /** * Convert a uint32_t value (src) to big endian and store it in the 4-byte buffer * pointed to by dest. */ -#define ltfs_u32tobe(dest, src) \ - do { \ - *((uint32_t *)(dest)) = htonl((src)); \ - } while (0) +static inline void ltfs_u32tobe(void *dest, uint32_t src) +{ + uint32_t tmp = htonl(src); + memcpy(dest, &tmp, sizeof(tmp)); +} /** * Convert a uint16_t value (src) to big endian and store it in the 2-byte buffer * pointed to by dest. */ -#define ltfs_u16tobe(dest, src) \ - do { \ - *((uint16_t *)(dest)) = htons((src)); \ - } while (0) +static inline void ltfs_u16tobe(void *dest, uint16_t src) +{ + uint16_t tmp = htons(src); + memcpy(dest, &tmp, sizeof(tmp)); +} /** * Convert a big endian 64-bit unsigned integer (pointed to by buf) * to a uint64_t in local byte order. */ -#define ltfs_betou64(buf) \ - (((uint64_t)ntohl(*((uint32_t *)(buf)))) << 32) + (uint64_t)ntohl(*(((uint32_t *)(buf))+1)) +static inline uint64_t ltfs_betou64(const void *buf) +{ + uint32_t tmp[2]; + memcpy(tmp, buf, sizeof(tmp)); + return ((uint64_t)ntohl(tmp[0]) << 32) | (uint64_t)ntohl(tmp[1]); +} /** * Convert a big endian 32-bit unsigned integer (pointed to by buf) * to a uint32_t in local byte order. */ -#define ltfs_betou32(buf) ntohl(*((uint32_t *)(buf))) +static inline uint32_t ltfs_betou32(const void *buf) +{ + uint32_t tmp; + memcpy(&tmp, buf, sizeof(tmp)); + return ntohl(tmp); +} /** * Convert a big endian 16-bit unsigned integer (pointed to by buf) * to a uint16_t in local byte order. */ -#define ltfs_betou16(buf) ntohs(*((uint16_t *)(buf))) +static inline uint16_t ltfs_betou16(const void *buf) +{ + uint16_t tmp; + memcpy(&tmp, buf, sizeof(tmp)); + return ntohs(tmp); +} #endif /* __LTFS_ENDIAN_H__ */ diff --git a/src/libltfs/ltfs_error.h b/src/libltfs/ltfs_error.h index 6e7fb341..025d2621 100644 --- a/src/libltfs/ltfs_error.h +++ b/src/libltfs/ltfs_error.h @@ -317,6 +317,7 @@ #define LTFS_XML_WRONG_PART_MAP 5048 /* Unexpected partition map in a label */ #define LTFS_XML_WRONG_BLOCKSIZE 5049 /* Unexpected blocksize in a label */ #define LTFS_XML_WRONG_COMP 5050 /* Unexpected compression in a label */ +#define LTFS_XML_DEEP_NESTING 5051 /* Directory nesting in the index is too deep */ #define LTFS_ERR_MAX 19999 diff --git a/src/libltfs/tape.c b/src/libltfs/tape.c index 255ca2a2..3ac80318 100644 --- a/src/libltfs/tape.c +++ b/src/libltfs/tape.c @@ -3,7 +3,7 @@ ** OO_Copyright_BEGIN ** ** -** Copyright 2010, 2025 IBM Corp. All rights reserved. +** Copyright 2010, 2026 IBM Corp. All rights reserved. ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions @@ -73,6 +73,7 @@ #include "ltfs_error.h" +#include "tape_drivers/ibm_tape.h" #include "tape.h" #include "tape_ops.h" #include "ltfs_endian.h" @@ -1245,7 +1246,7 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool } if (ltfs_caught_sigcont()) { - // Unset flag to avoid checking it again if it is not needed + // Unset flag to avoid checking it again if it is not needed ltfs_sigcont_set(false); ret_for_current_position = tape_get_position_from_drive(dev, ¤t_position); @@ -1470,7 +1471,7 @@ static int tape_update_density(struct device_data *dev, int density_code) mp_read_write_ctrl[1] = 0x00; mp_read_write_ctrl[26] = density_code; - ret = dev->backend->modeselect(dev->backend_data, mp_read_write_ctrl, TC_MP_READ_WRITE_CTRL_SIZE); + ret = dev->backend->modeselect(dev->backend_data, mp_read_write_ctrl, TC_MP_READ_WRITE_CTRL_SIZE, false); if (ret < 0) { ltfsmsg(LTFS_ERR, 17239E, "modeselect", ret); } @@ -1577,7 +1578,8 @@ int tape_format(struct device_data *dev, tape_partition_t index_part, int densit ret = dev->backend->modeselect( dev->backend_data, mp_medium_partition, - page_length + page_length, + false ); /* Issue Format Medium (Make partitioned medium) */ @@ -1767,7 +1769,7 @@ int tape_set_cart_coherency(struct device_data *dev, const tape_partition_t part struct tc_coherency *coh) { int ret; - unsigned char coh_data[TC_MAM_PAGE_COHERENCY_SIZE + TC_MAM_PAGE_HEADER_SIZE]; + unsigned char coh_data[TC_MAM_PAGE_COHERENCY_SIZE + TC_MAM_PAGE_HEADER_SIZE] = {0}; CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); @@ -2426,9 +2428,11 @@ int tape_set_pews(struct device_data *dev, bool set_value) int ret; unsigned char mp_dev_config_ext[TC_MP_DEV_CONFIG_EXT_SIZE]; struct tc_remaining_cap cap; + struct tc_drive_info tcinfo; uint64_t half_of_max_p0 = 0; static const uint16_t max_pews = 0xFFFF; uint16_t pews; + bool savable = false; CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); @@ -2472,7 +2476,12 @@ int tape_set_pews(struct device_data *dev, bool set_value) mp_dev_config_ext[22] = (uint8_t)(pews >> 8 & 0xFF); mp_dev_config_ext[23] = (uint8_t)(pews & 0xFF); - ret = dev->backend->modeselect(dev->backend_data, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE); + if (tape_get_info(dev, &tcinfo) == 0) { + if (!strcmp(IBM_VENDOR_ID, tcinfo.vendor)) { + savable = true; + } + } + ret = dev->backend->modeselect(dev->backend_data, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE, savable); if (ret < 0) ltfsmsg(LTFS_ERR, 17103E, ret); return 0; @@ -2530,6 +2539,8 @@ int tape_enable_append_only_mode(struct device_data *dev, bool enable) bool loaded = false; bool supported = true; unsigned char mp_dev_config_ext[TC_MP_DEV_CONFIG_EXT_SIZE]; + struct tc_drive_info tcinfo; + bool savable = false; CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG); @@ -2588,7 +2599,12 @@ int tape_enable_append_only_mode(struct device_data *dev, bool enable) mp_dev_config_ext[21] &= 0x0F; mp_dev_config_ext[21] |= enable ? 0x10 : 0x00; - ret = dev->backend->modeselect(dev->backend_data, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE); + if (tape_get_info(dev, &tcinfo) == 0) { + if (!strcmp(IBM_VENDOR_ID, tcinfo.vendor)) { + savable = true; + } + } + ret = dev->backend->modeselect(dev->backend_data, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE, savable); if (ret < 0) { if (ret == -EDEV_ILLEGAL_REQUEST) { ltfsmsg(LTFS_INFO, 17266I); @@ -3137,7 +3153,7 @@ int tape_set_attribute_to_cm(struct device_data* dev, if (!attr_data) { return -LTFS_NO_MEMORY; } - + /* fill the MAM header information */ ltfs_u16tobe(attr_data, type); /* set attribute type */ attr_data[2] = format; /* set data format type */ diff --git a/src/libltfs/tape_ops.h b/src/libltfs/tape_ops.h index 34c7a128..14b129fb 100644 --- a/src/libltfs/tape_ops.h +++ b/src/libltfs/tape_ops.h @@ -631,7 +631,7 @@ struct tape_ops { * @return 0 on success or a negative value on error. Backends for which Mode Select is * meaningless should return 0. */ - int (*modeselect)(void *device, unsigned char *buf, const size_t size); + int (*modeselect)(void *device, unsigned char *buf, const size_t size, bool save); /** * Send a SCSI Reserve Unit command to a device. diff --git a/src/libltfs/xml_reader.c b/src/libltfs/xml_reader.c index c9ddbb4a..ed1efe05 100644 --- a/src/libltfs/xml_reader.c +++ b/src/libltfs/xml_reader.c @@ -115,7 +115,7 @@ int xml_next_tag(xmlTextReaderPtr reader, const char *containing_name, return ret; *name = (const char *)xmlTextReaderConstName(reader); *type = xmlTextReaderNodeType(reader); - } while (strcmp(*name, containing_name) && (*type) != XML_ELEMENT_NODE); + } while (! *name || (strcmp(*name, containing_name) && (*type) != XML_ELEMENT_NODE)); return 0; } diff --git a/src/libltfs/xml_reader_libltfs.c b/src/libltfs/xml_reader_libltfs.c index ae5b9cf2..3870a0f7 100644 --- a/src/libltfs/xml_reader_libltfs.c +++ b/src/libltfs/xml_reader_libltfs.c @@ -98,6 +98,10 @@ static int decode_entry_name(char **new_name, const char *name) /* Always, length must be shorter than original but allocate null termination space */ len = strlen(name); tmp_name = malloc((len * sizeof(UChar)) + 1); + if (! tmp_name) { + ltfsmsg(LTFS_ERR, 10001E, "decode_entry_name: tmp_name"); + return -LTFS_NO_MEMORY; + } buf_decode[2] = '\0'; while (i < len) { @@ -575,8 +579,15 @@ static int _xml_parse_ip_criteria(xmlTextReaderPtr reader, struct ltfs_index *id ++num_patterns; /* quite inefficient, but the number of patterns should be small. */ - idx->original_criteria.glob_patterns = realloc(idx->original_criteria.glob_patterns, - (num_patterns + 1) * sizeof(struct ltfs_name)); + { + struct ltfs_name *new_patterns = realloc(idx->original_criteria.glob_patterns, + (num_patterns + 1) * sizeof(struct ltfs_name)); + if (! new_patterns) { + ltfsmsg(LTFS_ERR, 10001E, "_xml_parse_ip_criteria: glob_patterns"); + return -LTFS_NO_MEMORY; + } + idx->original_criteria.glob_patterns = new_patterns; + } if (_xml_parse_nametype(reader, &idx->original_criteria.glob_patterns[num_patterns - 1], @@ -863,10 +874,10 @@ static int _xml_parse_one_xattr(xmlTextReaderPtr reader, struct dentry *d) if (xattr) { TAILQ_INSERT_TAIL(&d->xattrlist, xattr, list); - if (!strcmp(xattr->key.name, "ltfs.vendor.IBM.immutable") && !strcmp(xattr->value, "1") ) { + if (xattr->value && !strcmp(xattr->key.name, "ltfs.vendor.IBM.immutable") && !strcmp(xattr->value, "1") ) { d->is_immutable = true; } - if (!strcmp(xattr->key.name, "ltfs.vendor.IBM.appendonly") && !strcmp(xattr->value, "1") ) { + if (xattr->value && !strcmp(xattr->key.name, "ltfs.vendor.IBM.appendonly") && !strcmp(xattr->value, "1") ) { d->is_appendonly = true; } } @@ -1192,11 +1203,16 @@ static int _xml_parse_file(xmlTextReaderPtr reader, struct ltfs_index *idx, stru * Parse a dir into the given directory. */ +/* Stack-safety bound for the recursive directory parser (XML_PARSE_HUGE + * disables libxml2's own nesting limit); not an LTFS format limit. */ +#define XML_MAX_DIRTREE_DEPTH 1024 + static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, struct ltfs_index *idx, struct ltfs_volume *vol, - struct name_list *dirname); /* Forward reference */ + struct name_list *dirname, int depth); /* Forward reference */ -static int _xml_parse_dir_contents(xmlTextReaderPtr reader, struct dentry *dir, struct ltfs_index *idx) +static int _xml_parse_dir_contents(xmlTextReaderPtr reader, struct dentry *dir, + struct ltfs_index *idx, int depth) { struct name_list *list = NULL, *entry_name = NULL; CHECK_ARG_NULL(dir, -LTFS_NULL_ARG); @@ -1228,7 +1244,7 @@ static int _xml_parse_dir_contents(xmlTextReaderPtr reader, struct dentry *dir, ltfsmsg(LTFS_ERR, 10001E, "_xml_parse_dir_contents: dir"); return -LTFS_NO_MEMORY; } - ret = _xml_parse_dirtree(reader, dir, idx, dir->vol, entry_name); + ret = _xml_parse_dirtree(reader, dir, idx, dir->vol, entry_name, depth + 1); if (ret < 0) { free(entry_name); return ret; @@ -1285,7 +1301,7 @@ static int _xml_parse_dir_contents(xmlTextReaderPtr reader, struct dentry *dir, */ static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, struct ltfs_index *idx, struct ltfs_volume *vol, - struct name_list *dirname) + struct name_list *dirname, int depth) { unsigned long long value_int; struct dentry *dir; @@ -1293,6 +1309,11 @@ static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, declare_parser_vars("directory"); declare_tracking_arrays(9, 1); + if (depth > XML_MAX_DIRTREE_DEPTH) { + ltfsmsg(LTFS_ERR, 17295E, XML_MAX_DIRTREE_DEPTH); + return -LTFS_XML_DEEP_NESTING; + } + if (! parent && idx->root) { dir = idx->root; dir->vol = vol; @@ -1407,7 +1428,7 @@ static int _xml_parse_dirtree(xmlTextReaderPtr reader, struct dentry *parent, check_required_tag(6); check_empty(); if (empty == 0) { - ret = _xml_parse_dir_contents(reader, dir, idx); + ret = _xml_parse_dir_contents(reader, dir, idx, depth); if (ret < 0) return ret; } @@ -1598,7 +1619,7 @@ static int _xml_parse_schema(xmlTextReaderPtr reader, struct ltfs_index *idx, st } else if (! strcmp(name, "directory")) { check_required_tag(6); assert_not_empty(); - ret = _xml_parse_dirtree(reader, NULL, idx, vol, NULL); + ret = _xml_parse_dirtree(reader, NULL, idx, vol, NULL, 0); if (ret < 0) return ret; diff --git a/src/tape_drivers/freebsd/cam/cam_tc.c b/src/tape_drivers/freebsd/cam/cam_tc.c index 7c7f82bd..6d708855 100644 --- a/src/tape_drivers/freebsd/cam/cam_tc.c +++ b/src/tape_drivers/freebsd/cam/cam_tc.c @@ -1955,7 +1955,7 @@ int camtape_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc, * @param size length of buf * @return 0 on success or a negative value on error */ -int camtape_modeselect(void *device, unsigned char *buf, const size_t size) +int camtape_modeselect(void *device, unsigned char *buf, const size_t size, bool save) { int rc; char *msg = NULL; @@ -2351,7 +2351,7 @@ int camtape_set_compression(void *device, const bool enable_compression, struct else buf[18] &= 0x7F; /* Unset DCE field*/ - rc = camtape_modeselect(device, buf, sizeof(buf)); + rc = camtape_modeselect(device, buf, sizeof(buf), false); ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCOMPRS)); return rc; @@ -2385,7 +2385,7 @@ int camtape_set_default(void *device) buf[1] = 0x00; buf[24] = 0x0C; - rc = camtape_modeselect(device, buf, sizeof(buf)); + rc = camtape_modeselect(device, buf, sizeof(buf), false); if (rc != DEVICE_GOOD) goto bailout; } @@ -3031,7 +3031,7 @@ int camtape_setcap(void *device, uint16_t proportion) buf[27] |= 0x01; buf[28] = 0x00; - rc = camtape_modeselect(device, buf, sizeof(buf)); + rc = camtape_modeselect(device, buf, sizeof(buf), false); } else { int timeout; @@ -3510,7 +3510,7 @@ static int camtape_set_encryption_state(struct camtape_data *softc, */ rwc_page->encryption_state |= encryption_state; - rc = camtape_modeselect(softc, buf, buf_fill_len); + rc = camtape_modeselect(softc, buf, buf_fill_len, false); bailout: if (rc != DEVICE_GOOD) @@ -3696,7 +3696,7 @@ int camtape_set_key(void *device, const unsigned char * const keyalias, const un scsi_ulto2b(0, mode_hdr->data_length); - rc = camtape_modeselect(device, buf, bufsize); + rc = camtape_modeselect(device, buf, bufsize, false); bailout: if (rc != DEVICE_GOOD) diff --git a/src/tape_drivers/generic/file/CMakeLists.txt b/src/tape_drivers/generic/file/CMakeLists.txt new file mode 100644 index 00000000..290252a9 --- /dev/null +++ b/src/tape_drivers/generic/file/CMakeLists.txt @@ -0,0 +1,9 @@ +set(_td "${CMAKE_SOURCE_DIR}/src/tape_drivers") + +ltfs_add_plugin(libtape-file + SOURCES + filedebug_tc.c + filedebug_conf_tc.c + ${_td}/ibm_tape.c + INCLUDES ${_td} + MSG tape_generic_file) diff --git a/src/tape_drivers/generic/file/filedebug_tc.c b/src/tape_drivers/generic/file/filedebug_tc.c index 2d486ebb..9bf4acf9 100644 --- a/src/tape_drivers/generic/file/filedebug_tc.c +++ b/src/tape_drivers/generic/file/filedebug_tc.c @@ -1426,7 +1426,7 @@ static inline int _sanitize_tape(struct filedebug_data *state) ret = -EDEV_MEDIUM_FORMAT_ERROR; break; } - } + } else if (gen == DRIVE_GEN_JAG4) { switch (state->conf.cart_type) { case TC_MP_JB: @@ -2036,7 +2036,7 @@ int filedebug_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc return DEVICE_GOOD; } -int filedebug_modeselect(void *device, unsigned char *buf, const size_t size) +int filedebug_modeselect(void *device, unsigned char *buf, const size_t size, bool save) { int ret = 0; struct filedebug_data *state = (struct filedebug_data *)device; diff --git a/src/tape_drivers/generic/itdtimg/CMakeLists.txt b/src/tape_drivers/generic/itdtimg/CMakeLists.txt new file mode 100644 index 00000000..187d0d26 --- /dev/null +++ b/src/tape_drivers/generic/itdtimg/CMakeLists.txt @@ -0,0 +1,4 @@ +ltfs_add_plugin(libtape-itdtimg + SOURCES itdtimg_tc.c + INCLUDES ${CMAKE_SOURCE_DIR}/src/tape_drivers + MSG tape_generic_itdtimg) diff --git a/src/tape_drivers/generic/itdtimg/itdtimg_tc.c b/src/tape_drivers/generic/itdtimg/itdtimg_tc.c index 7a5d768f..14eab2a0 100644 --- a/src/tape_drivers/generic/itdtimg/itdtimg_tc.c +++ b/src/tape_drivers/generic/itdtimg/itdtimg_tc.c @@ -870,7 +870,7 @@ int itdtimage_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc return DEVICE_GOOD; } -int itdtimage_modeselect(void *device, unsigned char *buf, const size_t size) +int itdtimage_modeselect(void *device, unsigned char *buf, const size_t size, bool save) { /* Do nothing */ return DEVICE_GOOD; diff --git a/src/tape_drivers/hp_tape.c b/src/tape_drivers/hp_tape.c index 23aa7327..e01b2368 100644 --- a/src/tape_drivers/hp_tape.c +++ b/src/tape_drivers/hp_tape.c @@ -63,12 +63,12 @@ #include "libltfs/ltfs_endian.h" struct supported_device *hp_supported_drives[] = { - TAPEDRIVE( HP_VENDOR_ID, "Ultrium 5-SCSI", DRIVE_LTO5, "[Ultrium 5-SCSI]" ), /* HP Ultrium Gen 5 */ - TAPEDRIVE( HP_VENDOR_ID, "Ultrium 6-SCSI", DRIVE_LTO6, "[Ultrium 6-SCSI]" ), /* HP Ultrium Gen 6 */ - TAPEDRIVE( HP_VENDOR_ID, "Ultrium 7-SCSI", DRIVE_LTO7, "[Ultrium 7-SCSI]" ), /* HP Ultrium Gen 7 */ - TAPEDRIVE( HPE_VENDOR_ID, "Ultrium 8-SCSI", DRIVE_LTO8, "[Ultrium 8-SCSI]" ), /* HPE Ultrium Gen 8 */ - TAPEDRIVE( HPE_VENDOR_ID, "Ultrium 9-SCSI", DRIVE_LTO9, "[Ultrium 9-SCSI]" ), /* HPE Ultrium Gen 9 */ - TAPEDRIVE( TANDBERG_VENDOR_ID, "LTO-6 HH ", DRIVE_LTO6_HH, "[LTO-6 HH]" ), /* TANDBERG LTO-6 HH */ + TAPEDRIVE( HP_VENDOR_ID, "Ultrium 5-SCSI", DRIVE_LTO5, "[Ultrium 5-SCSI]" ), /* HP Ultrium Gen 5 */ + TAPEDRIVE( HP_VENDOR_ID, "Ultrium 6-SCSI", DRIVE_LTO6, "[Ultrium 6-SCSI]" ), /* HP Ultrium Gen 6 */ + TAPEDRIVE( HP_VENDOR_ID, "Ultrium 7-SCSI", DRIVE_LTO7, "[Ultrium 7-SCSI]" ), /* HP Ultrium Gen 7 */ + TAPEDRIVE( HPE_VENDOR_ID, "Ultrium 8-SCSI", DRIVE_LTO8, "[Ultrium 8-SCSI]" ), /* HPE Ultrium Gen 8 */ + TAPEDRIVE( HPE_VENDOR_ID, "Ultrium 9-SCSI", DRIVE_LTO9, "[Ultrium 9-SCSI]" ), /* HPE Ultrium Gen 9 */ + TAPEDRIVE( TANDBERG_VENDOR_ID, "LTO-6 HH ", DRIVE_LTO6_HH, "[LTO-6 HH]" ), /* TANDBERG LTO-6 HH */ /* End of supported_devices */ NULL }; diff --git a/src/tape_drivers/linux/lin_tape/CMakeLists.txt b/src/tape_drivers/linux/lin_tape/CMakeLists.txt new file mode 100644 index 00000000..025682fc --- /dev/null +++ b/src/tape_drivers/linux/lin_tape/CMakeLists.txt @@ -0,0 +1,12 @@ +set(_td "${CMAKE_SOURCE_DIR}/src/tape_drivers") + +ltfs_add_plugin(libtape-lin_tape + SOURCES + lin_tape_ibmtape.c + ${_td}/vendor_compat.c + ${_td}/ibm_tape.c + ${_td}/hp_tape.c + ${_td}/quantum_tape.c + INCLUDES ${_td} + CRC + MSG tape_linux_lin_tape) diff --git a/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c b/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c index f67e54e9..84add631 100644 --- a/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c +++ b/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c @@ -2432,7 +2432,7 @@ int lin_tape_ibmtape_modesense(void *device, const uint8_t page, const TC_MP_PC_ * @param size length of buf * @return 0 on success or a negative value on error */ -int lin_tape_ibmtape_modeselect(void *device, unsigned char *buf, const size_t size) +int lin_tape_ibmtape_modeselect(void *device, unsigned char *buf, const size_t size, bool save) { struct sioc_pass_through spt; int rc; @@ -2765,7 +2765,7 @@ int lin_tape_ibmtape_set_compression(void *device, const bool enable_compression else buf[18] &= 0x7F; /* Unset DCE field*/ - rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf)); + rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf), false); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCOMPRS)); return rc; @@ -2800,7 +2800,7 @@ int lin_tape_ibmtape_set_default(void *device) buf[1] = 0x00; buf[24] = 0x0C; - rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf)); + rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf), false); if (rc != DEVICE_GOOD) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETDEFAULT)); return rc; @@ -3360,7 +3360,7 @@ int lin_tape_ibmtape_setcap(void *device, uint16_t proportion) buf[27] |= 0x01; buf[28] = 0x00; - rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf)); + rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf), false); } else { memset(&spt, 0, sizeof(spt)); diff --git a/src/tape_drivers/linux/sg/CMakeLists.txt b/src/tape_drivers/linux/sg/CMakeLists.txt new file mode 100644 index 00000000..37cfd2a2 --- /dev/null +++ b/src/tape_drivers/linux/sg/CMakeLists.txt @@ -0,0 +1,14 @@ +set(_td "${CMAKE_SOURCE_DIR}/src/tape_drivers") + +ltfs_add_plugin(libtape-sg + SOURCES + sg_scsi_tape.c + sg_tape.c + ${_td}/vendor_compat.c + ${_td}/ibm_tape.c + ${_td}/hp_tape.c + ${_td}/quantum_tape.c + ${_td}/open_factor.c + INCLUDES ${_td} + CRC + MSG tape_linux_sg) diff --git a/src/tape_drivers/linux/sg/sg_tape.c b/src/tape_drivers/linux/sg/sg_tape.c index 8a13493e..6ec9ee66 100644 --- a/src/tape_drivers/linux/sg/sg_tape.c +++ b/src/tape_drivers/linux/sg/sg_tape.c @@ -52,8 +52,10 @@ #include #include #include +#include #include +#include "libltfs/ltfs_error.h" #include "ltfs_copyright.h" #include "libltfs/ltfslogging.h" #include "libltfs/fs.h" @@ -104,6 +106,7 @@ struct sg_global_data global_data; #define MAX_RETRY (100) #define MAX_TAKE_DUMP_ATTEMPTS (10) +#define POR_MAX_RETRIES (3) /* Forward references (For keep function order to struct tape_ops) */ int sg_readpos(void *device, struct tc_position *pos); @@ -112,7 +115,7 @@ int sg_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_position int sg_logsense(void *device, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size); int sg_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc, const unsigned char subpage, unsigned char *buf, const size_t size); -int sg_modeselect(void *device, unsigned char *buf, const size_t size); +int sg_modeselect(void *device, unsigned char *buf, const size_t size, bool save); static const char *_generate_product_name(const char *product_id); /* Local functions */ @@ -232,7 +235,7 @@ static int _set_lbp(void *device, bool enable) buf[22] = 0; } - ret = sg_modeselect(device, buf, sizeof(buf)); + ret = sg_modeselect(device, buf, sizeof(buf), false); if (ret == DEVICE_GOOD) { if (enable) { @@ -604,7 +607,7 @@ int _raw_tur(const int fd) #define _clear_por(p) _clear_por_raw((p)->dev.fd); -void _clear_por_raw(const int fd) +int _clear_por_raw(const int fd) { int i = 0, ret = -1; @@ -624,6 +627,7 @@ void _clear_por_raw(const int fd) } i++; } + return ret; } #define _get_stable_tur_response(p) _get_stable_tur_response_raw((p)->dev.fd) @@ -1861,16 +1865,11 @@ static int _cdb_read(void *device, char *buf, size_t size, bool sili) return length; } -static inline int _handle_block_allocation_failure(void *device, struct tc_position *pos, - int *retry, char *op) +static inline int _resolve_position_after_io_cmd_failure(void *device, struct tc_position *pos, char *op) { int ret = 0; struct tc_position tmp_pos = {0, 0}; - /* Sleep 3 secs to wait garbage correction in kernel side and retry */ - ltfsmsg(LTFS_WARN, 30277W, ++(*retry)); - sleep(3); - ret = sg_readpos(device, &tmp_pos); if (ret == DEVICE_GOOD && pos->partition == tmp_pos.partition) { if (pos->block == tmp_pos.block) { @@ -1923,11 +1922,12 @@ static inline int _handle_block_allocation_failure(void *device, struct tc_posit int sg_read(void *device, char *buf, size_t size, struct tc_position *pos, const bool unusual_size) { - int32_t ret = -EDEV_UNKNOWN; + int32_t ret = -EDEV_UNKNOWN, ret_read = -1; struct sg_data *priv = (struct sg_data*)device; size_t datacount = size; struct tc_position pos_retry = {0, 0}; - int retry_count = 0; + int retry_count = 0, por_retry_count = 0; + struct timespec delay_ts = {0}; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_READ)); ltfsmsg(LTFS_DEBUG3, 30395D, "read", size, priv->drive_serial); @@ -1952,7 +1952,7 @@ int sg_read(void *device, char *buf, size_t size, } start_read: - ret = _cdb_read(device, buf, datacount, unusual_size); + ret_read = ret = _cdb_read(device, buf, datacount, unusual_size); if (ret == -EDEV_LENGTH_MISMATCH) { if (pos_retry.partition || pos_retry.block) { /* Return error when retry is already executed */ @@ -1984,11 +1984,38 @@ int sg_read(void *device, char *buf, size_t size, priv->use_sili = false; ret = _cdb_read(device, buf, datacount, unusual_size); } else if (ret == -EDEV_BUFFER_ALLOCATE_ERROR && retry_count < MAX_RETRY) { - ret = _handle_block_allocation_failure(device, pos, &retry_count, "read"); + ltfsmsg(LTFS_WARN, 30277W, ++retry_count); + struct timespec delay_ts; + delay_ts.tv_sec = 3; + delay_ts.tv_nsec = 0; + nanosleep(&delay_ts, NULL); // Wait for kernel GC + ret = _resolve_position_after_io_cmd_failure(device, pos, "read"); if (ret == -EDEV_RETRY) goto start_read; + } else if (ret == -EDEV_HOST_ERROR && por_retry_count < POR_MAX_RETRIES) { + ltfsmsg(LTFS_WARN, 30298W, "read", por_retry_count); + por_retry_count++; + delay_ts.tv_sec = 5; + delay_ts.tv_nsec = 0; + nanosleep(&delay_ts, NULL); + ret = _clear_por(priv); + if (ret == DEVICE_GOOD) { + ret = _resolve_position_after_io_cmd_failure(device, pos, "read"); + /* If the original command did not reach the driver, or it reached it but after failing there is a position mismatch; retry */ + if (ret == -EDEV_RETRY) { + goto start_read; + } else if (ret == 0) { + ret_read = datacount; // This is OK? Might need to set the block instead of that + } else { + ltfsmsg(LTFS_ERR, 30300E, ret); + } + } else { + ltfsmsg(LTFS_ERR, 30299E, ret); + } + ret = ret_read; } + if(ret == -EDEV_FILEMARK_DETECTED) { pos->filemarks++; @@ -2093,12 +2120,13 @@ static int _cdb_write(void *device, uint8_t *buf, size_t size, bool *ew, bool *p int sg_write(void *device, const char *buf, size_t count, struct tc_position *pos) { - int ret, ret_fo; + int ret, ret_fo, ret_write = -1; bool ew = false, pew = false; struct sg_data *priv = (struct sg_data*)device; struct tc_position cur_pos; size_t datacount = count; - int retry_count = 0; + int retry_count = 0, por_retry_count = 0; + struct timespec delay_ts = {0}; ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_ENTER(REQ_TC_WRITE)); @@ -2128,7 +2156,7 @@ int sg_write(void *device, const char *buf, size_t count, struct tc_position *po } start_write: - ret = _cdb_write(device, (uint8_t *)buf, datacount, &ew, &pew); + ret_write = ret = _cdb_write(device, (uint8_t *)buf, datacount, &ew, &pew); if (ret == DEVICE_GOOD) { pos->block++; pos->early_warning = ew; @@ -2146,9 +2174,34 @@ int sg_write(void *device, const char *buf, size_t count, struct tc_position *po ret = -EDEV_POR_OR_BUS_RESET; } } else if (ret == -EDEV_BUFFER_ALLOCATE_ERROR && retry_count < MAX_RETRY) { - ret = _handle_block_allocation_failure(device, pos, &retry_count, "write"); + ltfsmsg(LTFS_WARN, 30277W, ++retry_count); + delay_ts.tv_sec = 3; + delay_ts.tv_nsec = 0; + nanosleep(&delay_ts, NULL); // Wait for kernel GC + ret = _resolve_position_after_io_cmd_failure(device, pos, "write"); if (ret == -EDEV_RETRY) goto start_write; + } else if (ret == -EDEV_HOST_ERROR && por_retry_count < POR_MAX_RETRIES) { + ltfsmsg(LTFS_WARN, 30298W, "write", por_retry_count); + por_retry_count++; + delay_ts.tv_sec = 5; + delay_ts.tv_nsec = 0; + nanosleep(&delay_ts, NULL); + ret = _clear_por(priv); + if (ret == DEVICE_GOOD) { + ret = _resolve_position_after_io_cmd_failure(device, pos, "write"); + /* If the original command did not reach the driver, or it reached it but after failing there is a position mismatch; retry */ + if (ret == -EDEV_RETRY) { + goto start_write; + } else if (ret == 0) { + ret_write = datacount; // This is OK? Might need to set the blocksize instead of that + } else { + ltfsmsg(LTFS_ERR, 30300E, ret); + } + } else { + ltfsmsg(LTFS_ERR, 30299E, ret); + } + ret = ret_write; } ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_WRITE)); @@ -2393,7 +2446,7 @@ int sg_locate(void *device, struct tc_position dest, struct tc_position *pos) ret = sg_issue_cdb_command(&priv->dev, &req, &msg); if (ret < 0){ - if (dest.block == TAPE_BLOCK_MAX && ret == -EDEV_EOD_DETECTED) { + if (dest.block == TAPE_BLOCK_MAX && (ret == -EDEV_EOD_DETECTED || ret == -EDEV_EOD_NOT_FOUND)) { ltfsmsg(LTFS_DEBUG, 30224D, "Locate"); ret = DEVICE_GOOD; } else { @@ -2913,7 +2966,7 @@ int sg_setcap(void *device, uint16_t proportion) buf[27] |= 0x01; buf[28] = 0x00; - ret = sg_modeselect(device, buf, sizeof(buf)); + ret = sg_modeselect(device, buf, sizeof(buf), false); } else { /* Zero out the CDB and the result buffer */ ret = init_sg_io_header(&req); @@ -3298,7 +3351,7 @@ int sg_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc, return ret; } -int sg_modeselect(void *device, unsigned char *buf, const size_t size) +int sg_modeselect(void *device, unsigned char *buf, const size_t size, bool save) { int ret = -EDEV_UNKNOWN; int ret_ep = DEVICE_GOOD; @@ -3324,7 +3377,15 @@ int sg_modeselect(void *device, unsigned char *buf, const size_t size) /* Build CDB */ cdb[0] = MODE_SELECT10; - cdb[1] = 0x10; /* Set PF bit */ + /* + * Set PF and SP bit + * NOTE: Not all modepages support SP bit. + * The SCSI reference says: + * • SP (Save Pages): Only allowed to be set to one when explicitly mentioned in the description of the + * specific mode page + * Right now SDE and LE does not set any non savable pages, but this could change. + * */ + cdb[1] = 0x10 | (save? 1 : 0); ltfs_u16tobe(cdb + 7, size); timeout = get_timeout(priv->timeouts, cdb[0]); @@ -3740,7 +3801,7 @@ int sg_set_compression(void *device, const bool enable_compression, struct tc_po else buf[18] = buf[18] & 0x7E; - ret = sg_modeselect(device, buf, sizeof(buf)); + ret = sg_modeselect(device, buf, sizeof(buf), false); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCOMPRS)); @@ -3770,7 +3831,7 @@ int sg_set_default(void *device) buf[1] = 0x00; buf[24] = 0x0C; - ret = sg_modeselect(device, buf, sizeof(buf)); + ret = sg_modeselect(device, buf, sizeof(buf), false); if (ret < 0) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETDEFAULT)); return ret; diff --git a/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c b/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c index 0ea8df55..b339cc25 100644 --- a/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c +++ b/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c @@ -226,7 +226,7 @@ static int _set_lbp(void *device, bool enable) buf[22] = 0; } - ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf)); + ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf), false); if (ret == DEVICE_GOOD) { if (enable) { @@ -2466,7 +2466,7 @@ int scsipi_ibmtape_setcap(void *device, uint16_t proportion) buf[27] |= 0x01; buf[28] = 0x00; - ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf)); + ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf), false); } else { /* Zero out the CDB and the result buffer */ ret = init_scsireq(&req); @@ -3258,7 +3258,7 @@ int scsipi_ibmtape_set_compression(void *device, const bool enable_compression, else buf[18] = buf[18] & 0x7E; - ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf)); + ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf), false); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCOMPRS)); @@ -3288,7 +3288,7 @@ int scsipi_ibmtape_set_default(void *device) buf[1] = 0x00; buf[24] = 0x0C; - ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf)); + ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf), false); if (ret < 0) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETDEFAULT)); return ret; diff --git a/src/tape_drivers/osx/iokit/CMakeLists.txt b/src/tape_drivers/osx/iokit/CMakeLists.txt new file mode 100644 index 00000000..d1a7b395 --- /dev/null +++ b/src/tape_drivers/osx/iokit/CMakeLists.txt @@ -0,0 +1,15 @@ +set(_td "${CMAKE_SOURCE_DIR}/src/tape_drivers") + +ltfs_add_plugin(libtape-iokit + SOURCES + iokit_tape.c + iokit_scsi.c + iokit_service.c + ${_td}/vendor_compat.c + ${_td}/ibm_tape.c + ${_td}/hp_tape.c + ${_td}/quantum_tape.c + INCLUDES ${_td} + LIBS ${IOKIT_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} + CRC + MSG tape_iokit) diff --git a/src/tape_drivers/osx/iokit/iokit_tape.c b/src/tape_drivers/osx/iokit/iokit_tape.c index 7b72d2ff..e93ba1fa 100644 --- a/src/tape_drivers/osx/iokit/iokit_tape.c +++ b/src/tape_drivers/osx/iokit/iokit_tape.c @@ -108,7 +108,7 @@ int iokit_logsense(void *device, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size); int iokit_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc, const unsigned char subpage, unsigned char *buf, const size_t size); -int iokit_modeselect(void *device, unsigned char *buf, const size_t size); +int iokit_modeselect(void *device, unsigned char *buf, const size_t size, bool save); static const char *_generate_product_name(const char *product_id); /* Local functions */ @@ -229,7 +229,7 @@ static int _set_lbp(void *device, bool enable) buf[22] = 0; } - ret = iokit_modeselect(device, buf, sizeof(buf)); + ret = iokit_modeselect(device, buf, sizeof(buf), false); if (ret == DEVICE_GOOD) { if (enable) { @@ -2198,7 +2198,7 @@ int iokit_setcap(void *device, uint16_t proportion) buf[27] |= 0x01; buf[28] = 0x00; - ret = iokit_modeselect(device, buf, sizeof(buf)); + ret = iokit_modeselect(device, buf, sizeof(buf), false); } else { /* Zero out the CDB and the result buffer */ memset(cdb, 0, sizeof(cdb)); @@ -2524,7 +2524,7 @@ int iokit_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE return ret; } -int iokit_modeselect(void *device, unsigned char *buf, const size_t size) +int iokit_modeselect(void *device, unsigned char *buf, const size_t size, bool save) { int ret = -EDEV_UNKNOWN; struct iokit_data *priv = (struct iokit_data*)device; @@ -3011,7 +3011,7 @@ int iokit_set_compression(void *device, const bool enable_compression, struct tc else buf[18] = buf[18] & 0x7E; - ret = iokit_modeselect(device, buf, sizeof(buf)); + ret = iokit_modeselect(device, buf, sizeof(buf), false); ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCOMPRS)); @@ -3041,7 +3041,7 @@ int iokit_set_default(void *device) buf[1] = 0x00; buf[24] = 0x0C; - ret = iokit_modeselect(device, buf, sizeof(buf)); + ret = iokit_modeselect(device, buf, sizeof(buf), false); if (ret < 0) { ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETDEFAULT)); return ret; diff --git a/src/tape_drivers/vendor_compat.c b/src/tape_drivers/vendor_compat.c index 0c3ceb65..4761a4ce 100644 --- a/src/tape_drivers/vendor_compat.c +++ b/src/tape_drivers/vendor_compat.c @@ -264,6 +264,7 @@ struct error_table standard_tape_errors[] = { /* Sense Key 8 (Blank Check) */ {0x080005, -EDEV_EOD_DETECTED, "End-of-Data Detected"}, {0x081401, -EDEV_RECORD_NOT_FOUND, "Record Not Found, Void Tape"}, + {0x081403, -EDEV_EOD_NOT_FOUND, "End-of-Data (EOD) not found"}, /* Sense Key B (Aborted Command) */ {0x0B001E, -EDEV_ABORTED_COMMAND, "Conflicting SA Creation Request"}, {0x0B0B01, -EDEV_OVER_TEMPERATURE, "Warning - Specified Temperature Exceeded"}, @@ -319,6 +320,8 @@ int get_vendor_id(char* vendor) return VENDOR_HP; else if (!strncmp(vendor, HPE_VENDOR_ID, strlen(HPE_VENDOR_ID))) return VENDOR_HP; + else if (!strncmp(vendor, TANDBERG_VENDOR_ID, strlen(TANDBERG_VENDOR_ID))) + return VENDOR_HP; else if (!strncmp(vendor, QUANTUM_VENDOR_ID, strlen(QUANTUM_VENDOR_ID))) return VENDOR_QUANTUM; else diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt new file mode 100644 index 00000000..f0ba6c33 --- /dev/null +++ b/src/utils/CMakeLists.txt @@ -0,0 +1,13 @@ +add_executable(mkltfs mkltfs.c) +set_target_properties(mkltfs PROPERTIES POSITION_INDEPENDENT_CODE ON ENABLE_EXPORTS ON) +target_link_libraries(mkltfs PRIVATE ltfs) +ltfs_link_message(mkltfs bin_mkltfs) +install(TARGETS mkltfs RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(ltfsck ltfsck.c) +set_target_properties(ltfsck PROPERTIES POSITION_INDEPENDENT_CODE ON ENABLE_EXPORTS ON) +target_link_libraries(ltfsck PRIVATE ltfs) +ltfs_link_message(ltfsck bin_ltfsck) +install(TARGETS ltfsck RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +install(PROGRAMS ltfs_ordered_copy DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..6823b1bf --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,16 @@ +# Integration tests: the shell scripts under t/, if present, run through ctest; +# SKIP_RETURN_CODE 77 covers hosts without /dev/fuse. +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/helpers/fsops_helper.c") + add_executable(fsops_helper helpers/fsops_helper.c) + set_target_properties(fsops_helper PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests/helpers") +endif() + +file(GLOB _test_scripts CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/t/*.sh") +foreach(_path ${_test_scripts}) + get_filename_component(_t "${_path}" NAME_WE) + add_test(NAME ${_t} COMMAND sh "${_path}") + set_tests_properties(${_t} PROPERTIES + SKIP_RETURN_CODE 77 + ENVIRONMENT "top_srcdir=${CMAKE_SOURCE_DIR};top_builddir=${CMAKE_BINARY_DIR}") +endforeach()