Compare commits

...

No commits in common. "c8s" and "imports/c8-beta/scrub-2.5.2-12.el8" have entirely different histories.

9 changed files with 2 additions and 2390 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
SOURCES/scrub-2.5.2.tar.bz2 SOURCES/scrub-2.5.2.tar.bz2
/scrub-2.5.2.tar.bz2

1
.scrub.metadata Normal file
View File

@ -0,0 +1 @@
863e5894e6acb3f922cb25f58e260f9c59b55c14 SOURCES/scrub-2.5.2.tar.bz2

View File

@ -1,22 +1,12 @@
%bcond_without check
Name: scrub Name: scrub
Version: 2.5.2 Version: 2.5.2
Release: 16%{?dist} Release: 12%{?dist}
Summary: Disk scrubbing program Summary: Disk scrubbing program
License: GPLv2+ License: GPLv2+
Group: System Environment/Base Group: System Environment/Base
URL: http://code.google.com/p/diskscrub/ URL: http://code.google.com/p/diskscrub/
Source0: http://diskscrub.googlecode.com/files/%{name}-%{version}.tar.bz2 Source0: http://diskscrub.googlecode.com/files/%{name}-%{version}.tar.bz2
BuildRequires: autoconf automake libtool
BuildRequires: libgcrypt-devel
Patch0: scrub-2.5.2-extentonly.patch
Patch1: scrub-2.5.2-remove-aes-implementation.patch
Patch2: scrub-2.5.2-test-use-power-2-filesizes.patch
Patch3: scrub-2.5.2-symlinkresolve.patch
%description %description
Scrub writes patterns on files or disk devices to make Scrub writes patterns on files or disk devices to make
retrieving the data more difficult. It operates in one of three retrieving the data more difficult. It operates in one of three
@ -29,21 +19,10 @@ the file system is full, then scrubbed as in 2).
%prep %prep
%setup -q %setup -q
%patch0 -p1 -b .extent-only
%patch1 -p1 -b .remove-aes
%patch2 -p1 -b .test-use-power-2-filesizes
%patch3 -p1 -b .symlinkresolve
%build %build
./autogen.sh
%configure %configure
make %{?_smp_mflags} make %{?_smp_mflags}
%if %{with check}
%check
make check
%endif
%install %install
make DESTDIR=%{buildroot} install make DESTDIR=%{buildroot} install
@ -54,21 +33,6 @@ make DESTDIR=%{buildroot} install
%{_mandir}/man1/scrub.1* %{_mandir}/man1/scrub.1*
%changelog %changelog
* Mon Aug 16 2021 Sergio Arroutbi <sarroutb@redhat.com> - 2.5.2-16
- Fix covscan issues introduced in previous version
Resolves: rhbz#1920252
* Thu Aug 12 2021 Sergio Arroutbi <sarroutb@redhat.com> - 2.5.2-15
- Fix for symbolic link resolution
Resolves: rhbz#1920252
* Tue Jul 16 2019 Daniel Kopecek <dkopecek@redhat.com> - 2.5.2-14
Resolves: rhbz#1689897 - Missing '--extent-only' patch
Resolves: rhbz#1630298 - Removal of component scrub or its crypto from RHEL
* Tue May 14 2019 Daniel Kopecek <dkopecek@redhat.com> - 2.5.2-13
- spec: added check phase (conditional, enabled by default)
* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 2.5.2-12 * Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 2.5.2-12
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild - Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

View File

@ -1,6 +0,0 @@
--- !Policy
product_versions:
- rhel-8
decision_context: osci_compose_gate
rules:
- !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional}

View File

