mirror of
https://github.com/aaru-dps/fstester.git
synced 2025-12-16 19:24:39 +00:00
Try to use fcntl to create sparse files in Darwin.
This commit is contained in:
@@ -32,11 +32,11 @@ project(fssetter-darwin
|
|||||||
|
|
||||||
find_library(CARBON_LIBRARY NAMES Carbon)
|
find_library(CARBON_LIBRARY NAMES Carbon)
|
||||||
|
|
||||||
set(PLATFORM_SOURCES os.c darwin.h volume.c volume.h attr.c attr.h rsrcfork.c rsrcfork.h)
|
set(PLATFORM_SOURCES os.c darwin.h volume.c volume.h attr.c attr.h rsrcfork.c rsrcfork.h sparse.c xattr.c xattr.h)
|
||||||
|
|
||||||
if(CARBON_LIBRARY)
|
if(CARBON_LIBRARY)
|
||||||
add_definitions("-DHAVE_CARBON")
|
add_definitions("-DHAVE_CARBON")
|
||||||
set(PLATFORM_SOURCES ${PLATFORM_SOURCES} carbon.c carbon.h xattr.c xattr.h)
|
set(PLATFORM_SOURCES ${PLATFORM_SOURCES} carbon.c carbon.h)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(EXECUTABLE_NAME "fssetter-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
|
set(EXECUTABLE_NAME "fssetter-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
|
|||||||
@@ -13,5 +13,6 @@ void DarwinResourceFork(const char* path);
|
|||||||
void DarwinFileAttributes(const char* path);
|
void DarwinFileAttributes(const char* path);
|
||||||
void DarwinExtendedAttributes(const char* path);
|
void DarwinExtendedAttributes(const char* path);
|
||||||
void DarwinVolumeAttributes(const char* path);
|
void DarwinVolumeAttributes(const char* path);
|
||||||
|
int DarwinSparse(const char* path);
|
||||||
|
|
||||||
#endif // SETTER_SRC_DARWIN_DARWIN_H_
|
#endif // SETTER_SRC_DARWIN_DARWIN_H_
|
||||||
|
|||||||
151
setter/src/darwin/sparse.c
Normal file
151
setter/src/darwin/sparse.c
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2011-2021 Natalia Portillo
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "../include/consts.h"
|
||||||
|
#include "../log.h"
|
||||||
|
|
||||||
|
int DarwinSparse(const char* path)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
int rc, wRc, cRc, sRc;
|
||||||
|
FILE* h;
|
||||||
|
int i;
|
||||||
|
int fd;
|
||||||
|
int done = -1;
|
||||||
|
fpunchhole_t fphole;
|
||||||
|
memset(&fphole, 0, sizeof(fpunchhole_t));
|
||||||
|
|
||||||
|
ret = chdir(path);
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
log_write("Error %d changing to specified path.\n", errno);
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = mkdir("SPARSE", 0755);
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
log_write("Error %d creating working directory.\n", errno);
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = chdir("SPARSE");
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
log_write("Error %d changing to working directory.\n", errno);
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
done = 0;
|
||||||
|
|
||||||
|
log_write("Creating sparse files.\n");
|
||||||
|
|
||||||
|
h = fopen("SMALL", "w+");
|
||||||
|
rc = 0;
|
||||||
|
wRc = 0;
|
||||||
|
cRc = 0;
|
||||||
|
sRc = 0;
|
||||||
|
if(h == NULL) { rc = errno; }
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(i = 0; i < 4096 * 3; i += CLAUNIA_SIZE)
|
||||||
|
{
|
||||||
|
ret = fwrite(clauniaBytes, CLAUNIA_SIZE, 1, h);
|
||||||
|
if(ret < 0)
|
||||||
|
{
|
||||||
|
wRc = errno;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = fileno(h);
|
||||||
|
fphole.fp_offset = 4096;
|
||||||
|
fphole.fp_length = 8192;
|
||||||
|
ret = fcntl(fd, F_PUNCHHOLE, &fphole);
|
||||||
|
if(ret) sRc = errno;
|
||||||
|
else
|
||||||
|
done++;
|
||||||
|
|
||||||
|
ret = fclose(h);
|
||||||
|
if(ret) cRc = errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d, sRc = %d\n",
|
||||||
|
"SMALL",
|
||||||
|
4096 * 4,
|
||||||
|
rc,
|
||||||
|
wRc,
|
||||||
|
cRc,
|
||||||
|
sRc);
|
||||||
|
|
||||||
|
h = fopen("BIG", "w+");
|
||||||
|
rc = 0;
|
||||||
|
wRc = 0;
|
||||||
|
cRc = 0;
|
||||||
|
sRc = 0;
|
||||||
|
if(h == NULL) { rc = errno; }
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(i = 0; i < 4096 * 30; i += CLAUNIA_SIZE)
|
||||||
|
{
|
||||||
|
ret = fwrite(clauniaBytes, CLAUNIA_SIZE, 1, h);
|
||||||
|
if(ret < 0)
|
||||||
|
{
|
||||||
|
wRc = errno;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = fileno(h);
|
||||||
|
fphole.fp_offset = 32768;
|
||||||
|
fphole.fp_length = 81920;
|
||||||
|
ret = fcntl(fd, F_PUNCHHOLE, &fphole);
|
||||||
|
if(ret) sRc = errno;
|
||||||
|
else
|
||||||
|
done++;
|
||||||
|
|
||||||
|
ret = fclose(h);
|
||||||
|
if(ret) cRc = errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d, sRc = %d\n",
|
||||||
|
"BIG",
|
||||||
|
4096 * 30,
|
||||||
|
rc,
|
||||||
|
wRc,
|
||||||
|
cRc,
|
||||||
|
sRc);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
@@ -23,11 +23,11 @@ Copyright (C) 2011-2021 Natalia Portillo
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__LINUX__) || defined(__gnu_linux)
|
#if defined(__linux__) || defined(__LINUX__) || defined(__gnu_linux)
|
||||||
#define _GNU_SOURCE
|
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
#include "../linux/linux.h"
|
#include "../linux/linux.h"
|
||||||
|
#elif defined(__APPLE__) && defined(__MACH__)
|
||||||
|
#include "../darwin/darwin.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -57,6 +57,13 @@ void Sparse(const char* path)
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#elif defined(__APPLE__) && defined(__MACH__)
|
||||||
|
ret = DarwinSparse(path);
|
||||||
|
|
||||||
|
if(ret > 0) return;
|
||||||
|
|
||||||
|
ret = chdir(path);
|
||||||
|
rmdir("SPARSE");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = chdir(path);
|
ret = chdir(path);
|
||||||
|
|||||||
Reference in New Issue
Block a user