diff --git a/setter/src/unix/linux/CMakeLists.txt b/setter/src/unix/linux/CMakeLists.txt index 2d7633e..f406b7b 100644 --- a/setter/src/unix/linux/CMakeLists.txt +++ b/setter/src/unix/linux/CMakeLists.txt @@ -26,6 +26,6 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux") return() endif() -add_sources(attr.c sparse.c xattr.c xattr.h volume.c volume.h) +add_sources(attr.c sparse.c sparse.h xattr.c xattr.h volume.c volume.h) add_sub_libraries(dl) diff --git a/setter/src/unix/linux/sparse.c b/setter/src/unix/linux/sparse.c index f54de8b..f6e3ca3 100644 --- a/setter/src/unix/linux/sparse.c +++ b/setter/src/unix/linux/sparse.c @@ -24,6 +24,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../../include/consts.h" #define _GNU_SOURCE +#include #include #include #include @@ -34,14 +35,24 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../../log.h" #include "linux.h" +#include "sparse.h" void LinuxSparse(const char* path) { - int ret; - int rc, wRc, cRc, zRc; - FILE* h; - int i; - int fd; + int ret; + int rc, wRc, cRc, zRc; + FILE* h; + int i; + int fd; + _linux_fallocate linux_fallocate; + + linux_fallocate = (_linux_fallocate)dlsym(RTLD_DEFAULT, "fallocate"); + + if(!linux_fallocate) + { + log_write("Error loading fallocate(2) from libc: %s\n", dlerror()); + return; + } ret = chdir(path); @@ -88,7 +99,7 @@ void LinuxSparse(const char* path) } fd = fileno(h); - ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 4096, 8192); + ret = linux_fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 4096, 8192); if(ret) { zRc = errno; } ret = fclose(h); @@ -122,7 +133,7 @@ void LinuxSparse(const char* path) } fd = fileno(h); - ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 32768, 81920); + ret = linux_fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 32768, 81920); if(ret) { zRc = errno; } ret = fclose(h); diff --git a/setter/src/unix/linux/sparse.h b/setter/src/unix/linux/sparse.h new file mode 100644 index 0000000..b813484 --- /dev/null +++ b/setter/src/unix/linux/sparse.h @@ -0,0 +1,38 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + + Author(s) : Natalia Portillo + +--[ License ] --------------------------------------------------------------- + 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 . + +----------------------------------------------------------------------------- +Copyright (C) 2011-2021 Natalia Portillo +*****************************************************************************/ + +#ifndef AARU_FSTESTER_SETTER_SRC_LINUX_SPARSE_H_ +#define AARU_FSTESTER_SETTER_SRC_LINUX_SPARSE_H_ + +#ifndef FALLOC_FL_KEEP_SIZE +#define FALLOC_FL_KEEP_SIZE 0x01 +#endif + +#ifndef FALLOC_FL_PUNCH_HOLE +#define FALLOC_FL_PUNCH_HOLE 0x02 +#endif + +typedef int (*_linux_fallocate)(int fd, int mode, off_t offset, off_t len); + +#endif // AARU_FSTESTER_SETTER_SRC_LINUX_SPARSE_H_