@ -1,744 +0,0 @@
From 1dd2a8b9226594ae834e639e00abdf2f47ac4acc Mon Sep 17 00:00:00 2001
From: Daniel Kopecek <dkopecek@redhat.com>
Date: Tue, 16 Jul 2019 13:21:06 +0200
Subject: [PATCH] scrub allocated extent only
---
libscrub/Makefile.am | 1 +
man/scrub.1.in | 7 ++
src/Makefile.am | 2 +
src/fextent_apply.c | 142 ++++++++++++++++++++++++++
src/fextent_apply.h | 30 ++++++
src/fillfile.c | 231 +++++++++++++++++++++++++++++++++----------
src/fillfile.h | 4 +-
src/genrand.c | 2 +-
src/scrub.c | 36 ++++---
9 files changed, 383 insertions(+), 72 deletions(-)
create mode 100644 src/fextent_apply.c
create mode 100644 src/fextent_apply.h
diff --git a/libscrub/Makefile.am b/libscrub/Makefile.am
index 477c866..d88cd48 100644
--- a/libscrub/Makefile.am
+++ b/libscrub/Makefile.am
@@ -13,6 +13,7 @@ libscrub_la_SOURCES = \
libscrub.c \
scrub.h \
../src/aes.c \
+ ../src/fextent_apply.c \
../src/filldentry.c \
../src/fillfile.c \
../src/genrand.c \
diff --git a/man/scrub.1.in b/man/scrub.1.in
index a1c260a..72b114f 100644
--- a/man/scrub.1.in
+++ b/man/scrub.1.in
@@ -106,6 +106,13 @@ Don't generate random data in parallel with I/O.
.TP
\fI-h\fR, \fI--help\fR
Print a summary of command line options on stderr.
+.TP
+\fI-E\fR, \fI--extent-only\fR
+When scrubbing regular files, scrub only the file extents. This option is
+useful in combination with large sparse files. If used, scrub will skip
+the holes in the sparse file. Use this option with caution, the result may not
+be compliant with cited standards and information about the actual on-disk
+data allocation may leak since only the allocated parts will be scrubbed.
.SH SCRUB METHODS
.TP
.I "nnsa"
diff --git a/src/Makefile.am b/src/Makefile.am
index 0cbd8f7..5de0b68 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,6 +3,8 @@ bin_PROGRAMS = scrub
scrub_SOURCES = \
aes.c \
aes.h \
+ fextent_apply.c \
+ fextent_apply.h \
filldentry.c \
filldentry.h \
fillfile.c \
diff --git a/src/fextent_apply.c b/src/fextent_apply.c
new file mode 100644
index 0000000..31d3210
--- /dev/null
+++ b/src/fextent_apply.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2012 Red Hat Inc., Durham, North Carolina.
+ * All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Authors:
+ * Daniel Kopecek <dkopecek@redhat.com>
+ */
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+
+#include <linux/fs.h>
+#include <linux/fiemap.h>
+
+#ifndef NDEBUG
+# define dP(...) \
+ do { int __tmp_errno = errno; \
+ fprintf(stderr, "DEBUG: "__VA_ARGS__); \
+ errno = __tmp_errno; \
+ } while(0)
+#else
+# define dP(...) while(0)
+#endif
+
+int fextent_apply(int fd, int (*function)(int, struct fiemap_extent *, void *), void *arg)
+{
+ int ret = -1;
+ struct stat st;
+ struct fiemap *em;
+ uint32_t extent_count, i;
+
+ // lock, sync, stat
+ if (flock(fd, LOCK_EX) != 0) {
+ dP("flock(%d, LOCK_EX) failed: %s, %d.\n", fd, strerror(errno), errno);
+ return -1;
+ }
+ if (fsync(fd) != 0) {
+ dP("fsync(%d) failed: %s, %d.\n", fd, strerror(errno), errno);
+ goto exit_1;
+ }
+ if (fstat(fd, &st) != 0) {
+ dP("fstat(%d) failed: %s, %d.\n", fd, strerror(errno), errno);
+ goto exit_1;
+ }
+
+ /*
+ * fiemap => get extent count
+ */
+ em = malloc(sizeof(struct fiemap));
+
+ if (em == NULL) {
+ dP("malloc(%zu) returned NULL!\n", sizeof(struct fiemap));
+ goto exit_1;
+ }
+
+ memset(em, 0, sizeof(struct fiemap));
+
+ em->fm_start = 0;
+ em->fm_length = st.st_size;
+ em->fm_extent_count = 0;
+ em->fm_mapped_extents = 0;
+ em->fm_flags = 0;
+
+ if (ioctl(fd, FS_IOC_FIEMAP, em) != 0) {
+ dP("FS_IOC_FIEMAP: %s, %d.\n", strerror(errno), errno);
+ goto exit_0;
+ }
+
+ extent_count = em->fm_mapped_extents;
+ free(em);
+
+ /*
+ * fiemap => get extents
+ */
+ em = malloc (sizeof(struct fiemap)
+ + (sizeof(struct fiemap_extent) * extent_count));
+
+ if (em == NULL) {
+ dP("malloc(%zu) returned NULL!\n", sizeof(struct fiemap)
+ + (sizeof (struct fiemap_extent) * extent_count));
+ goto exit_0;
+ }
+
+ memset(em, 0, sizeof(struct fiemap)
+ + (sizeof(struct fiemap_extent) * extent_count));
+
+ em[0].fm_start = 0;
+ em[0].fm_length = st.st_size;
+ em[0].fm_extent_count = extent_count;
+ em[0].fm_flags = 0;
+
+ if (ioctl(fd, FS_IOC_FIEMAP, em) != 0) {
+ dP("FS_IOC_FIEMAP: %s, %d.\n", strerror(errno), errno);
+ goto exit_0;
+ }
+
+ for (i = 0; i < extent_count; ++i) {
+ // seek to extent start
+ if (lseek(fd, em->fm_extents[i].fe_logical, SEEK_SET) == (off_t)-1) {
+ dP("lseek(%d, %llu, SET) failed: %s, %d.\n",
+ fd, em->fm_extents[i].fe_logical, strerror(errno), errno);
+ goto exit_0;
+ }
+
+ ret = function(fd, em->fm_extents + i, arg);
+ if (ret != 0)
+ goto exit_0;
+ }
+
+ ret = 0;
+ exit_0:
+ // release resources
+ free (em);
+ exit_1:
+ // unlock
+ if (flock(fd, LOCK_UN) != 0)
+ ret = -1;
+
+ return ret;
+}
diff --git a/src/fextent_apply.h b/src/fextent_apply.h
new file mode 100644
index 0000000..40a54ec
--- /dev/null
+++ b/src/fextent_apply.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2012 Red Hat Inc., Durham, North Carolina.
+ * All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Authors:
+ * Daniel Kopecek <dkopecek@redhat.com>
+ */
+#ifndef FEXTENT_APPLY_H
+#define FEXTENT_APPLY_H
+
+#include <linux/fs.h>
+#include <linux/fiemap.h>
+
+int fextent_apply(int fd, int (*function)(int, struct fiemap_extent *, void *), void *arg);
+
+#endif /* FEXTENT_APPLY_H */
diff --git a/src/fillfile.c b/src/fillfile.c
index e0f67b6..a77367f 100644
--- a/src/fillfile.c
+++ b/src/fillfile.c
@@ -42,6 +42,7 @@
#include "util.h"
#include "fillfile.h"
+#include "fextent_apply.h"
static int no_threads = 0;
@@ -57,6 +58,20 @@ struct memstruct {
extern char *prog;
+struct fillfile_args {
+ char *path;
+ off_t filesize;
+ unsigned char *mem;
+ int memsize;
+ progress_t progress;
+ void *arg;
+ refill_t refill;
+ unsigned char *buf;
+};
+
+int fillextent(int fd, struct fiemap_extent *extent, void *pa);
+int checkextent(int fd, struct fiemap_extent *extent, void *pa);
+
#if defined(O_DIRECT) && (defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_MEMALIGN))
# define MY_O_DIRECT O_DIRECT
#else
@@ -155,11 +170,12 @@ refill_fini(struct memstruct *mp)
* If 'sparse' is true, only scrub first and last blocks (for testing).
* The number of bytes written is returned.
* If 'creat' is true, open with O_CREAT and allow ENOSPC to be non-fatal.
+ * IF 'extentonly' is true, fill only file extents with the given pattern
*/
off_t
fillfile(char *path, off_t filesize, unsigned char *mem, int memsize,
progress_t progress, void *arg, refill_t refill,
- bool sparse, bool creat)
+ bool sparse, bool creat, bool extentonly)
{
int fd = -1;
off_t n;
@@ -179,34 +195,58 @@ fillfile(char *path, off_t filesize, unsigned char *mem, int memsize,
}
if (fd < 0)
goto error;
- do {
- if (written + memsize > filesize)
- memsize = filesize - written;
- if (refill && !sparse) {
- if (!mp)
- if (refill_init(&mp, refill, memsize) < 0)
- goto error;
- if (refill_memcpy(mp, mem, memsize, filesize, written) < 0)
- goto error;
- }
- if (sparse && !(written == 0) && !(written + memsize == filesize)) {
- if (lseek(fd, memsize, SEEK_CUR) < 0)
- goto error;
- written += memsize;
- } else {
- n = write_all(fd, mem, memsize);
- if (creat && n < 0 && errno == ENOSPC)
- break;
- if (n == 0) {
- errno = EINVAL; /* write past end of device? */
- goto error;
- } else if (n < 0)
- goto error;
- written += n;
+
+ if (extentonly) {
+ struct fillfile_args fa;
+
+ fa.path = path;
+ fa.filesize = filesize;
+ fa.mem = mem;
+ fa.memsize = memsize;
+ fa.progress = progress;
+ fa.refill = refill;
+ fa.arg = arg;
+
+ if (fextent_apply(fd, fillextent, &fa) == 0) {
+ written = filesize;
}
- if (progress)
- progress(arg, (double)written/filesize);
- } while (written < filesize);
+ } else {
+ do {
+ if (written + memsize > filesize)
+ memsize = filesize - written;
+ if (refill && !sparse) {
+ if (!mp) {
+ if (refill_init(&mp, refill, memsize) < 0) {
+ goto error;
+ }
+ }
+ if (refill_memcpy(mp, mem, memsize, filesize, written) < 0) {
+ goto error;
+ }
+ }
+ if (sparse && !(written == 0) && !(written + memsize == filesize)) {
+ if (lseek(fd, memsize, SEEK_CUR) < 0) {
+ goto error;
+ }
+ written += memsize;
+ } else {
+ n = write_all(fd, mem, memsize);
+ if (creat && n < 0 && errno == ENOSPC)
+ break;
+ if (n == 0) {
+ errno = EINVAL;
+ goto error;
+ }
+ else if (n < 0) {
+ goto error;
+ }
+ written += n;
+ }
+ if (progress)
+ progress(arg, (double)written/filesize);
+ } while (written < filesize);
+ }
+
if (fsync(fd) < 0)
goto error;
#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
@@ -230,7 +270,7 @@ error:
*/
off_t
checkfile(char *path, off_t filesize, unsigned char *mem, int memsize,
- progress_t progress, void *arg, bool sparse)
+ progress_t progress, void *arg, bool sparse, bool extentonly)
{
int fd = -1;
off_t n;
@@ -238,8 +278,6 @@ checkfile(char *path, off_t filesize, unsigned char *mem, int memsize,
unsigned char *buf = NULL;
int openflags = O_RDONLY;
- if (!(buf = alloc_buffer(memsize)))
- goto nomem;
if (filetype(path) != FILE_CHAR)
openflags |= MY_O_DIRECT;
fd = open(path, openflags);
@@ -250,32 +288,60 @@ checkfile(char *path, off_t filesize, unsigned char *mem, int memsize,
}
if (fd < 0)
goto error;
- do {
- if (verified + memsize > filesize)
- memsize = filesize - verified;
- if (sparse && !(verified == 0) && !(verified + memsize == filesize)) {
- if (lseek(fd, memsize, SEEK_CUR) < 0)
- goto error;
- verified += memsize;
- } else {
- n = read_all(fd, buf, memsize);
- if (n < 0)
- goto error;
- if (n == 0) {
- errno = EINVAL; /* early EOF */
- goto error;
- }
- if (memcmp(mem, buf, memsize) != 0) {
- break; /* return < filesize means verification failure */
- }
- verified += n;
+ if (extentonly) {
+ struct fillfile_args fa;
+
+ fa.path = path;
+ fa.filesize = filesize;
+ fa.mem = mem;
+ fa.memsize = memsize;
+ fa.progress = progress;
+ fa.arg = arg;
+ fa.buf = alloc_buffer(memsize);
+
+ if (fa.buf == NULL) {
+ goto nomem;
}
- if (progress)
- progress(arg, (double)verified/filesize);
- } while (verified < filesize);
+
+ if (fextent_apply(fd, checkextent, &fa) == 0)
+ verified = filesize;
+
+ free(fa.buf);
+ } else {
+ if (!(buf = alloc_buffer(memsize)))
+ goto nomem;
+ do {
+ if (verified + memsize > filesize)
+ memsize = filesize - verified;
+ if (sparse && !(verified == 0) && !(verified + memsize == filesize)) {
+ if (lseek(fd, memsize, SEEK_CUR) < 0) {
+ goto error;
+ }
+ verified += memsize;
+ } else {
+ n = read_all(fd, buf, memsize);
+ if (n < 0) {
+ goto error;
+ }
+ if (n == 0) {
+ errno = EINVAL; /* early EOF */
+ goto error;
+ }
+ if (memcmp(mem, buf, memsize) != 0) {
+ break;
+ }
+ verified += n;
+ }
+ if (progress)
+ progress(arg, (double)verified/filesize);
+ } while (verified < filesize);
+ }
+
if (close(fd) < 0)
goto error;
- free(buf);
+ if (buf != NULL) {
+ free(buf);
+ }
return verified;
nomem:
errno = ENOMEM;
@@ -293,6 +359,63 @@ disable_threads(void)
no_threads = 1;
}
+int fillextent(int fd, struct fiemap_extent *extent, void *pa)
+{
+ off_t n;
+ off_t written = 0LL;
+ struct fillfile_args args = *(struct fillfile_args *)(pa);
+
+ do {
+ if (args.refill)
+ args.refill(args.mem, args.memsize);
+
+ if (written + args.memsize > extent->fe_length)
+ args.memsize = extent->fe_length - written;
+
+ n = write_all(fd, args.mem, args.memsize);
+
+ if (n < 0) {
+ fprintf(stderr, "%s: write %s: %s\n", prog, args.path, strerror(errno));
+ exit(1);
+ }
+ written += n;
+
+ if (args.progress)
+ args.progress(args.arg, (double)(extent->fe_logical + written)/args.filesize);
+ } while (written < extent->fe_length);
+
+ return 0;
+}
+
+int checkextent(int fd, struct fiemap_extent *extent, void *pa)
+{
+ off_t n;
+ off_t verified = 0LL;
+ struct fillfile_args args = *(struct fillfile_args *)(pa);
+
+ do {
+ if (verified + args.memsize > extent->fe_length)
+ args.memsize = extent->fe_length - verified;
+
+ n = read_all(fd, args.buf, args.memsize);
+ if (n < 0) {
+ return -1;
+ }
+ if (n == 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (memcmp(args.mem, args.buf, args.memsize) != 0) {
+ break;
+ }
+ verified += n;
+ if (args.progress)
+ args.progress(args.arg, (double)(extent->fe_logical+verified)/args.filesize);
+ } while (verified < extent->fe_length);
+
+ return 0;
+}
+
/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/
diff --git a/src/fillfile.h b/src/fillfile.h
index b9ef951..2fc917d 100644
--- a/src/fillfile.h
+++ b/src/fillfile.h
@@ -29,7 +29,7 @@ typedef void (*refill_t) (unsigned char *mem, int memsize);
off_t fillfile(char *path, off_t filesize, unsigned char *mem, int memsize,
progress_t progress, void *arg, refill_t refill,
- bool sparse, bool creat);
+ bool sparse, bool creat, bool extentonly);
off_t checkfile(char *path, off_t filesize, unsigned char *mem, int memsize,
- progress_t progress, void *arg, bool sparse);
+ progress_t progress, void *arg, bool sparse, bool extentonly);
void disable_threads(void);
diff --git a/src/genrand.c b/src/genrand.c
index 820c898..ecfd382 100644
--- a/src/genrand.c
+++ b/src/genrand.c
@@ -106,7 +106,7 @@ genrandraw(unsigned char *buf, int buflen)
buf[n] = result;
}
#endif
- return;
+ return 0;
}
}
diff --git a/src/scrub.c b/src/scrub.c
index dec71f3..b0eb1f7 100644
--- a/src/scrub.c
+++ b/src/scrub.c
@@ -58,12 +58,12 @@
#define BUFSIZE (4*1024*1024) /* default blocksize */
static bool scrub(char *path, off_t size, const sequence_t *seq,
- int bufsize, bool Sopt, bool sparse, bool enospc);
+ int bufsize, bool Sopt, bool sparse, bool enospc, bool extentonly);
static void scrub_free(char *path, off_t size, const sequence_t *seq,
int bufsize, bool Sopt);
static void scrub_dirent(char *path, char *newpath);
static void scrub_file(char *path, off_t size, const sequence_t *seq,
- int bufsize, bool Sopt, bool sparse);
+ int bufsize, bool Sopt, bool sparse, bool extentonly);
#if __APPLE__
static void scrub_resfork(char *path, const sequence_t *seq,
int bufsize);
@@ -71,7 +71,7 @@ static void scrub_resfork(char *path, const sequence_t *seq,
static void scrub_disk(char *path, off_t size, const sequence_t *seq,
int bufsize, bool Sopt, bool sparse);
-#define OPTIONS "p:D:Xb:s:fSrvTLRth"
+#define OPTIONS "p:D:Xb:s:fSrvTELRth"
#if HAVE_GETOPT_LONG
#define GETOPT(ac,av,opt,lopt) getopt_long(ac,av,opt,lopt,NULL)
static struct option longopts[] = {
@@ -85,6 +85,7 @@ static struct option longopts[] = {
{"remove", no_argument, 0, 'r'},
{"version", no_argument, 0, 'v'},
{"test-sparse", no_argument, 0, 'T'},
+ {"extent-only", no_argument, 0, 'E'},
{"no-link", no_argument, 0, 'L'},
{"no-hwrand", no_argument, 0, 'R'},
{"no-threads", no_argument, 0, 't'},
@@ -111,6 +112,7 @@ usage(void)
" -f, --force scrub despite signature from previous scrub\n"
" -S, --no-signature do not write scrub signature after scrub\n"
" -r, --remove remove file after scrub\n"
+" -E, --extent-only scrub only file extents\n"
" -L, --no-link do not scrub link target\n"
" -R, --no-hwrand do not use a hardware random number generator\n"
" -t, --no-threads do not compute random data in a parallel thread\n"
@@ -139,6 +141,7 @@ main(int argc, char *argv[])
bool Lopt = false;
bool Ropt = false;
bool topt = false;
+ bool Eopt = false;
extern int optind;
extern char *optarg;
int c;
@@ -207,6 +210,9 @@ main(int argc, char *argv[])
case 'T': /* --test-sparse */
Topt = true;
break;
+ case 'E': /* --extent-only */
+ Eopt = true;
+ break;
case 'L': /* --no-link */
Lopt = true;
break;
@@ -315,7 +321,7 @@ main(int argc, char *argv[])
prog, Dopt, filename);
exit(1);
}
- scrub_file(filename, sopt, seq, bopt, Sopt, Topt);
+ scrub_file(filename, sopt, seq, bopt, Sopt, Topt, Eopt);
#if __APPLE__
scrub_resfork(filename, seq, bopt);
#endif
@@ -346,14 +352,14 @@ done:
*/
static bool
scrub(char *path, off_t size, const sequence_t *seq, int bufsize,
- bool Sopt, bool sparse, bool enospc)
+ bool Sopt, bool sparse, bool enospc, bool extentonly)
{
unsigned char *buf;
int i;
prog_t p;
char sizestr[80];
bool isfull = false;
- off_t written, checked;
+ off_t written = (off_t)-1, checked = (off_t)-1;
if (!(buf = alloc_buffer(bufsize))) {
fprintf(stderr, "%s: out of memory\n", prog);
@@ -381,7 +387,7 @@ scrub(char *path, off_t size, const sequence_t *seq, int bufsize,
}
written = fillfile(path, size, buf, bufsize,
(progress_t)progress_update, p,
- (refill_t)genrand, sparse, enospc);
+ (refill_t)genrand, sparse, enospc, extentonly);
if (written == (off_t)-1) {
fprintf(stderr, "%s: %s: %s\n", prog, path,
strerror(errno));
@@ -395,7 +401,7 @@ scrub(char *path, off_t size, const sequence_t *seq, int bufsize,
memset_pat(buf, seq->pat[i], bufsize);
written = fillfile(path, size, buf, bufsize,
(progress_t)progress_update, p,
- NULL, sparse, enospc);
+ NULL, sparse, enospc, extentonly);
if (written == (off_t)-1) {
fprintf(stderr, "%s: %s: %s\n", prog, path,
strerror(errno));
@@ -409,7 +415,7 @@ scrub(char *path, off_t size, const sequence_t *seq, int bufsize,
memset_pat(buf, seq->pat[i], bufsize);
written = fillfile(path, size, buf, bufsize,
(progress_t)progress_update, p,
- NULL, sparse, enospc);
+ NULL, sparse, enospc, extentonly);
if (written == (off_t)-1) {
fprintf(stderr, "%s: %s: %s\n", prog, path,
strerror(errno));
@@ -419,7 +425,7 @@ scrub(char *path, off_t size, const sequence_t *seq, int bufsize,
printf("%s: %-8s", prog, "verify");
progress_create(&p, 50);
checked = checkfile(path, written, buf, bufsize,
- (progress_t)progress_update, p, sparse);
+ (progress_t)progress_update, p, sparse, extentonly);
if (checked == (off_t)-1) {
fprintf(stderr, "%s: %s: %s\n", prog, path,
strerror(errno));
@@ -513,7 +519,7 @@ scrub_free(char *dirpath, off_t size, const sequence_t *seq,
size = blkalign(size, sb.st_blksize, DOWN);
do {
snprintf(path, sizeof(path), "%s/scrub.%.3d", dirpath, fileno++);
- isfull = scrub(path, size, seq, bufsize, Sopt, false, true);
+ isfull = scrub(path, size, seq, bufsize, Sopt, false, true, false);
} while (!isfull);
while (--fileno >= 0) {
snprintf(path, sizeof(path), "%s/scrub.%.3d", dirpath, fileno);
@@ -565,7 +571,7 @@ scrub_dirent(char *path, char *newpath)
*/
static void
scrub_file(char *path, off_t size, const sequence_t *seq,
- int bufsize, bool Sopt, bool sparse)
+ int bufsize, bool Sopt, bool sparse, bool extentonly)
{
struct stat sb;
filetype_t ftype = filetype(path);
@@ -590,7 +596,7 @@ scrub_file(char *path, off_t size, const sequence_t *seq,
prog, path, (int)(size - sb.st_size));
}
}
- scrub(path, size, seq, bufsize, Sopt, sparse, false);
+ scrub(path, size, seq, bufsize, Sopt, sparse, false, extentonly);
}
/* Scrub apple resource fork component of file.
@@ -618,7 +624,7 @@ scrub_resfork(char *path, const sequence_t *seq, int bufsize)
printf("%s: padding %s with %d bytes to fill last fs block\n",
prog, rpath, (int)(rsize - rsb.st_size));
}
- scrub(rpath, rsize, seq, bufsize, false, false, false);
+ scrub(rpath, rsize, seq, bufsize, false, false, false, false);
}
#endif
@@ -639,7 +645,7 @@ scrub_disk(char *path, off_t size, const sequence_t *seq, int bufsize,
}
printf("%s: please verify that device size below is correct!\n", prog);
}
- scrub(path, size, seq, bufsize, Sopt, sparse, false);
+ scrub(path, size, seq, bufsize, Sopt, sparse, false, false);
}
/*
--
2.20.1

File diff suppressed because it is too large Load Diff

View File

@ -1,77 +0,0 @@
--- scrub-2.5.2.ori/src/scrub.c 2012-06-21 00:00:27.000000000 +0200
+++ scrub-2.5.2/src/scrub.c 2021-08-09 18:25:00.355142963 +0200
@@ -283,8 +283,8 @@
}
scrub_disk(filename, sopt, seq, bopt, Sopt, Topt);
break;
- case FILE_LINK:
- if (Lopt) {
+ case FILE_REGULAR:
+ if (is_symlink(filename) && Lopt) {
if (ropt) {
printf("%s: unlinking %s\n", prog, filename);
if (unlink(filename) != 0) {
@@ -295,7 +295,6 @@
}
break;
}
- case FILE_REGULAR:
if (access(filename, R_OK|W_OK) < 0) {
fprintf(stderr, "%s: no rw access to %s\n", prog, filename);
exit(1);
@@ -570,7 +570,7 @@
struct stat sb;
filetype_t ftype = filetype(path);
- assert(ftype == FILE_REGULAR || ftype == FILE_LINK);
+ assert(ftype == FILE_REGULAR);
if (stat(path, &sb) < 0) {
fprintf(stderr, "%s: stat %s: %s\n", prog, path, strerror(errno));
--- scrub-2.5.2.ori/src/util.c 2012-06-21 00:00:27.000000000 +0200
+++ scrub-2.5.2/src/util.c 2021-08-10 15:38:26.748107704 +0200
@@ -72,6 +72,15 @@
return n;
}
+/* Indicates whether the file represented by 'path' is a symlink.
+ */
+int
+is_symlink(char *path)
+{
+ struct stat sb;
+ return lstat(path, &sb) == 0 && S_ISLNK(sb.st_mode);
+}
+
/* Return the type of file represented by 'path'.
*/
filetype_t
@@ -90,10 +90,6 @@
filetype_t res = FILE_NOEXIST;
- if (lstat(path, &sb) == 0 && S_ISLNK(sb.st_mode)) {
- return FILE_LINK;
- }
-
if (stat(path, &sb) == 0) {
if (S_ISREG(sb.st_mode))
res = FILE_REGULAR;
--- scrub-2.5.2.ori/src/util.h 2012-06-21 00:00:27.000000000 +0200
+++ scrub-2.5.2/src/util.h 2021-08-16 16:12:25.306572001 +0200
@@ -35,7 +35,6 @@
FILE_REGULAR,
FILE_CHAR,
FILE_BLOCK,
- FILE_LINK,
FILE_OTHER,
} filetype_t;
@@ -43,6 +42,7 @@
int read_all(int fd, unsigned char *buf, int count);
int write_all(int fd, const unsigned char *buf, int count);
+int is_symlink(char *path);
filetype_t filetype(char *path);
off_t blkalign(off_t offset, int blocksize, round_t rtype);
void * alloc_buffer(int bufsize);

View File

@ -1,239 +0,0 @@
From 9f37f5d29f255285cbc7822788963681a8f659dd Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Tue, 26 Jan 2021 15:22:57 -0500
Subject: [PATCH] test: use a power of 2 for file sizes
Reduce the change of tests failing due to block size round-up.
Freebsd was failing that way.
Upstream: https://github.com/chaos/scrub/commit/5c66fc0537f4ecb21d4c3dcdd9020a02c8a2d819
---
test/t02 | 2 +-
test/t02.exp | 2 +-
test/t03 | 2 +-
test/t03.exp | 2 +-
test/t04 | 2 +-
test/t04.exp | 2 +-
test/t05 | 2 +-
test/t05.exp | 2 +-
test/t06 | 2 +-
test/t06.exp | 2 +-
test/t07 | 2 +-
test/t11 | 2 +-
test/t11.exp | 2 +-
test/t12 | 8 ++++----
test/t12.exp | 12 ++++++------
15 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/test/t02 b/test/t02
index d09a517..14c5ca7 100755
--- a/test/t02
+++ b/test/t02
@@ -1,6 +1,6 @@
#!/bin/sh
TESTFILE=${TMPDIR:-/tmp}/scrub-testfile.$$
rm -f $TESTFILE
-./pad 400k $TESTFILE || exit 1
+./pad 512k $TESTFILE || exit 1
$PATH_SCRUB -r $TESTFILE 2>&1 | sed -e "s!${TESTFILE}!file!" >t02.out || exit 1
diff t02.exp t02.out >t02.diff
diff --git a/test/t02.exp b/test/t02.exp
index 848c9b7..e026a17 100644
--- a/test/t02.exp
+++ b/test/t02.exp
@@ -1,5 +1,5 @@
scrub: using NNSA NAP-14.1-C patterns
-scrub: scrubbing file 409600 bytes (~400KB)
+scrub: scrubbing file 524288 bytes (~512KB)
scrub: random |................................................|
scrub: random |................................................|
scrub: 0x00 |................................................|
diff --git a/test/t03 b/test/t03
index db9ca61..917ec52 100755
--- a/test/t03
+++ b/test/t03
@@ -1,6 +1,6 @@
#!/bin/sh
TESTFILE=${TMPDIR:-/tmp}/scrub-testfile.$$
rm -f $TESTFILE
-./pad 400k $TESTFILE || exit 1
+./pad 512k $TESTFILE || exit 1
$PATH_SCRUB -r -p dod $TESTFILE 2>&1 | sed -e "s!$TESTFILE!file!" >t03.out || exit 1
diff t03.exp t03.out >t03.diff
diff --git a/test/t03.exp b/test/t03.exp
index e7e8015..4456149 100644
--- a/test/t03.exp
+++ b/test/t03.exp
@@ -1,5 +1,5 @@
scrub: using DoD 5220.22-M patterns
-scrub: scrubbing file 409600 bytes (~400KB)
+scrub: scrubbing file 524288 bytes (~512KB)
scrub: random |................................................|
scrub: 0x00 |................................................|
scrub: 0xff |................................................|
diff --git a/test/t04 b/test/t04
index 3dd4165..a33e9cd 100755
--- a/test/t04
+++ b/test/t04
@@ -1,6 +1,6 @@
#!/bin/sh
TESTFILE=${TMPDIR:-/tmp}/scrub-testfile.$$
rm -f $TESTFILE
-./pad 400k $TESTFILE || exit 1
+./pad 512k $TESTFILE || exit 1
$PATH_SCRUB -r -p bsi $TESTFILE 2>&1 | sed -e "s!$TESTFILE!file!" >t04.out || exit 1
diff t04.exp t04.out >t04.diff
diff --git a/test/t04.exp b/test/t04.exp
index 2bb6822..ac98d54 100644
--- a/test/t04.exp
+++ b/test/t04.exp
@@ -1,5 +1,5 @@
scrub: using BSI patterns
-scrub: scrubbing file 409600 bytes (~400KB)
+scrub: scrubbing file 524288 bytes (~512KB)
scrub: 0xff |................................................|
scrub: 0xfe |................................................|
scrub: 0xfd |................................................|
diff --git a/test/t05 b/test/t05
index 474fcd3..d9a6061 100755
--- a/test/t05
+++ b/test/t05
@@ -1,6 +1,6 @@
#!/bin/sh
TESTFILE=${TMPDIR:-/tmp}/scrub-testfile.$$
rm -f $TESTFILE
-./pad 400k $TESTFILE || exit 1
+./pad 512k $TESTFILE || exit 1
$PATH_SCRUB -r -p fastold $TESTFILE 2>&1 | sed -e "s!$TESTFILE!file!" >t05.out || exit 1
diff t05.exp t05.out >t05.diff
diff --git a/test/t05.exp b/test/t05.exp
index 48ba9b7..118d7e4 100644
--- a/test/t05.exp
+++ b/test/t05.exp
@@ -1,5 +1,5 @@
scrub: using pre v1.7 scrub (skip random) patterns
-scrub: scrubbing file 409600 bytes (~400KB)
+scrub: scrubbing file 524288 bytes (~512KB)
scrub: 0x00 |................................................|
scrub: 0xff |................................................|
scrub: 0xaa |................................................|
diff --git a/test/t06 b/test/t06
index 28eb856..48bde5a 100755
--- a/test/t06
+++ b/test/t06
@@ -1,7 +1,7 @@
#!/bin/sh
TESTFILE=${TMPDIR:-/tmp}/scrub-testfile.$$
rm -f $TESTFILE
-./pad 400k $TESTFILE || exit 1
+./pad 512k $TESTFILE || exit 1
$PATH_SCRUB -r -p old $TESTFILE 2>&1 | sed -e "s!$TESTFILE!file!" >t06.out || exit 1
diff t06.exp t06.out >t06.diff
rc=$?
diff --git a/test/t06.exp b/test/t06.exp
index 49967ec..e84360a 100644
--- a/test/t06.exp
+++ b/test/t06.exp
@@ -1,5 +1,5 @@
scrub: using pre v1.7 scrub patterns
-scrub: scrubbing file 409600 bytes (~400KB)
+scrub: scrubbing file 524288 bytes (~512KB)
scrub: 0x00 |................................................|
scrub: 0xff |................................................|
scrub: 0xaa |................................................|
diff --git a/test/t07 b/test/t07
index cb935bf..69eab76 100755
--- a/test/t07
+++ b/test/t07
@@ -1,7 +1,7 @@
#!/bin/sh
TESTFILE=${TMPDIR:-/tmp}/scrub-testfile.$$
rm -f $TESTFILE
-./pad 400k $TESTFILE
+./pad 512k $TESTFILE
(./tsig $TESTFILE && ./tsig $TESTFILE) >t07.out 2>&1
diff t07.exp t07.out >t07.diff
rc=$?
diff --git a/test/t11 b/test/t11
index 5a17b46..dd5444f 100755
--- a/test/t11
+++ b/test/t11
@@ -1,7 +1,7 @@
#!/bin/sh
TESTFILE=${TMPDIR:-/tmp}/scrub-testfile.$$
rm -f $TESTFILE
-./pad 400k $TESTFILE || exit 1
+./pad 512k $TESTFILE || exit 1
$PATH_SCRUB -r -p gutmann $TESTFILE 2>&1 | sed -e "s!$TESTFILE!file!" >t11.out || exit 1
diff t11.exp t11.out >t11.diff
rc=$?
diff --git a/test/t11.exp b/test/t11.exp
index abd2abf..895d903 100644
--- a/test/t11.exp
+++ b/test/t11.exp
@@ -1,5 +1,5 @@
scrub: using Gutmann patterns
-scrub: scrubbing file 409600 bytes (~400KB)
+scrub: scrubbing file 524288 bytes (~512KB)
scrub: random |................................................|
scrub: random |................................................|
scrub: random |................................................|
diff --git a/test/t12 b/test/t12
index c312220..260198f 100755
--- a/test/t12
+++ b/test/t12
@@ -1,14 +1,14 @@
#!/bin/sh
TESTFILE=${TMPDIR:-/tmp}/scrub-testfile.$$
rm -f $TESTFILE
-./pad 400k $TESTFILE || exit 1
-$PATH_SCRUB -s 400k $TESTFILE 2>&1 | sed -e "s!$TESTFILE!file!" >t12.out
+./pad 512k $TESTFILE || exit 1
+$PATH_SCRUB -s 512k $TESTFILE 2>&1 | sed -e "s!$TESTFILE!file!" >t12.out
test $? = 0 || exit 1
./tsize $TESTFILE >>t12.out 2>&1
-$PATH_SCRUB -f -s 300k $TESTFILE 2>&1 | sed -e "s!$TESTFILE!file!" >>t12.out
+$PATH_SCRUB -f -s 256k $TESTFILE 2>&1 | sed -e "s!$TESTFILE!file!" >>t12.out
test $? = 0 || exit 1
./tsize $TESTFILE >>t12.out 2>&1
-$PATH_SCRUB -f -s 500k $TESTFILE 2>&1 | sed -e "s!$TESTFILE!file!" >>t12.out
+$PATH_SCRUB -f -s 1024k $TESTFILE 2>&1 | sed -e "s!$TESTFILE!file!" >>t12.out
test $? = 0 || exit 1
./tsize $TESTFILE >>t12.out 2>&1
diff t12.exp t12.out >t12.diff
diff --git a/test/t12.exp b/test/t12.exp
index 33f2c97..4c5d987 100644
--- a/test/t12.exp
+++ b/test/t12.exp
@@ -1,22 +1,22 @@
scrub: using NNSA NAP-14.1-C patterns
-scrub: scrubbing file 409600 bytes (~400KB)
+scrub: scrubbing file 524288 bytes (~512KB)
scrub: random |................................................|
scrub: random |................................................|
scrub: 0x00 |................................................|
scrub: verify |................................................|
-409600
+524288
scrub: warning: -s size < file size
scrub: using NNSA NAP-14.1-C patterns
-scrub: scrubbing file 307200 bytes (~300KB)
+scrub: scrubbing file 262144 bytes (~256KB)
scrub: random |................................................|
scrub: random |................................................|
scrub: 0x00 |................................................|
scrub: verify |................................................|
-409600
+524288
scrub: using NNSA NAP-14.1-C patterns
-scrub: scrubbing file 512000 bytes (~500KB)
+scrub: scrubbing file 1048576 bytes (~1024KB)
scrub: random |................................................|
scrub: random |................................................|
scrub: 0x00 |................................................|
scrub: verify |................................................|
-512000
+1048576
--
2.27.0

View File

@ -1 +0,0 @@
SHA512 (scrub-2.5.2.tar.bz2) = 23815831a356b3a7c6a75354134c49912dc97f9e54130acaa9ee8e80cf839e18238bf69cf6d5aaf79dbbc3dc4195ca78cb6f0d5aca11972726956040fcc424e7